Skip to content

fix(archive): set message_type at materialization time (#839) - #894

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/semantic-artifacts-839
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/semantic-artifacts-839

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026 •

Copy link
Copy Markdown
Owner

Verification: deferred to wave batch per #852 policy.

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy of message type classification to better distinguish between regular messages and contextual/system information.
    • Enhanced detection of context messages through more refined heuristics and narrower matching criteria.
    • Strengthened message categorization during conversation materialization for more precise message handling.

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]>
Copilot AI review requested due to automatic review settings May 7, 2026 08:53
@coderabbitai

coderabbitai Bot commented May 7, 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: 489b0eed-f0a8-4754-9116-ffb949e45627

📥 Commits

Reviewing files that changed from the base of the PR and between 8080cea and 69bb2cb.

📒 Files selected for processing (3)
  • polylogue/archive/message/artifacts.py
  • polylogue/archive/message/model_runtime.py
  • polylogue/pipeline/materialization_runtime.py

📝 Walkthrough

Walkthrough

The PR improves message type classification by extending classify_text_message_type with new detection rules for context messages, refactoring is_context_dump to use the classification function with narrower heuristics, removing legacy marker patterns, and applying the enhanced classification during materialization.

Changes

Message Type Classification Improvements

Layer / File(s) Summary
Classification Markers & Patterns
polylogue/archive/message/artifacts.py
_CONTEXT_START_MARKERS adds <subagent_notification> marker; new regex _CONTENTS_OF_LINE_RE detects "Contents of …:" headings.
Classification Function & Documentation
polylogue/archive/message/artifacts.py
classify_text_message_type docstring expanded to describe persistence and fallback behavior; new rules check for complete <system>...</system> blocks, "Contents of …:" headings, and <file path=...> tags.
Property Logic Rewrite & Cleanup
polylogue/archive/message/model_runtime.py
is_context_dump rewritten to honor stored message_type first, then use classify_text_message_type with two narrow fallback heuristics; legacy marker constants and line patterns removed.
Materialization Integration
polylogue/pipeline/materialization_runtime.py
classify_text_message_type imported and called during materialize_conversation to refine message type classification when initially classified as MessageType.MESSAGE.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit bounds through message flows,
where context hides in structured prose—
<system> tags and file paths true,
now spotted fast, the classification's new. 🐰✨

✨ 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/semantic-artifacts-839

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 8c40ce4 into master May 7, 2026
4 of 5 checks passed
@Sinity
Sinity deleted the feature/fix/semantic-artifacts-839 branch May 7, 2026 08:53

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

Comment thread polylogue/archive/message/artifacts.py Resolved

Copilot AI 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.

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 resulting message_type on archive rows.
  • Update MessageRuntimeMixin context/protocol detection to prefer stored message_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.

Comment on lines 318 to +328
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
Comment on lines 18 to 23
_CONTEXT_START_MARKERS = (
"<environment_context>",
"<permissions instructions>",
"<subagent_notification>",
"<system>",
"<developer>",
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 9, 2026
) (#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]>
Sinity added a commit that referenced this pull request May 9, 2026
One-shot backfill operation that assigns message_type to conversation
rows lacking persisted type. Matches the classification logic from the
pipeline (PR #894). Idempotent — second run is a no-op.

Refs #839
Sinity added a commit that referenced this pull request May 9, 2026
…#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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Sinity/polylogue/pull/988)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@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.

  • 58.F011 / P1: fixed-already at the checked revision: polylogue/archive/message/artifacts.py:124-125 searches for a file-path marker on any line after the initial start-marker checks. Wrapped context whose second line starts with a file marker is no longer classified as ordinary dialogue.

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.

2 participants