Skip to content

fix(tui): keep the Windows Ctrl+C guard active in mini mode (#441) - #562

Merged
agenteinstinct1-max merged 3 commits into
dev-vibecodedfrom
arena/1d500508-silvercode
Oct 23, 2026
Merged

agenteinstinct1-max merged 3 commits into
dev-vibecodedfrom
arena/1d500508-silvercode

Conversation

@agenteinstinct1-max

@agenteinstinct1-max agenteinstinct1-max commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Refs #441

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

--mini returned from TuiThreadCommand before win32InstallCtrlCGuard() ran, so the mini runtime never installed the guard the full TUI relies on. When the external editor opens, openEditor suspends the renderer, which restores the console mode it found and re-enables ENABLE_PROCESSED_INPUT. Ctrl+C then becomes a console CTRL_C_EVENT for every process attached to the console instead of input the editor can consume, and the npm launcher – which listens for SIGINT so it cannot die ahead of its child – re-sent it with child.kill("SIGINT"). On Windows that is TerminateProcess: SilverCode dies abruptly, the mini runtime's temporary SIGINT handler and cleanup never run, and the editor is left behind.

Three changes:

  1. packages/opencode/src/cli/cmd/run.ts – runMini() installs win32InstallCtrlCGuard() around RunCommand.handler(...) and releases it in a finally. runMini is the shared entry for both silvercode --mini and silvercode attach <url> --mini (the tui.ts branch returns into it), so both get the guard before the split-footer renderer starts toggling raw mode. The guard re-clears ENABLE_PROCESSED_INPUT after every setRawMode call – including renderer.suspend() – with its existing 100 ms poll as the backstop, so the console never produces the Ctrl+C event in the first place.

  2. packages/tui/src/editor.ts – openEditor() re-asserts win32DisableProcessedInput() at the suspend handoff, before spawning the editor. The guard only wraps the stream it was installed on, and the handoff is exactly where the restore happens; callers without a guard (e.g. the full attach TUI) are covered too. The call sits inside the existing try, so a failure still resumes the renderer.

  3. packages/opencode/bin/silvercode – on Windows the launcher no longer forwards SIGINT to the child. The console has already delivered the event to the child, and child.kill("SIGINT") cannot deliver a signal there – it only force-terminates. The launcher keeps its SIGINT listener so it survives the event instead of dying ahead of its child, and still forwards SIGTERM/SIGHUP.

How did you verify your code works?

  • packages/opencode/test/cli/launcher.test.ts (new): drives the real bin/silvercode as a subprocess against a stub child. On the host platform SIGINT is forwarded and the child records it; through test/fixture/win32-launcher.cjs (pins process.platform before requiring the launcher) the child must not observe a forwarded SIGINT, while the launcher itself survives the signal and propagates the child's exit code. The win32 case fails against the pre-change launcher (child:sigint is observed) and passes after it.
  • bun test test/cli/launcher.test.ts from packages/opencode → 2 pass / 0 fail.
  • packages/tui: full suite 734 pass / 1 skip / 0 fail (includes the eight #377 editor suspend/resume cases); bun run typecheck (tsgo) clean.
  • packages/opencode: bun test test/cli/run 233 pass / 5 skip / 0 fail; bun test test/cli/tui 86 pass / 0 fail; test/cli/tui/thread.test.ts 10 pass / 0 fail.
  • CI on current head 5d3edb2f8d2a468ee65a4c541ed370606670e84f: Linux and Windows unit, typecheck, standards and compliance pass. The earlier 58cb480 Windows job failed. Available annotations do not identify the failing test, so the prior attribution to a stalled dependency-install test was unsupported and is retracted. The failure cause remains unknown; a later green run is not a causal fix.
  • oxlint on the touched files: 0 errors (only pre-existing advisory warnings). Prettier-clean; the pre-existing long-regex line in run.ts also fails --check on HEAD, so it was left untouched.
  • bun run typecheck for packages/opencode cannot run in this sandbox: tsc OOMs at the 3 GB container limit, so I checked the new test file with a single-file tsc run and left the package check to CI (which passed).

What stays unverified without a real Windows console

  • Raising an actual CTRL_C_EVENT and observing the console-mode handoff: kernel32 FFI is win32-only, and the launcher's signal path cannot be driven with process.kill on Windows (it terminates the target). The Windows policy is covered by the platform-pinned fixture; the guard call sites are structurally covered and the full suite runs on the Windows CI leg.
  • The editor's console-mode behavior on Windows for cooked-mode editors: the guard keeps ENABLE_PROCESSED_INPUT clear across the handoff, matching the full TUI's existing behavior rather than changing it.
  • bun:ffi binding behavior at runtime – untouched by this PR (the guard module already ships and is installed by the full TUI).

Screenshots / recordings

No visual change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Review follow-up

An unconditional VM policy test now loads the actual CJS launcher source and drives win32 and POSIX signal branches without host OS signals. It checks SIGINT policy, SIGTERM/SIGHUP forwarding, exit status and listener cleanup. This test runs on Windows too; it is not evidence of an actual Windows console Ctrl+C event or editor interaction. Mutation removing the win32 no-forward guard fails the win32 case. Local launcher suites:4passed,23assertions.

The direct-handler bypass suggestion was checked against production call sites: tui and attach mini entry points both call runMini, which installs the guard; the only mini:true handler call is there. No lifecycle move was needed. The terminal-win32 import follows the existing TUI pattern and its kernel DLL load is platform-gated. Actual Windows console behavior remains unverified.

This is partial implementation coverage of #441. Actual Windows console Ctrl+C/editor behavior remains unverified, so the issue stays open pending that acceptance check.

Post-merge review identified a known remaining mechanism gap: when process.stdin is redirected, mini can render using CONIN$ while the guard and editor reassertion still check process.stdin.isTTY. This configuration was not covered by this PR; #441 remains open and a separate follow-up is being prepared.

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown

Thanks for updating your PR! It now meets our contributing guidelines. 👍

agenteinstinct1-max and others added 2 commits October 23, 2026 19:53
mini returned before win32InstallCtrlCGuard() ran, so suspending for an
external editor restored processed console input and Ctrl+C became a
console event for the whole process group. The npm launcher then re-sent
it with child.kill("SIGINT"), which is TerminateProcess on Windows: the
mini runtime's SIGINT handler and cleanup never ran and the editor was
left behind.

Install the guard in runMini (covers --mini and attach --mini), re-assert
processed-input suppression at the editor handoff, and stop forwarding
SIGINT on win32 where the console already delivered the event.

Co-authored-by: arena-agent <[email protected]>
The package lib set (ESNext, DOM, DOM.Iterable) does not give
ReadableStream a Symbol.asyncIterator, so the launcher test's for-await
failed packages/opencode typecheck. Read the Bun.spawn stream through a
reader instead; behavior is unchanged.

Co-authored-by: arena-agent <[email protected]>
@kilo-code-bot

kilo-code-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • packages/opencode/test/cli/launcher-policy.test.ts
Previous Review Summary (commit aced1c9)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit aced1c9)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/test/cli/launcher.test.ts 67, 76 Both launcher tests are skipIf(noSignalDelivery) where noSignalDelivery = process.platform === "win32". On Windows CI both tests are skipped, so the Windows signal policy (the core of this PR) is never executed by the suite. The PR description acknowledges this ("the new launcher tests are skipped on win32") and relies on a platform-pinned fixture (win32-launcher.cjs) that only runs on POSIX hosts. This is a real coverage gap: a regression in the win32 branch would not be caught by the test suite on the platform where the branch matters. Consider a unit test that invokes the run() function directly with process.platform pinned to win32 and asserts forwarders.SIGINT is a no-op, independent of signal delivery.
packages/opencode/src/cli/cmd/run.ts 1041 win32InstallCtrlCGuard() is called unconditionally in runMini() and only short-circuits inside terminal-win32.ts when process.platform !== "win32". On POSIX hosts the function returns undefined after a few cheap checks, but the import itself pulls bun:ffi into the module graph for every silvercode --mini invocation on Linux/macOS. This is pre-existing pattern (same import already in tui.ts:19), so it is consistent, but it is worth noting that the guard is now loaded on the POSIX mini path where it does nothing. Not a defect, but the cost is module-load only and the pattern matches the full TUI.

SUGGESTION

File Line Issue
packages/opencode/src/cli/cmd/run.ts 1041-1079 The guard is installed in runMini() but RunCommand.handler is also reachable via the normal silvercode run --mini path through RunCommand directly (the handler is Effect.fn and runMini just wraps it). If a future caller invokes RunCommand.handler with mini: true without going through runMini, the guard will not be installed. Consider centralizing the guard installation so both entry points share it, or documenting that runMini is the only supported mini entry point.
Files Reviewed (6 files)
  • packages/opencode/bin/silvercode - 1 issue (win32 SIGINT no-forward; correct)
  • packages/opencode/src/cli/cmd/run.ts - 2 issues (guard install in runMini)
  • packages/opencode/test/cli/launcher.test.ts - 1 issue (Windows coverage gap)
  • packages/opencode/test/fixture/launcher-child.js - no issues
  • packages/opencode/test/fixture/win32-launcher.cjs - no issues
  • packages/tui/src/editor.ts - 1 issue (win32DisableProcessedInput at suspend handoff; correct)

Fix these issues in Kilo Cloud


Reviewed by free · Input: 50.8K · Output: 18.2K · Cached: 177.8K

// covered by the platform-pinned fixture instead.
const noSignalDelivery = process.platform === "win32"

test.skipIf(noSignalDelivery)("forwards SIGINT to the child on POSIX hosts", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Both launcher tests are skipIf(noSignalDelivery) where noSignalDelivery = process.platform === "win32". On Windows CI both tests are skipped, so the Windows signal policy — the core of this PR — is never exercised by the running suite. The platform-pinned win32-launcher.cjs fixture only runs on POSIX hosts (it pins process.platform on the child side but is itself launched and signalled from a POSIX host). A regression in the win32 branch would not be caught on the platform where the branch matters. Consider a unit test that calls the launcher's run() directly with process.platform pinned to win32 and asserts forwarders.SIGINT is a no-op, independent of signal delivery.

// Windows Ctrl+C guard installed for the whole runtime so those toggles
// cannot turn Ctrl+C into a console event that kills the launcher's child
// abruptly (#441).
const unguard = win32InstallCtrlCGuard()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The guard is installed in runMini() but RunCommand.handler is also reachable directly via silvercode run --mini (the handler is Effect.fn and runMini is only a thin wrapper). If a future caller invokes RunCommand.handler with mini: true without going through runMini, the guard will not be installed. Consider centralizing the guard installation so both entry points share it, or documenting that runMini is the only supported mini entry point.

@agenteinstinct1-max
agenteinstinct1-max merged commit 6f63637 into dev-vibecoded Oct 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant