Repository navigation
refactor(storage): extract MATERIALIZATION_COLUMNS_SQL for insight DDLs - #1380
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 |
0b73301 to
5f8e924
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]>
Every session-insight DDL file (`schema_ddl_insight_profiles`, `schema_ddl_insight_timelines`, `schema_ddl_insight_aggregates`) repeated the same materializer-lifecycle columns (`materializer_version`, `materialized_at`, `source_updated_at`, optional `source_sort_key`, `input_high_water_mark`, `input_high_water_mark_source`, `input_row_count`) by hand on every CREATE TABLE. Drift between copies would silently weaken the lifecycle contract. Extract a `schema_ddl_insight_common` module exposing `MATERIALIZATION_COLUMNS_SQL` (with `source_sort_key`), `MATERIALIZATION_COLUMNS_SQL_NO_SORT_KEY` (for `work_threads`, which has no per-row sort key), and a `materialization_columns_sql(...)` composer. Each insight DDL now splices the shared fragment between its domain columns. Rendered DDL strings are byte-identical before vs after across all three files (verified by SHA + full string comparison). Drift noted but preserved: `work_threads` omits `source_sort_key`; `provider_name` and `canonical_session_date` placements vary across tables (sometimes before lifecycle, sometimes mid-table) and so are intentionally NOT folded into the shared block — folding them would change column order on disk.
5f8e924 to
9f42b0b
Compare
Summary
Every session-insight table repeated the same 7-9 materializer-lifecycle columns by hand. Extract into a single composable SQL fragment in
schema_ddl_insight_common.py; migrate all six insight tables across three DDL files. Rendered SQL is byte-identical (SHA-256 verified per file).Problem
Six insight tables (
session_profiles,session_work_events,session_phases,session_tag_rollups,day_session_summaries, plus the aggregates trio) each spelled out the lifecycle column set —materializer_version,materialized_at,source_updated_at,source_sort_key,input_high_water_mark,input_high_water_mark_source,input_row_count— in theirCREATE TABLEstatements. Any drift between sites would let one materializer silently skip a lifecycle column on a fresh schema; nothing structural prevented that.Solution
polylogue/storage/sqlite/schema_ddl_insight_common.pyexposes:MATERIALIZATION_COLUMNS_SQL— the canonical 7-column block (withsource_sort_key).MATERIALIZATION_COLUMNS_SQL_NO_SORT_KEY— variant forwork_threads, the lone insight table that legitimately omitssource_sort_key(threads have no single source row to sort by).materialization_columns_sql(*, with_source_sort_key=True)for callers who want the variant inline.schema_ddl_insight_profiles.py(-8 LoC),schema_ddl_insight_timelines.py(-13 LoC),schema_ddl_insight_aggregates.py(-19 LoC).provider_nameandcanonical_session_dateintentionally stay per-table:provider_nameis part of the composite PK insession_tag_rollups/day_session_summariesand precedes the lifecycle block (column ordering matters on disk).canonical_session_dateplacement varies between tables and is absent from aggregates — it's actually domain, not lifecycle.Verification
CREATE TABLEstrings before and after via SHA-256:cc284a02…,587c20ba…,5b9ebcde…— identical pre- and post-ruff format.nix develop --command pytest tests/unit/storage -q→ no regressions (2 pre-existing failures on the parity-adapter tests inherited from master baseline, unrelated).devtools verify-topologyclean (helper module + LoC counts updated).Drift findings worth follow-up
(Documented in the commit message for archaeology; not addressed in this PR.)
work_threadsis the lone lifecycle-bearing table missingsource_sort_key. Either intentional (no sortable source row) or an oversight. Preserved as-is via the_NO_SORT_KEYvariant.provider_nameplacement varies between composite-PK and FK-keyed tables. Not a bug — composite PKs cluster the key columns together — but it's whyprovider_namecan't be folded into the shared block.canonical_session_datewas originally on the brief as a candidate lifecycle column. Reality: it's domain-specific (placement varies, absent from aggregates). Excluded for the right reason.