Repository navigation
feat(storage): refuse mismatched tier schemas at open - #4485
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 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. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfbeca39e0
ℹ️ 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".
## Summary A connection to a known archive tier whose `user_version` does not match this runtime's expected version is refused at open with a typed `SchemaSkewError`, before any caller can issue SQL against it. ## Problem `open_connection`, `open_daemon_connection`, and `open_readonly_connection` applied pragmas and handed back a connection regardless of the tier's schema version. A caller then read or wrote a tier this runtime does not understand, and the failure surfaced later as a confusing SQL error — or not at all, as a silently wrong read against an older shape. ## Solution - Add `SchemaSkewError` to `polylogue/core/errors.py` (code `schema_skew`, HTTP 409) carrying tier, expected, found, and a remedy. - Resolve the tier from the conventional archive filename when the caller does not name one, so existing call sites gain the check without changes; paths that are not a recognized tier are left alone. - Assert the version immediately after `sqlite3.connect` and before the pragma statements in all three open functions, so refusal precedes any use of the connection. ## Verification - `uv run devtools test tests/unit/storage/test_connection_profile.py` - `uv run devtools verify --quick` Anti-vacuity: the new tests stamp a wrong `user_version` on each tier and assert each of the three open functions raises `SchemaSkew`; removing the `_assert_schema_supported` call from any one of them turns that case red. ## Residual risk The check is fail-closed on version alone, so an archive at an older version is refused rather than opened read-only for inspection. The remedy string names rebuild-or-migrate; it does not perform either. Reviewed-by: Claude (Opus) cross-family review
## Summary Bootstrap routes create an archive tier and then validate it, rather than validating a tier that does not exist yet; `initialize_archive_tier` stamps the derived schema identity its readers assert; status and diagnostic readers report a skewed tier instead of refusing to open it. ## Problem `#4485` added an open-time tier version check to `open_connection` / `open_daemon_connection` without exempting the routes that create the tier on the connection they just opened. Every such route failed: ``` polylogue.core.errors.SchemaSkewError: ops schema skew: expected 1, found 0. rebuild or migrate the tier with the current runtime before retrying ``` `#4544` then declared a derived schema identity for the index and ops tiers and stamped it only on the path-based `initialize_archive_database` route. The connection-based `initialize_archive_tier` route — which nearly every test and several daemon writers use — left the tier unstamped, so its readers refused it: ``` ops derived schema identity mismatch: expected 4589cb1d…, found None ``` Status projections inherited both refusals and raised out of the daemon status surface, which is exactly the surface an operator needs when a tier is skewed. ## Solution - `open_initialized_tier_connection` owns the create-then-validate order: open with validation deferred, materialize, validate before handing the connection back. A genuinely skewed tier is still refused. - `initialize_archive_tier` stamps the derived schema identity, so no caller can create a derived tier its readers will reject. - Status and diagnostic readers (FTS, cursor-lag, catch-up, metrics, the event ledger, the space report, the workload probe, embedding status) read with `validate_schema=False`, following the precedent `archive_readiness` already set. - `ArchiveStore`'s read-only open defers to `assert_readable_archive_layout`, whose refusal names the generation and the lifecycle action rather than a bare version pair. ## Verification `devtools test <file> -p no:randomly -n 2`: | file | before | after | | --- | --- | --- | | `tests/unit/daemon/test_judgment_automation.py` | 24 failed | 43 passed | | `tests/unit/daemon/test_cursor_lag_{baseline,status,integration}.py` | 10 failed | 38 passed | | `tests/unit/daemon/test_daemon_status.py` | 9 failed | 2 failed (separate classes) | | `tests/unit/storage/test_archive_tiers_archive.py` | 5 failed | 3 failed (attachment-direction class) | | `tests/unit/storage/test_archive_tier_init.py` | — | 14 passed | `devtools verify --quick` green. ## Residual risk The status readers now read a skewed tier's tables; each already guards every read with a table-existence probe and degrades on `sqlite3.Error`, but a tier skewed in a way that keeps table names and changes column meaning would report wrong numbers rather than refusing. The readiness probe remains the surface that reports the skew itself. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz Co-authored-by: Claude Fable 5.1 <[email protected]>
…ures (#4563) ## Summary Three independent red classes, each landed as its own commit: 1. **`fix(devtools)`** — the index fast-forward tool reads the index it is about to carry forward without asserting that index is already at the runtime's version. 2. **`test`** — four hand-built fixtures pinned index shapes the runtime has moved past. 3. **`fix(surfaces)`** — the message-row envelope drops `identity_source`, which its own mask declares public. ## Problem and solution, per class ### Fast-forward reads `#4485`'s open-time tier check refused both pre-forward reads in a tool whose purpose is an index at a non-current version: ``` polylogue.core.errors.SchemaSkewError: index schema skew: expected 37, found 36 ``` `_inspect_clean_database` returns that version as its result and `_sample_manifest` samples the index being carried, so both read with `validate_schema=False`. The candidate-index read *after* the forward keeps the check: that index is at the target version and must be. ### Fixtures pinned to superseded shapes - `test_lineage_validation` stamped and asserted `user_version = 73`; both now derive from `INDEX_SCHEMA_VERSION`. - `test_reindex_canary_cli` stamped `43` on an index it had just seeded at the current version; the scenario is a title backfill and the version literal was incidental. - `test_envelope`'s hand-built `blocks` table predates `tool_outcome` (`#4539`), so the coordination evidence query failed with `no such column: r.tool_outcome`. - `test_web_reader` asserted an uppercase doctype; the renderer emits the lowercase HTML5 form. ### `identity_source` on the message row `_MESSAGE_MASK` declares the field public and the render envelope publishes it, but the row envelope's `field_order` omitted it. `message_row_envelope_from_domain` builds the row envelope by dumping the render envelope, so every paginated message read failed closed with `extra_forbidden`. The row envelope now lists the field where the mask puts it; the generated CLI-output schemas are regenerated to match. `_FakeApi` in the CLI message tests gains the `config` the read path builds its authority envelope from. ## Verification `devtools test <file> -p no:randomly -n 2`: | file | before | after | | --- | --- | --- | | `tests/unit/cli/test_messages.py` | 7 failed | **13 passed** | | `tests/unit/coordination/test_envelope.py` | 3 failed | 1 failed | | `tests/unit/devtools/test_lineage_validation.py` | 21 failed | 8 failed | | `tests/unit/devtools/test_index_fast_forward.py` | 25 `SchemaSkewError` | 0 `SchemaSkewError` | `devtools verify --quick` green. ## Residual risk `test_index_fast_forward.py` is still red on `ArchiveLocationError` from `#4411`'s symlink-farm discrimination, which refuses the two-root index-generation layout both that suite and `test_daemon_status.py` document as legitimate. `test_lineage_validation.py`'s remaining 8 come from the read envelope's behaviour on its hand-built partial index. Both are separate causes, not addressed here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
…ping, wire-receipt cost (#4591) ## Summary Five red classes from the 2026-09-03 corpus run, each its own commit. Two are product defects; three are fixtures pinned to shapes the runtime has moved past. ## Problem and solution, per class ### The relink route never derived attachment provenance (6 tests) `attachment_refs.direction` is `NOT NULL`, and only the main write route derived it from the owning turn. Blob-reference closure relinked attachments straight from the parsed record: ``` sqlite3.IntegrityError: NOT NULL constraint failed: attachment_refs.direction ``` The relink path now goes through the same shared derivation, reading the owning turn from the index when the append payload's own message map does not carry it — an append whose owning message is already materialized. Two of the six failed inside the main route instead, on a model-output attachment whose turn carried no provider id; `#4587` fixed that while this branch was open, and this commit builds on it. ### One session total on two model rows (1 test) `sessions.reported_cost_usd` is one exact dollar total for a session, written onto a single `session_model_usage` row. A merge-append that switched models left the superseded row holding the previous total, so every sum over the session counted it twice. The direction-refusal test alongside it named a user turn, whose direction the derivation supplies; only a role outside the user/model pair leaves the column underivable, so that is what it names now. ### Hand-built index fixtures without a tier version (12 tests) `#4485`'s open-time tier check refuses a database named for an archive tier whose `user_version` is 0: ``` SchemaSkewError: index schema skew: expected 85, found 0 ``` - The deployment-smoke browser-capture probe fixtures declare the version the read profile expects, read from the tier table. - The embed-backfill fixtures build the tier through the production bootstrap rather than touching a bare SQLite file. - The WAL/journal pragma probes name their scratch databases for what they are. They test the pragmas the connection factories apply; the tier check fired only because the files were called `index.db` and `ops.db`. ### Hand-built `blocks` tables without `tool_outcome` (6 tests) The insight-status and readiness queries read `blocks.tool_outcome`, the canonical structural outcome since `#4539`. Two fixtures predate it. ### A killed waiter left its pytest slot task queued (host defect) The waiter blocks on a task it queued through pueue, and the task outlives it. The slot's parallelism is one, so a task left with no waiter starves every other checkout on the host until someone reads the queue and kills it by hand -- which is what happened during this branch's own runs. The waiter now reaps the task it added when it is signalled or unwound: kill, then remove, then drop the launch file, which carries a resolved environment and must not survive either. ### Full-catalog wire receipts on single-provider assertions `build_wire_support_receipt` runs the synthetic corpus and the production parser for every catalogued package element. Profiled: 27 s per full-catalog call in a quiet process, and the file's heaviest tests measured 106-110 s of call time under `-n 2` -- inside a 120 s timeout with no margin, which is what the corpus run recorded as nine timeouts. `#4412` added two providers and the margin went. Tests that assert about one provider's entry, or that a receipt *changed*, now name the providers they read; three catalog-wide tests still build the whole catalog. Memoizing the schema-annotation parsing the profile flagged was tried and reverted: 26.5 s against 27.4 s, which does not buy an identity-keyed cache in production code. ### Reader assertions pointed at the wrong route The interpolated shell answers on `/w/` and the paste routes; the root and `/s/` serve the typed WebUI. Eight reads across the visual suites and `test_web_shell_reader.py` now fetch `/w/stack`. This also restores `test_reader_search_shell_dom_evidence`, which `#4579` deleted -- the shell it tests is still served, just not at the root, so repointing it was the right move and deleting it was not. ## Verification `devtools test <file> -n 2`: | file | before | after | | --- | --- | --- | | `tests/unit/storage/test_archive_tiers_write.py` | 2 failed | **107 passed** | | `tests/unit/maintenance/test_blob_reference_closure.py` | 6 failed | **13 passed** | | `tests/unit/cli/test_embed_activation.py` | 7 failed | **35 passed** | | `tests/unit/devtools/test_deployment_smoke.py` | 7 failed | **24 passed** | | `tests/unit/storage/test_wal_journal_size_limit.py` | 5 failed | **8 passed** | | `tests/unit/storage/test_session_insight_status_descriptors.py` | 5 failed | **13 passed** | | `tests/unit/core/test_insight_readiness.py` | 1 failed | **passed** | | `tests/unit/devtools/test_pytest_slot.py` | 7 passed | **8 passed** | | `tests/unit/storage/test_session_profile_model_usage_consistency.py` + `tests/unit/insights` | — | **730 passed** (cost regression check) | `devtools verify --quick` green at this head. The attachment and cost measurements above predate the rebase onto `#4587`, which rewrote `_attachment_provenance` under this commit; the storage suites are re-running against the merged shape. The slot-reaping test drives a real SIGTERM into a child waiter with a fake `pueue` on PATH. Anti-vacuity: dropping the `_reaping` context leaves the recorded calls at `add`/`wait`, the starvation shape itself. The visual and wire-receipt commits are still queued behind the host's pytest slot at the time of writing; they are committed, not yet measured. ## Residual risk The provider-scoped wire receipts trade catalog breadth for time in tests that assert about one provider. If a future provider's route breaks only in a receipt those tests build, three catalog-wide tests still catch it, one test later. `tests/unit/infra/test_pathology_zoo.py` was red in the corpus run and is green at this head with no change here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
#4485's open-time tier check reached the readers whose subject is a tier's version. Metrics, the workload probe, the embedding status payload and the schema-inference gate all exist to describe what a tier holds -- the probe payload's own fields are user_version and version_status -- and they raised instead of reporting. Each now opens without the version assertion and reports the skew as data, which is what their callers already model: metrics emits schema_mismatch:index as a blocker series. The context preamble's scheduler receipt is best effort by its own contract and already swallows sqlite errors; a tier this runtime cannot use joins them, so a disposable receipt never fails the preamble it describes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz
…ired tokens (#4598) ## Summary Eight more red classes from the 2026-09-03 corpus run, stacked on #4591. Four are product defects; four are fixtures pinned to shapes the runtime has moved past. ## Problem and solution, per class ### Status readers raised instead of reporting tier skew `#4485`'s open-time tier check reached the readers whose *subject* is a tier's version. The workload probe's payload carries `user_version` and `version_status` fields; metrics is supposed to emit `schema_mismatch:index` as a blocker series; the convergence-debt summary has an `error` field for saying why the view is unavailable. All of them raised instead: ``` SchemaSkewError: index schema skew: expected 85, found 1 ``` Metrics, the workload probe (three sites), the embedding status payload, the schema-inference gate's tier identity read and the debt summary now open without the version assertion and report what they find. The context preamble's scheduler receipt is best-effort by its own contract and already swallowed sqlite errors; a tier this runtime cannot use joins them. ### The relink route never derived attachment provenance `attachment_refs.direction` is `NOT NULL` and only the main write route derived it, so blob-reference closure failed the constraint on any record parsed before attachments carried direction. The relink path uses the same shared derivation, reading the owning turn from the index when the append payload's own message map does not carry it. ### One session cost total on two model rows `sessions.reported_cost_usd` is one exact dollar total, written onto a single `session_model_usage` row. A merge-append that switched models left the superseded row holding the previous total, double-counting it in every sum over the session. ### A read that skipped the controlled reader The delegation work-evidence materializer opened a read-only `ArchiveStore` directly — the one thing the read-surface boundary forbids, because such a read carries no admission, no execution budget and no cancellation. ### Fixtures that open a tier before building it A connection profile checks a tier's declared version at open time, so a test cannot open a tier-named path and initialize it afterwards. The assertion tests build the tier first through the production bootstrap; the mmap-budget test builds every attached tier the same way, since the tier filenames are its subject; the descriptor-binding test names its database for what it is. The embedding-drain stubs declare the version they claim, without which the daemon's probe passes them over and the drain silently reports no work. ### The resilience suite launched another checkout's daemon `which("polylogued")` resolves from PATH, which in a worktree is the main checkout. The tests launched a different tree's daemon against this tree's archive, then waited out their budget with nothing ingested and reported a timeout. The running interpreter's own script directory comes first now. The installed-wheel smoke had the same shape: `uv venv` picked whatever interpreter uv found, and the package refuses to start off free-threaded CPython. ### Rendered ages re-baselined instead of redacted `"relative_time": "70w ago"` became `"71w ago"` on its own, because the value is computed against the host clock over fixture timestamps that never move. This file's own contract routes such a field to `_redact`, "not to update the baseline". ### Surfaces that read a retired token as removed `#4363` retired the Beads issue route, but the `Origin` token stays: deleting it would narrow the durable `source.db` CHECKs that still admit stored rows. Three surfaces each encoded a different guess. Origin has twelve tokens, ten of them public badges — the generated-contract test derives that split from `PUBLIC_ORIGIN_TOKENS`, the teaching table follows the enum, and the namespace policy stays exhaustive over *executable* origins, which the retired one is not. Separately, `exclusive_keys` and `scratch` are retired descriptor keys, as `test_dev_loop_service` already declares. ## Verification `devtools test <file> -n 2`, worktree venv resynced to the current lockfile: | file | before | after | | --- | --- | --- | | `tests/unit/storage/test_durable_change_train.py` | 3 failed | **98 passed** | | `tests/unit/daemon/test_metrics_endpoint.py` | 2 failed | pass | | `tests/unit/maintenance/test_schema_inference_gate.py` | 1 failed | pass | | `tests/unit/storage/test_connection_profile.py` | 1 failed | pass | | `tests/unit/storage/test_archive_tiers_assertions.py` | 3 failed | pass | | `tests/unit/daemon/test_embedding_readiness.py` | 1 failed | pass | | `tests/unit/context/test_preamble.py::…non_git…` | 1 failed | pass | `devtools verify --quick` green at this head. ## Residual risk `validate_schema=False` is now used at seven read sites. Each is a status or identity projection whose caller models skew as data; none of them writes. A first attempt at this branch also relaxed the identity guard so an `ops.db` predating the ledger would converge. That fixed three tests and broke thirty in `test_durable_change_train.py` — bootstrap proceeded where it used to refuse. The relaxation is dropped and those three ops-convergence tests remain red; the reader change that types the absent ledger as `None` is kept and was measured separately as harmless (98 passed with it alone). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
|
Closing out open Codex review threads on this PR (evidence checked against master at 0914f89):
Resolving every thread listed; confirmed defects are fixed under the named bead. |
|
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. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
A connection to a known archive tier whose
user_versiondoes not match this runtime's expected version is refused at open with a typedSchemaSkewError, before any caller can issue SQL against it.Problem
open_connection,open_daemon_connection, andopen_readonly_connectionapplied pragmas and handed back a connection regardless of the tier's schema version. A caller then read or wrote a tier this runtime does not understand, and the failure surfaced later as a confusing SQL error — or not at all, as a silently wrong read against an older shape.Solution
SchemaSkewErrortopolylogue/core/errors.py(codeschema_skew, HTTP 409) carrying tier, expected, found, and a remedy.sqlite3.connectand before the pragma statements in all three open functions, so refusal precedes any use of the connection.Verification
uv run devtools test tests/unit/storage/test_connection_profile.pyuv run devtools verify --quickAnti-vacuity: the new tests stamp a wrong
user_versionon each tier and assert each of the three open functions raisesSchemaSkew; removing the_assert_schema_supportedcall from any one of them turns that case red.Residual risk
The check is fail-closed on version alone, so an archive at an older version is refused rather than opened read-only for inspection. The remedy string names rebuild-or-migrate; it does not perform either.
Reviewed-by: Claude (Opus) cross-family review