Skip to content

fix(storage): drop price_catalogs and session_model_usage pricing FK columns - #3696

Merged
Sinity merged 3 commits into
masterfrom
feature/schema/drop-price-catalogs-dead-columns
Aug 3, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/schema/drop-price-catalogs-dead-columns

Conversation

@Sinity

@Sinity Sinity commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

Drops price_catalogs (a whole table) and session_model_usage.priced_with/priced_at_ms (plus the FK and CHECK-half that referenced them) as dead weight: polylogue-v2mg kept price_catalogs alive on a justification that a 2026-07-31 shipped-but-dead audit measured false in all three named particulars, and this PR re-verified those particulars against current source before acting and removed the dead code, not just the label.

Problem

polylogue-v2mg (closed) dropped model_prices and session_reported_costs as zero-consumer tables but kept price_catalogs, with this justification quoted verbatim in index_convergence.py:

"The sibling price_catalogs table genuinely is read (session_model_usage.priced_with FK, active_price_catalog_id) and is kept."

polylogue-resk measured all three particulars false:

  1. session_model_usage.priced_with — zero production SELECTs. Every non-test reference was an INSERT/UPDATE/NULL-clear in write.py or the DDL FK line.
  2. session_model_usage.priced_at_ms — same shape, write-only.
  3. active_price_catalog_id — its only non-test caller was pricing_seed.py itself (a seeded-already check, not a genuine read).

Live data: of 18,655 session_model_usage rows, 10,222 had priced_with set with exactly 1 distinct value. Actual pricing resolution goes through the in-process polylogue.archive.semantic.pricing.PRICING dict — the same defect v2mg was closing for model_prices.

I re-verified all three particulars against current source (not just trusting the bead) before acting; nothing had drifted true since the finding.

One correction to the audit itself: its side-note that "session_profiles.priced_with/priced_at_ms are write-only too" does not hold. Those are a different, unrelated pair of columns — no FK to price_catalogs, sourced from cost_compute.py's _PRICE_SNAPSHOT_VERSION rather than pricing_seed.py — with a real production reader: daemon/http.py's _profile_panel_payload serves them in the session-insights HTTP reader panel via hydrate_session_profile. Those columns are left untouched; this PR documents the distinction at the session_model_usage DDL comment and in the benign-DDL registry entry so a future audit doesn't re-conflate the two.

Solution

index.db is the rebuildable derived tier, so this uses the two mechanisms the repo already has for derived-tier changes:

  • price_catalogs drops via the index-tier same-version benign-DDL registry (index_convergence.py), the same mechanism v2mg used for model_prices/session_reported_costs — a whole-table DROP TABLE IF EXISTS, idempotent, no version bump needed.
  • session_model_usage.priced_with/priced_at_ms and the CHECK half that referenced priced_with drop via a new INDEX_SCHEMA_VERSION v61, CONSTRAINT_ONLY delta (lifecycle.py) using the REPLACE_TABLE fast-forward operation — a dead-column-removal copy-forward in the same shape as the existing v33/v36/v38/v41/v44 precedents (existing rows copy-forward on every surviving column, no raw reparse).

pricing_seed.py (seed_price_catalog, active_price_catalog_id) is deleted along with its bootstrap.py/write.py call sites. write.py's _price_provider_usage_tokens/_upsert_provider_usage_model_rollup/_increment_provider_usage_model_rollup/_aggregate_message_tokens_into_model_usage no longer compute or write priced_with/priced_at_ms. docs/plans/layering.yaml's writer-module inventory drops the now-deleted pricing_seed.py entry; docs/schema.md no longer lists price_catalogs among the cost tables.

Test changes remove TestPriceCatalogSeed and every priced_with/priced_at_ms fixture/assertion against session_model_usage (tests against session_profiles, a different table, are untouched), and add two new tests exercising the v61 fast-forward specifically: a declaration-shape test and a genuine data round-trip test that builds a pre-v61-shaped session_model_usage table (FK + wider CHECK), seeds a 'priced' row, runs the real REPLACE_TABLE executor, and asserts priced_with/priced_at_ms are gone while token/cost/provenance data survive.

The committed docs/examples/demo-tour/ evidence encodes a manifest hash derived from the live archive schema, so it drifted with this change; regenerated via polylogue.demo.tour.run_demo_tour and copied back the two files devtools lab policy demo-tour-freshness flagged.

Verification

  • devtools lab policy schema-versioning → Schema evolution policy intact.
  • devtools test tests/unit/storage/test_index_fast_forward_executor.py tests/unit/storage/test_index_fast_forward_lifecycle.py → 23 passed, including the new test_v61_replace_table_drops_pricing_columns_and_keeps_the_rest.
  • devtools test across the full affected surface (archive_tiers write/ddl, pricing roundtrip, origin usage report, cost reconciliation probe, schema upgrade lane, cli insights, api facade contracts, cost rollup summary, session profile cost columns, claim vs evidence) → 527 passed, 5 failed; all 5 failures reproduce identically on a clean git stash of this diff (4 in test_insights.py: pre-existing timestamp/phases assertions; 1 in test_facade_contracts.py::test_no_undiscovered_async_methods, an unrelated get_setting/list_settings/set_setting contract gap) — confirmed pre-existing, not caused by this change.
  • devtools lab policy demo-tour-freshness → fresh tour output matches committed docs/examples/demo-tour/ (masked).
  • devtools verify --quick → exit_code: 0 (format, lint, mypy --strict, render all --check all clean).

Ref polylogue-resk

Sinity added 3 commits August 4, 2026 00:16
…columns

Problem: polylogue-v2mg kept price_catalogs while dropping model_prices and
session_reported_costs as zero-consumer tables, on the stated justification
that "session_model_usage.priced_with FK, active_price_catalog_id" are
genuine reads. A 2026-07-31 shipped-but-dead audit (polylogue-resk) measured
that justification false in all three named particulars: priced_with and
priced_at_ms had zero production SELECTs (every reference was an
INSERT/UPDATE in write.py, the DDL FK line, or prose -- the only SELECTs
were in tests/unit/storage/test_pricing_chain_roundtrip.py), and
active_price_catalog_id's only non-test caller was pricing_seed.py itself (a
seeded-already check, not a genuine read). Live data confirmed the column
carried no information (18,655 session_model_usage rows, 10,222 with
priced_with set, exactly 1 distinct value). Re-verified against current
source before acting; all three particulars still held.

Solution: index.db is a rebuildable derived tier, so this drops price_catalogs
via the index-tier same-version benign-DDL registry (index_convergence.py,
same mechanism v2mg used for model_prices/session_reported_costs) and drops
session_model_usage.priced_with/priced_at_ms plus the FK and the CHECK half
that referenced priced_with via a new INDEX_SCHEMA_VERSION v61 CONSTRAINT_ONLY
delta (lifecycle.py), a dead-column-removal REPLACE_TABLE copy-forward in the
same shape as v33/v36/v38/v41/v44. pricing_seed.py (seed_price_catalog,
active_price_catalog_id) is deleted along with its bootstrap.py/write.py call
sites. write.py's _price_provider_usage_tokens/_upsert_provider_usage_model_
rollup/_increment_provider_usage_model_rollup/_aggregate_message_tokens_into_
model_usage no longer compute or write priced_with/priced_at_ms.

While investigating, found the audit's "session_profiles.priced_with/
priced_at_ms are write-only too" side-note does not hold: those are a
DIFFERENT, unrelated pair of columns (no FK to price_catalogs, sourced from
cost_compute.py's _PRICE_SNAPSHOT_VERSION, not pricing_seed.py) with a real
production reader -- daemon/http.py's _profile_panel_payload serves them in
the session-insights HTTP reader panel via hydrate_session_profile. Those are
left untouched; this is documented at the session_model_usage DDL and in the
benign-DDL registry entry so a future audit does not re-conflate the two.

Verification:
- devtools lab policy schema-versioning -> "Schema evolution policy intact."
- devtools test tests/unit/storage/test_index_fast_forward_executor.py
  tests/unit/storage/test_index_fast_forward_lifecycle.py -> 23 passed,
  including a new test_v61_replace_table_drops_pricing_columns_and_keeps_the_rest
  that builds a pre-v61-shaped session_model_usage table (FK + wider CHECK),
  seeds a 'priced' row, runs the real REPLACE_TABLE executor, and asserts
  priced_with/priced_at_ms are gone while token/cost/provenance data survive.
- devtools test across the affected surface (archive_tiers write/ddl,
  pricing roundtrip, origin usage report, cost reconciliation probe, schema
  upgrade lane, cli insights, api facade contracts, cost rollup summary,
  session profile cost columns, claim vs evidence) -> 527 passed, 5 failed;
  all 5 failures reproduce identically on a clean stash of this diff (4 in
  test_insights.py: timestamp/phases assertions; 1 in test_facade_contracts.py:
  test_no_undiscovered_async_methods, an unrelated get_setting/list_settings/
  set_setting contract gap) -- pre-existing, not selected by this change.
- devtools verify --quick -> exit 0 (format, lint, mypy --strict, render all
  --check all clean).

Ref polylogue-resk
Removes TestPriceCatalogSeed (price_catalogs no longer exists) and every
priced_with/priced_at_ms assertion or fixture INSERT against
session_model_usage from test_pricing_chain_roundtrip.py,
test_origin_usage_report.py, test_cost_reconciliation_probe.py,
test_insights.py, and test_archive_tiers_write.py. Adds
test_v61_replace_table_drops_pricing_columns_and_keeps_the_rest and
test_v61_pricing_column_drop_is_a_clone_safe_constraint_copy_forward to
cover the new v61 fast-forward delta, and updates
test_archive_tiers_ddl.py's cost-table assertion to expect price_catalogs
absent from a fresh archive (mirroring the existing model_prices/
session_reported_costs assertions).

Ref polylogue-resk
The committed docs/examples/demo-tour/ evidence encodes a manifest hash
derived from the live archive schema; dropping price_catalogs and the
session_model_usage pricing columns (polylogue-resk) changed it. Regenerated
via polylogue.demo.tour.run_demo_tour and copied the two files
devtools lab policy demo-tour-freshness flagged as masked-different
(command-output/01-claim-versus-receipt.txt, transcript.txt) back into
docs/examples/demo-tour/. report.json/report.md only differed in the
wall-clock duration fields the freshness check already masks, so those were
left as committed.

Ref polylogue-resk
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b0042fa4-3898-46f9-b081-b98be8f4b5e6

📥 Commits

Reviewing files that changed from the base of the PR and between 0e8ddaf and 711d56b.

📒 Files selected for processing (19)
  • docs/examples/demo-tour/command-output/01-claim-versus-receipt.txt
  • docs/examples/demo-tour/transcript.txt
  • docs/plans/layering.yaml
  • docs/schema.md
  • polylogue/storage/sqlite/archive_tiers/bootstrap.py
  • polylogue/storage/sqlite/archive_tiers/index.py
  • polylogue/storage/sqlite/archive_tiers/index_convergence.py
  • polylogue/storage/sqlite/archive_tiers/pricing_seed.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • polylogue/storage/sqlite/lifecycle.py
  • tests/unit/cli/test_insights.py
  • tests/unit/devtools/test_cost_reconciliation_probe.py
  • tests/unit/devtools/test_verify_schema_upgrade_lane.py
  • tests/unit/storage/test_archive_tiers_ddl.py
  • tests/unit/storage/test_archive_tiers_write.py
  • tests/unit/storage/test_index_fast_forward_executor.py
  • tests/unit/storage/test_index_fast_forward_lifecycle.py
  • tests/unit/storage/test_origin_usage_report.py
  • tests/unit/storage/test_pricing_chain_roundtrip.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 09a6b45 into master Aug 3, 2026
3 checks passed
@Sinity
Sinity deleted the feature/schema/drop-price-catalogs-dead-columns branch August 3, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant