Repository navigation
fix(gateway): preserve concurrent agent workspace file edits - #135865
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. |
|
Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 1:42 AM ET / 05:42 UTC (Revision 5). ClawSweeper reviewWhat this changesAdds conditional agent workspace-file saves and explicit Reload/Overwrite recovery, preserving draft ancestry through Refresh and Reset. Merge readiness✅ Ready for maintainer review This repair remains necessary: current main still permits stale agent-file saves. The earlier findings are resolved, the supplied real-Gateway evidence covers the repaired behavior, and no blocking defect was found. Priority: P1 Review scores
Verification
How this fits togetherThe Control UI edits agent instructions and memory files through Gateway file RPCs. The Gateway compares the editor’s content hash with disk contents before publishing a save through the shared workspace update queue. flowchart TD
A[Control UI draft and hash] --> B[Agent file save request]
C[Session file saves] --> D[Shared workspace update queue]
B --> D
D --> E{Current hash matches?}
E -->|Yes| F[Write workspace file]
E -->|No| G[Keep draft and show conflict]
G --> H[Reload or explicit Overwrite]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +257, Tests +494, Docs 0, Other +8. Total +759 across 18 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep conditional saves at the shared write boundary and pair each editor draft with its matching hash, with explicit conflict recovery and unchanged legacy RPC behavior. Do we have a high-confidence way to reproduce the issue? Yes: open a file, change it through another writer, then save the original draft. Current-main source still permits the overwrite, and the supplied earlier-main runtime trace demonstrates it; this review did not execute current main. Is this the best way to solve the issue? Yes: reusing the existing write queue and carrying draft hashes fixes the reported stale-save path without changing file formats or legacy client semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b04a3f83adad. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
75e7b59 to
82fdee3
Compare
|
Refreshed against current main. Both P1 findings from the 75e7b59f1b80 review are fixed in the diff, each with its own regression case and its own before/after trace in the body. [P1] Serialize the hash check with the agent-file write. Fixed at the boundary you named. [P1] Prevent conflict reload from authorizing the stale draft. Fixed. The forced reload that refreshed the base hash while keeping the draft is removed. A refused write keeps the hash it was refused against, so a repeated Save is refused again rather than winning. Resolution is now explicit: the conflict callout offers Reload (take the workspace version, drop the draft) and Overwrite (re-read the current hash, then deliberately replace the workspace version), the same two-button contract Real Control UI proof. Added. The body carries a trace from real headless Chromium driving the real Control UI bundle against a real Gateway on a loopback port and a real agent workspace on disk, run on pristine main 82a74b1 and on this head with identical inputs. On main the Save lands silently and the agent's appended line is erased; here the Save is refused, the callout names the file and offers Reload and Overwrite, and a second click leaves the workspace bytes untouched. The three merge-risk items map onto the two findings and the proof above. One gap left open deliberately, stated in the body: a file that does not exist yet has no base token to send, so an operator Save that creates a bootstrap file can still race an agent creating the same file first. Closing that needs an New head: 82fdee3d9d857ef7b7ca38d7de633a3c4646b0bc. |
…iles changed since they were read The Control UI Agents Files editor saved whatever it held through agents.files.set, which wrote unconditionally. When the agent had appended memories to MEMORY.md (or any bootstrap file) after the operator opened it, Save replaced the file with the stale draft and reported ok. agents.files.get and agents.files.set now return the file's SHA-256 content hash, the same token sessions.files.set already uses. agents.files.set accepts an optional expectedHash and refuses the write with an agent_file_conflict error carrying currentHash when the on-disk hash differs. The compare and the write run inside the workspace update queue that already owns sessions.files.set, so two concurrent saves holding the same base hash cannot both be admitted. Omitting expectedHash keeps the unconditional overwrite for older clients. The Control UI sends the hash it last read. A refused write keeps that hash, so pressing Save again cannot win by accident; the conflict callout offers Reload and Overwrite, the same explicit resolution the session file editor already uses. Swift protocol models regenerated; the Kotlin output is unchanged.
82fdee3 to
3c4f936
Compare
|
The round-2 finding was correct and is fixed. New head: 3c4f936, rebased onto 4e33055. [P1] Preserve the dirty draft's base hash across Refresh. The stored hash is now the draft's write precondition rather than the base's. It advances only when the draft advances with it: on a write, on an explicit Reload or Overwrite, or on a read that rebases a clean draft. Coverage added in Live reproduction of the finding, and of the fix. The same browser driver ran unchanged against three trees. On 82fdee3d9d85 the two Saves were refused as intended, then Refresh-then-Save wrote One note on gates: the whole-graph Still open and deliberate, unchanged from the last round: a file that does not exist yet has no base token, so an operator Save that creates a bootstrap file can still race an agent creating the same file first. Closing that needs an |
Merge the pinned main integration while retaining the conditional-save contributor change. Pair refreshed text and hash on Reset, fence Overwrite after its read, and normalize schema-valid hash case at the agent write boundary.
|
landpr-approve-unrelated-red |
|
Thanks @yetval! Merged in 42db921. Bug: Save could silently replace workspace changes made after the editor opened a file. Fix: Conditional writes share the existing workspace queue. Repeated Save and dirty Refresh retain the draft's original hash. Reload, Overwrite, and Reset adopt the appropriate matching text/hash; Overwrite also checks that its editor scope remains active. Proof: Real Gateway, served Control UI, Chromium, independent disk reads, and source-blind acceptance covered conflict refusal and recovery. Concurrent agent/agent and agent/session writes produced one success. All 139 focused tests passed, including the corrected preview fixture's five Chromium cases. Fresh review passed on
Unrelated CI exception: Run 34315564760, attempt 1, finished with one failed child: checks-node-compact-large-19. A controlled reproduction on main 3f0f98ef demonstrated the existing deadline error-code race: mixed fake timers and real The fake tool invocation does not call the file editor or workspace queue, and this PR changes no Code Mode deadline or worker state. The reproduced inline-worker classification path was added in #141265, ce8fb532; its parent diff and ancestry were checked. That commit names RoboClaw as author, GitHub as committer, and credits @Takhoffman. This is a separate owner-level follow-up, not a change folded into this PR. No identical hosted main run, complete 96-file replay, or original hosted error message is claimed. Missing-file creation races and writers outside the process-local queue remain the documented limits. The distinct Refresh-cache issue #127592 remains untouched. |
…w#135865) Refuse stale agent-file saves through the existing workspace update queue and offer explicit Reload and Overwrite recovery. Preserve draft ancestry across Refresh, adopt matching text and hash on Reset, and fence the Overwrite continuation against retired editor scope. Verified with real Gateway and Chromium red/green proof, independent browser acceptance, concurrent agent/session writer controls, and focused regression coverage. Retains the contributor's conditional-save repair and current file admission, identity, size, and session behavior. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Saving an agent workspace file must preserve changes made after the editor opened it. The editor now refuses a stale Save and offers Reload or Overwrite. Reset also adopts the matching hash when it adopts refreshed text.
Evidence
The same real Gateway, served Control UI, Chromium, and separate workspace writer were used on pinned main
7c6ca652ef75c7bea81659879424551fabfdafe3and the repaired candidate. Captures were inspected. Private fixture contents, workspace paths, credentials, and infrastructure details are omitted here.agent_file_conflict; disk stayed 62 bytes and the draft remained in the editorSanitized excerpts from actual file RPC frames use
H0for the original content hash andH1for the later content hash. These are aliases, not literal request values:An independent source-blind browser pass repeated the conflict/recovery cases with fresh values, checked real disk bytes and passive RPC frames, and also saved empty and Unicode content. It found no browser behavior failures. Source provenance, direct RPC controls, and landing gates were explicitly outside that validator's browser role and were checked separately.
Repair
expectedHashon agent-file saves.This retains @yetval's conditional-save repair and resolves the outstanding Reset review finding. The separate Refresh-cache repair associated with #127592 has already shipped; this PR does not close or replace that issue.
Validation
Missing-file creation races remain outside this repair: there is no
expectedAbsentwrite precondition. Content hashes are not monotonic revisions. The process-local queue does not exclude an external writer changing bytes between comparison and publication, or writes from another Gateway process.