You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is the destruction of the TreeSitter client causing a memory leak? #36454
Code highlighting failed, falling back to plain text: warn: TreeSitter client destroyed
at destroy (B:/~BUN/root/chunk-pphanb3a.js:64:11891)
at VZ (B:/~BUN/root/chunk-pphanb3a.js:64:19204)
at finalizeDestroy (B:/~BUN/root/chunk-pphanb3a.js:93:22271)
at destroy (B:/~BUN/root/chunk-pphanb3a.js:93:19087)
at Ug (B:/~BUN/root/chunk-0pv4sh7x.js:94:18044)
at exit (B:/~BUN/root/chunk-0pv4sh7x.js:94:20824)
at Y (B:/~BUN/root/chunk-nvcaztx1.js:2:33829)
at runBinding (B:/~BUN/root/chunk-nvcaztx1.js:2:36254)
at _J (B:/~BUN/root/chunk-nvcaztx1.js:2:56789)
at HJ (B:/~BUN/root/chunk-nvcaztx1.js:2:50894)
at wJ (B:/~BUN/root/chunk-nvcaztx1.js:2:49442)
at EJ (B:/~BUN/root/chunk-nvcaztx1.js:2:48612)
at <anonymous> (B:/~BUN/root/chunk-nvcaztx1.js:2:70091)
at emitWithPriority (B:/~BUN/root/chunk-pphanb3a.js:2:38428)
at processParsedKey (B:/~BUN/root/chunk-pphanb3a.js:2:37897)
at handleStdinEvent (B:/~BUN/root/chunk-pphanb3a.js:93:5055)
at <anonymous> (B:/~BUN/root/chunk-pphanb3a.js:93:4924)
at drain (B:/~BUN/root/chunk-pphanb3a.js:32:7512)
at drainStdinParser (B:/~BUN/root/chunk-pphanb3a.js:93:4896)
at <anonymous> (B:/~BUN/root/chunk-pphanb3a.js:93:2753)
at emit (node:events:95:22)
at addChunk (internal:streams/readable:264:47)
at readableAddChunkPushByteMode (internal:streams/readable:242:18)
TreeSitterClient.destroy() rejects every in-flight highlightOnce() request in one shot via rejectPendingRequests(), which walks the whole messageCallbacks map. CodeRenderable.startHighlight() catches each rejection and logs it as a genuine highlighting failure — the console.warn at Code.ts:418 runs before the if (this.isDestroyed) return on the next line.
So the count of warnings tracks the number of queued highlight requests, not anything leaking. That's why it looks worse the longer the session has been running: more rendered code blocks in the transcript, more pending requests to reject.
Still reproducing on 1.18.18
macOS arm64. The v1.18.18 tag pins @opentui/core0.4.5, and the shipped bundle still has the warn ahead of the guard:
$ strings -a ~/.opencode/bin/opencode | grep -o 'Code highlighting failed.\{0,120\}'
Code highlighting failed, falling back to plain text:",H),this.isDestroyed)return;this.textBuffer.setText($)...
The warnings go straight to the terminal because finalizeDestroy() calls _console.destroy() → restoreOriginalConsole() in the same synchronous block, while the rejections settle on a later microtask — by the time they fire, global.console is the original one again. So if you're looking for these in opencode.log, they aren't there.
The warning path itself is renderable-side only (console.warn + textBuffer.setText), so it can't touch persistence. On the session I hit this with, all 209 messages were intact in opencode.db and opencode -s <session-id> resumed fine — the only casualty was the assistant turn that was mid-stream when Ctrl+C landed (cost: 0, all token counts 0), which just needs re-sending.
FWIW, the "remove MCP servers that can't load" workaround mentioned above addresses a different failure — it doesn't affect this particular stack.
Reproduces for me on macOS with OpenCode 1.18.30. On a normal TUI shutdown the terminal prints:
Code highlighting failed, falling back to plain text: warn: TreeSitter client destroyed
This looks like the same shutdown race tracked upstream in anomalyco/opentui#1319, which was closed as completed after renderer teardown was changed to invalidate pending CodeRenderable highlights before Tree-sitter shutdown.
OpenCode dev still pins @opentui/core, @opentui/keymap, and @opentui/solid to 0.4.5. There is also an existing, separately-motivated OpenCode upgrade PR, #46112, that moves the renderer stack to a newer OpenTUI for another rendering issue.
@kommander could you check whether #36454 disappears with the newer OpenTUI teardown and, if so, fold this into the dependency upgrade? If it does not, a teardown regression test would at least make the remaining gap explicit.
I'm not claiming the bump fixes it without verification — just cross-linking the upstream fix/status and the existing upgrade path.
Activity
c17r commentedon Jul 16, 2026
I'm also seeing this in 1.18.2 on MacOS
AndyLuoJJ commentedon Jul 23, 2026
Still exists in 1.18.4 on macOS
zengyuxiang0921 commentedon Jul 30, 2026
Same bug on windows node.js
zengyuxiang0921 commentedon Jul 30, 2026
Try removing mcp servers that can't load, that works for me
jizhi0v0 commentedon Aug 14, 2026
This isn't a memory leak — it's a shutdown race in
@opentui/core, and there's already a fix sitting upstream that nobody here seems to know about:What's actually happening
TreeSitterClient.destroy()rejects every in-flighthighlightOnce()request in one shot viarejectPendingRequests(), which walks the wholemessageCallbacksmap.CodeRenderable.startHighlight()catches each rejection and logs it as a genuine highlighting failure — theconsole.warnatCode.ts:418runs before theif (this.isDestroyed) returnon the next line.So the count of warnings tracks the number of queued highlight requests, not anything leaking. That's why it looks worse the longer the session has been running: more rendered code blocks in the transcript, more pending requests to reject.
Still reproducing on 1.18.18
macOS arm64. The
v1.18.18tag pins@opentui/core0.4.5, and the shipped bundle still has the warn ahead of the guard:Two things that may help people triaging this
It never reaches the log file. On my machine:
The warnings go straight to the terminal because
finalizeDestroy()calls_console.destroy()→restoreOriginalConsole()in the same synchronous block, while the rejections settle on a later microtask — by the time they fire,global.consoleis the original one again. So if you're looking for these inopencode.log, they aren't there.The warning path itself is renderable-side only (
console.warn+textBuffer.setText), so it can't touch persistence. On the session I hit this with, all 209 messages were intact inopencode.dbandopencode -s <session-id>resumed fine — the only casualty was the assistant turn that was mid-stream whenCtrl+Clanded (cost: 0, all token counts 0), which just needs re-sending.FWIW, the "remove MCP servers that can't load" workaround mentioned above addresses a different failure — it doesn't affect this particular stack.
ljsga commentedon Sep 6, 2026
This is still happening on 1.18.29 runnin gon macos 26.6.2
serezha93 commentedon Sep 11, 2026
Reproduces for me on macOS with OpenCode 1.18.30. On a normal TUI shutdown the terminal prints:
This looks like the same shutdown race tracked upstream in anomalyco/opentui#1319, which was closed as completed after renderer teardown was changed to invalidate pending
CodeRenderablehighlights before Tree-sitter shutdown.OpenCode
devstill pins@opentui/core,@opentui/keymap, and@opentui/solidto0.4.5. There is also an existing, separately-motivated OpenCode upgrade PR, #46112, that moves the renderer stack to a newer OpenTUI for another rendering issue.@kommander could you check whether #36454 disappears with the newer OpenTUI teardown and, if so, fold this into the dependency upgrade? If it does not, a teardown regression test would at least make the remaining gap explicit.
I'm not claiming the bump fixes it without verification — just cross-linking the upstream fix/status and the existing upgrade path.
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊