Skip to content

fix(fts): regenerate AFTER triggers to force re-binding after 0003#145

Merged
liplus-lin-lay merged 1 commit into
mainfrom
135-trigger-regen
Apr 28, 2026
Merged

fix(fts): regenerate AFTER triggers to force re-binding after 0003#145
liplus-lin-lay merged 1 commit into
mainfrom
135-trigger-regen

Conversation

@liplus-lin-lay
Copy link
Copy Markdown
Member

観測

  • 2026-04-28: migration 0003 (DROP+CREATE search_docs_code_fts) を merge し、D1 console で適用済み
  • 適用後も production Worker が D1_ERROR: SQLITE_CORRUPT_VTABtokenizer_kind=code の diff upsert で継続報告 (15:30 / 16:30 / 17:30 UTC pollDiffs cron)
  • nat_fts surface はクリーン (Fire OAuth and GitHub App authentication #4-9 で確認)。code_fts surface のみ corrupt が残る

仮説

0001 で宣言された AFTER INSERT/UPDATE/DELETE trigger は、search_docs_code_fts への参照を解決した状態で compile されている。0003 で virtual table を DROP+CREATE した後、trigger が古い参照を保持しているため write が失敗している可能性がある。trigger を DROP + CREATE で再宣言することで、新しい table 実体への再 bind を強制する。

変更

  • migrations/0004_fts5_triggers_regen.sql を追加 (+57 lines)
  • 3 つの trigger を DROP IF EXISTS してから CREATE で再宣言
  • 各 trigger の body は 0001_fts5_init.sql と byte-for-byte 同一 (検証済み)
  • declarative かつデータを持たないため、非破壊操作

適用と検証

  • merge は migration を自動適用しない
  • 別途 D1 console もしくは wrangler d1 migrations apply で 0004 を適用する
  • 検証: 適用後の次回 :30 pollDiffs cron で diff upsert が成功するか確認

Notes

Refs #135

)

0003 で search_docs_code_fts table を DROP+CREATE 後も Worker が
SQLITE_CORRUPT_VTAB を継続報告。trigger references の再解決のため
AFTER INSERT/UPDATE/DELETE trigger を DROP + CREATE で再宣言する。

Trigger は declarative でデータを持たないため、再宣言は非破壊操作。
Body は 0001 と byte-for-byte 同一で、宣言タイミングのみが変わる。

適用は merge 後に D1 console もしくは
`wrangler d1 migrations apply` で別途実行する。

Refs #135
@liplus-lin-lay liplus-lin-lay added the bug 動いていない、壊れている label Apr 28, 2026
@liplus-lin-lay liplus-lin-lay self-assigned this Apr 28, 2026
Copy link
Copy Markdown
Member Author

@liplus-lin-lay liplus-lin-lay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review (auto mode required)

Migration 内容の検証

  • migrations/0004_fts5_triggers_regen.sql の trigger body 3 種 (trg_search_docs_ai / trg_search_docs_ad / trg_search_docs_au) は 0001_fts5_init.sql と byte-for-byte 同一を確認済み
    • diff で 3 trigger 全て差分なし (AI MATCH / AD MATCH / AU MATCH)
    • 宣言タイミングのみ変更、SQL semantics は不変

非破壊性

  • Trigger は declarative でデータを持たない
  • DROP TRIGGER IF EXISTSCREATE TRIGGER は idempotent
  • search_docs table および search_docs_nat_fts / search_docs_code_fts の row data には触れない

適用パス note

  • merge では migration は自動適用されない
  • Master もしくは AI が merge 後に別途以下のいずれかで適用する:
    • D1 console で 0004 の SQL を直接実行
    • wrangler d1 migrations apply (Wrangler が migrations dir を順次適用)

検証パス

  • 適用後の次回 :30 pollDiffs cron 実行で tokenizer_kind=code の diff upsert が成功 (SQLITE_CORRUPT_VTAB が消える) ことを確認
  • nat_fts は元から clean なので影響観測対象外
  • 失敗継続の場合は axis 2 attempt 1/3 が外れたことを意味し、autonomous loop fire の次 axis (e.g., データ層 row level の reindex / search_docs row 再作成) に進む

影響範囲

  • src/*.ts は変更なし
  • 0001-0003 migration files は変更なし
  • 新規 SQL ファイル 1 件のみ (+57 lines)

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
github-rag-mcp 883ab70 Apr 28 2026, 05:45 PM

@liplus-lin-lay liplus-lin-lay merged commit ac325fa into main Apr 28, 2026
3 checks passed
@liplus-lin-lay liplus-lin-lay deleted the 135-trigger-regen branch April 28, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 動いていない、壊れている

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant