Skip to content

fix: keep sandbox tools from starving behind checkpoints - #200643

Merged
steipete merged 1 commit into
mainfrom
fix/2559-workspace-lease-fairness
Nov 17, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/2559-workspace-lease-fairness

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

A sandbox tool call can keep losing its workspace lease to later checkpoints. Polling did not preserve arrival order, so repeated checkpoint traffic could leave the tool waiting for minutes. A callback that requested a checkpoint while holding the same workspace lease also waited on itself.

User Impact

Waiting sandbox operations now get their turn before later checkpoints in the same Gateway. Workspace admission ends after 60 seconds with a visible error explaining which workspace is busy and when to retry. Recursive acquisition reports the custody conflict immediately.

Why This Change Was Made

Order admission at the existing workspace lease owner using the shared keyed FIFO primitive. Keep the persisted lease responsible for cross-process exclusion, expiry, renewal and cleanup, and propagate cancellation through worker admission. Queue release follows persisted lease settlement. This does not change acceptance, journal, conflict or recovery semantics, add a schema/config option, or claim FIFO across processes.

The deadline covers waiting, not execution. Existing callers keep their cancellation error contract. Normal tool finalization already releases execution custody before checkpointing; the new diagnostic catches a nested request instead of allowing a self-wait.

The change adds 81 net production lines for queue ordering, bounded cancellation and the self-dependency diagnostic. It removes the unbounded-at-worker-admission polling-only workspace path and reuses existing queue/lease owners rather than introducing a cache or durable queue.

Evidence

Two A/A controls on exact parent d565e17c2563632a64c94185d05042cf62483ae3 both fail the new real sandbox/backend regression: three later checkpoints run before the waiting tool. The candidate runs the tool first. Tests also cover same-worktree recursion, the 60-second deadline, caller cancellation and queue-slot cleanup. Additional parent controls fail the recursion diagnostic assertion and time out at the runner’s 120-second limit for the new 60-second deadline; the candidate passes both. The parent deadline control was stopped during its stuck teardown after recording that failure.

Real SQLite proof queues four workspace writes with renewal: each write commits and renewal succeeds without BUSY or reacquisition. A separate connection holding a write transaction produces actual SQLITE_BUSY on automatic renewal; the existing 25 ms retry succeeds after release while exclusion and owner identity remain intact. No renewal algorithm change was needed.

Final focused state/sandbox tests: 37 passed. Affected projection cancellation/admission cases: 4 passed. Earlier broader projection/store run: 107 passed, with the four subsequently repaired cases and two platform skips; existing lease timer cases: 6 passed. This is synthetic macOS proof with real SQLite and sandbox backend boundaries; live Podman behavior and production writer attribution are not claimed.

pnpm check:changed --base d565e17c2563632a64c94185d05042cf62483ae3 --timed passes changed-code checks but reports five inherited unused exports. The same Knip scans reproduce all five on the exact main parent:

These are main regressions requiring their owners' follow-up. They are outside this change.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime docker Docker and sandbox tooling agents Agent runtime and tooling size: M labels Nov 17, 2026
@steipete
steipete marked this pull request as ready for review November 17, 2026 14:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T14:51:38.581211Z 3b37411 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review head 3b37411d5f5b36e95955f4756ea26ce0c45f70a6, focusing on workspace FIFO hand-off, the acquisition deadline and cancellation contract, same-worktree self-dependency, and persisted lease exclusion/cleanup. Local Codex review is clean; synthetic before/after and real SQLite renewal evidence are in the PR body.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR orders workspace admission within a Gateway, limits acquisition waits to 60 seconds, and diagnoses recursive acquisition.

Example: A sandbox tool waits for own-worktree while three later checkpoints request custody.

  • Before: Polling lets all three later checkpoints acquire custody before the waiting tool.
  • After: The tool receives custody first; subsequent checkpoints follow in arrival order.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation and regression coverage are convincing, but fixture-only evidence does not satisfy the required real-behavior proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Sandbox tools can wait for minutes while later checkpoints repeatedly acquire the same workspace.
Reason: The repair restores predictable progress using existing owners, and the maintainer-authored direction explicitly accepts bounded waiting and immediate recursive-acquisition diagnostics.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: main still permits workspace-lease starvation, and the pinned diff has no actionable correctness or security findings.

Priority: P2
Reviewed head: 3b37411d5f5b36e95955f4756ea26ce0c45f70a6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply an isolated Gateway run with a real agent and Docker or Podman showing FIFO hand-off, timeout/cancellation recovery, and preserved workspace settings and edits after a latest-stable upgrade.
Agent review details

How this fits together

Sandbox commands, preparation, and checkpoints enter the workspace store, which acquires custody before reading or changing workspace projections; SQLite leases retain cross-process exclusion and cleanup ownership.

flowchart TD
  A[Sandbox tool or checkpoint] --> B[Workspace store]
  B --> C[Keyed FIFO admission]
  C --> D[Persisted SQLite lease]
  D --> E[Workspace operation]
  E --> F[Settlement and cleanup]
  F --> C
Loading

Technical review

Best possible solution:

Retain FIFO admission at the existing workspace lease boundary, with persisted leases continuing to own exclusion, renewal, and settlement.

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

Main's polling acquisition permits later callers to overtake a waiting tool, and the body records repeated parent failures against the committed regression; this read-only review did not execute tests.

Is this the best way to solve the issue?

The change repairs ordering at the shared workspace owner, preserves persisted exclusion, and removes the superseded acquisition path without adding a competing queue implementation or durable state.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cd326f9 adds src/gateway/worker-environments/local-workspace-store.ts:84 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd326f915580; files: src/gateway/worker-environments/local-workspace-store.ts)
  • Shakker: Raw commit 94ae988 adds src/gateway/worker-environments/local-workspace-cancellation.test-support.ts:559 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 94ae988ecbbf; files: src/gateway/worker-environments/local-workspace-cancellation.test-support.ts)

PR surface

Source +81, Tests +203, Docs +6. Total +290 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 103 22 +81
Tests 3 238 35 +203
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 347 57 +290

Preflight source

Source 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

Metric Value Why it matters
Acquisition limit 600,000 ms → 60,000 ms This deliberate runtime-policy change bounds waiting without limiting execution after admission.
Production versus test growth Production +103/-22; tests and support +238/-35 Production growth implements admission ordering and diagnostics using existing queue and lease primitives; tests cover distinct ordering, cancellation, and storage boundaries.

Labels

Label changes:

  • add P2: Checkpoint traffic can delay sandbox tools for minutes, with impact limited to contending managed workspaces.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Checkpoint traffic can delay sandbox tools for minutes, with impact limited to contending managed workspaces.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 10:03 AM ET / 15:03 UTC.

@steipete
steipete merged commit 20248a9 into main Nov 17, 2026
308 of 315 checks passed
@steipete
steipete deleted the fix/2559-workspace-lease-fairness branch November 17, 2026 15:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport FIFO workspace admission, bounded acquisition and immediate self-wait rejection while retaining persisted lease custody through settlement.

Adapt target store context; source-only preparation test helper is absent on this target. Preserve prepared sandbox boundary regressions.

(cherry picked from commit 20248a9)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
RomneyDa added a commit that referenced this pull request Nov 19, 2026
(cherry picked from commit 20248a9)

Companion disposition: state admission still belongs to the existing worker; keyed local lease replaces blocking checkpoint contention and forwards cancellation. Release adaptation: none.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 440c78ccf4d5d55a93aa59051d334dcdb3962547)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

1 participant