Repository navigation
Store: history reads reach any ancestor in O(log n), and pages stop at 256 KiB (#472) - #557
Merged
Merged
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
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. |
…ke 73 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: 2c610e1b54
ℹ️ 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
lydakis
pushed a commit
that referenced
this pull request
Oct 31, 2026
This was referenced Oct 31, 2026
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.
Item 1b of the daemon proposals from the fleet performance review, after #552. Closes #472.
Problem
The history reads that #552 moved beside the service loop still did work that grows with the length of a history, not with the size of the page:
history_nodespage walked and sorted the whole ancestry past its floor before itsLIMIT;fromis in the lineage walked from the head down to it;history_itemsbatch walked from the head down to the oldest node it asked for;Separately, a page had no byte bound (#472): one whose turns ran in hundreds of long folders could approach the 1 MiB event limit.
What changes
src/store/db.rs). Each node gets a narrowlineagerow (parent,depth,skip,start), written by the same insert that writes the node. It sits in its own table so a walk never pages through item blobs.skipis chosen as Bitcoin Core's block index choosespskip(GetSkipHeight), andancestor_byfollowsGetAncestor. Together they reach any ancestor in O(log n) steps for any tree shape, forks included.startis the nearest turn start at or above the node.in_lineage, which checksfromand everyhistory_itemsnode, becomes one ancestor lookup.start.turn_seqcomes from its parent'sstartinstead of a walk.approvalsalready does. When its turns ran in many long folders it holds fewer nodes thanlimit, and the next page continues fromnext_from(newest first) ornext_newer(oldest first). Its first node always fits.workspacesis now grouped in Rust from one row per turn, so it lists only the folders of the nodes that are kept.RUST_PROTOTYPE.md(thehistory_nodesandhistory_itemsparagraphs),MULTI_DAEMON.md(the bound-the-work item, which asked for a measured index), and a Perf screen inDAEMON_MEASUREMENTS.md.George picked skip pointers over the proposal's per-segment keyset paging. Nodes have no owner column, so keyset paging would have needed an owner column plus a fork table, and it would have assumed each bot's history is a single line.
Measurements
One bot with 2,000 turns of ten 2 KB nodes (20,000 nodes, 77.5 MiB), release build, main against this branch, two alternating runs each:
The deep reads are 30 to 80 times faster here, and they no longer grow with the history.
Costs:
Tests
skip_pointers_reach_any_ancestor_in_logarithmic_steps: a 20,000-node tree with forks. 2,000 random ancestor lookups all match a parent walk, and none takes more than 60 steps.history_pages_stop_at_their_byte_budget_and_continue: 120 turns, each in its own 3 KB folder. Every page stays within the budget and lists exactly its own turns' folders, and both directions of paging visit every node once, in order.a_store_from_before_skip_pointers_places_every_node: a store with a fork is opened with itslineagetable dropped at schema 72. The migration rebuilds identical rows, and pages come back identical.cargo test --workspaceandcargo clippy --workspace --all-targets -D warningspass locally.No protocol change: replies keep their shape, and a page may now hold fewer nodes than
limit, whichnext_fromalready covered. Follow-up candidates on the same primitive are other walks whose cost grows with history length (history_number, turn lookups by ordinal,lineage_holds_output).🤖 Generated with Claude Code