Omniscio

Global Search (Ctrl+K across everything) (part 2)

Everything Ctrl+K finds comes from a full-text index built in one place, and the rule is that what you can read in a conversation is what search can find — an agent row contributes only its prose, never its tool calls. The index stores no text of its own, so each result excerpt is rebuilt from the message when the row is shown, and a quoted phrase narrows a search to a true word-for-word match. A one-time job rebuilds the cold-storage archive’s index in the background, and tells you in your inbox if it keeps failing.

On this page

What it is

The page you are reading is the second half of Global Search, which describes the Ctrl+K palette itself: the tabs, the filters, how to use them and why a search stays fast. This part is the machinery underneath — what goes into the index search reads from, and how a phrase in quotes is matched word for word.

Where to find it

There is nothing to open: the index is built as messages arrive, and the archive rebuild runs by itself in the background after the app starts. The one thing you may see is an inbox notice when that rebuild keeps failing — search keeps working meanwhile.

How it behaves

What reaches the index, and how a phrase is matched word for word

What reaches the FTS index is decided in one place: indexableSearchText(source, content, opts) in search-index-text.ts, re-exported by fts-index-text.ts and shared so the archive's database-worker rebuild applies the identical rule. Operator rows return their content verbatim; agent rows return only the trailing prose after the last tool marker (▸ / ←) via extractProse(); still-streaming partials and system rows return null and contribute nothing.

An agent row's text also depends on the four display flags that decide what the chat actually shows (the final-marker toggles and the dev-pipeline switch). Search therefore indexes exactly the text you can read: nothing visible stops being findable, and a hit always has a visible match. Those flags are a required argument, so a caller that forgets them fails to compile rather than quietly indexing under a different rule — every producer (addMessage(), the table rebuild, the cold-storage rebuild, the archive's realignment, the backup merge, the interrupted-turn heal) now takes them from the one reader in index-render-flags.ts, and changing a display setting re-derives the index at the next launch rather than leaving it on the old rendering's words for good. That re-derive covers the main store; the cold-storage archive is indexed by its own one-time realignment, which a settings flip does not currently re-arm, so an archived agent row keeps the previous rendering's words until that is added.

A message becomes searchable a moment after it is saved, not during the save. The save commits the conversation row and one small "needs indexing" marker together, and a background pass writes the index entry right after it — because the index write itself (FTS5 tokenizing the whole body) is the expensive half, and doing it inside the save's database transaction made every other write wait on it. Nothing can be lost by this: the marker is saved atomically with the message, so a crash, a forced quit or a busy disk only delays the entry until the next pass (including the one at launch). See the FTS index contract the-index-catches-up-after-the-save.

The index stores no text of its own. conversation_messages_fts is contentless — it holds the search structure and nothing else, which is what makes it roughly half a gigabyte smaller than the layout it replaced. A result's excerpt is therefore rebuilt from the message when it is displayed, by snippet-rebuild.ts, through the same rule and the same flags the index was written with. A per-row try/catch keeps a single pathological row from blocking a rebuild.

On the read side, extractExactPhrases(input) (also in queries-messages.ts) pulls every positive quoted phrase out of the user's query — it skips negated phrases (those stay on the stemmed NOT path) and returns [] for any query containing an OR (each side of an OR only ever appears in one of the candidate rows, so AND-ing word-exact narrowing would wrongly reject real hits). Each extracted phrase becomes an extra AND phrase_exact(<the row's indexed text>, ?) = 1 condition on the FTS query. That operand is recomputed per row by the indexed_text(source, content, metadata, flags) scalar, because the index now stores no text of its own and the raw column is not a substitute: an agent row's raw content also carries its tool calls and results, so narrowing against it would admit rows whose phrase sits in text the index never holds and the excerpt — derived from prose — cannot show. Operator rows return their content unchanged, so the derivation costs only agent rows, and only on a quoted query. phrase_exact and indexed_text are deterministic SQLite scalars registered in custom-db-functions.ts — it compiles a per-needle regex ((?<!WORD)needle(?!WORD) with WORD = [\p{L}\p{N}_], iu flags, regex-metacharacters escaped, and every gap of whitespace or hyphens BETWEEN two words replaced with [\s-]+ by the shared phraseRegexSource in db-text-functions.ts), memoized in a 100-entry LRU. The result excerpt (snippet-rebuild.ts) builds its pattern with the same helper and anchors on the quoted phrase (excerptTerms), so it highlights exactly what the narrowing accepted; bare words are found only at a word start. searchSessionTitles adds the same phrase_exact(s.name, ?) condition per quoted phrase, and isSemanticEligible in search.ts refuses any query containing a quote. The result: FTS5's porter-stemmer recall narrows down to a true word-for-word match without rejecting the index's overall stemmed superset for unquoted searches.

The archive’s index: rebuilt once, in the background

The archive's index is rebuilt once, in the background. Messages moved to cold storage before 2026-09-17 were indexed at row ids that did not match their messages, so an archive search had to look every candidate up by its message id, and restoring an old session could quietly remove OTHER conversations' entries from Ctrl+K. A one-time job rebuilds the archive's index from the archived messages themselves — every entry at its own message's row id, curated by the same rule as the live index — and swaps it in with a rename, so search keeps using the old index until the new one is complete. It starts after the app does, runs off the main thread in short time-boxed steps beside the cold-storage sweep (slower when the computer is busy), picks up where it left off after a restart, and finally clears the old index a slice at a time. Once it has swapped in, archived results that had gone missing come back and the archive is searched by row id like the live store. The job is archive-fts-realign.ts, its database steps named-tx-archive-fts-realign.ts; the rule is archive-rowid-alignment-is-restored-once in the same contract.

If that rebuild keeps failing, the inbox says so. After three failed runs in a row the user gets one notice, "Archive search rebuild keeps failing": search still works as before, no message is affected, the rebuild keeps retrying on its own, and the notice clears itself once it finishes. A run cut short because the app was closing does not count, and neither does the developer kill switch; a background worker that could not start does. The count is kept in <data folder>/logs/archive-search-rebuild-failures.json, so failures across restarts add up. The notice is held during a brand-new user's first day (a fresh archive has nothing to rebuild), and it can be switched off like any other notice type. The code is archive-fts-realign-alert.ts; the rule is a-rebuild-that-keeps-failing-says-so in the same contract.

Why a search stays fast on a big history

A quoted phrase walks forward until it can prove its page. Each store's candidates are checked in the order the results are sorted, in growing batches, and only rows not yet checked are read again; the page is returned once it is full and every store's last checked row sorts at or behind the page's last row, or once every store has run out. It never returns a short page and never falls back to checking every match at once — the walk itself is what keeps a phrase search from decoding the whole history. No statement carries more than the background helper's 512-parameter budget: a store's candidate list rides as ids only while it fits, a wider store re-derives its candidates with the index's own match on each batch, and a batch too large for one statement is phrase-checked in slices — so thousands of look-alike candidates still answer instead of failing back to empty.

A newest- or oldest-sorted conversation search (the Ctrl+K default) reads only the rows it will show. Matches are found by the index's row id without opening any message; each store — the live database and the cold-storage archive — contributes at most one page, either by looking its few candidates up directly or by walking its timestamp index until the page is full; the archive is skipped entirely when the live store's page already sorts ahead of every archived message; and snippets plus session and project names are read for the displayed rows alone. Before this, every matching message was read and snippeted before the top 30 were kept, so a common word or a long history took 15-30 seconds and a rare word could take minutes. Relevance sort, counts and offset paging still use the single full query; a quoted phrase walks the same page-first path, widening its per-store batches until it can prove the page. The code is search-page-first.ts; the rules are in the search FTS index contract (time-sorted-search-reads-only-the-page).

The conversation read runs on a warm background helper. The conversation full-text read runs in a background database helper process, so a slow disk can never freeze the app while it runs. Those helpers are kept warm and ready between searches (up to two idle at a time), so a search never waits for one to start. Before 2026-10-09 every search started a fresh helper, and on a busy computer that start alone could take more than 10 seconds for a 0.2-second query. Each search still gets its own helper while it runs, a helper is reused only after a search that finished cleanly, and all idle helpers shut down when the database closes. See the search off-thread contract (warm-hosts-are-exclusive-and-reused-only-clean).

Global Search (Ctrl+K) is the page this continues — the palette, its tabs and its filters. What reaches the index is governed by the FTS index contract, and semantic-search.md covers the meaning-based matches that blend into the same result list.

Every lesson the conversation search has learned (each past fix, incident and special case) is pinned as a runnable check before the search is redesigned. The ledger, the route decision and the test records are in the conversation search rescue evidence, and the new checks live in tests/unit/db/search-lessons/.

Last verified 2026-10-02