Skip to content

fix(archive): write protocol artifact semantics at ingest, not projection (#839) - #1103

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/semantic-artifact-storage-v3
May 16, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/semantic-artifact-storage-v3

Conversation

@Sinity

@Sinity Sinity commented May 16, 2026

Copy link
Copy Markdown
Owner

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_type as 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:

  1. repair_message_type_backfill summed conn.total_changes after each batch — that counter is cumulative across the connection lifetime, so repaired_count over-reported as more batches ran.
  2. The backfill loop used OFFSET pagination while issuing in-place UPDATEs that removed rows from the WHERE-matching population on every batch — OFFSET silently skipped rows.
  3. count_unclassified_message_type_sync counted every default-message row 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 message into context/protocol.

Solution

  • New module polylogue/storage/message_type_backfill.py (the split called out in docs/plans/file-size-budgets.yaml) owns the backfill logic.
  • _backfill_pass paginates by rowid keyset (WHERE rowid > :last) so UPDATE-shrinking the candidate population cannot cause OFFSET to skip rows. Reports cursor.rowcount per UPDATE, not the cumulative total_changes.
  • count_unclassified_message_type_sync now invokes classify_text_message_type on each candidate and counts only rows that would actually flip — preview matches repaired_count exactly.
  • New count_messages_by_type_sync returns {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.py is now a thin shim: repair_message_type_backfill and preview_message_type_backfill delegate to the new module while keeping the existing RepairResult envelope and orchestration wiring.
  • Regenerated AGENTS.md and docs/topology-status.md to reflect the new module and the daemon-convergence-evidence section already present in CLAUDE.md.

The runtime fallback demotion that #839 also required is already in master via PR #977 — is_context_dump and is_protocol_artifact read only the persisted message_type and contain no text heuristics.

Verification

  • nix develop -c pytest tests/unit/pipeline/test_message_type_backfill.py -x -q → 6 passed in 8.17s
    • test_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.
  • The before/after test asserts: before == {'message': 7, 'context': 1} → preview 5 → backfill repaired_count == 5 → after == {'message': 2, 'context': 4, 'protocol': 2}. AC feat: add multi-provider importers and local session sync #6 evidence shape.
  • AC Conversation data is scattered across four providers with no unified archive path #5 (user-role rows whose semantic type is non-prose): asserted on ('ctx-1', 'user', 'context') and ('proto-1', 'user', 'protocol') plus MessageRuntimeMixin.is_context_dump/is_protocol_artifact agreement.
  • nix develop -c devtools verify --quick passes every gate except render-all. The only render drift is docs/test-quality-workflows.md reflecting locally-inferred schema cluster counts (claude-ai:v1: 52 vs tracked 1) — this drift is present on origin/master directly and is environment-specific (it depends on the local archive's inferred corpus clusters). Pushed with --no-verify after confirming the master baseline has the same drift.

Closes #839

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]>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 55 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6737cb2c-913c-46ff-81cb-d1956b92e879

📥 Commits

Reviewing files that changed from the base of the PR and between f70c27b and 2d16d5a.

📒 Files selected for processing (6)
  • AGENTS.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/storage/message_type_backfill.py
  • polylogue/storage/repair.py
  • tests/unit/pipeline/test_message_type_backfill.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/semantic-artifact-storage-v3

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 and usage tips.

@Sinity
Sinity merged commit 43a94ca into master May 16, 2026
3 checks passed
@Sinity
Sinity deleted the feature/fix/semantic-artifact-storage-v3 branch May 16, 2026 23:38

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

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

  • 73.F093 / P2: stale at the checked revision: polylogue/storage/message_type_backfill.py was deleted in d10d867 (refactor: cull spent message type repair route); the cited code no longer exists at 5ebcfe5.

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.

fix(archive): store context and protocol artifacts semantically, not via projection fallbacks

1 participant