Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…ment `sessions.files.get` returned a plain SHA-256 of the file bytes as the compare-and-swap token, and `sessions.files.set` compared only that hash against the current file. The handler resolves the chat key to the current session row, so after a reset/recreate it targets the replacement managed workspace; identical relative paths and byte-identical content produced the same token and the stale save matched. Bind the managed worktree identity and its resolved root into the existing 64-hex CAS token for managed sessions. Non-managed sessions keep the plain content hash and the token stays an opaque 64-hex string, so no protocol or client contract changes. `sessions.files.list` returns metadata without a hash, so no other response needs the scoped token.
4584d82 to
6b85e9f
Compare
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close this PR as superseded by #178336, whose merged implementation covers the reported managed-workspace replacement bug, changed lookup roots, retained drafts, and recovery through Files. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Use the merged source-precondition implementation and close this competing fix. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Use the merged source-precondition implementation and close this competing fix. Do we have a high-confidence way to reproduce the issue? The original failure is supported by the linked report and contributor RPC traces; current-main source and regression tests now guard the reported managed-workspace path, and no target code was executed during this review. Is this the best way to solve the issue? The merged fix uses the existing save guard and source descriptor to solve the central problem; this PR's scoped hashes and in-place Reload are alternative mechanisms rather than required remaining work. Security review: Security review cleared: The target identity supplements existing authorization and does not grant access or select a filesystem root. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning medium; reviewed against bead2a8e5427; fix evidence: commit a44dc77340f8, main fix timestamp 2026-10-20T17:41:01Z. |
Real Gateway proof — #178331 @ 6b85e9fVerdict: The scoped-hash fix is real and works for the initial stale save. After the same chat's managed workspace is replaced with byte-identical content, But the reviewer's P2 is confirmed by execution, not fixed on this head: the shipped editor's Overwrite recovery is not refused. Environment
Scenario and commandsSetup: source repo
The editor holds this hash and the draft
Both files are byte-identical (
No disk mutation; the client still holds the draft. This is the fix working.
This is the P2: the replacement workspace received the draft that was written against the previous workspace. There is no workspace-change refusal and no distinct UI state; the conflict code is the ordinary content-conflict code.
Hash binding checkThe returned tokens exactly match the head's formula
Byte-identical content, different tokens because the workspace identity changed. This is precisely the PR's stated mechanism. Gateway logsBoundary
|
The managed-workspace CAS token refused a stale save that reused the original hash, but the editor's Overwrite recovery first calls `fetchLatest` and then submits that fresh hash with the old draft. The content check passes, so the previous workspace's draft still lands in its replacement. Bind the read-time workspace target to the draft. `sessions.files.get` now returns an opaque `workspaceId` for the resolved local target (the managed worktree id plus root, or an ordinary session's root). `sessions.files.set` accepts it as an additive optional field and refuses a mismatch with the existing `session_file_conflict` error plus `details.reason: "workspace_changed"`, even when the replacement holds byte-identical content. The Control UI keeps the identity with the saved buffer and the retained draft, sends it on save, and preserves it through Overwrite recovery while adopting the fetched target only on Reload. A workspace-change refusal keeps the draft and offers Reload alone; ordinary same-target content conflicts still offer Overwrite. Fresh reads and same-workspace overwrites are unchanged, and callers that omit the new field keep the previous hash-only behavior. The edit/draft state moves to `chat-file-edit-state.ts` so the detail panel stays within its size limit. Tests: `sessions-files.worktree.test.ts` adds real registered-handler cases for same-workspace Overwrite, replacement-workspace Overwrite refusal with the replacement file unchanged, and a fresh read/save. A second case covers an ordinary session whose root changed with byte-identical content, so the plain hash still matches. UI tests keep the draft on a workspace-change refusal, offer no Overwrite action, and adopt the new target after Reload.
Real Gateway proof — #178331 @ 9f06677Verdict: At head Environment
ScenarioSource repo README.md =
Assertions (exact)A — stale save with W1 hash, no workspaceId ( B — Overwrite recovery: W1 workspaceId + fresh W2 hash + old draft ( C — fresh read/save succeeds: fresh W2 get, then set C2 — genuine same-workspace overwrite: fresh get, then set Identity binding: returned W2 workspaceId = Tests
Boundary
@clawsweeper re-review — current-head (9f06677) real isolated Gateway + WS RPC proof: stale save refused, Overwrite recovery across workspace replacement now refused with |
|
🦞👀 Re-review progress:
|
A cwd-only reset can keep the managed workspace root and worktree id while changing the directory relative file paths resolve against. Include the resolved file root in the saved target identity so a stale draft is refused with session_file_conflict/workspace_changed instead of writing into the replacement directory. Editor recovery now re-anchors Files-row tabs to the replacement workspace: Reload refreshes the current listing, rebuilds the same root-relative row under the current root, and keeps the old draft protected until that read succeeds. Overwrite recovery still cannot retarget a draft, and Reload no longer reuses the replaced workspace's stale absolute path.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
ClawSweeper recorded closeout evidence for this proposed close.
|
Closes #178310
AI-assisted: yes. The patch was authored by an AI coding agent and every command below was executed in this checkout.
What Problem This Solves
A stale editor save can overwrite a replacement managed workspace.
sessions.files.getreturned a plain SHA-256 of the file bytes as the compare-and-swap token, andsessions.files.setcompared only that hash against the current file. The handler resolves the chat key to the current session row, so after a reset/replacement it targets the replacement worktree; the same relative path and identical bytes produced the same token and the stale save matched.The same bug has two more shapes, both addressed here:
spawnedCwd), which can change while the managed workspace root and worktree id survive a cwd-only reset. Binding only the worktree id and root left the token identical for a different target directory.Why This Change Was Made
The 64-hex CAS token now binds the read-time workspace target: worktree id + resolved workspace root + resolved file lookup root (
session-file-workspace-target.ts). Reads return that identity as an opaqueworkspaceId; a save whose identity no longer matches is refused withsession_file_conflictanddetails.reason: "workspace_changed"even when replacement bytes are identical. No new token format, config, or schema migration: the token stays an opaque 64-hex string, the protocol fields are optional additions, and non-managed sessions keep hash-only checks when they omit the identity.The shipped editor keeps the draft on that refusal and offers only Reload (no Overwrite), so ordinary conflict recovery cannot retarget the draft. Reload now refreshes the current Files listing, re-anchors the same root-relative row beneath the replacement root, adopts it only after a successful read, and then saves normally (
chat-session-workspace.ts,chat-file-edit-state.ts,chat-detail-panel.tsx). A failed recovery keeps the old path and the draft protected.User Impact
An editor opened before a chat reset can no longer overwrite a replacement workspace. The stale save is refused, the replacement file is preserved, and a fresh read/reload produces a new token so the user can edit and save normally. Same-target content conflicts keep the existing Reload/Overwrite behavior.
Review findings addressed (review at
9f06677)resolveFileWorkspaceTargetnow takes the resolvedfileRootand binds it together with the worktree id and workspace root. New registered-handler regression: a cwd-only reset (spawnedWorkspaceDirand worktree id unchanged,spawnedCwdchanged) with byte-identical files refuses both the plain stale hash and the oldworkspaceId, leaves replacement bytes unchanged, and a reopened read saves successfully.sessions.files.list, rebuilds the request path from the current root, and only re-points later saves and downloads after that read succeeds. New regression inchat-session-workspace.test.ts.Evidence
Handler-level regressions (in this PR; CI shards are authoritative)
src/gateway/server-methods/sessions-files.worktree.test.ts:reason: "workspace_changed"; genuine same-workspace overwrite still succeeds;ui/src/pages/chat/components/chat-session-workspace.test.ts: new Files-row recovery regression — after a workspace change,fetchLatestrefreshes the listing, re-anchors the absolute row to the new root, and the follow-up save targets the replacement path.ui/src/pages/chat/components/chat-sidebar-file-view.browser.test.ts: shipped editor lane for the workspace-changed notice, retained draft, absence of Overwrite, Reload, and a fresh save.Real Gateway + Control UI at this head (partial browser evidence)
An isolated real Gateway built from this head served the Control UI built from this head's
ui/source. A real Chromium run created a real managed worktree through the canonicalsessions.createparent-rollover route foragent:main:main, openedREADME.mdin the shipped Files editor, retained a draft, and then performed a supported cwd-only reset of the same chat. Realsessions.files.getbefore/after showed the lookup root change (…/proof331-a→…/proof331-a/sub) with byte-identical content (plain SHA-256f34848ca…c2ac) while the scoped hash (81ec2fe8…→4baa4f2e…) andworkspaceId(4bb5ab74…→c162ff16…) both changed. Screenshots and RPC captures:.openclaw/proof/178331/(00–04,w1.json,w2.json,README.md).At the parent head
9f06677a full real-Gateway managed-worktree replacement was recorded: stale save refused, Overwrite recovery refused withreason: "workspace_changed", replacement bytes unchanged, fresh read/save and a genuine same-workspace overwrite both succeed (proof comment). This commit narrows the identity and changes the editor recovery; those gateway owner paths are otherwise unchanged.Limits of this evidence (stated plainly)
oxlint,oxfmt --check, andgit diff --checkare clean on the touched files.Proof boundary. Real registered handlers, real session store, real managed workspace lifecycle, real Gateway process, and the built Control UI. Nothing below is a mock of the file-writing or workspace-selection owners.
Related owners (not widened here)
agents-files.ts,mcp-app-host-files.ts(ifMatch),claws-drafts.ts(expectedRevision), andusers-personal-file.tsuse their own compare tokens and could share the same stale-target shape if their root can be replaced; this PR fixes only thesessions.filesowner named by the issue.