Skip to content

fix: Derive four drifted mirrors from the facts that own them - #5042

Merged
Sinity merged 5 commits into
masterfrom
fix/mirror-audit
Sep 14, 2026
Merged

Sinity merged 5 commits into
masterfrom
fix/mirror-audit

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026

Copy link
Copy Markdown
Owner

A deliberate sweep for facts stated by hand in more than one place. Four had
already drifted; two of those produce wrong observable outcomes on the
from-scratch rebuild path this campaign is about to run.

1. FTS5 automerge silently skipped a trigger-maintained table

Owner: the index-tier DDL. polylogue/daemon/fts_automerge.py hand-listed two
surfaces (messages_fts, session_work_events_fts) behind a "must be kept in
sync" comment pointing at a file that no longer exists.

Drifted: blocks_command_trigram — an FTS5 table on blocks — was missing
from the list, so neither the startup automerge=0 pass nor the bounded periodic
merge ever reached it. It kept FTS5's default automerge and paid unbounded
inline segment merges on the live-ingest writer
— exactly the write
amplification #1864 removed for the other two, on the heaviest path during a
from-scratch rebuild.

Now read from sqlite_master; no new import edge.

2. config paths reported archive_complete for an archive missing audit.db

Owner: ARCHIVE_TIER_SPECS via archive_layout.ARCHIVE_TIER_ORDER.

Drifted: cli/commands/paths.py listed five of six tiers, omitting audit —
in two places (tier_paths and _TIER_ENUM_BY_NAME). With audit.db absent,
final_shape_ready was true, storage_layout said archive_complete,
archive_layout_ready stayed true, and missing_backup_required_tier:audit
could never fire
— for a durable, append-only tier.

That is the readiness signal an operator reads while standing an archive up from
scratch. A fourth copy in the CLI test pinned the drift; it now derives too.

3. The affected-run worker cap exceeded the corpus cap in its own cgroup

Owner: worker_memory.width_within(PYTEST_SLICE_MEMORY_HIGH_MIB).

Drifted: AFFECTED_MAX_WORKERS = 4 against a derived CORPUS_MAX_WORKERS = 3 — admitting the selective run wider than the full corpus, peak 10,127 MiB
against a 9,830 MiB headroom budget that exists precisely because a corpus run
was already OOM-killed in that cgroup. Now min(policy, CORPUS_MAX_WORKERS); a
third copy in the test reads the constant.

4. Three drifted doc facts

docs/insights-rigor-matrix.md declared rigor.py its source of truth and then
hand-wrote 11 of 13 contracts, omitting command_shapes/tool_episodes and
naming threads as work_threads — an insight type nothing answers to. Now a
generated surface under render all --check.

docs/provider-origin-identity.md enumerated "every current Origin token"
inside the paragraph forbidding second token lists, and omitted beads-issue;
docs/data-model.md carried the same 11-of-12 list. Both copies deleted rather
than corrected.

Anti-vacuity

  • FTS: test_configure_covers_every_declared_fts5_surface enumerates the
    built schema's FTS5 tables and asserts each is at automerge=0. Restoring the
    hand list goes red on blocks_command_trigram — proven directly, not assumed.
  • Tiers: fixture and assertions generated from ARCHIVE_TIER_ORDER; the
    blocker test now asserts missing_backup_required_tier:audit is emitted.
    Restoring the five-name literal goes red.
  • Width: test_affected_width_never_exceeds_the_memory_owner asserts the cap
    is at or below CORPUS_MAX_WORKERS; a literal above it goes red, and lowering
    the slice moves the cap with no edit.
  • Rigor matrix: editing any contract now makes render all --check report it
    out of sync — a gate the hand-written matrix was never subject to.

Checked and agreeing, no change

pytest slice 12G ↔ Sinnix runtime-defaults.nix (the sibling-repo drift is not
present here); worker/controller peak constants; polylogued 14G/18G ↔
memoryBudgetGiB; cloud worker width (4 copies); .agentctl pool names ↔ Sinnix
POLICY_POOLS; version 0.3.0; requires-python across 10 sites; the devtools
catalog and docs/devtools.md (genuinely generated); gate names; storage tier
lists in archive_identity.py and daemon/status.py; Origin ↔ ORIGIN_SPECS
(import-time parity guard); INSIGHT_REGISTRY ↔ _RIGOR_MATRIX.

One false positive, deliberately not acted on: the agent manual's "ten-tool"
claim against a 12-tool registry is correct — registry.py carries a
target_visible flag, the two event tools declare no transaction projection, and
test_tool_declarations.py:68 already pins the partition. Coupling it would have
created a false dependency.

Filed rather than derived

polylogue-xbg9e (P2) corpus width derives 3 while Sinnix provisioned 4 —
headroom counted twice, a cross-repo decision. polylogue-29naz (P2) MCP
_INSIGHT_PROJECTIONS hand list, including an already-visible
tool-episodes/tool_episodes spelling split. polylogue-b1vr1 (P3) ungated
second tier lists, plus two items flagged unsure rather than coupled:
migration_runner.py:1125 vs :1210 differing required_tiers, and
manifest_models.py's five-tier Literals. polylogue-mnwxy (P3) mypy 3.11 /
ruff py310 vs requires-python >=3.14.

Verification

devtools test test_paths.py test_verification_admission.py test_live_write_amplification.py
  PASSED exit=0   receipt 20260914T061123Z-focused-test-1405648-6665bbdd
devtools verify --quick     15/15
devtools render all --check clean

Residual: config paths output still has no audit_database_path key or
"Audit DB" line — a surface-contract change left out of the readiness fix
deliberately, noted in polylogue-b1vr1.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Sinity and others added 5 commits September 14, 2026 07:54
The daemon's FTS5 tuning read a hand-maintained `_FTS_SURFACES` tuple whose
comment pointed at a file that no longer exists (`fts_lifecycle.py` moved to
`storage/fts/`). The list had already drifted: `blocks_command_trigram`, an
FTS5 surface declared by the index tier and maintained by triggers on
`blocks`, was absent from it, so neither the startup `automerge=0` pass nor
the bounded periodic merge ever reached it. It kept FTS5's default automerge
and paid unbounded inline segment merges on the live-ingest writer -- exactly
the write amplification #1864 removed for the other two surfaces, and the
heaviest path during a from-scratch rebuild.

The surface set is now read from `sqlite_master` on the open connection, so
the tier DDL that declares an FTS5 table is its sole owner. The presence
checks fall out of the enumeration, and no new import edge is added.

Anti-vacuity: `test_configure_covers_every_declared_fts5_surface` enumerates
the FTS5 tables in the built schema and asserts every one of them is tuned to
automerge=0. Declaring a new FTS5 surface moves the tuned set with no edit
here; restoring the hand list makes it red on `blocks_command_trigram`.

Verification:
  devtools test tests/integration/test_live_write_amplification.py
  -> PASSED exit=0 diagnosis=pytest_passed

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
…budget

`AFFECTED_MAX_WORKERS` was a hand-set `4`: a second statement of how many
pytest workers fit in `agentctl-pytest.slice`, restated beside the derived
one instead of read from it. It had already drifted past the owner. An
affected run occupies the same slice as the corpus run, and
`worker_memory.width_within(PYTEST_SLICE_MEMORY_HIGH_MIB)` currently answers
3, so on an idle slice the *selective* run was admitted at 4 workers where
the full corpus is held to 3 -- a peak of 4*2263 + 1075 = 10127 MiB against
the 9830 MiB headroom budget that exists because a corpus run was already
OOM-killed in this slice.

Width is now `min(AFFECTED_POLICY_MAX_WORKERS, CORPUS_MAX_WORKERS)`: this
module stays free to be stricter than memory allows, but can no longer claim
more than the memory owner says fits, and a change to the slice budget moves
it with no edit here. A third copy of the literal, `"max_workers": 4` in the
admission payload test, now reads the constant.

Anti-vacuity: `test_affected_width_never_exceeds_the_memory_owner` asserts
the cap is at or below `CORPUS_MAX_WORKERS` and equals the minimum; restoring
a hand-set literal above the corpus width makes it red.

Verification:
  devtools test tests/unit/devtools/test_verification_admission.py
  -> PASSED exit=0 diagnosis=pytest_passed

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
`config paths` built its tier set by hand and listed five tiers: `audit` was
missing. The consequences were wrong observable outcomes, not cosmetics. With
`audit.db` absent, `missing_tiers` could not contain `audit`, so
`final_shape_ready` was true, `storage_layout` reported `archive_complete`,
and -- because `missing_backup_required` filters `BACKUP_REQUIRED_TIERS`
through `missing_tiers` -- the `missing_backup_required_tier:audit` blocker
could never fire and `archive_layout_ready` stayed true for an archive
missing a durable, append-only tier. `archive_schema_ready` likewise skipped
the audit tier's version check. This is the readiness signal an operator
reads while standing up an archive from scratch.

`archive_layout.py` exists because this exact truth had already been
hand-written twice and drifted; its docstring says so. Membership is now read
from `ARCHIVE_TIER_ORDER` (which derives from `ARCHIVE_TIER_SPECS`), the
name->enum map is built from `ArchiveTier` itself, and the schema-ready check
folds over the resolved tiers instead of a five-name literal. A fourth copy,
`_ARCHIVE_TIERS` in the CLI test, now derives from the same owner.

Anti-vacuity: the test fixture and its assertions are generated from
`ARCHIVE_TIER_ORDER`, and `test_paths_json_reports_archive_layout_blockers`
now asserts `missing_backup_required_tier:audit` is emitted and that `audit`
appears in `missing_tiers`. Adding a tier to `ARCHIVE_TIER_SPECS` moves both
the command and the test with no edit at either site; restoring the five-name
literal makes them red.

Verification:
  devtools test tests/unit/cli/test_paths.py
  -> PASSED exit=0 diagnosis=pytest_passed

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Follow-up to the tier derivation: `ARCHIVE_TIER_ORDER` is `tuple[str, ...]`
while `ArchiveLocation.active_tier` takes the `ArchiveTierName` literal, so
the derived enumeration needs an explicit cast to keep `gate mypy` green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Three documentation facts were restated by hand beside their owners, and all
three had already drifted.

`docs/insights-rigor-matrix.md` named `rigor.py:list_rigor_contracts()` its
source of truth in the second paragraph and then hand-wrote the rows anyway.
It carried 11 of the registry's 13 contracts -- `command_shapes` and
`tool_episodes` were absent entirely -- and listed the `threads` contract
under `work_threads`, an insight type nothing in the codebase answers to, so
a reader following the doc would ask for a name the registry rejects. Every
bullet in a row turned out to be a projection of one contract field, so the
matrix is now a generated block rendered by `devtools render
insights-rigor-matrix` and covered by `devtools render all --check`.

`docs/provider-origin-identity.md` enumerated "every current `Origin` token"
in the same paragraph that tells the reader not to hand-maintain a second
per-origin token list, and its list was missing `beads-issue`.
`docs/data-model.md` carried the same 11-of-12 list. Both copies are deleted
rather than corrected: the `Origin` enum owns the set, and
`docs/agent-manual.md` already renders it from `origin_meanings()` under an
import-time parity check.

`docs/maintenance.md` also referred to `work_threads`; corrected to `threads`.

Anti-vacuity: adding a contract to the rigor registry, or editing one's
fields, now makes `devtools render all --check` report
`insights-rigor-matrix` out of sync until it is regenerated -- the gate that
the hand-written matrix was never subject to. The two origin lists can no
longer drift because they no longer exist.

Verification:
  devtools render all --check   -> no "out of sync"; insights-rigor-matrix checked
  devtools verify --quick       -> 15/15 gates ok

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 6 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: b04b6642-7d8e-41a2-ad6e-53218ebc8198

📥 Commits

Reviewing files that changed from the base of the PR and between f84dd3b and 41d7d9b.

📒 Files selected for processing (12)
  • devtools/generated_surfaces.py
  • devtools/render_insights_rigor.py
  • devtools/verification_admission.py
  • docs/data-model.md
  • docs/insights-rigor-matrix.md
  • docs/maintenance.md
  • docs/provider-origin-identity.md
  • polylogue/cli/commands/paths.py
  • polylogue/daemon/fts_automerge.py
  • tests/integration/test_live_write_amplification.py
  • tests/unit/cli/test_paths.py
  • tests/unit/devtools/test_verification_admission.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 465ffa0 into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the fix/mirror-audit branch September 14, 2026 06:31
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