Repository navigation
Allow plugin dynamic instructions up to 32768 characters - #7050
Merged
Merged
Conversation
configure().instructions and contributeInstructions each truncated at 4096 characters, so a plugin could not deliver a real set of global agent instructions (about 15.7K characters). Both channels now share one PLUGIN_DYNAMIC_INSTRUCTIONS_MAX_CHARS limit of 32768. Static tool instruction snippets keep their 4096 limit. Refs #6995 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 was referenced Dec 1, 2026
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
Plugins add always-on text to thread instructions through
bb.agents.configure().instructionsandbb.agents.contributeInstructions. Each channel silently truncated at 4096 characters:normalizePluginAgentConfigurationinpackages/plugin-sdk/src/internal/host-policy.tsand the contribution loop inapps/server/src/services/threads/thread-runtime-config.tseach sliced to their own hardcoded constant. A real set of global agent instructions (about 15.7K characters, from theagent-instructionsplugin in #6995) loses most of its text, while the user's own<dataDir>/AGENTS.mdand.bb/AGENTS.mdare uncapped.What changed
PLUGIN_DYNAMIC_INSTRUCTIONS_MAX_CHARS = 32_768in the SDK host policy now caps both channels; the server imports it instead of keeping its own constant.backend-contract.tsdoc comments and the plugin-authoring guide (backend-cli-agents.md), and bumped the plugin SDK to 0.6.124.This is the "higher fixed cap" option from #6995. It does not add the install-time instruction-size display the issue also asks for, and over-cap text is still truncated silently (#5565); both remain open.
How you verified
apps/server/test/threads/thread-runtime-config.test.ts: a 15,700-charactercontributeInstructionsresult must arrive whole, and a 40,000-character one must be cut at exactly 32,768. Failed before the fix (the 15.7K text was missing), passes after.packages/plugin-sdk/src/testing/__tests__/fake-plugin-host.test.ts: the same forconfigure().instructions(15,700 kept, 40,000 cut to 32,768). Failed before ("expected length 15700 but got 4096"), passes after.pnpm exec turbo run test --filter=@get-bb/plugin-sdk(410 passed), plus the server test file andturbo run typecheckfor@bb/serverand@get-bb/plugin-sdk.pnpm start:worktree: installed a local plugin that sends about 15.7K characters through each channel, each ending in a unique sentence. A Claude Code thread quoted both final sentences back verbatim.Part of #6995
🤖 Generated with Claude Code