fix(coding-agent): preserve saved cwd on daemon resume - #1128
Open
aoright wants to merge 1 commit into
Open
Conversation
MingTeer
approved these changes
Aug 13, 2026
MingTeer
left a comment
There was a problem hiding this comment.
Verified the fix end-to-end on our fork (17 commits behind upstream/main). Traced the full path and it closes the loop:
- Bug: the supervisor merges
defaultSessionConfig.cwdinto the forwardedcommand.config, so the worker'scwdOverride = command.config?.cwdis always set, andSessionManager.openAsync(sessionPath, dir, cwdOverride)lets it override the header cwd. Resumed sessions silently run in the daemon launch directory. - Fix: deleting
config.cwdwhensessionPathis set and the client sent no explicit cwd makescwdOverrideundefined, so the header cwd wins; runtime cwd then comes fromsessionManager.getCwd(). The worker-sideif (!config.cwd) throwis unaffected since the worker re-merges with its own defaults.mergeAgentSessionRuntimeConfigalways returns a fresh object, so thedeletecan't pollute shared config. Scope is correctly limited to resume-without-explicit-cwd; new sessions and--cwdbehave as before. - A/B check: the regression test fails against the pre-fix
daemon-supervisor.tsand passes with the fix.
One non-blocking note on the test: it spreads ...process.env into the spawned supervisor. When run from inside a prime-agent session (e.g. via the IPython tool or a tmux pane), PRIME_AGENT_INTERNAL_DAEMON_WORKER and friends leak in, the spawned process identifies as a worker instead of a supervisor, and the handshake times out. Scrubbing PRIME_AGENT_INTERNAL_* from the test env would make it more portable.
We cherry-picked this onto our fork because the silent wrong-directory behavior writes into the wrong repository. Hope it lands upstream.
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.
Summary
cwdwhen the supervisor forwards a saved-session create to its worker, soSessionManager.openAsyncuses the cwd recorded in the session header.This is a backward-compatible behavior fix; the daemon wire shape and schema are unchanged.
Testing
npx tsx ../../node_modules/vitest/dist/cli.js --run test/suite/regressions/1124-resume-recorded-cwd.test.tsnpm run checkFixes #1124
Note
Fix resumed daemon sessions to use saved working directory instead of daemon launch directory
When resuming a session from a
sessionPath, the spawned worker process was starting in the daemon's launch directory instead of the session's recordedcwd. The fix introducesprepareWorkerLaunchindaemon-supervisor.ts, which stripscwdfrom the config for resumed sessions and passes it directly to the spawn options instead. A regression test in1124-resume-recorded-cwd.test.tsverifies the correct directory is used.Macroscope summarized 88eb3be.