Skip to content

Daemon: reads that decide nothing run beside the service loop, on a reader pool (#391) - #552

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

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

Conversation

@lydakis

@lydakis lydakis commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

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 bots listing or turns held every other session's submit, interrupt or pause behind it. Every read also queued behind every other read: on main, a bots listing waited 95 s behind 320 searches across every bot.

What changes

  • Reader pool (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 N defaults to one per logical CPU and is reported in ready.limits.readers. It follows the existing --max-* pattern and is forwarded and compared by the CLI.
  • Observation lane (src/server/lane.rs): history_nodes, history_items, history_search, turns, bots, events, usage and prompts run 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 error observation_failed.
  • Per-session order stays (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).
  • events moves from the writer to a reader. usage and history_search each spawned an unbounded task; they now go through the lane and its bound.
  • At shutdown, reads still running get 5 s to answer.
  • Docs: RUST_PROTOTYPE.md (limits table, a new Observation reads section, the input queue paragraph, bots/usage notes). DAEMON_MEASUREMENTS.md has the Perf screen.

Measurements

bench/fair_queuing.py gained several flooding sessions (--flooders, each creating and deleting its own bots), deep histories (--history-turns/--history-bytes), history and search floods, a bots probe, --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:

Flood Probe main this PR
8,000 history_nodes inspect 8.8 / 11.6 / 20.8 1.1 / 2.3 / 5.5
1,600 bots inspect 18.0 / 25.5 / 33.5 2.4 / 4.8 / 6.9
320 history_search * bots 4.5 / 7.0 / 94,543 4.7 / 364 / 465

The search flood finishes in 44 s instead of 101 s, and the bots flood 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 pipelined events pages drop from 4,897 to 2,204 per second. The full tables are in DAEMON_MEASUREMENTS.md. Each extra reader connection adds a 2 MiB page cache.

Tests

  • New lane tests: seats and order, and a panicking read still answers.
  • New session tests: 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 --workspace and cargo clippy --workspace --all-targets -D warnings pass 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.readers is a new field, and the commands are unchanged.

🤖 Generated with Claude Code

…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
@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-31T19:34:05.239860Z 0a30d6a New commits
🔒 Security Review ✅ Completed 2026-10-31T19:05:18.151723Z 2d45e3f 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: 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".

Comment thread src/server/session.rs Resolved
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

@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: 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".

Comment thread src/server/session.rs Resolved
Comment thread bench/fair_queuing.py Resolved
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
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.

Daemon reads all queue on one SQLite reader connection

2 participants