Skip to content

fix(storage): drop threads_fts, a maintained FTS index with zero consumers - #3699

Merged
Sinity merged 6 commits into
masterfrom
feature/storage/drop-threads-fts-dead-search-index
Aug 4, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/storage/drop-threads-fts-dead-search-index

Conversation

@Sinity

@Sinity Sinity commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

Drops threads_fts (table, 3 triggers, and all rebuild/repair/freshness plumbing), a trigger-maintained FTS5 index with zero application-layer search consumers. blocks_command_trigram, flagged in the same original audit, is investigated separately below and kept in full — it has a real consumer.

Problem

polylogue-eizc asked me to re-verify a 2026-07-31 producer/consumer audit's finding that threads_fts and blocks_command_trigram are maintained FTS surfaces with zero search consumers, and to remove them if the finding still holds (or document why not).

Re-verification against present source confirmed threads_fts is still dead: its only MATCH reader, session_insight_thread_queries.list_threads, has zero production callers anywhere in the codebase (only the storage-layer mixin and tests reference it), and the live "analyze threads" search path (archive_tiers/archive.py:list_thread_insights) already does a manual LIKE substring scan over thread_id/session title/repo/branch, never touching threads_fts.

blocks_command_trigram is a different story: the original audit's rg tool_detail_text check missed devtools/affordance_usage.py's _cli_action_rows, which drives its substring test off blocks_command_trigram via the exact blocks.rowid IN (SELECT rowid FROM blocks_command_trigram WHERE tool_detail_text LIKE ...) shape the table's own DDL header comment prescribes, for the documented 900x speedup. This is wired into a real command (devtools workspace affordance-usage, introduced in PR #2622). It is a genuine consumer the audit missed, not one that appeared since — so it is kept, with a comment explaining why.

Solution

  • Dropped threads_fts, its 3 triggers, and every piece of rebuild/repair/freshness machinery that referenced it, across archive_tiers/index.py, fts/sql.py, fts/fts_lifecycle.py, fts/dangling_repair.py, fts/freshness.py, daemon/fts_startup.py, daemon/fts_automerge.py, daemon/fts_status.py, daemon/status.py, daemon/convergence_stages.py, insights/session/{status,runtime,repair_assessment}.py, derived/{insights,derived_status}.py, repair.py, maintenance/preview.py, devtools/synthetic_benchmark_runtime.py.
  • list_threads's text-query path now does a plain LIKE scan over threads.search_text instead of an FTS5 MATCH, mirroring the shape the live analyze-threads search path already uses — no behavior loss, just no longer backed by a redundant index nobody read.
  • INDEX_SCHEMA_VERSION bumped 61->62 (rebased on top of a concurrent PR that had already taken v61). lifecycle.py declares the v62 delta as CACHE_REMOVAL (same class as v37/v41's precedent): a clone-safe fast-forward drops the orphaned table and its triggers in place. This needed a small executor extension — DROP_TABLE operations can now bundle ("trigger", name) objects ahead of the ("table", name) object, since dropping the FTS5 virtual table does not implicitly drop the AFTER INSERT/DELETE/UPDATE ON threads triggers that feed it (they'd otherwise fail on their next fire against a table that no longer exists). Covered by a new integration test that runs the real apply_index_fast_forward plan against a v61-shaped fixture.
  • Regenerated docs/examples/demo-tour/ — its completion-claim sample-manifest hash embeds PRAGMA user_version, so the schema bump deterministically shifted it (confirmed deterministic by running the tour twice back-to-back with an identical fresh hash both times, not a flaky gate).

Alternatives rejected

Dropping both flagged surfaces uniformly, per the original audit, was the starting assumption — rejected once devtools/affordance_usage.py turned up as a real blocks_command_trigram consumer during re-verification. Reimplementing blocks_command_trigram's search as a LIKE scan (like threads_fts) was considered and rejected: unlike threads_fts's zero-caller path, this one is a real, currently-used command with a documented 900x measured speedup from the trigram index, so replacing it would be a real regression, not a cleanup.

Verification

  • devtools test tests/unit/storage/test_fts_escape_in_insights.py tests/unit/storage/test_derived_status.py tests/unit/storage/test_dangling_fts_derived_surfaces.py tests/unit/storage/test_index_fast_forward_executor.py tests/unit/storage/test_schema_policy_contracts.py tests/unit/storage/test_repair.py tests/unit/storage/test_pl_fold.py tests/unit/daemon/test_convergence_stages.py tests/unit/daemon/test_daemon_cli.py tests/unit/devtools/test_benchmark_campaigns.py — 310 passed.
  • devtools test tests/unit/daemon/test_metrics_endpoint.py surfaces one pre-existing, unrelated failure (test_embedding_backlog_and_latest_catchup_state, a CHECK constraint failed: status IN (...) on embed-catchup run status "cancelled") that reproduces identically in isolation with zero threads_fts/trigram involvement — not caused by this change.
  • devtools verify --quick — fully green (ruff format/check, mypy --strict, render all, layering, all lab policy gates including demo-tour-freshness).
  • Added test_v62_drop_table_removes_threads_fts_and_its_triggers: builds a real v61-shaped fixture (threads/threads_fts/3 triggers + a kept sibling blocks_command_trigram), runs the actual apply_index_fast_forward plan, asserts the table+triggers are gone, the sibling survives, and user_version reaches 62.

Ref polylogue-eizc

🤖 Generated with Claude Code

Sinity and others added 3 commits August 4, 2026 00:39
…umers

Problem: polylogue-eizc's producer/consumer audit (2026-07-31) flagged
threads_fts and blocks_command_trigram as trigger-maintained FTS surfaces
with zero application-layer search consumers. Re-verified against present
source: threads_fts's only MATCH reader
(session_insight_thread_queries.list_threads) still has zero production
callers -- the live "analyze threads" search path
(archive_tiers/archive.py:list_thread_insights) already does a manual LIKE
substring scan and never touches threads_fts. blocks_command_trigram was
NOT dropped: devtools/affordance_usage.py's _cli_action_rows (wired via
`devtools workspace affordance-usage`, PR #2622) is a real, functional
consumer the original zero-consumer finding missed -- kept in full.

Solution: drop threads_fts (table, 3 triggers, rebuild/repair/freshness
plumbing) across archive_tiers/index.py, fts/sql.py, fts/fts_lifecycle.py,
fts/dangling_repair.py, fts/freshness.py, daemon/fts_startup.py,
daemon/fts_automerge.py, daemon/fts_status.py, daemon/status.py,
daemon/convergence_stages.py, insights/session/{status,runtime,
repair_assessment}.py, derived/{insights,derived_status}.py, repair.py,
maintenance/preview.py, devtools/synthetic_benchmark_runtime.py.
list_threads' text-query path now does a plain LIKE scan over
threads.search_text instead of an FTS5 MATCH, mirroring the already-live
analyze-threads search shape -- no behavior loss, just no longer backed by
a redundant index. INDEX_SCHEMA_VERSION bumped 60->61; lifecycle.py
declares the v61 delta as CACHE_REMOVAL (same class as v37/v41): a
clone-safe fast-forward drops the table and its triggers via a new
DROP_TABLE-with-trigger-objects executor path (no
`polylogue ops reset --index && polylogued run` required).

Verification: devtools test across the touched surface (fts_lifecycle,
fts_status, dangling_repair, derived_status, repair, schema_policy_contracts,
pl_fold, index_fast_forward_executor, convergence_stages, daemon_cli,
metrics_endpoint, benchmark_campaigns) -- 337 passed, 1 pre-existing
unrelated failure (test_embedding_backlog_and_latest_catchup_state, a
CHECK-constraint mismatch on embed catchup run status="cancelled", fails
identically in isolation with no threads_fts/trigram involvement).
`ruff format`/`mypy --strict`/`render all` all clean via devtools verify
--quick (the only other failure, lab policy demo-tour-freshness, is an
unrelated nondeterministic sample-manifest hash drift with no FTS content).

Ref polylogue-eizc

Co-Authored-By: Claude <[email protected]>
Problem: the v62 IndexDeltaDeclaration (threads_fts removal) exercises a
new executor capability -- DROP_TABLE operations that bundle trigger
objects ahead of the table object, since dropping the threads_fts FTS5
virtual table does not implicitly drop the AFTER INSERT/DELETE/UPDATE ON
threads triggers that feed it. That capability had only generic DROP_TABLE
coverage (an already-absent table) before this change.

Solution: test_v62_drop_table_removes_threads_fts_and_its_triggers builds
a v61-shaped fixture with threads/threads_fts/its three triggers plus an
unrelated sibling FTS surface (blocks_command_trigram, kept), applies the
real v62 declaration through apply_index_fast_forward, and asserts the
table and all three triggers are gone while the sibling survives and
user_version reaches 62.

Verification: devtools test tests/unit/storage/test_index_fast_forward_executor.py
-- 9 passed. devtools verify --quick clean except the pre-existing
unrelated demo-tour-freshness nondeterministic sample-manifest drift.

Ref polylogue-eizc

Co-Authored-By: Claude <[email protected]>
Problem: devtools lab policy demo-tour-freshness compares a live-run
`polylogue demo tour` against the committed docs/examples/demo-tour/
evidence. The completion-claim experiment's sample manifest hash embeds
`PRAGMA user_version` (polylogue/demo/receipts.py:_archive_cursor), so
bumping INDEX_SCHEMA_VERSION 61->62 for the threads_fts removal
deterministically shifts that hash -- confirmed deterministic by running
the tour twice back-to-back and getting an identical fresh hash both
times, so this is not a flaky/nondeterministic gate, just a fixture that
needed regenerating for the new schema version (same remediation path
already used by prior schema-version-bumping PRs, e.g. the resk pricing
column removal this branch was rebased onto).

Solution: `polylogue demo tour --out-dir polylogue-demo-tour --force`,
copied the regenerated command-output/report.json/report.md/
transcript.txt/recording.tape into docs/examples/demo-tour/.

Verification: devtools lab policy demo-tour-freshness now reports
"fresh tour output matches committed docs/examples/demo-tour/ (masked)".

Ref polylogue-eizc

Co-Authored-By: Claude <[email protected]>
@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: 14 minutes

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: c8ba7d9b-e454-4403-bc7a-40098bcc21a1

📥 Commits

Reviewing files that changed from the base of the PR and between 4530c99 and d26d128.

⛔ Files ignored due to path filters (1)
  • docs/examples/demo-tour/demo-tour.gif is excluded by !**/*.gif
📒 Files selected for processing (38)
  • devtools/synthetic_benchmark_runtime.py
  • docs/examples/demo-tour/command-output/01-claim-versus-receipt.txt
  • docs/examples/demo-tour/report.json
  • docs/examples/demo-tour/report.md
  • docs/examples/demo-tour/transcript.txt
  • docs/internals.md
  • docs/schema.md
  • docs/search.md
  • polylogue/daemon/convergence_stages.py
  • polylogue/daemon/fts_automerge.py
  • polylogue/daemon/fts_startup.py
  • polylogue/daemon/fts_status.py
  • polylogue/daemon/status.py
  • polylogue/maintenance/preview.py
  • polylogue/storage/derived/derived_status.py
  • polylogue/storage/derived/insights.py
  • polylogue/storage/fts/dangling_repair.py
  • polylogue/storage/fts/freshness.py
  • polylogue/storage/fts/fts_lifecycle.py
  • polylogue/storage/fts/sql.py
  • polylogue/storage/insights/session/repair_assessment.py
  • polylogue/storage/insights/session/runtime.py
  • polylogue/storage/insights/session/status.py
  • polylogue/storage/repair.py
  • polylogue/storage/sqlite/archive_tiers/index.py
  • polylogue/storage/sqlite/archive_tiers/index_fast_forward_executor.py
  • polylogue/storage/sqlite/lifecycle.py
  • polylogue/storage/sqlite/queries/session_insight_thread_queries.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/daemon/test_daemon_cli.py
  • tests/unit/devtools/test_benchmark_campaigns.py
  • tests/unit/storage/test_dangling_fts_derived_surfaces.py
  • tests/unit/storage/test_derived_status.py
  • tests/unit/storage/test_fts_escape_in_insights.py
  • tests/unit/storage/test_index_fast_forward_executor.py
  • tests/unit/storage/test_pl_fold.py
  • tests/unit/storage/test_repair.py
  • tests/unit/storage/test_schema_policy_contracts.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 added 3 commits August 4, 2026 02:52
Problem: PR #3699 was interrupted by concurrent index schema changes, leaving the dead threads_fts removal on an obsolete version boundary.\n\nWhat changed: Reconcile the branch with current master at v62, retain the live blocks_command_trigram consumer, and apply threads_fts removal as clone-safe index v63. Regenerate the deterministic demo report and preserve generated scratch artifacts outside the commit.\n\nCompatibility/migration: Existing index generations fast-forward from v62 to v63 by dropping threads_fts and its triggers. No raw replay is required.
Regenerate the committed demo-tour evidence after reconciling the index schema version. The generated tour passes, and obsolete generated files are removed by the current renderer.
Keep the documentation-linked uvx proof and the canonical recording tape path while retaining the regenerated schema-v63 evidence.
@Sinity
Sinity merged commit f2bad6e into master Aug 4, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/storage/drop-threads-fts-dead-search-index branch August 4, 2026 00:58
Sinity added a commit that referenced this pull request Aug 4, 2026
Summary\nRecord the two recovered bootstrap lanes as closed in Beads
after their code PRs landed.\n\nProblem\nThe durable task records
remained open after PR #3699 and PR #3701 merged.\n\nSolution\nClose
polylogue-eizc with the v63 threads_fts removal evidence and
polylogue-lyv4 with the async targeted rebuild
evidence.\n\nVerification\nThe Beads pre-push hook validated the JSONL
and dependency graph with zero unhandled findings.
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