Skip to content

fix(search): read a long line of unclosed brackets in one pass - #3565

Merged
devswha merged 1 commit into
mainfrom
fix/search-unclosed-brackets
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/search-unclosed-brackets

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Found by a code review of shared/ and server/core/ (finding: shared/conversation-search.ts:70). No issue was filed.

Change

GET /api/pane/conversation/search reads every turn it searches through plainText, 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). searchConversationPages runs 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:

  • a label ends at the first ] of its line, so every [ before it shares that end, and when the first of them is no link none is;
  • with no ) 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

  • New: the scan against the pattern as it was written, over every text of up to six of [ ] ( ) ! \n a (137,257 texts) and 20,000 longer generated ones, plus one hand-written line with each shape.
  • New: four lines of 200,000 characters ([[[…, [[[…], ![![…, [a]([a](…) 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).
  • Outside the tree: 3,060,800 texts over wider alphabets (\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).
  • Skipped: bun run check full, the integration and browser lanes (no route, frame or UI change).

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Searches across conversations with very long, unmatched brackets no longer stall, helping keep the server responsive.
    • Search results remain available for matching text earlier in the conversation, even when a later line contains unmatched brackets.

Search text extraction now handles Markdown links and images with a scanner instead of a global regex. Tests cover generated inputs and long malformed bracket patterns. The changelog reports that searches over long lines of unclosed brackets no longer stall the server.

Changes: Markdown Search Text Handling

Layer / File(s) Summary
Link-label scanning and regression coverage
shared/conversation-search.ts, shared/conversation-search.test.ts, changelog.d/search-unclosed-brackets.md
plainText uses linkLabels to retain link and image labels while omitting destinations and image markers. Tests compare output against reference behavior and check that long malformed bracket inputs remain searchable. The changelog describes the prior server stall.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#3013: Changed-turn checks use searchableText, the text extraction path changed here.
  • devswha/ovis#3001: Changed-turn matching uses searchableText, which this PR updates.
  • devswha/ovis#2988: Changed-turn matching accounts for Markdown links through searchableText, which this PR updates.
Merge Risk: Minimal · up to 3a4f5

The change addresses searches stalled by long lines of unclosed brackets. No unresolved merge-blocking issue was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the search fix and the long unclosed-bracket performance issue.
Description check Passed The description explains the problem and resulting behavior, and lists validation results and skipped checks. It also states that no issue was filed, which addresses the template’s issue-link guidance…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem and resulting behavior, and lists validation results and skipped checks. It also states that no issue was filed, which addresses the template’s issue-link guidance for features.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f885760 and 3a4f564.

Files selected for processing: 3

  • changelog.d/search-unclosed-brackets.md
  • shared/conversation-search.test.ts
  • shared/conversation-search.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate: FAIL

Local merge gate: FAIL #3565 merge=65c2351b85a8 head=3a4f564ebda9 main=e46e13bf45a0 on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 in 588s, reruns=2

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 herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 (13% busy before the start, host load 60.33; shards=4 unit_workers=8 browser_main_workers=2 browser_other_workers=16). Scope: full. Native Windows install and the macOS checks are not part of this gate.

Step Command Result Seconds Counts
fast-install bun install --frozen-lockfile pass 0 -
release-guards bun scripts/release-guards.ts --base e46e13bf45a0 pass 0 -
fast bun run check fast pass 199 tests 14699 pass / 0 fail; check steps 6 ok / 0 failed
integration-install bun install --frozen-lockfile pass 0 -
integration bun run check integration pass 218 tests 1386 pass / 0 fail; check steps 3 ok / 0 failed
browser-main-install bun install --frozen-lockfile pass 0 -
browser-main-build bun run build pass 12 -
browser-main BROWSER_SCRIPTS=ui-regression,ui-contexts-regression bun run check run -- bun scripts/ci-browser-parallel.ts pass 391 browser scripts 2/2 passed
browser-other-install bun install --frozen-lockfile pass 0 -
browser-other-build bun run build && bun run build:shell pass 18 -
browser-other BROWSER_EXCLUDE=<those two> bun run check run -- bun scripts/ci-browser-parallel.ts fail (exit 1) 561 check steps 0 ok / 1 failed; browser scripts 199/200 passed

Reruns:

  • browser scripts/palette-machines-demo-regression.ts failed, then passed on its automatic second run
  • browser scripts/relay-e2e-regression.ts failed, then passed on its automatic second run

Total 588s.

@devswha
devswha merged commit 03481c8 into main Nov 10, 2026
29 of 31 checks passed
@devswha
devswha deleted the fix/search-unclosed-brackets branch November 10, 2026 11:34
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 3a4f564ebda9 as 03481c881a04 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

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).

devswha added a commit that referenced this pull request Nov 10, 2026
…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]>
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