Repository navigation
fix(sandbox): speed replay and harden session streams - #4188
Merged
Merged
Conversation
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.
Contributor
Author
|
Post-merge independent review of #4188 at
Verified correct
LOW
INFO
Routing: to the manager as follow-ups. |
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-parser4.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
bun run checkinitially 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.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.