fix: make session file roots backend-authoritative, never trust client cwd - #70
Merged
Conversation
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.
Problem
The remote file browser sometimes rooted a session at the filesystem
root (
/) instead of the project directory — reproducibly once twosessions were active (session switching races the App's 4s instance-list
poll).
Root cause chain (verified live — a hub instance was advertising
workspace: "/"):session/load's cwd from the hub instance list andfell back to "/" whenever that list was stale;
loadSession/resumeSessionblindly recorded theclient's cwd into
sessionCwds— the value the/fsendpoint scopesfile access to;
projectCwd()returned the firstsessionCwdsentry, so onepolluted "/" hijacked the instance's advertised workspace and every
later remote load inherited it.
Fix — the client no longer decides the file scope
session/load·resumeignore theclient cwd. The root comes from what the bridge recorded at creation,
corrected by the backend's own
session/resumeresult(
session.workspace.workspacePath). This also self-healspreviously-polluted entries on the next load.
session/newstill trusts the editor'sworktree (creation semantics); "/" is rejected everywhere as a
degenerate root.
or after realpath) is refused with 403 — a polluted record can never
widen remote access to the whole filesystem.
projectCwd(): most-recently-active session's cwd, skipping "/"entries — the advertised workspace can no longer be poisoned by one
bad entry.
Companion App fix (zcode-acp-app): stop sending the "/" fallback — omit
cwd when the instance list doesn't know the instance.
Testing
tests/session-cwd.test.ts(9 cases): client cwd ignored (evenplausible paths), backend workspace adoption, polluted-entry healing,
already-live root retention, creation-time cwd guard, projectCwd
recency + "/" skipping.
/fsroot-"/" refusal case intests/remote-file-endpoint.test.ts.