Skip to content

fix: reacquire missing raw blob evidence - #2390

Merged
Sinity merged 2 commits into
masterfrom
feature/fix/live-watch-missing-blob-reacquire
Jun 25, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/fix/live-watch-missing-blob-reacquire

Conversation

@Sinity

@Sinity Sinity commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR makes missing raw blob rows stop acting as valid live-cursor proof, adds a dry-run-by-default cursor invalidation maintenance command, and uses that path to repair the live archive without deleting raw rows, source files, index rows, blobs, or user state.

Problem

The live archive had source.db.raw_sessions rows whose blob_hash pointed at absent blob files. Some of those rows were not materialized in index.db.sessions, but the live watcher and batch helper could still treat the source-tier row as acquisition evidence. Existing ops.db.ingest_cursor rows then kept those source files settled, so normal startup catch-up did not re-acquire the missing raw payloads.

Solution

  • Require the named content-addressed blob to exist before watcher cursor reconciliation accepts a source-tier raw row.
  • Require the named blob to exist before archive-tier raw fingerprints are returned to append/full-ingest planning.
  • Add polylogue ops maintenance missing-raw-blob-cursors, dry-run by default, which finds unmaterialized missing-blob raw rows whose source files still exist and optionally deletes only the matching rebuildable ops.db.ingest_cursor rows.
  • Add focused tests for the positive and negative cursor/fingerprint cases and for dry-run/apply CLI behavior.

Live repair evidence

Ref #2308.

Before repair, the live archive had 315 unmaterialized missing-blob raw rows: 96 ChatGPT browser-capture, 5 Claude.ai browser-capture, 55 Codex, and 159 Claude Code. A current durable-tier backup was written at /home/sinity/.local/share/polylogue/archive-db-backups/manual-durable-pre-reacquire-20260625T133437Z before mutation.

The new maintenance command dry-run reported 315 cursor candidates, then --apply deleted exactly 315 rebuildable cursor rows. Branch-local polylogued run --no-api --no-browser-capture catch-up then re-acquired those source files through the normal ingest path. After repair, a direct source/index/blob reconciliation reported missing_unmaterialized: 0; 389 remaining missing blob rows are already materialized by current source/native evidence and are not user-visible materialization debt.

Operational caveat

Full re-acquisition is currently slow: browser-capture and Claude Code full-ingest chunks processed around 0.2 files/s, and one 50-file chunk briefly grew index.db-wal to about 5.9 GiB before checkpointing back down. That is not fixed here; it is runtime performance evidence for a follow-up optimization of full-ingest batching/transaction shape.

Verification

  • devtools test tests/unit/sources/test_live_catchup_planning.py::test_catch_up_repairs_missing_cursor_from_archive_source_row tests/unit/sources/test_live_catchup_planning.py::test_catch_up_does_not_repair_cursor_from_archive_row_with_missing_blob tests/unit/sources/test_live_catchup_planning.py::test_catch_up_reconciles_browser_capture_cursor_from_archive_origin tests/unit/sources/test_live_batch_support.py::test_codex_append_plan_reads_archive_file_set_session_identity tests/unit/sources/test_live_batch_support.py::test_latest_raw_fingerprint_ignores_archive_source_row_with_missing_blob
  • devtools test tests/unit/cli/test_archive_maintenance_cli.py::test_missing_raw_blob_cursor_repair_dry_run_keeps_cursor tests/unit/cli/test_archive_maintenance_cli.py::test_missing_raw_blob_cursor_repair_apply_deletes_only_cursor tests/unit/sources/test_live_catchup_planning.py::test_catch_up_does_not_repair_cursor_from_archive_row_with_missing_blob tests/unit/sources/test_live_batch_support.py::test_latest_raw_fingerprint_ignores_archive_source_row_with_missing_blob
  • devtools verify --quick
  • push hook: devtools verify --quick
  • devtools verify static steps passed, but pytest-testmon selected 9,964 tests because the local seed was stale for this head and timed out at 2700s before producing a JSON report. This is recorded as run 20260625T142529Z-testmon-4089363-7abcaa74; it is not treated as a focused failure of this patch.
  • Live branch catch-up against /home/sinity/.local/share/polylogue: zero remaining unmaterialized missing-blob rows by direct source/index/blob reconciliation.

Summary by CodeRabbit

  • New Features

    • Added a maintenance command to find and optionally remove stale ingestion cursors related to missing archived content.
    • Supports dry-run, apply mode, limits, and plain or JSON output with a summary of affected items.
  • Bug Fixes

    • Improved archive recovery so missing content is detected before restoring cursor state.
    • Prevents cursor repair when the referenced archive file is unavailable, reducing inconsistent recovery behavior.

Sinity added 2 commits June 25, 2026 15:32
Problem: live catch-up and append planning could treat a source-tier raw row as acquisition proof even when the content-addressed blob named by that row was absent. That lets old raw debt suppress fresh acquisition work.

What changed: require archive blob presence before restoring a watcher cursor or returning a raw fingerprint from archive-tier state. Existing positive tests now create the corresponding blob fixture, and new negative tests preserve missing-blob rows as debt while scheduling re-acquisition work.

Verification: devtools test tests/unit/sources/test_live_catchup_planning.py::test_catch_up_repairs_missing_cursor_from_archive_source_row tests/unit/sources/test_live_catchup_planning.py::test_catch_up_does_not_repair_cursor_from_archive_row_with_missing_blob tests/unit/sources/test_live_catchup_planning.py::test_catch_up_reconciles_browser_capture_cursor_from_archive_origin tests/unit/sources/test_live_batch_support.py::test_codex_append_plan_reads_archive_file_set_session_identity tests/unit/sources/test_live_batch_support.py::test_latest_raw_fingerprint_ignores_archive_source_row_with_missing_blob

Verification: devtools verify --quick
Problem: after missing raw blobs are detected, existing live cursors can keep source files settled, so ordinary catch-up never re-acquires the raw payload even though the source file still exists.

What changed: add a dry-run-by-default ops maintenance command that finds unmaterialized raw rows whose blob is absent and source path still exists, then optionally deletes only the matching rebuildable ingest_cursor rows. Raw rows, source files, index rows, blobs, and user state are left intact.

Verification: devtools test tests/unit/cli/test_archive_maintenance_cli.py::test_missing_raw_blob_cursor_repair_dry_run_keeps_cursor tests/unit/cli/test_archive_maintenance_cli.py::test_missing_raw_blob_cursor_repair_apply_deletes_only_cursor tests/unit/sources/test_live_catchup_planning.py::test_catch_up_does_not_repair_cursor_from_archive_row_with_missing_blob tests/unit/sources/test_live_batch_support.py::test_latest_raw_fingerprint_ignores_archive_source_row_with_missing_blob

Verification: devtools verify --quick
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR adds archive-blob existence checks to raw-fingerprint lookup and archived cursor reconciliation, and introduces a maintenance command that reports or deletes ingest cursors for raw sessions whose blobs exist but whose indexed materialization is missing.

Changes

Archive blob cursor repair

Layer / File(s) Summary
Blob existence and raw fingerprint lookup
polylogue/sources/live/batch_support.py, polylogue/sources/live/batch.py, tests/unit/sources/test_live_batch_support.py
_archive_blob_exists validates archive blob paths, _latest_archive_tiers_raw_fingerprint returns a raw id only when the blob exists, and tests cover writing blobs and the missing-blob case.
Archived cursor reconciliation
polylogue/sources/live/watcher.py, tests/unit/sources/test_live_catchup_planning.py
_reconcile_archived_cursor stops when the archive blob is absent, and catch-up tests cover archive rows with and without the on-disk blob.
Candidate selection helpers
polylogue/cli/commands/maintenance.py
Maintenance helpers scan source.db and index.db for raw sessions whose blobs exist on disk, deduplicate by source path, and exclude already materialized native-id matches.
Missing raw blob cursor command
polylogue/cli/commands/maintenance.py, tests/unit/cli/test_archive_maintenance_cli.py
missing-raw-blob-cursors reports candidate ingest cursors in plain text or JSON, and deletes matching ops.db.ingest_cursor rows when --apply is set; CLI tests cover dry-run and apply.

🎯 4 (Complex) | ⏱️ ~60 minutes

I hopped by moonlit blob, so neat,
and tapped the paths with tiny feet.
The missing cursors found their way,
with carrot-bright and tidy day. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.24% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: re-acquiring missing raw-blob evidence.
Description check ✅ Passed The description covers Summary, Problem, Solution, and Verification well, but it omits the template's explicit Changelog and Risks/Follow-ups sections.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/live-watch-missing-blob-reacquire

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.

@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: 2aae4a1302

ℹ️ 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/sources/live/batch_support.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 71.F061 / P2: fixed-already at the checked revision: The configured blob-store accessor now returns archive_root()/blob at polylogue/paths/_roots.py:315. That is the same layout used by the cursor's _archive_blob_exists helper, including when POLYLOGUE_ARCHIVE_ROOT is explicitly set, so the prior XDG-versus-archive-root mismatch is gone.

Only the rows listed above are dispositioned. Held findings remain open.

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