Skip to content

perf(sandbox): run registry reservation and removal transactions in the executor - #165558

Merged
steipete merged 4 commits into
mainfrom
dbasync/w4sbxreg
Oct 5, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/w4sbxreg

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sandbox reservation and removal-intent transactions still executed shared-state SQLite on the Gateway thread during provisioning, recreate, and pruning.

Why This Change Was Made

Run both transactions through the existing shared-state executor. The worker selects the authoritative reservation and evaluates typed prune criteria against current rows. Remove the superseded host transactions and now-private kernel exports.

Accepted removal retains its original physical database and generation through provider work. Terminal deletion uses the existing cleanup worker with current host grants and an exact-generation predicate. Gateway shutdown seals new removals before scheduler cancellation and joins accepted settlement; this association survives direct database close/reopen while the Gateway remains live.

User Impact

No schema, configuration, or stored-format changes. Released sandbox callback signatures stay unchanged. Synchronous generation checks remain intentionally retained: these callbacks span provider waits and deferred process launch and must observe foreign removals. Async companions remain next-SDK-major work; there is no authority cache or prepared-row substitute.

Production: +405 / -161 / net +244; 566 changed lines. No new OPENCLAW_* names.

T1 same-rules ratchet: 882 → 879 globally; 4 → 1 in this lane. The original five-site audit also included the insertion helper, now worker-only; the ratchet applies that classification to both revisions rather than crediting metadata alone. The common live-generation row reader remains T1.

Overlap: #131941 touches sandbox activity/pruning; #162433 is the separate umbrella ownership design. This change keeps its scope to registry transactions and their settlement.

Retained follow-up debt: the pre-existing browser/retirement caller guard at src/agents/sandbox/registry.ts:56 can recheck other owners synchronously, including the session/worktree assertions in src/gateway/worker-environments/local-workspace-projection.ts:282. Those checks remain live in grants; the zero-caller-SQL boundary applies to the moved reservation/removal operations, not these retained other-owner guards.

Evidence

Instrumented, warmed real-entry MAIN SQL counts:

Entry point Before After
resolveSandboxContext 23 15
removeSandboxContainer 9 0

These are executed-statement counts, excluding prepare calls, from the same synthetic fixture; they are not a latency claim. The final native-boundary regression proves zero caller-thread SQL for reservation, removal, and readback.

  • Four final core regressions passed with --maxWorkers=1: zero caller SQL, stale-prune refusal, direct database-close settlement, and Gateway shutdown after database reopen. Command wall time: 578.02s, including 289.681s worker preparation.
  • Eight focused lifecycle/regression tests passed in 466.35s, including supervisor-admission removal and retained-handle revocation. Earlier race fixtures were corrected to wait for actual removal-intent acknowledgement instead of assuming read discovery implied commit.
  • Eleven caller/import suites passed: 56 tests, 524.56s, with --maxWorkers=1. Includes runtime-process-build-graph, shared-state worker imports, and reply import closure. Existing host-owned project routing covers the changed callers; no new worker pins or serial configuration.
  • Both review-discovered close races were reproduced before their fixes. Independent Codex P2 review with Ultrafast is clean after resolution.
  • Core and all test-type shards, formatting, native schema compatibility, core/script lint, remaining constituent static guards, and both import-cycle checks passed (Madge: zero cycles). Database worker ratchet passed.
  • SDK diff: 0 entrypoints added/removed, 0 direct export-declaration changes, 128 reachable declaration-closure changes; acknowledgement digest 38618131. The report follows declaration modules through SandboxRegistryEntry type imports, so it includes the internal facade's async reservation signature and new kernel declarations. Public callback/entry shapes are unchanged. SDK surface budget passes: 151 public entrypoints, 3,652 exports, 2,113 callable exports; no budget increase.
  • Published-driver update cell passed on isolated Linux: 2026.9.8 → candidate ff398b3a90a4, with the commit and all changed runtime hashes verified before packaging. Durable/incognito before-and-after probes passed; final phase finished, readiness HTTP 200, running candidate version verified. Package build/integrity: 740.13s; complete cell: 518.50s (actual updater 422.07s). Testbox admission timed out and AWS quota fallback provided insufficient memory; both leases were stopped. The successful Hetzner run used the existing Docker bootstrap after standard hydration omitted Docker. No budget caps were raised.

check-changed encountered inherited dead-export findings for GoogleMeetJoinResult (extensions/google-meet/src/transports/types.ts), resolveGatewayWorkboardWorkspaceAccess (extensions/workboard/src/gateway-helpers.ts), and MeetingRuntimeOwner (src/meeting-bot/runtime-facade-types.ts). Their declarations and reference sets are unchanged from base b658e685c314d154946358293b190e1fd3ad7c4d; the final export scan reports no sandbox findings. Remaining constituent checks run explicitly, without suppressing the failed gate. Final CI run wall time was 10m24s for the entire selected workflow; this is not an incremental test-cost measurement.

Landing verification at a8ec3471820e7: the original focused sandbox change remains 17 files with no additional sandbox production changes. Merge commits d3dae1553b8d, 59b2568238ac, and a8ec3471820e7 incorporated three available main fixes; none needed conflict resolution or a rebase. Fresh Codex P2 review is clean. After the final integration, pnpm tsgo:core, all 27 pnpm tsgo:core:test shards, and the separate test/tsconfig/tsconfig.test.root.other.json type graph pass; Madge reports zero cycles.

Released v2026.9.8 SDK subpaths and api.runtime.sandbox do not expose the changed internal reservation/removal functions or removed kernel exports. Public synchronous callbacks remain unchanged. The refreshed SDK report (f1930848efe6 → d3dae1553b8d, digest 28ac6e6d) reports 0 entrypoints added/removed, 0 direct export changes, and 128 reachable declaration changes. Subsequent integrations change none of the sandbox, sandbox SDK, or plugin-runtime type inputs, so this report remains applicable to the unchanged PR delta. Existing database-worker and forked host-owned projects cover all affected direct and indirect callers; no routing additions are needed.

CI failure attribution:

  • Run 37307334966, original head ff398b3a90a4: the sole root was a 17-file Madge cycle introduced on main by 1b7d11db6a98. It reproduced identically on clean main 91dc92261fda; all component and scanner inputs matched the CI baseline and tested merge. Main fixed it in 21901766c534, incorporated by the first merge. Scheduled main had skipped Madge, explaining its otherwise green guard result.
  • Run 37312368035, head d3dae1553b8d: two tooling shards failed because main's cycle fix omitted deferred-plugin-migrations.contract.ts from the wrapper extraction inventory. Import closure reproduced 5/5 on both PR and main. Whole macOS provisioning files failed only with that missing module. Isolated Linux repeated all three failing provisioning cases 5/5 on each immutable head (d3dae1553b8d and f1930848efe6), including the Linux-only case; every repetition reported the identical missing contract. Main fixed the inventory in 044859704eba, incorporated by the second merge. Testbox was stopped after 15 minutes without admission; the authorized AWS comparison completed, and both leases were stopped/released.
  • Run 37319338085, head 59b2568238ac: the sole root was test/gateway-rpc-exporters.test.ts:110 TS2322, where main 3e7f2d88803e assigned descriptors with optional profileAccess to the normalized array requiring it. The exact root-other type graph reproduced the sole error 5/5 on main and 5/5 on the PR, with identical relevant source and compiler inputs. Main fixed the fixture in b9f2ea649750, incorporated by the third merge; the formerly failing type graph now passes locally.

The earlier PR-context check was corrected by using the required template headings; its replacement passed. No CI rerun was used merely to obtain green, and no admin exception has been used. Final-head CI run 37325029113 passed: 61 successful jobs, 24 conditionally skipped, no failed or cancelled jobs. ClawSweeper completed review of a8ec3471820e752a72bd30824ebc847df7ba3c59 at 2026-10-05 14:36 UTC with no actionable findings.

…he executor

Keep reservation selection and removal intent in the existing shared-state writer. Retain live synchronous generation checks for released sandbox callbacks. Join accepted removal across scheduler cancellation, direct database close, and database reopen while the Gateway remains live.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 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: a8ec3471820e752a72bd30824ebc847df7ba3c59
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/sandbox/backend.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/prune.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/registry-lifecycle.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/registry-write.worker.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/registry.kernel.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/registry.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 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 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 10:59 AM ET / 14:59 UTC (Revision 8).

ClawSweeper review

What this changes

Moves sandbox reservation and removal transactions into the existing SQLite worker and makes Gateway shutdown wait for accepted removal cleanup.

Merge readiness

✅ Ready for maintainer review

Keep open: the change remains useful because inspected main and the latest release still execute these transactions on the caller thread. No actionable introduced defect was found, and GitHub confirms successful CI for the pinned head.

Priority: P2
Reviewed head: a8ec3471820e752a72bd30824ebc847df7ba3c59

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker migration with relevant runtime observations, lifecycle regressions, preserved public contracts, and successful exact-head CI.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Recorded production-entry SQL observations and an isolated Linux update cell support the worker cutover; inspected regressions cover revocation and shutdown settlement. No stored-data contract changes were found.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Recorded production-entry SQL observations and an isolated Linux update cell support the worker cutover; inspected regressions cover revocation and shutdown settlement. No stored-data contract changes were found.
Evidence reviewed 10 items Pinned introduction and current-main necessity: The introduced delta moves reservation and removal intent out of host transactions. Independently inspected fetched main still implements both with runOpenClawStateWriteTransaction in the registry facade.
Latest release retains caller transaction: The registry source at v2026.9.8 still reserves synchronously using the host write transaction; this PR's reservation cutover is not already shipped there.
Worker authority and authoritative selection: The real worker requests transaction and commit admission around synchronous registry operations. Removal selection checks backend, scope, creation generation, and current-row prune eligibility.
Findings None None.
Security None None.

How this fits together

The sandbox registry records runtime allocations used by provisioning, recreation, and pruning. Its worker commits reservation and removal decisions, while backend managers perform provider operations and Gateway lifecycle code joins their cleanup.

flowchart TD
  A[Provision or prune request] --> B[Live host authority]
  B --> C[Shared SQLite worker]
  C --> D[Authoritative registry decision]
  D --> E[Sandbox backend operation]
  E --> F[Exact generation cleanup]
  G[Gateway shutdown] --> F
  F --> C
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +244, Tests +250, Docs +16, Other +1. Total +511 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 9 405 161 +244
Tests 4 267 17 +250
Docs 1 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 3 3 2 +1
Total 17 691 180 +511

Review metrics

Metric Value Why it matters
Production versus test growth production net +244 lines; tests net +250 lines Production growth is justified by accepted-removal settlement across provider waits, database closure, and Gateway shutdown.

Technical review

Best possible solution:

Keep one shared-state transaction owner, bind cleanup to its original database and generation, and preserve released synchronous sandbox callbacks.

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

Not applicable as a reported product bug; caller-thread transaction placement is directly visible on inspected main, and the PR supplies before/after execution counts.

Is this the best way to solve the issue?

Yes: extending the existing executor removes the host transactions while keeping reservation policy, public callbacks, and terminal cleanup under their established owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime performance and lifecycle improvement without an established urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 verified repository-admin author is exempt from ordinary contributor proof. Recorded production-entry SQL observations and an isolated Linux update cell support the worker cutover; inspected regressions cover revocation and shutdown settlement. No stored-data contract changes were found.

Evidence

What I checked:

  • Pinned introduction and current-main necessity: The introduced delta moves reservation and removal intent out of host transactions. Independently inspected fetched main still implements both with runOpenClawStateWriteTransaction in the registry facade. (src/agents/sandbox/registry.ts:156, bb3a8a9ac304)
  • Latest release retains caller transaction: The registry source at v2026.9.8 still reserves synchronously using the host write transaction; this PR's reservation cutover is not already shipped there. (src/agents/sandbox/registry.ts:146, fc23bc864e45)
  • Worker authority and authoritative selection: The real worker requests transaction and commit admission around synchronous registry operations. Removal selection checks backend, scope, creation generation, and current-row prune eligibility. (src/agents/sandbox/registry-write.worker.ts:22, a8ec3471820e)
  • Bounded terminal cleanup authority: Removal captures the physical database identity and generation before provider work. Terminal cleanup retains current host checks at worker grants and uses the existing exact-generation deletion predicate; the cleanup-store owner refuses a replaced physical database. (src/agents/sandbox/registry-lifecycle.ts:108, a8ec3471820e)
  • Shutdown and race regressions: Inspected tests exercise real SQLite workers for caller-thread SQL exclusion, activity advancing after prune discovery, and removal across database close. The Gateway regression verifies admission sealing, scheduler cancellation, provider settlement, and final row deletion after database reopen. Tests were inspected, not executed during this read-only review. (src/gateway/server-close.sandbox-registry.test.ts:27, a8ec3471820e)
  • Captured runtime and upgrade evidence: The supplied complete PR body reports warmed production-entry SQL counts of 23 to 15 for sandbox context resolution and 9 to 0 for container removal, plus an isolated Linux published-driver update from 2026.9.8 to ff398b3 with HTTP 200 readiness and durable/incognito probes. These are recorded observations, not reviewer reruns; later integrations are reported to leave sandbox runtime inputs unchanged. (ff398b3a90a4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-10-05T12:09:40.723Z sha ff398b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T12:20:38.621Z sha ff398b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T12:42:06.881Z sha ff398b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T12:55:46.452Z sha d3dae15 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T13:54:43.672Z sha 59b2568 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T14:14:58.548Z sha 59b2568 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T14:36:36.853Z sha a8ec347 :: needs maintainer review before merge. :: none

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 7f4cf34 into main Oct 5, 2026
154 checks passed
@steipete
steipete deleted the dbasync/w4sbxreg branch October 5, 2026 15:14
@steipete

steipete commented Oct 5, 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 6, 2026
…he executor (openclaw#165558)

Keep reservation selection and removal intent in the existing shared-state writer. Retain live synchronous generation checks for released sandbox callbacks. Join accepted removal across scheduler cancellation, direct database close, and database reopen while the Gateway remains live.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: L 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