Repository navigation
search: searching every chat reads a trigram index, about 70x faster on 50,000 messages, and finds Привет, École and Über - #477
Merged
Conversation
…ge, about 70x faster on 50,000 messages Searching all chats ran lower(text) LIKE '%needle%' over every row: 78 ms p95 in bench:persistence (50,000 messages), blocking the server for that long unless the worker ran it. A contentless FTS5 trigram index (detail=none) of each text message's text and each activity's tool name now narrows a needle of three or more characters to the rows that hold all of its trigrams; the same LIKE still decides every match, so results do not change. A property test checks that against a brute-force reading for any messages, edits, deletions and needle. bench:persistence, search p95: 76-81 ms -> 0.43-0.62 ms; event loop max with searches: 82-87 ms -> 3-15 ms. Costs: a message write's p95 0.12 -> 0.20 ms; the index adds about 15% to messages.db; the first start after the update builds it once (about 0.6 s per 50,000 messages). A needle found in most messages, or under three characters, still reads every candidate row.
…ривет, École, Über) SQLite's lower() and LIKE fold ASCII letters only, while the query is lowercased in JavaScript, so a search for "Привет" never found a message saying "Привет": the needle became "привет" and the row kept its capital П. Rows are now lowercased by the same toLowerCase() as the query (a deterministic SQL function on the search's connection) and matched with instr. The trigram index folds case itself, so it still narrows a search; a needle holding U+0307 (from "İ", which lowercases to i + U+0307) reads every row, since no indexed text holds that pair. The property test now uses an alphabet with Cyrillic, Greek sigmas, İ/ı, ß/ẞ, DŽ/Dž/dž, the Kelvin and Ångström signs and a ligature, against toLowerCase().includes. A needle under three characters, or found in most messages, still reads every candidate: that path now costs 17-34% more (35 -> 47 ms for a two-letter needle on 50,000 messages).
…itten, checked for every cased letter SQLite's FTS5 case folding is older than JavaScript's toLowerCase(): it has no pairs for Cherokee, Georgian Mtavruli, Adlam, Osage and the Greek and Cyrillic letters added since Unicode 7, and keeps İ apart from i, so a needle folded by one could miss rows folded by the other (1,395 of 9,234 checks missed). A search now asks the index for each three-character window written any way that lowercases to it (İ standing for an i that ends a window, Σ for ς), so the index only has to apply the same tokenizer to both sides. A test runs every letter Unicode gives a lower case at each place in a window. The index triggers read a tool name only from valid JSON, so one damaged row cannot stop the database from opening.
…no trigram of a private conversation A contentless FTS5 index keeps a deleted row's trigrams until its segments merge, and VACUUM does not merge them, so a Team Cloud export that removed a member's private conversations still held trigrams of their words. The snapshot now drops the index and its triggers; the database builds it again from the rows left when it next opens.
… text is lowercased by SQLite A search in one conversation asked the trigram index for every conversation's candidates first: 1 ms became 20-44 ms for words most messages hold. It reads the conversation's rows by thread again. SQLite's lower() agrees with toLowerCase() on ASCII text, so only a value with other characters calls the JavaScript lowercase.
…e-text-index.ts message-db.ts is at its size ratchet; the FTS5 setup moves out unchanged.
…instead of 30 ms on the first search No letter past U+1FFFF has a lower case (the last is U+1E921); a test fails if a later Unicode adds one.
…ite runs faster than instr
2 of 3 tasks
… and the guest skill card test stages four kinds of work bacb532 left two tests red on dev. Its new skill_manage description dropped the word reusable, so find_tool ranked skills_list first for "save this procedure as a reusable skill"; the description says reusable SKILL.md again (a skill is recurring work, which that change keeps). Its duplicate check turns away a create that covers an existing skill, and the guest skill card test staged four skills with one description, the same as an earlier test's: each now has its own kind of work. (cherry picked from commit 78889fc)
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file.
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
Yabuku-xD
added a commit
to Yabuku-xD/duskbot
that referenced
this pull request
Dec 1, 2026
…list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. (cherry picked from commit 54f5c51)
…s 60 servers link from their own addresses Every link chaos run since the per-address limit on new links (adc99d7, Nov 14) was cancelled at CI's 60-minute limit, on main pushes, the weekly run and every PR that touches the link service: the scenarios finished in about five minutes and printed their table, but a socket or timer a scenario left open held the process. The run now exits once its results are written. The storm's 60 servers set up their links over one connection, so the node's front gave them one address, which the limit refused after 30 (Too many new links from here); each now uses its own connection, as 60 machines would. Locally, --quick passes all 12 scenarios and exits in 5.6 minutes. (cherry picked from commit 83ab615)
…y list's retries chat-mcp-tools' shutdown verdict, memory-order and the encrypted workspace restore failed in PR DuskBotAI#479's run 46740020170, whose change does not reach them, and pass locally. (cherry picked from commit c47197f)
…os job installs no packages The job runs `node apps/link-service/chaos/run.mjs` straight after checkout, so the undici import failed with ERR_MODULE_NOT_FOUND before any scenario ran.
…ds nothing for 8 s, as the app does src/lib/live-events.ts gives up on a dial that sends nothing in LIVE_EVENTS_OPEN_MS (8 s) and dials again. The probe dropped a quiet stream only after it had sent something, so one silent dial after node-5xx's 502s held it down until the relay closed it, about 90 s, and failed the scenario in CI on five of seven runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Searching every chat read every message:
lower(text) LIKE '%needle%'over the wholemessagestable. Onpnpm bench:persistence(50,000 messages) that is about 80 ms per search, and the server stalls for that long unless the search worker runs it.The same query also missed words with a capital letter outside A-Z. SQLite's
lower()andLIKEfold only ASCII, while the query is lowercased in JavaScript, so ondeva search for Привет finds nothing in a chat that says "Привет, команда". "École" and "Über" behave the same way, as does any Cyrillic, Greek or accented capital.This PR:
messages_search, a contentless FTS5 trigram index (detail=none) of each text message's text and each activity's tool name. It narrows a search of 3 or more characters to rows that hold its trigrams. The search query's own comparison still decides every match, so the index never adds a result;toLowerCase()as the query (a deterministic SQL function on the search connection). ASCII-only values keep SQLite'slower(), which gives the same result for them;İapart fromi. A query that relied on it missed 1,395 of 9,234 checks over every cased letter;messages_searchbeforeVACUUM. A contentless index keeps a deleted row's trigrams until its segments merge, and the snapshot comment says no search index may still hold a private conversation's words. The index is built again from the remaining rows when the database next opens;server/message-text-index.ts, becausemessage-db.tsis at its size ratchet. This is a move only, with no change.A search in one conversation does not use the index: its rows are already indexed by thread.
Numbers
pnpm bench:persistence(50,000 messages, an absent needle), Apple Silicon, Node 26.13.1, SQLite 3.54.1, two serial runs each. The machine had other load (load average about 5), so read these as ranges:devThe index cannot help a needle that most messages hold. Here is my own script on the same machine: 50 threads × 1,000 messages of about 1 KB, every message made from the same 20 words, median of 15:
dev, all chatsdev→ PRzq(under 3 characters, no index)alpha(in every message)Foxtrot Golf(in most messages)So a search for a word in almost every message, across all chats, is about 30-50% slower. A word in few messages is about 100x faster.
Other costs:
messages.dbgrows about 15% (52.4 MB to 60.5 MB on synthetic text).toLowerCase()when SQLite'slower()does not already match.How it was checked
server/message-search-query.test.ts:toLowerCase()text holds the lowercased needle. Its alphabet has Cyrillic, Greek sigmas,İ ı,ß ẞ,DŽ Dž dž, the Kelvin and Ångström signs andfi. I ran it 20,000 times locally;İ→iform. Each one fails the tests. The new tests also fail on the version before the case fix.workspace-backup-team-private.test.ts: the snapshot holds nomessages_searchtable or trigger. A database opened from it builds the index again and finds the team's words but not the private ones. Without the drop, this test fails.dev'smessage-db.tswrote a database, then this branch opened it. The index and triggers were created. In-process, worker and thread-scoped searches all find "Привет", "привет" and "École", whichdevdoes not find in the same file.control-dusk launch,new-bot, twosend+waitturns with the fake engine, thenGET /api/search(the worker path). "Привет", "ПРИВЕТ" and "école" find the Russian message, "quarterly" finds the English one, and "absent words" finds nothing.pnpm typecheckandpnpm lintpass. The CI source guards pass, includingfile-size-ratchet.server/that touch messages, search, backups, routes, email, stores or memory: 158 pass, 1 skipped (1,855 tests). On this Mac the wholevitest rundid not finish: it takes hours on the default single worker, and the Vitest pool crashed withEPIPEat 8 workers. CI's shards cover the rest.pnpm typecheck,pnpm lintandpnpm testpass (typecheck and lint pass; forpnpm test, see the line above)No new runtime dependency.
fast-checkis a dev dependency for the property test. The property-tests PR from this fork also adds it, so whichever merges second needs a one-line rebase ofpackage.jsonandpnpm-lock.yaml.Not in this PR:
ensureRecallIndexcreatesmessages_ftsand runs itsrebuildas two separate statements. If the process stops between them, later starts skip the rebuild. I found this by reading the code, not by running it, and left it for a separate change.This branch also carries the commits of #483: the fix for two tests red on
dev(thefind_toolranking and the guest skill card), the flaky-test retry list for tests that failed at random in CI on Dec 1, and the link chaos fix, so this PR's CI can pass. They drop out of the diff once #483 merges.