Skip to content

fix(pi): resume at requested cwd when the session's directory was removed - #3099

Open
fgrehm wants to merge 1 commit into
get-bb:mainfrom
fgrehm:fix/pi-resume-stale-session-cwd
Open

fix(pi): resume at requested cwd when the session's directory was removed#3099
fgrehm wants to merge 1 commit into
get-bb:mainfrom
fgrehm:fix/pi-resume-stale-session-cwd

Conversation

@fgrehm

@fgrehm fgrehm commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Human comments

Similar to the other PR I just opened, this almost drove me nuts 😅 I'm now rebuilding my container with both patches and will report back if anything goes wrong.

What was wrong

When update_environment_directory moved a thread to a new environment (e.g. the agent deleted the old worktree first), the next turn died at the bridge: thread/resume rejected with Cannot resume: the pi session's working directory "...no longer exists." because the pi session file still recorded the old cwd — even though the runtime supplied a valid, existing requested cwd. In the observed case the thread was effectively bricked until an external stop/recovery.

Root cause: resumedSessionMissingCwd (plugins/provider-pi/src/bridge/bridge.ts:532) rejects the whole resume whenever the persisted cwd is gone, without considering the requested cwd.

What changed

  • thread/resume now only rejects when the requested cwd is also missing — i.e. there is genuinely nowhere to run. With the persisted cwd gone but a valid requested cwd present, resume proceeds.
  • constructPiThreadSession prefers the persisted session cwd only when the directory still exists (new usablePersistedSessionCwd()), falling back to the requested cwd for the child spawn and delta-translation sessionCwd. When the persisted cwd still exists, behavior is unchanged (session reports the header cwd).
  • No wire/protocol changes; provider-bridge-only. No CLI/guide/doc updates needed.

How you verified

  • New regression test resumes at bb's requested cwd when the session header's cwd was removed (bridge.round2.test.ts): red before the fix (reproduced the exact user error text), green after.
  • Existing a resumed thread reports the session header's cwd, not the cwd bb asked for still passes — persisted-cwd precedence preserved when the dir exists.
  • bridge.round2 + bridge.settings + bridge.checkpoint-fork: 15/15 pass. turbo run typecheck --filter=bb-plugin-provider-pi: clean.

AGENT GENERATED
Generated with "Omen Alpha" (Opencode Go) via BB / Pi

@fgrehm fgrehm changed the title fix(pi): resume at requested cwd when the session's directory was rem… fix(pi): resume at requested cwd when the session's directory was removed Sep 4, 2026
…oved

thread/resume rejected the whole turn when the pi session header's cwd
no longer exists, even when bb already moved the thread to a new
environment directory and supplied an existing requested cwd. That is
what bricked the follow-up turn after update_environment_directory
removed the old worktree.

Only reject when the requested cwd is also missing; the session cwd now
falls back to the requested cwd when the persisted one is gone. Prefer
the persisted cwd as before when it still exists.

Adds a regression test covering the removed-worktree resume.
@fgrehm
fgrehm force-pushed the fix/pi-resume-stale-session-cwd branch from 6c297c4 to bc4d6af Compare September 5, 2026 03:05
@fgrehm
fgrehm marked this pull request as ready for review September 6, 2026 15:33
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.

1 participant