[GH-ISSUE #6119] Pressing Ctrl+C in the Windows launcher window kills the server outright instead of shutting it down #3397

Closed
opened 2026-10-21 06:02:40 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6119

Originally assigned to: @SpicyMarinara on GitHub.

On Windows, stopping the app with Ctrl+C in the launcher console ends the server abruptly rather than shutting it down cleanly. The console never prints "Shutdown complete", and the next start warns that your previous session "ended without shutting down" and was force-quit or lost power - even though you stopped it the normal way. Anything saved in the last fraction of a second before Ctrl+C can also be lost even though the app told you it saved.

How to reproduce (try it yourself)

This only happens on Windows. Run the same steps on macOS or Linux with ./start.sh as a control - there everything works correctly.

  1. Check out staging at 52799569c and build as usual.
  2. Double-click start.bat, or run it from a cmd.exe window. Wait until the console prints Starting Marinara Engine on http://0.0.0.0:7860 and then the server's own Marinara Engine server listening line.
  3. Let it sit idle for about ten seconds. You do not need to create anything - the bug does not depend on a pending save.
  4. Press Ctrl+C once in the console.
  5. Look through the console output for the line Shutdown complete.
  6. Run start.bat again and read the first few seconds of console output.

What you'll see: at step 5 there is no Shutdown complete line. At step 6 the new session prints Previous session (pid NNN) ended without shutting down: ... Nothing was logged, so the process was ended from outside - ... on desktop, a force-quit or power loss. See Support Diagnostics for the record. That warning appears after every ordinary Ctrl+C.

What should happen: the console prints Received SIGINT; shutting down Marinara Engine and then Shutdown complete, exits cleanly, and the next start prints no force-quit warning - exactly what happens today on macOS and Linux.

Do not use the Received SIGINT; shutting down Marinara Engine line as your test: the Windows console also sends the stop key to the server directly, so that first line often prints a millisecond before the server is killed. Only the missing Shutdown complete and the next-boot warning reliably show the problem.

Worth doing in the same pass, because it would make this worse: start a local model so a sidecar process is running, note its process id in Task Manager, press Ctrl+C, then check whether the sidecar is still alive and still holding its port. Nothing reaps it if the clean shutdown is skipped.

To confirm this is new: in cmd.exe, with a throwaway data directory, run node dist\index.js from packages\server and press Ctrl+C - you get both shutdown lines. Then run node ..\..\scripts\run-server.mjs dist\index.js and press Ctrl+C - you get neither. The second command is what start.bat runs today.

Where it is

At staging 52799569c:

  • scripts/run-server.mjs:16 - inside the SIGINT/SIGTERM/SIGHUP relay loop (lines 9-20): child?.kill(signal);. The 39-line file has no process.platform === "win32" branch. On Windows, Node ignores the signal name and terminates the process forcefully (documented in the repo's own node_modules/@types/node/child_process.d.ts:275-276), so the server's handler never runs.
  • scripts/run-server.mjs:17 - stopTimer = setTimeout(() => child?.kill("SIGKILL"), 10_000); - the intended ten-second grace window, dead code on Windows because line 16 already terminated the child.
  • start.bat:406 - node ../../scripts/run-server.mjs dist/index.js, the Windows entry point that introduces the supervisor. Line 393 tells the user "Press Ctrl+C to stop".
  • packages/server/src/index.ts:90-121 - shutdown() and its process.on("SIGINT", ...) handler, none of which runs; index.ts:69 and :74-76 are the only process.once("exit", ...) hooks (sidecar cleanup and exit stamping) and neither fires.
  • packages/server/src/db/file-backed-store.ts:326 - const SAVE_DEBOUNCE_MS = 750; with the timer at :3732-3737, the window in which accepted saves are still only in memory.

What's happening

On Windows, pressing Ctrl+C in a console already sends the stop event to every program attached to that console, including the server. The launcher then also calls child.kill(signal). On Windows that is not a signal at all - Windows has no signals, so Node terminates the process immediately and forcefully. The server begins shutting down properly and is killed a moment later, before it finishes.

Three things are skipped. The store never drains its debounced writes, so up to about three quarters of a second of saves the app already confirmed can be lost. The bounded-close work from #5863, which exists specifically to prevent a write-dropping abrupt end, never arms. And the exit hooks never run, so sidecar processes are not cleaned up and the session is never stamped as a deliberate exit - which is why the next start reports a force-quit. That last consequence happens every time, not just when a save is pending, and it lands in Support Diagnostics, making the session postmortem from #5506 unreliable on Windows.

The data-loss part is narrower than it sounds: measured against a live server, a save that returns success reaches disk about 450 ms later, so stopping a full second after clicking Save keeps the data. The missing clean shutdown and the false force-quit report are the parts that happen every time.

Suggested fix

The launcher should not re-send a stop that the Windows console has already delivered to the server. The narrowest correct change is to make the relay POSIX-only: on Windows, mark the supervisor as stopping, skip the child.kill(signal) call, and wait for the child's own close event - keeping the ten-second forced-kill escalation as a backstop for a server that hangs. child.kill() can never be graceful on Windows, so if the design ever changes so the server does not share the console, the stop request has to travel some other way (a Windows console control event, or a request over stdin/IPC).

Whichever shape the fix takes, it needs coverage. scripts/regressions/server-signal-shutdown.regression.ts:80-83 asserts exactly the two log lines Windows breaks, but the regression lanes run only on Linux, so the Windows path has no automated coverage at all. Adding that coverage may be a separate infrastructure task if Windows CI is not available.

Context

This is a regression introduced by PR #5962, which closed #5934. Before it, start.bat:406 ran node dist/index.js directly and the console Ctrl+C reached the server, which shut down gracefully; scripts/run-server.mjs has exactly one commit in its history, from that PR. It undoes the protection added in #5863 on Windows and corrupts the session postmortem from #5506. PR #5962's description flagged native Windows behaviour as a manual verification item, but no follow-up issue was opened. Unreleased on staging (latest release is v2.4.4), so no shipped build is affected yet.

Two corrections to earlier notes, so nobody chases the wrong code: the writer lease does recover on the next boot, but not through probeWriterLeaseLiveness - that returns "uncertain" on Windows at file-backed-store.ts:1603 and its liveness check is armed only for Docker-on-Linux and Termux (:2348-2351); recovery comes from the process-id check at :2457. And the skipped exit hooks, including the false force-quit report, were not part of the original write-up.

The failing case could not be executed here - this machine is Linux and the defect lives in Windows-only process handling - so the cost was measured on Linux by substituting an abrupt kill, and the Windows trigger rests on Node's shipped documentation plus a recorded Windows probe. A Windows pass is required before closing.

Found by an AI-assisted sweep of merged PR #5962 against issue #5934, then re-verified against staging 52799569c on 2026-09-13 as far as a Linux machine allows. Please verify on Windows before fixing.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6119 Originally assigned to: @SpicyMarinara on GitHub. On Windows, stopping the app with Ctrl+C in the launcher console ends the server abruptly rather than shutting it down cleanly. The console never prints "Shutdown complete", and the next start warns that your previous session "ended without shutting down" and was force-quit or lost power - even though you stopped it the normal way. Anything saved in the last fraction of a second before Ctrl+C can also be lost even though the app told you it saved. ## How to reproduce (try it yourself) This only happens on Windows. Run the same steps on macOS or Linux with `./start.sh` as a control - there everything works correctly. 1. Check out `staging` at 52799569c and build as usual. 2. Double-click `start.bat`, or run it from a `cmd.exe` window. Wait until the console prints `Starting Marinara Engine on http://0.0.0.0:7860` and then the server's own `Marinara Engine server listening` line. 3. Let it sit idle for about ten seconds. You do not need to create anything - the bug does not depend on a pending save. 4. Press Ctrl+C once in the console. 5. Look through the console output for the line `Shutdown complete`. 6. Run `start.bat` again and read the first few seconds of console output. **What you'll see:** at step 5 there is no `Shutdown complete` line. At step 6 the new session prints `Previous session (pid NNN) ended without shutting down: ... Nothing was logged, so the process was ended from outside - ... on desktop, a force-quit or power loss. See Support Diagnostics for the record.` That warning appears after every ordinary Ctrl+C. **What should happen:** the console prints `Received SIGINT; shutting down Marinara Engine` and then `Shutdown complete`, exits cleanly, and the next start prints no force-quit warning - exactly what happens today on macOS and Linux. Do not use the `Received SIGINT; shutting down Marinara Engine` line as your test: the Windows console also sends the stop key to the server directly, so that first line often prints a millisecond before the server is killed. Only the missing `Shutdown complete` and the next-boot warning reliably show the problem. Worth doing in the same pass, because it would make this worse: start a local model so a sidecar process is running, note its process id in Task Manager, press Ctrl+C, then check whether the sidecar is still alive and still holding its port. Nothing reaps it if the clean shutdown is skipped. To confirm this is new: in `cmd.exe`, with a throwaway data directory, run `node dist\index.js` from `packages\server` and press Ctrl+C - you get both shutdown lines. Then run `node ..\..\scripts\run-server.mjs dist\index.js` and press Ctrl+C - you get neither. The second command is what `start.bat` runs today. ## Where it is At staging 52799569c: - `scripts/run-server.mjs:16` - inside the SIGINT/SIGTERM/SIGHUP relay loop (lines 9-20): `child?.kill(signal);`. The 39-line file has no `process.platform === "win32"` branch. On Windows, Node ignores the signal name and terminates the process forcefully (documented in the repo's own `node_modules/@types/node/child_process.d.ts:275-276`), so the server's handler never runs. - `scripts/run-server.mjs:17` - `stopTimer = setTimeout(() => child?.kill("SIGKILL"), 10_000);` - the intended ten-second grace window, dead code on Windows because line 16 already terminated the child. - `start.bat:406` - `node ../../scripts/run-server.mjs dist/index.js`, the Windows entry point that introduces the supervisor. Line 393 tells the user "Press Ctrl+C to stop". - `packages/server/src/index.ts:90-121` - `shutdown()` and its `process.on("SIGINT", ...)` handler, none of which runs; `index.ts:69` and `:74-76` are the only `process.once("exit", ...)` hooks (sidecar cleanup and exit stamping) and neither fires. - `packages/server/src/db/file-backed-store.ts:326` - `const SAVE_DEBOUNCE_MS = 750;` with the timer at `:3732-3737`, the window in which accepted saves are still only in memory. ## What's happening On Windows, pressing Ctrl+C in a console already sends the stop event to every program attached to that console, including the server. The launcher then also calls `child.kill(signal)`. On Windows that is not a signal at all - Windows has no signals, so Node terminates the process immediately and forcefully. The server begins shutting down properly and is killed a moment later, before it finishes. Three things are skipped. The store never drains its debounced writes, so up to about three quarters of a second of saves the app already confirmed can be lost. The bounded-close work from #5863, which exists specifically to prevent a write-dropping abrupt end, never arms. And the exit hooks never run, so sidecar processes are not cleaned up and the session is never stamped as a deliberate exit - which is why the next start reports a force-quit. That last consequence happens every time, not just when a save is pending, and it lands in Support Diagnostics, making the session postmortem from #5506 unreliable on Windows. The data-loss part is narrower than it sounds: measured against a live server, a save that returns success reaches disk about 450 ms later, so stopping a full second after clicking Save keeps the data. The missing clean shutdown and the false force-quit report are the parts that happen every time. ## Suggested fix The launcher should not re-send a stop that the Windows console has already delivered to the server. The narrowest correct change is to make the relay POSIX-only: on Windows, mark the supervisor as stopping, skip the `child.kill(signal)` call, and wait for the child's own close event - keeping the ten-second forced-kill escalation as a backstop for a server that hangs. `child.kill()` can never be graceful on Windows, so if the design ever changes so the server does not share the console, the stop request has to travel some other way (a Windows console control event, or a request over stdin/IPC). Whichever shape the fix takes, it needs coverage. `scripts/regressions/server-signal-shutdown.regression.ts:80-83` asserts exactly the two log lines Windows breaks, but the regression lanes run only on Linux, so the Windows path has no automated coverage at all. Adding that coverage may be a separate infrastructure task if Windows CI is not available. ## Context This is a regression introduced by PR #5962, which closed #5934. Before it, `start.bat:406` ran `node dist/index.js` directly and the console Ctrl+C reached the server, which shut down gracefully; `scripts/run-server.mjs` has exactly one commit in its history, from that PR. It undoes the protection added in #5863 on Windows and corrupts the session postmortem from #5506. PR #5962's description flagged native Windows behaviour as a manual verification item, but no follow-up issue was opened. Unreleased on staging (latest release is v2.4.4), so no shipped build is affected yet. Two corrections to earlier notes, so nobody chases the wrong code: the writer lease does recover on the next boot, but not through `probeWriterLeaseLiveness` - that returns "uncertain" on Windows at `file-backed-store.ts:1603` and its liveness check is armed only for Docker-on-Linux and Termux (`:2348-2351`); recovery comes from the process-id check at `:2457`. And the skipped exit hooks, including the false force-quit report, were not part of the original write-up. The failing case could not be executed here - this machine is Linux and the defect lives in Windows-only process handling - so the cost was measured on Linux by substituting an abrupt kill, and the Windows trigger rests on Node's shipped documentation plus a recorded Windows probe. A Windows pass is required before closing. Found by an AI-assisted sweep of merged PR #5962 against issue #5934, then re-verified against staging 52799569c on 2026-09-13 as far as a Linux machine allows. Please verify on Windows before fixing.
bsakaguchi 2026-10-21 06:02:40 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.

<!-- gh-comment-id:5651922848 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): @SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Fixed in #6137, now merged to staging (e044997a2). The Windows launcher lets native console signal delivery reach the server so shutdown can finish saving.

<!-- gh-comment-id:5652782477 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). The Windows launcher lets native console signal delivery reach the server so shutdown can finish saving.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3397
No description provided.