[Bug]: OpenCode CLI OSC title leak pollutes agent inventory — Agent not found → UnknownError #7754
Bug#
OpenCode <=1.18 writes OSC title sequence ESC ]0;<cwd>: ready BEL to stdout for every non-help command even when stdout is a pipe. T3 captures that via ChildProcessSpawner + collectStreamAsString and the parsers stored a polluted agent id:
Agent not found: "\u001b]0;imbios: ready\u0007build". Available agents: build, explore, general, plan
Followed by generic wrapper:
UnknownError: UnknownError
at <anonymous> (//root/chunk-09733s3k.js:1096:2069)
at SessionPrompt.createUserMessage (//root/chunk-09733s3k.js:1096:9954)
...
at SessionHttpApi.promptAsync (//root/chunk-ys5kjase.js:2:84381)
Evidence#
~/.t3/userdata/logs/provider/events.*.logshows twosession.errorper turn: first is the polluted agent, second is the generic UnknownError.projection_threads.model_selection_jsonpolluted for 3 threads:
{"instanceId":"opencode","model":"opencode-go/mimo-v2.5","options":[{"id":"agent","value":"\u001b]0;imbios: ready\u0007build"}]}
- Repro:
opencode agent list 2>&1 | cat -v→^[]0;tmp: ready^Gbuild (primary)even withenv -i PATH=... opencode agent listandTERM=dumb— opencode binary itself leaks, not shell/ghostty. - Also
opencode models --verbose 2>&1 | cat -v→^[]0;tmp: ready^Gopencode/big-pickle— caused model inventory to drop to 0 without the fix (SLUG_RE didn't match). Skills JSON degraded to[].
Root cause#
apps/server/src/provider/opencodeRuntime.ts:208,270 parseModelsCliOutput/parseAgentListCliOutput assumed clean stdout. No strip of OSC ESC ]...BEL / CSI ESC[...m.
Fix#
See PR from fork (ImBIOS/t3code#2 merged to ImBIOS:main, will open upstream PR). Summary:
packages/shared/src/stripTerminalEscapes.ts: sharedstripTerminalEscapes/sanitizeTerminalValueopencodeRuntime.ts: strip beforeparseModels/Agent/Skills, defensive at entryOpenCodeProvider.ts: sanitize inventory agent names/variants +--versionparsingOpenCodeAdapter.ts+OpenCodeTextGeneration.ts: sanitize storedagent/variantbeforesession.promptAsyncpackages/shared/src/model.ts: sanitize persisted option values and model slugs on read (repairs polluted threads without DB migration)- Tests: regression cases for OSC/ANSI in both parsers
Upstream#
Should be fixed in sst/opencode as well: CLI should write OSC title to /dev/tty/stderr only when isTTY, not stdout pipe. T3 fix is defensive regardless.
Repro steps#
opencode agent list | cat -vshows OSC prefix- Start T3 server, no external opencode server →
loadInventoryFromClistores polluted agent - New thread → send → fails with UnknownError stack
Expected#
Clean agent inventory, no OSC leak.
Related report #7716 covers the same problem and adds useful evidence.
The exact broken build-agent value contains the OSC title fragment ready build. Issue 7754 documents the same stdout escape leak, failed agent selection, and persisted polluted value, with a more complete reproduction. This is not the separate plan-mode filter or custom-agent enumeration issue.
I'm linking the report here before I close it as a duplicate during an automated pass. The source report and its attachments will remain available at #7716.
t3dotgg(GitHub profile, opens in a new tab) closed this
Duplicate of #7716: both reports describe an OSC terminal-title prefix contaminating the OpenCode build agent name and causing sends with that agent to fail. Confirmed by comparing both reports and the existing maintainer comment; no runtime reproduction was performed for this duplicate closure.
juliusmarminge closed this
Sign in to join this conversation.
📦 Want this fix today — without waiting for #7755 to merge?#
Two ways, both live now:
Option A — zero tooling:
ImBIOS/t3code@mainalready contains this fix (landed via ImBIOS/t3code#2). Clone/vendor from there:Option B — forkhub intent-patch (recommended if you maintain your own fork and want to keep receiving upstream releases)
This fix is published as an intent-patch: instead of pinning a frozen diff, you import the spec (
INTENT.md+ acceptance criteria +verify.sh), and an AI coding agent re-derives it against whatever upstream SHA your checkout is at — then again on every future upstream release, until #7755 merges (after whichfh cleanup --applydrops the patch and you return to official releases).Patch contents (browse):
INTENT.md(root cause, non-negotiables, implementation notes) ·ACCEPTANCE.md·reference.diff(+139/−14, hint only) ·verify.sh. Discoverable viafh search --author ImBIOSorfh search --target github.com/pingdotgg/t3code.If you hit the same bug on a different T3 version, the intent survives: re-derivation adapts the fix to your tree rather than replaying a stale diff.