Skip to content

fix(storage): widen empty-session repair to catch content-empty phantoms - #3583

Merged
Sinity merged 1 commit into
masterfrom
feature/storage/widen-empty-session-repair-phantom-artifacts
Aug 2, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/storage/widen-empty-session-repair-phantom-artifacts

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Widens polylogue/storage/repair.py's empty_sessions maintenance-repair target so it also catches sessions that have message rows but zero real content (all-zero-word messages), not only literally message-less sessions. Adds the one missing regression test among 6 named phantom-artifact shapes.

Problem

polylogue-21qj found 6 non-transcript files under watched ~/.claude/projects trees had been ingested as claude-code-session rows in the live archive: a sinex analysis-index (conversation_relationships.jsonl, 96,748 empty messages), a derived duplicate-messages index (high_value_messages.jsonl, 8,763 real duplicate messages), an empty problem-index (problems_index.jsonl), 3x oversized-tool-output spill files (tool-results/toolu_*.json), and a workflow journal (journal.jsonl).

Investigating against the live archive (read-only, /realm/db/polylogue) and the current checkout found 5 of the 6 shapes are already refused at detection time by prior merged work (#3426 self-generated analysis/ dir guard, #3428 looks_like_code envelope-marker requirement, c6190d7 letting record content override the analysis/ guard, and the pre-existing workflow_journal OriginArtifactRule). Verified live: reran each real file's exact byte content (read from source.db + the blob store, since 2 of 3 sinex files no longer exist on disk) through classify_artifact/detect_provider_evidence — all return parse_as_session=False.

For cleanup, polylogue-ne6k had already built exactly the classifier + dry-run-gated actuator pattern this bead asked for (repair.py's empty_sessions target, wired through polylogue maintenance repair --target empty_sessions, dry-run by default) — but scoped to literally message-less sessions (NOT EXISTS messages). conversation_relationships has 96,748 message rows (every one carrying zero blocks/words), so it fell outside that predicate and was never even a repair candidate.

Solution

  • Widened _empty_session_candidate_ids (renamed from _empty_session_message_less_candidates) to also propose sessions where sessions.word_count = 0 regardless of message_count. The existing positive-classification gate (_raw_artifact_positively_fails_classification) remains the sole deletion authority — a legitimate all-tool-use session with no text turns still passes classification and is retained (pinned by test_all_empty_content_session_with_legit_raw_is_retained).
  • Added test_all_empty_content_session_with_phantom_raw_counts_as_debris, pinning that a conversation_relationships-shaped session (many zero-word message rows, relationship-index-shaped raw artifact under analysis/) is now flagged.
  • Added test_analysis_signal_duplicate_messages_are_not_a_session to test_artifact_taxonomy.py, the missing regression pin for the 6th named shape (high_value_messages.jsonl's real field shape: file/timestamp/type/content).
  • Updated the empty_sessions maintenance-target description to reflect the broader predicate.

high_value_messages.jsonl (8,763 non-empty messages, 827,894 words) is deliberately excluded from the purge — its content is real duplicated conversation text, and investigation found the real source session (bad69218-...) is stuck revision_authority='quarantined' and never parsed, so this phantom is currently the archive's only queryable copy of that content. Blanket deletion would be real data loss, not garbage collection. Deferred to polylogue-6bebe.

Verification

  • devtools test tests/unit/storage/test_empty_session_repair_provenance.py tests/unit/sources/test_artifact_taxonomy.py — 15 passed.
  • devtools verify --quick — exit 0, all 19 steps green (also ran again automatically via the pre-push hook).
  • Read-only measurement against the live archive: before this change, conversation_relationships was absent from _empty_session_debris_session_ids's output; after, it is flagged alongside the already-flagged problems_index/journal/3x toolu_*. Total flagged debris across the archive went from 5023 to 5076 rows (+53 — this generalization also catches other same-shaped phantoms archive-wide, not only the 5 named in this bead).
  • Pre-existing, unrelated failure found and not fixed here: tests/unit/maintenance/test_planner_contract.py and test_planner_filter_narrowing.py fail with a TypeError (row_factory not set on a test fixture's index connection) on master (120cf6f) too, confirmed via git stash before this change. Filed as polylogue-9rdky.

Ref polylogue-21qj, polylogue-gvgi (closed as duplicate), polylogue-6bebe, polylogue-9rdky

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3785415d-bc00-45cb-89fb-2de0a944a637

📥 Commits

Reviewing files that changed from the base of the PR and between aeb5bbc and 757d5d3.

📒 Files selected for processing (4)
  • polylogue/maintenance/targets.py
  • polylogue/storage/repair.py
  • tests/unit/sources/test_artifact_taxonomy.py
  • tests/unit/storage/test_empty_session_repair_provenance.py

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.

@Sinity
Sinity force-pushed the feature/storage/widen-empty-session-repair-phantom-artifacts branch 2 times, most recently from 3829a55 to 05257a0 Compare August 2, 2026 19:53
Problem: polylogue-21qj found 6 non-transcript files under watched
~/.claude/projects trees (a sinex analysis-index, a tool-result spill file
x3, a workflow journal, a derived duplicate-messages index) had been
ingested as claude-code-session rows. Investigation found 5 of the 6 shapes
are already refused at detection time by prior work (#3426, #3428,
c6190d7, and the pre-existing workflow_journal OriginArtifactRule) --
verified live by rerunning each real file's exact byte content (read from
source.db + the blob store, since 2 of 3 sinex files no longer exist on
disk) through classify_artifact/detect_provider_evidence.

For cleanup, polylogue-ne6k had already built the classifier+dry-run-gated
maintenance-repair pattern this bead asked for (repair.py's `empty_sessions`
target, wired through `polylogue maintenance repair --target
empty_sessions`) -- but scoped to literally message-less sessions
(`NOT EXISTS messages`). claude-code-session:conversation_relationships has
96,748 MESSAGE ROWS, every one carrying zero blocks/words, so it fell
outside that predicate entirely and was never even a repair candidate.

Solution: widen `_empty_session_candidate_ids` (renamed from
`_empty_session_message_less_candidates`) to also propose sessions where
`sessions.word_count = 0` regardless of message_count. The existing
positive-classification gate (`_raw_artifact_positively_fails_classification`)
remains the sole deletion authority, so a legitimate all-tool-use session
with no text turns is still retained (its raw artifact still carries real
Claude Code envelope markers and passes classification).

Also added the one missing regression pin: analysis/signal/high_value_
messages.jsonl (the 6th named shape) was already refused via the
analysis/ directory heuristic but had no dedicated test using its real
field shape (file/timestamp/type/content). That session is deliberately
excluded from the empty_sessions purge (word_count=827,894, real content)
-- investigation found its real source session is stuck
revision_authority='quarantined' and never parsed, so it is currently the
archive's only queryable copy of that conversation; deferred to
polylogue-6bebe rather than deciding blanket deletion here.

Verification:
- devtools test tests/unit/storage/test_empty_session_repair_provenance.py
  tests/unit/sources/test_artifact_taxonomy.py -- 15 passed. New tests pin
  both the widened-predicate debris case and its "legit all-tool-use"
  sibling that must NOT be swept in, plus the high_value_messages shape.
- devtools verify --quick -- exit 0, all 19 steps green.
- Read-only measurement against the live archive (/realm/db/polylogue):
  before this change, conversation_relationships was absent from
  `_empty_session_debris_session_ids`'s output; after, it is flagged
  alongside problems_index/journal/3x toolu_*. Total flagged debris across
  the archive went from 5023 to 5076 rows (+53, this generalization also
  catches other same-shaped phantoms, not only the 5 named here).
- Pre-existing, unrelated failure noted and NOT fixed here: tests/unit/
  maintenance/test_planner_contract.py and test_planner_filter_narrowing.py
  fail with a TypeError (row_factory not set on a test fixture's index
  connection) on master (120cf6f) before this change too (confirmed via
  git stash) -- filed as polylogue-9rdky.

Ref polylogue-21qj, polylogue-gvgi (closed as duplicate), polylogue-6bebe,
polylogue-9rdky

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/storage/widen-empty-session-repair-phantom-artifacts branch from 05257a0 to 757d5d3 Compare August 2, 2026 20:10
@Sinity
Sinity merged commit 292f319 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/storage/widen-empty-session-repair-phantom-artifacts branch August 2, 2026 20:11
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