Repository navigation
fix: recover sandbox file tools after stopping a run - #200669
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
bf65112 to
7c46ddc
Compare
|
Codex review: needs maintainer review before merge. What this changesPropagates cancellation through sandbox file operations and bounds same-file queue waits while preserving write exclusion. Example: Stop a sandbox read of /workspace/same.txt, then retry that file.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a current cancellation defect that main still contains; no definite introduced correctness or security defect was found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherAgent read, edit, write, and apply_patch calls reserve physical file identities through a shared queue before accessing the sandbox filesystem bridge and container backend. flowchart TD
A[Agent file tool call] --> B[Physical file identity]
B --> C[Shared file queue]
C --> D[Sandbox filesystem bridge]
D --> E[Container backend]
F[Run cancellation] --> C
F --> D
E --> G[Settlement and reservation release]
Technical reviewBest possible solution: Keep cancellation and bounded admission in the existing queue and bridge owners, retaining reservations until actual operation settlement. Do we have a high-confidence way to reproduce the issue? Current-main source shows unbounded queue waits and omitted sandbox operation signals, supported by the supplied base-failing regressions; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch repairs cancellation at existing owners, preserves FIFO and settlement, and documents uncancellable boundaries without adding speculative recovery machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7b0a97a4c96e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +231, Tests +198, Docs +8, Other 0. Total +437 across 21 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 17, 2026, 11:30 AM ET / 16:30 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* fix: recover sandbox file tools after stopping a run * test: adapt file fixtures to cancellation signals * fix: use a typed sandbox filesystem error
* fix: recover sandbox file tools after stopping a run * test: adapt file fixtures to cancellation signals * fix: use a typed sandbox filesystem error (cherry picked from commit 88e9e3b) Co-authored-by: RomneyDa <[email protected]>
* fix: recover sandbox file tools after stopping a run * test: adapt file fixtures to cancellation signals * fix: use a typed sandbox filesystem error Release adaptation: Reviewed sandbox cancellation and source-preserved caller adapters. (cherry picked from commit 88e9e3b) Co-authored-by: RomneyDa <[email protected]>
Baseline adaptation: Make ordered physical-file reservation abortable before execution with the existing FIFO lease registry while preserving executing writer custody. (cherry picked from commit 88e9e3b) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 452f36f142d60413e920863e792d3e7601c582cf)
Related: #200601
What Problem This Solves
After a sandbox file operation hangs, stopping the run can leave its file reservation occupied. Retrying read, edit, write, or apply_patch on the same file then waits silently until the reply watchdog stops another turn.
User Impact
Stopping a run now cancels queued file work and reaches active sandbox filesystem commands. A file operation waiting behind unfinished work reports an actionable busy-file error after three minutes, including the earlier operation's age. Other files remain usable. There is no configuration, watchdog-threshold, or container-command timeout change.
A running operation retains exclusion until its real settlement. A canceled or expired waiter never executes later, and never permits overlapping writes.
Why This Change Was Made
Root-cause chain (base
a3dd700b):src/agents/sessions/tools/file-mutation-queue.ts:11retains process-global tails;src/agents/sandbox/file-mutation-identity.ts:54includes the sandbox root in the physical key;src/plugin-sdk/keyed-async-queue.ts:33chains an unbounded predecessor;src/agents/agent-tools.read.ts:887–915omits read/access/stat signals;src/agents/sandbox/fs-bridge-path-safety.ts:318drops cancellation at the descriptor boundary.src/agents/sandbox/container-engine.ts:106starts the helper without a deadline and can only cancel it when supplied a signal. The observer race insrc/agents/embedded-agent-runner/run/attempt-tool-search-executor.ts:135does not by itself settle the implementation holding the key.The existing keyed queue now accepts an optional admission signal. Its returned waiter can reject immediately, but the reserved tail still joins its predecessor before skipping the canceled callback. The file-queue owner bounds waits and keeps running-age metadata on its existing tails; one warning records only a key hash, holder age, and waiter wait. No parallel registry is introduced. The sandbox adapters move into
agent-tools.read.operations.tsbecause the existing read module’s mandatory line-cap ratchet forbids growth; this preserves one adapter owner and the existing factory path.Execution/run signals propagate through read/edit/write operations, verification and memory-provenance readback, the mounted bridge's canonical path checks and stat commands, and the existing container-engine cancellation option. Ordinary descriptor reads use Node's signal support.
openRootFileand the fs-safe bounded descriptor API lack signal support: they remain joined through real settlement, with abort checked afterward. Mutation checkpoints also retain their existing settlement contract.#200601 preserves pending-tool attribution when the watchdog stops a reply; this change repairs file-operation cancellation and contention beneath that diagnostic. The separate
codex/codemode-abandoned-call-cancellane landed in #200647 and cancels abandoned worker-to-Gateway tool calls. This branch is rebased onto that change, with patch-identical commits. No Code Mode bridge or execution files are changed here.Evidence
OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 pnpm test src/agents/agent-tools.read.sandbox-queue-abort.test.ts src/agents/sessions/tools/file-mutation-queue.test.ts --maxWorkers=1On base
a3dd700bb8677db62fe481cf692a2c9afe570c60, the production file-tool/real-bridge regression fails for sandbox access, read, and write-precheck stat: the held container command receives no abort while the same-file retry is queued. The queue-owner regression also fails: cancellation and expiry do not reject, and both callbacks execute after the holder is released. An unrelated file remains usable in each scenario.The fixed tests use a synthetic container engine and fake timers. They verify same-file recovery after abort, queued callback suppression, the three-minute actionable error, unrelated-file progress, and exclusion through real settlement of a canceled active writer. This is production-owner boundary proof, not a live rootless Podman incident reproduction.
Checks passed: 247 tests across 15 affected files (one existing skip), production core typecheck, targeted test typecheck, touched-file lint/format,
git diff --check, andpnpm build(3m42.6s). After the review-requested exclusion assertion, the two regression files passed again (5 tests). The adapter extraction also passed 27 tests across its sandbox/host consumers (five Windows-only skips on macOS), the line-cap ratchet, core typecheck, and lint;pnpm buildpassed after extraction in 2m54.5s and again on the final rebased head in 2m5.1s. The final rebased core typecheck and all five queue/bridge regressions also passed. Independent Codex autoreview through P2 finished scoped-clean after addressing that proof gap; a further clean review covers the fixture repair. Initial CI test-type failures were caused by five existing fixtures passing Node fs functions directly into the newly signal-aware contracts. Those fixtures now translate signals to Node options; both failed type graphs and all 61 runtime cases pass locally. The subsequent safety ratchet caught an assertion moved into the extracted adapter; it now uses a typed error declaration and shrinks the original file’s allowance. The assertion ratchet, core typecheck, lint/format, and independent Codex review pass for that repair. Run 44119346624 also exposed an unrelated lint failure:src/agents/subagents/registry/subagent-result-owed.expiry-discard.test.ts:53declares_warning, rejected byeslint(no-underscore-dangle). That source is byte-identical in baseline05243ef8, PR head, and the CI merge; lint configuration is unchanged, and focused local lint reproduces the same error. This inherited failure is retained as failed evidence rather than rerun. The assertion failure is repaired before landing. Final run 44123017046 passes build, security, all typechecks and baseline ratchets, but retains two inherited roots: that same lint error, andserver.config-patch.test.ts > uses fresh revisions after agent create, update, and delete before reload appliestiming out itsagents.deleterequest at the existing 10,000ms client limit. The test, fixture, RPC client, and deletion handler/drain are identical in CI baseline9122a49band actual tested mergefe52c306; this flow issues config/skills RPCs and never invokes the changed file tools or queue. Its precise CI latency trigger remains unknown. The native exception evidence retains both failed jobs and the downstream gate, with source equality and causal attribution; it does not label CI green. A local replay in original file order passed all 67 cases (333.37s wrapper, 162.93s Vitest), including the timed-out case in 12.08s; that is reproduction evidence, not a claimed repair.Test cost: 198 net test lines: two new test definitions (one parameterized over access/read/stat) plus signal adapters in five existing fixtures, below the 400-line budget. Local single-file wall time: sandbox adapter/bridge 62.04s (54.84s Vitest duration, dominated by a cold compiler generation); queue owner 15.71s. Fixture single-file wall times: bootstrap memory 18.44s; memory provenance 10.05s; channel recovery 18.69s; operator recovery 59.44s; sharing publication 23.34s. The existing operator suite already exercises full authority/worker flows; only its read adapter changes here. Exact-head CI run 44123017046 completed: 18 passing selected Node test jobs totaled 5,700 job-seconds, the config-RPC job with the unrelated timeout took 659 job-seconds, and build-artifacts passed in 801 seconds. These are whole-job costs including setup and selected consumers, not incremental per-file times; the run does not publish per-file observation artifacts. Added test bodies are under 0.1s per file; compilation dominates the real adapter/bridge graph. Fake timers cover the full three-minute wait without sleeping. Production growth is 231 net lines, plus eight documentation lines and a one-entry assertion-baseline reduction: optional signal propagation, admission cancellation in the existing queue, and age metadata on its existing tails replace the unbounded silent wait; there is no second queue owner or registry.
Trigger investigation (incident/base trace; #200643 subsequently adds FIFO workspace admission and a 60s acquisition bound): the helper path has no OpenClaw per-container exec queue (
src/agents/sandbox/docker-backend.ts:132). The engine also awaits a state-path preflight without a signal (container-engine.ts:103→state-owner.ts:41→state-owner-path.ts:40→ host realpath); a blocked host filesystem can stall before Podman starts. Rootless native Podman may enter a systemd user scope (src/agents/sandbox/container-engine.ts:73) before exec; Podman startup/lock/attach or a filesystem stall can therefore wait without a workspace cwd. Workspace serialization is the reconciliation lease (src/gateway/worker-environments/local-workspace-store.ts:221; the incident base used ten-minute acquisition, and #200643 now owns FIFO/60s acquisition), held through helper execution (src/agents/sandbox/local-workspace.ts:293). Normal checkpoint pause and helper exec are ordered by that lease; pause/unpause commands themselves have 30s control deadlines (src/agents/sandbox/local-workspace-quiescence.ts:354,395). Current upstream Podman source rejects already-paused containers after acquiring its lock, while its attach wait has no explicit timeout; the deployed Podman version has not been reproduced here. A freeze after exec starts remains possible outside normal custody. No source evidence singles out pasta networking.The checkpoint final host-work join (
src/infra/git-worker.ts:578) and mutation checkpoint (src/agents/sandbox/local-workspace.ts:366) intentionally await actual host work. They can retain a queue slot if that work never settles. A normal live operation renews its lease, but cancellation/loss can stop renewal (src/state/openclaw-state-lease.ts:190–196) while an uncooperative callback remains pending; absence of a live lease does not identify the blocked await. Checkpoint/preparation sharing (src/gateway/worker-environments/local-workspace-projection.ts:100–143) is another workspace wait, separate from the per-file queue; its checkpoint API has no caller signal. No speculative checkpoint or pause fix is included. Remaining uncancellable boundaries are engine host preflight (container-engine.ts:103), fs-safe open (fs-bridge-path-safety.ts:324) and bounded descriptor read (fs-bridge.ts:391); caller cancellation is checked around the latter two without releasing write exclusion early. The existing 30s convention is for control commands, not filesystem helpers, so this adds no filesystem command deadline.Release-note context: recover same-file sandbox operations after stopping a run; report bounded file contention without weakening write exclusion.