Repository navigation
Daemon: reads that decide nothing run beside the service loop, on a reader pool (#391) - #552
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
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: 2d45e3f023
ℹ️ 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".
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
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0c7494fa9
ℹ️ 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".
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
This is item 1 of the daemon proposals from the fleet performance review, which George approved in order. Closes #391.
Problem
Reads that decide nothing ran in the service loop on one reader connection. A page of history, a
botslisting orturnsheld every other session's submit, interrupt or pause behind it. Every read also queued behind every other read: on main, abotslisting waited 95 s behind 320 searches across every bot.What changes
src/store.rs):Store::open_with(path, readers)opens N WAL reader connections, each on its own thread, sharing one job queue. The new startup flag--max-readers Ndefaults to one per logical CPU and is reported inready.limits.readers. It follows the existing--max-*pattern and is forwarded and compared by the CLI.src/server/lane.rs):history_nodes,history_items,history_search,turns,bots,events,usageandpromptsrun beside the loop, the way Kubernetes API Priority and Fairness gives a priority level its own seats. They take all but one reader and wait in arrival order beyond that, so a turn's own reads (context, compaction plans) always find a free connection. Each read writes its own answer from its task, so the loop never serializes a multi-megabyte page. A read whose task fails answers with the typed errorobservation_failed.src/server/session.rs): the docs promise that "A session's own requests keep their order". A session with a read in flight is parked: its next request waits for the answer while every other session is served. Each session reads at most an eighth of the 64-request input queue ahead. A parked session's queued requests, and what it reads up to that share while parked, take no room in the shared queue. So any number of parked sessions leave the queue to the others, and a parked session's reader still reaches the lease renewals behind its requests (Codex review).eventsmoves from the writer to a reader.usageandhistory_searcheach spawned an unbounded task; they now go through the lane and its bound.RUST_PROTOTYPE.md(limits table, a new Observation reads section, the input queue paragraph,bots/usagenotes).DAEMON_MEASUREMENTS.mdhas the Perf screen.Measurements
bench/fair_queuing.pygained several flooding sessions (--flooders, each creating and deleting its own bots), deep histories (--history-turns/--history-bytes), history and search floods, abotsprobe,--readers, and a probe in its own process. The old probe ran in-process, where parsing the flood's replies under the GIL skewed its timings. Setup: 4-core container, 210 bots with 10 turns of 64 KiB each (129 MiB), 4 sessions flooding. Probe p50 / p95 / max in ms:history_nodesinspectbotsinspecthistory_search *botsThe search flood finishes in 44 s instead of 101 s, and the
botsflood runs at 903 per second instead of 509. The trade-off: a single session pipelining cheap reads now runs them one at a time through the lane, so 5,000 pipelinedeventspages drop from 4,897 to 2,204 per second. The full tables are inDAEMON_MEASUREMENTS.md. Each extra reader connection adds a 2 MiB page cache.Tests
lanetests: seats and order, and a panicking read still answers.sessiontests: a parked session waits while others take turns, each session reads at most its share ahead, parked sessions give the room back to the others, and a parked session still renews behind its requests.cargo test --workspaceandcargo clippy --workspace --all-targets -D warningspass locally, and CI is green, including the Python runtime suite.Not here: bounded history traversal (#472) follows as its own PR. George chose skip pointers for it over per-segment keyset paging. No protocol bump:
ready.limits.readersis a new field, and the commands are unchanged.🤖 Generated with Claude Code