Repository navigation
Conversation
ymichael
force-pushed
the
bb/session-title-summary-is-invalid-for-cjk-charact-thr_f95s7km2rk
branch
from
September 21, 2026 18:12
68e3261 to
28b4c57
Compare
ymichael
force-pushed
the
bb/session-title-summary-is-invalid-for-cjk-charact-thr_f95s7km2rk
branch
from
September 21, 2026 20:46
b97ff4b to
ede5994
Compare
ymichael
deleted the
bb/session-title-summary-is-invalid-for-cjk-charact-thr_f95s7km2rk
branch
September 21, 2026 20:52
ymichael
added a commit
that referenced
this pull request
Nov 18, 2026
## Human comments ## What was wrong bb capped text with raw UTF-16 `.slice(0, n)` / `.slice(-n)` / `.substring` in dozens of places. When an emoji's surrogate pair straddled the cap, the cut kept half of it, a lone surrogate. Much of that text goes to agents: child-thread output reported to the parent (`child-thread-notifications.ts`), the restart-resume note (`restart-resume.ts`), plugin instructions (`thread-runtime-config.ts`, `host-policy.ts`), MCP/browser/annotation tool results, and more. It also goes to push notifications and terminal titles. `JSON.stringify` escapes a lone surrogate as `\ud83d`. Codex's serde-based app-server rejects that escape and drops the whole message without answering. bb then waits on `thread/start` until it times out. Nothing made text well-formed before it left for a provider, so any one bad cut could break a turn. T3 Code fixed the same class: pingdotgg/t3code#30369, #29168, #29653, #29906 (#30369 pointed us at it). ## What changed - **Safe cuts where text reaches an agent or a person.** Caps on user or agent text now use `sliceUtf16Head` / `sliceUtf16Tail` from `@bb/text-utils` (added in #3995, but #7050's plugin-instructions cap and older cuts such as child-thread output never used them): server, daemon, app, desktop, CLI, web, packages, and first-party plugins. Plugins get the same functions through the SDK (below) instead of local copies. Cuts on text that cannot hold a surrogate pair (ASCII slugs, handles, hostnames, URLs, tag names) and log-only or dev-tooling output are left alone. The page script in agent-annotations is stringified into the browser, so its copy lives inside the injected functions. `boundedMarkdownPreview` now cuts with `sliceUtf16Head` and checks for a split token against the original text. - **Well-formed at the provider boundary.** `serializeJsonRpcLine` in `bridge-kit/runtime-json-rpc.ts` replaces lone surrogates with U+FFFD in every string the runtime sends to a provider bridge (requests, results, errors), so every provider gets well-formed turn input and instructions. It serializes with plain `JSON.stringify` and only re-serializes with the replacer when the line holds an escaped lone surrogate (`\ud`), so normal traffic pays nothing extra (20k-string message: 1.3 ms plain, 4.6 ms always-replacer, 1.5 ms with the check). The ACP message stream and the Codex bridge's app-server writer use the same function, which also covers text a bridge builds itself. New `toWellFormedUtf16` in `@bb/text-utils`. - **Plugin SDK exports.** Core's own functions, re-exported with `experimental_` names (entries in `docs/api_to_audit.md`, symbols in the Plugin Guide): - `experimental_sliceUtf16Head` from `@get-bb/plugin-sdk` (server code) and `@get-bb/plugin-sdk/app` (wired in `plugin-sdk-app-impl.tsx`). - `experimental_sliceUtf16Head` / `experimental_sliceUtf16Tail` from `@get-bb/plugin-sdk/host`, because the root SDK runtime in host bundles is a stub. Browser Automation's host code and the Claude Code and Codex providers use it. - `experimental_serializeJsonRpcLine` from `@get-bb/plugin-sdk/provider-bridge`, used by the Codex app-server writer. - Agent Annotations keeps an inline copy because its page script is stringified into the browser. The 10 plugins that use the runtime-provided root or `/app` export require `bbPluginSdk >=0.6.161`, as #6760 did for the host-path helpers. - No lint guard: the provider boundary makes any future raw cut harmless to providers, so a name-based heuristic rule was not worth its false positives. - No server/daemon wire change, so `HOST_DAEMON_PROTOCOL_VERSION` stays the same. The JSON-RPC change is between the daemon and its own bridge processes. `@get-bb/plugin-sdk` is bumped to 0.6.161 for the new exports and the changed bridge code. `@bb/text-utils` was added as a dependency to the packages that newly import it. ## How you verified **Repro on origin/main (502cf5a), real dev instance (`pnpm start:worktree`) with real Codex:** a local plugin contributed instructions `"x".repeat(32767) + "😀 …"`; the 32,768-char cap cut the emoji in half. - Codex thread: `Command thread.start failed — codex app-server did not answer thread/start within 60000ms` (status `error`). - Control with the plugin disabled: the thread replies `ok`. - Talking to `codex app-server` (codex-cli 0.169.0) directly with the same bytes: stderr `Failed to deserialize JSONRPCMessage: unexpected end of hex escape at line 1 column 32921`, and no response. With a safe cut, both `thread/start` and `turn/start` succeed. - Claude Code accepted the same instructions, so this broke Codex turns but not Claude Code turns. **After the fix, same dev data dir and plugin enabled:** the Codex thread starts and replies `ok`. **Tests added:** - runtime JSON-RPC: a lone surrogate never reaches the provider's stdin, while real emoji pairs survive. - Cut boundaries for child-thread output, plugin instructions, restart-resume command names, and push-notification `truncate`. - `toWellFormedUtf16`. **Commands:** - `pnpm exec turbo run typecheck --filter='...[origin/main]'`: 112/112 passed. - `pnpm exec turbo run test lint --filter='[origin/main]'`: everything passed except `@bb/app` `CommandPalette.test.tsx` and `@bb/server` `install-machine-script.test.ts`. Both were timeouts while a dev instance was running and pass on rerun; neither touches changed code. - `pnpm exec turbo run prepare:bundled`: 70/70 passed. **After trimming the change (811d979):** `pnpm exec turbo run typecheck lint --filter='...[HEAD]'` 151/151, `pnpm exec turbo run test --filter='[HEAD]'` 29/29, `prepare:bundled` for the touched plugins 12/12. On a rebuilt `pnpm start:worktree` with real Codex, a plugin whose instructions put an emoji at the 32,768 cap and one that sends a raw lone surrogate both get `ok`. **After moving the helpers into the SDK (2d6fa48):** `pnpm exec turbo run typecheck lint --filter='...[HEAD]'` 129/129, `pnpm exec turbo run test --filter='[HEAD]'` 23/23 (including `@bb/app`, `@get-bb/plugin-sdk` and the Plugin Guide), `prepare:bundled` for the 12 touched plugins 18/18. The built bundles show the Codex host bundle inlining `serializeJsonRpcLine`, the Docs server importing `experimental_sliceUtf16Head` from the runtime root, and Browser Automation's app reading it from the app runtime. Both live Codex checks still reply `ok` on a rebuilt `pnpm start:worktree`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
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/domaindespite having no domain semantics.What changed
Added a dependency-free internal
@bb/text-utilspackage 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
sliceUtf16HeadandsliceUtf16Tailhelpers 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 noHOST_DAEMON_PROTOCOL_VERSIONchange.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, andbb-plugin-tasksthat 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-tasksAll 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.mjspassed.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 --checkalso passed. Commands: