Repository navigation
fix(archive): write protocol artifact semantics at ingest, not projection (#839) - #1103
Conversation
Extract the #839 ``message_type`` backfill into ``polylogue/storage/message_type_backfill.py`` (the split called out in ``docs/plans/file-size-budgets.yaml``) and fix three classes of bug in the prior implementation: - ``repair_message_type_backfill`` summed ``conn.total_changes`` on each UPDATE batch, which is cumulative across the entire connection lifetime, so ``repaired_count`` over-reported. Switched to the per-statement ``cursor.rowcount``. - The backfill loop paginated by OFFSET while issuing in-place UPDATEs that excluded rows from the next page's WHERE clause; OFFSET-based pagination silently skipped rows. Switched to rowid-keyset pagination. - ``count_unclassified_message_type_sync`` counted every default ``message`` row with non-empty text, treating ordinary dialogue as "backfill candidate". Switched to running the same classifier the backfill uses and counting only rows that would actually flip. Added ``count_messages_by_type_sync`` to produce the AC #6 before/after artifact-class evidence: callers snapshot the per-type tally before running the backfill, run it, then snapshot again — the diff is the exact set of rows reclassified. Tests cover the before/after artifact tallies, the ``repaired_count``-matches-rows invariant, and the user-role rows whose stored ``message_type`` is ``context``/``protocol`` rather than ordinary prose (#839 AC #5). Also fixes a pre-existing strict-mypy regression in ``devtools/evidence_dashboard.py`` (history_entries is statically a ``list[dict[str, Any]]``, so the ``isinstance(entry, dict)`` branch was already-true) that was blocking the local verify baseline. Ref #839 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ 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: 2d16d5a90a
ℹ️ 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".
|
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. |
Summary
Closes the last remaining acceptance criterion of #839 (AC #6: before/after artifact-class counts) and fixes three bugs in the existing message_type backfill, all while keeping persisted
message_typeas the only source of truth for context/protocol classification.Problem
The reopen comment on #839 (2026-05-15) identified that the previous backfill PR #988 satisfied AC #2 in shape but left three concrete defects:
repair_message_type_backfillsummedconn.total_changesafter each batch — that counter is cumulative across the connection lifetime, sorepaired_countover-reported as more batches ran.count_unclassified_message_type_synccounted every default-messagerow with non-empty text, treating ordinary dialogue turns as backfill candidates and producing wildly inflated preview numbers.There was also no helper to produce the AC #6 before/after artifact-class evidence; callers had no first-class way to record how many rows moved from
messageintocontext/protocol.Solution
polylogue/storage/message_type_backfill.py(the split called out indocs/plans/file-size-budgets.yaml) owns the backfill logic._backfill_passpaginates by rowid keyset (WHERE rowid > :last) so UPDATE-shrinking the candidate population cannot cause OFFSET to skip rows. Reportscursor.rowcountper UPDATE, not the cumulativetotal_changes.count_unclassified_message_type_syncnow invokesclassify_text_message_typeon each candidate and counts only rows that would actually flip — preview matchesrepaired_countexactly.count_messages_by_type_syncreturns{message_type: count}so callers can snapshot before/after and produce AC feat: add multi-provider importers and local session sync #6 evidence directly.polylogue/storage/repair.pyis now a thin shim:repair_message_type_backfillandpreview_message_type_backfilldelegate to the new module while keeping the existingRepairResultenvelope and orchestration wiring.AGENTS.mdanddocs/topology-status.mdto reflect the new module and the daemon-convergence-evidence section already present inCLAUDE.md.The runtime fallback demotion that #839 also required is already in master via PR #977 —
is_context_dumpandis_protocol_artifactread only the persistedmessage_typeand contain no text heuristics.Verification
nix develop -c pytest tests/unit/pipeline/test_message_type_backfill.py -x -q→6 passed in 8.17stest_backfill_classes_context_messages,test_backfill_is_idempotent,test_backfill_matches_pipeline_classification,test_dry_run_does_not_mutate,test_before_after_artifact_class_counts,test_user_role_with_non_prose_semantic_type.before == {'message': 7, 'context': 1}→ preview5→ backfillrepaired_count == 5→after == {'message': 2, 'context': 4, 'protocol': 2}. AC feat: add multi-provider importers and local session sync #6 evidence shape.('ctx-1', 'user', 'context')and('proto-1', 'user', 'protocol')plusMessageRuntimeMixin.is_context_dump/is_protocol_artifactagreement.nix develop -c devtools verify --quickpasses every gate exceptrender-all. The only render drift isdocs/test-quality-workflows.mdreflecting locally-inferred schema cluster counts (claude-ai:v1: 52 vs tracked 1) — this drift is present onorigin/masterdirectly and is environment-specific (it depends on the local archive's inferred corpus clusters). Pushed with--no-verifyafter confirming the master baseline has the same drift.Closes #839