Skip to content

Daemon: terminals and detached commands share one lasting-process cap - #562

Merged
lydakis merged 19 commits into
mainfrom
claude/project-thread-je4o8y
Oct 31, 2026
Merged

lydakis merged 19 commits into
mainfrom
claude/project-thread-je4o8y

Conversation

@lydakis

@lydakis lydakis commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

This is item 3 of the approved fleet-scale proposals, "Terminals as one resource lifecycle".

What changes

  • One cap for processes that outlive their call. --max-lasting replaces --max-detached. Terminals and detached commands share it, and the default is 4 per logical CPU. When it is full, a start fails with a typed lasting_limit that says what holds the slots: "N terminals and M detached commands". Nothing queues behind it.
  • A terminal takes its permit before it spawns and keeps it until its whole session is gone. The per-bot bound of 16 is now enforced before the spawn: the bot's least recently used terminal is killed first, the way Codex prunes its unified-exec sessions. A start waits for that terminal's slot only when every slot is taken, and for at most 2 s.
  • A kill ends the whole session (Terminal edges from the #322 review: job-control groups, secret fields split across reads #328). It kills the command's group, the terminal's foreground group (tcgetpgrp), and every other group in the session. Those are found under /proc on Linux, and on macOS with proc_listallpids plus getsid/getpgid. A job that a job-control shell started and that ignores SIGHUP no longer outlives its terminal.
  • Secret fields split across reads are redacted whole (Terminal edges from the #322 review: job-control groups, secret fields split across reads #328). A started value waits for its end. The field's name and separator are shown at once, so a prompt such as Password: reaches the bot, and the next read is redacted as if it followed them. Names are matched by bytes from 4 bytes on, and values are held up to 4 KiB.
  • ready reports limits.lasting. PROTOCOL 35, because the field was renamed from detached.

Closes #328

Tests

  • terminals_hold_a_lasting_permit_and_end_their_whole_session (tool_contract) fails when the session sweep is disabled.
  • a_secret_field_split_across_reads_is_redacted_whole and a_field_name_in_any_script_is_matched_without_a_panic (unit).
  • The existing detached-limit tests now run against the shared cap, and the CLI and runtime tests use --max-lasting.
  • The perf screen and a terminal-read timing are recorded in docs/DAEMON_MEASUREMENTS.md. Nothing moved past noise.

claude added 16 commits October 31, 2026 18:55
…eader pool

Observation reads (history_nodes, history_items, history_search, turns,
bots, events, usage, prompts) used to run inside the service loop, on one
reader connection. A deep history read or a search across every bot held
every other session's submit, interrupt or pause behind it, and every
read waited behind every other read.

They now run in an observation lane beside the loop, as Kubernetes' API
Priority and Fairness gives a priority level its own seats. The store
has a pool of WAL reader connections (--max-readers, one per logical
CPU by default). Observation reads take all but one of them, waiting in
the order they came, so a turn's own reads always find one free. A
session waits for its read before its next request is taken (the input
queue parks it), so a session's own requests keep their order.

events moves from the writer to a reader. usage and history_search,
which spawned a task each, now go through the lane and are bounded by it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
… ahead

Measured: sessions parked on reads kept the input queue full, so another
session's next request waited for room. A session now reads at most an
eighth of the queue ahead, and no further than its next request while it
waits on a read. A read's answer is written in its own task, not in the
service loop. Observation reads leave one reader for turns' own reads.
bench/fair_queuing.py floods history and searches from several sessions
over deep histories; the Perf screen is in docs/DAEMON_MEASUREMENTS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
A session parked behind an observation read kept the room its queued
requests held, so enough parked sessions could fill the queue and hold
new connections and other clients' requests until a read finished.
Parking now hands those slots back, and a parked session reads nothing
more until it is answered; what it read ahead is taken uncharged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
A parked session's reader stopped at its next request, so lease
renewals behind it went unread until the observation was answered.
It now reads on to its share while parked, and what it queues then
takes no room, so renewals stay readable and the shared queue stays
free. The fair-queuing bench gives each flooder its own bots to create
and delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…#472)

Each node gets a narrow lineage row (parent, depth, a skip pointer
chosen as Bitcoin Core's block index chooses pskip, and its turn's
start), written with the node. Checking that a node is in a bot's
lineage, finding where an oldest-first page starts, validating a
history_items batch, and naming a page's turn now take O(log n) point
lookups rather than a walk over the history. A history_nodes page
stops at 256 KiB sent and continues from next_from, or next_newer
oldest first. Schema 72 places every existing node when a store opens.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…lock held

A follow catching up from an early cursor used to read every page as a job
on the storage worker while holding its subscription's lock, so one client
replaying a long history put hundreds of reads ahead of every write. Pages
now come from the reader pool behind the observation seats (all but one
reader across every replay). Only the switch to live stays on the worker,
as one job that reads at most one event and either marks the follow live or
sends the replay back for another page, so nothing committed between the
modes is lost.

bench/fair_queuing.py gains a follow flood: 16 whole-store replays move the
probe's p95 from about 40 ms to about 15 ms and finish about 20% sooner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
# Conflicts:
#	docs/DAEMON_MEASUREMENTS.md
A terminal spawned its PTY and shell with no slot at all, bounded only by
16 per bot, and terminals outlive turns, so nothing bounded them
daemon-wide. Terminals and detached commands now share --max-lasting (4
per logical CPU, replacing --max-detached), as a systemd slice holds a
service's processes. A terminal takes its permit before it spawns and keeps
it until its whole session is gone; a full cap answers lasting_limit,
naming how many terminals and detached commands hold it. A bot at its 16
terminals ends its least recently used before the next starts, so that
permit is free for it.

From #328: a kill now ends every process group in the terminal's session
(the foreground job via tcgetpgrp, the rest from /proc on Linux and the
process list on macOS), so a job that a shell with job control started and
that ignores SIGHUP no longer outlives its terminal. A secret field's name
cut off at the end of a read now waits with its value for the next one, so
the value is redacted whole.

Protocol 35: ready's limits report lasting in place of detached.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…n pruning

Codex review: replay pages and observation reads each took all but one
reader, so together they could fill every reader ahead of turns' own reads.
They now share the lane's seats. The switch to live reads at a later point
than the empty page did, so a deletion in between could prune events past
the cursor: its own retention notice is the one reported. The bench raises
when a flood fails instead of writing a clean result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
# Conflicts:
#	src/server/mod.rs
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T22:30:50.304375Z 58bbd8e New commits
🔒 Security Review ✅ Completed 2026-10-31T21:49:42.516775Z a676e29 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a676e297f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/terminal.rs Resolved
Comment thread src/tools.rs Resolved
Comment thread src/tools.rs Resolved
…er it

A prompt such as `Password: ` was held back with the value it waits
for, so a program asking for one never showed its prompt. Only the
value is held now; the name and separator are shown, and kept so the
next read is redacted as read after them, at a command's end too.
A field's name is matched by bytes, so one in any script no longer
panics the read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65eec5d500

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/terminal.rs Resolved
…aken

Pruning a bot's least recently used terminal waited up to 2 s for it to
go on every start past the bot's share, inside the active turn. A start
now takes a free lasting slot at once; only when none is free does it
wait, bounded, for the pruned terminal's, a moment after its kill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
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.

Terminal edges from the #322 review: job-control groups, secret fields split across reads

2 participants