Skip to content

fix(sandbox): release retained command memory and bound stdin - #4185

Merged
yannickmonney merged 1 commit into
mainfrom
fix/sandbox-ram-growth
Oct 3, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/sandbox-ram-growth

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A busy sandbox could keep completed commands' request payloads, HTTP consumers and diagnostic buffers alive while another command or background process remained active. Held-open stdin also queued every write when the child stopped reading. Release those references at their actual lifetime boundaries and refuse a whole stdin line before the 8 MiB queue budget is exceeded. Accepted data, disk-journal replay, cancellation and process ownership remain intact.

Also detach device tunnel abort listeners on every terminal path and cancel an upload when OPEN fails before its reader starts. Runnerd releases parsed body buffers and disconnected request/response objects; its detach signal uses an explicit reason because Node's default abort exception stack itself retained the response. Backpressured journal replay releases its in-flight HTTP consumer on disconnect.

Against baseline 952c7ea0, the regression tests reproduce 42 retained completed request/consumer objects, two retained disconnected HTTP objects, and stdin accepted beyond its queue budget. This change makes those objects collect while sibling commands and descendant pipes remain live, and verifies exact accepted stdin delivery and recovery. These are isolated Node reproductions, not production fleet measurements.

Checklist

  • All five CI workflows completed successfully on 4019cca173b852ffa06efc2c52e65926ac733631: Checks, Build, E2E, SAST and Commitlint. All eight Compose images, smoke testing and runtime/image validation pass.
  • Whole-tree SAST passed on the integrated revision in CI and locally. The local scan ran 476 rules on 4,497 files with zero findings; its configured scanner reported 103 partially analyzed files and 17 files above its size limit.
  • Translations: N/A — no UI messages or locale content changed.
  • User docs: N/A — internal resource cleanup; no new configuration/API fields. Runtime README, session contract and manual automation register describe the bounds and coverage.
  • Root READMEs: N/A — installation and product overview unchanged.

Test plan

  • CI Unit on the exact head: both affected workspaces executed with cache misses. Sandbox: 868 passed. Daemon: 312 passed, 2 optional Pillow skips, including all four actual Node memory regressions. All 22 tunnel tests pass; no listener-leak warnings.
  • Complete Linux daemon suite: 313 passed, 1 permission-test skip as root, including the real C subreaper and all four bundled Node 24 memory tests. The unchanged permission case passed in the earlier non-root proof.
  • Container smoke test: 29/29 passed. Image validation and sandbox runtime behavior checks pass.
  • All three image scan jobs pass. Direct SARIF comparison finds no new findings: runtime results match the merged sandbox baseline, and platform/sandbox results match main. Existing dependency findings remain. The aggregate Trivy check is neutral because eight historical scan configurations are absent from this PR, with zero check annotations.
  • Complete E2E: all 16 platform shards, docs and web passed on the first run, with no retry/failure diagnostics or report artifacts.
  • All three original memory regressions fail against baseline 952c7ea0 and pass here. The fourth test disconnects an actual Node HTTP replay consumer while it awaits drain, proves its request/response collect, then successfully reconnects and cancels the still-running command.
  • Tests cover primary consumer detachment, replay continuity, exact stdin admission/refusal/EOF behavior, parsed-body release and repeated tunnel cleanup, including synchronous OPEN failure and upload cancellation.
  • Affected workspace lint/typechecks: 4/4 tasks pass. Whole-tree formatting, conflict/link checks, manual grammar and protocol parity pass. Independent integration reviews report no findings.
  • Tested/pushed commit: 4019cca173b852ffa06efc2c52e65926ac733631, based on 952c7ea0d8ff2f297dd50902be1827c57506251e.

Deploy updated runtime and spawner images; existing runnerd processes need replacement through normal session lifecycle before they use the new code. No workspace deletion or database migration.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-ram-growth branch from 932d5ad to 4019cca Compare October 3, 2026 22:38
@yannickmonney
yannickmonney merged commit 88c57e3 into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-ram-growth branch October 3, 2026 23:42
yannickmonney added a commit that referenced this pull request Oct 4, 2026
* fix(platform): enforce project rights for run controls

Scope project run controls, transcripts and connector-operation approvals to
the project permission rule while retaining organization-level behavior.
Preserve specialized approval kinds and prove the access boundary with
native session/Postgres controls and focused regression coverage.

* fix(sandbox): bound agent execution and recover session state (#4174)

Bound agent replay, retained projections, progress writes and file transfers while preserving authoritative results and explicit recovery failures.

Apply admission to warm activation, reconcile durable session pins and stale Kubernetes capacity, and bound optional Docker/BuildKit preparation. Include regression coverage and operator documentation.

* feat(platform): run GPT-6 models in chat, subscriptions only in tasks (#4181)

* fix(sandbox): release retained command memory and bound stdin (#4185)

Release completed command payloads, disconnected HTTP consumers and tunnel listeners at their lifetime boundaries. Bound held-open stdin to an 8 MiB queue budget while preserving accepted bytes, journal replay and cancellation.

Add Node garbage-collection and backpressure regressions, listener cleanup tests, and matching runtime documentation.

* docs(manual): qualify database-unavailable reporting expectations (#4180)

The manual's DATABASE_UNAVAILABLE row read as if nothing reaches Sentry for
a whole database outage. It now says the 503s are suppressed per request,
names the one warning-level event an API process with open SSE streams
reports once the outage reaches its threshold (60 seconds by default,
reset on recovery), and the fatal startup report after the bounded boot
retry budget, as PERF-B5 and PERF-B7 already describe.

Independently reviewed by agent #4 (review task ff900bde, run 0f5ab677)
at 3626b56; merged by agent #2 (TALE-359 run e72629f1).

Closes #4044
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent review of #4185 at 88c57e311 (squash of 4019cca17, merged by root at 23:42:05Z with no review on record): the source is accepted with LOW follow-ups.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run e72629f1-3dd3-46d7-931c-3a9a08f52696.
  • Method: one read-only source reviewer, with its claims cross-checked. Nothing was run, so the CI counts and the memory-test results are the PR's own claims.

LOW

  1. The stdin-bound test allows one line past 8 MiB.
    • The check is at exec-manager.ts:1170-1175; the test asserts accepted <= ceil(8 MiB/line)+1 (exec-manager.memory.test.ts:217).
    • The test line is 60,015 B, and the first write goes into the 64 KiB pipe. The correct check therefore accepts 140 lines, and both mutants accept 141, which the bound allows:
      • dropping + buf.byteLength;
      • comparing against MAX + RUNNERD_STDIN_MAX_BYTES.
    • Test: a stub stdin whose writableLength is MAX − len, which must accept, and MAX − len + 1, which must refuse with nothing written.
  2. The release of process state and the ring has no test.
    • The memory tests only hold WeakRefs to request and emit (:171), and detach() already cuts emit.
    • Two mutants pass all four memory tests:
      • reverting rootAlive/leaderRunning to closures over rec (:960-976);
      • deleting record.ring = [] (:673-674).
    • Together, these allow up to 256 deferred execs, each keeping a full record and a 256 KiB ring (about 64 MiB).
    • Test: also WeakRef the journal or a ring sentinel.
  3. Close mode now drops stdin that a descendant is still reading. Hypothesis, not run.
    • commandExit destroys child.stdin (:716-717) in close mode too.
    • Example: a leader that forks a reader and exits at once. The reader gets about one pipe buffer, then EOF, and the exec still reports exit 0 with truncated: false.
    • Before this PR, Node kept writing the whole payload.
    • The PR's "accepted data … remain intact" overstates this.
    • Test: deliver the full payload, or report the loss.

INFO

  • From fix(sandbox): bound agent execution and recover session state #4174, not introduced here: a stale deadline can kill a sibling's dev server early.
    • An attach() during finish's await journal.drain() (:663) re-arms the deadline (:243, :254-260), and nothing clears it again. endNow then reaps this exec's deferred leftovers while a sibling is live.
    • Fix: armDeadline should be a no-op once the exec has settled.
  • Hypothesis: a running exec's req stays reachable while run() is suspended (:616). The cost is bounded at 4 live execs × about 8 MiB. The PR claims only completed commands.
  • The seq documentation is slightly off: the journal-failure fail event gets a seq but isn't journaled (:409, :468-473).
  • The stdin bound is per exec, so the daemon can hold up to 4 × 8 MiB pending. Request bodies are token-gated and bounded at 30 s.
  • A caller abort after the tunnel retires no longer errors the buffered inbound body (tunnel.ts:812-817). That's harmless, because all the data has arrived.

Verified correct

  • The squash equals the head, apart from an automation.md hunk offset.
  • Closures don't hold the request: no closure in run() references req.
  • Detach on every end: the consumer detaches on abort, finish and spawn failure, and the ring is handed over to recent.
  • A refused stdin line queues nothing. The refusal happens before any write or EOF.
  • After exit, writes fail honestly. Writes after the command exits now return STDIN_CLOSED rather than ok: true, and the platform retries WRITE_FAILED with backoff.
  • A client disconnecting mid-stdin gets a 400, with no partial line written.
  • Cleanup: the body-intake and tunnel abort-listener cleanup cover both the success and error paths.

Routing: the LOWs go to the manager as follow-ups. 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