Skip to content

fix(sandbox): harden agent runs and resource recovery - #4189

Merged
yannickmonney merged 7 commits into
mainfrom
fix/agent-sandbox-resource-reliability
Oct 4, 2026
Merged

yannickmonney merged 7 commits into
mainfrom
fix/agent-sandbox-resource-reliability

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Agent runs can lose execution history when corrupt stream records are discarded, exceed their caller's staging deadline, or start in sessions whose inner Docker engine has failed. Validate the full stream protocol, bound each staging batch and Docker readiness wait, and recover only idle, unpinned compute while preserving workspaces and active execution.

Connected devices now enforce host resource admission, keep ambiguous creates on their original device, and preserve durable placement state across failed writes. Disk admission observes both workspaces and the verified Docker data-root filesystem, with safe cache-upkeep accounting when the constrained filesystem changes. Operator documentation in EN/DE/FR states the monitoring and external-quota boundaries.

Checklist

  • bun run check passes (format, lint, typecheck, all tests).
  • bun run lint:sast passes (Opengrep); touched-code pre-commit scan also passed.
  • Translations: N/A for UI catalogs; no visible UI labels or message keys changed.
  • Docs updated in docs/{en,de,fr}/ and sandbox service contracts.
  • Root READMEs: N/A; product setup is unchanged. Sandbox and runtime READMEs updated.

Test plan

  • Regression tests exercise malformed SSE/NDJSON and replay markers, stream cancellation, batch timeout, Docker capability loss, concurrent device placement, pre/post-rename persistence failures, and multiple filesystem reserves.
  • Full repository gate passes on 35abeb60c: 58/58 tasks, including 5,262 UI tests, 81,711 platform server tests, and 326 daemon tests. Run with serial Turbo tasks and two Vitest workers using Bun 1.4.2 and Node 24.21.0. Knip and the manual-reference guard also pass.
  • Full backend integration passes on the final combined commit: 1,522 checks across all 224 lanes, zero failures or skipped lanes, against a fresh database image built from this change and isolated object storage.
  • Final reconciliation passes 68 platform SSE tests, 37 runtime staging/admission/health tests (two Linux-only skips locally), and 410 controller tests, with workspace lint/type checking clean. Two canonical-base64 regressions were observed red→green. Full repository, Knip, SAST and isolated backend integration pass on 35abeb60c. Upstream secure staging, replay limits, per-session memory defaults and output handling are retained.
  • Cleanup/stream reconciliation passes 35 runnerd/protocol tests (including real HTTP producer cancellation), 80 runtime cleanup tests (four Linux-only skips locally), and 35 session-view/embedding tests. Strict malformed-record rejection and tenant/spend semantics remain intact.
  • Actual Node 24 Docker-health smoke passes 12 assertions across 6 Unix-socket probes. Docker filesystem discovery matches mountinfo, daemon metadata, and statfs in a restricted real Linux container.
  • Updated EN/DE/FR operator docs were visually reviewed in the native preview at desktop and mobile widths; merged memory-default paragraphs were rechecked in the rendered DOM at 1280 and 390 pixels without horizontal overflow.
  • The embedding contract suite passes all 32 tests after correcting its pooled-buffer view to respect the decoded byte range. Mock execution-result fixtures now satisfy the full wire type.

The existing progress coalescing, bounded full replay journals, streaming/reusable staging, warm memory admission, workload-scoped Docker capability, and bounded BuildKit preparation are retained. No production throughput percentage or per-volume quota is claimed.

@yannickmonney
yannickmonney marked this pull request as ready for review October 3, 2026 23:28
@yannickmonney
yannickmonney merged commit d29a3c8 into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/agent-sandbox-resource-reliability branch October 4, 2026 06:09
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent review of #4189 at d29a3c8fe (squash of 35abeb60c, merged by root at 06:09Z on 4 Oct with no independent review on record; the squash tree equals merge-tree(bd2275c3f, head)). Five new MEDIUM follow-ups, and three earlier MEDIUMs still open.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run 1abd0c9f-3022-4cac-b25f-d32f0089a9ec.
  • Method: one read-only source reviewer, using a helper sub-trace, with a 25-minute time box over 46 files. I re-read N4's path and N1's premise myself. Nothing was run.

Earlier sandbox MEDIUMs, all still on main

New MEDIUM

  • N1, a regression: the hub's deleting sweep can delete a brand-new session's route.
    • Placement writes now publish memory only after the rename (placements.ts:176-195,215). The old set() updated memory synchronously; I confirmed the difference.
    • Scenario: session X is marked deleting on device A while a create for X is mid-write (hub.ts:581, :587).
      • recheckDeleting still sees X as deleting. It sends a destroy and captures the new create's generation (:253-266, :395).
      • A answers done, and the create commits X→A and returns 201.
      • Finalization then computes recreated=false and deletes X's route (:683). The next call gets 404, and the platform treats the session as destroyed.
    • Test: hold writeSnapshot, run recheckDeleting with the device answering done, then release. Expect X→A, not deleting.
  • N2: a stale candidate list can route a session permanently to a removed device.
    • The candidates are computed once (hub.ts:561-577). If device B is removed during A's slow 429, the loop still writes X→B.
    • The forward gets an offline 503, the placement is kept on 5xx (:614-617), and B can never reconnect because its tickets are revoked. The session id then gets 503 indefinitely.
    • Fix: re-check at :577 that devices.get(id) === device and that the device is still compatible.
  • N3: creates that provably never reached the device keep the placement. The hub's own 503s, "device gone before send" (:700) and TunnelBusyError/device_busy (:716-721), keep the placement and set a 60 s cooldown, with no fallback. The old code released the placement and fell back. The docs line "A 5xx … keeps the placement: the remote create may have succeeded" is false for these cases.
  • N4: an exit record with a negative durationMs is now fatal. I verified this path myself.
    • The producer uses wall-clock time, Date.now() - startedAtMs (exec-manager.ts:653), and the validators now require nonNegativeNumber (protocol.ts:185, runnerd-protocol.ts:245, session_client.ts:1345).
    • A backward clock step during a short exec (an NTP step or a VM resume) turns a cleanly exited command into a fatal REPLAY_UNAVAILABLE.
    • Fix: use performance.now(), or clamp at the producer.
  • N5 (the trigger is a hypothesis): one slow /_ping destroys a held DinD session.
    • The probe is a single attempt with a 750 ms deadline and no hysteresis (inner-docker-health.ts:25-43,81-84).
    • dockerReady: false reclaims the session from the sweep, acquire and the exec pre-check (session-routes.ts:1452-1454, :2084, :2380). An acquired turn between tool calls qualifies, and the stop removes the DinD volume.
    • An unreachable runnerd, by contrast, needs WEDGED_PROBE_FAILURES consecutive failures.

LOW and INFO

  • N6: a pinned DinD session whose dockerd died is a permanently dead slot.
  • N7: a failed exec pre-check skips evictIfBackendGone.
  • N8: a first-drain failure settles start_failed without cancelling the exec.
  • N9 (hypothesis): a truncated final record is now fatal.
  • N10: mutants no test kills:
    • deleting bufferedBytes = 0;
    • removing single validator clauses or fail codes;
    • moving inflightCreates++ after the await;
    • 'wx' changed to 'w';
    • removing the placements fsync.
  • N11: the disk "filesystem" label is the observation path, not a filesystem identity.
  • N12: the body's "bound each staging batch" claim is misleading. file-ops.ts is unchanged here; fix(sandbox): bound replay consumers and preserve agent output #4170 added that deadline.
  • N13: devices now auto-size their slot count from host memory, and inflightCreates is released on the answer rather than at the next report.

Verified correct

  • Placement writes are serialized, atomic and keep memory consistent on failure.
  • Hub slot accounting releases on every path.
  • Stream records match their validators, the reader is always released, and protocol errors are coded, with no eviction.
  • Entrypoint readiness is bounded.
  • Inner-Docker health: the probe body is capped.
  • Data-root mount checks pass argv only, with a 64-hex container id.
  • Busy, pinned and acquire-race sessions stay protected by runnerd's atomic claim.

Routing: to the manager as follow-ups. N1 is a regression on the create path. Nothing here needs a revert.

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