Repository navigation
Conversation
Thread title generation measured text in whitespace-delimited tokens and UTF-16 code units, which is meaningless for Chinese, Japanese and other scripts that do not separate words with spaces. Root cause, in apps/server/src/services/threads/title-generation.ts: - shouldGenerateThreadTitle required `text.split(/\s+/u).length >= 5`. A Chinese or Japanese prompt of any length is one token, so inference was never attempted and the thread kept the raw prompt prefix as its label. Reproduced on a running instance: a 64-character Chinese prompt recorded `reason: "too-short"` with `durationMs: 0`, while a 123-character English prompt produced "Investigate sidebar environment labels". - sanitizeGeneratedTitle capped titles at five space-delimited words. That is a no-op for Chinese and Japanese (any length passed through) and destructive for Korean, which cut "포크 후 사이드바 스레드 행의 잘못된 환경 배지 조사" down to the dangling "포크 후 사이드바 스레드 행의". - deriveTitleFallback sliced at 77 UTF-16 code units, which splits a surrogate pair for astral characters such as 𠮷 and emits a lone surrogate, and spends the 80-unit budget on text that renders twice as wide. All three now share one measure in services/lib/text-measure.ts: Intl.Segmenter for word and grapheme boundaries, plus a display width that charges wide characters two columns. Eligibility counts word-like segments, the generated title breaks at the last word boundary within a 48-column budget, and the fallback elides on grapheme boundaries within an 80-column budget. The prompt template no longer states the limit in English words. Latin behaviour is unchanged: display width equals length for ASCII, and "Investigate Extremely Long Generated Thread Title Output" still yields "Investigate Extremely Long Generated Thread". Verified on a running instance from this worktree. Before the fix, Chinese and Japanese threads were untitled and the sidebar showed the full prompt; after it they are titled "调查分叉线程环境标记错误" and "フォーク後の環境バッジ誤表示を調査", Korean gained "포크 후 사이드바 환경 배지 오류 조사", English still yields "Fix sidebar thread environment labels", and the short "修复这个错误" is still correctly skipped. Co-Authored-By: Claude Opus 5 <[email protected]>
ymichael
force-pushed
the
bb/session-title-summary-is-invalid-for-cjk-charact-thr_f95s7km2rk
branch
from
September 21, 2026 16:45
e8784bd to
da6065d
Compare
ymichael
deleted the
bb/session-title-summary-is-invalid-for-cjk-charact-thr_f95s7km2rk
branch
September 21, 2026 17:03
ymichael
added a commit
that referenced
this pull request
Sep 21, 2026
## Human comments ## What was wrong The Unicode-aware text measurement introduced in #3990 was local to the server title generator, while other compact user-facing labels still treated JavaScript UTF-16 code-unit length as display width. Wide-script text could therefore occupy roughly twice its intended terminal or UI width. Compact-label truncation could split grapheme clusters such as joined emoji, while hard `slice()` boundaries could split astral characters at surrogate-pair boundaries. The repository's generic HTML escaping and UTF-16 slicing helpers also lived in `@bb/domain` despite having no domain semantics. ## What changed Added a dependency-free internal `@bb/text-utils` package and moved text measurement, UTF-16-safe slicing, and HTML escaping out of `@bb/domain`. Core server, database, desktop, client, CLI, Connect, host-daemon, thread-view, provider-bridge, and Plugin Guide consumers import those primitives from the dedicated package. The Tasks and Workflows plugins keep equivalent narrowly scoped helpers inside their own packages rather than depending on a private `@bb/*` utility package. CLI table widths and truncation, queued-message previews, terminal command titles, timeline separators, workflow fallback labels, and Tasks delegated-thread titles use grapheme-safe display-width measurement. New `sliceUtf16Head` and `sliceUtf16Tail` helpers preserve the existing code-unit limits while preventing hard caps from splitting surrogate pairs in blocker and conversation summaries, queued-message reasons, provider presentation text, todo snapshots, terminal titles, daemon payload previews, and provider stderr tails. Connect and Plugin Guide HTML generation now use the shared escaper. Emoji width detection uses Unicode emoji-presentation properties and recognizes variation-selector and keycap sequences. Flags, hearts, airplanes, keycaps, and watches occupy two columns, preventing CLI table rendering from unexpectedly truncating titles or emitting lone surrogates. Text-presentation symbols remain narrow. The same detection is used in both plugin-local helpers. Added focused coverage for HTML escaping, surrogate boundaries, CJK text, astral ideographs, joined emoji, and rendered emoji tables. There are no server/daemon wire changes and no `HOST_DAEMON_PROTOCOL_VERSION` change. The queued-message preview adds 99 raw bytes to the measured app boot payload. After rebasing, the raw boot allowance increases by 512 bytes relative to current main, from 1,826,261 to 1,826,773 bytes; the Brotli cap remains unchanged. The current production bundle is 1,698.3 KiB raw / 417.3 KiB Brotli and passes the bundle budget. ## How you verified Added regression tests in `@bb/text-utils`, `@bb/cli`, `@bb/client-core`, `bb-plugin-workflows`, and `bb-plugin-tasks` that fail under code-unit truncation and pass with display-width truncation. Existing database and desktop coverage verifies the moved UTF-16 and HTML helpers at their consumers. Ran: `pnpm exec turbo run test typecheck --filter=@bb/text-utils --filter=@bb/domain --filter=@bb/db --filter=@bb/server --filter=@bb/cli --filter=@bb/client-core --filter=bb-plugin-workflows --filter=bb-plugin-tasks` All 24 original Turbo tasks passed. The run included 3,037 server tests, 826 CLI tests, 590 database tests, 394 Tasks tests, 301 client-core tests, 248 Workflows tests, 213 domain tests, and 11 initial text-utils tests. After localizing the plugin helpers, both plugin typechecks and all 642 plugin tests passed, and the Tasks bundled-plugin build passed. Desktop typecheck and the 22 directly affected local-view, log-viewer, and existing-server-dialog tests passed. For the expanded core sweep, all 12 affected typecheck tasks passed, along with 5,088 app tests, 3,037 server tests, 411 thread-view tests, 284 provider-bridge protocol tests, 121 Connect tests, 76 Plugin API map tests, and 13 text-utils tests. The host-daemon suite passed 726 of 727 tests on its broad concurrent run; its unrelated Git credential-prompt timing test passed immediately when rerun in isolation, as did the directly affected 35 terminal-manager tests. A fresh production app build and `node apps/app/scripts/check-bundle-budget.mjs` passed. The emoji-width regression tests failed before the fix (all five rendered-table cases) and passed afterward. The focused verification passed all 38 tests: 19 text-utils tests, 7 CLI table tests, 10 Tasks delegation tests, and 2 Workflows UI-view tests. Text-utils typecheck and `git diff --check` also passed. Commands: ```sh pnpm exec turbo run test typecheck --filter=@bb/text-utils pnpm exec turbo run test --filter=@bb/cli -- src/__tests__/table.test.ts pnpm exec turbo run test --filter=bb-plugin-tasks -- delegate/delegate.test.ts pnpm exec turbo run test --filter=bb-plugin-workflows -- src/ui-view.test.ts ``` > AGENT GENERATED
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.
Human comments
What was wrong
Thread title generation measured text in whitespace-delimited tokens and UTF-16 code units, neither of which means anything in scripts that do not separate words with spaces.
shouldGenerateThreadTitlegated inference ontext.split(/\s+/u).length >= 5, so a Chinese or Japanese prompt is one token at any length and the model was never called — the thread kept the raw prompt prefix as its label forever. The same mistake appears twice more:sanitizeGeneratedTitlecapped titles at five space-delimited words, which is a no-op for Chinese and Japanese (any length passed through) and destructive for Korean, andderiveTitleFallbacksliced at 77 UTF-16 code units, which splits a surrogate pair on astral characters such as 𠮷 and emits a lone surrogate. Reported on Discord (#bugs, laogui6132, 2026-09-21, "Session title summary is invalid for cjk characters"); no GitHub issue was filed. The sidebar is not involved —.bb-thread-titletruncates with CSS ellipsis, which is width-based and script-agnostic.What changed
New
apps/server/src/services/lib/text-measure.tsgives all three call sites one measure:Intl.Segmenterfor word and grapheme boundaries, plus a display width that charges wide characters two columns. Inapps/server/src/services/threads/title-generation.ts, eligibility now counts word-like segments, the generated title breaks at the last word boundary within a 48-column budget, and the fallback elides on grapheme boundaries within an 80-column budget.packages/templates/src/templates/generate-thread-metadata.mdno longer states its limit in English words.Latin behaviour is unchanged by construction: display width equals length for ASCII, so
deriveTitleFallbackis byte-identical on English input and the pre-existing assertion"Investigate Extremely Long Generated Thread Title Output"→"Investigate Extremely Long Generated Thread"still holds untouched. No wire, CLI, or configuration surface changed, so noHOST_DAEMON_PROTOCOL_VERSIONbump.How you verified
Reproduced on a running instance from this worktree (
pnpm start:worktree) before changing anything, creating threads viabb thread spawnwhose first message was CJK text of varying lengths. Before the fix, the Chinese (64 chars) and Japanese (57 chars) threads recordedreason: "too-short"withdurationMs: 0— proving the model was never called — and stayed untitled, while a 123-character English prompt producedInvestigate sidebar environment labels. The sidebar DOM for those rows contained the entire prompt. Korean reached inference but was cut to the dangling포크 후 사이드바 스레드 행의, losing its verb.Rebuilt and re-ran the same inputs after the fix:
too-short)调查分叉线程环境标记错误too-short)フォーク後の環境バッジ誤表示を調査포크 후 스레드 환경 배지포크 후 사이드바 환경 배지 오류 조사修复分叉后侧边栏徽章修复分叉后 sidebar badge 错误Investigate sidebar environment labelsFix sidebar thread environment labelstoo-short)too-short) — correctly skipped23 new or changed test cases in
apps/server/test/services/text-measure.test.tsandapps/server/test/threads/title-generation.test.tscover Chinese, Japanese, Korean, mixed and English, surrogate pairs, emoji ZWJ clusters, and the hard-cut path when a single word exceeds the budget. Each fails on the parent commit and passes here.pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates— 3032 server tests and 47 template tests pass.pnpm exec turbo run typecheck lint --filter='...[origin/main]'— 67 tasks, clean.🤖 Generated with Claude Code