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
Windows TUI segfault after long session (bun:ffi console guard polling) #31144
OpenCode TUI crashes on Windows after a long-running session (~116 minutes). The process segfaults inside the embedded Bun runtime (v1.3.14) during an FFI call.
Stack trace points to Zig::JSFFIFunction::trampoline (JSFFIFunction.cpp:166). The only bun:ffi usage in OpenCode is the Windows console Ctrl+C guard in packages/opencode/src/cli/cmd/tui/win32.ts (win32InstallCtrlCGuard), which polls GetConsoleMode / SetConsoleMode on kernel32.dll every 100ms. That guard is installed from thread.ts and app.tsx when the TUI starts.
This may be a Bun runtime defect, but OpenCode is the only code path exercising repeated FFI here. Consider reducing or eliminating the 100ms polling backstop if a safer workaround exists.
Plugins
None confirmed at crash time (default/global install).
OpenCode version
1.16.2
Steps to reproduce
Windows 11 x64, OpenCode 1.16.2 installed globally (opencode-ai npm package).
Launch TUI with a resumed session: opencode -s <session-id> (also reproduced with opencode -c).
Use the TUI normally with agent activity (shell spawns, MCP tools, fetch) for 1–2 hours.
If your crash is distinct (specifically the bun:ffi FFI polling path in win32.ts rather than a general Bun runtime bug), feel free to keep this open and clarify the difference.
Confirming this on Windows 11, opencode 1.17.10, bundled Bun 1.3.14.
Same signature every launch: panic(main thread): Segmentation fault in the FFI trampoline (Zig::JSFFIFunction::trampoline), crash address ending in …AA2. CLI paths (--version, --help, models, opencode serve) are fine — it only dies in an active TUI session.
I traced the hot path to packages/tui/src/terminal-win32.ts → win32InstallCtrlCGuard():
constinterval=setInterval(enforce,100)
enforce calls GetConsoleMode / SetConsoleMode on kernel32.dll through bun:ffi every 100 ms. Over a long session that's thousands of FFI trampoline calls, which is what eventually trips the Bun 1.3.14 trampoline bug (matches #31144 "console guard polling" and the FFI crash in #31607 / #28046).
Confirmed clean on 1.16.2, which predates this guard. Since the underlying defect is in Bun's FFI (Bun-side fix referenced in #28046), the practical workarounds for anyone hitting this:
Downgrade: npm i -g opencode-ai@1.16.2
Or stay on latest and use opencode serve + the browser UI — the server path doesn't install the console guard, so it sidesteps the FFI poll.
Happy to test a patched build (e.g. a longer poll interval, an opt-in env flag to disable the guard, or a bumped Bun) on this machine if useful — I have a 100% repro.
1.3.14 (0d9b296), windows x64 baseline, StandaloneExecutable
identical
Top frame
JSFFIFunction::trampoline
identical
Trigger
sustained FFI polling, long session
sustained FFI polling, ~116 min
The fault-address page offset differs slightly (0xA62 here vs 0x108 / 0xAA2 in other reports), which is why this is worth recording as an additional data point — but the crash site is identical.
Per Jarred-Sumner on oven-sh/bun#31941, the JSFFIFunction::trampoline path was the TinyCC trampoline and no longer exists after #35246, which ships in Bun 1.4.0. So this crash class should disappear once the embedded runtime is bumped.
This is now blocked on opencode#44946 (bump embedded Bun to 1.4.2), which is still open pending a Windows smoke test — see my note there.
Workaround for anyone hitting this today:opencode serve + browser UI avoids installing the console guard entirely, so it sidesteps the FFI poll (confirmed by @jojosenthusiast above).
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.
Activity
github-actions commentedon Jun 6, 2026
This issue might be a duplicate of existing issues. Please check:
If your crash is distinct (specifically the
bun:ffiFFI polling path inwin32.tsrather than a general Bun runtime bug), feel free to keep this open and clarify the difference.Zireael commentedon Jun 6, 2026
Looks like the flagged bugs are still open. One of them even submitted a PR, which is still not merged.
jojosenthusiast commentedon Jun 25, 2026
Confirming this on Windows 11, opencode
1.17.10, bundled Bun1.3.14.Same signature every launch:
panic(main thread): Segmentation faultin the FFI trampoline (Zig::JSFFIFunction::trampoline), crash address ending in…AA2. CLI paths (--version,--help,models,opencode serve) are fine — it only dies in an active TUI session.I traced the hot path to
packages/tui/src/terminal-win32.ts→win32InstallCtrlCGuard():enforcecallsGetConsoleMode/SetConsoleModeonkernel32.dllthroughbun:ffievery 100 ms. Over a long session that's thousands of FFI trampoline calls, which is what eventually trips the Bun 1.3.14 trampoline bug (matches #31144 "console guard polling" and the FFI crash in #31607 / #28046).Confirmed clean on
1.16.2, which predates this guard. Since the underlying defect is in Bun's FFI (Bun-side fix referenced in #28046), the practical workarounds for anyone hitting this:npm i -g opencode-ai@1.16.2opencode serve+ the browser UI — the server path doesn't install the console guard, so it sidesteps the FFI poll.Happy to test a patched build (e.g. a longer poll interval, an opt-in env flag to disable the guard, or a bumped Bun) on this machine if useful — I have a 100% repro.
poberto commentedon Jul 30, 2026
I'm experiencing the same thing in latest opencode release. I believe there was a Bun fix that was merged yesterday.
boyingliu01 commentedon Sep 16, 2026
Confirming this still reproduces on
opencode 1.18.31(embedded Bun 1.3.14,0d9b296a) on Windows — the bug is not fixed as of this version.Crash
Crash report (full decoded stack): https://bun.report/1.3.14/ea10d9b296m7Gz/339/D_is33sB_____A20gBkmt144B
Decoded stack — same
Zig::JSFFIFunction::trampolineframe as the original report:Environment
win11_dt)sse42 avx avx2 avx512opencode-ai, global install)opencode.exe --user-agent=opencode/1.18.31 --use-system-ca -- --log-level "WARN"Session characteristics
This is a long-session crash consistent with the sustained-FFI-polling profile:
Notably
Faults: 1,054,253,338(~1.05 billion page faults) under heavyspawn/fetch/ multi-process activity (atrayworkerprocess was also present).Why this is the same bug, not a new one
1.3.14 (0d9b296), windows x64 baseline, StandaloneExecutableJSFFIFunction::trampolineThe fault-address page offset differs slightly (
0xA62here vs0x108/0xAA2in other reports), which is why this is worth recording as an additional data point — but the crash site is identical.Per Jarred-Sumner on oven-sh/bun#31941, the
JSFFIFunction::trampolinepath was the TinyCC trampoline and no longer exists after #35246, which ships in Bun 1.4.0. So this crash class should disappear once the embedded runtime is bumped.This is now blocked on opencode#44946 (bump embedded Bun to 1.4.2), which is still open pending a Windows smoke test — see my note there.
Workaround for anyone hitting this today:
opencode serve+ browser UI avoids installing the console guard entirely, so it sidesteps the FFI poll (confirmed by @jojosenthusiast above).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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊