Skip to content

fix: add FTS trigger awareness to readiness checks and self-healing repair - #554

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/fts-trigger-awareness
Apr 28, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/fts-trigger-awareness

Conversation

@Sinity

@Sinity Sinity commented Apr 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

FTS triggers could be silently missing after suspend/resume cycles, causing index staleness that went undetected by readiness checks and doctor diagnostics.

Problem

When suspend_fts_triggers ran and the process terminated before restore_fts_triggers (crash, interrupt, or exception between the two calls), triggers stayed dropped permanently. Readiness checks only verified row counts — they never checked whether the FTS triggers actually existed. ensure_fts_index also didn't recreate triggers, so any code path that created FTS tables via that function left them triggerless.

Solution

Three-layer fix:

  1. fts_lifecycle.py: Split _FTS_TRIGGER_NAMES into _MESSAGE_FTS_TRIGGER_NAMES and _ACTION_EVENT_FTS_TRIGGER_NAMES. Added _triggers_present_sync/async helpers that query sqlite_master for trigger existence. Updated message_fts_readiness_sync/async to check triggers and return triggers_present in the result dict. ensure_fts_index_sync/async now call restore_fts_triggers after creating FTS tables.
  2. repair.py: repair_dangling_fts now calls restore_fts_triggers_sync after fixing orphaned rows, using CREATE TRIGGER IF NOT EXISTS for idempotency.
  3. readiness/__init__.py: Doctor reads triggers_present from the readiness result and reports a specific WARNING when triggers are missing.

Verification

  • devtools verify --quick (format, lint, mypy, render-all, topology checks)
  • Unit tests: pytest -q --ignore=tests/integration — 3963 passed
  • test_fts5.py stub updated to return proper trigger count

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added detection of missing FTS (Full-Text Search) triggers with actionable repair recommendations during index readiness checks
  • Bug Fixes

    • Enhanced FTS index lifecycle management to track trigger presence and automatically restore missing triggers during repair operations
    • Improved diagnostics to distinguish missing triggers from other readiness issues
  • Tests

    • Updated test stubs for improved FTS trigger verification accuracy

…epair

Missing triggers after suspend/resume cycles caused silent index staleness
that went undetected by readiness checks and doctor diagnostics.

Now readiness verifies all three messages_fts triggers exist, dangling_fts
repair recreates them, and ensure_fts_index auto-recovers on connection.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@Sinity
Sinity merged commit 4ac1571 into master Apr 28, 2026
10 of 11 checks passed
@Sinity
Sinity deleted the feature/fix/fts-trigger-awareness branch April 28, 2026 08:03
@coderabbitai

coderabbitai Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d02d6c86-b1c7-431f-9da9-420bf1f1c367

📥 Commits

Reviewing files that changed from the base of the PR and between c53134b and 253b7f9.

📒 Files selected for processing (5)
  • docs/plans/file-size-budgets.yaml
  • polylogue/readiness/__init__.py
  • polylogue/storage/fts/fts_lifecycle.py
  • polylogue/storage/repair.py
  • tests/unit/storage/test_fts5.py

📝 Walkthrough

Walkthrough

The changes enhance FTS (Full-Text Search) trigger management by adding trigger presence verification to readiness checks, restoring triggers during index maintenance and repair operations, and updating test stubs to reflect conditional schema queries. These modifications ensure missing FTS triggers are detected and reported during readiness assessments and restored as part of repair workflows.

Changes

Cohort / File(s) Summary
FTS Trigger Lifecycle Enhancements
polylogue/storage/fts/fts_lifecycle.py
Adds trigger presence tracking to readiness checks via new sqlite_master query helpers. Splits trigger names into message-specific and action-event-specific constants, recomposes them for bulk operations, and restores triggers after FTS index creation. Returns triggers_present flag in readiness result dicts. Exports _MESSAGE_FTS_TRIGGER_DDL via __all__.
Readiness Check Integration
polylogue/readiness/__init__.py
Extracts triggers_present flag from FTS readiness sync output (defaults to True). When index is not ready and triggers are missing, returns a distinct warning message recommending a dangling_fts repair action instead of the default warning path.
Repair Workflow Update
polylogue/storage/repair.py
Integrates trigger restoration into repair_dangling_fts by calling restore_fts_triggers_sync() after repairing messages_fts contents and before commit, re-synchronizing trigger state as part of the repair workflow.
Test Stub & Budget Updates
tests/unit/storage/test_fts5.py, docs/plans/file-size-budgets.yaml
Test stub's sqlite_master query handling becomes conditional: returns table row dict for messages_fts table checks, tuple (3,) for other queries. File-size budget ceiling for test_fts5.py increases from 1500 to 1510.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Readiness
    participant FTS Lifecycle
    participant Database

    Client->>Readiness: Check index readiness
    Readiness->>FTS Lifecycle: message_fts_readiness_sync()
    FTS Lifecycle->>Database: Query sqlite_master for FTS triggers
    Database-->>FTS Lifecycle: Returns trigger presence status
    FTS Lifecycle-->>FTS Lifecycle: Compute readiness with triggers_present
    FTS Lifecycle-->>Readiness: Return {ready, triggers_present, ...}
    
    alt Triggers Missing
        Readiness-->>Client: Return stale index warning + dangling_fts repair action
    else Triggers Present
        Readiness-->>Client: Return standard warning or ready status
    end
Loading
sequenceDiagram
    actor Client
    participant Repair
    participant Database
    participant FTS Lifecycle

    Client->>Repair: repair_dangling_fts()
    Repair->>Database: INSERT INTO messages_fts (repaired rows)
    Repair->>FTS Lifecycle: restore_fts_triggers_sync(conn)
    FTS Lifecycle->>Database: Create/verify FTS triggers exist
    Database-->>FTS Lifecycle: Triggers restored
    FTS Lifecycle-->>Repair: Complete
    Repair->>Database: conn.commit()
    Repair-->>Client: Repair complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 The triggers now dance in the FTS glow,
We verify, restore, and let readiness know—
When stale indices whisper their plight,
The dangling-fts repair sets things right! ✨
A tale of presence checks and database care,
Where rabbits ensure the triggers are there! 🌿

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/fts-trigger-awareness

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 and usage tips.

Sinity added a commit that referenced this pull request Apr 28, 2026
## Summary
Add NotebookEdit tool dispatch to `extract_file_changes` in
semantic_capture.py.

## Problem
The function handled Read, Write, and Edit tool invocations but silently
dropped NotebookEdit operations from Claude Code sessions.

## Solution
Added NotebookEdit branch that extracts `new_source` content and records
it as an edit operation.

Note: the other two items from #552 (FTS suspend outside try block,
missing embed stage dispatch) were already fixed in #554 and #558.

Closes #552

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 <[email protected]>
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ 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".

@Sinity
Sinity requested a review from Copilot May 1, 2026 01:55
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:20
Sinity added a commit that referenced this pull request May 7, 2026
…epair (#554)

## Summary
FTS triggers could be silently missing after suspend/resume cycles,
causing index staleness that went undetected by readiness checks and
doctor diagnostics.

## Problem
When `suspend_fts_triggers` ran and the process terminated before
`restore_fts_triggers` (crash, interrupt, or exception between the two
calls), triggers stayed dropped permanently. Readiness checks only
verified row counts — they never checked whether the FTS triggers
actually existed. `ensure_fts_index` also didn't recreate triggers, so
any code path that created FTS tables via that function left them
triggerless.

## Solution
Three-layer fix:
1. **`fts_lifecycle.py`**: Split `_FTS_TRIGGER_NAMES` into
`_MESSAGE_FTS_TRIGGER_NAMES` and `_ACTION_EVENT_FTS_TRIGGER_NAMES`.
Added `_triggers_present_sync/async` helpers that query `sqlite_master`
for trigger existence. Updated `message_fts_readiness_sync/async` to
check triggers and return `triggers_present` in the result dict.
`ensure_fts_index_sync/async` now call `restore_fts_triggers` after
creating FTS tables.
2. **`repair.py`**: `repair_dangling_fts` now calls
`restore_fts_triggers_sync` after fixing orphaned rows, using `CREATE
TRIGGER IF NOT EXISTS` for idempotency.
3. **`readiness/__init__.py`**: Doctor reads `triggers_present` from the
readiness result and reports a specific WARNING when triggers are
missing.

## Verification
- `devtools verify --quick` (format, lint, mypy, render-all, topology
checks)
- Unit tests: `pytest -q --ignore=tests/integration` — 3963 passed
- `test_fts5.py` stub updated to return proper trigger count

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 <[email protected]>
Sinity added a commit that referenced this pull request May 7, 2026
## Summary
Add NotebookEdit tool dispatch to `extract_file_changes` in
semantic_capture.py.

## Problem
The function handled Read, Write, and Edit tool invocations but silently
dropped NotebookEdit operations from Claude Code sessions.

## Solution
Added NotebookEdit branch that extracts `new_source` content and records
it as an edit operation.

Note: the other two items from #552 (FTS suspend outside try block,
missing embed stage dispatch) were already fixed in #554 and #558.

Closes #552

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 <[email protected]>
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