Skip to content

fix(triage): repair Codex review findings - #4506

Merged
Sinity merged 19 commits into
masterfrom
fix/codex-triage-rest
Sep 1, 2026
Merged

Sinity merged 19 commits into
masterfrom
fix/codex-triage-rest

Conversation

@Sinity

@Sinity Sinity commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Completes the reviewed triage fixes and addresses four follow-up findings from Codex review.

Problem

Legacy Claude cursors could mint semantic authority from unverified current bytes. Claude AI and AI Studio/Drive topology declarations omitted parser-carried data. Sinex publication encoded parser tool results before canonical outcomes were derived.

Solution

Legacy cursors retain nonsemantic authority and therefore take the established full-ingest path after a rewrite. Claude AI and AI Studio/Drive now declare their carried message parents and derived branch state. A source-level tool-outcome helper is shared by the archive writer and Sinex adapter, so publication uses the same canonical outcome derivation.

Verification

  • nix develop --accept-flake-config --command devtools test tests/unit/sources/test_live_deferred_append_dedup.py: 7 passed.
  • nix develop --accept-flake-config --command devtools test tests/unit/sinex/test_material_adapter.py: 5 passed.
  • nix develop --accept-flake-config --command devtools test tests/unit/storage/test_tool_outcome.py: 26 passed.
  • nix develop --accept-flake-config --command devtools test tests/unit/sources/test_origin_specs.py -k topology_capability_census_is_complete_and_typed: 1 passed.
  • nix develop --accept-flake-config --command devtools verify --quick: exit 0.

Residual risk

The complete corpus and live daemon were not run. The previously filed replay coverage gap remains in polylogue-rkdej.

Disposition

Finding Result
3908111340 Legacy Claude cursors no longer upgrade unverified current bytes.
3908111349 Claude AI topology declares carried parents and derived branch state.
3908111353 Sinex derives canonical tool outcomes before publication encoding.
3908242286 AI Studio/Drive topology declares carried parents and derived branch state.

LANE-BRANCH: fix/codex-triage-rest
LANE-COMMIT: d4490a1
LANE-QUICK: green


Receipt: harvest-7b77c896872f25018843497654fe527e

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 626a92f1-eee1-4198-a677-8de47f1abfef


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 1, 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-09-01T21:42:52.960373Z 81a8afd Manual request
ℹ️ 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: 185b8941f2

ℹ️ 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 polylogue/sources/live/watcher.py Outdated
Comment on lines +890 to +894
if self._source_name_for(path).split(":", 1)[0] == "claude-code" and path.parent.name == "tool-results":
session_dir = path.parent.parent
root_transcript = session_dir.parent / f"{session_dir.name}.jsonl"
owners = [root_transcript, *sorted((session_dir / "subagents").glob("agent-*.jsonl"))]
self._pending_paths.update(owner for owner in owners if owner.is_file())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bypass the unchanged-file filter for sidecar owners

When a tool-results file changes after its owning transcript already has an up-to-date cursor, adding that transcript to _pending_paths does not cause a reparse: _flush_pending subsequently runs every path through _needs_work_from_state, which returns false for the owner's unchanged size/stat and removes it from the batch. Only the sidecar itself is ingested, so apply_tool_result_sidecars never reruns and the archived tool result remains stale until the transcript happens to change. Carry these expanded owner paths as forced reparses through the production flush path rather than merely adding them to the ordinary pending set.

AGENTS.md reference: AGENTS.md:L162-L166

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 11bfaab — force expanded Claude owner transcripts through the changed-file flush filter. [review-fix lane]

Comment thread polylogue/mcp/server_support.py Resolved
@Sinity

Sinity commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 11bfaabf3e

ℹ️ 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 polylogue/sources/origin_specs.py Resolved
Comment thread polylogue/sinex/material_adapter.py Resolved

@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: 074703c545

ℹ️ 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 polylogue/sources/origin_specs.py Resolved
@Sinity
Sinity force-pushed the fix/codex-triage-rest branch from 074703c to f2e8ff6 Compare September 1, 2026 21:04

@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: f2e8ff6ac8

ℹ️ 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 polylogue/sources/origin_specs.py Resolved
@Sinity
Sinity force-pushed the fix/codex-triage-rest branch from f2e8ff6 to a48717e Compare September 1, 2026 21:16

@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: a48717e24d

ℹ️ 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 polylogue/daemon/http.py Resolved
@Sinity

Sinity commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 81a8afd40e

ℹ️ 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".

@Sinity
Sinity merged commit 5be5954 into master Sep 1, 2026
3 checks passed
@Sinity
Sinity deleted the fix/codex-triage-rest branch September 1, 2026 21:50
Sinity added a commit that referenced this pull request Sep 3, 2026
…4587)

## Summary

Fixes the eleven verified Codex review findings in the sources / daemon
/
operations sweep. Each was re-confirmed at this branch's base before
being
changed; none were taken on faith from the sweep file.

## Findings and what changed

| # | PR | Site | Claim | Action |
| --- | --- | --- | --- | --- |
| 1 | #4455 | `daemon/backup.py` `_source_recoverability_proofs` | a
full-snapshot append row is hashed as a byte window | fixed: falls back
to the full prefix `[0, end)` when the window does not prove the blob |
| 2 | #4457 | `operations/append_acquisition_replay.py` | unbounded
`handle.readline()` during replay | fixed: bounded at 1 MiB, matching
live acquisition |
| 3 | #4506 | `sources/live/deferred_cursor.py` | semantic frontier
re-derived from current bytes with no comparison to retained evidence |
fixed: recomposed frontier must reproduce the recorded **body** digest |
| 4 | #4506 | `sources/origin_specs.py` | ChatGPT derives
`inheritance_branch_point` from `mapping.parent`/`mapping.children` |
fixed: declared structurally absent |
| 5 | #4515 | `sources/live/source_selection.py` | no typed-vs-generic
tiebreak, so a typed source loses ownership to a nested generic root |
fixed: ownership resolved among sources that accept the path |
| 6 | #4539 | `sources/live/watcher.py` | tool-outcome semantics changed
without a parser-fingerprint bump | fixed: `live-batched-v2` ->
`live-batched-v3` |
| 7 | #4549 | `sources/live/batch.py` | legacy promotion commits durably
before append planning succeeds; resynthesized cursor never returned |
fixed: promotion deferred behind a successful plan; cursor handed back
to the caller |
| 8 | #4549 | `sources/sqlite_snapshot.py` | `sqlite_sequence` excluded,
so insert-then-delete on AUTOINCREMENT yields no digest change | fixed:
AUTOINCREMENT state included |
| 9 | #4549 | `sources/live/batch.py` | full-head Claude authority
computed from the live file | fixed: live prefix must reproduce the
retained blob digest |
| 10 | #4554 | `parsers/base_support.py` -> write boundary | idless
model turn yields `("model_output", None)` and the write rejects the
whole session | fixed at the write boundary (see note) |
| 11 | #4558 | `sources/origin_specs.py` | fingerprint memo keyed on
`(path, mtime, size)` | fixed: keyed by content digest |

None were refuted. Master moved while this work ran; `git diff` over all
eleven files across that range is empty, so every cited line still
described
current code.

### Finding 1: live exposure remains unconfirmed

The code-level defect is real and now covered by a test. Its **live**
reachability is not established: every current production caller of
`admit_raw_observation` (`revision_governance.py:825,3995,4126`) passes
`prior_head=None`, which never reaches the append arm that writes the
full-payload-with-tail-offsets shape. This fixes the defect without
claiming
it was reachable in production.

### Finding 6: schema-regime classification

Classified as **none of the schema-regime classes** -- it is not a
schema
change. There is no DDL edit and no derived-tier version bump, so no
`DerivedDeltaClass` declaration in `storage/sqlite/lifecycle.py`
applies; that
table is keyed on index-schema version pairs.

It is a *parser-semantic* change, whose declared route is the
fingerprint bump
itself. `base_support.py` is already inside the origin-spec
parser-semantic
closure (verified: `_semantic_source_paths` for a parser resolves it),
so the
origin-scoped fingerprint recomputed on its own with #4539. The gap was
only
the live watcher's hand-written literal. Bumping it marks every existing
live
cursor as stale, and the watcher routes those sources back through parse
on
its next pass -- the production convergence route. Nothing forces a
rebuild by
hand.

**Operational consequence:** the first daemon pass after this lands
re-ingests
every live-watched source once. That is the intended cost of the
correction,
but it is a real one.

### Finding 10: fixed at the write boundary, not the parser

The sweep points at `base_support.py:633-635`. The parser genuinely
cannot fix
this: `attachment_from_meta` takes `message_id: str | None` and there is
no
identity to name when it is `None`. The stored message id exists only at
the
write boundary, which is where the producer is now supplied -- covering
both
the parser-declared and role-derived paths. The fallback completes
missing
provenance and never overwrites parser-supplied evidence.

### Findings 3 and 9 are one fix

Both derived Claude authority from bytes on disk at planning time rather
than
from retained evidence, so a rewrite preserving the prefix length
inherited
the previous observation's authority. Finding 3 (deferred cursor)
compares the
recomposed frontier's body digest against the recorded one; finding 9
(full-head resynthesis) requires the live prefix to hash to the retained
blob.
The reconstructed-chain branch already proved its prefix byte by byte
and is
left alone.

Finding 3's check is deliberately on the **body**, not the whole
frontier
token: `ClaudeSemanticFrontier` is "replaceable header plus stable
body", and
an equality check on the token broke
`test_deferred_claude_cursor_rebases_frontier_after_header_rewrite`,
which
protects legitimate rebasing onto a rewritten header.

## Verification

Anti-vacuity was verified mechanically, not asserted: with all ten
source
files reverted to master and the new tests kept, every new test fails.

```
git checkout <master> -- <the ten source files>
devtools test tests/unit/sources/test_reviewed_acquisition_defects.py \
  tests/unit/storage/test_attachment_idless_model_turn.py \
  tests/unit/sources/test_live_deferred_append_dedup.py \
  tests/unit/sources/test_live_append_cursor_resynthesis.py \
  tests/unit/daemon/test_backup.py -n 2
-> 15 failed, 79 passed
```

The 15 are the 13 new tests plus the 2 existing expectations this change
updates. `test_backup_still_proves_a_window_shaped_append_row`
**passes** on
master -- it is the control proving finding 1's fix did not
over-generalize
into "always read the full prefix".

With the fixes restored, the same selection is green:

```
devtools test tests/unit/sources/test_reviewed_acquisition_defects.py -n 2         -> 5 passed
devtools test tests/unit/sources/test_live_deferred_append_dedup.py -n 2           -> 8 passed
devtools test tests/unit/sources/test_live_append_cursor_resynthesis.py -n 2       -> 13 passed
devtools test tests/unit/daemon/test_backup.py \
  tests/unit/storage/test_attachment_idless_model_turn.py -n 2                     -> 68 passed
devtools verify --quick                                                            -> all 12 gates ok
devtools render all --check                                                        -> exit 0, no "out of sync"
```

Collateral selection over the consumers of the changed modules (live
watcher,
source snapshot, source differential, catchup planning, codex state, and
the
four attachment suites):

```
devtools test tests/unit/sources/test_live_watcher.py \
  tests/unit/sources/test_source_snapshot.py \
  tests/unit/sources/test_source_differential.py \
  tests/unit/sources/test_live_catchup_planning.py \
  tests/unit/sources/parsers/test_codex_state.py \
  tests/unit/storage/test_attachment_acquisition.py \
  tests/unit/storage/test_attachment_first_class_ids.py \
  tests/unit/storage/test_source_attachments.py \
  tests/unit/storage/test_attachment_relink.py -n 2
-> 1 failed, 218 passed
```

After the fixture fix below, the one affected file was re-run on its
own:

```
devtools test tests/unit/sources/test_live_watcher.py -n 2   -> 125 passed
```

The other eight files were green in the combined run and are untouched
by
that fixture change; no combined re-run was made, so the "219" total is
not
claimed as an observed number.

The single failure was
`test_parser_fingerprint_change_triggers_reingest`,
caused by this branch and not inherited. It simulated a fingerprint
change by
monkeypatching `_PARSER_FINGERPRINT` to the *literal*
`"live-batched-v3"`,
which finding 6 makes the real value -- so the patch became a no-op, no
change
was simulated, and no reingest fired.

The bump is not miswired; the fixture collided with it. The sentinel now
derives from the real constant (`f"{_PARSER_FINGERPRINT}-changed"`), so
the
test asserts the same behaviour and cannot silently no-op on a future
bump.
Finding 6's own test
(`test_superseded_parser_fingerprint_refuses_append_
planning`) independently proves a `live-batched-v2` cursor refuses
append
planning, and went red when the constant was reverted.

Selected scope only: this proves the selected files, not the corpus.

## Residual risk

- **Finding 6 forces a one-time live re-ingest** of every watched source
on
  the next daemon pass.
- **Finding 8 changes `sqlite_logical_revision`** for every
AUTOINCREMENT
database, so previously recorded identities differ once and those
sources
  re-acquire on next observation. Self-healing, but not free.
- **Finding 5 changes ownership for overlapping default roots** beyond
the
  reported case: a `.db` under `~/.codex/sessions/` now resolves to
`codex-state` rather than `codex`, because only `codex-state` accepts
it.
That looks correct, but it is a behaviour change the finding did not
name.
- **Finding 7** delays promotion until planning succeeds, not until the
plan
is *applied*. Closing that gap needs a larger refactor of the ingest
stage.
- **Finding 11** reads parser sources instead of stat-ing them. A
per-process
digest cache keyed on full inode identity including `st_ctime_ns` (which
`os.utime` cannot restore) keeps this correct and measurably faster than
before: 0.818 ms/call warm vs 1.343 ms/call for the previous stat-keyed
  signature, over a 449-file / 9 MB closure.
- Three tests are reported red on master itself
  (`test_archive_tiers_api_session_costs_read_index_tier`,
  `test_existing_same_version_ops_database_receives_additive_call_log`,
`test_record_context_delivery_requires_initialized_user_tier`). None are
in
  files this branch touches and none were in the selections run here.

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sinity added a commit that referenced this pull request Sep 3, 2026
#4594)

## Summary

Fixes 20 of the 22 Codex review findings recorded for storage. One is
refuted
with evidence, one is confirmed only in part, and two are deferred with
reasons. Five commits, one per seam:

1. `material-protocol` — semantics versioning and read gating
2. `storage` — derived schema identity, manifests, lifecycle admission
3. `storage` — writer provenance, tool verdicts, session kind
4. `storage` — vector counting and index attachment
5. `storage` — provider cost attribution on append

Every finding was re-confirmed by behavior at this branch's base
(`c1d2544f0`); the recorded line numbers were treated as hints, since
they were
captured against `cc58ef3e6`.

## Problem

### Semantics versioning (#4554, #4557)

- **20** — `material_protocol/v1/constants.py:22`: `SEMANTICS_VERSION`
was 3
  while attachment records had gained `direction`, `producer_ref` and
  `caption`, so the encoder emitted bytes the declared version did not
describe. `test_checked_in_bytes_match_a_fresh_encode` was red on
master.
Confirmed by decoding both sides: the fresh encode carries the three
keys,
  the checked-in fixture does not.
- **21** — `material_protocol/v1/verify.py:50-92`: `resolve_anchor`
verified an
  anchor's digest, record id and seq but never the manifest's semantics
version. Only `verify_revision` called `require_current_semantics`, so
the
single-record read path decoded records whose shape this reader may not
  implement.
- **22** — `material_protocol/v1/manifest.py:194`:
`int(payload["semantics_version"])` coerced before comparison, so a
declared
  `3.9` truncated to a supported `3`.

### Schema identity, manifests, lifecycle (#4544, #4546, #4548, #4560,
#4556)

- **10** — `archive_tiers/index.py` appends `schema_identity` to
`INDEX_DDL`,
but `tests/infra/reindex_differential.py::compared_table_census` raises
on
any DDL table with no declared classification, so the rebuild
differential
  raised on every current archive.
- **11** — `schema_manifest.py`: `canonical_schema_manifest` executed
the whole
tier DDL into a fresh `:memory:` database on every call, and every read
open
  asserts against it.
- **12** — `schema.py:73`: `except (RuntimeError, sqlite3.Error)`
reported
`rebuild_index` for both, so a SQLite failure that never inspected the
schema
was indistinguishable from real drift — and told the operator to destroy
a
  sound index.
- **13** — `schema_manifest.py:33`: the projection filtered only
`NOT LIKE 'sqlite_%'`, so FTS5 shadow tables were compared and an FTS5
build
  change would read as archive schema drift.
- **15** — `archive_tiers/bootstrap.py`:
`open_initialized_tier_connection` ran
  `initialize_archive_tier` before `assert_tier_schema_supported`.
`_apply_archive_tier_convergence` rewrites `user_version` to the spec
version
(bootstrap.py:387-388), so the check validated a value the same call had
just
written: a tier at some other version was restamped into apparent
currency
and admitted. `initialize_archive_database` gets this right (it reads
the
  stored version first, bootstrap.py:553); this route did not.
- **16** — `stamp_derived_schema_identity` issues an `INSERT ... ON
CONFLICT`
and never commits. It runs *after* `_materialize_archive_tier`'s own
commit,
so it sits in its own open transaction and rolls back on close. Some
callers
  committed afterwards; `open_initialized_tier_connection` and the OPS
  same-version reapply did not.
- **17** — `connection_profile.py`: the post-materialization check read
only
`PRAGMA user_version` and never the derived identity — the one thing the
stamp exists for, and the only one of the two that materialization has
not
  just overwritten.
- **18** — `raw_failure_lifecycle.py:111`: `validate_schema=False` on
the
  admission path (callers `bulk_rebuild.py`, `archive_verification.py`).
- **19** — `archive_readiness.py:269`: bare
`sqlite3.connect(...mode=ro)` with
  no version check, reached from `readiness/capability.py`'s frontier
  source-selection. Its result is surfaced to users as
  `source_embedded_messages`.

### Writer (#4506, #4561)

- **1** — `write.py`: `session_kind` is derived once at admission from
`session.branch_type` alone. `_refresh_session_projection` later
re-derives
`branch_type` from resolved `session_links` — including
hook-authoritative
edges the parser never saw — but its `UPDATE`s never touched
`session_kind`,
so a subagent child discovered after admission stayed `PRIMARY`
permanently.
- **2** — `write.py::_coalesce_block_row`: `tool_outcome`,
  `tool_result_is_error`, `tool_result_exit_code` and
`tool_result_outcome_unknown_reason` were each coalesced independently
by
`_coalesce_scalar`, so a merge could persist a fresh `success` beside a
stale
  `is_error=1`/`exit_code=1` that contradicts it.
- **4** — `write.py::_attachment_provenance`: with no `message_id`
fallback, a
  model turn whose provider supplied no message id derived
`("model_output", None)`, which the writer then rejects — failing the
whole
session write. **Superseded during this work**: #4587 landed the same
fix
  with a better implementation (`resolved_message_id`, applied to the
parser-declared path as well as the role-derived one). This branch drops
its
own version and keeps master's. Finding 5 is still fixed here, because
#4587
  did not touch the stale test.
- **5** — `tests/.../test_archive_tiers_write.py`:
`test_writer_refuses_attachment_without_derived_direction` still
asserted the
refusal contract #4561 replaced, and was red on master with `DID NOT
RAISE`.

### Embeddings and vector search (#4538)

- **7** — `sqlite_vec_runtime.py:98`: `ATTACH DATABASE ?` with no
existence
check. ATTACH creates the file, so a missing active index silently
became an
  empty database and the projection reported an archive with no eligible
  messages.
- **9** — `sqlite_vec_queries.py:277-293`: `count_session_embeddings`
counted
rows in `current_embedding_messages` — the *eligible-message*
projection,
  which has no relation to `message_embeddings` — so a session mid
materialization or with failed embeds reported vectors it did not have.
The
  value reaches users through `repository_vectors.py` →
`daemon/similarity.py` → `web_shell_similar.py` as "N embedded
messages".

## Solution

Semantics: bump `SEMANTICS_VERSION` to 4 and regenerate the checked-in
cross-repo fixture; gate `resolve_anchor` on the version as
`verify_revision`
already was; read the declared version as an exact integer, rejecting
`bool`,
non-integral floats and strings.

Schema identity: commit the stamp inside `initialize_archive_tier`, the
single
choke point every derived-tier materialization passes through; admit the
stored version in `open_initialized_tier_connection` *before*
materialization
can restamp it; assert the derived identity in
`assert_tier_schema_supported`
alongside the version; split `assert_readable_archive_layout`'s handler
so a
SQLite failure reports a new `retry` lifecycle action instead of
`rebuild_index`; cache the canonical manifest per declared schema, keyed
on the
DDL so a substituted schema cannot take a stale hit; exclude FTS5 shadow
tables
by exact suffix; route raw-failure admission and frontier source
selection
through the schema-enforcing open; classify `schema_identity` in the
rebuild
differential as comparable, since a rebuild producing a different
identity is
exactly what that differential is for.

Writer: take all four tool-verdict columns from one row together;
re-derive
`session_kind` through `admitted_session_kind` wherever the projection
writes
`branch_type`; replace the stale attachment-direction refusal test with
tests
for the derivation #4587 introduced.

Vectors: count distinct stored refs joined to vector metadata; refuse a
missing
active index instead of creating one.

## Half-refuted, half-fixed

- **3** — "`_seed_session_model_usage_rows` never clears rows for a
previous
model, so `usage.py`'s `SUM(provider_cost_usd)` double-counts after a
model
  switch."

**Refuted for the full-replace path**, which is the mechanism as stated.
Every full-replace write first calls `_clear_session_projection_rows`,
whose
table list includes `session_model_usage` (write.py:1217), so no stale
row
  survives to be summed. Two existing tests cover exactly this and pass:
`test_provider_usage_model_switch_on_reingest_does_not_double_count` and

`test_provider_usage_model_vanishing_on_reingest_leaves_no_stale_rollup`.

**Confirmed for merge-append**, which that clearing cascade does not
cover.
  master already carries a test for the intended contract —
`test_merge_append_replaces_prior_provider_total_on_model_switch`, added
by
#4505 — and it has been failing ever since, because nothing clears the
prior
model's `provider_cost_usd`. Verified by exercising the writer directly
at
  master's `write.py` and at this branch's: both returned
`[gpt-new 2.0, gpt-old 1.0]` where the test requires `gpt-old` to be
`None`.
  The fifth commit clears the prior attribution, and that same probe now
  returns `[gpt-new 2.0, gpt-old None]`.

## Refuted, not fixed

- **14** — "`SameVersionSchemaVariant` has no upper bound; the index
tier is at
v85 while the v78 SEMANTIC_REPARSE entry's variant is still unbounded."
There
is no v78 variant. `INDEX_SAME_VERSION_SCHEMA_VARIANTS` contains exactly
one
entry, `introduced_version=63` (`remove_fts_bulk_guard` on three trigram
triggers), and always has. The named entity does not exist, so there is
no
concrete input with a wrong outcome. The open-ended applicability of
that one
entry is a deliberate property of a permanently retained benign
trigger-body
  variant, not a defect.

## Deferred, with reasons

Two findings are real and unfixed here because each is a design change
rather
than a review-sweep patch. Both warrant their own tracked work:

- **6** — the embedding contract refresh commits data and metadata
non-atomically, and both `writer_lock()` and `recover_interrupted()`
call
`_generations()`, which raises on the resulting mismatch with no path
out.
  Confirmed still true. A fix means making `generation.json` publication
crash-safe and giving recovery a way to re-derive the contract from the
committed database; that is the embeddings lifecycle's durability
contract,
  not a patch.
- **8** — `sqlite_vec_runtime._get_connection` rebuilds the full
`current_embedding_messages` projection — a whole-archive scan and join
with
  a per-row hash — on every connection, and every query opens its own
  connection. Confirmed still true. A fix needs a cache keyed on index
generation or a pooled connection, with the invalidation and concurrency
  design that implies.

Also worth noting: there is no `devtools` command to regenerate the
material-protocol golden fixture. It was regenerated here through
`encode_session_revision` + `write_revision` and verified byte-for-byte
against
a fresh encode; a supported regeneration route would be a reasonable
follow-up.

## Verification

```
devtools verify --quick
devtools test tests/unit/storage/test_writer_verdict_and_kind_projection.py \
  tests/unit/storage/test_derived_schema_identity_admission.py \
  tests/unit/storage/test_archive_tiers_write.py \
  tests/unit/storage/test_vec_session_seed.py \
  tests/unit/material_protocol/v1/ \
  tests/unit/storage/test_archive_readiness.py \
  tests/unit/storage/test_derived_schema_identity.py \
  tests/unit/storage/test_cost_queries.py -n 4
```

All twelve static gates pass, including `schema-versioning`.

Anti-vacuity was checked by mutation, not assumed. Reverting the
`conn.commit()`
in `initialize_archive_tier` turns
`test_schema_identity_stamp_survives_the_connection_that_wrote_it` red;
deleting the stored-version admission from
`open_initialized_tier_connection`
turns `test_a_skewed_tier_is_refused_before_materialisation_restamps_it`
red.
Both were run and observed. Every new test's docstring names the
specific
mutation that makes it fail.

## Residual risk

- Asserting the derived identity in `assert_tier_schema_supported`
refuses a
tier at the current version whose stamp does not match this runtime.
That is
the intent, and `initialize_archive_database` already enforced the same
check
on its own route, so an archive in normal use is already stamped. The
check
is deliberately *not* on every `open_connection` — an earlier draft put
it in
`_assert_schema_supported`, which would have made every read open
recompute
`derived_schema_identity` (uncached, over three fingerprints) and would
have
  refused any never-stamped archive on a read-only path.
- `lifecycle_action="retry"` is a new value in that field. It is
free-form and
forwarded to MCP payloads; no closed vocabulary or dispatch consumes it.
- The FTS5 shadow filter matches the five exact FTS5 suffixes rather
than a
name prefix. A prefix would have wrongly dropped `messages_fts_identity`
and
the three `messages_fts_a{i,d,u}` triggers, which are ours; the test
asserts
  both halves.
- Bumping `SEMANTICS_VERSION` to 4 makes this reader reject v3 bytes by
contract. `constants.py` notes the fixture is checked in "in lockstep
with
the Sinex counterpart (sinex-4j2.1)"; that repo pins the same version
and
will need the corresponding bump. Nothing in this repo reads v3 bytes
from
  disk outside the regenerated fixture.
- `tests/unit/storage/test_archive_readiness.py` builds stub two-table
index
databases to exercise gap classification. Now that the probe reads
through
the schema-enforcing open, those fixtures stamp the precondition
explicitly
  via a named helper rather than relying on the probe not checking.

## Inherited failure


`tests/unit/storage/test_connection_profile.py::test_open_readonly_connection_uses_descriptor_bound_database`
fails identically on clean `origin/master` (verified by stashing this
branch's
changes and rerunning). It is not touched or fixed here.

`test_merge_append_replaces_prior_provider_total_on_model_switch` was
also
inherited-red, confirmed the same way; unlike the above it is fixed
here,
because it is the merge-append half of finding 3.

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

https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):

  • P1 polylogue/storage/sqlite/archive_tiers/write.py:837: Fixed on master (checked at 64a9bd0): Projection refresh re-derives session_kind from the branch type it projects from resolved links (_projected_session_kind, write.py:8397-8410), used for both root and child projections (write.py:8478, 8506). A child known only through a hook-derived subagent edge is therefore stored as subagent.
  • P1 polylogue/storage/sqlite/archive_tiers/write.py:2662: Fixed on master (checked at 64a9bd0): Verdict columns are skipped in the field-by-field coalesce (write.py:4709-4710). They are then copied as one unit from whichever row expresses a verdict (_apply_tool_verdict, write.py:4686-4690), before the content hash is computed (write.py:4720-4722).
  • P1 polylogue/storage/sqlite/archive_tiers/write.py:5757: Fixed on master (checked at 64a9bd0): _write_provider_cost splits the reported total across the declared rows. It then clears provider_cost_usd on every other model row of the session (write.py:210-214), so a model switch no longer leaves the previous total summed alongside the new one.

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at f88b4a6):

  • P1 polylogue/sinex/material_adapter.py:263: Fixed on master (checked at f88b4a6): The Sinex material adapter runs the shared derive_tool_outcomes normalization over the parsed session before encoding blocks (polylogue/sinex/material_adapter.py:417).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at c950478):

  • P2 polylogue/sources/live/deferred_cursor.py:70: Fixed on master (checked at c950478): A legacy Claude frontier is promoted only when the recomposed body digest equals the cursor's accepted body_sha256; otherwise no semantic authority is written (polylogue/sources/live/deferred_cursor.py:89-95).
  • P2 polylogue/sources/origin_specs.py:1427: Fixed on master (checked at c950478): The Claude AI spec now declares the message parent as carried and branch state as positive-derived (polylogue/sources/origin_specs.py:2941-2948).
  • P2 polylogue/sources/origin_specs.py:1508: Fixed on master (checked at c950478): The AI Studio/Drive spec now declares the message parent as carried and branch state as positive-derived (polylogue/sources/origin_specs.py:3080-3089).
  • P2 polylogue/sources/origin_specs.py:1108: Fixed on master (checked at c950478): In the ChatGPT spec, the inheritance branch point is now declared through _absent_topology, so intra-conversation mapping ancestry is no longer advertised as session inheritance (polylogue/sources/origin_specs.py:2157).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 5d56c3a):

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at c0dda6f):

  • P2 polylogue/daemon/http.py:420: Fixed on master (checked at 64a9bd0): Duplicate detection is retained by comparing tuple length with set length for both generated and installed routes (polylogue/daemon/http.py:459-460).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 8e6234c):

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 8e6234c):

  • P2 polylogue/mcp/server_support.py:448: Fixed on master (checked at 64a9bd0): schema_bootstrap imports the single SchemaSkewError from polylogue.core.errors, so the MCP branch covers derived-tier checks (polylogue/storage/sqlite/schema_bootstrap.py:27).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 5ebcfe5):

Resolving every thread listed; confirmed defects are fixed under the named bead.

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