Skip to content

fix(sandbox): resume btrfs workspaces after atomic checkpoint capture - #196662

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-checkpoint-pause-duration-20260919
Nov 10, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-checkpoint-pause-duration-20260919

Conversation

@steipete

@steipete steipete commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Changed sandbox commands freeze the guest throughout workspace discovery, Git capture, and canonical reconciliation. With large workspaces, scanning alone can take seconds while every process in the container is paused.

User Impact

For provisioned btrfs subvolumes, checkpoint now pauses for the existing native snapshot operation, resumes the guest, and synchronizes canonical state from that captured tree. Command completion still waits for canonical acceptance, preserving read-after-command consistency. Initial recovery and imports retain their existing pause boundaries. No configuration, schema, dependency, or cache is added.

Why This Change Was Made

The checkpoint owner reuses the template backend's native copy primitive under its existing lease. Snapshot fingerprints translate only the proven snapshot device back to the source identity, preserving unchanged probes. Btrfs omits nested subvolumes: the manifest walker detects its inode-2 placeholders before accepting a receipt, then re-pauses under the same lease and uses the existing complete Git capture. Unsupported backends and ordinary directories also retain that path, resuming after durable capture.

The owner removes its private capture after resume and removes leftovers on the next lease. Native removal now repairs inaccessible directories only after a permission failure; it does not follow symlinks or change live source permissions. This is required for snapshots containing ordinary read-only workspace directories.

Snapshot creation can wait for btrfs dirty-data writeback, so this bounds the paused work rather than promising a fixed wall-clock limit. Recursive snapshot cleanup adds work after resume; the native comparison will report that cost explicitly.

Evidence

The real Podman+btrfs comparison completed all five counterbalanced pairs: 50 measured mutating commands per arm, plus two A/A controls. Every command passed canonical and subsequent guest read checks. The fixture contains 62,000 synthetic files / 1.1 GB, 10,001 session metadata rows, and a 33.65 GiB synthetic database. No production data was used.

Metric Parent Atomic capture
Pause p50 / p95 / max 1,619.63 / 1,830.52 / 4,497.19 ms 194.23 / 241.48 / 269.72 ms
Command p50 / p95 / max 2,374.14 / 2,854.99 / 7,252.07 ms 3,038.07 / 3,665.20 / 4,221.59 ms
Whole-cgroup CPU per command 3,493.06 ms 4,472.75 ms
Main-isolate allocation per command 19.22 MB 20.49 MB

Median pause improves 88%; median command latency and whole-cgroup CPU increase 28%. A/A pause, command and CPU spread was about 1–1.3%; allocation spread was 9.4%, so no allocation benefit is claimed. All pairs, including the slower first candidate arm, are retained. The 1.36–1.42 s manifest scan runs paused on the parent and unpaused on the candidate in all 50 commands. Native snapshot copy takes 106 ms median; recursive cleanup takes 511 ms after resume. Cleanup explains most of the extra command latency. The maximum guest heartbeat gap falls from 4.43 s to 243 ms.

Timing uses parent 3f17d921f6cc1cf03d52054a74ba3a5e885f5c35 and implementation 64147937916763407221bef031a138af43dd40a8, with the same frozen harness. Final head 32b8f86f7fc49989f7ae6ab5c1346831b82b5be6 changes only type placement and emits byte-identical JavaScript. The harness runs on a task-owned Linux ARM64 rig with four CPUs and 12 GiB memory, Podman 4.3.1, btrfs 6.2, and Node 26.12.1 for allocation accounting. CPU includes native helpers, Git and the guest; allocation covers only the main V8 isolate. Separate baseline/candidate profiles passed and are excluded from these timing distributions. Final-head native nested-subvolume fallback also passed: two pauses of 180.84 and 5,387.44 ms, complete nested canonical contents, correct next guest read, preserved 0555 source permissions, and no capture artifact. The matching baseline paused 5,947.87 ms; both perform full hashing because the existing fingerprint format rejects mixed-device reuse. This single diagnostic pair is excluded from performance statistics and is not a timing-improvement claim. An oversized 20-command functional run hit its 240-second deadline after at least 17 completed commands; that partial run is retained, and the bounded follow-up changed only the proof driver loop count to one.

  • Atomic ordering regressions fail on the prior head because manifest scanning still observes a paused guest. Final affected replay: 17 passed, including seven authority-loss cases. Broader touched-owner proof before the operation-file extraction: 125 passed, two existing platform skips.
  • Read-only artifact removal regression fails before the fix with EACCES; all ten native-owner tests now pass. Real Linux btrfs create/copy/remove also passes as UID 501 with no effective capabilities, preserving live nested contents and read-only modes.
  • Final pnpm check:changed --base 3f17d921f6cc1cf03d52054a74ba3a5e885f5c35: all categories pass except the exact inherited unused-export set below. These are existing main regressions, not passing checks.
  • Independent Codex review of the final atomic implementation: scoped-clean through P2, with final source-integrity verification. Prior-head green CI and hosted reviews do not cover this revision; fresh exact-head checks remain required.

Production delta: +199 lines, including snapshot lifecycle/cleanup, nested-subvolume fallback, and source identity preservation. Moving the existing projection operation whole keeps one lifecycle owner within the line cap. Test delta: +245 lines for ordering, recovery, fingerprint reuse, fallback, authority loss, and artifact permissions. Benchmark code is proof-only.

CI on 64147937916763407221bef031a138af43dd40a8 found one introduced static type-import cycle. The repair moves the capture contract into the existing workspace types module and imports it directly. The exact failing guard is red on that head and green after repair; targeted typechecking passes. All six changed files emit byte-identical JavaScript, so the native comparison remains runtime-equivalent. The repair is committed as 32b8f86f7fc49989f7ae6ab5c1346831b82b5be6 and passes fresh Codex review. Final exact-head CI 42832460455 passed. ClawSweeper re-reviewed this head with zero findings and zero open items; item 1 response. No admin exception or CI rerun was needed.

Exact-parent unused-export regression attribution

Both Knip scans exit 1 on parent 3f17d921f6cc1cf03d52054a74ba3a5e885f5c35; normalized symbol sets match the final candidate check exactly, with no module-resolution failures. Owner history and consumer-removal patches identify these sources:

Export owner / symbols Introducing commit / PR Cause
compaction-safeguard-quality: nestRequiredSummaryHeadings c7152f3 / #196207 Formatting moved into owner; external consumer removed.
models-config: planOpenClawModelsJsonSource; openclaw-tools: filterToolsByClientCaps; auth-storage: AuthCredential, AuthStatus, AuthStorageBackend; model-registry: ResolvedRequestAuth; linux-oom-score: resolveOomScoreWrappedCommand, spawnWithInheritedOomScore 625945b / #192552 Consumers moved to leaf owners; facade exports retained.
tool-search-directory: MAX_MCP_TOOL_DIRECTORY_BYTES, sanitizeMcpToolDirectoryDescription 80ba593 / #196252 Added exports with only test external consumers.
config-write-flow: replyWithBillingRouteWarnings 56617cd / #191326 Export only externally used by tests; #196570 adds a test use, not the regression.
provider-external-auth: resolveExternalAuthProfilesWithPlugins 071f606 / #139911 Native binding bypasses facade.
provider-runtime: augmentModelCatalogWithProviderPlugins, formatProviderAuthProfileApiKeyWithPlugin, loginProviderOAuthWithPlugin, refreshProviderOAuthCredentialWithPlugin, resolveProviderOAuthCredentialWithPlugin, resolveProviderOAuthRefreshCapabilityWithPlugin f63e5cd / #190205 Lazy runtime binders moved to auth/catalog owners.
provider-runtime: classifyProviderFailoverSignalWithPlugin, resolveExternalAuthProfilesWithPlugins 964fa99 / #132716 Callers moved to leaf owners.
provider-runtime: resolveProviderModernModelRef 33d8f24 / #129184 Caller moved to test helper.
provider-runtime: resolveProviderRuntimePlugin a7436c8 Split provider hook runtime seam; transcript-policy moved to leaf owner. No PR number in commit message.
plugins/types: ProviderAuthOptionBag, ProviderNonInteractiveApiKeyCredentialParams, ProviderNonInteractiveApiKeyResult, ProviderResolveNonInteractiveApiKeyParams cf1ae7b / #190544 Consumers moved to provider-auth-types.
shared/browser-pair: BROWSER_PAIR_CODE_LENGTH d85ebfe / #191513 Export introduced with internal use only.

The full-scan set is the heading helper, client-cap facade, four provider auth types, spawnWithInheritedOomScore facade, and browser constant. This identifies unused export surfaces, not necessarily unused implementations.

Keep command finalization awaiting canonical acceptance and retain paused imports and recovery. Resume only after the newly captured export has a durable Git result; later guest writes remain available for the next checkpoint.
@clawsweeper

clawsweeper Bot commented Nov 10, 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 scripts Repository scripts docker Docker and sandbox tooling agents Agent runtime and tooling size: L labels Nov 10, 2026
@steipete
steipete marked this pull request as ready for review November 10, 2026 12:28
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review head 2705620, especially the distinction between newly captured command exports and paused import/recovery settlement. Command finalization still awaits canonical acceptance; the new regression covers a later guest write during both normal and interrupted acceptance. Native Podman+btrfs performance comparison remains pending and will be added before merge.

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 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-10T14:20:51.120476Z 32b8f86 New commits
ℹ️ 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.

@github-actions

github-actions Bot commented Nov 10, 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: 32b8f86f7fc49989f7ae6ab5c1346831b82b5be6
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

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

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR resumes eligible btrfs sandboxes after snapshot capture while canonical synchronization continues.

Example: A command edits a provisioned btrfs workspace containing 62,000 files.

  • Before: Reported median guest pause was 1,619.63 ms.
  • After: Reported median pause is 194.23 ms, while median command completion increases from 2,374.14 to 3,038.07 ms.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent implementation with the prior blocker repaired and meaningful native measurements; the declared native fallback validation remains incomplete.
Proof confidence 🦐 gold shrimp (3/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: Performance · Worth it: Yes · Fix scope: Complete
User problem: Background guest processes freeze for seconds while changed workspaces are scanned and synchronized.
Reason: Native measurements show a substantial freeze reduction, and the maintainer-authored proposal records the accompanying command-latency and CPU increase.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a concrete sandbox freeze, and the previous import-cycle finding is fixed; no new actionable code defect was found.

Priority: P2
Reviewed head: 32b8f86f7fc49989f7ae6ab5c1346831b82b5be6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Complete the declared native btrfs nested-subvolume checkpoint run, showing preserved canonical contents, resumed guest execution, and capture cleanup.
Agent review details

How this fits together

Sandbox command finalization exports private workspace changes through the leased checkpoint owner into the canonical managed worktree.

flowchart LR
  A[Guest command] --> B[Checkpoint lease]
  B --> C[Paused snapshot capture]
  C --> D[Resumed guest]
  C --> E[Captured manifest and Git result]
  E --> F[Canonical acceptance]
  F --> G[Command completion]
Loading

Technical review

Best possible solution:

Keep capture and canonical acceptance under the existing checkpoint lease, using atomic snapshots where complete and durable Git capture elsewhere.

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

Current-main source keeps changed-workspace scanning inside quiescence, and the submitted native parent comparison records the resulting guest pauses; no target code was executed during this review.

Is this the best way to solve the issue?

The change reuses existing snapshot, lease, staging, and acceptance owners; its fallback and cleanup serve the same invariant without adding another state owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Shakker: Raw commit 4c3fd8a adds src/agents/sandbox/local-workspace-quiescence.ts:344 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 4c3fd8a08b56; files: src/agents/sandbox/local-workspace-quiescence.ts)
  • RoboClaw: Raw commit 28d8ee4 adds src/agents/sandbox/local-workspace-quiescence.ts:203 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 28d8ee4f096b; files: src/agents/sandbox/local-workspace-quiescence.ts)

PR surface

Source +199, Tests +245, Docs +197, Other +259. Total +900 across 20 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 341 142 +199
Tests 6 356 111 +245
Docs 2 201 4 +197
Config 0 0 0 0
Generated 0 0 0 0
Other 2 304 45 +259
Total 20 1202 302 +900

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
Production versus regression-test growth Production +199 lines; tests +245 lines Growth covers snapshot lifecycle, complete fallback, fingerprint identity, recovery ordering, and private-artifact permissions while retaining one operation owner.

Labels

Label changes:

  • add P2: Reduces disruptive freezes for changed commands in eligible local btrfs sandboxes, with a measured and disclosed completion-cost tradeoff.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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: Reduces disruptive freezes for changed commands in eligible local btrfs sandboxes, with a measured and disclosed completion-cost tradeoff.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-10T12:33:28.914Z sha 2705620 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-10T14:09:18.126Z sha 6414793 :: needs changes before merge. :: [P2] Move the capture type into a leaf contract to break import cycles

Reviewed November 10, 2026, 9:26 AM ET / 14:26 UTC (Revision 3).

@steipete
steipete marked this pull request as draft November 10, 2026 13:03
@steipete

Copy link
Copy Markdown
Contributor Author

Performance acceptance is not met by the current head. The first matched native Podman/btrfs pair measured pause median 1600.88 → 1582.71 ms (-1.1%), versus 1.1% spread between baseline control medians; complete command median rose 2323.88 → 2490.04 ms (+7.2%). Manifest scanning dominates the pause. All read-after-command assertions passed, but these measurements do not justify claiming the long-freeze issue is solved.

I am revising the implementation to use the existing atomic btrfs snapshot primitive for provisioned subvolumes, with nested-subvolume omission detection before acceptance and a paused retry when needed. Snapshot disposal cost will be measured outside the pause. The current PR is held as draft until this path and its native proof are complete. No merge is requested.

@steipete steipete changed the title fix(sandbox): resume captured commands before canonical synchronization fix(sandbox): resume btrfs workspaces after atomic checkpoint capture Nov 10, 2026
@steipete
steipete marked this pull request as ready for review November 10, 2026 14:00
@steipete

Copy link
Copy Markdown
Contributor Author

The PR now implements atomic btrfs capture at head 64147937916763407221bef031a138af43dd40a8, superseding the earlier durable-Git-only candidate. The body describes nested-subvolume fallback, source fingerprint identity, artifact cleanup, focused red/green tests, and the ongoing native comparison. Independent local Codex review is scoped-clean through P2. Prior ClawSweeper review had zero open items; please review this new final implementation. Performance measurements remain a merge gate.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. label Nov 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing every open item in the latest review on 64147937916763407221bef031a138af43dd40a8:

  1. Move the capture type into a leaf contract: fixed in 32b8f86f7fc49989f7ae6ab5c1346831b82b5be6. The unchanged contract now lives in local-workspace-types.ts:6. Consumers import it directly: checkpoint:14, fingerprints:4, manifest-scan:47, state:38, and fingerprints test:13. There is no checkpoint re-export. The exact Madge guard reproduced one SCC before this fix and reports zero afterward; targeted typechecking and formatting pass. All six files emit byte-identical JavaScript, preserving the ongoing native performance comparison. Fresh local Codex review is scoped-clean through P2.

The previous CI failure was introduced by this PR, not inherited. Fresh exact-head CI is required. Native comparison and final fallback proof remain merge gates.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@steipete
steipete merged commit 10d6744 into main Nov 10, 2026
166 of 168 checks passed
@steipete
steipete deleted the steipete/perf-micro-checkpoint-pause-duration-20260919 branch November 10, 2026 14:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…openclaw#196662)

* fix(sandbox): resume captured commands before canonical synchronization

Keep command finalization awaiting canonical acceptance and retain paused imports and recovery. Resume only after the newly captured export has a durable Git result; later guest writes remain available for the next checkpoint.

* test(sandbox): measure checkpoint manifest owner phases

* fix(sandbox): capture btrfs checkpoints before resuming synchronization

* fix(sandbox): keep checkpoint capture types out of runtime owners
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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