You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(native-chat): reopen an OpenCode chat in the folder OpenCode moved it to - #42590
OpenCode can move a conversation into another folder on its own, for example into a worktree it just created. When Orca later reopened that chat, it asked OpenCode for the conversation in the chat's original folder. OpenCode said no, and Orca quietly started a brand-new conversation instead. Now Orca asks OpenCode where the conversation lives and reopens it there.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$55
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$55
Prod
8
$\color{#1a7f37}{\Huge{\mathbf{+}}}$112
$\color{#cf222e}{\Huge{\mathbf{−}}}$28
$\color{#1a7f37}{\Huge{\mathbf{+}}}$84
What Changed
Before: an OpenCode 2.x chat whose conversation OpenCode had moved could not be reopened after a restart or reconnect. Orca showed "OpenCode couldn't reopen its earlier session, so this chat continues in a new one" and carried on in a new, empty OpenCode session. Session History still listed the old conversation, but its row opened the chat, and the chat now continued the new conversation. That is the "resume B opens A" report in #41652.
After: the chat reopens the same OpenCode conversation in the folder it moved to, with no warning row and no new session.
How it works:
OpenCode 2.x refuses session/load from the wrong folder with -32602 and data { sessionId, cwd } ("session X does not belong to cwd: Y").
The OpenCode dialect recognises exactly that refusal through a new sessionInOtherFolder hook, beside the existing sessionLost hook.
It matches on the structured data, not the message text.
On that refusal, acpSessionOtherFolder (in acp-session-reopen-failure.ts, next to acpReopenTakeover) pages ACP session/list with no cwd. That lists every folder's sessions. It finds the conversation's current folder.
The handshake then retries the load there once.
Any other refusal, a failed lookup, or a failed retry goes through the existing takeover unchanged.
The chat's own folder, process cwd and Orca's file and branch views still use the workspace. Only the ACP session is opened where OpenCode keeps it.
AcpAgentConnection.listSessions now takes { cwd?, cursor? }. Its one existing caller, the Antigravity host probe, still passes { cwd }.
Why
The takeover exists for a conversation the agent really lost. A moved conversation isn't lost: OpenCode still has it, just in another folder. Replacing it hid the user's history behind a new session and broke Session History's resume.
Alternatives considered:
Refusing with a "conversation moved" error: smaller, but it leaves the chat unopenable.
Pinning the moved folder as the chat's launch directory: built in an earlier version of this branch. Review showed that Orca's renderer ties branch controls, remote file addressing and image links to the workspace identity. A pin pointing at another folder made those disagree, so it was dropped. Looking the folder up on each reopen costs one refused load plus a session/list page for moved chats only, and changes nothing else.
Linked Issue
Related to #41652: this fixes the wrong-session resume.
That issue also reports the active session tab disappearing from mobile. This PR doesn't prove or fix that part. Settling it needs:
the host and phone versions;
the host's <profile>/logs/main.trace.ndjson from the incident window;
whether the chat showed the "couldn't reopen its earlier session" row;
select id, directory, time_updated from session_v2 from the reporter's opencode.db for the two sessions.
Visual Proof
The UI is unchanged. What changes is which conversation the chat continues. These are from a live run instead of screenshots: a worktree-built headless orca serve, real OpenCode 2.2.7 on a free model, an isolated HOME/XDG_* and a folder workspace. The chat was created in proj and replied. OpenCode's own session.move then moved the conversation to proj-moved, and it took effect on the chat's next turn. After that the serve was restarted and a message was sent again.
Before, on origin/main: a second OpenCode session appears in the old folder, and the chat's chain records restore-failed:
Live run as above: the before case on origin/main, and the after case with three starts on this branch.
I also checked OpenCode 2.2.7's refusal directly over ACP:
session/load from another folder → -32602 … does not belong to cwd;
from the parent folder → refused too;
from the session's own folder → loads;
after session.move → the old folder is refused and the new one loads.
One regression test, acp-structured-session-adapter-resume.test.ts, replays that captured refusal. It expects a second load in the listed folder and no session/new. It fails on main: one load, then a takeover.
pnpm check:changed passes. The focused ACP tests pass, and so do the 92 test files test-dependents lists, except server-ingest-structured-status.test.ts, which fails the same way on main (unable to open database file).
Platform: macOS. Linux and Windows aren't affected differently: OpenCode normalises the folder comparison itself (FSUtil.resolve), and Orca only passes OpenCode's own reported path back.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
Riskiest part: a reopened moved chat now runs its ACP session in a folder that differs from the workspace. OpenCode itself chose that folder; before this change the chat lost the conversation instead.
Composer @ mentions still resolve against the workspace, as they did on main while a moved conversation was live.
If the moved folder was deleted, OpenCode still lists it. The retry then either loads it (its tools fail there) or is refused. A refusal goes to the old takeover.
Narrow trigger: only OpenCode's exact -32602 { sessionId, cwd } refusal for the same session and folder. Agents that don't advertise sessionCapabilities.list keep today's takeover. OpenCode 1.x never sends this refusal.
Wire and versions: no new wire fields or saved data, so older phones and paired hosts aren't affected.
Antigravity: the probe's call changed shape only. It still sends { cwd: folder }.
Back out: a plain revert.
Level: Low
AI Disclosure
Review
Two review-loop rounds (Codex + Claude):
Round 1:
A failed session/list lookup skipped the takeover. Fixed: lookup and retry failures now go through the takeover policy.
Renderer link and composer folders didn't follow a pinned folder. Made moot when the pin was dropped.
Round 2:
Antigravity's probe would have sent its folder as a cursor. Fixed: listSessions({ cwd?, cursor? }).
Branch controls, remote file addressing and image context disagreeing with a pinned folder. Moot: the pin and its renderer changes were removed, so the renderer matches main.
This touches the native-chat reopen and ownership area from #30930 (@brennanb2025).
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Mobile and remote hosts: the handshake runs on the execution host, so local, paired and SSH hosts and both phone apps get the fix with no client changes.
Folder workspaces: covered. The live run used a folder workspace.
Performance: a moved chat pays one refused load plus session/list pages on each reopen. Other chats pay nothing.
Follow-ups, deliberately not in this PR:
Session History offers no terminal resume for a chat's earlier conversations (terminalResumeBlocked always refuses chat-owned links). A row for a conversation a chat replaced after a failed restore can only open that chat.
Orca's UI (links, composer, branch controls) doesn't follow a folder the agent moved the conversation to. That needs workspace identity to allow a second folder.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
…d it to
OpenCode 2.x moves a conversation with its session_move tool and then refuses session/load from the old folder. Look the session up with session/list and load it where it lives instead of replacing it with a new session.
The ACP dialect now identifies OpenCode errors that indicate a session belongs to another folder. The connection exposes paginated session listing, and the resume flow uses it to find the session’s folder and retry the reopen there. The added test covers a session moved from /workspace/project to /workspace/project-worktree.
Merge Risk: Low · up to f1768
Reopening an OpenCode 2.x chat from its moved folder should work as described. A misbehaving agent that repeats a pagination cursor could stall the reopen before it falls back to a new session. The regression test also does not check that the session lookup omits the folder. Both are small, localized fixes.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the change: an OpenCode chat is reopened in the folder OpenCode moved its conversation to. The changeset adds a sessionInOtherFolder hook, a session/list lookup, and a retry of session…
Description check
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Risk, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Che…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the change: an OpenCode chat is reopened in the folder OpenCode moved its conversation to. The changeset adds a sessionInOtherFolder hook, a session/list lookup, and a retry of session/load in the reported folder, so the title matches the main change. It follows the fix(scope) convention and is concise.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Risk, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. It explains the before and after behavior, the mechanism, the alternatives considered, and the rollback path. The Visual Proof section gives live-run output instead of screenshots, which is acceptable for a backend behavior change. The Linked Issue section cites #41652 as related, not fixed. The template asks for a linked issue for outside contributors, and the author does not say whether they are a maintainer. The AI Disclosure section is empty. The Testing checkboxes are ticked, but the Testing section lists a single platform (macOS) only.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The handler returns the moved session regardless of frame.params. If lookup incorrectly sends cwd: '/workspace/project', this test can still pass. Assert that session/list was sent and that its parameters omit cwd. This protects the unscoped lookup required by the PR objective.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 24079969-ae29-453a-be67-993ea07200f8
Commits
Reviewing files that changed from the base of the PR and between 285ddd1 and f176805.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Quick win
Stop paging when a session/list cursor repeats.
A page without the target session can repeat its nextCursor. The loop then sends the same session/list request again. It exits only when the agent answers differently, the start is abandoned or closed, or a call times out. Until then, the reopen does not reach takeover. This affects only an agent that returns a repeated cursor. Track the cursors already requested and throw when one repeats. The existing lookup-failure path then applies takeover.
Suggested fix
--- "a/src/main/acp/session/start/acp-session-reopen-failure.ts"+++ "b/src/main/acp/session/start/acp-session-reopen-failure.ts"@@ -66,18 +66,24 @@
) {
return null
}
let cursor: string | undefined
+ const seen = new Set<string>()
do {
const page = sessionListPage.parse(
await input.connection.listSessions(cursor ? { cursor } : {})
)
input.assertStarting()
const listed = page.sessions.find((session) => session.sessionId === sessionId)
if (listed) {
return listed.cwd === cwd ? null : listed.cwd
}
- cursor = page.nextCursor ?? undefined+ const next = page.nextCursor ?? undefined+ if (next && seen.has(next)) {+ throw new Error('session/list returned a repeated cursor')+ }+ if (next) seen.add(next)+ cursor = next
} while (cursor)
return null
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
OpenCode can move a conversation into another folder on its own, for example into a worktree it just created. When Orca later reopened that chat, it asked OpenCode for the conversation in the chat's original folder. OpenCode said no, and Orca quietly started a brand-new conversation instead. Now Orca asks OpenCode where the conversation lives and reopens it there.
What Changed
Before: an OpenCode 2.x chat whose conversation OpenCode had moved could not be reopened after a restart or reconnect. Orca showed "OpenCode couldn't reopen its earlier session, so this chat continues in a new one" and carried on in a new, empty OpenCode session. Session History still listed the old conversation, but its row opened the chat, and the chat now continued the new conversation. That is the "resume B opens A" report in #41652.
After: the chat reopens the same OpenCode conversation in the folder it moved to, with no warning row and no new session.
How it works:
session/loadfrom the wrong folder with-32602and data{ sessionId, cwd }("session X does not belong to cwd: Y").sessionInOtherFolderhook, beside the existingsessionLosthook.acpSessionOtherFolder(inacp-session-reopen-failure.ts, next toacpReopenTakeover) pages ACPsession/listwith nocwd. That lists every folder's sessions. It finds the conversation's current folder.AcpAgentConnection.listSessionsnow takes{ cwd?, cursor? }. Its one existing caller, the Antigravity host probe, still passes{ cwd }.Why
The takeover exists for a conversation the agent really lost. A moved conversation isn't lost: OpenCode still has it, just in another folder. Replacing it hid the user's history behind a new session and broke Session History's resume.
Alternatives considered:
session/listpage for moved chats only, and changes nothing else.Linked Issue
Related to #41652: this fixes the wrong-session resume.
That issue also reports the active session tab disappearing from mobile. This PR doesn't prove or fix that part. Settling it needs:
<profile>/logs/main.trace.ndjsonfrom the incident window;select id, directory, time_updated from session_v2from the reporter'sopencode.dbfor the two sessions.Visual Proof
The UI is unchanged. What changes is which conversation the chat continues. These are from a live run instead of screenshots: a worktree-built headless
orca serve, real OpenCode 2.2.7 on a free model, an isolatedHOME/XDG_*and a folder workspace. The chat was created inprojand replied. OpenCode's ownsession.movethen moved the conversation toproj-moved, and it took effect on the chat's next turn. After that the serve was restarted and a message was sent again.Before, on
origin/main: a second OpenCode session appears in the old folder, and the chat's chain recordsrestore-failed:After, on this branch, with two restarts: one OpenCode session, and every reopen resumes it in
proj-moved:Testing
Live run as above: the before case on
origin/main, and the after case with three starts on this branch.I also checked OpenCode 2.2.7's refusal directly over ACP:
session/loadfrom another folder →-32602 … does not belong to cwd;session.move→ the old folder is refused and the new one loads.One regression test,
acp-structured-session-adapter-resume.test.ts, replays that captured refusal. It expects a second load in the listed folder and nosession/new. It fails onmain: one load, then a takeover.pnpm check:changedpasses. The focused ACP tests pass, and so do the 92 test filestest-dependentslists, exceptserver-ingest-structured-status.test.ts, which fails the same way onmain(unable to open database file).Platform: macOS. Linux and Windows aren't affected differently: OpenCode normalises the folder comparison itself (
FSUtil.resolve), and Orca only passes OpenCode's own reported path back.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
Riskiest part: a reopened moved chat now runs its ACP session in a folder that differs from the workspace. OpenCode itself chose that folder; before this change the chat lost the conversation instead.
@mentions still resolve against the workspace, as they did onmainwhile a moved conversation was live.Narrow trigger: only OpenCode's exact
-32602 { sessionId, cwd }refusal for the same session and folder. Agents that don't advertisesessionCapabilities.listkeep today's takeover. OpenCode 1.x never sends this refusal.Wire and versions: no new wire fields or saved data, so older phones and paired hosts aren't affected.
Antigravity: the probe's call changed shape only. It still sends
{ cwd: folder }.Back out: a plain revert.
Level: Low
AI Disclosure
Review
Two
review-looprounds (Codex + Claude):session/listlookup skipped the takeover. Fixed: lookup and retry failures now go through the takeover policy.listSessions({ cwd?, cursor? }).main.This touches the native-chat reopen and ownership area from #30930 (@brennanb2025).
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
session/listpages on each reopen. Other chats pay nothing.Follow-ups, deliberately not in this PR:
terminalResumeBlockedalways refuses chat-owned links). A row for a conversation a chat replaced after a failed restore can only open that chat./cdmoves a conversation's folder and History resumes in the old one. Same class of bug, different agent.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)