Skip to content

feat: Route empty-generation ingest through a cold-build boundary - #5236

Merged
Sinity merged 9 commits into
masterfrom
feat/one-materialization-route
Sep 18, 2026
Merged

Sinity merged 9 commits into
masterfrom
feat/one-materialization-route

Conversation

@Sinity

@Sinity Sinity commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

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

  • Detect an empty active generation and create an owned inactive generation via IndexGenerationStore.
  • Feed ordinary dispatcher intake pages into that generation.
  • Promote when the backlog drains (a non-progressing pass after a progressing one); discard on crash.
  • Keep source.db as a read-through symlink so durable writes never fork.
  • Record polylogue/sources/live/cold_build.py in 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.py
  • tests/unit/sources/test_cold_build_generation.py
  • tests/unit/daemon/test_batch_policy.py
  • tests/unit/daemon/test_intake_backlog_drain.py
  • tests/unit/operations/test_archive_debt.py
  • devtools gate schema-closure --update (count 561 -> 562)

Summary by CodeRabbit

  • New Features

    • Added the --cold-build-index option to build a new index generation while keeping the active index available to readers.
    • Completed cold builds are validated before promotion, while unsuccessful or interrupted builds are discarded safely.
  • Bug Fixes

    • Improved oversized raw-materialization reporting by distinguishing ordinary and maximum streamable blob limits.
    • Preserved index consistency and search availability during multi-pass cold builds.
  • Tests

    • Added coverage for cold-build promotion, rollback, backlog draining, and blob-size boundary handling.

Sinity and others added 7 commits September 18, 2026 22:39
…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
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
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7b0786a9-4aa6-4b37-8f72-051db7c165b4

📥 Commits

Reviewing files that changed from the base of the PR and between ee36023 and 41cdc3e.

📒 Files selected for processing (16)
  • docs/plans/schema-closure-baseline.json
  • polylogue/daemon/cli.py
  • polylogue/operations/archive_debt.py
  • polylogue/operations/intake_adapters.py
  • polylogue/pipeline/batch_policy.py
  • polylogue/sources/live/archive_open.py
  • polylogue/sources/live/batch.py
  • polylogue/sources/live/cold_build.py
  • polylogue/storage/index_generation.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/connection_profile.py
  • tests/unit/daemon/test_batch_policy.py
  • tests/unit/daemon/test_intake_backlog_drain.py
  • tests/unit/operations/test_archive_debt.py
  • tests/unit/sources/test_cold_build_generation.py
  • tests/unit/sources/test_live_cold_build_route.py
 ____________________________________________________________________________________________________________________________________________________________________
< Don't gather requirements - dig for them. Requirements rarely lie on the surface. They're buried deep beneath layers of assumptions, misconceptions, and politics. >
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 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
🔒 Security Review ✅ Completed 2026-09-18T20:48:45.975123Z b85b5e7 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.

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.
@Sinity
Sinity merged commit cc1c740 into master Sep 18, 2026
2 checks passed
@Sinity
Sinity deleted the feat/one-materialization-route branch September 18, 2026 21:01
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.

1 participant