Skip to content

fix(storage): copy forward legacy browser NULL identities (#2843) - #2843

Merged
Sinity merged 4 commits into
masterfrom
feature/fix/legacy-browser-native-id
Jul 13, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/fix/legacy-browser-native-id

Conversation

@Sinity

@Sinity Sinity commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add a dedicated maintenance actuator for the exact historical browser-capture
raw shape whose durable native_id is NULL. It preserves original evidence and
creates a canonical copy-forward raw with the parser-derived identity.

Problem

The retained browser bytes normalize to one ChatGPT session, but the durable
source raw lacks native identity. The ordinary browser-origin repair correctly
rejects it; relaxing that identity proof would be unsafe. The legacy route also
needs one crash-durable outcome across source.db and index.db.

Solution

  • Add a separately named repair API and maintenance command for the exact
    legacy shape only.
  • Require exact unknown-export/browser/full/quarantined/singleton evidence,
    NULL native identity, parser result, source/blob agreement, census, current
    head, and application receipt.
  • Run legacy apply in the rollback-superjournal-v1 offline maintenance
    window: idle checkpoint, temporary DELETE journals, synchronous=EXTRA,
    BEGIN EXCLUSIVE, index-main/source-attached transaction, then WAL restore.
  • Bind protocol, legacy NULL witness, parser-derived identity, and journal
    posture in legacy receipts. Existing ordinary v1 receipt targets remain
    compatible.

Acceptance criteria

Criterion Status Evidence
Ordinary route rejects NULL; legacy route alone accepts exact evidence Satisfied storage tests
Witness drift fails before a source write Satisfied source/head/application mutations
Copy-forward preserves old evidence and parsed identity Satisfied receipt and byte-for-byte assertions
Competing or non-singleton evidence is rejected Satisfied head/membership/blob-ref regressions
Crash cannot commit only one tier Satisfied subprocess deaths before/after commit plus resume
Normal failure rolls back both tiers Satisfied injected index-transition failure
Reapply is idempotent; stale proof writes nothing Satisfied focused tests
Source-v7 and pre-legacy ordinary receipts remain supported Satisfied compatibility regressions

Verification

  • devtools test tests/unit/storage/test_browser_capture_origin_repair.py -k "legacy_browser_native_id or prelegacy_planned_receipt" — 16 passed, 93 deselected.
  • Independent final selected scope — 18 passed.
  • devtools verify --quick — success; pre-push reran it successfully.
  • Independent durability review confirmed the offline guard, lease/exclusion,
    same-device condition, super-journal transaction, WAL restoration, and
    before/after-commit crash recovery.

Follow-up / live operation

No live archive mutation is included. Before live use: take a fresh full
backup, stop the daemon, run the exact read-only dry-run, apply with a stored
receipt, then verify the postflight census has zero mismatched heads.

Ref polylogue-lkrc.1

Problem: a historical browser-capture raw has native_id NULL even though\nits retained bytes normalize to a canonical ChatGPT session. Ordinary\norigin repair correctly refuses that mismatch and must remain strict.\n\nWhat changed: add a separately named legacy-only maintenance actuator\nthat requires the exact NULL identity evidence shape, reproves the full\nsource/blob/parser/census/head/application witnesses, and copy-forwards a\nnew canonical raw. Planned and applied receipts bind the NULL witness and\nparser-derived identity; the original durable evidence remains untouched.\n\nCompatibility: pre-existing ordinary terminal receipts remain readable;\nlegacy receipts use a dedicated schema.\n\nRef polylogue-lkrc.1\n\nCo-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a maintenance command and storage API for repairing legacy browser-capture records with NULL native_id. The repair validates evidence, supports schema-aware staging and journal recovery, records legacy receipt metadata, and includes CLI and storage coverage.

Changes

Legacy native-id repair

Layer / File(s) Summary
Repair entrypoints and contracts
polylogue/cli/commands/maintenance.py, polylogue/storage/repair.py
Adds the maintenance command, legacy repair API, report fields, receipt constants, and JSON/plain-text output handling.
Legacy eligibility and evidence validation
polylogue/storage/repair.py
Supports nullable native IDs, parser-derived IDs, legacy copy-forward payloads, and exact membership/blob evidence checks.
Schema-aware staging and crash recovery
polylogue/storage/repair.py
Adds source-schema staging, legacy journal orchestration, proof revalidation, receipt locking, and terminal finalization.
Repair recovery and validation tests
tests/unit/cli/test_archive_maintenance_cli.py, tests/unit/storage/test_browser_capture_origin_repair.py
Tests CLI validation, idempotency, crash recovery, evidence drift, schema compatibility, stale proofs, eligibility rules, and atomic rollback.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant MaintenanceCommand
  participant RepairEngine
  participant SourceDB
  participant IndexDB
  participant Receipt
  Operator->>MaintenanceCommand: Provide raw IDs and apply options
  MaintenanceCommand->>RepairEngine: Invoke legacy native-id repair
  RepairEngine->>SourceDB: Validate and stage legacy evidence
  RepairEngine->>IndexDB: Apply copy-forward repair
  RepairEngine->>Receipt: Record planned and terminal states
  Receipt-->>MaintenanceCommand: Return repair report
  MaintenanceCommand-->>Operator: Render repair result
Loading

Possibly related PRs

  • Sinity/polylogue#2836: Both changes modify browser-capture semantic-head handling and copy-forward finalization in polylogue/storage/repair.py.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and clearly matches the main change: adding legacy browser NULL-identity copy-forward repair.
Description check ✅ Passed The description covers the required summary, problem, solution, verification, and follow-up details, with only the Changelog section omitted.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/legacy-browser-native-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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

A legacy receipt detail is valid only while the dedicated repair path supplies\na concrete parser-derived native identity. Ordinary origin repair must not\naccept a legacy-shaped detail with a missing identity witness.\n\nRef polylogue-lkrc.1\n\nCo-Authored-By: Claude <[email protected]>

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

ℹ️ 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 polylogue/storage/repair.py Resolved
The dedicated NULL-native browser capture route now rejects competing\ncanonical authority and non-singleton source witnesses.  It stages the\ncopy-forward source rows and index transition in one attached-database\ntransaction, leaving the ordinary repair route unchanged.\n\nRegression coverage proves rollback after source staging, receipt state,\nsource-v7 compatibility, and idempotence.\n\nRef polylogue-lkrc.1.\n\nCo-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

The independent-review changes are pushed at 6672367. Please re-audit the legacy-only transaction, singleton proof, and rollback invariants. Local verification is recorded in the PR body; no live archive mutation was run.

Problem: the legacy browser-native-id actuator needs one durable outcome\nacross source.db and index.db even if its process dies mid-repair.\n\nWhat changed: enter a guarded, legacy-only DELETE rollback-journal\nmaintenance window so SQLite uses the attached-database super-journal\nprotocol, then restore normal WAL posture before terminalizing the receipt.\nRecord the protocol and posture evidence in legacy receipts while keeping\nordinary v1 receipt targets compatible.\n\nVerification: focused legacy repair tests exercise subprocess deaths before\nand after commit, recovery, rollback, and ordinary receipt resumption.\n\nCo-Authored-By: Claude <[email protected]>
@Sinity
Sinity merged commit 8564367 into master Jul 13, 2026
2 checks passed
@Sinity
Sinity deleted the feature/fix/legacy-browser-native-id branch July 13, 2026 14:08
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