Repository navigation
fix(sources): keep strongest title evidence across Claude Code chunks - #3506
Conversation
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]>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
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 |
…t-lane beads Co-Authored-By: Claude <[email protected]>
…th follow-up Co-Authored-By: Claude <[email protected]>
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, wheneverthe 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 gotworse, not better, despite polylogue-pbuh (closed, merged) already adding
a title-resolution ladder to
code_parser.py's single-pass parser (ai-titleSpot-checking several
ai-title-bearing raw session files against the livearchive confirmed the single-pass ladder works correctly when a session is
parsed in one pass (e.g.
35548562-...correctly resolved totitle_source='origin',title='Review lanes performance wave documentation'). Butpolylogue/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:
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.HEURISTICguess in an early chunkkeeps that guess forever, even when a later chunk carries a real
ai-titlesidecar record (TitleSource.ORIGIN, confidence 1.0) — confirmeddirectly:
d6f4b0c3-840b-47b6-bd57-5f1bd6c9c7d4.jsonlcontains 490ai-titlerecords, yet the live archive shows this session
title=native_id(
title_source='unknown'). This is the "551 substantive sessions with zerohuman-readable title" defect the bead's own notes call the sharpest instance
of the problem.
title_source/title_ref/title_confidenceweren't evenpart of the merge
update={}dict, so provenance could point at stale/wrongevidence relative to whatever
titlestring won.Solution
polylogue/sources/dispatch.py: added_claude_code_title_rank, ranking achunk's title by
title_source/title_confidenceusing the sameprecedence 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) soai-title and custom-title — both
(ORIGIN, 1.0)— keep the exactrelative order they have within one chunk.
merge_parsed_session_chunksnow selectstitle,title_source,title_ref, andtitle_confidencetogether as one unit (whichever chunkranks higher), instead of merging
titlealone with the oldfirst-non-UUID-wins rule.
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
Pre-push hook re-ran
devtools verify --quickon push: exit 0.AC matrix (bd polylogue-t5lg)
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.
title_source/title_ref) —title_source/title_ref/title_confidencealready existed onsessions(pbuh); this PR fixes them going stale relative to the mergedtitleacross chunks.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 citedabove (16,552 total / 14,801 UUID-titled / 273
title_source=origin) weremeasured read-only against the live archive during investigation, not
mutated by this PR.
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_rankand the four-fieldtitle_winnerselection back to the old
existing.title if existing.title != existing.provider_session_id else session.title(keeping only
titlein the mergeupdate={}) makestest_merge_parsed_session_chunks_prefers_stronger_title_evidence_over_first_chunkfail: it asserts a later
ai-titlechunk's title wins over an earlierHEURISTICchunk's title, which the old rule cannot produce (it always keepswhichever chunk resolved a non-UUID title first). Production caller:
parse_stream_payload(dispatch.py) is the sole entry point for ClaudeCode's multi-GiB streaming ingest path
(
pipeline/services/ingest_batch), invoked for every raw Claude Code sessionlarge enough to require chunked parsing — this is not a test-only code path.
Ref polylogue-t5lg