Skip to content

Windows TUI segfault after long session (bun:ffi console guard polling) #31144

Closed as not planned

Description

@Zireael

Description

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.

Crash report: https://bun.report/1.3.14/ea10d9b296m7Bz+339/DC8B.bebf9eff3affffbf-00000000.dllup1xB_is33sB___A2qaxv/jqH

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

  1. Windows 11 x64, OpenCode 1.16.2 installed globally (opencode-ai npm package).
  2. Launch TUI with a resumed session: opencode -s <session-id> (also reproduced with opencode -c).
  3. Use the TUI normally with agent activity (shell spawns, MCP tools, fetch) for 1–2 hours.
  4. Process segfaults; Bun crash dialog appears.

Relevant code: packages/opencode/src/cli/cmd/tui/win32.ts — win32InstallCtrlCGuard() → setInterval(enforce, 100) calling FFI symbols.

Screenshot and/or share link

https://bun.report/1.3.14/ea10d9b296m7Bz+339/DC8B.bebf9eff3affffbf-00000000.dllup1xB_is33sB___A2qaxv/jqH

Operating System

Windows 11 (build 26200)

Terminal

Windows Terminal

Activity

  1. github-actions commented on Jun 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    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.

  2. Zireael commented on Jun 6, 2026

    @Zireael
    Author

    Looks like the flagged bugs are still open. One of them even submitted a PR, which is still not merged.

  3. jojosenthusiast commented on Jun 25, 2026

    @jojosenthusiast

    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():

    const interval = 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.

  4. poberto commented on Jul 30, 2026

    @poberto

    I'm experiencing the same thing in latest opencode release. I believe there was a Bun fix that was merged yesterday.

  5. boyingliu01 commented on Sep 16, 2026

    @boyingliu01

    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

    Bun v1.3.14 (0d9b296a) Windows x64 (baseline)
    panic(main thread): Segmentation fault at address 0x20A3EC55A62
    

    Crash report (full decoded stack): https://bun.report/1.3.14/ea10d9b296m7Gz/339/D_is33sB_____A20gBkmt144B

    Decoded stack — same Zig::JSFFIFunction::trampoline frame as the original report:

    Bun v1.3.14 (0d9b296) on windows x86_64_baseline [StandaloneExecutable]
    Segmentation fault at address 0x20A3EC55A62
    - *1 unknown/js code*
    - JSFFIFunction.cpp:166: Zig::JSFFIFunction::trampoline
    Features: spawn, standalone_executable, transpiler_cache, tsconfig, virtual_modules,
              workers_spawned, napi_module_register, process_dlopen, Bun.stderr, Bun.stdin,
              Bun.stdout, fetch, http_server, jsc, shell
    

    Environment

    • OS: Windows 11 (win11_dt)
    • CPU: sse42 avx avx2 avx512
    • opencode: 1.18.31 (opencode-ai, global install)
    • Embedded Bun: 1.3.14 — bun.report itself reports "Embedded Bun version: 1.3.14 / Latest release: 1.4.2"
    • Args: 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:

    Elapsed: 1265442ms  User: 5669109ms  Sys: 1134578ms
    RSS: 1.79GB | Peak: 2.44GB | Commit: 2.40GB
    Faults: 1054253338 | Machine: 34.07GB
    

    Notably Faults: 1,054,253,338 (~1.05 billion page faults) under heavy spawn / fetch / multi-process activity (a trayworker process was also present).

    Why this is the same bug, not a new one

    This crash oven-sh/bun#31941 (closed, fixed by #35246)
    Bun build 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).

  6. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions