Repository navigation
fix(search): read a long line of unclosed brackets in one pass - #3565
Conversation
The conversation search drops a link's address with a pattern that starts over at every `[` and reads on to the line's end from each, so a line of brackets that never close took its length squared: 0.4 s for 20,000 characters, 36 s for 200,000. The search route runs it synchronously for every turn it reads, and its one-second budget is checked only between pages, so one such line in a conversation stalled every terminal stream and request on each search. The links are now read by a scan that gives what the pattern gave: the test compares the two over every text of up to six link characters and 20,000 longer ones. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Local merge gate: FAIL
The Linux suites of the required checks (Fast checks, Integration and browser), run on main e46e13b with this PR's head 3a4f564 merged in (local merge 65c2351b85a8, not pushed), as groups side by side in the self-hosted CI runner image on
Reruns:
Total 588s. |
Merge passMerged head
Both reviewers CLEAR (Claude Opus 5.5, Codex Terra); the old and new scans gave identical output on 1.19 million texts. LOW for a follow-up: the same quadratic link pattern is still in the browser (src/lib/userMessageFold.ts, ChatView's Copy as plain text). |
…seen Connecting (#3592) ## Why `scripts/relay-shell-browser-qa.ts` failed twice in a row in two local merge gates on 2026-11-10 (the gates of #3565 and #3566, on unrelated changes) and is ranked flaky in CI: `TimeoutError: waitFor: Timeout 20000ms exceeded`, waiting for `main[data-relay-state="connecting"]`, at `:432` called from the stopped-relay block (`:1249`). Two failures in a row fail the gate. In that block the relay is stopped, so the connection is refused at once. `pairFrom` clicks Pair and only then starts waiting for the Connecting screen, which the refusal has already ended. Measured in the page with a `MutationObserver`: Connecting is on screen for 16 to 25 ms. - **Why it usually passes:** unloaded, the wait starts inside that window. - **Why it fails next to 16 browser workers:** the click's return and the wait's first look take longer than that, the screen is gone for good, and the wait runs out its 20 s. A longer wait would not help. It is not a product race: a relay that refuses at once should leave that screen at once. ## What The block opens its page with the bridge held and releases it once Connecting was seen, the seam the block before it already uses for the silent relay (`open({ mode: "hold" })`, `bridge.release.resolve()`). Three lines, test-only. The step proves what it did: Pair with the relay gone shows Connecting, then "The relay could not be reached", over one socket. The page sees the same events (open, then close 1011); only the close now comes after the script has seen Connecting. ## Proof In the CI runner image, a container of its own, one browser worker: | Run | Result | |---|---| | `main` + the wait started 100 ms later (a scratch patch, not in this PR) | fails 2 of 2 with the gate's signature; Connecting on screen for 16 ms | | this change + the same delay | passes 2 of 2; Connecting on screen for 108 ms | | this change, plain | passes 3 of 3 (117 s each) | ## Validation - `bun run check fast`: pass on this head (14804 unit tests pass, 0 fail). - `scripts/relay-shell-browser-qa.ts` in the runner image: the rows above. - Skipped: the rest of the browser lane and the integration suite (one step of one script changed); a 16-worker lane was not run here (the next gates are that). ## Not in this PR - `scripts/relay-e2e-regression.ts` fails its first attempt in most gates for another reason (a warning banner of a pane the app opened by itself, counted over the whole page); its fix is the next PR. - The same shape, a wait for Connecting after a click, is at eleven other call sites of this script. There the next screen needs a PC's answer through the relay, so Connecting lasts, and none failed in the reports read. - `:784` waits 62 s of real time for the page's 60 s introduction wait under a 75 s bound; no failure seen. - `scripts/relay-dashboard-fixtures.ts:153`, "no account key after the sign-in": flaky twice in CI, not investigated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.2 <[email protected]>
Found by a code review of
shared/andserver/core/(finding:shared/conversation-search.ts:70). No issue was filed.Change
GET /api/pane/conversation/searchreads every turn it searches throughplainText, which dropped a Markdown link's address with/!?\[([^\]\n]*)\]\([^)\n]*\)/g. That pattern starts over at every[and reads on to the line's end from each, so a line of brackets that never close costs its length squared: 0.4 s for 20,000 characters and 36 s for 200,000 (Bun 1.4.3).searchConversationPagesruns it synchronously for each page and checks its one-second budget only between pages, so one such line in a conversation (a pasted log, minified text, an agent's output) stalled every terminal stream, WebSocket and request on each search of that pane.The links are now read by a scan,
linkLabels, that gives what the pattern gave, in one pass:]of its line, so every[before it shares that end, and when the first of them is no link none is;)before the line ends, no later link of that line closes either.What a search reads is unchanged. The page imports the same file (
matchPart,pickedTurn), so it gains the same bound. No contract change.Tests
[ ] ( ) ! \n a(137,257 texts) and 20,000 longer generated ones, plus one hand-written line with each shape.[[[…,[[[…], are read within the test's 5 s timeout. On main they take 4 to 36 s each, and bun fails a synchronous test that returns after its timeout (checked with a probe).\r, tabs,$1,$&, quotes, other Markdown marks, Hangul, emoji, a lone surrogate, link fragments) compared with the old pattern: none differ. The scan measured at 100k to 800k characters grows linearly (about 1.4 ms at 800k).Validation
bun test shared/conversation-search.test.ts: 26 pass.bun run check fast: pass (unit 14470 pass, 0 fail, 50 skip; typecheck, build, generated types and themes fresh).bun run check full, the integration and browser lanes (no route, frame or UI change).🤖 Generated with Claude Code