Skip to content

fix: make raw materialization replay auditable - #2387

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/raw-materialization-replay
Jun 25, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/raw-materialization-replay

Conversation

@Sinity

@Sinity Sinity commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make raw acquisition, parsed duplicate handling, index materialization, and FTS freshness converge as one auditable maintenance path. This adds a raw_materialization repair target, fixes duplicate raw replay behavior, and routes split-tier raw-state updates to source.db.

Problem

Production v8 replay exposed raw evidence rows that were acquired and parse-clean but absent from index.db.sessions. The old behavior could replay duplicate ChatGPT export fragments forever, force-rewrite already-materialized sessions, and report stale raw-materialization debt even after replay. Split archive raw-state updates also went through the index backend instead of the source tier.

Solution

  • Add a non-destructive raw_materialization maintenance target that replays available raw blobs and leaves missing blobs as blocked evidence.
  • Let raw-materialization replay defer per-batch FTS repair and run the existing FTS repair once afterward.
  • Treat duplicate raw sources with an existing session and at least the same message count as skipped rather than rewriting the existing session.
  • Mark parsed raw records that produce no new materialized sessions as skipped raw evidence.
  • Route SessionRepository.update_raw_state through source.db when using split archive tiers.
  • Refresh generated CLI/test-quality docs for the new maintenance target.

Verification

  • devtools test tests/unit/storage/test_repair.py::test_raw_materialization_preview_counts_replayable_rows_without_erasing_missing_blobs tests/unit/storage/test_repair.py::test_raw_materialization_defers_batch_fts_then_repairs_once tests/unit/storage/test_raw.py::TestRawSessionStorage::test_repository_update_raw_state_uses_source_tier tests/unit/pipeline/test_ingest_batch.py::test_write_session_skips_shorter_duplicate_raw_source tests/unit/pipeline/test_ingest_batch.py::test_write_session_skips_equal_count_duplicate_raw_source tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_uses_one_typed_update_per_raw tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_marks_skipped_raw_before_success tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_preserves_validation_only_failure_without_quarantine tests/unit/pipeline/test_parsing_service.py::TestParsingServiceStreaming tests/unit/storage/test_archive_tiers_ddl.py::test_archive_tiers_database_bootstrap_leaves_current_tier_unchanged tests/unit/maintenance/test_idempotency.py::test_supported_targets_cover_ac_required_set tests/unit/core/test_maintenance_targets.py — 19 passed.
  • devtools verify --quick — passed locally and in pre-push hook.
  • Production replay evidence: raw_materialization preview now reports replay 0 with 315 missing-blob rows blocked and preserved; dangling_fts reports in sync; diagnostics report ok with FTS triggers present and empty convergence debt.

Ref #2308

Summary by CodeRabbit

  • New Features

    • Added support for a new maintenance repair target, raw_materialization, including CLI/documentation visibility and replay support.
    • Introduced a repair flow that can restore missing raw materializations and then reconcile related full-text search data.
  • Bug Fixes

    • Improved ingest behavior to skip unchanged duplicates more reliably.
    • Raw-state updates now go to the correct database tier, and batch persistence handles skipped/succeeded records more accurately.
  • Documentation

    • Updated CLI and workflow docs to reflect the new target and coverage status.

Problem
Production v8 replay exposed raw_sessions rows that were acquired and parse-clean but absent from index.db. The old repair surface could not replay them as one auditable convergence state, duplicate raw fragments rewrote existing sessions, and split-tier raw-state updates did not persist to source.db.

What changed
Added a raw_materialization maintenance target that replays only available raw blobs and leaves missing blobs as blocked debt. Parsing can now defer per-batch FTS repair and repair once afterward. Duplicate raw sources with an existing session and at least the same message count skip instead of rewriting. Parsed raw records that produce no new materialized sessions are marked skipped, and split-tier raw-state updates write through source.db.

Production evidence
Replayed the production v8 archive from source evidence. Final archive state: 15,994 sessions, 5,499,362 messages, 80,654 web constructs, 2,895,128 usage events, and AI Studio materialized to 222 sessions. raw_materialization preview now reports replay 0 with 315 missing-blob rows blocked and preserved. FTS repair reports in sync with triggers present.

Verification
- devtools test tests/unit/storage/test_repair.py::test_raw_materialization_preview_counts_replayable_rows_without_erasing_missing_blobs tests/unit/storage/test_repair.py::test_raw_materialization_defers_batch_fts_then_repairs_once tests/unit/storage/test_raw.py::TestRawSessionStorage::test_repository_update_raw_state_uses_source_tier tests/unit/pipeline/test_ingest_batch.py::test_write_session_skips_shorter_duplicate_raw_source tests/unit/pipeline/test_ingest_batch.py::test_write_session_skips_equal_count_duplicate_raw_source tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_uses_one_typed_update_per_raw tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_marks_skipped_raw_before_success tests/unit/pipeline/test_ingest_batch.py::test_persist_batch_raw_state_updates_preserves_validation_only_failure_without_quarantine tests/unit/pipeline/test_parsing_service.py::TestParsingServiceStreaming tests/unit/storage/test_archive_tiers_ddl.py::test_archive_tiers_database_bootstrap_leaves_current_tier_unchanged tests/unit/maintenance/test_idempotency.py::test_supported_targets_cover_ac_required_set tests/unit/core/test_maintenance_targets.py
- devtools verify --quick

Ref #2308
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e7244364-d814-4570-8c83-d809632d78c6

📥 Commits

Reviewing files that changed from the base of the PR and between bad677e and 7d550d1.

📒 Files selected for processing (18)
  • docs/cli-reference.md
  • docs/test-quality-workflows.md
  • polylogue/maintenance/replay.py
  • polylogue/maintenance/targets.py
  • polylogue/pipeline/services/ingest_batch/_core.py
  • polylogue/pipeline/services/parsing.py
  • polylogue/pipeline/services/parsing_workflow.py
  • polylogue/storage/repair.py
  • polylogue/storage/repository/__init__.py
  • polylogue/storage/repository/raw/repository_raw.py
  • polylogue/storage/sqlite/archive_tiers/bootstrap.py
  • tests/unit/core/test_maintenance_targets.py
  • tests/unit/maintenance/test_idempotency.py
  • tests/unit/pipeline/test_ingest_batch.py
  • tests/unit/pipeline/test_parsing_service.py
  • tests/unit/storage/test_archive_tiers_ddl.py
  • tests/unit/storage/test_raw.py
  • tests/unit/storage/test_repair.py

📝 Walkthrough

Walkthrough

Adds a new raw_materialization maintenance target, wires it into replay and docs, threads repair_message_fts through parsing and ingest batch flows, updates source-tier raw-state persistence, and adds a repair routine that materializes replayable raw sessions before FTS repair.

Changes

Raw Materialization Repair Flow

Layer / File(s) Summary
Maintenance target registration
polylogue/maintenance/targets.py, polylogue/maintenance/replay.py, docs/cli-reference.md, docs/test-quality-workflows.md, tests/unit/core/test_maintenance_targets.py, tests/unit/maintenance/test_idempotency.py
raw_materialization is added to the maintenance catalog and replay dispatch, and the docs and target-coverage tests include it.
Source-tier repository plumbing
polylogue/storage/repository/__init__.py, polylogue/storage/repository/raw/repository_raw.py, polylogue/storage/sqlite/archive_tiers/bootstrap.py, tests/unit/storage/test_raw.py, tests/unit/storage/test_archive_tiers_ddl.py
SessionRepository can open source.db, raw-state updates use that backend when available, and archive initialization returns early when the tier version already matches.
Parsing workflow forwarding
polylogue/pipeline/services/parsing_workflow.py, polylogue/pipeline/services/parsing.py, tests/unit/pipeline/test_parsing_service.py
parse_from_raw forwards repair_message_fts through the service and workflow, and raw-ID batching now uses the synchronous helper before batch writes begin.
Ingest batch write control
polylogue/pipeline/services/ingest_batch/_core.py, tests/unit/pipeline/test_ingest_batch.py
Ingest batches now count written sessions, mark raws that materialize nothing, and expose repair_message_fts through the batch API and FTS suspension path.
Skipped raw-state persistence
polylogue/pipeline/services/ingest_batch/_core.py, tests/unit/pipeline/test_ingest_batch.py
Raw-state persistence now uses the source backend when present, skips succeeded/skipped overlaps, and writes skipped raws with the skipped validation state.
Raw materialization repair orchestration
polylogue/storage/repair.py, tests/unit/storage/test_repair.py
repair_raw_materialization discovers replayable raws, reports missing-blob debt, runs parsing and dangling-FTS repair, and exports the new entry point.

Sequence Diagram(s)

sequenceDiagram
  participant Repair as repair_raw_materialization
  participant BlobStore
  participant Parse as ParsingService.parse_from_raw
  participant Ingest as process_ingest_batch
  participant Repo as SessionRepository.update_raw_state
  participant FTS as repair_dangling_fts

  Repair->>BlobStore: exists(blob_hash)
  Repair->>Parse: replay raw_ids
  Parse->>Ingest: repair_message_fts
  Ingest->>Repo: persist raw validation state
  Repair->>FTS: repair dangling rows
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • Sinity/polylogue#1428 — Also updates polylogue/maintenance/replay.py dispatch wiring for new maintenance target names.
  • Sinity/polylogue#1453 — Also threads repair_message_fts through the ingest/commit path.
  • Sinity/polylogue#2321 — Also changes ingest batch write behavior in polylogue/pipeline/services/ingest_batch/_core.py.

Suggested labels

area:storage, area:pipeline, area:cli, type:test

Poem

A bunny peeks at raw and light,
Then hops through FTS late at night.
With source.db and replay cheer,
The little bugs all disappear. 🐇

✨ 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/raw-materialization-replay

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.

github-actions Bot pushed a commit that referenced this pull request Jun 25, 2026
@Sinity
Sinity merged commit 3f48928 into master Jun 25, 2026
14 of 15 checks passed
@Sinity
Sinity deleted the feature/fix/raw-materialization-replay branch June 25, 2026 11:54

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

ℹ️ 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/maintenance/targets.py Resolved
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@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.

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