Repository navigation
Conversation
nwparker
force-pushed
the
oom-slice-3-daemon-wire
branch
from
July 27, 2026 06:10
7fe414b to
f5a64ff
Compare
The daemon control socket accepted whatever a peer sent: unbounded connection counts, unbounded concurrent requests, and request payloads whose strings, environment maps, and PTY dimensions were retained without a size check. A single misbehaving or wedged client could hold the main process's memory proportional to what it chose to send. This adds an admission layer in front of the terminal host: - Connection ceilings for pre-auth transports, control clients, and stream attachments, plus a handshake deadline so a socket that never says hello is dropped instead of parked. - Per-client and process-wide caps on active request count, retained request bytes, and reserved response bytes, released when the request settles. - A field-level limit table for retained request strings (ids, cwd, command, history seed, env names/values) measured in UTF-8 bytes, with entry and aggregate caps on env maps, and a PTY dimension check. - A tighter line ceiling for handshake framing than for session data, since a hello is a fixed small record from an unauthenticated peer. - Outbound symmetry on the client: pending-request and control-buffer caps so a stalled daemon can't grow the app's own send queue without bound. - Daemon control files (pid, token) read through a bounded reader. Rejections answer the request with an error rather than closing the connection, so a malformed request from one caller does not disturb the session. notify() keeps its delivered/undelivered return: an over-buffer notify now reports false and destroys, so the caller's existing write-failure recovery runs immediately instead of waiting for the close event. Tests: the limit table is unit-tested directly, and the server suite asserts the live socket actually consults it — a malformed request is answered with an error and never reaches spawn. Verified by mutation: unwiring the admission call, or answering notify errors, each fail the suite. The checkpoint-timer test picked 10s as its timer's identity, which now collides with the handshake deadline the server arms during spawn; it uses a distinct delay so the assertion still proves the timer is dirty-gated (verified against a mutant that removes the gate).
nwparker
force-pushed
the
oom-slice-4-daemon-admission
branch
from
July 27, 2026 06:20
87097b4 to
97c07e6
Compare
nwparker
force-pushed
the
oom-slice-3-daemon-wire
branch
from
July 27, 2026 06:40
f5a64ff to
2fd224d
Compare
OrcaWin
marked this pull request as draft
October 27, 2026 09:44
Collaborator
|
Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-28T03:18:08Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes. |
This branch has not been deployed
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.
Slice 4 of the re-landed OOM work. Stacked on #10874 (slice 3) — review the diff against
oom-slice-3-daemon-wire, notmain.ELI5
The daemon is the background process that owns your terminals. Anything connected to it could previously say "here, hold this" and the daemon would hold it — as many connections as it liked, as many requests in flight as it liked, each one as large as it liked. Nobody was counting.
This adds a bouncer at the door. There's a limit on how many can come in, how many requests each can have going at once, and how big any one piece of a request is allowed to be. Over the limit gets a polite "no" instead of being let in and remembered.
What this fixes
Every retained field on the daemon's ingress path was previously unbounded:
cwd,command,historySeed, idsenvmapcols/rowsreadFileSyncStrings are measured in UTF-8 bytes, not code units, so a multi-byte payload can't slip past a length check.
Proof the bound works
daemon-server-admission.test.tsdrives a realDaemonServerover a real socket and asserts each ceiling holds, then that capacity is released and reusable after disconnect — a limiter that leaks its counter would pass a naive cap test and fail these.Proof of no regression
src/main/daemon+src/main/providers; node typecheck and lint clean.notify()returnsfalsewhen it can't buffer, so the caller's existing write-failure recovery runs immediately rather than waiting for a close event — a silent drop would desync the terminal invisibly. Both thefalseandtruepaths are asserted.createOrAttachline, and it's clamped at the producer rather than raised here.Mutation-tested
A passing test proves nothing if it also passes against a broken implementation. Each of these was deliberately broken and the suite confirmed to fail:
notify()always reports deliveredThe first two initially survived — the limit table was unit-tested directly, but nothing asserted the server actually called it, so removing the wiring left the suite green. Tests were added to close that gap.
One test changed, and why
daemon-pty-adapter.test.tsidentifies the checkpoint timer by its delay, and had chosen 10s — which now collides with the handshake deadline the live server arms during spawn. It uses a distinct delay instead. Verified against a mutant that removes the dirty-gate: the test still fails, so it continues to prove what it claims.User-facing behavior changes
None expected in normal use — every ceiling sits well above real usage. Under genuine abuse or a wedged peer, the daemon now answers an error or closes one connection instead of growing main-process memory.
Made with Orca 🐋