fix(pi): resume at requested cwd when the session's directory was removed - #3099
Open
fgrehm wants to merge 1 commit into
Open
fix(pi): resume at requested cwd when the session's directory was removed#3099fgrehm wants to merge 1 commit into
fgrehm wants to merge 1 commit into
Conversation
…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
force-pushed
the
fix/pi-resume-stale-session-cwd
branch
from
September 5, 2026 03:05
6c297c4 to
bc4d6af
Compare
fgrehm
marked this pull request as ready for review
September 6, 2026 15:33
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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_directorymoved a thread to a new environment (e.g. the agent deleted the old worktree first), the next turn died at the bridge:thread/resumerejected withCannot 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/resumenow 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.constructPiThreadSessionprefers the persisted session cwd only when the directory still exists (newusablePersistedSessionCwd()), falling back to the requested cwd for the child spawn and delta-translationsessionCwd. When the persisted cwd still exists, behavior is unchanged (session reports the header cwd).How you verified
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.a resumed thread reports the session header's cwd, not the cwd bb asked forstill 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.