Skip to content

fix(storage): scope duplicate-raw-identity proof to its own logical key - #3326

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/raw-authority-fold-duplicate-alias-postcondition
Jul 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/raw-authority-fold-duplicate-alias-postcondition

Conversation

@Sinity

@Sinity Sinity commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a live, recurring polylogued failure: fold_duplicate_alias raw-authority repair kept raising RuntimeError: duplicate strategy did not reach its typed terminal postcondition for the same plan hash on every retry, never converging (observed 7 identical failures over 90 minutes for one plan, 1 for another).

Problem

_inspect_duplicate_raw_identity (polylogue/storage/repair.py) proves a (stale_raw_id, canonical_raw_id) pair is an exact pre-/post-#2729 duplicate-fold shape, and looked up the stale raw's accepted-head row with SELECT ... FROM raw_revision_heads WHERE accepted_raw_id = ? — scoped only by raw id, not by which session/logical source key the caller actually cares about.

Correlating the two failing plan hashes to live data (read-only, via mode=ro connections against /realm/db/polylogue) showed why that's ambiguous: the same physical raw acquisition (one raw_id under the old native-id-inclusive scheme) is legitimately the accepted head of four different sessions simultaneously — forked/subagent/resumed Claude Code sessions replay the identical parent JSONL evidence, so each session's own materialization can independently accept that raw as its head. fetchone() on the unscoped query picked an arbitrary one of those four sessions. The frontier item classified for session 896c6b64-... ended up carrying a strategy witness describing session 560a3328-...'s head instead of its own — directly confirmed: the item's own index_preconditions.logical_source_key was 896c6b64-... while its strategy_witness.logical_source_key was 560a3328-....

At apply time this meant the fold repointed the wrong session's head inside the transaction; the re-inspect (also unscoped) then found a different remaining row still pointing at the stale raw, saw the canonical now claimed, and returned "ineligible" instead of "already_repaired" — tripping the typed postcondition check and rolling back the whole transaction. Since nothing ever committed, the same plan hash and error recurred identically on every retry, exactly matching the 90-minute log pattern.

This is an application-logic bug (a missing scope key), not a design gap requiring a new terminal status — "already_repaired" only needed disambiguation.

Solution

  • _inspect_duplicate_raw_identity (polylogue/storage/repair.py) now takes a required logical_source_key parameter and scopes the stale raw's accepted-head lookup and the "already_repaired" session/superseded-receipt checks to that key. The canonical raw's head/session checks stay unscoped — "not claimed by anyone yet" is genuinely global, not per-session.
  • The three call sites in polylogue/storage/raw_reconciler.py (_classify_frontier, and both _apply_strategy inspect calls for FOLD_DUPLICATE_ALIAS) now pass the frontier row's/item's own logical_source_key.
  • Added _seed_duplicate_raw_fanout and two regression tests in tests/unit/storage/test_duplicate_raw_identity_repair.py reproducing the exact fan-out shape (one stale raw shared as accepted head by two sessions, one canonical twin available): one proves classification no longer cross-contaminates the strategy witness between siblings, the other proves applying either sibling's plan folds only that sibling and leaves the other's head/session pointer untouched. Both new tests fail against the pre-fix code with the exact same "did not reach its typed terminal postcondition" RuntimeError observed live (verified by temporarily reverting the fix and re-running).

Did not perform any live write against /realm/db/polylogue — all live-archive reads used explicit mode=ro URI connections; the fix ships in code for the daemon to pick up on its next deploy.

Verification

  • devtools test tests/unit/storage/test_duplicate_raw_identity_repair.py → 9 passed (2 new tests confirmed to fail against pre-fix code).
  • devtools test tests/unit/storage/test_repair.py tests/unit/storage/test_quarantined_accepted_raw_repair.py tests/unit/storage/test_browser_capture_origin_repair.py tests/unit/storage/test_raw_authority_ledger.py tests/unit/storage/test_quarantine_repair_budget.py tests/unit/devtools/test_raw_authority_scale_proof.py tests/unit/devtools/test_raw_authority_restart_proof.py → 141 passed, no regressions.
  • mypy --strict polylogue/storage/repair.py polylogue/storage/raw_reconciler.py → Success, no issues.
  • ruff check / ruff format --check on all touched files → clean.
  • devtools render all --check → no drift.
  • devtools verify --quick ran clean on push (pre-push hook, exit 0).
  • Did not run devtools verify --all (out of scope for this focused fix).

Ref polylogue-ihc8

Problem: polylogued has been logging "raw authority strategy failed
plan=... actuator=fold_duplicate_alias / RuntimeError: duplicate
strategy did not reach its typed terminal postcondition" recurringly
for 90+ minutes (7 identical failures for one plan hash, 1 for
another), never converging.

Root cause (evidence trail): correlated both plan hashes to their
underlying raw pairs by replaying `_frontier_rows`/`_classify_frontier`
read-only against the live archive at /realm/db/polylogue. Plan
058be945e... resolved to stale raw 08f40243e9... (a pre-#2729
native-id-inclusive raw) and canonical raw e869e6bf26... Querying
`raw_revision_heads WHERE accepted_raw_id = '08f40243e9...'` live
returned FOUR rows, one per logical_source_key/session
(560a3328-..., 0f5e001c-..., 850e32cf-..., 896c6b64-...): the exact
same physical raw acquisition is legitimately the accepted head of
several sessions at once (forked/subagent/resumed sessions replay
the identical parent JSONL evidence). `_inspect_duplicate_raw_identity`
looked this row up by `accepted_raw_id` alone, so `fetchone()` silently
picked an arbitrary one of those four -- the frontier item classified
for session 896c6b64 carried a strategy witness describing session
560a3328's head instead of its own (confirmed directly: the item's own
`index_preconditions.logical_source_key` was 896c6b64 while its
`strategy_witness.logical_source_key` was 560a3328). Applying the fold
then repointed the wrong session's head inside the transaction, the
re-inspect (still unscoped) picked up whatever row was left pointing at
the stale raw, found the canonical now claimed, returned "ineligible"
instead of "already_repaired", and the whole transaction rolled back --
reproducing the identical plan hash and error on every retry with no
progress, exactly matching the 90-minute log pattern.

What changed:
- `_inspect_duplicate_raw_identity` (polylogue/storage/repair.py) now
  takes a required `logical_source_key` parameter and scopes the stale
  raw's accepted-head lookup (and the "already_repaired" session/
  superseded-receipt checks) to that key. The canonical raw's head/
  session checks stay unscoped, since "not claimed by anyone yet" is
  genuinely a global fact, not a per-session one.
- The three call sites in `polylogue/storage/raw_reconciler.py`
  (`_classify_frontier` and both `_apply_strategy` inspect calls) now
  pass the frontier row's/item's own `logical_source_key`.
- Added a regression fixture (`_seed_duplicate_raw_fanout`) and two
  tests reproducing the exact fan-out shape (one stale raw shared as
  accepted head by two sessions, one canonical twin): one proves
  classification no longer cross-contaminates the strategy witness
  between siblings, the other proves applying either sibling's plan
  folds only that sibling and leaves the other's head/session pointer
  untouched. Both tests fail against the pre-fix code with the exact
  same "did not reach its typed terminal postcondition" RuntimeError
  observed live (verified by temporarily reverting the fix).

This is an application-logic bug, not a design gap requiring a new
terminal status: "already_repaired" only ever needed disambiguation,
not a new state.

Verification:
- `devtools test tests/unit/storage/test_duplicate_raw_identity_repair.py`
  -> 9 passed (was 9 passed/0 new before this change; the 2 new tests
  fail against the pre-fix code, confirmed by reverting).
- `devtools test tests/unit/storage/test_repair.py
  tests/unit/storage/test_quarantined_accepted_raw_repair.py
  tests/unit/storage/test_browser_capture_origin_repair.py
  tests/unit/storage/test_raw_authority_ledger.py
  tests/unit/storage/test_quarantine_repair_budget.py
  tests/unit/devtools/test_raw_authority_scale_proof.py
  tests/unit/devtools/test_raw_authority_restart_proof.py`
  -> 141 passed (no regressions in adjacent raw-authority surfaces).
- `mypy --strict polylogue/storage/repair.py
  polylogue/storage/raw_reconciler.py` -> Success, no issues.
- `ruff check` / `ruff format --check` on all three touched files ->
  clean.
- `devtools render all --check` -> no drift (no new modules added).
- Did NOT run `devtools verify --all` or touch the live archive at
  /realm/db/polylogue in any write mode; all live-archive reads used
  explicit `mode=ro` URI connections.

Ref polylogue-ihc8

Co-Authored-By: Claude <[email protected]>
@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, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 823d4426-b64a-4175-8502-d0bc2beaf898

📥 Commits

Reviewing files that changed from the base of the PR and between 427bc98 and b8242ae.

📒 Files selected for processing (3)
  • polylogue/storage/raw_reconciler.py
  • polylogue/storage/repair.py
  • tests/unit/storage/test_duplicate_raw_identity_repair.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/raw-authority-fold-duplicate-alias-postcondition

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 41baf99 into master Jul 27, 2026
3 checks passed
@Sinity
Sinity deleted the feature/fix/raw-authority-fold-duplicate-alias-postcondition branch July 27, 2026 14:46
Sinity added a commit that referenced this pull request Jul 27, 2026
Fast-forwarding master after several parallel PRs merged (#3326-#3331)
triggered the documented post-merge reimport hazard: the beads-guard hook
correctly detected and restored 10 issues (yyvg.7, z9gh.7, z9gh.3, z9gh,
ihc8, t93b, n2f4, r7p6, u0dm, yyvg.6) whose live notes/status/priority were
newer than what the merged .beads/*.jsonl snapshot on disk reflected.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 27, 2026
polylogue-ihc8's fix (PR #3326) was already merged in a prior session;
this session's agent re-verified read-only against the live archive
(deploy still pending, sinnix-side) and filed polylogue-dmvo to track
the N:1 raw-fanout edge case (4 sessions sharing one stale raw, only 1
canonical twin) once the fix deploys.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 28, 2026
…ia met

polylogue-ihc8 was left open pending live confirmation that
fold_duplicate_alias's fix (PR #3326) actually converges in production.
Session 896c6b64's successful fold onto its canonical raw (verified
repeatedly across this session's ewfp/zaiz investigation) is that
confirmation. Closing per the bead's own stated criteria.

Co-Authored-By: Claude <[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