Repository navigation
fix(agents): serialize concurrent sandbox memory-flush appends - #117757
chelsealong wants to merge 3 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed September 5, 2026, 4:02 AM ET / 08:02 UTC. ClawSweeper reviewWhat this changesSerializes sandbox memory-flush appends with ordinary file mutations and adds concurrency and queued-cancellation regression tests. Merge readiness⛔ Blocked before merge - 4 items remain The memory-loss bug remains on current main and in v2026.9.1, and this maintainer-engaged PR remains useful. No blocking defect is established in its introduced hunks; the previous provenance finding depended on later main changes and an unverified conflict resolution. Priority: P1 Review scores
Verification
How this fits togetherBefore compaction, OpenClaw saves durable conversation notes into daily memory files. The sandbox append wrapper turns each note into a filesystem read-modify-write operation, which must coordinate with other writers to preserve existing notes. flowchart TD
A[Pre-compaction memory turn] --> B[Append-only write wrapper]
B --> C[Per-file mutation queue]
D[Ordinary write and edit tools] --> C
C --> E[Sandbox filesystem bridge]
E --> F[Daily memory file]
F --> G[Durable notes for later sessions]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +8, Tests +260. Total +268 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Use one canonical sandbox mutation lane for the complete memory append and provenance transaction, preserving ordinary-write coordination and cancellation. Do we have a high-confidence way to reproduce the issue? Yes, from source: overlapping sandbox flushes can read the same contents and overwrite one another. The supplied issue trace demonstrates that interleaving on an older revision; this review did not execute current main. Is this the best way to solve the issue? Yes for the pinned base: reusing the ordinary mutation queue repairs the owning write boundary without adding a parallel mechanism. The conflicted branch needs integration with current main before that judgment can extend to a landing candidate. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 961464a5177e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
|
Addressed the P2 finding: the queued sandbox-append callback now rechecks |
5c23dca to
0884fce
Compare
|
Maintainer repair refreshed at ce1d0cf.
Exact-head validation on
Hosted CI is terminal but not green: 78 success, 36 skipped, 1 neutral, and 2 failures (the test job plus aggregate gate). Live-main audit: merge-tree against Verdict: HOLD until the unrelated compact-shard timeout is fixed or the required hosted gate becomes green. No merge performed. |
0884fce to
c795bd7
Compare
Sandboxed memory-flush appends read, concatenated, and overwrote the whole file with no atomic append primitive or mutation queue, so two concurrent flushes for the same sandbox workspace could both report success while one note was silently dropped. Route the sandbox append through the same in-process mutation queue ordinary write/edit tools already use, keyed by sandbox root + relative path. Fixes openclaw#117741
…e wait Recheck the abort signal inside the queued sandbox-append callback, matching the existing write/edit queue convention, so a memory flush cancelled while waiting behind another append no longer mutates the sandbox bridge.
c795bd7 to
ce1d0cf
Compare
vincentkoc
left a comment
There was a problem hiding this comment.
Maintainer HOLD on exact head ce1d0cff19e60fd777127e6cab36899480a28a21.
The patch does not serialize every supported spelling of the same sandbox file. wrapToolWorkspaceRootGuardWithOptions maps /workspace/... for validation but, without normalizeGuardedPathParams, passes the original argument onward (src/agents/agent-tools.read.ts:801-879; construction at src/agents/agent-tools.ts:939-970). Ordinary write/edit therefore queue on the literal /workspace/memory/... string (src/agents/sessions/tools/write.ts:546-548, src/agents/sessions/tools/edit.ts:408-411), while memory flush queues on the host-side allowedAbsolutePath (src/agents/agent-tools.read.ts:711-748). The sandbox bridge later resolves both spellings to the same backing file.
I reproduced this deterministically on the exact PR head by changing the two existing append-vs-write/edit cases to send /workspace/<memory path> and using a production-shaped bridge resolver where relative and container paths reach the same file:
- focused
agents-corerun: 2 failed, 116 skipped - both failures completed in 34 ms
- expected
ordinary write\ndurable note/edited value\ndurable note - received only
durable note
Restoring the PR's relative-path-only cases makes the same focused run pass 2/2, confirming the current tests miss the supported alias.
Best-fix verdict: too narrow / wrong identity boundary. The queue key must come from a canonical sandbox mutation identity owned by the sandbox context/bridge and shared by memory flush, write, edit, and apply-patch. A host-path-only repair also remains insufficient for shared remote sandbox scopes where distinct local roots can map to one remote workspace.
Please keep #117741 open. This PR should not merge until the canonical identity repair and both alias regressions are present.
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
Closes #117741
AI-assisted PR: built with Claude (Claude Code). I reviewed the diff and confirmed I understand what it does and why; see disclosure checklist at the bottom.
What Problem This Solves
Fixes an issue where two concurrent memory-flush writes for the same sandboxed agent workspace (e.g. two sessions sharing one persistent
rwsandbox) could each report a successful append while one of the two durable notes silently disappeared from the daily memory file. Because the lost write happens immediately before compaction removes the source conversation detail, the dropped note was often the only persistent record of that content, with no error surfaced to the caller.Why This Change Was Made
appendMemoryFlushContent's sandbox branch (src/agents/agent-tools.read.ts) implemented "append" as an unlocked read → concatenate → whole-filewriteFile, with no queue or atomic primitive around it — unlike the ordinarywrite/edittools, which already serialize same-path mutations throughwithFileMutationQueue. The memory-flush wrapper (wrapToolMemoryFlushAppendOnlyWrite) calls this sandbox append directly and bypasses that queue entirely, so two racing flushes can both read the same starting content and the laterwriteFilesilently clobbers the earlier one.The fix routes the sandbox append through the same in-process mutation queue used by
write/edit, via a newwithMutationQueueKeyexport (src/agents/sessions/tools/file-mutation-queue.ts) that serializes on a caller-supplied key instead of a resolved hostrealpath. A plain filesystem-realpath key doesn't work here because sandbox backends resolve to a real host path only for local/Docker-mounted bridges — the remote shell-backed bridge (RemoteShellSandboxFsBridge) has no host path at all — so the queue key is built fromsandbox.root+ the relative memory path instead, which every backend has.withFileMutationQueue/withFileMutationQueueswere refactored to build their keys the same way and delegate to the new key-based queue, so there is one canonical queue implementation instead of two.This closes the in-process race (multiple sessions/tools inside one gateway process sharing a sandbox workspace), matching the level of protection the sibling
write/edittools already provide. It does not add cross-process locking — no sandbox backend exposes an atomic append primitive today, and ordinarywrite/edithave the same in-process-only limitation, so this keeps the fix consistent with the existing invariant rather than introducing new mechanism.User Impact
Operators running sandboxed agents with a shared writable workspace (e.g. two concurrent sessions on one agent) no longer silently lose a durable memory note when two memory-flush compactions race. Both notes are now preserved in the daily memory file regardless of interleaving.
Evidence
Added
it("serializes concurrent sandbox memory-flush appends instead of losing one")tosrc/agents/agent-tools.create-openclaw-coding-tools.test.ts, using the same productioncreateOpenClawCodingTools({ sandbox, trigger: "memory", memoryFlushWritePath })wiring as the existing sandbox memory-flush tests, with a real filesystem-backed sandbox bridge (createHostSandboxFsBridge) shared by two independent tool instances (mirroring two sessions on one sandbox workspace). The first realwriteFilecall is paused (bounded by a 100ms fallback) so a genuinely racing second write, if any, can reach the same point before either commits — reproducing the exact read-modify-write race from the bug report without relying on incidental scheduling.Before the fix (
git checkout HEAD~1 -- src/agents/agent-tools.read.ts src/agents/sessions/tools/file-mutation-queue.ts src/agents/sessions/tools/index.ts), the new test fails, reproducing the reported data loss:After the fix, the same test passes (both notes preserved) along with the full existing suite for this file:
Also ran, all green:
One unrelated
check:changedstep —test temp creation report (warning-only)— fails locally withENOBUFSwhile diffing againstorigin/main; this fork'sorigin/mainis thousands of commits behindupstream/main(8733 files / ~1.1M lines of unrelated diff), which is an environment/remote-staleness issue, not something introduced by this change. The step is explicitly warning-only.AI Disclosure Checklist
autoreviewskill itself was not available in this non-interactive session; the equivalent test/typecheck/lint/check-changed commands above were run manually)