Skip to content

fix(sandbox): reduce agent overhead and harden session recovery - #4173

Merged
yannickmonney merged 10 commits into
mainfrom
fix/sandbox-audit-remediation
Oct 4, 2026
Merged

yannickmonney merged 10 commits into
mainfrom
fix/sandbox-audit-remediation

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Agent sandboxes start an inner Docker engine even when the task never uses it. This PR activates Docker on the first ordinary socket connection, shares concurrent startup, and stops the engine after five idle minutes only when a complete inventory confirms no active containers or enabled restart policies. The next command wakes it with its image store, volumes, networks and workspace intact. Agents need no mode selector; deployment capability restrictions still apply.

Health checks use a bounded supervisor endpoint that keeps intentionally idle Docker available without waking it. One slow probe refuses new work without stopping the session. Probe-based recovery requires three distinct failures spanning five seconds, resets on health recovery or engine replacement, and never counts cached reads again. Confirmed startup failure or unexpected exit is immediate failure evidence. Recovery still requires the atomic idle claim and all existing activity, pin and incarnation fences.

During a rolling upgrade, keep old spawners pinned to their existing runtime image until replacement; older spawners cannot interpret the new recovery-confidence field. A new spawner with an older runtime refuses unhealthy new work while retaining normal idle/lifetime cleanup.

The same change closes recovery and resource-boundary gaps:

  • Keep replay journals on the workspace disk, anchor directory access, bound stalled I/O, validate sequence continuity, and fail explicitly when required history is unavailable. Pass backpressure through runnerd and the spawner’s HTTP stream, retaining bounded buffers and prompt cancellation.
  • Preserve exact final narrative output within the existing explicit safety cap while keeping live display/progress bounded. Reuse verified staged content, safely handle managed-root type changes, and retain streaming atomic transfers and bounded artifact reads.
  • Persist desired pin changes and delivery jobs atomically, retry the latest intent for the correct incarnation, repair historical pin drift, and run independent deadline-bound watchdog passes with fair active/historical quotas. Apply memory admission to warm reactivation without double charging its reservation.
  • Default optional shared-cache preparation to five seconds, capped at one quarter of the session startup budget. Preserve the configurable budget, cancellation, provisioning ownership, parallel mirror setup, and whole-create deadline from main.

English, German and French operator docs describe the automatic lifecycle. Runtime isolation, privileges and configured memory ceilings remain unchanged. Active tools/builders can still grow within their configured limits; these changes do not establish a fleet-wide hard memory or disk quota.

Validation for final head 5ed405612c762d6b6d1b16ed2a7472de393a785b:

  • All seven hosted workflows passed on attempt 1, including all 16 platform E2E shards, full backend integration, all eight image builds, image validation and native CLI builds. Actual CI checkout was event merge 0121ae742c303de303f011583e9e65288ffc320f.
  • Full local repository gate: 58/58 tasks, 38 cache replays, exit 0. Fresh hosted platform unit: 81,925 passed; sandbox: 1,109; runtime: 379 with two image-dependent skips; UI: 5,437. Scoped regression suites cover recovery confidence, incarnation fences, cancellation, replay continuity, staging and bounded progress. Both skipped vision cases also passed in the isolated local Linux run.
  • Real PostgreSQL and the CLI-pinned object store: 1,559/1,559 checks across all 228 lanes, with zero skipped lanes or checks.
  • E2E: 211 passed across platform/web/docs, one existing platform fixme, zero test retries or flakes; web prerender: 822 passed. Browser components: 327 fresh platform tests and 212 valid shared-package cache replays.
  • Container proof: 40/40 image checks, 83/83 runtime conformance checks, 29/29 compose smoke checks and 7/7 docs-container checks. Native Linux/macOS/Windows CLI execution and compiled smoke pass; ARM64 and macOS x64 cross-build execution skips match their host architecture.
  • Security gates pass. Dependency audit reports zero vulnerabilities across 1,380 packages. Built-image advisory findings are identical to the previously built PR revision; the four filesystem Trivy notices and accepted SAST suppressions are unchanged. Scoped SAST fully scans 32 changed files with zero findings; the large integration harness reaches the scanner's token limit, so its test addition was reviewed and exercised by the real database run.
  • All 24 hosted performance workloads ran 20 samples each, with correctness checks for complete output, exact replay and bounded immutable tails. These are not a controlled end-to-end speedup measurement. Cache-input regression guards: 46/46; manual guard: five trees and 1,454 boxes. English/German/French operator docs were rendered at mobile and desktop widths.

Final log review distinguished real execution from cache replay, checked Playwright diagnostics and existing fixture/cleanup warnings, and verified compatibility with subsequent changes on main. No failed test or flaky retry remains; existing scanner findings and coverage limits are recorded above.

@yannickmonney
yannickmonney marked this pull request as ready for review October 3, 2026 21:00
@yannickmonney
yannickmonney force-pushed the fix/sandbox-audit-remediation branch 7 times, most recently from a1c2f8b to e9bf623 Compare October 4, 2026 06:31
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Source-specific follow-up from the postmerge #4189 review, for this existing lifecycle lane. This is a read-only source finding, not an observed production slow-ping incident or a request for another parallel implementation.

At current main ffa15e019c3b6453bfb82dc44231abef2b8be0de, one /_ping timeout produces dockerReady:false. The sweep/acquire/exec pre-check can then call reclaimIdle with idleBeforeMs = now - 1. The daemon's atomic claim correctly protects live execs, active operations, pins, new generations and newer activity; however, an acquired allocation with no live exec/active operation can qualify without being released. Docker stopSession preserves its workspace but removes the ephemeral inner-Docker volume.

This immediate recovery is deliberate in the existing route tests. The unresolved question is whether one transient probe failure is enough evidence to stop the session, rather than merely refuse new work. On this PR's exact head e9bf623cab238cddd24ae372d7b6c224facace6d, supervisor health uses a nested 500 ms engine probe inside runnerd's 750 ms budget; the route still makes the single-false stop decision. #4200 adds replacement-incarnation fences but retains that eligibility.

Please evaluate this within your existing health/lifecycle ownership. A bounded causal test should hold a synthetic socket past the production probe deadline, then recover it, and distinguish new-work refusal from destructive recovery. If confidence/hysteresis is needed, scope it to the same engine/session incarnation, do not count repeated reads of one cached failure as independent evidence, reset on healthy observations, and retain bounded recovery for sustained failure. Keep all existing claim/incarnation/pin/busy controls.

No runtime was launched and no source changed in this audit. Please retain this as a source-bound acceptance question until the causal controls establish the behavior; do not infer fleet-wide failure or waive the existing unhealthy-recovery tests. Parent coordination is reserving this question to the current #4173 owner, not opening a duplicate writer.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-audit-remediation branch 3 times, most recently from dfb8e2a to cd861f9 Compare October 4, 2026 15:56
@yannickmonney
yannickmonney force-pushed the fix/sandbox-audit-remediation branch from cd861f9 to 5ed4056 Compare October 4, 2026 17:26
@yannickmonney
yannickmonney merged commit 7e54939 into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-audit-remediation branch October 4, 2026 21:17
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