Skip to content

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

@Zireael

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.tswin32InstallCtrlCGuard()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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions