Repository navigation
refactor(storage): trim FTS bloat and migrate stale tag read paths (#817) - #1098
Conversation
Add three focused regression tests under tests/unit/storage/test_fts_bloat_invariants.py that lock in the post-#944 external-content FTS conversion: - test_messages_fts_is_contentless_external_content asserts the DDL carries content='messages', content_rowid='rowid'. A future schema edit that drops the option (or flips back to standalone FTS5) fails loudly. - test_messages_fts_storage_does_not_duplicate_message_bodies synthesises ~10 MB of message text and uses dbstat to confirm messages_fts_* pages stay well under the messages table size (observed ratio ~0.2; threshold 0.5 guards against a regression to a full duplicate copy). - test_messages_fts_deletion_consistency_with_external_content guards the AD trigger so DELETE on messages drops the corresponding FTS row, preventing the regression that forced the earlier content-sync revert. Ref #817 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`history_entries` is typed `list[dict[str, Any]]` (line 328), so the `isinstance(entry, dict)` guard at line 347 was always true. mypy --strict flagged it as `redundant-expr`, blocking the verify-quick gate. Removing the guard makes the local mypy baseline clean.
|
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 (2)
✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cd503acb8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Pin the post-#944 external-content FTS conversion with three focused
regression tests, and clear an inherited mypy
redundant-exprfailurethat was blocking the local
devtools verify --quickbaseline.The headline scope of #817 — FTS storage bloat, external-content delete
correctness, FTS trigger commit-ordering, JSON tag read paths — already
landed across #944 / #882. After auditing each acceptance criterion on
master and against the corrections in the reopened-issue comments
(
live_cursoris active,conversation_tagsis active,ArchiveWriteGatewayis active), the actionable remaining work for thisscope is durable evidence: the invariants must not silently regress,
and the catalogue must hold them after future schema edits.
Problem
The original PR for #817 attempted the external-content FTS conversion
but reverted it because a DELETE on
messagesleft the row matchable inFTS. The conversion was reapplied in #944 (with the corrected
messages_fts_adtrigger), but no committed test verifies either:content='messages', content_rowid='rowid',pages (the original "~6 GB bloat" claim),
messagesis propagated tomessages_ftsvia the ADtrigger (the exact bug that forced the earlier revert).
Without that coverage, the next schema edit that touches
MESSAGE_FTS_DDLor the trigger DDL in
polylogue/storage/fts/fts_lifecycle.pycansilently bring the bloat back, and CI will not notice.
Concurrent finding:
devtools verify --quickon master fails with onemypy
[redundant-expr]error indevtools/evidence_dashboard.py:347introduced by #1091. That blocks every push from this branch (and
every other branch), so it is folded into this PR.
Solution
tests/unit/storage/test_fts_bloat_invariants.py(new file, owned bythe storage tier):
test_messages_fts_is_contentless_external_content— readssqlite_master.sqlformessages_ftsand asserts the DDL stillcarries both
content='messages'andcontent_rowid='rowid'.test_messages_fts_storage_does_not_duplicate_message_bodies—synthesises 2000 messages × ~5 KB and uses the
dbstatvirtualtable to compare
SUM(pgsize) WHERE name LIKE 'messages_fts%'toSUM(pgsize) WHERE name LIKE 'messages%'. Observed ratio on thefixture is ~0.2; threshold is 0.5, well below the ~1.0 a regression
to standalone FTS5 would produce.
test_messages_fts_deletion_consistency_with_external_content—inserts two messages with unique tokens, deletes one, and asserts
the deleted token no longer matches while the surviving token still
does. Pins the
messages_fts_adtrigger semantics.The dedicated file (151 LOC) was placed alongside
test_fts5.pyinsteadof inlined because
test_fts5.pyis already at its declareddocs/plans/file-size-budgets.yamlceiling of 1650 LOC.devtools/evidence_dashboard.py— drop theisinstance(entry, dict)guard on a
list[dict[str, Any]]so mypy --strict is clean again.Audit results for the original #817 acceptance criteria
idx_messages_provider_role,idx_messages_provider_stats, all fouridx_conv_stats_*indexes are actively used byEXPLAIN QUERY PLANon the filter pushdowns and provider-rollup queriesstorage/sqlite/queries/conversations_identity.py:list_tagsalready prefers theconversation_tags+tagsM2M join; the JSONmetadata->'tags'query is an explicitly documented fallback for unmigrated archives only. The otherjson_extract(metadata, '$.tags')matches inschema_bootstrap.pyare one-time migration backfill SQL (SchemaBackfillDescriptor), not runtime readstest_fts_triggers_restored_after_exception(test_fts5.py:1498),test_fts_triggers_restored_after_exception_during_ingest(test_backend.py:1652), plus daemon startup-repair path inpolylogue/daemon/cli.py:_fts_startup_checkSCHEMA_DDLANALYZE scheduling already exists in
polylogue/daemon/cli.py:_periodic_db_optimize(dailyPRAGMA optimize).Files NOT changed (intentional)
Per the worktree scope, only
polylogue/storage/sqlite/,polylogue/storage/search_providers/, repository read-side mixins, and related tests are owned by this PR. The mypy fix indevtools/is an inherited blocker that must be cleared to push from this branch; it is intentionally minimal (one line) and unrelated to ownership boundaries.Verification
Measured FTS bloat (synthetic 2000-message fixture, ~10 MB of message
text, post-VACUUM):
Stale JSON-tag read paths migrated: 0 (the only remaining JSON read in
list_tagsis an explicit fallback for unmigrated archives, kept onpurpose per the issue's "stale JSON tag reads should use
conversation_tags+tags" framing combined with the schema-bootstrapbackfill that turns the JSON tags into M2M rows on first start).
Ref #817