Repository navigation
perf: avoid full-session active-leaf churn - #2394
Conversation
Problem: live append attempts on a giant Codex session read only a tiny tail but still spent several seconds in the append parse/write window. Static tracing showed the append writer dirtied every message row while moving the active leaf, which also fired FTS update triggers for the whole session.\n\nWhat changed: constrain the merge-append active-leaf reset to rows that are currently active leaves, preserving stale-multiple-leaf cleanup while avoiding proportional rewrites. Add a regression that appending to a large session keeps active-leaf semantics and bounds SQLite changes.\n\nVerification: devtools test tests/unit/storage/test_archive_tiers_write.py -k 'merge_append_clears_only_existing_active_leaf or provider_usage_events_append_preserves_prior_history'; devtools test tests/unit/sources/test_live_watcher.py -k 'codex_append_uses_existing_session_identity_when_tail_lacks_session_meta or live_append_merges_tail_visible_through_public_archive_read'; devtools verify --quick.\n\nRef #2391
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe merge-append SQLite write path still clears active-leaf flags for a session, and a new regression test checks that appending into a large existing session leaves one active leaf, adds one message, and keeps SQLite changes low. ChangesMerge-append active leaf update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
Tightens the merge-append archive writer so appending to a live session clears only rows that are currently marked as active leaves, then appends the new tail. This keeps the active-leaf invariant while avoiding full-session message rewrites for giant Codex/Claude sessions.
Problem
Live
polyloguedevidence for a 137 MB active Codex JSONL showed append batches reading only KB-sized tails while still spending about 5.4-5.8 seconds inside the append parse/write window. The append path already avoided full message replacement, but it still ranUPDATE messages SET is_active_leaf = 0 WHERE session_id = ?, which dirtied every prior message row. Because message updates fire the FTS update trigger, moving a single active leaf could churn FTS rows for the entire giant session.Solution
The append writer now narrows the reset predicate to
session_id = ? AND is_active_leaf != 0. That preserves cleanup of stale multiple-active-leaf states but keeps normal appends proportional to the number of current active leaves plus the appended messages.A regression test builds a 200-message Codex session, appends one message through
merge_append=True, and asserts the active leaf moves, total messages remain present, and SQLite changes stay bounded rather than proportional to the existing session size.Verification
Passed:
devtools test tests/unit/storage/test_archive_tiers_write.py -k 'merge_append_clears_only_existing_active_leaf or provider_usage_events_append_preserves_prior_history'— 2 passed.devtools test tests/unit/sources/test_live_watcher.py -k 'codex_append_uses_existing_session_identity_when_tail_lacks_session_meta or live_append_merges_tail_visible_through_public_archive_read'— 2 passed.devtools verify --quick— passed before commit.devtools verify --quick— passed for commit1cda48f18.Default
devtools verifystatic checks passed, then pytest-testmon selected 2429 tests and failed 26 unrelated contract/snapshot tests. The failures were in origin enum expectations, CLI/query/action snapshots, artifact graph/scenario coverage expectations, raw-materialization/check health contracts, MCP tool classification, and product workflow guard text. None exercised the changed archive append predicate or live append workflow.Ref #2391
Summary by CodeRabbit