Skip to content

fix(sources): keep strongest title evidence across Claude Code chunks - #3506

Merged
Sinity merged 1 commit into
masterfrom
fix/sources/claude-code-title-chunk-merge-precedence
Aug 1, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/sources/claude-code-title-chunk-merge-precedence

Conversation

@Sinity

@Sinity Sinity commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a title-merge bug in Claude Code's memory-bounded multi-GiB streaming
ingest path that silently discarded a session's provider-supplied title
(ai-title/custom-title/agent-name) in favor of a weaker guess, whenever
the session was large/long-lived enough to be parsed as multiple streamed
chunks.

Problem

Ref polylogue-t5lg: "84.6% of Claude Code sessions are titled with a raw
UUID: 10,157 of 12,001." Re-measuring the live archive (read-only,
/realm/db/polylogue/index.db) during investigation showed the problem got
worse, not better, despite polylogue-pbuh (closed, merged) already adding
a title-resolution ladder to code_parser.py's single-pass parser (ai-title

custom-title > agent-name > first-human-message heuristic > raw id, with
title_source/title_ref/title_confidence provenance):

claude-code-session: 16,552 total / 14,801 UUID-titled (89.4%)
  title_source breakdown: unknown=14,848  heuristic=1,431  origin=273

Spot-checking several ai-title-bearing raw session files against the live
archive confirmed the single-pass ladder works correctly when a session is
parsed in one pass
(e.g. 35548562-... correctly resolved to
title_source='origin', title='Review lanes performance wave documentation'). But polylogue/sources/dispatch.py:merge_parsed_session_chunks
— the only caller of Claude Code's streaming path, used for JSONL files large
enough that eager whole-file parsing isn't memory-bounded — merged chunk
titles with:

"title": existing.title if existing.title != existing.provider_session_id else session.title,

i.e. "whichever chunk resolves a non-UUID title first wins, permanently."
A large session (bead notes cite a 6,059-message / 536,011-word example) that
happens to resolve a weak TitleSource.HEURISTIC guess in an early chunk
keeps that guess forever, even when a later chunk carries a real
ai-title sidecar record (TitleSource.ORIGIN, confidence 1.0) — confirmed
directly: d6f4b0c3-840b-47b6-bd57-5f1bd6c9c7d4.jsonl contains 490 ai-title
records, yet the live archive shows this session title=native_id
(title_source='unknown'). This is the "551 substantive sessions with zero
human-readable title" defect the bead's own notes call the sharpest instance
of the problem. title_source/title_ref/title_confidence weren't even
part of the merge update={} dict, so provenance could point at stale/wrong
evidence relative to whatever title string won.

Solution

  • polylogue/sources/dispatch.py: added _claude_code_title_rank, ranking a
    chunk's title by title_source/title_confidence using the same
    precedence order the single-pass parser already applies (custom-title >
    ai-title > agent-name > heuristic > unknown/raw-id), with a small
    title_ref-prefix tie-break (_CLAUDE_CODE_TITLE_REF_PRIORITY) so
    ai-title and custom-title — both (ORIGIN, 1.0) — keep the exact
    relative order they have within one chunk.
  • merge_parsed_session_chunks now selects title, title_source,
    title_ref, and title_confidence together as one unit (whichever chunk
    ranks higher), instead of merging title alone with the old
    first-non-UUID-wins rule.
  • Two new regression tests in tests/unit/sources/test_source_laws.py
    (test_merge_parsed_session_chunks_prefers_stronger_title_evidence_over_first_chunk,
    test_merge_parsed_session_chunks_keeps_stronger_earlier_title_over_weaker_later_chunk)
    cover both merge directions.

This does not invent a second/parallel resolution mechanism — it fixes
the one place the existing ladder (polylogue-pbuh/ih67-style precedence) was
silently bypassed.

Verification

devtools test tests/unit/sources/test_source_laws.py \
  tests/unit/storage/test_revision_replay.py \
  tests/unit/sources/test_claude_code_sidecar_evidence.py
  -> 194 passed

devtools verify --quick
  -> exit_code: 0 (ruff format/check, mypy --strict, render all --check,
     layering, closure-matrix, schema-versioning/promotion lab checks)

Pre-push hook re-ran devtools verify --quick on push: exit 0.

AC matrix (bd polylogue-t5lg)

  1. Title derived from authored content via the existing ladder, not a
    parallel mechanism
    — satisfied for the single-pass path by prior work
    (polylogue-pbuh). This PR fixes the one place that mechanism was silently
    discarded: multi-chunk merge for large streamed sessions.
  2. Title provenance recorded (title_source/title_ref) —
    title_source/title_ref/title_confidence already existed on
    sessions (pbuh); this PR fixes them going stale relative to the merged
    title across chunks.
  3. Live re-measure, before/after census — NOT attempted in this PR.
    This is a read-only worktree lane; re-measuring the live archive requires
    an operator-authorized polylogue ops reprocess/reset against
    /realm/db/polylogue, out of this PR's scope. The "before" numbers cited
    above (16,552 total / 14,801 UUID-titled / 273 title_source=origin) were
    measured read-only against the live archive during investigation, not
    mutated by this PR.
  4. Existing rows acquire titles through ordinary reprocess, not a bespoke
    backfill
    — unaffected: this fix only changes parse-time merge behavior;
    an ordinary reprocess re-parses affected raws and picks up the corrected
    merge automatically, no separate script needed.

Anti-vacuity

Reverting _claude_code_title_rank and the four-field title_winner
selection back to the old
existing.title if existing.title != existing.provider_session_id else session.title
(keeping only title in the merge update={}) makes
test_merge_parsed_session_chunks_prefers_stronger_title_evidence_over_first_chunk
fail: it asserts a later ai-title chunk's title wins over an earlier
HEURISTIC chunk's title, which the old rule cannot produce (it always keeps
whichever chunk resolved a non-UUID title first). Production caller:
parse_stream_payload (dispatch.py) is the sole entry point for Claude
Code's multi-GiB streaming ingest path
(pipeline/services/ingest_batch), invoked for every raw Claude Code session
large enough to require chunked parsing — this is not a test-only code path.

Ref polylogue-t5lg

Problem: bd polylogue-t5lg measured 84.6% (10,157/12,001) of Claude Code
sessions titled with a raw UUID, and a live re-measurement found it got
WORSE (89.3%, 14,626/16,374) despite the parser already having a
resolution ladder for ai-title/custom-title/agent-name sidecar records
(bd polylogue-pbuh, single-pass precedence in code_parser.py). Live-archive
spot checks (read-only, /realm/db/polylogue/index.db) confirmed the
single-pass ladder resolves titles correctly when a session is parsed in
one pass, but `merge_parsed_session_chunks` (dispatch.py, the only caller
of Claude Code's memory-bounded multi-GiB streaming path) merged chunk
titles with `existing.title if existing.title != existing.provider_session_id
else session.title` -- "whichever chunk resolved a non-UUID title FIRST
wins, forever". A large/long-lived session (e.g. one sampled at 6,059
messages) that resolves a weak first-human-message HEURISTIC title in an
early chunk permanently keeps that guess even when a later chunk carries
an ai-title sidecar record (TitleSource.ORIGIN, confidence 1.0) -- the
exact "551 substantive sessions with zero human-readable title" defect
this bead's notes call the sharpest instance of the problem.

Solution: add `_claude_code_title_rank` (dispatch.py), ranking a chunk's
title_source/title_confidence identically to code_parser.py's own
single-pass precedence (custom-title > ai-title > agent-name > heuristic
> unknown/raw-id), with a title_ref-prefix tie-break so ai-title and
custom-title -- both TitleSource.ORIGIN/confidence 1.0 -- keep the same
relative order across chunks that they have within one chunk.
`merge_parsed_session_chunks` now moves title/title_source/title_ref/
title_confidence together as one unit selected by this rank, so
provenance never points at different chunk evidence than the title text
it describes (previously only `title` was merged; title_source/title_ref/
title_confidence silently kept whatever the first chunk had).

Verification:
  devtools test tests/unit/sources/test_source_laws.py
    tests/unit/storage/test_revision_replay.py
    tests/unit/sources/test_claude_code_sidecar_evidence.py -> 194 passed
  devtools verify --quick -> exit 0 (ruff format/check, mypy, render all,
    layering, schema-versioning lab checks)

AC matrix (bd polylogue-t5lg):
  AC1 (derive from authored content via ih67's ladder, not a parallel
      mechanism) -- satisfied for the single-pass path by prior work
      (pbuh); this PR fixes the ONE place that mechanism was silently
      discarded (multi-chunk merge for large streamed sessions).
  AC2 (title provenance recorded) -- title_source/title_ref/title_confidence
      already existed on sessions (pbuh); this PR fixes them going stale
      relative to the merged title across chunks.
  AC3 (live re-measure, before/after census) -- NOT attempted in this PR.
      This is a read-only worktree lane; re-measuring the live archive
      requires an operator-authorized `polylogue ops reprocess`/reset
      against /realm/db/polylogue, out of this PR's scope. Before this
      fix: claude-code-session 16,552 total / 14,801 UUID-titled (89.4%),
      title_source=origin only 273 (measured read-only against the live
      archive during investigation, not mutated).
  AC4 (existing rows acquire titles through ordinary reprocess, not a
      bespoke backfill) -- unaffected: this fix changes parse-time
      behavior only; an ordinary reprocess re-parses affected raws and
      picks up the corrected merge automatically.

Anti-vacuity: reverting `_claude_code_title_rank`/the four-field
`title_winner` update back to the old
`existing.title if existing.title != existing.provider_session_id else
session.title` line (keeping only `title` in the merge) makes both new
regression tests fail --
test_merge_parsed_session_chunks_prefers_stronger_title_evidence_over_first_chunk
asserts the later ai-title chunk wins over an earlier heuristic chunk.
Production caller: `parse_stream_payload` (dispatch.py) is the sole
entrypoint for Claude Code's multi-GiB streaming ingest path
(pipeline/services/ingest_batch), invoked for every raw Claude Code
session large enough to require chunked parsing.

Ref polylogue-t5lg

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 1, 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: 49 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: df3d582f-f9a4-4c65-86ae-074b8c1369f5

📥 Commits

Reviewing files that changed from the base of the PR and between 5d449f9 and 196615c.

📒 Files selected for processing (2)
  • polylogue/sources/dispatch.py
  • tests/unit/sources/test_source_laws.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 added a commit that referenced this pull request Aug 1, 2026
@Sinity
Sinity merged commit e58b06f into master Aug 1, 2026
3 checks passed
@Sinity
Sinity deleted the fix/sources/claude-code-title-chunk-merge-precedence branch August 1, 2026 11:54
Sinity added a commit that referenced this pull request Aug 1, 2026
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