Repository navigation
Conversation
One daemon serves sessions for many projects. A client-reported `working_dir`
describes the project that *client* is sitting in, not the project its target
session belongs to, but both the resume path and the subscribe path treated it
as authoritative. Attaching to a session from another project therefore moved
that session's bash and file tools, its project-local MCP config, its memory
scope, and its swarm grouping into the attaching client's tree, while the header
still showed the original project.
A client's directory is now creation-only, mirroring the rule the request
handler already applied to system prompts ("never apply an override to a target
attachment") and which had never been applied to `working_dir`.
`session_working_dir_for_client` decides it in one place: an existing session
directory always wins, a session with none adopts the reported directory only
while it is being created, and a session that stays unattributed stays
unattributed rather than falling back to the daemon's cwd. Deliberately moving a
session to another project needs an explicit request, which the wire protocol
does not have; the only three requests carrying a `working_dir` (Subscribe,
CommSpawn, spawn-agent) all either create a session or attach to one.
All four writers reachable from a single attach now read one resolved answer
instead of resolving separately, which is what made the agent and its MCP config
disagree:
- `handle_resume_session` resolves `bound_working_dir` once, from the live
target's agent or the on-disk copy, and feeds both the restored session and
`mcp_working_dir`. It reads the live agent with `try_lock`: a generating
target owns that lock, and awaiting it would deadlock the attach.
- `apply_or_defer_subscribe_working_dir` applies the rule in both branches,
including the deferred one that runs for a busy agent, where the guard would
otherwise lapse mid-turn.
- The swarm re-key is computed after the same rule, so membership cannot be
grouped under the attaching client's project while the session's own tools run
in its own.
- The `session_working_dir_for_client` unit test covers each arm, and the
pre-existing test that asserted a project-to-project move was honored now
asserts the opposite contract: such a report is refused, and a session with no
directory yet still adopts one at creation.
`canonicalize_or` in `server::util` is shared instead of duplicating, so resume
and resume-all cannot drift on what counts as the same project.
Tests: `cross_project_attach_preserves_target_session_working_dir` covers the
live-target attach (agent directory, post-subscribe directory, swarm member, and
the on-disk copy), and
`cross_project_attach_of_offline_session_preserves_its_working_dir` covers the
restore-from-disk path, which is the only one that binds a directory. Each was
confirmed to fail with its own guard disabled.
…s branch The cherry-pick brought `working_dir_in_scope` across, but upstream has no resume-all project scoping any more, so nothing calls it. Removing it keeps this PR to the subscribe and resume attach paths it is actually about. `cross_project_attach.rs` only needs `crate::session::Session`.
…ject's session One daemon serves sessions for many projects. A client-reported `working_dir` describes the project that *client* is sitting in, not the project its target session belongs to, but the resume and subscribe paths both treated it as authoritative. A client in project A attaching to a session stored under project B therefore moved B's bash and file tools, its project-local MCP config, its memory scope and its swarm grouping into A's tree, while the header still showed the original project. `session_working_dir_for_client` now decides it in one place: an existing session directory always wins, a session with none adopts the reported directory only while it is being created, and a session that stays unattributed stays unattributed rather than falling back to the daemon's cwd. Deliberately moving a session to another project needs an explicit request the wire protocol does not have; the only three requests carrying a `working_dir` (Subscribe, CommSpawn, spawn-agent) all either create a session or attach to one. `handle_resume_session` resolves `bound_working_dir` once and feeds both the restored session and `mcp_working_dir`, which is what let the agent and its MCP config disagree. It reads the live target through `try_lock`: a generating target owns that lock and awaiting it would deadlock the attach. A refused lock reads the on-disk session stub rather than being swallowed, because a refused lock is not the same fact as a session having no directory, and reading it as one is what handed the attaching client's directory to a busy session. The policy lives in `subscribe_working_dir_policy.rs` so `client_session.rs` does not grow past its tracked code-size budget. Regression tests cover both attach paths. Reverting the guard makes `resume_preserves_target_working_dir_on_cross_project_attach`, `cross_project_attach_preserves_target_session_working_dir` and `cross_project_attach_of_offline_session_preserves_its_working_dir` fail on their own assertions, each reporting the subscriber's directory against the session's. Verified: all seven budget gates, the 14 isolation tests, `cargo check -p jcode-app-core --tests`, `cargo fmt --check`.
Contributor
|
…h and reconnect - Resolve established directory from persisted stub or member state when live agent lock is busy (issue 1) - Unify authoritative session directory for agent, swarm member, and MCP registration across repeated subscribes (issue 2) - Pass explicit creation context to preserve unattributed working directory on attach/reconnect (issue 3) - Add regression tests covering busy attach, repeated subscribe, and unattributed reconnect
xenking
added a commit
to xenking/jcode
that referenced
this pull request
Nov 22, 2026
Use the target session root for Subscribe and ResumeSession. A client cwd can initialize a new session but cannot override a restored or live target, including its project-local MCP scope. Upstream: 1jehuang#1733 Co-authored-by: Cristiano Martini Bergamo <[email protected]>
xenking
added a commit
to xenking/jcode
that referenced
this pull request
Nov 22, 2026
Upstream-PR: 1jehuang#1357 Upstream-PR-Commit: 1jehuang#1357 0da5e81 Upstream-PR: 1jehuang#1362 Upstream-PR-Commit: 1jehuang#1362 5962058 Upstream-PR: 1jehuang#1486 Upstream-PR-Commit: 1jehuang#1486 fadc624 Upstream-PR: 1jehuang#1733 Upstream-PR-Commit: 1jehuang#1733 01f3415 Upstream-PR: 1jehuang#1750 Upstream-PR-Commit: 1jehuang#1750 1ac0c82 Upstream-PR: 1jehuang#1822 Upstream-PR-Commit: 1jehuang#1822 73f85fc Upstream-PR: 1jehuang#1912 Upstream-PR-Commit: 1jehuang#1912 36d7682 Upstream-PR: 1jehuang#1978 Upstream-PR-Commit: 1jehuang#1978 0f55643 Upstream-PR: 1jehuang#2007 Upstream-PR-Commit: 1jehuang#2007 638f87c Upstream-PR: 1jehuang#2213 Upstream-PR-Commit: 1jehuang#2213 c5e1487 Upstream-PR: 1jehuang#2234 Upstream-PR-Commit: 1jehuang#2234 0d4d5d4 Upstream-PR: 1jehuang#2266 Upstream-PR-Commit: 1jehuang#2266 217ddc2 Upstream-PR: 1jehuang#2267 Upstream-PR-Commit: 1jehuang#2267 e98c40b
This branch has not been deployed
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.
One daemon serves sessions for many projects. A client-reported
working_dirdescribes the project that client is sitting in, not the project its target session belongs to, but the resume and subscribe paths both treated it as authoritative. A client in project A attaching to a session stored under project B therefore moved B's bash and file tools, its project-local MCP config, its memory scope and its swarm grouping into A's tree, while the header still showed the original project.session_working_dir_for_clientnow decides it in one place: an existing session directory always wins, a session with none adopts the reported directory only while it is being created, and a session that stays unattributed stays unattributed rather than falling back to the daemon's cwd. Deliberately moving a session to another project needs an explicit request the wire protocol does not have; the only three requests carrying aworking_dir(Subscribe, CommSpawn, spawn-agent) all either create a session or attach to one.handle_resume_sessionresolvesbound_working_dironce and feeds both the restored session andmcp_working_dir, which is what let the agent and its MCP config disagree. It reads the live target throughtry_lock: a generating target owns that lock and awaiting it would deadlock the attach. A refused lock reads the on-disk session stub rather than being swallowed, because a refused lock is not the same fact as a session having no directory, and reading it as one is what handed the attaching client's directory to a busy session.The policy lives in
subscribe_working_dir_policy.rssoclient_session.rsdoes not grow past its tracked code-size budget.Regression tests
Three new tests cover both attach paths. Reverting the guard makes each fail on its own assertion, reporting the subscriber's directory against the session's:
resume_preserves_target_working_dir_on_cross_project_attachcross_project_attach_preserves_target_session_working_dircross_project_attach_of_offline_session_preserves_its_working_dirVerification
cargo check -p jcode-app-core --tests,cargo fmt --check