Skip to content

fix(sandbox): queue reads behind in-flight writes to the same file - #125091

Merged
obviyus merged 7 commits into
openclaw:mainfrom
malimo:fix/sandbox-read-write-race-and-codex-lazy-store
Aug 27, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
malimo:fix/sandbox-read-write-race-and-codex-lazy-store

Conversation

@malimo

@malimo malimo commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Same-turn tool calls can run in parallel. A write and read of the same new sandbox file could race. The read could return File not found even though the accepted write finished moments later.

Why This Change Was Made

write, edit, and apply_patch already share one per-file operation queue. read now joins that queue through path resolution, access, and byte capture. The queue releases before image handling, text decoding, truncation, and result formatting.

Sandbox bridges now own physical file identity. This makes host-mirror, remote-workspace, and filesystem-alias spellings converge before the operation is registered. When identity lookup is asynchronous, registration keeps the provider's tool-call order even if the later lookup finishes first. Identity lookups still run concurrently, and operations on different files remain parallel.

Bridge identity stays internal. The public SandboxFsBridge contract is unchanged, and existing plugin bridges retain their resolved-path identity behavior. This change adds no retry, configuration, protocol, or storage path.

User Impact

An agent can write and read one file in the same turn without an intermittent stale or missing-file result. Independent files do not wait for the write to finish.

Evidence

Live red and green

A real Telegram Test Server direct-message turn used one provider response with three parallel calls:

  1. Write same-turn-written-by-provider through the remote workspace path.
  2. Read the same new file through its host mirror.
  3. Read a seeded parallel-control.txt file.

The proof delayed the real write for 1.5 seconds before file creation.

Revision Same-file read Different-file read Final files
Exact main at ef858c0f1bb File not found before the write finished parallel-control during the delay Both requested values
Exact head 4954c13058c same-turn-written-by-provider parallel-control during the delay Both requested values

Current main advanced to 599b46c49bb after the red run. The queue, sandbox bridge, tool, and agent-loop files are unchanged from the proven revision.

The final Telegram reply was:

WRITE=accepted; SAME_PATH=same-turn-written-by-provider; DIFFERENT_PATH=parallel-control

The retained provider requests contain the real tool results. The filesystem timeline records the full pre-creation delay. The final command read both values from disk. The exact build records 4954c13058cd0c3c26607e977378a49611b95f6c in its build metadata.

Regression support

  • The remote bridge regression delays the earlier write's identity lookup and lets the later read resolve the same identity first.
  • Before the repair, it fails because the read reaches stat before the write registers.
  • The accepted Unicode fallback spellings have a separate pre-fix delayed-write regression.
  • After the repair, 11 focused files pass with 239 tests and one platform case skipped.
  • Exact-head check-changed passes production and test types, lint, formatting, dead exports, import cycles, and repository guards.
  • The Plugin SDK surface check passes all 147 public subpaths and 339 total entrypoints.
  • The exact-head full build passes.

Scope

  • Production: +275/-47, net +228.
  • Tests: +169/-1, net +168.
  • The production growth establishes one shared owner boundary across read, write, edit, apply-patch, local aliases, and remote aliases. No narrower consumer guard can represent those identities or preserve asynchronous admission order.

🤖 Generated with Claude Code

@malimo
malimo requested review from a team as code owners August 17, 2026 05:56
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: 4954c13058cd0c3c26607e977378a49611b95f6c

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: copilot-proxy Extension: copilot-proxy extensions: diagnostics-otel Extension: diagnostics-otel extensions: llm-task Extension: llm-task extensions: lobster Extension: lobster labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 6:30 PM ET / 22:30 UTC.

ClawSweeper review

What this changes

The PR serializes sandbox reads with earlier writes, edits, and patch operations for the same physical file, including remote aliases.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

The race remains on current main and the branch repairs its shared queue boundary with credible real-run evidence, but it adds an optional public sandbox-plugin API that needs owner confirmation before merge.

Priority: P2
Reviewed head: d3e015144cf74f2c6d11506f3a5f9cfe547147fe
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The behavioral proof and regression coverage are strong, while the public plugin SDK contract still needs an owner decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides an after-fix real Telegram Test Server turn with a red current-main comparison, exact-head green output, and persisted-file confirmation.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides an after-fix real Telegram Test Server turn with a red current-main comparison, exact-head green output, and persisted-file confirmation.
Evidence reviewed 8 items Current-main race shape: Current fetched main resolves a read path and immediately reads its bytes, while its queue only wraps mutation callers; it has no read admission path.
Shared owner-boundary repair: The branch admits asynchronously resolved physical keys in assistant-message order, then queues only matching file operations.
Runtime caller and bridge boundary: Core coding-tool construction gives sandboxed read, edit, and write tools the same bridge; the remote bridge now produces canonical identity keys.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/sandbox/remote-fs-bridge.test.ts -t "orders sandbox tools through one remote alias identity"

Result: PASS (completed)

[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-125091-acH0o0/target

 ✓  agents-support  src/agents/sandbox/remote-fs-bridge.test.ts (21 tests | 20 skipped) 356ms
     ✓ orders sandbox tools through one remote alias identity  353ms

 Test Files  1 passed (1)
      Tests  1 passed | 20 skipped (21)
   Start at  22:31:01
   Duration  3.84s (transform 2.50s, setup 993ms, import 2.13s, tests 356ms, environment 0ms)

[test] passed 1 Vitest shard in 10.52s





































Assertions:

  • PASS expect_output: orders sandbox tools through one remote alias identity
  • PASS expect_output: Tests

How this fits together

Agent coding tools read and mutate files through sandbox filesystem bridges. The shared queue prevents same-file tool calls in one assistant turn from observing a write before it finishes.

flowchart LR
  A[Parallel agent tool calls] --> B[Read write edit and patch tools]
  B --> C[Bridge resolves physical file identity]
  C --> D[Per-file admission queue]
  D --> E[Local or remote sandbox filesystem]
  E --> F[Read snapshot or mutation result]
Loading

Decision needed

Question Recommendation
Should OpenClaw make backend-owned physical file identity an optional public SandboxFsBridge capability for same-file operation ordering? Approve the additive bridge capability: Accept the optional backward-compatible method as the canonical extension point for remote physical-path ordering.

Why: The patch is functionally coherent and preserves existing bridge implementations, but the type is exported through the plugin SDK and therefore sets a durable external contract.

Before merge

  • Resolve merge risk (P1) - SandboxFsBridge is a public plugin SDK type; the optional identity method is backward-compatible but becomes a permanent external contract without a maintainer-visible API decision.
  • Resolve merge risk (P1) - The bug fix adds net 196 production lines; the remote alias and asynchronous-admission boundary explains the added behavior, but its size warrants owner review before landing.
Agent review details

Security

None.

PR surface

Source +196, Tests +114. Total +310 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 9 236 40 +196
Tests 2 115 1 +114
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 351 41 +310

Review metrics

Metric Value Why it matters
Production versus test LOC production +196 net; tests +114 net The regression spans local aliases, remote bridges, and four tool entry points; the public owner-boundary expansion needs explicit acceptance.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/tools/edit.ts, serialized state: src/agents/sessions/tools/file-mutation-queue.ts, serialized state: src/agents/sessions/tools/read.ts, serialized state: src/agents/sessions/tools/write.ts, unknown-data-model-change: src/agents/sessions/tools/file-mutation-queue.ts, unknown-data-model-change: src/agents/sessions/tools/read.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm the public bridge contract (recommended)
    Approve the optional identity capability as an additive plugin SDK contract, retaining fallback behavior for existing bridges.
  2. Redesign before merge
    Pause the PR if maintainers do not want physical identity exposed through the public sandbox bridge interface.

Technical review

Best possible solution:

Keep one canonical queue-identity boundary, and approve the narrow optional SDK capability only if sandbox-backend owners accept it as the supported way to expose physical file identity.

Do we have a high-confidence way to reproduce the issue?

Yes, source reproducible: current main reads immediately after path resolution without joining the mutation queue, and the PR supplies a matching real red/green scenario.

Is this the best way to solve the issue?

Unclear pending API direction: shared physical identity is the right repair layer, but maintainers must decide whether its public plugin SDK surface is acceptable.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b181d789837d.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The PR adds an optional method to the public sandbox plugin bridge type, creating a durable external contract.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides an after-fix real Telegram Test Server turn with a red current-main comparison, exact-head green output, and persisted-file confirmation.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This addresses an intermittent same-turn agent file-read failure without evidence of broad runtime outage.
  • merge-risk: 🚨 compatibility: The PR adds an optional method to the public sandbox plugin bridge type, creating a durable external contract.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides an after-fix real Telegram Test Server turn with a red current-main comparison, exact-head green output, and persisted-file confirmation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix real Telegram Test Server turn with a red current-main comparison, exact-head green output, and persisted-file confirmation.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Authored the exact-key async queue consolidation that established the central queue module. (role: queue-owner history contributor; confidence: medium; commits: c2fc7aa28a49; files: src/agents/sessions/tools/file-mutation-queue.ts)
  • Vincent Koc: Authored the prior remote filesystem-read pinning repair, the closest historical owner boundary to canonical remote identities. (role: remote sandbox boundary contributor; confidence: high; commits: 121870a08583; files: src/agents/sandbox/remote-fs-bridge.ts, src/plugin-sdk/sandbox.ts)
  • Peter Steinberger: Authored a recent remote-sandbox hardlink-safety repair in the same bridge area. (role: recent adjacent sandbox contributor; confidence: medium; commits: 49f77492233a; files: src/agents/sandbox/remote-fs-bridge.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain maintainer confirmation that the optional public SandboxFsBridge identity capability is the intended long-term contract.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-08-17T06:21:00.933Z sha 79564cda36b3e8c8d092fa21789d9ef805da0d64 :: needs real behavior proof before merge. :: [P2] Release the mutation queue after reading the bytes
  • reviewed 2026-08-17T06:36:37.886Z sha 6005d504740d8bdd42491b4b15038e58a073a8b8 :: needs real behavior proof before merge. :: [P2] Release the queue after reading the bytes | [P2] Canonicalize fresh paths through an existing parent
  • reviewed 2026-08-17T07:20:00.538Z sha db5f6496c7b3c63b65311c345c5f02d5119e88b2 :: needs real behavior proof before merge. :: [P2] Release the queue after capturing the file bytes | [P2] Canonicalize a fresh leaf through its existing parent
  • reviewed 2026-08-23T06:22:29.512Z sha db5f6496c7b3c63b65311c345c5f02d5119e88b2 :: needs real behavior proof before merge. :: [P2] Release the queue after capturing the file bytes
  • reviewed 2026-08-27T17:23:51.057Z sha 52a8168 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T19:17:19.579Z sha 51c7211 :: needs real behavior proof before merge. :: [P2] Canonicalize the queue identity before sandbox reads | [P2] Make the ordering regression deterministic
  • reviewed 2026-08-27T20:18:25.648Z sha 8150fcf :: needs changes before merge. :: [P2] Queue remote sandbox aliases by their canonical backend path

@obviyus

obviyus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks @malimo!

Proof: On exact head 4954c13058c, a real Telegram Test Server turn issued a write, a same-file read through another accepted path spelling, and an unrelated read in one provider response. The write was delayed for 1.5 seconds before file creation. Current main returned File not found; the merged head returned the written bytes, the unrelated read completed during the delay, and final disk contents matched both requested values.

  • Bug: A same-turn read could run before an accepted write to the same sandbox file and report missing or stale data.
  • Fix: One file queue now preserves tool-call admission order and uses bridge-owned identity for local, remote, alias, and accepted Unicode path spellings.

Example

Before After
Write accepted; read returns File not found Write accepted; read returns the written text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants