Skip to content

fix(sandbox): improve agent throughput and sandbox reliability - #4177

Merged
yannickmonney merged 15 commits into
mainfrom
fix/agent-sandbox-audit-complete
Oct 4, 2026
Merged

yannickmonney merged 15 commits into
mainfrom
fix/agent-sandbox-audit-complete

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keep agent work moving when one answer, sandbox, disk, or Docker operation stalls. Recovery rotates unreachable runs fairly, direct chat immediately reuses each available worker slot, and delayed progress cannot regress an active run's heartbeat. Sandbox creation and staging share cancellation budgets; failed creates preserve workspace data and remove only their own container incarnation.

Build on main's existing journal, replay protocol, projection, Docker capability, and ownership contracts:

  • Add durable recovery visit clocks (migration 0150), skip-locked claims, bounded cancellable probes, and a race-safe missing-op claim.
  • Bound replay attachments, reject invalid cursors, refuse incomplete transcripts, and carry staging/status cancellation through every service hop.
  • Bound whole Docker creation and optional BuildKit setup, cancel expired queued operations, keep cleanup independently bounded, and size solver parallelism from configured CPUs.
  • Count nonterminal Kubernetes pods plus local create reservations, return retryable responses for unknown session state, and warm images without blocking control traffic.
  • Make existing skill-staging coverage deterministic under concurrent uploads while preserving prompt order and checking every file's exact contents.

Checklist

  • Full root bun run check passes: 58/58 tasks, 34 cached, exit 0.
  • Fresh local SAST passes with zero findings; analysis limits are recorded below.
  • Translations: no new UI message keys; affected operator documentation is updated in EN/DE/FR.
  • Docs, sandbox/runtime/build-helper/backend READMEs, and .env.example are updated. Root multilingual READMEs are N/A because installation entry points are unchanged.
  • Automated coverage is registered in the manual-test map; lint:manual passes (5 trees, 1,447 boxes).
  • All six final hosted workflows complete successfully on their first attempt; advisory image findings and analysis limits are recorded below.

Test plan

Final head: 824a7cde660d6d9da5377ab06aff046caf74c08a, integrated with main d29a3c8fe78cdba54d247fe82ea5195f702c0651. Full local checks, exact-head PostgreSQL integration and full SAST have passed. Hosted workflows pin merge candidate 91387103b8e52d95f4202d800d60c1b91cf697b8; its file tree exactly equals this local head. All six hosted workflows completed successfully on their first attempt, including the actual container smoke, image-validation, runtime behavior and advisory scan steps. Earlier candidate results are historical only.

  • Combined sandbox suite: 1,024 passed / zero failures, 50 files; targeted client/protocol/routes/Docker-create/device/disk checks 312/312. Full types and lint pass.
  • Combined runtime: 332 passed / 15 platform-specific skips / zero failures, 26 files. Full types and lint pass uncached. Incoming inner-Docker health/protocol/entrypoint behavior is preserved with bounded replay readers, cursor refusal, cancellation and zero-write protection.
  • Combined platform intersections: 224/224 tests across 14 files, full platform types and lint green. Incoming strict SSE validation retains cancellation, retryable reader admission, and complete refusal of incomplete legacy results.
  • Both migrations retain their original contents: main’s 0149_in_place_retry_state.sql and this PR’s unshipped 0150_agent_recovery_fairness.sql. Exact-head real PostgreSQL/MinIO integration passed 1,541/1,541 checks across all 225 required lanes, including concurrent boot, recovery fairness and claim races. The live migration ledger confirms both files applied.
  • The full local gate completed 58/58 tasks (34 cached) in 23m24s with exit 0. Fresh executions include 81,755 platform unit tests (12 environmental skips), 5,311 UI tests across 576 files, 1,024 sandbox tests, and 332 runtime tests (15 platform-specific skips).
  • Full local SAST completed 476 rules / 4,505 files / zero findings. It reported 85 partially analyzed files, 2,390 configured exclusions and 17 files over the existing 1 MiB limit. The four changed paths with named timeouts subsequently passed a focused standard scan with 162 applicable rules and no timeout/partial-analysis warnings. No rules, limits, exclusions or suppressions were changed.
  • Formatting, Knip and manual coverage checks pass. Independent reviews of the runtime merge and platform/spawner protocol boundaries found no concrete regressions. Incoming production UI and message catalogs are byte-identical to main.
  • Corrected the operator reference’s stale fixed-four/background-completion paragraph to match the configurable BuildKit provisioning budget and CPU-derived solver limit. The EN/DE/FR pages were inspected in the running docs site at 390px and 1280px with no document overflow.

Hosted validation

All executed jobs use merge candidate 91387103b8e52d95f4202d800d60c1b91cf697b8, whose tree exactly equals PR head 824a7cde. Later main changes through 43f29ec53713823dfb6a7358783e1128bd1c3ca7 were reviewed and merge cleanly; they are outside this candidate's execution evidence.

  • Checks: all 12 jobs passed. Fresh affected suites passed 81,765 platform unit tests (2 existing environmental skips), 1,024 sandbox tests, 345 Linux runtime tests (2 Pillow skips), 5,311 UI tests, and 327 platform browser tests. Shared UI browser results were cached. Real PostgreSQL/MinIO integration freshly passed 1,541/1,541 checks across all 225 required lanes. All 22 performance workloads executed with 20 samples each; no matched baseline supports a percentage improvement claim.
  • E2E: all 18 browser jobs passed on their first attempt, with no diagnostic artifacts. Platform: 66 passed / 1 pre-existing search credential-harness fixme; docs: 55 passed; web: 90 passed.
  • CLI: all five targets passed, including native binary smoke checks, Linux typecheck and macOS signature validation; cross-compilation and platform-specific skips are expected. Commitlint: all 15 PR commits passed.
  • SAST: 476 rules / 4,505 files / zero unsuppressed findings; 14 accepted suppressions are unchanged. The scan reports 36 partially analyzed files, 2,390 configured exclusions and 18 files over 1 MiB; this is not a claim of complete analysis. The unchanged English message catalog is the only timeout path named by its logs; focused local follow-up covered all four changed paths named by local timeouts.
  • Build: all eight image builds, Docs container checks and Storybook passed. Every image source/revision and uploaded receipt matches 91387103. Fresh execution passed 29/29 container smoke tests, 40/40 image checks and 83/83 runtime behavior checks. All four Trivy scans, SARIF uploads and CycloneDX inventories completed. Runtime image: 6,067 MB within its 6,600 MB budget; sandbox: 302 MB within 320 MB.

Image dependency advisories

GitHub’s aggregate Trivy comparison is neutral: seven historical main scan configurations are absent from this PR (trivy-controller, trivy-convex, trivy-db, trivy-proxy, trivy-sandbox-egress, trivy-sandbox-llm-gateway, trivy-fs). Its automatic PR alert comparison is therefore incomplete; the four changed-image scans required by the current workflow all executed successfully and were manually compared as described below.

Successful advisory scan execution retains the following package findings. Counts are SARIF occurrences, including duplicate installed copies; no new suppressions were added.

Image Total Critical High
platform 1,149 21 316
sandbox 401 4 111
sandbox-buildkitd 293 4 61
sandbox-runtime 1,744 20 230

Every platform, sandbox and BuildKit vulnerability/package/installed-version identity appears in retained main scan records. For runtime, 1,730 of 1,744 occurrences match the retained main runtime inventory by vulnerability/package/installed version; 14 additional occurrences comprise 13 unmatched identities plus another copy of an already known http-cache-semantics finding. Those locations are in the Cursor, OpenClaw and Hermes installations upgraded by main commit d74fb3d7, before the integrated d29a3c8fe base. This PR changes no Dockerfile, agent pin, package manifest, lockfile or scan suppression. The retained runtime inventory predates those main upgrades; a post-upgrade main inventory was unavailable, so exact current-main image equivalence is unproven.

The unmatched records include Critical CVE-2026-102992 in Cursor's piscina 4.9.3 (scanner lists 4.9.4 as a fix), High CVE-2026-102276/CVE-2026-102278 in OpenClaw's brace-expansion 5.0.9, and High CVE-2026-19534 in its undici 6.28.0 (fix 6.28.1). The extra http-cache-semantics occurrence is High CVE-2026-93748, with no fix listed. These dependency advisories remain unresolved. Scan diagnostics also include a large platform source-map warning and runtime SPDX-license serialization warnings; scan, SARIF and inventory steps completed successfully.

Kubernetes admission across simultaneous replicas remains best effort; ResourceQuota provides hard namespace limits. Deadline cancellation preserves workspaces for retry or explicit destruction. Performance coverage is exercised, but no matched baseline supports a percentage speedup claim.

@yannickmonney
yannickmonney force-pushed the fix/agent-sandbox-audit-complete branch from 5fd9d82 to 1c19bf8 Compare October 3, 2026 20:52
@yannickmonney
yannickmonney marked this pull request as ready for review October 3, 2026 20:52
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Source-specific follow-up from the postmerge #4189 review, for this existing lifecycle lane. Read-only comparison uses current main ffa15e019c3b6453bfb82dc44231abef2b8be0de and this PR's exact head 824a7cde660d6d9da5377ab06aff046caf74c08a; no runtime was launched.

Earlier P2: abandoned nonterminal containers. Docker's isReapableContainerStatus accepts only exited/dead. listSessions reports created/paused as degraded but not ended, so adoption keeps them in the unregistered capacity set. The Docker backend has no reapStaleSession implementation; the route's optional hook therefore does not recover them. These predicates remain in this PR.

This is deliberately conservative: a created container may be another replica's slow successful create, and a paused container may be intentional. Please assess a bounded stale-owner recovery contract in this existing lane. Neither state nor age alone is sufficient destruction authority. Any automatic recovery needs a current immutable incarnation plus evidence that the create/owner cannot still complete, and must preserve slow concurrent winners, legitimate pauses, unknown inspection outcomes and all workspace data. Retain source diagnosis as unexecuted until controlled tests demonstrate an abandoned case and the protected controls.

Earlier P3 is materially addressed here. cleanupCreateAttempt now removes only the attempt-labelled container under an independent deadline and preserves workspace/owner markers/inner-Docker storage. This replaces main's fresh-create destroySession cleanup implicated in moved-root workspace loss. Do not create a duplicate P3 repair. Existing cleanup tests cover fresh/resume preservation; before calling P3 accepted, retain source-bound controls for the moved-root workspace and readiness-failure path, including a replacement/concurrent winner. This audit did not independently execute the PR body's reported tests or certify hosted acceptance.

Parent coordination keeps P2/P3 with this existing #4177 owner. The separate N1–N3 device-hub repair does not touch your lifecycle files.

@yannickmonney
yannickmonney merged commit 9e8f87f into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/agent-sandbox-audit-complete branch October 4, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant