Skip to content

fix(sandbox): speed replay and harden session streams - #4188

Merged
yannickmonney merged 1 commit into
mainfrom
fix/sandbox-execution-throughput
Oct 4, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/sandbox-execution-throughput

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Late reconnects currently reread the entire execution journal, small output bursts issue one filesystem write per record, and concurrent sandbox requests repeat the same backend probes. This change seeks to a bounded sparse journal index, batches queued writes, and shares only in-flight probes. It also fixes output loss when SSE CRLF delimiters cross chunks and prevents a delayed dead-session probe from evicting a replacement or releasing stop-owned capacity.

Deterministic before/after probes on the actual journal show 16,000 small records taking 16,000 → 267 writes, with a last-ten-record reconnect reading 8,756,894 → 17,536 bytes (134 → 1 reads). Fragmented 4 MiB SSE delimiter scans fall from 2.15 billion → 16.8 million characters, plus one linear frame-budget pass. A controlled 16-request cold adoption burst uses 34 → 4 backend operations; warm concurrent checks use 16 → 1. These are synthetic operation counts, not production agent latency or RSS claims.

The existing replay ordering, full cursor-zero history, 64 MiB transcript / 256 MiB session limits, physical disk accounting, 16 MiB SSE frame limit, UTF-8 cursor state, and lifecycle admission fences remain. The parser is the pinned, dependency-free eventsource-parser 4.1.1; a counter-only guard retains the whole-frame limit. Two Node performance workloads make journal writes and late reconnects repeatable in CI.

Checklist

  • Check coverage — bun run check initially exited 1 in the UI suite: 5,209/5,211 UI tests passed; two unchanged 5s timeouts passed on their first isolated rerun (589/658 ms), with no test/source/timeout changes. The fresh, uncached hosted UI suite passed all 5,211 tests. Fresh local server/PII: 81,615 passed, 12 conditional skips; runtime daemon: 296 passed, 15 host/compiler-dependent skips. The separate lint/type/unit remainder passed all 57 tasks (16 fresh, 41 cached). No test, timeout, or source changes were needed to resolve the UI validation.
  • bun run lint:sast --jobs 2 . — exit 0, zero findings; scanner reported 40 partial-analysis files and excluded/size-limited files. Focused full-rule scan: nine changed TypeScript files, zero findings and zero analysis errors.
  • Translations — N/A: no localized strings or public error wording changed.
  • Product docs — N/A: internal transport/lifecycle fixes; performance README and automated coverage register updated.
  • Root READMEs — N/A: no public setting, command, API field or deployment requirement changed.

Test plan

  • Regression tests reproduce split-CRLF output loss, quadratic scanning, duplicate probes, delayed eviction and stop-capacity races on the baseline, then pass with the fixes.

  • Sandbox suite: 871 passed. Client stream suite: 42 passed. Journal suite: 7 passed; manager suite: 54 passed, four host-platform skips. Full platform/sandbox lint and typecheck pass (fresh executions); runtime lint/typecheck and scoped client/performance lint pass.

  • Exact current source on Node 24.21.0/Linux: three readers verify full 2 MiB output, detach preserves execution, detached child cancellation reaps correctly, and staging abort/hash repair/pruning checks pass. Native shim source is unchanged and was compared before reuse.

  • Formatting, conflict/link checks and manual coverage checks pass. Linux daemon suite: 302 passed, 9 compiler-dependent skips. A supplemental two-CPU-capped run hit an unchanged FIFO deadline test; its isolated and full uncapped reruns pass. Fresh local and hosted production dependency audits both pass across 1,380 packages. Hosted SAST, Trivy vulnerability gate, commit lint, all five CLI builds, whole-repo lint, and web Playwright (90 tests, all first attempt) pass. Hosted UI (5,211 tests, uncached), docs Playwright (55 tests, all first attempt), and Storybook also pass. All seven current workflows are green: Checks, Build, E2E, CLI, SAST, Commitlint and the explicitly dispatched Security run. Earlier draft runs were superseded when the PR became ready.

  • Fresh hosted unit suites: platform 81,625 passed, 2 conditional skips; sandbox 871 passed; daemon 309 passed, 2 conditional skips. Hosted UI: 5,211 passed, plus 307 platform component browser tests. Backend integration: 1,517/1,517 checks across 224/224 lanes, using real Postgres and object storage with all lanes required. All 211 Playwright tests passed on their first attempt across web, docs and 16 platform shards. Eight images built; 40 image validations and 29 container smoke tests passed. Image SARIF/SBOM scans completed; their advisory job status is not a claim of zero image vulnerabilities.

  • Hosted performance: eight harness tests and both new workloads pass, each with 20 samples plus two warmups on Node 22.21.1/Linux x64. Current-only medians: 26.48 ms per 16,000-record write/drain/verify batch; 0.904 ms per 20 sequential tail-ten reconnects. These host filesystem measurements exclude network/container latency and do not establish a CI before/after speedup.

No database migration or UI changes. Kubernetes operation counts use a controlled backend; live-cluster throughput and production memory sizing remain deployment measurements.

Seek journal cursors through bounded sparse offsets and batch queued writes. Parse fragmented SSE incrementally without losing split CRLF output, and share only in-flight session probes while fencing delayed eviction by incarnation. Add regression and repeatable performance coverage. Internal transport and lifecycle changes only; no public fields, settings or localized UI changes.
@yannickmonney
yannickmonney marked this pull request as ready for review October 3, 2026 22:44
@yannickmonney
yannickmonney merged commit b5d1aa2 into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-execution-throughput branch October 4, 2026 00:09
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent review of #4188 at b5d1aa2d6 (squash of 6f0d176d0, merged by root at 00:09Z on 4 Oct with no review on record): the source is accepted. There is no HIGH or MEDIUM finding, only LOW follow-ups.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run 554ef899-2405-42cc-8bfd-e575c9b857fe.
  • Method: one read-only source reviewer. Nothing was run.
  • Squash: its tree a0137287f equals merge-tree 0592b64a9 6f0d176d0.

Verified correct

  • Sequence numbers match file positions. Every persisted event is appended with its own seq, and the terminal event is appended first as seq + 1.
  • Resume neither loses nor duplicates events.
    • replayPosition picks the last checkpoint at or below the target, and the target never passes throughSeq. replay-complete is always emitted.
    • Bad sinceSeq values, whether NaN, negative or Infinity, are safe.
  • Checkpoints sit at record starts, so a reader never splits UTF-8 or JSON.
  • Batched writes are sound.
    • Short writes are accounted for, and paused output always resumes.
    • Reserved bytes are released on close, including those of a disposed journal.
  • The 16 MiB frame limit is unchanged and runs before the parser.
  • The split-CRLF output-loss fix is real, using eventsource-parser 4.1.1's skipNextLineFeed.
  • The liveness fences hold, and the probe map can't leak.
  • No conflict with fix(sandbox): release retained command memory and bound stdin #4185 or fix(sandbox): bound logs and repair persistent storage cleanup #4182.

LOW

  1. Shared in-flight backend reads can answer a later caller with a result from before that caller's trigger. This breaks the rule the file itself states for lists (session-routes.ts:1312-1322).
    • Where: resolveForAdoption (session-routes.ts:1254-1272) and evictIfBackendGone joining checkingLiveness (:1598-1599).
    • A Kubernetes lookup can stay open for about 30 s while being shared:
      • a later route miss can get a false 404 from a lookup that started before the backend recovered;
      • a runnerd-failure path can get "alive" from a probe that started before the container died.
    • The test at session-routes.test.ts:2249 pins the first behaviour. Either accept and document it, or answer late misses from a fresh read.
  2. Four test gaps, each with a surviving mutant:
    • (a) Checkpoint spacing: a checkpoint on every record passes, because the count test uses exactly 64 KiB records. The "≤1024 entries" bound is unprotected.
    • (b) The Math.min(sinceSeq + 1, throughSeq) guard (exec-journal.ts:333) can be removed and everything still passes.
    • (c) The 128 KiB per-write cap can be removed and everything still passes.
    • (d) The CRLF pairing in the platform's frame limiter can be removed without failing a test, because the oversized-frame tests are LF-only.

INFO

  • The disk budget is now reserved per batch, so OUTPUT_LIMIT can trip up to one batch earlier. The outcome is the same.
  • A destroy during a probe now answers "alive". handleGet re-reads the registry, and only the activity path continues with a stale endpoint.

Routing: to the manager as follow-ups.

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