Repository navigation
fix(storage): permit same-raw revision CAS supersede - #3194
Conversation
Problem: record_revision_application_sync's equal-frontier CAS branch rejected any incoming receipt whose derived semantics (content hash, session_id) differed from the existing raw_revision_heads row, even when the receipt was derived from the exact same accepted_raw_id. A parser or identity-law fix reparsing already-committed raw evidence into a new content hash therefore hit "raw revision CAS rejected a conflicting accepted head" instead of superseding the head. Same symptom one gate earlier: the immutable raw_revision_applications ledger's natural key (decision_id) deliberately excludes accepted_content_hash, so a pure content-hash change for an otherwise identical decision hit "conflicting raw revision application receipt" before ever reaching the heads CAS. Both blocked re-derivation from identical evidence, which contradicts the derived-tier doctrine (derived content re-derives from source) and made every parser improvement poison already-committed archives. Solution: in polylogue/storage/sqlite/archive_tiers/revision_application.py, permit both same-raw paths to supersede instead of rejecting: - the ledger check now updates the existing row's accepted_content_hash in place when every other decision-defining field already matched (i.e. only content hash differs for the same decision_id); - the heads CAS equal-frontier branch now allows the update when receipt.accepted_raw_id equals the existing head's accepted_raw_id, alongside the existing fold-authorization exemption. Cross-raw conflicts (differing accepted_raw_id, same frontier, no fold authorization) are unaffected and still reject. - every raise in the function now carries logical_source_key, existing vs incoming raw ids/session ids/frontiers, and content-hash prefixes, so a rebuild failure is diagnosable without a debugger. Audited for a second CAS implementation (async twin): none exists -- record_revision_application_sync is the sole writer of raw_revision_heads across all call sites (archive.py, repair.py). Tests: extended tests/unit/storage/test_revision_application.py with same-raw content-hash supersede, same-raw session_id supersede (identity fix), cross-raw conflict without fold authorization (asserts both raw ids appear in the message), idempotent same-everything re-application, and split the frontier-mismatch rejections into their own case. Verification: devtools test tests/unit/storage/test_revision_application.py (12 passed); devtools test tests/unit/sources/test_live_batch_support.py (5 pre-existing failures reproduced identically on master 08cd41b via a throwaway baseline worktree, unrelated to this change; 63 passed). Ref ab5bad1f resume #4
Problem: devtools verify --quick reported mypy --strict failing on tests/unit/storage/test_revision_application.py:174 -- `receipt.accepted_raw_id` is typed str | None, so `in message` was an unsupported operand check. Solution: assert not-None before the membership check, matching the existing dataclass typing instead of loosening it. Verification: devtools verify --quick (mypy ok); devtools test tests/unit/storage/test_revision_application.py (12 passed).
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4aac9cc70
ℹ️ 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".
| conn.execute( | ||
| "UPDATE raw_revision_applications SET accepted_content_hash = ? WHERE decision_id = ?", | ||
| (receipt.accepted_content_hash, receipt.decision_id), | ||
| ) |
There was a problem hiding this comment.
Refresh receipt timestamps when re-deriving the accepted hash
When the same raw evidence reparses to a new content hash, this updates the existing application row's hash but leaves its old decided_at_ms; the subsequent head upsert records the new decided_at_ms. The raw-retention path in raw_retention._active_index_raw_authority requires head.decided_at_ms = application.decided_at_ms before treating a superseded receipt as deletion authority, so after precisely this re-derivation flow none of the updated superseded receipts match the head and their raw blobs remain ineligible for collection indefinitely. Refresh the receipt cohort's timestamp along with the hash, or otherwise preserve the timestamp equality used by retention.
Useful? React with 👍 / 👎.
Summary
record_revision_application_syncnow permits a raw-revision replay tosupersede its own previous accepted head when the incoming receipt is
derived from the same
accepted_raw_id— a re-derivation from identicalraw evidence, not a genuine conflict. Every raise in the function now
carries diagnostic context (logical source key, existing vs incoming raw
ids/session ids/frontiers, content-hash prefixes).
This unblocks resume #4 of operation ab5bad1f: resume #3 failed fast
after the #3191 parser fix because ~466 already-committed sessions'
raw evidence now reparses to a different content hash (and in some cases
a different
session_idafter identity-law fixes), and the CAS wastreating that as an unauthorized conflict.
Problem
polylogue/storage/sqlite/archive_tiers/revision_application.py'sequal-frontier CAS branch rejected any incoming receipt whose derived
semantics (
accepted_content_hash,session_id) differed from theexisting
raw_revision_headsrow at the same frontier, unless aFullSnapshotFoldAuthorizationwas present — even when the receipt'saccepted_raw_idwas identical to the existing head's. The raw blobis content-addressed and unchanged after a parser fix; only the
derivation (parsed content, and possibly the session_id it resolves
to) changed. Blocking same-raw re-derivation contradicts the repo's
derived-tier doctrine ("derived content re-derives from source",
docs/architecture.md) and means every parser or identity-lawimprovement poisons already-committed archives on the next rebuild.
While reproducing this at fixture scale, a second, earlier gate with
the identical failure mode turned up:
raw_revision_applications'immutable-ledger check uses
decision_idas its natural key, anddecision_iddeliberately excludesaccepted_content_hashfrom itshash payload. So a receipt that is identical to an existing ledger row
in every decision-defining field except
accepted_content_hash(thepure "same raw, reparsed to a different hash" case) hit "conflicting
raw revision application receipt" before ever reaching the heads
CAS — same root cause, one call earlier.
Solution
Both in
polylogue/storage/sqlite/archive_tiers/revision_application.py:raw_revision_applications): when an existing rowfound by
decision_iddiffers from the incoming receipt only inaccepted_content_hash(the only fielddecision_id's hash doesn'tcover),
UPDATEthe row'saccepted_content_hashin place instead ofraising. Any other field actually differing is unreachable without a
decision_idhash collision and still raises defensively.raw_revision_heads, equal-frontier branch): added asame_raw_supersede = receipt.accepted_raw_id == existing_head[1]exemption alongside the existing fold-authorization exemption. Falls
through to the same
UPSERTthat fold-authorized folds already use.Cross-raw conflicts (different
accepted_raw_id, same frontier,differing semantics, no fold authorization) are unaffected and still
reject — that guard protects real divergence. Older-frontier and
incomparable-frontier-kind rejections are unaffected.
logical_source_key, existing vs incomingaccepted_raw_id/session_id/frontier, and content-hash prefixes. A 10-hour rebuilddied on a context-free
RuntimeErrortwice this weekend.Async twin audit: grepped the repo for a second CAS implementation
(
record_revision_applicationwithout_sync, anasync_sqlitetree,etc.) — none exists.
record_revision_application_syncis the solewriter of
raw_revision_headsacross every call site(
storage/sqlite/archive_tiers/archive.py,storage/repair.py).Verification
devtools test tests/unit/storage/test_revision_application.py— 12passed. Extended (not duplicated) with: same-raw content-hash
supersede, same-raw session_id supersede (identity-law fix case),
cross-raw conflict without fold authorization (asserts the message
names both
accepted_raw_ids), idempotent same-everythingre-application, and a frontier-mismatch case split out of the old
parametrized test whose other two cases this PR intentionally
changes the expected outcome of.
devtools test tests/unit/sources/test_live_batch_support.py— 63passed, 5 failed. Reproduced the identical 5 failures on unmodified
master (
08cd41b34) via a throwawaygit worktree, confirming theyare pre-existing and unrelated to this change (removed the worktree
after comparison).
devtools test tests/unit/storage/test_repair.py tests/unit/storage/test_raw_revision_authority.py tests/unit/storage/test_duplicate_raw_identity_repair.py— 95passed (broader affected-area check for the touched CAS surface).
devtools verify --quick— all steps green (ruff format/check, mypy--strict, render all, topology/layering/closure-matrix/manifests/
ci-workflows/doc-commands/docs-coverage/test-infra-currency/
test-clock-hygiene/pytest-timeout-overrides/degrade-loudly).
Not run:
devtools verify --all(full non-integration suite) — thetargeted + affected-area runs above cover the touched surface; the
per-PR CI
testjob runs post-merge on master per repo convention.Ref ab5bad1f resume #4