Repository navigation
fix(tui): keep the Windows Ctrl+C guard active in mini mode (#441) - #562
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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]>
58cb480 to
aced1c9
Compare
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
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
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (6 files)
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 () => { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
Issue for this PR
Refs #441
Type of change
What does this PR do?
--minireturned fromTuiThreadCommandbeforewin32InstallCtrlCGuard()ran, so the mini runtime never installed the guard the full TUI relies on. When the external editor opens,openEditorsuspends the renderer, which restores the console mode it found and re-enablesENABLE_PROCESSED_INPUT. Ctrl+C then becomes a consoleCTRL_C_EVENTfor 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 withchild.kill("SIGINT"). On Windows that isTerminateProcess: SilverCode dies abruptly, the mini runtime's temporary SIGINT handler and cleanup never run, and the editor is left behind.Three changes:
packages/opencode/src/cli/cmd/run.ts–runMini()installswin32InstallCtrlCGuard()aroundRunCommand.handler(...)and releases it in afinally.runMiniis the shared entry for bothsilvercode --miniandsilvercode attach <url> --mini(thetui.tsbranch returns into it), so both get the guard before the split-footer renderer starts toggling raw mode. The guard re-clearsENABLE_PROCESSED_INPUTafter everysetRawModecall – includingrenderer.suspend()– with its existing 100 ms poll as the backstop, so the console never produces the Ctrl+C event in the first place.packages/tui/src/editor.ts–openEditor()re-assertswin32DisableProcessedInput()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 fullattachTUI) are covered too. The call sits inside the existingtry, so a failure still resumes the renderer.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, andchild.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 realbin/silvercodeas a subprocess against a stub child. On the host platform SIGINT is forwarded and the child records it; throughtest/fixture/win32-launcher.cjs(pinsprocess.platformbefore 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:sigintis observed) and passes after it.bun test test/cli/launcher.test.tsfrompackages/opencode→ 2 pass / 0 fail.packages/tui: full suite 734 pass / 1 skip / 0 fail (includes the eight#377editor suspend/resume cases);bun run typecheck(tsgo) clean.packages/opencode:bun test test/cli/run233 pass / 5 skip / 0 fail;bun test test/cli/tui86 pass / 0 fail;test/cli/tui/thread.test.ts10 pass / 0 fail.5d3edb2f8d2a468ee65a4c541ed370606670e84f: Linux and Windows unit, typecheck, standards and compliance pass. The earlier58cb480Windows 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.oxlinton the touched files: 0 errors (only pre-existing advisory warnings). Prettier-clean; the pre-existing long-regex line inrun.tsalso fails--checkonHEAD, so it was left untouched.bun run typecheckforpackages/opencodecannot run in this sandbox:tscOOMs at the 3 GB container limit, so I checked the new test file with a single-filetscrun and left the package check to CI (which passed).What stays unverified without a real Windows console
CTRL_C_EVENTand observing the console-mode handoff:kernel32FFI is win32-only, and the launcher's signal path cannot be driven withprocess.killon 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.ENABLE_PROCESSED_INPUTclear across the handoff, matching the full TUI's existing behavior rather than changing it.bun:ffibinding 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
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.