Skip to content

feat(maintenance): add source-conservation and population-coverage gates - #4685

Merged
Sinity merged 1 commit into
masterfrom
lane/conservation-gate
Sep 5, 2026
Merged

Sinity merged 1 commit into
masterfrom
lane/conservation-gate

Conversation

@Sinity

@Sinity Sinity commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds two verification instruments: the source-conservation verify-archive
declaration (polylogue-bx26w, with the phantom-session term for polylogue-b508)
and devtools gate population-coverage (polylogue-rrxe4.1).

Problem

Nothing accounted for the whole acquired population. source-index-coverage
reasons over logical heads, so a raw row that is neither a head nor an error
could vanish from every ledger, and no check asked the reverse question: does
every index session, message, block, and attachment ref trace back to a raw
row it is entitled to come from? Against the live archive that gap hides real
material — sessions materialized from declared non-session artifacts
(polylogue-b508 phantoms) are indistinguishable from real ones by row shape.

Separately, no gate asserted that every origin, detector route, and artifact
kind observed in a source inventory is actually declared and witnessed.

Solution

source-conservation types every acquired source item — each raw_sessions
row, hook event, and history sidecar — into exactly one term that cites the
rule explaining it, and traces every index row back to its owner. Only
unexplained terms block: unexplained, unclassified_shape, source_lost,
orphans, and phantoms. Phantoms are reported by lineage and never deleted.

A source file that no longer exists on disk is not by itself a loss. When the
archive still retains the raw payload bytes the content is conserved, so that
is typed accounting (source_missing); only a vanished file whose bytes are
also gone (source_lost) blocks. This is what makes the check usable as the
acceptance instrument for a rebuilt archive, where 12,717 rows are
source-missing by ordinary export rotation.

population-coverage derives coverage from the declarations. A stored
recognized_unparsed support status is a row value, not a declaration, so it
no longer confers coverage on a kind that no OriginSpec rule claims. The
gate evaluates a source inventory only when --archive-root names one; it
previously defaulted to the operator's configured archive, which made a repo
gate's verdict depend on ambient machine state.

Two fixes fall out of the fixture work: planner-stats now covers the set
docs/maintenance.md and CLAUDE.md already documented (session_links was
missing from the code's tuple while action_pairs was never ANALYZEd by the
coherent fixture, so the check warned on every seeding), and the coherent
fixture ANALYZEs the whole index tier.

Verification

.venv/bin/python -m devtools test tests/unit/maintenance/test_source_conservation.py tests/unit/devtools/test_verify_population_coverage.py tests/unit/maintenance/test_archive_verification.py

================== 133 passed, 3 warnings in 71.27s (0:01:11) ==================

.venv/bin/python -m devtools verify --quick — all 13 gates ok, no out of sync.

.venv/bin/python -m devtools gate population-coverage — Population coverage: PASS.

Against the live archive, the forward direction accounts for all 43,124 raw
rows: 20,206 materialized, 8,153 revision-superseded, 12,717 source-missing,
1,140 non-session, 483 pending, 323 sidecar artifacts, 68 parse failures, and
34 unexplained. Reverse: 23,496 sessions, of which 5,072 are phantoms by
lineage, plus 1,858 unreferenced attachments.

Each changed test names its anti-vacuity condition:
test_deleted_source_file_retypes_the_raw_as_source_missing is vacuous
without the on-disk probe (the raw stays materialized);
test_deleted_source_file_without_retained_bytes_trips_source_conservation
is vacuous without the retained-bytes join (byte loss reads as the
non-blocking term); test_removed_artifact_rule_turns_its_kind_uncovered is
vacuous if coverage is read off the stored support status rather than the
declarations.

Residuals

The 34 unexplained raws and 5,072 phantoms are reported, not resolved — that
is the point of the instrument, and closing them is separate work.

Run against the live archive, population-coverage --archive-root reports two
uncovered constructs, aistudio-drive/unknown/decode_failed (15) and
aistudio-drive/unknown/unknown (2). Both predate this change and want their
own bead.

source-conservation stats every distinct source path once per run. That is
bounded by distinct paths rather than raw rows, but it is real I/O on a cold
cache; callers that must not touch the filesystem can pass
probe_filesystem=False.

Beads: polylogue-bx26w, polylogue-rrxe4.1, polylogue-b508

🤖 Generated with Claude Code

https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid

@coderabbitai

coderabbitai Bot commented Sep 5, 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: 83c4d2ad-54e1-4222-b311-be7f39549058


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 5, 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-05T15:54:03.051657Z 7900e50 New commits
ℹ️ 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.

@Sinity
Sinity enabled auto-merge (squash) September 5, 2026 13:11

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

ℹ️ 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 devtools/verify_population_coverage.py Resolved
Comment thread devtools/verify_population_coverage.py Resolved
Comment thread devtools/verify_population_coverage.py Resolved
Comment thread devtools/verify_population_coverage.py Resolved
Add the `source-conservation` verify-archive declaration: every acquired
source item types into exactly one term citing its rule, and every index
session, message, block, and attachment ref traces back to a raw row.
Phantom sessions (polylogue-b508) are reported by lineage and never
deleted. A source file that is gone while the archive still retains its
raw payload bytes is typed accounting (`source_missing`); only genuine
byte loss (`source_lost`) blocks, alongside unexplained, unclassified,
orphan, and phantom terms.

Add `devtools gate population-coverage`: every origin, detector route,
and artifact kind is declared and witnessed. Coverage comes from the
declarations, so a stored `recognized_unparsed` support status is not
itself a declaration, and the gate evaluates a source inventory only
when `--archive-root` names one - its result never depends on ambient
machine state.

`planner-stats` now covers the documented set including `session_links`,
and the coherent fixture ANALYZEs the whole index tier.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
@Sinity
Sinity force-pushed the lane/conservation-gate branch from c372428 to 7900e50 Compare September 5, 2026 15:31
@Sinity
Sinity merged commit 0fa2a9a into master Sep 5, 2026
4 checks passed
@Sinity
Sinity deleted the lane/conservation-gate branch September 5, 2026 15:36

@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: 7900e502c6

ℹ️ 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 devtools/verify_population_coverage.py Resolved
Comment thread devtools/verify_population_coverage.py Resolved
Sinity added a commit that referenced this pull request Sep 5, 2026
…4697)

## Summary

Restores the archive verification registry to green on seeded fixtures.
Two
merged PRs each left one declaration non-green, and 16 corpus tests
assert the
whole registry at a single seam
(`tests/infra/convergence_harness.py:371`), so
both surfaced as the same failure.

## Problem

Corpus run on master 754553b
(`/realm/tmp/work/corpus-2026-09-05c.log`):

```
AssertionError: archive verification registry is not green: [('planner-stats', 'warning',
'sqlite_stat1 missing coverage for: session_links (polylogue-l3tk class)', ...),
('source-conservation', 'error', '5 raw item(s), 0 hook event(s), 4 index session(s);
revision_superseded=1; attachment_unreferenced=1!', ...)]
```

**source-conservation.** #4692 (917e793) stopped dropping an
attachment whose
owning message is ambiguous and began retaining it as a typed unowned
row
(`ref_count` 0, deliberately excluded from the ref-count sweep). It has
no
`attachment_refs` row, so `source-conservation` counted it under
`attachment_unreferenced`, which blocks. A deliberate, explained
retention was
reported as archive corruption.

**planner-stats.** #4685 (0fa2a9a) added `session_links` to the
verified
covered set. The empty-table exemption added by #4692 is working
correctly —
the warning fires because `session_links` is *populated* and
un-ANALYZEd. The
production rebuild route (`rebuild_index.py`) did ANALYZE it; the test
archive
builders ANALYZEd a separately hand-copied list
(`tests/infra/convergence_harness.py`,
`tests/infra/schema_inference.py`) that
still read `blocks, messages, action_pairs`. One route drifted from the
verified set with nothing to catch it.

## Solution

**source-conservation** splits the ref-less attachment population on
`ref_count`, which is the discriminator the writer already establishes:

- `ref_count = 0` — inserted unreferenced and kept out of the sweep, so
it
  never had a ref: the new non-blocking `attachment_unowned` term.
- `ref_count != 0` — refreshed while refs existed, then lost them
without the
  sweep running. This is exactly the state
`refresh_and_sweep_attachment_rows` documents as unreachable from every
read
  path; it stays `attachment_unreferenced` and keeps blocking.

No schema change: adding a marker column to the index tier would have
forced an
`INDEX_SCHEMA_VERSION` bump, regenerated schema-disposition artifacts,
and a
rebuild plan, to record a fact two existing columns already determine.

**planner-stats** moves the covered set to one constant,
`PLANNER_STATS_COVERED_TABLES` in
`polylogue/storage/sqlite/maintenance.py`,
with an `analyze_planner_stats_tables()` helper. The verification check,
the
rebuild replay, and both test builders now read it, so a table added to
the
verified set cannot go uncovered on a single route. `rebuild_index`
still
ANALYZEs `sessions` in addition, for its session-scoped replay lookups.

## Verification

Red-first, measured against the same fixtures with the pre-fix modules
loaded
side by side:

```
=== owner-ambiguous (ref_count=0) ===
  OLD: blocking_count=1  ... attachment_unreferenced=1!
  NEW: blocking_count=0  ... attachment_unowned=1
=== stale ref_count (ref_count=2) ===
  OLD: blocking_count=1  ... attachment_unreferenced=1!
  NEW: blocking_count=1  ... attachment_unreferenced=1!
```

```
OLD builder ANALYZE set : warning  missing=['session_links']
NEW builder ANALYZE seam: ok       missing=[]
```

The `ref_count=2` row is the control: the split does not disable the
blocking
term, it only stops it claiming the explained case.

Four new tests, each naming its anti-vacuity condition:
`4 passed, 3 warnings in 13.81s`.

`.venv/bin/python -m devtools verify --quick` — exit 0, all 13 gates ok,
no
`out of sync`.

`ruff check` / `ruff format --check` clean across `polylogue/` and
`tests/`;
`mypy` clean on the changed production modules.

## Residuals

- The 13-file affected-set run (the previously-red
convergence/property/reindex
files) is still queued behind an unrelated full `verify` on the host's
single
pytest slot. Both non-green terms that produced the assertion are proven
resolved above, but those 16 tests have not yet been observed green in
one
  run; I will post the result on this PR when it lands.
- `test_convergence_builder_analyze_covers_every_verified_table` imports
the
builder's private `_analyze_registry_tables` deliberately: asserting
against
a restatement of the table list would not catch a builder reverting to a
  hand-copied one.
- Unrelated, found while researching: CLAUDE.md and `docs/internals.md`
still
  point at `polylogue/storage/sqlite/lifecycle.py` and the delta-class
lifecycle mechanism, deleted in #4666 (879a995). Wants its own sweep.

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

https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid

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 ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@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 0914f89):

  • P2 polylogue/maintenance/archive_verification.py:83: Fixed on master (checked at 0914f89): planner-stats now counts a table as missing only when it is populated, because a bare ANALYZE writes no sqlite_stat1 row for an empty table (polylogue/maintenance/archive_verification.py:2689-2697). An empty session_links table no longer causes a warning.
  • P2 polylogue/maintenance/source_conservation.py:275: Fixed on master (checked at 0914f89): _source_exists now resolves <container>:<member> coordinates through zip_member_coordinate and checks for the member inside the ZIP, so it no longer probes the full coordinate as a filesystem path (polylogue/maintenance/source_conservation.py:421).

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 bf68918):

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