Skip to content

fix: Land the small verified closure fixes in one batch - #5221

Merged
Sinity merged 2 commits into
masterfrom
fix/small-closure-batch
Sep 16, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/small-closure-batch

Conversation

@Sinity

@Sinity Sinity commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

Thirteen small beads from the reindex closure sweep, each fixed at its production seam with one regression test. Product code touched: migration_runner, durable_change_train, session_revision_membership, raw_materialization, write_coordinator, bootstrap, drive parser, local_agent parser, hook_producer (+ packaged and contrib copies), live batch, verify_distribution_surface, scenarios/projections, docs/architecture.md.

Problem (evidence, all verified at e56edbe)

  • tgq71: sorted(files.iterdir(), key=name) orders 1000_x.sql before 999_y.sql; the chain check then refuses every migration past 999.
  • yfc4f: _validate_audit_adoption_continuity opened the live source.db with immutable=1, which ignores the WAL; after an unclean shutdown a committed v32 sits only in the WAL and the check returned silently.
  • iaffn: _message_axis_relation rescanned every content key once per shared identity (O(n²) per comparison).
  • i60k5: _claude_ai_empty_conversation re-read and re-decoded a single-line export the leading-objects probe had already decoded.
  • tcear: _PriorityGate._wake_next popped an already-granted head and granted a second waiter when a sibling cancelled during handoff.
  • o7d39: a durable tier ahead of the runtime fell to the mv <path> <path>.stale remedy.
  • 54a31: four one-line parser/hook defects with derived patches (Drive chain sort, nested transcript guard, Gemini display-only turn) held back only by a PR cap.
  • bzx7h: live/batch.py routed any file named like a Codex state db into Codex acquisition before generic detection.
  • 877es: gate distribution was red on master because PACKAGE_RESOURCES named a resource whose module was deleted.
  • 54erj, 5jebf: vocabulary and doc residue of the deleted mutation/benchmark campaigns.

Solution

One fix per bead as described in the commit; no behaviour widened, no size branch or second route added. live/batch.py is inside the derived schema closure; this lands before the fresh build starts, per the campaign rule.

Verification

devtools test tests/unit/storage/test_migration_sort_key.py tests/unit/storage/test_durable_tier_ahead_of_runtime.py tests/unit/operations/test_durable_change_train_wal_continuity.py tests/unit/daemon/test_write_coordinator.py tests/unit/archive/test_raw_materialization.py tests/unit/archive/test_session_revision_membership.py tests/unit/sources/test_parsers_local_agent.py tests/unit/sources/test_hook_producer.py tests/unit/sources/test_parsers_drive.py "tests/unit/sources/test_live_batch_support.py::test_codex_state_filename_alone_does_not_route_a_foreign_file_to_codex_acquisition" "tests/unit/sources/test_live_batch_support.py::test_source_only_foreign_sqlite_name_cannot_claim_codex_authority"
-> 195 passed (receipt 20260916T015038Z + rerun 20260916T015649Z after the oracle fix)
devtools verify --quick   -> quick run success (exit 0) in 269.0s
devtools gate distribution -> gate distribution: ok

Residuals

  • The Drive chain test pins _sort_instant ordering, not a full parse of a two-offset chain.
  • The Gemini and hook guard changes were not run against the live hook spool; the packaged and contrib copies mirror hook_producer.py by hand as before.
  • 54a31 (2), the duplicate-payload prefetch cross-wiring, is not in this batch: it lives on the watcher chunk route that polylogue-v4dcc deletes.

Beads: polylogue-tgq71 yfc4f iaffn i60k5 tcear o7d39 54a31 bzx7h 877es 54erj 5jebf

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw

Thirteen beads whose fix was already derived and verified against head,
each with one regression at its production seam:

- tgq71: migration discovery sorts by numeric version (999 before 1000).
- yfc4f: the live source.db continuity check no longer opens immutable=1,
  so an uncheckpointed WAL is read instead of turning the check into a
  silent pass.
- iaffn: message-axis revision comparison builds its per-identity content
  index in one pass (was quadratic in shared identities).
- i60k5: the Claude.ai empty-conversation probe reuses the decoded
  single-line export instead of reading and decoding the artifact twice.
- tcear: the priority gate never grants twice when a sibling waiter cancels
  during the release handoff.
- o7d39: a durable tier newer than the runtime says "update the runtime";
  it no longer prints `mv source.db source.db.stale` as the remedy.
- 54a31 (1): Drive parent chains sort by parsed instant, not by timestamp
  text ('+02:00' after 'Z').
- 54a31 (3): hook transcript guard sums string content depth-capped in all
  three copies (hook_producer, packaged CLI, contrib script), so a transcript
  nested in a list or dict is refused.
- 54a31 (4): a Gemini CLI user turn with empty content but a typed
  displayContent is kept.
- bzx7h: the Codex state-db acquisition branch requires the Codex fallback
  provider; a foreign file merely named state_5.sqlite goes to detection.
- 877es: the deleted historical-continuity resource is dropped from
  PACKAGE_RESOURCES; gate distribution passes again.
- 54erj: the three producer-less ScenarioProjectionSourceKind members go.
- 5jebf: docs/architecture.md stops advertising mutation/benchmark campaigns.

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 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d9904d13-d279-4a79-9011-e12a39dd4211

📥 Commits

Reviewing files that changed from the base of the PR and between 74f52a5 and fc544d5.

📒 Files selected for processing (26)
  • contrib/polylogue-hook
  • devtools/verify_distribution_surface.py
  • docs/architecture.md
  • packaging/polylogue-hooks/src/polylogue_hooks/cli.py
  • polylogue/archive/raw_materialization.py
  • polylogue/archive/session_revision_membership.py
  • polylogue/daemon/write_coordinator.py
  • polylogue/operations/durable_change_train.py
  • polylogue/scenarios/projections.py
  • polylogue/sources/hook_producer.py
  • polylogue/sources/live/batch.py
  • polylogue/sources/parsers/drive.py
  • polylogue/sources/parsers/local_agent.py
  • polylogue/storage/sqlite/archive_tiers/bootstrap.py
  • polylogue/storage/sqlite/migration_runner.py
  • tests/unit/archive/test_raw_materialization.py
  • tests/unit/archive/test_session_revision_membership.py
  • tests/unit/daemon/test_write_coordinator.py
  • tests/unit/devtools/test_verify_distribution_surface.py
  • tests/unit/operations/test_durable_change_train_wal_continuity.py
  • tests/unit/sources/test_hook_producer.py
  • tests/unit/sources/test_live_batch_support.py
  • tests/unit/sources/test_parsers_drive.py
  • tests/unit/sources/test_parsers_local_agent.py
  • tests/unit/storage/test_durable_tier_ahead_of_runtime.py
  • tests/unit/storage/test_migration_sort_key.py

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 16, 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-16T02:08:04.307740Z 27d3bb6 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.

… declaration

The test certified the deleted historical-continuity resource by name;
with PACKAGE_RESOURCES empty it asserts the declared-resource refusal
through a monkeypatched entry and that an empty declaration passes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw
@Sinity
Sinity merged commit 342cf9e into master Sep 16, 2026
3 checks passed
@Sinity
Sinity deleted the fix/small-closure-batch branch September 16, 2026 02:38
Sinity added a commit that referenced this pull request Sep 18, 2026
## Summary

Six tests were red on master after the 2026-09-16 wave
(polylogue-3t9ea); four were real product defects, two stale test
premises. All six are green.

## Problem and solution, per test

- Delegation stage check caught only `FileNotFoundError`, so a locked or
skewed probe aborted the whole convergence pass. Now degrades to "assume
work" with a `daemon.stage.check_failed` event, like the
standing-queries stage.
- `polylogue_vector_derivation_hash` takes a registered recipe hash
since polylogue-crcst, but `sqlite_vec_runtime` still passed a model
name, so every managed or pinned vector projection raised
`SqliteVecError`. `EmbeddingRecipe` is threaded through the vector read
binding (`open_operation_read(vector_recipe=...)`); this also fixes
`test_vec.py::test_open_vector_read_snapshot_uses_only_the_explicit_pinned_paths`.
- #5221 added `fallback_provider is Provider.CODEX` to the structural
Codex state-db acquire arm; `canonical_acquisition_provider` aliases
only the exact `codex-state`/`codex-memories` tokens, so watch sources
named otherwise resolved to `unknown` and their `goals_1.sqlite` was
silently excluded. Conjunct reverted on the structural arm; the
source-only arm keeps it, and #5221's foreign `state_5.sqlite` guard
still refuses via the structural check.
- The MCP query-capability catalog had grown to 26,357 bytes against the
25,000-byte response budget, so `_json_payload` silently returned the
generic over-budget envelope and MCP discovery exposed no query
vocabulary at all. The resource now measures the serialized catalog and,
only when over budget, applies one declared reduction (per-unit field
names → `field_count` + explain route); 18,300 bytes now.
- Embedding-readiness test seeded `embedding_status` into the anchor db
while the payload reads `root/embeddings.db`; re-seeded into a real tier
pair, contract kept, terminal/retryable split added.
- Attachment-acquisition test's private id mirror still used NUL framing
after `_hash_bytes` moved to length-prefixed framing; it now uses the
production `_attachment_id`.

## Gate finding (not changed here)

No required per-PR check runs pytest: `verify_quick` is static gates
only, the CI `test` job is `workflow_dispatch` with `run_full_suite`,
and the only broad pytest evidence is the nightly `verify_all`. Master
going red on these was structurally invisible until the nightly. Adding
a required pytest selection reverses an explicit operator policy, so it
is surfaced on polylogue-3t9ea and polylogue-u9nmr for a ruling rather
than changed.

## Closure

`sources/live/batch.py` and
`storage/search_providers/sqlite_vec_runtime.py` are IN the
derived-schema closure; the identity moves. Lands before the rebuild.

## Verification

- `agentctl ... verify_quick` → job VQ_PLACEHOLDER
- `agentctl ... pytest_focused -- <the eight files +
tests/unit/operations + tests/unit/mcp + daemon_execution>` → job
PF_PLACEHOLDER
- Worker: the eight files → 262 passed; ruff/mypy clean.

## Residuals

- `vector_model` → `vector_recipe` keyword rename on
`open_operation_read`: `daemon_execution.py` is the only production
caller; the integration selection above covers tests/unit/operations and
tests/unit/mcp.
- The delegation check now swallows every exception into "assume work"
with a warning event, matching the standing-queries precedent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 22, 2026
…5409)

## Summary

A real `polylogued run` ingests nothing. Four sites on its own ingest
path open a write-mode archive connection with no lease held — or bound
to the wrong archive root — and the armed single-writer boundary raises
`UnleasedWriteError`, which refuses the whole intake page. Live ingest
has been broken since 2026-09-16.

## Problem

This was filed as a cluster of 16 failing tests with two candidate
explanations. **Both are refuted**, and the defect is production-only.

- *"Startup never converges"* — no. `daemon.started` fires, the watcher
binds all 16 source roots, the API answers, and per-publication ops
writes succeed under their own lease in the same log.
- *"A writer lease is never released"* — no. Every
`daemon.writer.released … status=success` line shows holds of 1–800 ms.
The defect is a lease never **taken**.

Reproduced outside pytest with the installed `polylogued` console script
against a synthetic 3-session corpus — no fixture, no harness. The line
that decides the diagnosis, from the real daemon's stderr at base:

```
daemon.intake.page_refused ... error_detail=open_connection(<root>/ops.db) requires the daemon
write lease; open it inside write_lease(...) ... error_type=UnleasedWriteError files=3
outcome=degraded reason=page_admission_failed
```

Bisected on the real binary: `OK messages=50` at `342cf9e20` (#5221),
`TIMEOUT last=0` at `1c1895098` (#5263) and every later point. The
window opens at `d7d3ddae5` (#5224, 2026-09-16), which added
`require_write_lease` to `CursorStore.ops_write_scope`; #5265 moved the
raise site to `get_records` but did not introduce it.

**#5382 is not the cause**, despite the differential that pointed there:
the cluster was already failing in the 09-21 corpus run, and #5382
landed 09-22 02:54 UTC.

The four sites, each proven by stack capture at the raise:

| Site | Route |
|---|---|
| `sources/live/batch.py:963` | `get_records` → `_connect_ops` →
`open_connection(ops.db)` on the event loop |
| `daemon/cli.py` | `_drain_convergence_debt_once` → `CursorStore(db)` →
`initialize_archive_database(ops.db)` |
| `sources/live/batch.py:1515` | inline `self._event_emitter(...)` →
`open_daemon_connection(ops.db)` |
| `archive.py:1435` | `_ensure_source_conn` bound to the candidate
generation dir, not the declared root |

## Verification

Production route, the real binary, no pytest:

| | base `0df0f6a00` | head |
|---|---|---|
| result | `TIMEOUT last=0` | **`OK messages=50`** |
| `UnleasedWriteError` lines | 81 | **0** |
| `convergence_debt.pass.error` | present | **0** |

Re-run after rebasing onto current master `17566b048`: **`OK messages=50
after 27.3s`, 0 unleased errors** — the fix holds on the current tree,
not only on the base it was written against.

- `devtools verify --quick` → **21/25 gates green at time of writing,
with the single failure being `gate atlas`, which is already red on
master** (`docs/atlas/daemon.md`, hook-carrier anchor). Reproduced in a
clean detached worktree at `17566b048` carrying none of these changes.
PR #5408 fixes it.
- `devtools render all --check` → exit 0, `grep -c 'out of sync'` =
**0**.
- `devtools test` over `test_daemon_resilience.py`,
`test_schema_preflight.py`, `test_daemon_ops_lease_boundary.py`,
`test_daemon_operation_route.py`, `test_inferred_corpus_loop.py` →
**exit 0, 72 selected, 72 passed**. No timeout, mark or wait bound was
changed anywhere, so the resilience tests reach their own
`_wait_for_messages` assertions with real nonzero counts.
- `test_daemon_cli.py` at head: 106/112. At base: 100/107. Delta is one
test **fixed**; the remaining 6 are byte-identical inherited red.
Baseline established by detaching at the base SHA and running the same
selection.

### Anti-vacuity, executed

Four production reverts, one at a time, each restored:

- revert `_connect_ops_read` → `UnleasedWriteError:
open_connection(…/ops.db) requires the daemon write lease`, from two
independent tests
- revert the `_run_sync` wrapper on the batch emitter →
`UnleasedWriteError: live batch event ledger requires the daemon write
lease`
- revert `admit_stage_write` on the `CursorStore` construction →
`UnleasedWriteError: open_connection(…/ops.db)`
- revert `_ensure_source_conn` to `archive_root=self.archive_root` →
`UnleasedWriteError:
open_source_tier_write_connection(…/gen-1790055341112-6db616a2/source.db)
is outside the archive bound to writer test.cold_build`

Opposite direction pinned:
`test_ops_tier_writes_still_require_the_write_lease` fails if `ops.db`
is made lease-free wholesale.

## The cluster was three causes, not one

- **12 of 16** are the production defect above.
- **2** are a stale test contract: they assert
`assert_scopes_balanced(at_least=N)` on the degraded short-circuit path,
but #5265 retired the one-scope-per-batch contract and #5388 put the
scope inside each admitted publication. A degraded batch returns
synthetic skip metrics before `begin_ingest_attempt`, so it correctly
performs zero ops writes and can never satisfy `at_least>=1`. Retargeted
to `assert_no_ops_bookkeeping`.
- **1** is a harness more restrictive than production — a phantom.
`test_fresh_runtime_prepares_tier_journals…` died in its own `seed`:
`SessionBuilder.save` writes through the thread-local cache in
`storage/sqlite/connection.py`, whose `index.db` connection ATTACHes the
sibling durable tiers and is never closed, so `PRAGMA
journal_mode=DELETE` on `source.db` hit the seeding thread's own lock.
Isolated proof: `source LOCKED database is locked` / `user ok` / `audit
ok`. A fresh `polylogued` process has no such cached connection, so
**production cannot exhibit this one at all**.
- **1 more** was fixed by #5388 landing on master during the lane; it
passes at base untouched.

The harness was **under**-reporting, never over-reporting, for the real
cause.

## Still red, handed back

The 4
`test_daemon_watcher_hints_wake_fair_intake_and_canonical_derivation`
params are a **fourth, distinct cause** that only became visible once
the daemon started ingesting. They are no longer `CancelledError`; the
fix carries them past ingest (`ingested_session_count=1`) into
`test_daemon_cli.py:2747`, where `sum(report.done == 1 …) ==
expected_versions` sees `[(…, 0), (…, 2)]` — the canonical derivation
kernel reported done=0 then done=2 instead of one per version. That is a
derivation-batching question and needs its own bead. Confirmed
inherited-red at base by the same nodeids.

Two further inherited reds, failing identically at base and head:
`test_raw_observation_publication_holds_writer_lease_through_replay`
(`AttributeError: 'FakeArchive' object has no attribute 'archive_root'`
— a test double that never gained an attribute production now reads) and
`test_run_daemon_services_parks_operation_recovery_on_audit_schema_mismatch`.

The 2 `test_inferred_corpus_loop.py` property tests pass at head, but
**no code cause was established** for their corpus-run timeouts and they
do not arm the write lease. The honest reading is host-load starvation,
not a fix — do not credit them here.

## Behaviour change worth a reviewer's eye

The 7 SELECT-only `CursorStore` readers now open read-only when no
`ops_write_scope` connection is held. On a fresh archive with no
`ops.db` they raise `sqlite3.OperationalError: unable to open database
file` instead of silently bootstrapping it through a write-mode open.
The daemon bootstraps the archive root before any of these run, and
`cli.py:1584` already documents this exact `initialize=False` read-probe
pattern — its `get_record` call was a fifth latent `UnleasedWriteError`
site that this change also removes — so the typed failure is judged
correct rather than adding an unexercised guard.

## Schema closure

IN: `sources/live/batch.py`, `sources/live/cursor.py`,
`archive_tiers/archive.py`. out: `daemon/cli.py` and all three test
files.

- `DerivedTier.index`: `8a971a53…` (base, measured in a detached
worktree) → `abb040da…`
- `DerivedTier.ops`: unchanged

A closure move on ordinary code — no DDL, no lowering or materializer
semantics, no durable migration. Needs reconvergence, and **must land
before a fresh rebuild starts, never during one**. Re-measure at merge;
other lanes are moving this value concurrently.

## Follow-ups, same defect class, left unlanded

- `archive.py:5599` `ArchiveStore.delete_sessions` still binds
`require_write_lease(archive_root=self.archive_root)` instead of
`_write_lease_archive_root`, so a delete on a generation-rooted store
fails exactly as `_ensure_source_conn` did.
- `daemon/cli.py:487`
`_mark_interrupted_live_ingest_attempts_on_shutdown` constructs
`CursorStore(initialize=True)` on the shutdown path — an unleased ops
write. Currently unreached because signal termination logs
`daemon.shutdown.ingest_recovery_deferred`, but a non-signal graceful
stop would hit it.

Neither was fixed because neither could be exercised.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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