Repository navigation
fix(storage): route session native_id through single normalization helper - #3450
Conversation
…lper Problem: an invariants audit (polylogue-lyr2) found _write_session bound a session's native_id RAW into the sessions INSERT while session_id (used for cache keys, lineage lookups, the FK-failure log message, and everything else downstream in the same write) was computed via core.identity_law.session_id, which strips whitespace. Same logical session, two spellings, one row -- the exact incident class that produced ab5bad1f's lost 10-hour rebuild, which was fixed at message level via _stored_message_native_id + a property test but never given a session-level sibling. session_links.dst_native_id (parent references written by _write_session_link) had the same raw-vs-stripped mismatch against the sessions.native_id it must exact-match to resolve. Solution: add _stored_session_native_id (archive_tiers/write.py), mirroring _stored_message_native_id -- the single source of truth every session identity call site now routes through, applied once right after provider_session_id is read so session_id, the sessions INSERT bind, and _resolve_session_graph's native_id all see the same value. _write_session_link normalizes dst_native_id the same way before writing a parent-session reference, since the resolver matches it against sessions.native_id by exact string equality. Property test tests/property/test_session_identity_normalization.py mirrors test_message_identity_normalization.py: sweeps pathological native_id shapes (empty, whitespace-only, padded, mixed) and asserts the DB-generated sessions.session_id matches identity_law.session_id, plus the ValueError path for unidentifiable (whitespace-only) native ids. Rebuild impact: verified 0 padded/whitespace native_ids exist in the live archive today (see index.db query in the PR description), so this changes nothing a rebuild would write for current data -- it closes a latent divergence that only a future/edge-case provider export would trigger. No SEMANTIC_REPARSE delta needed: output is byte-identical for all live rows. Verification: devtools test tests/property/test_session_identity_normalization.py tests/unit/storage/test_archive_tiers_write.py tests/unit/storage/test_lineage_normalization.py tests/property/test_message_identity_normalization.py -- 106 passed. Co-Authored-By: Claude <[email protected]>
…logue-t83e Problem: polylogue-t83e (P1) flagged 6 Drive-cache Claude Code transcripts colliding with local raw session identities, but the prior hs3y content-shape audit only confirmed the bytes were genuinely Claude-Code-shaped -- it never cross-checked those native_ids against local raw_sessions for actual session_id collisions, so the collision claim was unverified against the live archive. What changed: verified against /realm/db/polylogue (index.db/source.db, read-only) -- confirmed 6 real collisions via SQL join, confirmed the drive-cache raw currently wins all 6, and byte-diffed one pair in the blob store: the drive copy is an exact prefix of the local file (same conversation, stale/truncated snapshot), with a concrete live consequence (session title regressed to a generic "continue" fallback). Recorded the root cause (a freshness-tie gap shared by three duplicate skip-stale-replace implementations), why a full fix isn't safe to land without deeper acquisition-provenance plumbing verification, and a scoped recommendation for the next implementer. Left the bead open (not closed) -- this is diagnosis, not a closing fix. Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 31 seconds 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 (3)
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 |
Summary
Fixes polylogue-lyr2 (session identity computed two ways) with a single
source-of-truth helper mirroring the message-level
ab5bad1ffix. Alsorecords verified live-archive forensics on polylogue-t83e (Drive-cache
Claude Code duplicates colliding with local session identity) — diagnosed,
not closed, since the correct fix needs acquisition-provenance plumbing
verification this PR's effort budget can't safely cover.
Problem
polylogue-lyr2: an invariants audit found
_write_session(
archive_tiers/write.py) bound a session'snative_idRAW into thesessionsINSERT, whilesession_id(used for cache keys, lineage lookups,the FK-failure log message, and everything else downstream in the same
write) was computed via
core.identity_law.session_id, which stripswhitespace. Same logical session, two spellings, one row — the exact
incident class that produced
ab5bad1f's lost 10-hour rebuild, fixed atmessage level via
_stored_message_native_id+ a property test, but nevergiven a session-level sibling.
session_links.dst_native_id(parentreferences written by
_write_session_link) had the same raw-vs-strippedmismatch against the
sessions.native_idit must exact-match to resolvelineage edges.
polylogue-t83e: a prior audit (hs3y, PR #3436) confirmed 12
~/.local/share/polylogue/drive-cache/gemini/*.jsonl.txt.jsonrows aregenuinely Claude-Code-shaped content (not a misclassification) and left
them alone. It never cross-checked those native_ids against local raws for
actual
session_idcollisions. This session verified, against the livearchive (read-only): 6 of those native_ids collide with genuinely-local
~/.claude/projects/...raws — confirmed by SQL join, not inference —and in all 6 the drive-cache copy currently wins the row. Byte-diffing one
pair in the blob store shows the drive copy is an exact byte prefix of the
local file (same conversation, stale/truncated snapshot, not a distinct
identity) with a concrete live consequence:
sessions.titleforclaude-code-session:0213d48f-5b7a-4241-b77a-eb714672dc3bcurrently readsthe generic fallback
"continue"instead of the real summary title, becausethe stale drive copy won a freshness tie.
Solution
_stored_session_native_id(polylogue/storage/sqlite/archive_tiers/write.py),mirroring
_stored_message_native_id— the single source of truth everysession-identity call site now routes through. Applied once right after
provider_session_idis read, sosession_id, thesessionsINSERT bind,and
_resolve_session_graph'snative_idargument all see the same value._write_session_linknow normalizesdst_native_id(strip + surrogatesubstitution) before writing a parent-session reference, matching how the
resolver (
_resolve_outbound_session_links) exact-matches it againstsessions.native_id.tests/property/test_session_identity_normalization.pymirrors
test_message_identity_normalization.py: sweeps pathologicalprovider_session_idshapes (empty, whitespace-only, padded, mixed)through the real write path and asserts the DB-generated
sessions.session_idmatchesidentity_law.session_id, plus theValueErrorpath for unidentifiable (whitespace-only) native ids.exact session/raw ids, byte-diff result, root-cause trace through the three
duplicate skip-stale-replace implementations in
write.py,pipeline/services/ingest_batch/_core.py, andstorage/sqlite/archive_tiers/revision_governance.py, and why a detectionfix needs
fallback_provider/DRIVE_LIKE_PROVIDERS-scoped plumbing Icould not safely verify this session) as a bd comment plus a
chore(beads)commit. Bead left open, not closed.Rebuild impact (explicit, per both beads)
sessions.native_idand 0 padded
session_links.dst_native_idrows exist in the livearchive today (
sqlite3 "file:/realm/db/polylogue/index.db?mode=ro").This PR changes nothing a rebuild would write for current data — it closes
a latent divergence that only a future/pathological provider export would
trigger. No
SEMANTIC_REPARSEdelta needed: output is byte-identicalfor every live row.
raw for the 6 known collisions (and any undiscovered siblings) and picks
whichever raw its replay order processes last for that
native_id—exactly today's live, order-dependent behavior, now precisely diagnosed
rather than merely suspected. No
SEMANTIC_REPARSEdeclaration appliessince no detection/parsing code changed here.
Verification
Live-archive counts (read-only,
/realm/db/polylogue/{index,source}.db):Full evidence trail (exact commands, byte-diff output, root-cause trace) is
recorded on
polylogue-t83e's bd comment for the next implementer.Ref polylogue-lyr2, Ref polylogue-t83e