Skip to content

fix(agents): prevent concurrent workspace setup failures - #164377

Merged
steipete merged 2 commits into
mainfrom
codex/workspace-preparation-fifo
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/workspace-preparation-fifo

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes workspace setup failing during concurrent first turns with “Workspace filesystem changed while preparing state” before any provider request, as observed in the Full Release Validation source-performance job.

User Impact

Concurrent runs can prepare the same workspace reliably while retaining each caller’s bootstrap options and result. Requests canceled or revoked while queued cannot publish workspace files when their turn arrives.

Why This Change Was Made

Complete local preparation and consented bootstrap seeding share one FIFO per canonical filesystem directory. Sandbox copying and scaffolding retain the same slot, and dev-template publication joins the same owner. Existing Gateway custody guards are captured before waiting and checked before filesystem effects; worker admission retains its separate host-only authority and recovery predicate. Different directories remain independent, accepted writes settle before the next caller enters, and the old Git-only shared-promise path is removed.

Evidence

  • Deterministic negative controls reproduced overlapping preparation, acceptance of a replaced directory, command/reply writes after queued cancellation, and a later caller claiming AGENTS.md between sandbox copying and scaffolding. The integrated custody regression also fails by publishing AGENTS.md when the guard is borrowed instead of captured.
  • Focused integration validation: 62 tests passed in 82.92 seconds with --maxWorkers=1, including workspace, sandbox, and state/managed/browser custody cases. Earlier worker, atomic-publication, SQLite-safety, and caller compatibility proof is retained. Initial owner/caller regression cases took 11.3 seconds of serial local test time; the extended custody case took 0.70 seconds.
  • The complete native changed-file gate passed in 22m22.546s on all 27 changed paths, using the exact staged candidate and pinned main commit fd8397a6bb6e10eb5346f7a1452ac2e970033127. Production/test typechecks, lint, ratchets, storage guards, and import-cycle checks passed.
  • The integrated sourcePerformance runtime build passed in 167.892 seconds. Fresh AutoReview of the complete candidate is clean through P2.
  • CI attempt 1 passed for published head e9b5a30416738beabb0d7b16756d2cc33f844c36. All 12 introduced or materially changed regression cases executed once and passed, totaling 5.777 seconds of rounded, reported case duration; measured costs are below.

Before the main integration, the unchanged baseline and initial repaired candidate each completed and verified all eight mock warmup turns on macOS. Both benchmark invocations exited 1 during Gateway teardown before a measured run began. This is not a passing performance benchmark; the separately diagnosed Darwin filesystem-watcher cleanup limitation remains outside this repair. The original Full Release Validation performance job runs on Linux.

Measured CI regression costs
Test file (linked to owning CI job) Changed cases Changed-case seconds All file cases All-case seconds
src/agents/workspace.test.ts 7 3.174 49 12.592
src/agents/sandbox/workspace.test.ts 3 0.427 10 0.847
src/commands/agent.worktree-race.test.ts 1 1.241 3 5.538
src/auto-reply/reply/get-reply.workspace-failure.test.ts 1 0.935 5 0.956
Total 12 5.777 67 19.933

These are sums of Vitest's rounded per-case durations, not file wall time or incremental job cost. Each file ran once in the recorded CI plan. The successful run tested GitHub merge 72591dfcfb61c86e08e9eafd174cdb42759dee5a, combining base 7ae1ec5a37b6bb807cfbc51e1e1be5542c25ac67 with the published PR head; the four test files and their workspace registration helper are unchanged between that head and the tested merge.

Focused integration test command

Run through the repository test wrapper (pnpm test uses the same entry point):

node scripts/run-vitest.mjs src/agents/workspace.test.ts src/agents/sandbox/workspace.test.ts src/agents/sandbox/context.state-owner.test.ts src/agents/sandbox/context.managed-custody.test.ts src/agents/sandbox/context.browser-state-owner.test.ts --maxWorkers=1

The current candidate integrates pinned main commit fd8397a6bb6e10eb5346f7a1452ac2e970033127 and preserves its hosted sandbox custody contract. The review, test, and isolated build/check copies are bound to the same complete candidate tree and per-file hashes, modes, and deletion.

Serialize complete workspace preparation and bootstrap seeding per canonical
directory while retaining each caller's options, authority, filesystem identity,
and accepted-write settlement. Keep sandbox copying and scaffolding in one
interval and retire the Git-only shared-promise path.

Original-code controls reproduce the race, canceled-caller writes, root
replacement, and sandbox ordering gap. Focused tests, the full changed-file gate,
and the source-performance runtime build pass. The unchanged Darwin benchmark
shutdown failure remains separate; all eight mock warmup turns verify.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 docs Improvements or additions to documentation cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL labels Oct 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 12:26 PM ET / 16:26 UTC (Revision 2).

ClawSweeper review

What this changes

The PR serializes workspace setup, bootstrap seeding, sandbox copying, and dev-template publication per directory while retaining each caller’s options and cancellation checks.

Merge readiness

✅ Ready for maintainer review

The fix remains useful, and no introduced blocking defect was found. The revised head addresses the previous integration concern by preserving sandbox custody across queued preparation.

Priority: P2
Reviewed head: e9b5a30416738beabb0d7b16756d2cc33f844c36

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate does not apply to this verified maintainer-authored PR. Reported warmup turns cover the runtime entrypoint but do not establish a passing performance benchmark; inspected regressions supplement source review of queue and custody behavior. No stored schema or serialized-format contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this verified maintainer-authored PR. Reported warmup turns cover the runtime entrypoint but do not establish a passing performance benchmark; inspected regressions supplement source review of queue and custody behavior. No stored schema or serialized-format contract changes.
Evidence reviewed 9 items Pinned introduction and parentage: Reviewed the introduced delta from fd8397a to e9b5a30. Raw head parents match the supplied original-head record; the stale GitHub test merge was not used to infer removal of current-main behavior.
Single preparation owner: The preparation queue uses the existing store-writer queue, captures filesystem identity before waiting, and checks it again on entry. The shared writer preserves the caller’s async context and holds the slot through settlement.
Sandbox custody preserved: Sandbox preparation captures the guard before waiting, checks retained mutation authority before copying, and runs subsequent scaffolding inside the same queue interval. Worker admission continues to receive SQL-free host checks and its separate recovery predicate.
Findings None None.
Security None None.

How this fits together

Workspace preparation runs before agent execution and creates bootstrap files, initializes Git, and records setup state. Command, reply, cron, voice, and sandbox callers feed this preparation owner before continuing their runs.

flowchart TD
  A[Agent and sandbox requests] --> B[Capture options and authority]
  B --> C[Canonical directory queue]
  C --> D[Recheck authority and directory identity]
  D --> E[Prepare bootstrap files and Git]
  E --> F[Settle workspace state writes]
  F --> G[Return caller result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +213, Tests +560, Docs +7, Other 0. Total +780 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 16 496 283 +213
Tests 7 818 258 +560
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 2 2 0
Total 26 1323 543 +780

Review metrics

Metric Value Why it matters
Production and regression growth production net +213 lines; tests and test support net +559 lines Production growth has a stated ownership rationale, while the larger test addition exercises queue ordering, caller isolation, cancellation, and custody.

Technical review

Best possible solution:

Keep complete local preparation under one directory owner while preserving existing bootstrap contents, worker admission, and live caller authority.

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

Yes, source provides a high-confidence path: concurrent callers can interleave complete preparation on main while filesystem evidence rejects their competing writes. The PR records negative controls; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes, serializing the complete preparation interval through the existing queue owner addresses the race while preserving individual results and custody checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b6cde0d5f24c.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded concurrent workspace preparation failure before provider execution.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor proof gate does not apply to this verified maintainer-authored PR. Reported warmup turns cover the runtime entrypoint but do not establish a passing performance benchmark; inspected regressions supplement source review of queue and custody behavior. No stored schema or serialized-format contract changes.

Evidence

What I checked:

  • Pinned introduction and parentage: Reviewed the introduced delta from fd8397a to e9b5a30. Raw head parents match the supplied original-head record; the stale GitHub test merge was not used to infer removal of current-main behavior. (e9b5a3041673)
  • Single preparation owner: The preparation queue uses the existing store-writer queue, captures filesystem identity before waiting, and checks it again on entry. The shared writer preserves the caller’s async context and holds the slot through settlement. (src/agents/workspace-preparation.ts:11, e9b5a3041673)
  • Sandbox custody preserved: Sandbox preparation captures the guard before waiting, checks retained mutation authority before copying, and runs subsequent scaffolding inside the same queue interval. Worker admission continues to receive SQL-free host checks and its separate recovery predicate. (src/agents/workspace.ts:596, e9b5a3041673)
  • Forbidden-effect regression coverage: The hosted-custody regression releases the actual Gateway state owner while preparation is queued or paused after a destination read, then asserts an empty destination and the custody refusal. Command and reply regressions likewise check cancellation before scaffolding; these are supplemental tests, not independently executed live proof. (src/agents/sandbox/workspace.test.ts:34, e9b5a3041673)
  • Current-main necessity: Fetched main still coalesces only Git initialization and lacks the complete preparation queue. No verified merged fixing PR was supplied or established. (src/agents/workspace-git.ts:6, b6cde0d5f24c)
  • Latest-release check: The supplied latest release commit has no workspace-preparation module; no release provenance establishes this broader fix as already shipped. (fc23bc864e45)

Likely related people:

  • Peter Steinberger: Raw commit 6c1e166 adds src/agents/workspace-state-guard.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6c1e1667bd61; files: src/agents/workspace-state-guard.ts)

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 (1 earlier review cycle)
  • reviewed 2026-10-03T15:33:34.835Z sha 6121c74 :: needs changes before merge. :: none

Integrate pinned main while keeping sandbox copying and scaffolding in one FIFO
interval. Capture the existing custody guard before waiting and preserve the
separation between host filesystem checks and worker admission.
@steipete
steipete marked this pull request as ready for review October 3, 2026 16:21
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: e9b5a30416738beabb0d7b16756d2cc33f844c36
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/sandbox/context.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/workspace.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@steipete
steipete merged commit bd14552 into main Oct 3, 2026
223 checks passed
@steipete
steipete deleted the codex/workspace-preparation-fifo branch October 3, 2026 17:08
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…4377)

Serialize complete workspace preparation and bootstrap seeding per canonical
directory while retaining each caller's options, authority, filesystem identity,
and accepted-write settlement. Keep sandbox copying and scaffolding in one
interval and retire the Git-only shared-promise path.

Original-code controls reproduce the race, canceled-caller writes, root
replacement, and sandbox ordering gap. Focused tests, the full changed-file gate,
and the source-performance runtime build pass. The unchanged Darwin benchmark
shutdown failure remains separate; all eight mock warmup turns verify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: XL 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.

1 participant