Skip to content

fix: confirm Stop after managed sandbox checkpoint cleanup - #172800

Merged
shakkernerd merged 2 commits into
mainfrom
fix/guest-stop-cleanup
Oct 15, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
fix/guest-stop-cleanup

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #172723.

What Problem This Solves

Stopping a guest run with an active command in a managed Docker or Podman workspace can report incomplete command cleanup after the process has already terminated. Command finalization then checkpoints the private checkout, but the checkpoint retains the run assertion that Stop has canceled. A helper that finishes cleanup after its parent exits can also lose the workspace owner before that checkpoint completes.

User Impact

Stop can settle accepted workspace changes after the request-owned command terminates, including when the parent exits first. New commands and file operations remain blocked. Conflicting edits, replaced session/worktree bindings, lost Gateway or operator authority, and real process cleanup failures still surface as errors. The repair uses the existing configuration and persisted formats.

Why This Change Was Made

The managed-workspace owner already holds the exact session incarnation, lifecycle revision, worktree binding, and database custody needed for reconciliation. Preparation now separates execution admission from settlement, and the sandbox context captures the original operator authority and existing Gateway ownership guard for settlement.

Accepted commands retain that same workspace owner through the backend's existing opaque finalization-token handoff. Parent disposal closes admission immediately; the finalizer releases retained custody after backend cleanup and checkpointing finish. File mutations likewise retain their owner through their checkpoint. Failed preparation and failed finalization release custody while preserving the failure. The existing reconciliation lease, conflict recovery, and process termination remain responsible for their operations.

The canonical workspace documentation describes this lifetime and its failure boundaries.

Evidence

The initial reproduction on 7e823106a77c63640806c0646c9dc8a21b35871f reaches the real Git/SQLite projection through the bound backend's finalizeExec and fails with AbortError: agent run aborted, code OPENCLAW_DIRECT_ABORT. A second deterministic reproduction on 976e58c disposes the parent workspace before finalization and fails with Local sandbox workspace authority changed. Both regression scenarios pass with this correction; no timer race is used.

The projection suite passed 25 tests, with its existing opt-in real Podman case skipped. It covers settlement after parent disposal, refusal of new shell/exec/file work, multiple accepted finalizers, real reconciliation conflicts, and replacement-session rejection. pnpm test src/gateway/worker-environments/local-workspace-projection.test.ts --maxWorkers=1 took 83.95 seconds; the original Stop and parent-disposal cases took 6.77 and 0.83 seconds. The exact-head main CI run passed in 837 seconds across 70 jobs; that is full-run wall time, not an estimate for this individual suite.

Two further cases enter through the real workspace/sandbox-context path with captured operator/profile authority, prepared run admission, and Gateway state ownership. Accepted output checkpoints after cancellation and foreground closure. A committed role revocation or released Gateway owner then rejects a pending finalizer before it changes the canonical file. These cases took 9.26 and 1.59 seconds. Only container execution is substituted in this harness; the authority and filesystem reconciliation owners are real.

Changed-file formatting/lint, the line-cap ratchet, refreshed type-graph discovery, and the affected production/test graphs passed. Five related caller and process-cleanup files passed 24 tests. Applicable unchanged consumer coverage is retained from the earlier 31-file run. The complete independent engineering and adversarial review is clean, including the original-owner lifetime correction and live runtime binding. The corrected full runtime build passed in 30 minutes 17 seconds, followed by the native private-QA build; the sandbox configuration E2E file passed all six tests in 31.25 seconds. A prior UI Stop diagnostic where the child and helper completed naturally is excluded from cancellation proof.

The corrected live guest UI run used the normal Stop button while the native reviewer was running and its request-owned helper was waiting. The click began 38 ms after the reviewer model event. chat.abort returned ok: true, aborted: true; the child was killed with zero pending descendants and no active children. The helper settled as killed/manual-cancel, exit 0, and its private output directory was empty. The UI showed Interrupted and the stopped child, with no incomplete-cancellation warning. Exit 0 here confirms cancellation cleanup, not a successful review verdict.

The served build was composition 3c24a1948fa984a3ee87ab971ee81a799923b807, with the two changed production files and UI tree identical to candidate 81c67bd539d91def9e47331981c5b56768af1cec. The remaining composition delta was inspected for the request, process, session and checkpoint contracts; it does not change this behavior. Build and restart succeeded with unchanged configuration. The recording includes the actual click sequence and clearly labels its end at +0.455 seconds before displaying a separately captured settled screenshot. Raw native receipts supply the later settlement facts.

Visual evidence

Open preview

Before After
Before: stopped child with a red warning that command cleanup could not be confirmed. After: Interrupted, child finished with stopped status, idle composer and no incomplete-cancellation warning.

Actual Stop interaction, followed by an explicitly labeled later settled screenshot

stop-proof.mp4

Visual verification

  • Baseline: da65be6
  • Exact head: 3c24a1948fa984a3ee87ab971ee81a799923b807
  • Scenario: Stop a guest parent while its native reviewer is running and its request-owned helper is waiting. Confirm child and helper cancellation, accepted checkpoint cleanup, and an idle composer without an incomplete-cancellation warning.
  • Runtime/build: Native source build of composition 3c24a1948fa9, containing candidate 81c67bd with identical changed production files and identical UI tree. Both build and restart succeeded; configuration stayed unchanged.
  • Stop timing: Normal Stop click began 38 ms after the reviewer model event; child was running and helper was waiting.
  • Native settlement: chat.abort returned ok:true and aborted:true; child killed, zero pending descendants; helper killed/manual-cancel, exit 0; private output directory empty.
  • Capture coverage: Actual timestamped capture ends 0.455 s after click start. A labeled transition leads to the separately captured settled screenshot; the video does not claim continuous capture of later cleanup.
  • Comparison conditions: Same 1280 × 720 viewport, dark chat UI and cancellation flow. Separate synthetic runs and sidebar selection differ; private labels and prompt text are redacted without covering Stop, child status or cleanup warning.
  • Original failing screenshot retained from the observed pre-fix run.
  • Matched changed production blobs and UI tree between candidate 81c67bd and served composition 3c24a1948fa9; relevant composition delta inspected.
  • Raw native receipts confirm one canceled running reviewer and request-owned helper, no remaining active descendants, and empty private output.
  • Stopped-child failed/stopped aggregate is the expected cancellation result, not a failed review verdict.
  • Parent-disposal and original operator/Gateway revocation boundaries also passed the real-authority owner harness.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@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: S labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 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: 81c67bd539d91def9e47331981c5b56768af1cec
  • Maintainer: @shakkernerd
  • Repository role: maintain

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

@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retains managed-workspace custody until accepted command cleanup and checkpointing finish after Stop or parent disposal.

Example: A guest command edits source.txt in a managed Docker workspace, then the user clicks Stop.

  • Before: The command terminates, but checkpointing rejects with OPENCLAW_DIRECT_ABORT and the UI reports unconfirmed cleanup.
  • After: Accepted edits finish checkpointing and the UI shows Interrupted without the cleanup warning, while new execution remains blocked.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by live-flow evidence, meaningful final-effect authority controls, and passing exact-head CI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Inspected before/after UI screenshots and the supplied live Stop receipts exercise the changed cleanup behavior on a served composition reported to contain identical production blobs; the real-authority reconciliation harness additionally verifies allowed settlement and refusal before canonical writes after operator revocation or Gateway release.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stop reports incomplete cleanup after the command has terminated because required managed-workspace settlement loses authority.
Reason: The maintainer-authored direction restores confirmed cancellation and accepted-output settlement while preserving denial of new work and genuine reconciliation failures.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current managed-sandbox cancellation defect, preserves live settlement authority, and has no actionable findings.

Priority: P2
Reviewed head: 81c67bd539d91def9e47331981c5b56768af1cec

Before merge

None.

Findings

None.

Agent review details

How this fits together

The sandbox adapter binds command execution and file operations to a session-owned private checkout; finalization reconciles accepted edits into the canonical managed worktree under live session, operator, and Gateway authority.

flowchart TD
  A[Guest run] --> B[Sandbox adapter]
  B --> C[Execution admission]
  C --> D[Docker or Podman command]
  D --> E[Retained finalizer]
  E --> F[Live workspace authority]
  F --> G[Canonical checkpoint]
Loading

Technical review

Best possible solution:

Land the focused lifetime repair using the existing workspace owner, reconciliation lease, and live authority checks.

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

Current-main source shows finalization calling checkpoint through the canceled run assertion; the submitted reproductions report the matching OPENCLAW_DIRECT_ABORT failure and a separate parent-disposal failure, but no target code was executed during this review.

Is this the best way to solve the issue?

The repair addresses the owning lifetime invariant without reacquiring replacement authority or swallowing checkpoint failures; inspected callers already carry the opaque finalization token, and execution admission retains its original checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Managed-workspace checkpoint and disposal lifetime changes intended behavior with a stated reason (28d8ee4: The original managed-project implementation isolated guest source and reconciled accepted changes through an exact session-owned workspace; immediate disposal and the shared execution assertion did not distinguish accepted cleanup from new work.)
  • Command preparation and checkpoint admission keeps the original intent (ebf89c9: Command preparation and shell calls wait for checkpoint custody to end, with canceled waiters prevented from dispatching into a paused runtime.)
  • Gateway custody and prepared session authority keeps the original intent (df346f5: Sandbox preparation must remain under its original live Gateway owner rather than allowing foreign or released ownership to perform mutations.)
  • Worker-backed session and worktree predicates keeps the original intent (cbc53ac: Session reads and authority move through prepared worker facts while the Gateway remains the database owner; this PR retains that existing owner rather than creating another authority path.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced diff separates execution admission from settlement and retains the existing workspace owner through opaque finalization tokens and file-mutation cleanup. (src/agents/sandbox/local-workspace.ts:25, 81c67bd539d9)
  • Current main still has the defect: Current main passes the run assertion into the workspace owner and uses that same owner for checkpointing; Stop therefore invalidates required settlement, and parent disposal releases custody immediately. (src/agents/sandbox/local-workspace.ts:26, 4542896b10d1)
  • Original authority remains enforced: Settlement captures the original operator authority and Gateway ownership assertion; the existing owner retains exact session incarnation, lifecycle revision, and worktree predicates. (src/agents/sandbox/context.ts:280, 81c67bd539d9)
  • Final-effect negative controls: The production-owner harness settles accepted edits after abort and parent disposal, then commits operator revocation or releases Gateway custody and verifies that pending finalization cannot change canonical source.txt; only container execution is substituted. (src/gateway/worker-environments/local-workspace-cancellation.test-support.ts:257, 81c67bd539d9)
  • Inspected live-flow evidence: The downloaded before screenshot shows the incomplete-cancellation warning; the after screenshot shows Interrupted, a stopped child, and an idle composer without that warning. The PR records chat.abort returning ok:true and aborted:true, killed descendants, and helper cleanup after an actual Stop click. (81c67bd539d9)
  • Inspection limitations: Video preparation reports 'ffprobe failed: spawnSync ffprobe ENOENT'; browser fetch returned Cache miss, and local browser preparation was blocked because the advertised scratch directory is read-only. The served composition commit is absent locally, so its stated blob equivalence could not be independently compared. File-follow history also reached unavailable objects. These are reviewer-side limits, not contributor defects.

Likely related people:

  • Shakker: Raw commit ebf89c9 adds src/agents/sandbox/local-workspace.ts:112 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ebf89c91cb78; files: src/agents/sandbox/local-workspace.ts)
  • Peter Steinberger: Raw commit df346f5 adds src/agents/sandbox/context.ts:526 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: df346f5729d0; files: src/agents/sandbox/context.ts)

PR surface

Source +73, Tests +354, Docs +6. Total +433 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 107 34 +73
Tests 4 368 14 +354
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 481 48 +433

Review metrics

Metric Value Why it matters
Production versus test changes Production +107/-34 lines; tests and test support +368/-14 lines. Production growth implements retained cleanup custody; the larger test change exercises cancellation, parent disposal, conflicting edits, replacement sessions, and live authority revocation through real reconciliation owners.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster. Replaced prior rating: 🦪 silver shellfish.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The defect affects Stop confirmation and accepted workspace settlement for managed local sandboxes, with a limited surface and no established broader outage or data loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster. Replaced prior rating: 🦪 silver shellfish.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-15T04:07:41.169Z sha 976e58c :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-15T04:58:31.519Z sha 81c67bd :: needs maintainer review before merge. :: none

Reviewed October 15, 2026, 1:11 AM ET / 05:11 UTC (Revision 3).

@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@shakkernerd shakkernerd self-assigned this Oct 15, 2026
@shakkernerd
shakkernerd merged commit fe60f48 into main Oct 15, 2026
158 checks passed
@shakkernerd
shakkernerd deleted the fix/guest-stop-cleanup branch October 15, 2026 05:38
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: Stop now confirms cancellation after accepted managed-workspace command cleanup finishes.

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

Preserve managed-workspace settlement authority until accepted command cleanup finishes, so Stop confirms cancellation after checkpointing while new execution and revoked authority remain blocked.

Fixes openclaw#172723.
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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Stop reports command cleanup failure during managed sandbox checkpoint

1 participant