Skip to content

fix: Derive id-less message identity from content, not position - #5103

Merged
Sinity merged 1 commit into
masterfrom
fix/content-derived-message-identity
Sep 14, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/content-derived-message-identity

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

messages.message_id no longer falls back to the parser's ordinal when a provider supplies no message id. The fallback is now a digest of the message's own declared semantic fields plus an occurrence ordinal scoped to that digest: 'c:' || content_identity || '.' || content_occurrence. message_id remains a SQLite generated column.

Index tier, so no migration — but the derived schema identity moves and the archive must fully reconverge. Land before a rebuild starts, never during one.

Problem

archive_tiers_specs.py:286 derived the id-less branch as 'p:' || position || '.' || variant_index, where position is the parser's ordinal (write.py:_build_message_rows), and blocks.block_id = message_id || ':' || position inherited it.

user.db is the durable, irreplaceable tier, and it keys into exactly these ids. archive_tiers/user_overlay.py is the explicit map (session / message / block / attachment / paste_span / work_event / phase / thread), and security/secret_scan.py is a live production writer persisting findings as block:<block_id>.

The durable-ref consequence. When an upstream export gains or loses one message, every later p: id renumbers. A stored durable reference does not then dangle — it silently resolves onto a different message. A secret-scan finding recorded against one block comes to point at an unrelated block. No existence check can see this: both orphan detectors in the tree are existence-based.

Cost inverts at the rebuild boundary. Changing message_id breaks every p:-shaped ref already stored; after the wipe there are none, so the breakage is free exactly once.

Solution

The generated-column question (answered before writing code)

A content hash cannot be computed in SQL from a message row alone — the content lives in blocks, a different table. But it does not have to be: the hash is computed in Python at the write boundary and stored as an ordinary column, exactly as the pre-existing content_address and content_hash columns already are. message_id therefore stays a generated column, computed in SQL from columns on its own row. The generated-column model is preserved, not worked around.

Two new messages columns:

  • content_identity TEXT — hash_payload(_message_semantic_payload(message)) truncated to 32 hex chars (128 bits; it only has to separate messages inside one session). The payload is _HASHED_FIELDS["ParsedMessage"] from pipeline/ids.py — the partition that already declares exhaustively which parser fields are content, and which are parser-only coordinates or independently-owned measurements. Position, variant index, branch index, path markers, usage and timing are all on the excluded side, which is precisely the property this identity needs.
  • content_occurrence INTEGER NOT NULL DEFAULT 0 — occurrence ordinal among messages sharing that digest. Two byte-identical id-less messages stay distinguishable, and an unrelated insertion never moves either one's ordinal.

Invariants preserved

  • Namespace disjointness. n: / c: still keep a provider-native id from ever colliding with a fallback. core/identity_law.py is the Python mirror and now raises rather than inventing an identity when neither is available.
  • identity_source still records which path fired — native or content (was native / positional).
  • No silently-NULL id. A new table CHECK(native_id IS NOT NULL OR content_identity IS NOT NULL) refuses a row that would generate a NULL message_id (UNIQUE admits many NULLs, so every reference into such a row would dangle unseen).

Write path

message_content_identities(messages, occurrence_offsets=...) resolves the batch once in write_parsed_session_to_archive, and that one tuple is threaded to every row builder and every id-recomputing helper (the same route duplicate_native_ids already takes), so no two of them can disagree with the generated column or with each other. _message_id now requires it — there is no positional default left to fall back into.

Appends need a second frontier coordinate: _stored_content_occurrences(conn, session_id) returns the per-digest counts already written, so an appended message identical to a stored one continues that digest's numbering instead of colliding. PreparedSessionRows carries those offsets and the merge-append path validates them alongside position_offset.

material_protocol/v1 mirrors the index ids, so MessageInput gained the same two fields; the hydrated-archive adapter restates them from the stored id via a new split_message_local_id.

Verification

Schema closure on every touched file (devtools schema closure <file>):

IN   polylogue/archive/message/models.py
IN   polylogue/core/identity_law.py
IN   polylogue/pipeline/ids.py
IN   polylogue/storage/runtime/archive/records.py
IN   polylogue/storage/sqlite/archive_tiers/archive_tiers_specs.py
IN   polylogue/storage/sqlite/archive_tiers/write.py
IN   polylogue/surfaces/payloads.py
out  polylogue/material_protocol/v1/input_model.py
out  polylogue/material_protocol/v1/records.py
out  polylogue/sinex/material_adapter.py
out  polylogue/storage/attachment_relink.py

Seven files are IN the derived-schema closure. The identity moves; the archive must reconverge.

New tests (tests/unit/pipeline/test_archive_write.py):

  • test_inserted_message_does_not_renumber_later_idless_message_ids — two archives built from exports differing only by an inserted message give the same local id to the same logical message.
  • test_identical_idless_messages_keep_distinct_occurrence_ordinals — byte-identical id-less messages stay distinct and stably numbered.

Anti-vacuity, verified by reverting. Making message_content_identities return the ordinal instead of the digest (the exact pre-fix behavior, consistent on both the SQL and Python sides) turns the first test red with:

E           AssertionError: 'second' changed identity because an unrelated message was inserted
E           assert 'c:1.0' == 'c:2.0'

That is the defect itself: one insertion, and a message two positions later answers to a different id.

Commands, all on the final tree:

  • devtools verify --quick — exit 0 (every static gate: format, lint, mypy, generated-surfaces, layering, patterns, doc-commands, schema-manifest, oracle-integrity, testmon-selection, consumer-reachability, test-packages, timestamp-doctrine, durable-enum-checks, schema-privacy).
  • devtools test tests/unit/core/test_identity_law.py tests/property/test_message_identity_normalization.py tests/unit/pipeline/test_archive_write.py tests/unit/storage/test_archive_tiers_write.py tests/unit/pipeline/test_branching.py — PASSED exit=0.
  • devtools test tests/unit/storage/test_topology_edges.py — PASSED exit=0.
  • devtools test tests/unit/storage/test_spec_owned_row_plumbing.py tests/unit/storage/test_query_unit_time_expression.py tests/infra — PASSED exit=0.
  • devtools render all --check — no out of sync.
  • devtools gate atlas — 19 BLOCKs, every one of them also present on a clean master tree (re-run to confirm); none names a file this PR touches.

A wider tests/unit/storage tests/unit/maintenance tests/property tests/unit/pipeline sweep surfaced three fixtures that inserted messages rows with neither identity (now supplying a content_identity) and one hand-authored oracle asserting literal p: ids; it was then cancelled rather than run to completion under host-pool contention, so the broad evidence here is CI's, not a local full run.

Residuals

  • messages.content_identity truncates the digest to 128 bits. Uniqueness is only required within one session; a collision there would surface as a UNIQUE violation on message_id, not as silent misresolution.
  • This shrinks, but does not close, the gap behind maintenance durable-reference-transition: content-derived ids need no IdentityMigrationMap, but transition="successor" still has no implementing branch in assertion_transition.py and make_default_convergence_stages still contains no overlay/ref stage.
  • messages.position / variant_index are unchanged and still own transcript order and the primary key; only identity moved off them.
  • content_identity / content_occurrence are write-bound storage inputs and are not projected onto MessageRecord — message_id and identity_source already state the identity on read surfaces.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

`messages.message_id` fell back to `'p:' || position || '.' ||
variant_index` whenever a provider supplied no message id, and
`blocks.block_id = message_id || ':' || position` inherited it. `position`
is the parser's ordinal, so an upstream export that gained or lost one
message renumbered every later `p:` id.

`user.db` is the durable, irreplaceable tier and keys into exactly these
ids (`user_overlay.py` maps session/message/block/attachment/paste_span/
work_event/phase/thread), with a live writer in `security/secret_scan.py`
persisting findings as `block:<block_id>`. Under renumbering a stored
durable reference does not dangle -- it silently resolves onto a
*different* message. Both orphan detectors in the tree are
existence-based, so nothing sees it.

The fallback is now content-derived: `'c:' || content_identity || '.' ||
content_occurrence`. `content_identity` is a digest over the declared
semantic partition already exhaustively defined in `pipeline/ids.py`
(`_HASHED_FIELDS["ParsedMessage"]`), which puts position, variant index,
branch index, path markers, usage and timing on the excluded side.
`content_occurrence` counts only among messages sharing one digest, so an
unrelated insertion never moves it.

`message_id` stays a SQLite generated column: both inputs are plain
columns on the row, written by the same choke point that already computes
`content_address` and `content_hash`. The `n:`/`c:` namespace tags keep a
provider-native id from ever colliding with a fallback, a new table CHECK
refuses a row carrying neither identity, and `identity_source` now records
`native` or `content`.

Index tier, so no migration -- but it moves the derived schema identity
and requires full reconvergence.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@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 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 8 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: f0983d34-e691-40e3-b70e-badf1543b687

📥 Commits

Reviewing files that changed from the base of the PR and between 513c887 and 2449a59.

📒 Files selected for processing (67)
  • CLAUDE.md
  • docs/atlas/00-core.md
  • docs/atlas/storage.md
  • docs/data-model.md
  • docs/material-protocol-v1.md
  • docs/schema.md
  • docs/schemas/cli-output/session-message-row.schema.json
  • docs/schemas/cli-output/session-messages-response.schema.json
  • polylogue/archive/message/models.py
  • polylogue/core/identity_law.py
  • polylogue/material_protocol/v1/input_model.py
  • polylogue/material_protocol/v1/records.py
  • polylogue/pipeline/ids.py
  • polylogue/sinex/material_adapter.py
  • polylogue/storage/attachment_relink.py
  • polylogue/storage/runtime/archive/records.py
  • polylogue/storage/sqlite/archive_tiers/archive_tiers_specs.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • polylogue/surfaces/payloads.py
  • tests/benchmarks/test_full_session_replace.py
  • tests/benchmarks/test_graph_resolve_deferred_tail.py
  • tests/infra/identity.py
  • tests/infra/schema_inference.py
  • tests/property/test_fts_identity_state_machine.py
  • tests/property/test_message_identity_normalization.py
  • tests/property/test_session_count_write_paths.py
  • tests/property/test_write_path_state_machine.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/archive/query/test_execution_control.py
  • tests/unit/archive/test_with_units_projection.py
  • tests/unit/cli/test_query_exec_laws.py
  • tests/unit/cli/test_query_expression.py
  • tests/unit/cli/test_streaming_markdown_read_view.py
  • tests/unit/core/test_identity_law.py
  • tests/unit/daemon/test_web_reader.py
  • tests/unit/maintenance/test_archive_verification.py
  • tests/unit/maintenance/test_source_conservation.py
  • tests/unit/mcp/test_read_messages_view.py
  • tests/unit/pipeline/test_archive_write.py
  • tests/unit/pipeline/test_branching.py
  • tests/unit/pipeline/test_resilience.py
  • tests/unit/sources/test_claude_code_fork_context_ref.py
  • tests/unit/sources/test_claude_code_normalization_laws.py
  • tests/unit/storage/test_archive_search_contracts.py
  • tests/unit/storage/test_archive_tiers_archive.py
  • tests/unit/storage/test_archive_tiers_assertions.py
  • tests/unit/storage/test_archive_tiers_ddl.py
  • tests/unit/storage/test_archive_tiers_provider_fixtures.py
  • tests/unit/storage/test_archive_tiers_write.py
  • tests/unit/storage/test_attachment_acquisition.py
  • tests/unit/storage/test_attachment_relink.py
  • tests/unit/storage/test_fts_repair_sql.py
  • tests/unit/storage/test_lineage_normalization.py
  • tests/unit/storage/test_marks_identity_preserving.py
  • tests/unit/storage/test_message_query_reads.py
  • tests/unit/storage/test_pl_fold.py
  • tests/unit/storage/test_query_unit_time_expression.py
  • tests/unit/storage/test_schema_safety.py
  • tests/unit/storage/test_search_snapshot_ownership.py
  • tests/unit/storage/test_search_timeless_since_filter.py
  • tests/unit/storage/test_session_insight_refresh.py
  • tests/unit/storage/test_spec_driven_hydration.py
  • tests/unit/storage/test_spec_owned_row_plumbing.py
  • tests/unit/storage/test_store_ops.py
  • tests/unit/storage/test_unread_wire_batch_v46.py
  • tests/unit/test_transcript_order_agreement.py
  • tests/visual/conftest.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.

@Sinity
Sinity merged commit 398c604 into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the fix/content-derived-message-identity branch September 14, 2026 17:07
Sinity added a commit that referenced this pull request Sep 14, 2026
## Summary

Every hand-built `messages` fixture that inserted a row with neither
`native_id` nor `content_identity` now states the identity it actually
models. Adds the refusal test the new CHECK was missing.

## Problem

PR #5103 replaced positional message identity (`p:position.variant`)
with content-derived identity (`c:<digest>.<occurrence>`) and added to
the index tier:

```
CHECK(native_id IS NOT NULL OR content_identity IS NOT NULL)
```

The constraint is right: a row with neither identity generates a NULL
`message_id`, and `UNIQUE` admits many NULLs, so such rows would be
mutually indistinguishable and unreferenceable. #5103's author fixed the
three fixtures they hit and cancelled a wider sweep under pytest-pool
contention, saying the broad evidence would have to come from CI.

That evidence: a full-corpus `verify_all` on frozen master `890a2921e`
(job 1570, receipt
`.cache/verify/runs/20260914T200510Z-all-4027943-f8bc83ff`) reported
**147 failures, 116 of them** this one error:

```
IntegrityError: CHECK constraint failed: native_id IS NOT NULL OR content_identity IS NOT NULL
```

Parsing that run's `pytest-report.json` for the error gives the exact
worklist — five files, not four:

| failures | file |
| --- | --- |
| 88 | `tests/unit/maintenance/test_archive_verification.py` |
| 22 | `tests/unit/maintenance/test_source_conservation.py` |
| 4 | `tests/unit/storage/test_search_timeless_since_filter.py` |
| 1 | `tests/unit/storage/test_archive_tiers_ddl.py` |
| 1 | `tests/unit/storage/test_revision_application.py` |

A sweep of `INSERT INTO messages` across `tests/` found no further
offenders on the production index DDL: the remaining identity-less
inserts (`test_repo_facet_canonicalization.py`, the `embed_*` and
`status` tests) run against hand-written toy schemas that carry no such
column, and `tests/infra/storage_records.py` always supplies
`native_id`.

## Solution

Identity was chosen per fixture, not uniformly:

- **`content_identity`, because the fixture models an id-less message.**
Every offending row here is id-less by construction — none of them names
a provider message id, and several already assert a `c:<digest>.0` block
id downstream, so the fixture had already decided which identity path it
was on. `test_archive_verification.py`, `test_source_conservation.py`
and `test_revision_application.py` reuse the digest literal their own
block ids already embed, which is the precedent #5103 set in
`tests/infra/schema_inference.py:53`.
- **A derived digest where the fixture builds its ids in Python.**
`test_search_timeless_since_filter.py` and `test_archive_tiers_ddl.py`
call `archive_message_id(session, None)`, which now requires a
`content_identity`. New helper
`tests/infra/identity.fixture_content_identity(*parts)` digests the
semantic text the fixture models, truncated to the production width
(`MESSAGE_CONTENT_IDENTITY_HEX_CHARS`), so the INSERT and the expected
id come from one value.
- **`content_occurrence`, not `variant_index`, separates the DDL test's
two id-less rows.** They model two variants of the same content, so they
share a digest; the generated column consumes `content_occurrence`, and
`variant_index` remains what it is — transcript order, not identity. The
stale assertion (which expected `archive_message_id(..., None)` twice,
now two distinct ids) is updated with them.
- **No fixture was found inserting an identity-less row deliberately**,
and no test anywhere asserted the CHECK refuses one — `grep` for the
constraint text hit only `archive_tiers_specs.py:497`.
`test_a_message_with_neither_identity_is_refused_by_the_index_schema`
closes that gap. Anti-vacuity: delete the CHECK from the spec and the
insert succeeds, so the test goes red.

`test_revision_application.py` carried a second staleness in the same
fixture — a block row keyed on the old positional id
`codex-session:session:0.0`. Corrected to the `c:` form.

## Verification

`devtools test` on all five files, from this worktree:

```
1 failed, 202 passed, 1 warning in 113.52s
devtools test: FAILED exit=1 receipt=.cache/verify/runs/20260914T215910Z-focused-test-4156515-bfcd8adf/run.json
```

All 116 CHECK failures are cleared. The one remaining failure is

`test_every_live_declaration_does_not_error_on_the_real_pipeline_corpus[blob-integrity]`
— pre-existing and unrelated (a stray
`.polylogue-index-liveness-watermark.json` in the seeded artifact's blob
namespace); it is one of the 31 non-identity failures in the same master
receipt, and is not addressed here.

`devtools verify --quick`: all 17 static gates ok, exit 0.

`devtools schema closure` on all six touched files: `out` for every one,
as expected for test files — no reconvergence implied.

## Residuals

- Nothing in this PR clears any of the other 31 failures from that run
(stale CLI snapshots, the `no such column` regex mismatch, the Hermes
marker `ValueError`s, the fresh-root `OperationalError`, the
`blob-integrity` seeded-artifact finding). Those remain open.
- No identity here was genuinely ambiguous: every offending row was
id-less by construction, so `content_identity` was the honest field in
all of them, and `native_id` was never a candidate.
- Full-corpus re-verification has not been run on this branch; the
evidence above is the five affected selections plus the static gates.

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

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Expanded coverage for message identity handling, including consistent
identifiers for repeated content.
  * Added validation that messages must include a supported identity.
* Improved verification of archive integrity and full-text search
behavior.
* Added coverage confirming timeless sessions are included appropriately
by date filters while out-of-range timestamped sessions remain excluded.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

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

## Summary

#5103 made an id-less message's identity content-derived. Two
declarations still describe the world before it. One is a latent
correctness gap in the session-input binding; one is a stale test
fixture.

> **⚠️ This PR is IN the derived schema-identity closure. It must land
before an archive rebuild starts, never during one.** See the closure
section.

## Evidence

Receipt `.cache/verify/runs/20260914T233651Z-all-207009-89ddea6b`
(`verify_all`, job 1699, 22,540 selected, 29 failed).

**Caveat on that receipt:** its `run.json` records `git_head:
f7964ac` — the tip of branch
`rebase-5165`, *not* `master` and not an ancestor of it — and
`final_git_head: 724d175`. The shared checkout advanced across 7
merged PRs during the run, so it is not evidence of a frozen tree. I
re-ran all 29 node ids at true `master` HEAD: 17 reproduce, 12 do not.
These 2 are among the 17.

## Per-failure classification

| Failure | Classification | Cause |
| --- | --- | --- |
|
`test_session_partition_convergence::test_the_partition_input_columns_are_projected_or_declared_excluded`
| **product defect (latent)** | `content_identity` /
`content_occurrence` neither projected nor excluded in
`SESSION_INPUT_PROJECTION_COLUMNS`; the binding digest can report VALID
over a moved output |
|
`test_lineage_validation::test_hand_built_index_declares_every_production_column_of_route_backed_tables`
| **stale test** | test-side `messages` DDL mirror not updated for #5103
|

## Problem

`SESSION_INPUT_PROJECTION_COLUMNS` is hashed into the session-input
binding digest; a stored binding compares unequal only when a projected
value moves. It is a freshness/invalidation digest, and the derived
profile outputs embed `message_id`.

After #5103, `message_id` for an id-less message is generated from
`content_identity || '.' || content_occurrence`. Neither column was
classified.

**They are not covered by the projected `content_hash`.** I verified the
two field sets directly rather than assuming:

- `content_identity` hashes `_HASHED_FIELDS["ParsedMessage"]`: `blocks,
delivery_status, end_turn, is_aborted_mid_stream, material_origin,
message_type, model_effort, model_name, occurred_at_ms,
parent_message_provider_id, paste_spans, provider_message_id, recipient,
role, sender_name, stop_reason, text, timestamp, user_context_text`.
- `_message_content_hash`
(`storage/sqlite/archive_tiers/write.py:2559+`) hashes a strict subset —
it omits **`is_aborted_mid_stream`, `parent_message_provider_id`,
`paste_spans`, `timestamp`**.

Concrete counterexample: change `parent_message_provider_id` on an
id-less message. `content_identity` moves → `message_id` moves → derived
rows carry new message ids. `content_hash` does not move (that field is
not among its inputs) and `parent_message_id` is itself
declared-excluded. Every projected column is unchanged, so **the binding
reports VALID over a moved output.**

`content_occurrence` is reachable independently: it is offset-continued
on append, so a re-ingest ordering change renumbers it without touching
any other projected value.

## Solution

**Project, do not exclude.** Exclusion was not actually available:
`message_id` is itself excluded, on a reason #5103 made false
(*"generated from session_id, position, variant_index and native_id"*).
Excluding its inputs as well would leave the entire message identity
unbound by the digest. That stale reason is corrected here too.

Both options are AST-visible changes to `input_binding.py` and move the
schema identity identically, so the cheaper-looking option was not
cheaper.

The second change is a pure test fixture. `grep -E "CREATE TABLE (IF NOT
EXISTS )?messages"` over `polylogue/`, `devtools/`, `tests/` returns
exactly one production DDL site, generated from the specs — so no
production route could have silently dropped these columns. Its
`identity_source` default (`'positional'` vs production `'content'`) was
stale from the same PR and is corrected.

`SESSION_INPUT_RECIPE_VERSION` is **not** bumped: the projection tuple
itself moved, so every stored binding already compares unequal.

## Verification

```
devtools test tests/unit/devtools/test_lineage_validation.py tests/unit/storage/test_session_partition_convergence.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T013747Z-focused-test-322371-09072164/run.json
```

Because the projection is closure-bearing, I also ran every declared
consumer of the binding and the derived-identity gates:

```
devtools test tests/unit/storage/test_session_profile_derivation.py tests/unit/storage/test_lineage_normalization.py \
  tests/unit/storage/test_derived_schema_identity.py tests/unit/storage/test_derived_schema_identity_admission.py \
  tests/unit/storage/test_derived_status.py tests/unit/storage/test_session_profile_cost_columns.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T013921Z-focused-test-323349-dafc4468/run.json
```

## Schema closure

```
devtools schema closure polylogue/storage/derived/session/input_binding.py
IN   polylogue/storage/derived/session/input_binding.py
  Editing a file marked IN moves the derived schema identity: the archive must
  reconverge, and the change must land before a fresh rebuild starts, never during one.

devtools schema closure tests/unit/devtools/test_lineage_validation.py
out  tests/unit/devtools/test_lineage_validation.py
```

**IN.** This PR moves the derived schema identity and requires full
reconvergence. Land it before any rebuild begins.

## Anti-vacuity

The completeness test goes red on any `messages` column that is neither
projected nor declared-excluded — removing either new entry reproduces
the failure exactly. The lineage fixture test goes red by name if either
column is dropped from the hand-built DDL.

**Honest residual on the projection specifically:** that completeness
check proves the columns are *classified*, not that projecting them was
the *right* classification. The existing role differential at
`test_session_partition_convergence.py:965` is not parameterized over
these columns, so it does not cover them. The non-vacuous test would be
a differential on a session of id-less messages that moves
`parent_message_provider_id` (or `paste_spans`) so `content_identity`
moves while `content_hash` and every other projected column hold still:
the binding must change with the columns projected, and must not with
them monkeypatched out. I have not added it — flagging it as follow-up
test work rather than claiming coverage this PR does not have.

## Residuals

- The differential test above is not written.
- `CLAUDE.md`'s identity section still documents the retired `p:`
positional fallback; #5103 replaced it with `c:`. Not corrected here —
separate concern, and it is doc text rather than a closure input.

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

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

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

Three unrelated tests on `master` still describe the world before a
landed product change. Each names the PR that moved the product. None is
a product defect; in each case the product is right and the test was
left behind.

## Evidence

Receipt `.cache/verify/runs/20260914T233651Z-all-207009-89ddea6b`
(`verify_all`, job 1699, 22,540 selected, 29 failed).

**Caveat on that receipt:** its `run.json` records `git_head:
f7964ac` — the tip of branch
`rebase-5165`, *not* `master` and not an ancestor of it — and
`final_git_head: 724d175`. The shared checkout advanced across 7
merged PRs during the run, so it is not evidence of a frozen tree. I
re-ran all 29 node ids at true `master` HEAD: 17 reproduce, 12 do not.
These 3 are among the 17.

## Per-failure classification

| Failure | Classification | Which PR moved the product |
| --- | --- | --- |
|
`test_schema_policy_contracts::test_read_only_archive_open_does_not_bootstrap_missing_tiers`
| **stale test** | #5162 (`817eec6f4`) typed the refusal as
`ArchiveTierUnavailableError` |
|
`test_write_path_state_machine::test_positional_branch_point_alias_is_typed_dangling`
| **stale test** (premise no longer constructible) | #5103 (`398c60458`)
made id-less message identity content-derived |
|
`test_compare_command::test_compare_with_verdict_records_and_is_readable_via_calibration`
| **stale test** | #5172 (`724d17535`) routed CLI facade writes through
declared daemon operations |

## Solution

**#5162 leftover.** `ArchiveTierUnavailableError` is a `DatabaseError`,
not an `sqlite3` exception, so it propagated straight through
`pytest.raises(sqlite3.OperationalError)`. #5162 landed its own
replacement (`test_absent_index_tier_is_typed.py`); this was the other
half. The test's actual subject — `assert not
any(tmp_path.glob("*.db"))`, that a read-only open of nothing creates
nothing — is untouched.

**#5103 leftover — the one worth reading closely.** The old test
renumbered the parent (`A,B` → `X,A,B`) so the child's
`p:<position>.<variant>` branch-point alias would land on a different
row. Under content-derived identity that alias no longer exists:
`message_id` is now `'c:' || content_identity || '.' ||
content_occurrence`, so "B" resolves to the same real message wherever
it sits, the content witness matches, and the composed prefix `X, A, B`
was **legitimately correct**. The writer was not wrongly resolving
anything — there was no longer a dangling reference to detect.

The dangling rule itself is intact and still worth proving, so I rebuilt
the premise rather than relaxing the rule: the replacement now **drops
"B" outright**, so the child's branch point genuinely vanishes and the
envelope must truncate to the child's own tail. Renamed to
`test_vanished_branch_point_is_typed_dangling` to say what it actually
tests.

**#5172 leftover.** Requiring a daemon for `compare --verdict` is not an
over-reach — it is the stated single-writer route, and `judge` moved the
same way. #5172 migrated `test_judge_command`,
`test_mark_note_identity`, `test_verb_cardinality`,
`test_cli_action_contracts` and `test_assertion_candidates`, but missed
this file. The verdict case moves onto the same `cli_daemon_archive`
stack (a real `DaemonOperationRuntime` behind a real UDS listener), so
the file's whole stated premise — a real production caller for
`blind_items`, `ClaimWithControls`, `compute_calibration` and
`upsert_comparative_judgment_assertion` — survives rather than being
mocked away. Its sibling `test_compare_without_verdict…` still passes
untouched because it records nothing.

## Anti-vacuity

- **Read-only open:** restore bootstrap on the read-only path
(`initialize = not read_only`) and the no-`*.db` assertion goes red.
Keeping the expected type narrow (rather than the `DatabaseError` base)
keeps it red if the boundary re-leaks a raw driver error.
- **Vanished branch point:** delete the content-witness guard in
`write.py` (`if witness is not None: … composed = own; break`) and the
child composes the wrong parent prefix instead of truncating. This is
the condition the test always named — it just could not reach it any
more.
- **Compare:** mock the facade instead of supplying a daemon and the
file's premise is lost; stub the storage chokepoint and the
`--calibration` agreement rate goes wrong.

## Verification

```
devtools test tests/unit/storage/test_write_path_state_machine.py tests/unit/storage/test_schema_policy_contracts.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T014134Z-focused-test-325111-9b54466f/run.json

devtools test tests/unit/cli/test_compare_command.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T014228Z-focused-test-325880-7bf93813/run.json
```

## Schema closure

```
out  tests/unit/cli/test_compare_command.py
out  tests/unit/storage/test_write_path_state_machine.py
out  tests/unit/storage/test_schema_policy_contracts.py
```

**All OUT.** Test-only change; no product file touched. Does not need to
land before an archive rebuild.

## Residuals

- `CLAUDE.md`'s identity section still documents the retired `p:`
positional fallback that #5103 replaced with `c:`. Not corrected here —
it is doc text, not a closure input, and belongs with whoever owns that
section.
- `test_cli_operation_authority.py` covers the daemon-down refusal
matrix for `mark` and `judge` but not `compare`. Adding that case is
worthwhile follow-up; it is new coverage rather than part of this
red→green repair, so I have not claimed it.

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

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

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