fix(lcm): session reads hide superseded replay copies (t_9cdad21b) - #1053
Conversation
The replay-block dedup migration soft-hides NON-canonical replay copies (superseded_by set; the higher store_ids, i.e. the session tail). Only search/grep filtered them. Every per-session read - get_session_tail, get_session_count, get_session_token_total, get_session_messages(_after), get_range, load_session_page/count, load_session_window - returned them, so re-bind reconcile matched incoming replays against hidden rows (the new test re-appends the whole replay without this fix) and counts/token totals kept counting ~899k hidden rows on the snapshot. - store: _VISIBLE_MESSAGE_CLAUSE on all session-scoped reads. Raw by design: get()/get_many by store_id, whole-corpus coverage scan, delete_session_messages, get_source_stats, scan_session_retention_stats. - db_bootstrap: partial index idx_msg_session_visible(session_id, store_id) WHERE superseded_by IS NULL, existence-checked first so a store open takes no write lock once built. Without it COUNT on the largest live session (63,392 rows) went 2 ms -> 75 ms. - test: store reads, reconcile re-bind over a hidden block, index plan, and an AST detector that fails on any new per-session read in store.py lacking the clause (allowlist needs a reason).
|
🤖 merged-by: apollo · lane: kanban-merge-pass · gate: BYPASS: FleetReview paused by Ace 2026-09-22 (state/fleetreview-pause marker present) · why: t_9cdad21b: lcm store: get_session_tail / get_session_count / get_session_messages(_after) d; Argus off card review (Ace 13:08), CI green |
FleetReviewReview: post-merge · head Post-merge review ( profile: light (rule: default light: lines 227<800, files 3<1000000, hunks 10<1000000, no hot path) · round 0 · members: B-assert-ctx, C-assert-xhigh, F, G · families: anthropic,openai,xai Confidence: 3/5 Findings
FleetReview provenance · models: B=gpt-6-sol, C=claude-code-opus-5-5, D=grok-4.6, F=gpt-6-sol · cost: $3.14 · duration: 5m 30s · rounds: 1 · files examined: 3 |
Kanban t_9cdad21b (derived from t_f97bce35). Must land before/with the live replay-dedup apply.
Per-session store reads (tail/count/token total/messages/after/range/load page+window) now filter
superseded_by IS NULL, backed by a partial indexidx_msg_session_visible. Measured on the live store: COUNT on the largest session (63,392 rows) would go 2 ms -> 75 ms without the index. Index build on the 1.35 GB argus copy took 0.25 s; the 12 GB main DB should be a one-time few seconds at first open.raw_session_count in reconcile means 'before ignore-pattern filtering', not 'including hidden copies', so it takes the visible count.
Tests: tests/context_engine/test_lcm_superseded_session_reads.py (6; 5 fail on main, including the reconcile re-bind test which re-appends the replay). Local narrow run: that file + test_dup_on_replay_fix + test_ingest_timestamp_fidelity, 35 pass. CI is the gate.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.