Repository navigation
perf(storage): stop materializing action_pairs text copies - #3159
Conversation
Problem: dbstat on the live rebuild generation showed action_pairs at
4.1GB for 868,522 rows (~4.7KB/row) -- every tool interaction existed
~3x on disk (blocks.text/tool_input, action_pairs.output_text/tool_input,
FTS). The ~4.7KB rows live in SQLite overflow-page chains, so a
per-session `DELETE FROM action_pairs WHERE session_id=?` pays dozens of
scattered page reads per row, turning a whale session replace into hours
of random IO (confirmed via strace: 27K distinct pread64/s, offsets
concentrated in the action_pairs tail, zero sample overlap 30s apart).
Solution: action_pairs now keeps only join/rank/outcome columns
(tool_use_block_id, tool_result_block_id, session_id, message_id,
tool_id, use_rank, tool_name, semantic_type, tool_command, tool_path,
is_error, exit_code); tool_input/output_text are dropped. The `actions`
VIEW is rewritten to re-join `blocks` by tool_use_block_id (INNER,
NOT NULL FK) and tool_result_block_id (LEFT, nullable) at read time, so
every reader keeps byte-identical payloads with zero caller change.
Consumer audit (rg across storage/repository, insights, daemon, MCP,
CLI, api, devtools) found every reader goes through the `actions` view;
none touches action_pairs.output_text/tool_input directly except the
DDL/refresh/lifecycle machinery this PR edits. delegation_facts reads
through the view transparently too (verified unchanged).
Index schema version 40 -> 41 (derived tier, no migration chain per the
schema regime); added an IndexDeltaDeclaration(version=41,
classes=(CACHE_REMOVAL, VIEW_ONLY)) since the transition is copy-forward
safe (no parser semantics involved). Noted the bump on polylogue-bo9n and
polylogue-v6i3 (their own decisions remain open, not implemented here).
Discovered pre-existing gaps while auditing, filed separately rather than
folding into this PR's blast radius: polylogue-5h5y (index schema v40
never got a declared delta class -- confirmed independent of this change
by reverting and re-running the lint) and polylogue-m8nj (delegation_facts
still materializes its own, smaller, instruction_payload/artifact_text
copy for the subagent-dispatch cohort).
Verification:
- devtools test on directly-touched + consumer test files (action_pairs
refresh SQL, actions/delegations views, planner-stats plan shape,
archive_verification, schema policy contracts, tool_usage insights,
delegation query units) -- all green except 4 pre-existing failures in
test_tool_usage.py/test_delegations_view.py ("unknown database
user_tier" / "unable to open database file"), confirmed identical on
unmodified HEAD.
- devtools verify --quick: exit 0.
- devtools render all --check: exit 0, no "out of sync".
- devtools lab policy docs-drift: zero unhandled drift.
- devtools lab policy schema-versioning: 1 pre-existing failure (v40 gap,
polylogue-5h5y), no new failures from v41.
- Byte-equivalence proof: tests/unit/storage/test_archive_tiers_ddl.py
already pins exact output_text/tool_command/is_error/exit_code values
through the `actions` view across matched/unmatched/error/reemitted-
tool_id/variant-tie/empty-string scenarios; all pass unchanged against
the new join-based view. Added
test_action_pairs_does_not_materialize_text_copies to lock the trimmed
column set in place.
Ref polylogue-2i2w
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: 4 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 Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 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
action_pairsstops storing copies oftool_input/output_text; it now keeps only join/rank/outcome columns, and theactionsVIEW re-joinsblocksfor the text at read time so every reader keeps byte-identical payloads.Problem
dbstat on the live rebuild generation showed
action_pairsat 4.1GB for 868,522 rows (~4.7KB/row) — every tool interaction existed ~3x on disk (blocks.text/blocks.tool_input,action_pairs.output_text/action_pairs.tool_input, plus FTS). The ~4.7KB rows live in SQLite overflow-page chains, so a per-sessionDELETE FROM action_pairs WHERE session_id=?pays dozens of scattered page reads per row. strace on a live whale-session delete confirmed the mechanism: 27K distinctpread64/s concentrated in theaction_pairstail with zero sample overlap 30s apart — pure forward progress through a colossal random-IO workload, turning a whale session replace into hours of IO. This is tracked aspolylogue-2i2w.Solution
action_pairs(polylogue/storage/sqlite/archive_tiers/index.py) dropstool_input/output_text; surviving columns:tool_use_block_id,tool_result_block_id,session_id,message_id,tool_id,use_rank,tool_name,semantic_type,tool_command,tool_path,is_error,exit_code.action_pairs_refresh_sql(polylogue/storage/sqlite/action_pairs.py) no longer selects/inserts the dropped columns.actionsVIEW is rewritten to INNER JOINblocksbytool_use_block_id(NOT NULL FK, cascade) and LEFT JOINblocksbytool_result_block_id(nullable, SET NULL) to re-servetool_input/output_textat read time — same column names/order as before, so every consumer is unaffected.rgacrossstorage/repository,insights,daemon,mcp,cli,api,devtools): every reader of pair text goes through theactionsview. None readsaction_pairs.output_text/tool_inputdirectly except the DDL/refresh/lifecycle machinery this PR edits (action_pairs.py,write.py'srefresh_action_pairscalls,schema_bootstrap.py's stat1 seed rows,archive_verification.py's planner-stats table-name list).delegation_facts_source/delegation_facts(subagent-dispatch cohort) reads through the view too and is transparently unaffected (verified via its own tests, unchanged).docs/internals.md§ Schema Versioning Model). AddedIndexDeltaDeclaration(version=41, classes=(CACHE_REMOVAL, VIEW_ONLY))topolylogue/storage/sqlite/lifecycle.pysince the transition is copy-forward safe (no parser semantics involved). Added the matchingdocs/internals.mdchangelog entry.polylogue-bo9nandpolylogue-v6i3per the schema-regime batching convention — their own decisions (session_events aggregation, FTS bulk-mode skip) remain open and are not implemented here.Discovered, filed separately (not fixed here, to keep blast radius narrow)
polylogue-5h5y: index schema v40 (query_unit_frame_state, PR feat(query): bind query_units continuations to the archive epoch #3068) never got a declared delta class inlifecycle.py—devtools lab policy schema-versioningalready failed before this PR (confirmed by reverting my changes to HEAD and re-running the lint: identicalmissing: [40]failure).polylogue-m8nj:delegation_factsstill materializes its own (smaller, subagent-dispatch-only) copy ofinstruction_payload/artifact_text.Verification
devtools test tests/unit/sources/test_codex_event_stream_contract.py tests/unit/storage/test_archive_tiers_ddl.py tests/unit/storage/test_archive_tiers_write.py tests/unit/storage/test_archive_tiers_assertions.py tests/unit/storage/test_planner_statistics_seed.py tests/unit/maintenance/test_archive_verification.py tests/unit/storage/test_schema_policy_contracts.py tests/unit/insights/test_tool_usage.py tests/unit/storage/test_delegations_view.py tests/unit/pipeline/test_delegation_provider_fixtures.py tests/unit/storage/test_schema_safety.py→ all green except 4 pre-existing failures intest_tool_usage.py/test_delegations_view.py(unknown database user_tier/unable to open database file) — confirmed identical failure set on unmodified HEAD (reverted files, re-ran, same 4 failures), unrelated to this change.devtools verify --quick→ exit 0 (ran automatically again via the pre-push hook).devtools render all --check→ exit 0, noout of sync.devtools lab policy docs-drift→ "zero unhandled drift".devtools lab policy schema-versioning→ 1 pre-existing failure (v40 gap, tracked aspolylogue-5h5y), no new failures introduced by v41.tests/unit/storage/test_archive_tiers_ddl.pyalready pins exactoutput_text/tool_command/is_error/exit_codevalues through theactionsview across matched/unmatched/error/reemitted-tool_id/variant-tie/empty-string-tool_id scenarios — all pass unchanged against the new join-based view (this is the golden-fixture proof: values were pinned before this change and are reproduced by the rewritten view).test_agent_action_and_delegation_views_are_indexed_projections(assertsUSING INDEXin theactionsquery plan, noWINDOW/WITHin the view SQL) also passes unchanged. Addedtest_action_pairs_does_not_materialize_text_copiesto lock the trimmed column set in place as a regression guard.action_pairsshould collapse from ~4.1GB to a small fraction of that (likely low hundreds of MB, in-page, no overflow chains) on a real rebuild — most of the measured 4.1GB is expected to be reclaimed fromindex.db's ~19.6GB total. Confirming this needs a realpolylogue ops reset --index && polylogued run+ dbstat pass, which is the coordinator's call.Ref polylogue-2i2w