Skip to content

fix(gateway): refuse stale session file saves after workspace replacement - #178331

Closed
HeZ2z wants to merge 3 commits into
openclaw:mainfrom
HeZ2z:fix/session-files-workspace-target
Closed

HeZ2z wants to merge 3 commits into
openclaw:mainfrom
HeZ2z:fix/session-files-workspace-target

Conversation

@HeZ2z

@HeZ2z HeZ2z commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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.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/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:

  1. Lookup root (P1). Relative paths resolve against the session's file lookup root (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.
  2. Recovery path (P2). Files-panel rows are addressed by an absolute path under the root they were listed in. After a same-chat workspace change, the workspace-changed notice's Reload reused that stale absolute path, which either failed once the old root was removed or re-read the old checkout instead of the replacement file.

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 opaque workspaceId; a save whose identity no longer matches is refused with session_file_conflict and details.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)

  • [P1] Include the file lookup root in the saved target identity — resolveFileWorkspaceTarget now takes the resolved fileRoot and binds it together with the worktree id and workspace root. New registered-handler regression: a cwd-only reset (spawnedWorkspaceDir and worktree id unchanged, spawnedCwd changed) with byte-identical files refuses both the plain stale hash and the old workspaceId, leaves replacement bytes unchanged, and a reopened read saves successfully.
  • [P2] Make workspace-change recovery reach the replacement file — Files-row tabs now retain their root-relative row path; Reload refreshes 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 in chat-session-workspace.test.ts.
  • Docs updated for the workspace-changed notice and recovery behavior.

Evidence

Handler-level regressions (in this PR; CI shards are authoritative)

  • src/gateway/server-methods/sessions-files.worktree.test.ts:
    • stale save after worktree replacement (byte-identical) refused; replacement bytes preserved; fresh token saves;
    • Overwrite recovery (fresh hash + old workspaceId) refused with reason: "workspace_changed"; genuine same-workspace overwrite still succeeds;
    • ordinary session root change; same worktree id with a new root;
    • new: cwd-only reset changes only the file lookup root — stale hash and stale identity refused, replacement bytes unchanged, fresh read/save succeeds.
  • ui/src/pages/chat/components/chat-session-workspace.test.ts: new Files-row recovery regression — after a workspace change, fetchLatest refreshes 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 canonical sessions.create parent-rollover route for agent:main:main, opened README.md in the shipped Files editor, retained a draft, and then performed a supported cwd-only reset of the same chat. Real sessions.files.get before/after showed the lookup root change (…/proof331-a → …/proof331-a/sub) with byte-identical content (plain SHA-256 f34848ca…c2ac) while the scoped hash (81ec2fe8… → 4baa4f2e…) and workspaceId (4bb5ab74… → c162ff16…) both changed. Screenshots and RPC captures: .openclaw/proof/178331/ (00–04, w1.json, w2.json, README.md).

At the parent head 9f06677 a full real-Gateway managed-worktree replacement was recorded: stale save refused, Overwrite recovery refused with reason: "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)

  • The isolated run could not keep a same-pane draft open through the reset: the current Control UI retires file previews when that pane receives the session-reset event, so the notice → Reload → fresh-save sequence is covered by the shipped-UI browser lane and the UI regression, not by a recording. A full managed-worktree replacement could not be driven through the same-key reset route in isolation (the reset preserves the checkout and refuses rebinding a second worktree name), so the browser evidence uses the supported cwd-only target change plus the parent-head replacement proof above.
  • Focused local Vitest could not complete on this shared build host (heavy concurrent jobs; the runner's worker-cache watchdog aborted both attempts). CI's changed-test shards are the authoritative run for the added regressions. oxlint, oxfmt --check, and git diff --check are clean on the touched files.
  • Latest-stable upgrade coverage for the optional protocol fields was not captured; the fields are additive and no stored data is migrated.

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), and users-personal-file.ts use their own compare tokens and could share the same stale-target shape if their root can be replaced; this PR fixes only the sessions.files owner named by the issue.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 20, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 20, 2026
…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.
@HeZ2z
HeZ2z force-pushed the fix/session-files-workspace-target branch from 4584d82 to 6b85e9f Compare October 20, 2026 10:28
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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
Relationship: superseded
Canonical: #178336
Summary: The merged canonical PR resolves the same managed-workspace stale-save defect reported by the linked issue.

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 details

Best 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:

  • Shakker: Raw commit c4ccdcb adds src/gateway/server-methods/sessions-files.ts:117 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c4ccdcb8b4d2; files: src/gateway/server-methods/sessions-files.ts)
  • Peter Steinberger: Raw commit 82667a6 adds src/gateway/server-methods/sessions-files.ts:353 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 82667a66e57a; files: src/gateway/server-methods/sessions-files.ts)

Codex review notes: model internal, reasoning medium; reviewed against bead2a8e5427; fix evidence: commit a44dc77340f8, main fix timestamp 2026-10-20T17:41:01Z.

@HeZ2z

HeZ2z commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Real Gateway proof — #178331 @ 6b85e9f

Verdict: 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, sessions.files.set with the pre-replacement hash is refused with session_file_conflict, the replacement file is unchanged, and the draft remains client-side. A fresh read then saves successfully.

But the reviewer's P2 is confirmed by execution, not fixed on this head: the shipped editor's Overwrite recovery is not refused. fetchLatest returns the replacement workspace's scoped hash, and Overwrite submits the old draft with it — the old draft is written into the replacement workspace.

Environment

  • Worktree wproof-178331, branch tmp-331, HEAD 6b85e9f72339a8ff1c1ea599faf54ec3d964eafa.
  • Build produced by the repo entry node scripts/run-node.mjs; dist/.buildstamp says "head":"6b85e9f72339a8ff1c1ea599faf54ec3d964eafa","inputsClean":true.
  • Isolated state: HOME=/tmp/proof331/home, OPENCLAW_STATE_DIR=/tmp/proof331/state, OPENCLAW_CONFIG_PATH=/tmp/proof331/state/openclaw.json; loopback token auth; no real provider credentials or model calls.
  • Gateway: node scripts/run-node.mjs gateway --port 54829 --bind loopback --compact; GET /health → {"ok":true,"status":"live"}.
  • RPC driver: the built product CLI, node dist/entry.js gateway call <method> --url ws://127.0.0.1:54829 --token <isolated-token> --json --params '<json>'. (scripts/run-node.mjs refuses runtime-artifact publication while a Gateway is running; the build it produced is the client used for the RPCs.)

Scenario and commands

Setup: source repo /tmp/proof331/workspace contains committed README.md = base\n (5 bytes, raw SHA-256 f34848ca92665c342abd5816c9e3eda0e82180671195362bcd0080544a3bc2ac), with a local bare origin so the old worktree is losslessly removable by the product.

call below is the exact CLI invocation above; payloads are exact.

  1. Create the main chat row:
call sessions.create '{"key":"agent:main:main","agentId":"main"}'
→ {"ok":true,"key":"agent:main:main","sessionId":"755f6408-5f5b-4320-9108-8c13385a83e3"}
  1. Same-chat reset via sessions.create with a managed worktree (the issue Files saves can overwrite a replacement workspace after a same-chat reset #178310 route):
call sessions.create '{"agentId":"main","parentSessionKey":"main","emitCommandHooks":true,"worktree":true,"worktreeName":"proof331-a"}'
→ {"ok":true,"key":"agent:main:main","worktree":{"id":"5897b4a0-cff2-44bb-a803-12e222742255",
   "path":"/private/tmp/proof331/state/worktrees/bbedd900a89e4a1b/proof331-a","branch":"openclaw/proof331-a"}}
  1. Open README.md through the real Files RPC:
call sessions.files.get '{"sessionKey":"agent:main:main","path":"README.md"}'
→ {"root":"/private/tmp/proof331/state/worktrees/bbedd900a89e4a1b/proof331-a",
   "file":{"content":"base\n","size":5,
           "hash":"eb4657054ecc42f80e0e747cdd64414dff3c2daca720f759d2a01a12ef8de181"}}

The editor holds this hash and the draft draft from the original workspace\n locally.

  1. Make the old worktree losslessly removable (the product deliberately retains unpushed worktrees):
git -C .../proof331-a push -q origin HEAD:refs/heads/openclaw/proof331-a
git -C .../proof331-a log HEAD --not --remotes --oneline | wc -l
→ 0
  1. Reset the chat to detach and remove that workspace:
call sessions.create '{"agentId":"main","parentSessionKey":"main","emitCommandHooks":true}'
→ {"ok":true,"key":"agent:main:main","entry":{...}}   # no spawnedCwd / sessionRoot / worktree fields
test -e .../proof331-a || echo "W1 removed"
→ W1 removed
  1. Create the replacement managed workspace for the same chat key:
call sessions.create '{"key":"agent:main:main","agentId":"main","worktree":true,"worktreeName":"proof331-b"}'
→ {"ok":true,"key":"agent:main:main","worktree":{"id":"f6d11490-9c8a-4319-abed-8f062849980a",
   "path":"/private/tmp/proof331/state/worktrees/bbedd900a89e4a1b/proof331-b","branch":"openclaw/proof331-b"}}
cat .../proof331-b/README.md
→ base

Both files are byte-identical (base\n, 5 bytes). The fresh read now returns a different token:

call sessions.files.get '{"sessionKey":"agent:main:main","path":"README.md"}'
→ {"root":".../proof331-b","file":{"content":"base\n",
   "hash":"ff9e987e0c6e8abe9b705aded7c8ee18721aaf978682260c19b397f6c4f7e9a7"}}
  1. Stale save with the hash taken before replacement:
call sessions.files.set '{"sessionKey":"agent:main:main","path":"README.md",
  "content":"draft from the original workspace\n",
  "expectedHash":"eb4657054ecc42f80e0e747cdd64414dff3c2daca720f759d2a01a12ef8de181"}'
→ {"ok":false,"error":{"code":"INVALID_REQUEST",
   "message":"session file changed since it was read",
   "details":{"type":"session_file_conflict","path":"README.md",
              "currentHash":"ff9e987e0c6e8abe9b705aded7c8ee18721aaf978682260c19b397f6c4f7e9a7"}}}
cat .../proof331-b/README.md
→ base

No disk mutation; the client still holds the draft. This is the fix working.

  1. Editor Overwrite recovery — same two calls the shipped editor makes (fetchLatest then save the captured local text with the fetched hash):
call sessions.files.get '{"sessionKey":"agent:main:main","path":"README.md"}'
→ {"file":{"content":"base\n","hash":"ff9e987e0c6e8abe9b705aded7c8ee18721aaf978682260c19b397f6c4f7e9a7"}}
call sessions.files.set '{"sessionKey":"agent:main:main","path":"README.md",
  "content":"draft from the original workspace\n",
  "expectedHash":"ff9e987e0c6e8abe9b705aded7c8ee18721aaf978682260c19b397f6c4f7e9a7"}'
→ {"sessionKey":"agent:main:main","root":".../proof331-b",
   "file":{"size":34,"kind":"modified",
           "hash":"27c25211a4fc185cfb92b335ec060ee7dedc45129d66e1292a22785c31454bfb"}}
cat .../proof331-b/README.md
→ draft from the original workspace

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.

  1. Reopen (fresh read) and save successfully:
call sessions.files.get '{"sessionKey":"agent:main:main","path":"README.md"}'
→ {"file":{"content":"draft from the original workspace\n",
           "hash":"27c25211a4fc185cfb92b335ec060ee7dedc45129d66e1292a22785c31454bfb"}}
call sessions.files.set '{"sessionKey":"agent:main:main","path":"README.md",
  "content":"reopened draft saved\n","expectedHash":"27c25211a4fc185cfb92b335ec060ee7dedc45129d66e1292a22785c31454bfb"}'
→ {"sessionKey":"agent:main:main","root":".../proof331-b",
   "file":{"size":21,"kind":"modified",
           "hash":"22179dac5a7c00ab92e3b3b3d4cd5d99ef843345f840a1a6b3f58f9e3323a60e"}}
cat .../proof331-b/README.md
→ reopened draft saved

Hash binding check

The returned tokens exactly match the head's formula sha256(worktreeId + "\0" + root + "\0" + bytes):

Target Scoped token Plain SHA-256 of bytes
W1 5897… @ .../proof331-a eb465705…d6f6 f34848ca…c2ac
W2 f6d1… @ .../proof331-b ff9e987e…e9a7 f34848ca…c2ac

Byte-identical content, different tokens because the workspace identity changed. This is precisely the PR's stated mechanism.

Gateway logs

2026-10-20T23:55:18.652+08:00 [agents/worktrees] worktree base origin/main at 1728ba43a8ada9ac18f1e90ab5e5807123e4c7b3 (commit age 0.0 days; fetch succeeded)
2026-10-20T23:55:19.055+08:00 [agents/worktrees] managed worktree preparation kind=managed template=cold ... outcome=returned durationMs=959 ...
2026-10-20T23:55:38.227+08:00 [agents/worktrees] worktree base origin/main at 1728ba43a8ada9ac18f1e90ab5e5807123e4c7b3 (commit age 0.0 days; fetch succeeded)
2026-10-20T23:55:39.047+08:00 [agents/worktrees] managed worktree preparation kind=managed template=warm ... outcome=returned durationMs=1012 ...
2026-10-20T23:55:44.339+08:00 [ws] ⇄ res ✗ sessions.files.set 3ms errorCode=INVALID_REQUEST errorMessage=session file changed since it was read bytes=300 ...

Boundary

  • Real: isolated Gateway process from the reviewed head; real managed worktree allocation/removal (not mocked); real session rows; real WebSocket operator RPCs; real filesystem reads/writes.
  • Not a browser Control UI run. The driver issues the same sessions.files.get / sessions.files.set payloads the shipped editor uses, and reproduces its fetchLatest → local-text save Overwrite sequence (ui/src/pages/chat/components/chat-detail-panel.tsx:472-503, ui/src/pages/chat/components/chat-session-workspace.ts:315-336). No rendered editor or screenshot is claimed.
  • No model/agent inference was used. The worktree branch was pushed to a local bare origin only so the reset could remove the old workspace losslessly; the product otherwise retains an unpushed worktree (retained-unpushed), and that path is unrelated to the save precondition.
  • This is head-only evidence. No base-commit run was performed here.
  • The required Overwrite-refusal behavior is absent on this head. The successful step 8 must not be read as satisfying that clause; it is the reproduction of the reviewer's P2 finding.

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.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: L and removed size: S labels Oct 20, 2026
@HeZ2z

HeZ2z commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Real Gateway proof — #178331 @ 9f06677

Verdict: At head 9f06677f9, the shipped editor's Overwrite recovery is refused after the same chat's managed workspace is replaced. All three requested assertions pass on the real product.

Environment

  • Worktree wproof2-178331, branch tmp-331c, HEAD 9f06677f926a7261b8a46d4c0904accea66e41f1.
  • Build: node --import ./scripts/tsx.mjs scripts/build-all.mts gatewayWatch → exit 0 (1m11.2s). dist/.buildstamp head 9f06677f…, inputsClean:true; CLI 2026.10.5.
  • Isolated HOME=/tmp/proof331b/home, OPENCLAW_STATE_DIR=/tmp/proof331b/state, OPENCLAW_CONFIG_PATH=…/openclaw.json; loopback token auth on port 63136; /health → {"ok":true,"status":"live"}.
  • Driver: node dist/entry.js gateway call <method> --url ws://127.0.0.1:63136 --token <token> --json --params '<json>'.

Scenario

Source repo README.md = base\n (5 bytes, plain SHA-256 f34848ca…c2ac), pushed to a local bare origin.

  1. sessions.create {"key":"agent:main:main","agentId":"main"} → sessionId 93fa09db-ffb0-444c-9720-1bded0dbea0d.
  2. Same chat, managed worktree: {"agentId":"main","parentSessionKey":"main","emitCommandHooks":true,"worktree":true,"worktreeName":"proof331b-a"} → W1 id 55b67fe5-f34c-4844-8770-6e8f1c6c1273, root /private/tmp/proof331b/state/worktrees/0c6639cf31a3a4cf/proof331b-a, branch openclaw/proof331b-a.
  3. sessions.files.get → base\n, hash 917e2738…e4a9, workspaceId f26d0df5…e7e6.
  4. Push W1 HEAD to the bare origin; unpushed commits = 0.
  5. Reset same key (sessions.create without worktree) → no worktree fields; W1 directory removed.
  6. Recreate W2 for agent:main:main (worktreeName":"proof331b-b") → id 7796b9ac-b5fd-4866-8253-4b80d068c118, root …/proof331b-b; README byte-identical base\n. Fresh get → hash 3c178206…968f, workspaceId 29f5ce15…4416.

Assertions (exact)

A — stale save with W1 hash, no workspaceId (expectedHash 917e…):
{"ok":false,"error":{"code":"INVALID_REQUEST","message":"session file changed since it was read","details":{"type":"session_file_conflict","path":"README.md","currentHash":"3c178206…968f"}}}. File stayed base\n.

B — Overwrite recovery: W1 workspaceId + fresh W2 hash + old draft (content":"draft from the original workspace\n", expectedHash 3c178206…968f, workspaceId f26d0df5…e7e6):
{"ok":false,"error":{"code":"INVALID_REQUEST","message":"session workspace changed since it was read","details":{"type":"session_file_conflict","path":"README.md","reason":"workspace_changed"}}}.
No write: README stayed base\n, 5 bytes, plain SHA-256 f34848ca…c2ac.

C — fresh read/save succeeds: fresh W2 get, then set fresh save after reopen\n with expectedHash 3c178206… and no workspaceId → ok, size 24, hash 2079a008…3f99.

C2 — genuine same-workspace overwrite: fresh get, then set same-workspace overwrite\n with expectedHash 2079a008… and matching workspaceId 29f5ce15…4416 → ok, size 25, hash 0df371f0…cbfb.

Identity binding: returned W2 workspaceId = sha256(worktreeId + "\0" + root) exactly; scoped hashes = sha256(worktreeId + "\0" + root + "\0" + bytes). Byte-identical files in W1/W2 produced different tokens.

Tests

node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server-methods/sessions-files.worktree.test.ts src/gateway/server-methods/sessions-files.test.ts → exit 0, 2 files passed; 49 passed | 1 skipped (50), 59.46s. Includes refuses the editor's overwrite recovery after the same chat replaces its worktree and refuses a stale save….

Boundary

  • Real: isolated Gateway process at the reviewed head; real managed worktree allocation/removal; real session rows; real WebSocket operator RPCs; real filesystem reads/writes. No mocks.
  • Not a browser Control UI run. The driver issues the same payloads the shipped editor makes. UI sequence confirmed at ui/src/pages/chat/components/chat-detail-panel.tsx:458-503 (Overwrite captures localWorkspaceId and the fetched hash; Reload adopts latest.workspaceId) and chat-session-workspace.ts:283-301.
  • No model/agent inference. The local bare origin exists only so the reset could losslessly remove W1. Head-only evidence; no base-commit run. Isolated state/processes cleaned; build left in dist. Artifacts: /tmp/proof331b-evidence-artifacts.

@clawsweeper re-review — current-head (9f06677) real isolated Gateway + WS RPC proof: stale save refused, Overwrite recovery across workspace replacement now refused with reason:"workspace_changed" (file unchanged, draft retained), fresh read/save and genuine same-workspace overwrite still succeed; owning gateway tests 49 passed/1 skipped. Boundary: RPC-level real product, editor payloads replicated from UI source.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 20, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
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.
@HeZ2z

HeZ2z commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper recorded closeout evidence for this proposed close.

  • Action: close remains subject to final live verification.
  • Close reason: duplicate or superseded.
    Review evidence: durable ClawSweeper review.
  • Coverage proof: The source report describes concrete merged behavior and regression coverage matching PR A's core intent, corroborated by PR B's current conversation. It identifies no remaining material work; scoped hashes and in-place Reload are alternative mechanisms. Covering PR: fix: prevent stale Files saves after workspace replacement #178336.

@clawsweeper clawsweeper Bot closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files saves can overwrite a replacement workspace after a same-chat reset

1 participant