Repository navigation
Sonny: a lead keeps so many task windows open, closing the least recently used - #591
Conversation
…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
…ke 73 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
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
Each sandboxed bot's own socket was bound on its first command and kept, with its accept task, until the bot was deleted, so every bot that ever ran a sandboxed command held a listening descriptor forever: past macOS's default 256-descriptor limit long before 10,000 bots. Opening it now hands out a share, held by the turn's policy and by every running command's sandbox hold (foreground, background, detached, terminal), as a refcounted handle or systemd's socket activation keeps a unit's socket. Thirty seconds after the last share goes it closes; a share taken again in that time keeps the same listener, and accepted connections keep their sessions. Deleting the bot still closes it at once. 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
…it until the read is done Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
An empty write_stdin waits live for the bot's approval_hold_ms, then parks its turn on the terminal's handle until the command ends or the poll's time runs out, holding no task and no active slot. The resumed turn reads what the terminal wrote meanwhile. A steer waiting for the boundary keeps the poll live. Closes #324 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Every session's reader takes credit before it reads: a line's first 4 KiB from the budget or a reserve kept for short lines, and a line that goes on waits for credit for the longest line at once, so readers never each hold part of what they need. The request gives it back once the service takes it up. --max-input-bytes, a sixteenth of physical memory by default (at least 64 MiB), 0 unbounded; ready reports limits.input_bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
# Conflicts: # src/server/mod.rs
…and a quarter for the lookout Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
A command's or a fetched page's output over 64 KiB is redacted with spawn_blocking, under a byte budget of two of the largest results per logical CPU, instead of on the runtime's thread (8 ms a MiB measured). Closes #316 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…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
…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
# Conflicts: # docs/DAEMON_MEASUREMENTS.md
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…layed A fixed sleep could end before a slow replay had read its history in, so a slower revision would replay less and read as cheaper. The screen now keeps what the terminal shows (pyte, a measurement dependency) and waits for the replay's footer: ready once it stops reading, done once 512x has caught up with now, refusing the run past a limit. The result says how long each took. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
The fleet's hour holds as many turns as the daemon ran in the time given, so two revisions replay different histories. The replay now goes through a counting socket too, and the gate compares its CPU per thousand lines read rather than in total; a replay that read nothing is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
bench.query_plans plans every variant of a listing from its named clauses; numbering the parameters as they were bound left braces it could not fill. The filters now take ?3 and ?4, a maker without a name binding ?3 as NULL, and the audit plans all eight variants of `bots`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…eck formulas for this machine A foreground command the load gate holds past 1.5 s now parks its turn before the call starts, as a verdict park does: one commit, no task, no active slot, and it survives restart. The turn view's waiting_on carries load: true. A server task wakes every parked turn when the gate opens, or the oldest alone on a loaded machine where none of the daemon's commands runs, and reads the store only after a turn parks. A background command waiting at the gate takes a freed slot only if the gate still admits it, so a burst cannot pass the gate together. [daemon] formulas are worked out for this machine when the file is read, so one below 0 here is config_invalid then rather than at a daemon start. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
A round's calls that run together were checked against the load gate by their first alone, so a read ahead of shell calls let the commands start on a loaded machine. The batch is now formed first and parked whole, none of it started, when the gate holds any command in it; the park names the command it holds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…e, and the matched screen Background commands waiting at a shut gate now hold a fair line, and the queue's fast path takes a free slot only while nobody waits in it, so a newcomer between two readings cannot take the slot ahead of an older waiter. A command its rules forbid is refused rather than held, since it starts nothing. DAEMON_MEASUREMENTS records the Perf workflow's matched screen of the branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…limit stays one The gate held every foreground shell call before the turn looked at its verdict or its rules, so a denial, a forbidden command, one a rule asks about with no gate, or an escape no gate allows sat parked until the load fell. Now only a call that would start at once is held; a gated call waits for its verdict instead and starts once allowed. A `[daemon] load` below 0.005 was rounded to 0, which is no gate; it is passed whole. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
#577 took 43, so this branch's protocol moves to 44. The turn test's rules are a policy given as data, as Sonny now passes them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…ntly used Past `[sonny] task_windows` (32 by default, 0 for no limit, in /config), a new task window closes the one the person used least recently, as VS Code's editor limit does. Each window's own Sonny marks its agent's file in ~/.agent/sonny/used/ when the person focuses, types or clicks there, at most once every 10 s; the lead reads those times only when it needs room. A window whose task needs the person, failed, or holds a block it asked for is never closed for room. A window closed for room stays closed while its task works on, and /status opens it again. The limit is read again on the layout's worker whenever the config file changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 637acc0db7
ℹ️ 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".
…e their windows say need the person Two leads of a folder share its multiplexer home, so a lead now counts and closes only its own tasks' windows. What holds a window is no longer only what this lead heard since it started: each window's Sonny keeps a file in ~/.agent/sonny/held/ while its agent failed, waits on an approval, or has a question open in it, and leaves it for the next window until its status says otherwise. So a lead started again, which hears neither old failures nor open questions, still keeps those windows. The protected set is built in one place (room_for), tested from a lead's state through to the window it closes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be3a6e2319
ℹ️ 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".
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f750820c97
ℹ️ 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".
…ow opened again on a failed agent keeps it Writes asked one after another run one at a time and each writes what the window wants now, so an earlier write finishing late cannot undo a later one. At start, a window with no turn running reports its last turn's end as live: a failure (not a model that said nothing) is "error", so its held file stands across a restart of both the window and its lead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
…eopens one it closed for room Tasks shown together (a split beside another task) are one window: they count once against task_windows, and close together, held whole when any of them is. A window holding a lead's or another lead's blocks is not a task window. Which windows a lead closed for room is kept in ~/.agent/sonny/aside/, so /status opens one again after the lead restarts, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
Backend::tab says what a window placement opened a block in: the window for Rex, the tab for Herdr, and the tab itself for cmux, whose task tabs share the lead's pane. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc1f7927c3
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4e88719e7
ℹ️ 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".
Part of the fleet performance review (#391's window half): hundreds of running tasks should not open hundreds of multiplexer windows.
What changes
New setting
[sonny] task_windows. It defaults to 32, 0 means no limit, and it is also in/config. The layout's worker reads it again whenever the config file changes.Closing for room. When a new task window would go over the limit, the lead closes the window the person used least recently, as VS Code's
workbench.editor.limitdoes.~/.agent/sonny/used/<bot>when the person focuses, types or clicks there, at most once every 10 s, off the UI thread.Only the lead's own windows. Only the lead's own tasks' windows count and close: its lineage plus the bots it tracks. Another lead in the same folder keeps its own windows.
A window counts once. Tasks shown together in one window (a split beside another task) count as one window and close together. The backend's
tab()names the unit: Rex's window, Herdr's tab, or cmux's tab itself (cmux's tabs share the lead's pane).Windows that never close for room:
The lead's own state can't tell all of these, and it doesn't survive a restart. So each window's Sonny also keeps
~/.agent/sonny/held/<bot>while its agent failed, waits on an approval, or has a question open.Reopening. A window closed for room stays closed while its task keeps working, and the agent keeps running throughout.
/status, or naming the task, opens it again, also after the lead restarts: which windows it closed is kept in~/.agent/sonny/aside/<bot>.The notice. The lead says what it closed in one notice, worded like the other footer notices:
closed fix's window for room (32 task windows at most, in /config); /status opens it again.Cleanup. Deleting a bot removes its files.
These answer the second external review's three protection gaps for this PR: another lead's window could close, protection wasn't rebuilt after a restart, and open questions had no protection. They also answer Codex's later findings.
Screenshots
The only visible change is the notice line above. Getting it on screen takes a live multiplexer with 33 task windows, which this cloud box doesn't have, so the screenshot will come from the Mac run.
Checks
cargo test -p sonny --bin sonny: 858 passed. The new tests build protection from the lead's state rather than passing it in:past_its_room_a_task_window_closes_the_one_used_least_recentlya_window_that_says_its_task_failed_keeps_its_placea_lead_makes_room_only_from_its_own_windows_that_nothing_holdsa_window_holds_its_place_while_its_agent_failed_or_asksa_window_counts_once_with_every_task_placed_in_it_and_closes_wholetabs_that_share_the_lead_s_pane_each_count_as_a_windowa_lead_started_again_still_opens_a_window_it_closed_for_roomcargo clippy -p sonny --all-targets: clean.🤖 Generated with Claude Code