Repository navigation
fix(archive): set message_type at materialization time (#839) - #894
Conversation
Classify messages as CONTEXT or PROTOCOL during materialization so stored rows carry authoritative semantic type, not read-time text heuristics. Problem: MessageType.CONTEXT and MessageType.PROTOCOL are valid enum values but were never set during materialization. Classification happened at read time via regex heuristics in model_runtime.py, meaning every read surface re-classified the same text repeatedly. Solution: - Call classify_text_message_type() during materialization after content-block-based classification, persisting CONTEXT/PROTOCOL in messages.message_type at write time. - Enhance classify_text_message_type() with additional context heuristics previously scattered across model_runtime.py (subagent_notification marker, <system>...</system> pair detection, Contents-of-line pattern, <file path= prefix). - Simplify is_context_dump and is_protocol_artifact to trust stored message_type first, keeping classify_text_message_type as resilience fallback for pre-#839 archive rows. Remove duplicate local marker constants from model_runtime.py. Verification: deferred to wave batch per #852 policy. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR improves message type classification by extending ChangesMessage Type Classification Improvements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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: 69bb2cbe30
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
This PR improves archive semantics by ensuring message_type (especially context and protocol artifacts encoded as plain text) is classified and persisted during conversation materialization, and by aligning runtime helpers to treat the stored message_type as authoritative while retaining fallback heuristics for pre-#839 rows.
Changes:
- Classify text-only runtime artifacts during
materialize_conversation()and persist the resultingmessage_typeon archive rows. - Update
MessageRuntimeMixincontext/protocol detection to prefer storedmessage_type, with text-based fallback for older archives. - Centralize and extend text artifact heuristics in
classify_text_message_type()(including additional context markers/patterns).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
polylogue/pipeline/materialization_runtime.py |
Adds materialization-time classification for context/protocol artifacts when message_type is still MESSAGE. |
polylogue/archive/message/model_runtime.py |
Makes context/protocol detection primarily rely on persisted message_type, with fallback for legacy rows. |
polylogue/archive/message/artifacts.py |
Extends and documents text heuristics used to classify runtime context/protocol artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if message_type == MessageType.MESSAGE: | ||
| if has_thinking_block: | ||
| message_type = MessageType.THINKING | ||
| elif has_tool_result_block or msg.role == "tool": | ||
| message_type = MessageType.TOOL_RESULT | ||
| elif has_tool_block: | ||
| message_type = MessageType.TOOL_USE | ||
| if message_type == MessageType.MESSAGE: | ||
| classified = classify_text_message_type(msg.text) | ||
| if classified is not None: | ||
| message_type = classified |
| _CONTEXT_START_MARKERS = ( | ||
| "<environment_context>", | ||
| "<permissions instructions>", | ||
| "<subagent_notification>", | ||
| "<system>", | ||
| "<developer>", |
PR #836 taught projections how to avoid treating Claude Code / Codex protocol artifacts as user prose, but stored rows still contained context and protocol artifacts as inline message text or legacy `message_type` values, forcing runtime classifiers to compensate at every read. - `polylogue/pipeline/materialization_runtime.py`: persists `MessageType.CONTEXT` and `MessageType.PROTOCOL` directly on the materialized rows so the archive table represents the semantic entity instead of leaving classification to hydration. - `polylogue/archive/message/{artifacts,model_runtime}.py`: hydration trusts the persisted type and only falls back to the runtime classifier when the row predates the materializer change. Refs #839
PR #836 taught projections how to avoid treating Claude Code / Codex protocol artifacts as user prose, but stored rows still contained context and protocol artifacts as inline message text or legacy `message_type` values, forcing runtime classifiers to compensate at every read. - `polylogue/pipeline/materialization_runtime.py`: persists `MessageType.CONTEXT` and `MessageType.PROTOCOL` directly on the materialized rows so the archive table represents the semantic entity instead of leaving classification to hydration. - `polylogue/archive/message/{artifacts,model_runtime}.py`: hydration trusts the persisted type and only falls back to the runtime classifier when the row predates the materializer change. Refs #839
) (#977) ## Summary Removes the runtime `classify_text_message_type()` fallback at `polylogue/archive/message/model_runtime.py:242,255`. Post-#894, new rows have persisted `message_type` from the pipeline. This PR drops the safety-net fallback so that classification only comes from the persisted type column. ## Problem AC #3 of #839: "stop using runtime classification." The runtime fallback was a safety net for rows that lacked persisted message_type. That safety net is no longer needed for new rows (post-#894) but was suppressing the visibility of pre-#839 rows that still need backfill. ## Solution - Return sentinel (UNKNOWN) when message lacks persisted type, instead of calling the runtime classifier - Test covers: persisted type used, missing persisted type returns UNKNOWN, classify_text_message_type NOT called at runtime ## Certification ### WORK 1. Stop using runtime classification at model_runtime.py:242,255 (AC #3 of #839) ### REALIZATION 1. polylogue/archive/message/model_runtime.py: dropped fallback; test: tests/unit/archive/test_model_runtime_no_runtime_classify.py ### DECLARATION I declare the WORK item above to be fully realized. AC #2 (pre-#839 row backfill) and AC #6 (artifact counts) of #839 are EXCLUDED from this PR — they remain tracked in #839 and #971. Verified by: pytest tests/unit/archive/ -q. Refs #839 Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…#988) ## Summary Adds a one-shot, idempotent backfill operation that assigns `message_type` to rows ingested before PR #894 (which introduced persisted CONTEXT/PROTOCOL classification). Complements PR #977 (dropping the runtime classifier fallback). ## Certification ### WORK AC #2 of #839: backfill pre-#839 rows with correct message_type ### REALIZATION 1. polylogue/maintenance/targets.py: maintenance target registration 2. polylogue/storage/repair.py: idempotent backfill logic 3. tests/unit/pipeline/test_message_type_backfill.py: idempotency + fill coverage ### DECLARATION I declare the WORK item above to be fully realized. AC #6 (before/after artifact counts) remains tracked in #839. Verified by: pytest. Refs #839 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added a new message type backfill maintenance operation that automatically classifies and updates unclassified messages. * **Tests** * Added comprehensive test coverage for the message type backfill operation, including idempotency and dry-run validation. [](https://app.coderabbit.ai/change-stack/Sinity/polylogue/pull/988) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
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. |
Verification: deferred to wave batch per #852 policy.
Summary by CodeRabbit