Repository navigation
feat: Route empty-generation ingest through a cold-build boundary - #5236
Conversation
…ration The cold-build write shape existed but was reachable only from sources/revision_backfill.py: select_cold_build_shape set fresh_build and defer_secondary_indexes solely for an owned inactive generation, so the ordinary live ingest pass -- the route the daemon's intake dispatcher actually uses -- took the live write profile and the full compare/replace writer no matter how empty the index generation was. The shape is now selected from generation state on that route. The live write open asks for it on every pass; ArchiveStore engages it only while the generation is provably empty under the writer lease, and reverts to the live profile otherwise, so nothing latches and the transition back is just the next pass finding a non-empty generation. What the active generation takes: synchronous=OFF, a raised WAL autocheckpoint threshold, foreign_keys=OFF with PRAGMA foreign_key_check at the boundary, and plain INSERT under fresh mode. index.db is rebuildable, which is the same argument the bulk-build profile already makes. What it deliberately does not take, and why: journal_mode=MEMORY and locking_mode=EXCLUSIVE would lock out or unmoor the CLI/MCP/daemon readers of the active generation, and dropping the deferred reader indexes is visible to schema_manifest -- which projects sqlite_master including indexes -- so a read-only open of such a generation refuses with a schema mismatch and tells the operator to reset the index. Those three levers stay with the owned inactive generation (polylogue-b7dkb). Fresh mode is per write, not per pass: a page carrying two revisions of one logical key takes the ordinary compare/replace path for the second rather than tripping the absence assertion. Refs polylogue-6xcqj, polylogue-bp12n.9 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
archive_debt classified an oversized raw against RAW_MATERIALIZATION_EXECUTE_BLOB_LIMIT_BYTES (1 GiB) and told the operator "Actual replay is blocked by the 1.0 GiB raw-materialization execution limit". No executor consults that constant; it has no other reader in the tree. The daemon refuses an ordinary component over 64 MiB (RAW_MATERIALIZATION_ORDINARY_BLOB_LIMIT_BYTES) and escalates only a stream-record-safe one, to an 8 GiB whale envelope. So a 500 MiB non-stream-safe raw that the daemon will refuse every pass was reported as actionable with "run daemon convergence", and a stream-safe raw past the whale envelope was too. The debt row now classifies against the ordinary limit, treats a row as stream-safe only within the whale envelope, and names both thresholds. Refs polylogue-6kur.3 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
The bulk-build profile's 512 MiB cache / 4 GiB mmap window is sized for a throwaway process that owns the machine. The active cold-build connection is the daemon's own live writer, sharing a cgroup budget with its readers -- the exact shape of the 2026-07-31 mapped-bytes incident this module already documents. Measured on a 500-file synthetic cold build through the dispatcher: the bulk sizes cost 433 MiB peak RSS against the live profile's 261 MiB, for a shape whose window on this route is a single intake page. The durability levers (synchronous=OFF, raised autocheckpoint, foreign_keys=OFF) are what this profile is for; the memory window is not. Refs polylogue-6xcqj Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
finish_active_cold_build() began with an unconditional commit() so that PRAGMA foreign_key_check and wal_checkpoint had a clean boundary. That was wrong: ArchiveStore.close() closes the connection without committing, so an open transaction is rolled back on every ordinary exit path. Committing at the boundary would persist work the non-cold path discards -- which is precisely how a cold-shape boundary could change what an ingest pass defers or fails, on the one pass where the shape is engaged. The foreign-key check reads this connection's own view and is valid with a transaction open, so the verification is unchanged. The WAL truncation is not valid inside a transaction and is skipped while one is open; the pass that engaged the shape has already committed its records by then, so the ordinary case still truncates. Found while investigating an integration-run failure of test_streamed_incomplete_jsonl_capture_defers_completed_source_until_authority_recovers, whose second (retry) pass writes on a still-empty generation. That failure did not reproduce in four runs, so this is not a claimed fix for it -- it is a real hazard on the same seam, removed on its own merits. Refs polylogue-6xcqj Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
Root cause of the integration-run failure of test_streamed_incomplete_jsonl_capture_defers_completed_source_until_authority_recovers: PRAGMA synchronous cannot be set inside a transaction -- SQLite answers "Safety level may not be changed inside a transaction". finish_active_cold_build restored the live durability pragmas, but it does not own the connection's transaction state, so whenever a record left a transaction open the restore raised OperationalError and failed the whole ingest pass. On the retry pass of a deferred hot capture -- which writes on a still-empty generation, so the cold shape is engaged -- that turned a successful record into a failure. The leading commit() masked it most of the time, which is why it presented as an order-dependent flake; removing that commit (correctly, since close() does not commit) exposed it as 72 failures in the same selection. Nothing needs restoring. synchronous, foreign_keys and wal_autocheckpoint are per-connection and this connection is closed when the pass ends; the next pass opens fresh and re-selects the shape from generation state. journal_mode is the only file-level setting and the cold profile never changes it -- it stays WAL, so readers are unaffected throughout. The boundary now only truncates the WAL, best-effort, when no transaction is open. Foreign-key enforcement also returns to ON. Turning it off required a verification pass at a boundary, and this shape now has no boundary that may mutate the connection. Keeping it on means the cold shape relaxes durability only and provably cannot change what a pass writes, defers or refuses -- which is the property that makes it safe to select automatically on the live route. Refs polylogue-6xcqj Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
sessions.session_id is a generated column (origin || ':' || native_id) and origin is vocabulary-checked, so the open-transaction regression's fixture row has to be built the way the schema declares it. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (16)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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. |
The dispatcher slice already selected the cold-build connection profile on an empty active generation. That still writes the live index file, so it cannot take MEMORY journal, exclusive locking, or deferred reader indexes. This composes the existing IndexGenerationStore lifecycle into polylogued run: create an owned inactive generation, feed ordinary intake pages into it, promote when the backlog drains, and discard on crash. source.db stays a read-through symlink; a half-built candidate is never a reader-visible index. Records cold_build.py in the derived-schema identity closure.
daemon/cli.py imported polylogue.sources.live.cold_build directly, which the layering gate forbids. The daemon ring already owns a re-export module for intake adapters; the cold-build lifecycle joins that seam so the writer still composes one owned generation without a sources import.
Summary
When the active index generation is empty, live ingest writes into an owned inactive generation and promotes it when the intake backlog drains. Readers keep the previous (empty) generation for the whole build. A crash discards the candidate.
Problem
A first build still paid the live-writer cost even though no reader could see the empty generation. Selecting the cold-build connection profile on the live index file is not enough: that file cannot take MEMORY journal, exclusive locking, or deferred reader indexes while readers hold it.
Solution
polylogue/sources/live/cold_build.pyin the derived-schema identity closure.This is the polylogued-run composition slice of polylogue-b7dkb, not the later per-worker shard merge.
Verification
Focused tests after rebase onto current master, plus the owned-generation tests:
tests/unit/sources/test_live_cold_build_route.pytests/unit/sources/test_cold_build_generation.pytests/unit/daemon/test_batch_policy.pytests/unit/daemon/test_intake_backlog_drain.pytests/unit/operations/test_archive_debt.pydevtools gate schema-closure --update(count 561 -> 562)Summary by CodeRabbit
New Features
--cold-build-indexoption to build a new index generation while keeping the active index available to readers.Bug Fixes
Tests