fix(sessions): guard continueRecent/list against cwd collisions in shared session dir#96881
fix(sessions): guard continueRecent/list against cwd collisions in shared session dir#96881moguangyu5-design wants to merge 2 commits into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. This PR is now superseded: current main already has the same compatibility-preserving cwd-aware session resume/list fix from the merged canonical branch, and this branch only reworks the same two files with alternate helper shape and duplicate coverage. Canonical path: Keep the current-main implementation from #97785 and close this duplicate branch; any further session-collision work should be a narrow follow-up against current main. So I’m closing this here and keeping the remaining discussion on #97785. Review detailsBest possible solution: Keep the current-main implementation from #97785 and close this duplicate branch; any further session-collision work should be a narrow follow-up against current main. Do we have a high-confidence way to reproduce the issue? No, current main no longer reproduces the bug: the session manager now filters recent-session lookup and project-scoped list results by exact header cwd. The latest release still has the old behavior, so this is fixed on main but not yet shipped in Is this the best way to solve the issue? No, this PR is no longer the best way to solve the issue because #97785 already merged the same compatibility-preserving fix with real on-disk proof. The best path is to keep that implementation and avoid landing duplicate session-selection changes. Security review: Security review cleared: The diff only changes local JSONL session-header parsing/filtering and tests; it adds no dependencies, workflow changes, secret handling, downloads, or new code-execution paths. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against fc5ba0e58bb4; fix evidence: commit e2dd5a0309a3, main fix timestamp 2026-06-30T17:46:40-07:00. |
|
I think the cwd-less fallback in this PR needs either a cited shipped-state reason or removal. Two-lens read:
If there is a real legacy state this preserves, please cite the version/path and add a regression test showing why those files should match every cwd. Otherwise, I think the cwd-scoped paths should require a string header cwd matching the requested cwd, leaving cwd-less/malformed files discoverable only through explicit open/list-all style flows rather than project-scoped resume/list. |
|
@harjothkhara Good catch. I removed the cwd-less fallback entirely.
You are right that shipped headers (v2026.5.28, v2026.6.10) always record |
|
Real behavior proof for the cwd-collision fix. I verified the regression tests reproduce the bug on Repro steps
Before the fix (on
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
b2fd3aa to
a7eced0
Compare
|
ClawSweeper applied the proposed close for this PR.
|
Closes #96542
What Problem This Solves
getDefaultSessionDirencodes the cwd by replacing path separators (/,\\,:) with-, which is not injective. Two genuinely different project directories such as/home/alice/dev/client/appand/home/alice/dev/client-appcollapse to the same session directory.When
SessionManager.continueRecentorSessionManager.listlater reads that directory, it used to pick the newest file by mtime without checking the cwd stored in the session header. As a result, resuming a session from one project could silently load the conversation from the other project, carrying unrelated history into the current working directory.Why This Change Was Made
findMostRecentSessionnow parses the session header and filters bycwd.SessionManager.continueRecentpasses the requestedcwdtofindMostRecentSession, so it only resumes a session whose header cwd matches the current project.SessionManager.listfilters its results by the requestedcwdas well, so listing sessions for a colliding directory only returns sessions that belong to the requested project.cwdmatch; cwd-less/malformed files are not silently adopted as belonging to an arbitrary project. Shipped session headers (e.g. v2026.5.28, v2026.6.10) always recordcwd, so no compatibility fallback is needed.User Impact
Users working in directories whose paths differ only by a path separator are no longer at risk of
continueresuming the wrong project's conversation. The fix is fully backward-compatible with existing session files that have a recordedcwd.Evidence
Added regression tests in
src/agents/sessions/session-manager.test.tsthat reproduce the collision and the wrong-project resume:getDefaultSessionDir("/home/alice/dev/client/app")andgetDefaultSessionDir("/home/alice/dev/client-app")currently map to the same directory.client-appstrictly newer, and verified thatcontinueRecent(cwdA)now resumes theclient/appsession instead of the newerclient-appsession.SessionManager.list(cwdA)andSessionManager.list(cwdB)each return only their own session.Local verification:
All passed.