Repository navigation
refactor(storage): consolidate session-insight writers onto replace_insight_rows - #1379
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ 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 |
3d8d4b5 to
77c8fab
Compare
…#1384) ## Summary PR #1370 (typed ranked-result envelope) changed `polylogue list --format json` for search-mode queries to emit `{"hits": [...], "limit": N, "next_cursor": ...}` rather than a bare JSON array. The CLI parity adapter at `tests/infra/surfaces.py:307` still expected a bare array and asserted `not isinstance(parsed, list)`, causing both `test_search_unique_token_parity` and `test_search_shared_token_parity` to fail on every search-mode case on master. ## Solution When the parsed CLI output is a dict carrying a `hits` array (the typed envelope shape), peel the `hits` and continue with the existing per-row id extraction. The list-mode and search-hit-mode shapes still work unchanged — they hit the same row loop directly. Updated the inline doc to enumerate all three shapes the adapter now handles. ## Verification - `nix develop --command pytest tests/unit/storage/test_surface_parity_adapters.py -q` → **10 passed** (was 2 failures on master). - No production code touched; test-infra only. ## Scope Single-file, test-infra-only change. Should land before #1379 / #1380 / #1382 (or alongside) so those PRs' CI runs are unmasked by this pre-existing failure. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Extract the DELETE-then-INSERT shape shared by every replace_*_bulk function in polylogue/storage/sqlite/queries/ into a single helper. Each call site builds its own column list and per-record extractor (needed because session_*_insert_columns depend on a runtime has_legacy_payload probe) and delegates the boilerplate. The helper produces byte-identical SQL to the previous handwritten sites: one DELETE ... WHERE id_col IN (?, ?, ...) when ids are present, one build_insert_sql(table, columns) INSERT via executemany when records are present, and a commit gated on transaction_depth == 0. Mirrors lynchpin/substrate/_helpers.py::promote_rows, adjusted for aiosqlite and polylogue's per-call dynamic column lists. Co-Authored-By: Claude <[email protected]>
…ight_rows
Phase 2 of the polylogue symmetry sweep. Commit 9474f322 added the
shared replace_insight_rows helper; this commit migrates the three
call sites that fit its shape:
- session_insight_profile_writes.py:replace_session_profiles_bulk
- session_insight_timeline_writes.py:replace_session_work_events_bulk
- session_insight_timeline_writes.py:replace_session_phases_bulk
Each loses ~14 LoC of DELETE-then-executemany scaffolding; SQL output
is byte-identical. The has_legacy_payload column-discovery short-circuits
on empty input.
Sites NOT migrated, with reason:
- session_insight_summary_queries.py {replace_session_tag_rollup_rows,
replace_day_session_summaries} use a 2-column composite WHERE
(provider_name = ? AND day = ?), not a single-column IN list.
Generalising replace_insight_rows for 2 sites at the cost of API
surface isn't worth it. Skip; revisit if a third composite site
appears.
The architectural read estimated 5 collapsible sites; reality was 3 +
2 different-shape. Truth-checking the audit pays off.
Verification:
- nix develop --command pytest tests/unit/storage -q
→ 760 passed; 3 pre-existing failures (verified on master via stash).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
77c8fab to
336b230
Compare
Summary
replace_insight_rowshelper inpolylogue/storage/sqlite/queries/_bulk_replace.py— the canonical DELETE-WHERE-id-IN + executemany INSERT pattern, modeled on lynchpin'spromote_rows.replace_session_tag_rollup_rows,replace_day_session_summaries) stay handwritten — see Solution.Problem
Three
replace_*_bulkfunctions inqueries/session_insight_*_writes.pyeach spelled out the same DELETE-then-INSERT scaffold by hand: build placeholders for anIN (?, ?, …)clause, run the DELETE, look uphas_legacy_payloadviaPRAGMA table_info, build the INSERT SQL viabuild_insert_sql,executemany, commit whentransaction_depth == 0. The drift surface between these copies was the lifecycle contract itself — any of them could quietly skip the commit, skip the DELETE-empty guard, or miscount placeholders without the others noticing.Solution
polylogue/storage/sqlite/queries/_bulk_replace.pyexposesreplace_insight_rows(conn, *, table, id_column, id_values, columns, records, extractor, transaction_depth). SQL output is byte-identical to the hand-rolled originals.replace_session_profiles_bulk,replace_session_work_events_bulk,replace_session_phases_bulknow computehas_legacy_payloadonce and delegate. Each loses ~14 LoC of scaffolding.id_column+id_valuesforWHERE … IN (?, ?, …). Sites with a different predicate shape (replace_session_tag_rollup_rowsandreplace_day_session_summariesuse compositeprovider_name = ? AND day/bucket_day = ?) are intentionally not migrated — generalising the helper's API for 2 sites at the cost of clarity for the 3 that already fit isn't worth it. Revisit if a 3rd composite-WHERE writer appears.Verification
nix develop --command pytest tests/unit/storage -q→760 passedplus the dedicatedtests/unit/storage/test_bulk_replace.py(18 cases covering empty input, single, multi-record, idempotent re-insert, transaction-depth commit behavior).test_no_unaudited_string_interpolated_sql,test_search_unique_token_parity,test_search_shared_token_parity. Of these,test_no_unaudited_string_interpolated_sqlactually now passes on this branch because the migration replaced inline f-string DELETE/INSERT SQL with the helper's audited template — accidental bonus fix.devtools verify-topologyclean (helper module added to topology-target.yaml, migrated files' LoC counts updated).Files
polylogue/storage/sqlite/queries/_bulk_replace.py(+66, new)tests/unit/storage/test_bulk_replace.py(+229, new)polylogue/storage/sqlite/queries/session_insight_profile_writes.py(-9 net)polylogue/storage/sqlite/queries/session_insight_timeline_writes.py(-18 net)docs/plans/topology-target.yaml(+ entry for_bulk_replace.py, LoC counts updated)