Skip to content

fix: reduce stream retention and add performance telemetry - #4156

Merged
yannickmonney merged 11 commits into
mainfrom
fix/performance-reliability
Oct 3, 2026
Merged

yannickmonney merged 11 commits into
mainfrom
fix/performance-reliability

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Long subprocess lines, disconnected daemon consumers and slow SSE readers could retain excessive memory; simultaneous SEO requests also rebuilt the same artifacts and could repopulate invalidated caches. Bound and release that state, coalesce concurrent work, and add sampled backend spans plus repeatable performance measurements.

  • Incremental capped line capture preserves Unicode and releases readers promptly; small string fragments no longer retain oversized backing buffers. Aborted daemon attaches remove completion callbacks. Sandbox SSE uses a byte budget and detaches slow readers without killing their exec.
  • SEO builds share one cache generation, coalesce cold bursts, retry failures and prevent obsolete builds or misses from replacing fresh state. Concurrent metrics scrapes share one collection, and route/method labels have finite vocabularies.
  • BACKEND_SENTRY_TRACES_SAMPLE_RATE enables HTTP and worker spans, with drain/handler/handover children. It defaults to 0; transaction data is scrubbed, automatic SQL/HTTP spans are disabled and outgoing trace headers remain disabled. Operator docs cover EN/DE/FR.
  • bun run test:performance runs 20 default workloads with latency, throughput, CPU and RAM reports; an additional pinned Opengrep workload is opt-in. Every workspace has an explicit coverage entry. An uncached CI job retains 20-sample reports and participates in release-candidate checks. Worker/scanner cancellation has cleanup regressions.
  • Make watchdog integration fixtures and daemon process-output tests independent of other tests and concurrent output ordering, preserving their strict assertions. Derive Knip public entry points from the published package manifests so worktree checks resolve their actual APIs while still detecting unused internal code.

Checklist

  • bun run check — 58/58 tasks passed, zero cached, on pinned Bun 1.4.2. A subsequent upstream integration-harness merge passed platform typechecking, 50 focused harness/guard tests, two source-archive tests, formatting, conflict, link and manual gates. CI checks now pass on the final head; the Unit job passed on its second attempt after an initial first-PowerShell-startup timeout.
  • bun run lint:sast — final full scan passed: 476 rules, 4,487 files, zero findings.
  • UI message translations: N/A — no UI catalog strings changed.
  • Operator docs updated and rendered in EN/DE/FR; all three tracing pages passed browser inspection.
  • Root README translations: N/A — installation and product overview are unchanged; backend, sandbox, shared UI and contributor references describe the changes.

Validation

  • Strict real-Postgres/object-store integration: 1,507/1,507 checks across 222/222 lanes, zero skips, fresh isolated state. This full run preceded the final upstream harness merge; the merged head then passed 35/35 checks across four focused stream/watchdog lanes, plus three HTTP-shutdown unit tests. CI subsequently repeated the full 1,507/1,507 checks across 222/222 lanes successfully.
  • All 20 default workloads passed 20 measured samples on Bun 1.4.2; the Node daemon workload also passed 20 samples after the upstream merges. The Linux CI performance artifact also passed all 20 workloads × 20 samples on the pinned runtimes. Optional scanner probes and interruption regressions passed. Timings include recorded host load and are diagnostic, not calibrated speedup claims.
  • Full daemon suite after integrating upstream sandbox fixes: 259 passed, 14 expected Linux-only skips. The repaired output-ordering test passed ten repetitions.
  • Shared stream, SEO concurrency/invalidation, sandbox disconnect/backpressure, and real Sentry transport/privacy regressions passed. Release-candidate/workflow companion guards passed.
  • CI E2E passed 191 tests without retries, with one existing test.fixme skip. Production builds completed for platform, web, docs, UI docs and AI gateway; four built sites passed HTTP and real-browser navigation probes. The old local Bun's docs SSR build stall was bypassed with the supported Node loader; the repository pins newer Bun.
  • Separate disposable infrastructure probes passed for PostgreSQL queries/vector operations, MinIO round trips, Caddy forwarding/compression, Tinyproxy allow/refuse behavior, Bifrost whole/streamed mock responses, and offline BuildKit build/cache/prune behavior. Reports identify released-binary/current-config combinations explicitly.
  • Knip passes with package-manifest entry points. A sensitivity probe still detected a synthetic unused internal file and export; no findings were suppressed. The manual-test gate passes all five trees / 1,434 boxes.

These are representative measurements across the repository and infrastructure. Authenticated end-to-end UI, sustained multi-tenant load, provider refresh, Linux runtime isolation and complete deployment capacity are not all covered; the runner reports those gaps explicitly. No live model credits or production data were used.

@yannickmonney
yannickmonney marked this pull request as ready for review October 3, 2026 17:13
@yannickmonney
yannickmonney merged commit aa2e739 into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the fix/performance-reliability branch October 3, 2026 18:54
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent review of #4156 at aa2e73974: root merged it at 18:53Z with no review on record. Tale agent #2 3f9fdcee, TALE-359 run a721a46a-c362-49ac-8936-9fa055181d29. This is a source review by one read-only reviewer, and I re-checked the constants and the replay code myself. Nothing was executed.

Verdict: MEDIUM found in the stream-retention part. The telemetry part is accepted.

MEDIUM: when the new 8 MiB SSE limit disconnects a slow reader, the reconnect silently skips output.

  • The limit: services/sandbox/src/sse.ts now errors the stream once its queue reaches RUNNERD_CONSUMER_BUFFER_MAX_BYTES (8 MiB, runnerd-protocol.ts:41), with the message "SSE consumer exceeded its buffered output limit", and aborts the runnerd fetch.
  • The reconnect: the platform reconnects with sinceSeq set to the last event it consumed. Runnerd replays only from its ring, which exec-manager.ts:443-450 trims to RUNNERD_RING_BUFFER_BYTES (256 KiB, daemon/src/protocol.ts:13; base64 payloads, so about 190 KiB of raw output).
    • Replay drops seq <= sinceSeq (exec-manager.ts:242,258) and never reports a gap.
    • The platform cursor takes the highest seq it sees (session_client.ts:1346), though its comment promises "no missed or double-counted events" (:1234).
  • What a user loses: take a chat turn streaming with collectOutput:false (external_turn_shared.ts:653,658), where the SSE stream is the only copy of the output. Every limit-triggered disconnect loses roughly 7.8 MiB of stdout and can splice a partial NDJSON line onto an unrelated one.
    • If output stays fast this repeats, because each reconnect makes progress and resets the retry budget (:1300).
    • A cut-off collectOutput exec reconnects to stdoutBase64:''.
  • Before the PR: sandbox memory could grow, but nothing was lost.
  • No sandbox-side log: fail() logs nothing, and the route's catch returns silently on abort (session-routes.ts:2148,2305).
  • Open: whether Bun.serve and the device hub relay let the queue actually reach 8 MiB on a real socket. That decides reachability, and whether the memory bound works at all.
  • Fix direction:
    • have runnerd emit an explicit gap or truncation event when its oldest kept seq is greater than sinceSeq+1, and have the platform surface it;
    • log the disconnect.
    • Test: more than 12 MiB of seq-numbered stdout, a reader stalled until the limit trips, then a reconnect. Assert contiguous seqs or an explicit gap event.

LOW (development tooling only): pipeNodeStream now removes its 'error' listener on finish (packages/shared/src/process/pipe-lines.ts:145-171). An 'error' emitted after 'end' would now crash services/platform/scripts/dev-output.ts.

INFO: release-candidate-gate.ts:114 makes the new uncached Performance job required for release candidates. A flaky shared-runner run (15-minute timeout) can now block a release.

Verified correct (telemetry)

  • Tracing is opt-in: BACKEND_SENTRY_TRACES_SAMPLE_RATE defaults to 0, and tracing is enabled only after a DSN init.
  • No new destination: tracePropagationTargets: [], and the http/fetch integrations run with spans:false.
  • Scrubbing: scrubTransaction drops request, user, breadcrumbs and extra, and keeps only allowlisted span attributes. Span names come from bounded vocabularies, and no ids or payloads go into spans.
  • Overhead: negligible when tracing is disabled.
  • Untouched paths: /events resume and chat-stream replay are unchanged.
  • Route labels: they match every /api/app/* mount, and a test derives that list from source.

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