Skip to content

fix(acp): rebind sessions when their directory moves - #66612

Open
rh0kzy wants to merge 8 commits into
anomalyco:devfrom
rh0kzy:acp-session-move
Open

rh0kzy wants to merge 8 commits into
anomalyco:devfrom
rh0kzy:acp-session-move

Conversation

@rh0kzy

@rh0kzy rh0kzy commented Nov 26, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #66573

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

opencode acp ignored session.moved, so moving a session to a worktree left the client pinned to the old cwd and unable to load it after restart. ACP now rebinds the attached session to the new directory, reloads catalog/MCP state, notifies the client with _meta["opencode/directory"], and uses the current directory for active and background turn permissions/diffs. Catalog watching recovers after transient destination load failures. Mismatch errors also include the real session directory.

No feature flag is needed for this bug fix.

How did you verify your code works?

  • bun test test/acp/session.test.ts test/acp/permission.test.ts test/acp/turn.test.ts --rerun-each 10 --timeout 30000 --only-failures — 220 pass
  • bun test test/acp --timeout 30000 --only-failures — 119 pass
  • bun typecheck and bun run typecheck:tsc in packages/cli — pass
  • bun typecheck in services/site — pass
  • bun run build in services/site — pass (668 docs pages, worker start checks pass)
  • bun run lint with the repository's pinned tools — pass (existing warnings only)

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #52952

Public API: ACP: adds a session_info_update with _meta["opencode/directory"] when a session moves, and adds directory to the cwd-mismatch error data (backwards compatible)

Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The move notification works. I ran the #66573 reproduction from source on the base and on this branch. With the session moved through the ACP process's own server (as the agent's session.move tool does), the client gets session_info_update with _meta["opencode/directory"]. After a restart, the cwd-mismatch error now includes the session's real directory, and loading with that directory works. The repro's opencode api session.move goes to a different server (ACP starts its own standalone one), so that path still sends nothing, which is expected. bun test test/acp (119 pass) and tsc -b both pass.

Public API (ACP protocol), additive and backwards compatible:

  • New: attached sessions get a session_info_update with _meta: { "opencode/directory": <dir> } when they move.
  • Changed: the invalid-params error for a cwd mismatch on session/load / session/resume / session/fork adds data.directory, and its message gains ; session directory: <dir>.

Concerns:

  • Please remove docs/superpowers/plans/2026-11-26-acp-session-move.md and docs/superpowers/specs/2026-11-26-acp-session-move-design.md. They look like planning notes for the change, not repository docs.
  • After a client restart, a client that doesn't read the new _meta key (Zed today) still can't load the session with its original cwd. It can only recover by reading directory from the error. That helps, but it's worth being explicit that the restart case reported in #66573 depends on clients adopting this.
  • recover retries without limit (see inline comment).

Related: #52952

)
})

const recover = Effect.fnUntraced(function* (entry: Entry, previous: Catalog, directory: string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the destination catalog never loads (for example, the worktree was removed or its config is broken), this retries every second for as long as the session stays attached, and nothing is logged. Until it succeeds there is no follow fiber, so entry.selected isn't drained: model and mode switches made elsewhere stop producing config_option_update for this session. Could you cap the retries or back off, log the failure, and keep handling selection changes on the previous catalog until the destination loads?

@@ -0,0 +1,201 @@
# ACP Session Move Rebinding Implementation Plan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file and docs/superpowers/specs/2026-11-26-acp-session-move-design.md look like planning notes for this change and shouldn't be committed to the repository. Please drop both. The user-facing docs in acp.mdx are enough.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

acp: worktree rebind makes session permanently unloadable ("does not belong to cwd")

2 participants