[GH-ISSUE #6154] Stopping the server with Ctrl+C is reported as an error even though the shutdown is clean #3427

Closed
opened 2026-10-21 06:02:59 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Pressing Ctrl+C to stop Marinara Engine now finishes cleanly and then prints an error anyway. The server says "Shutdown complete", and right after that the launcher says the server exited with status 130, or pnpm prints a red ELIFECYCLE failure. Nothing is actually broken, but every normal stop looks like a crash, and on Termux that fake error line is also written into the saved session log people attach to support reports.

How to reproduce (try it yourself)

Use a spare checkout and a throwaway data folder, not the copy you normally run on port 7860.

  1. In the checkout root, run pnpm start.
  2. Wait for the line Server listening at http://....
  3. Press Ctrl+C once, the ordinary way you stop the app.

What you'll see: the server logs Received SIGINT; shutting down Marinara Engine and then Shutdown complete, and immediately after that pnpm prints ELIFECYCLE Command failed with exit code 130. Running echo $? prints 130.

What should happen: after Shutdown complete the command should end quietly with status 0, because the stop succeeded.

The same thing on Termux, where it is louder:

  1. Run ./start-termux.sh, wait for Server listening, press Ctrl+C once.
  2. Run tail -3 ~/.marinara-engine/logs/server-*.log.

What you'll see: on screen and in that saved log, [ERROR] Marinara Engine server exited with status 130. after a completely normal stop.

What should happen: no error line on screen and none in the saved log.

To confirm it is the new wrapper and not the server: from packages/server run node dist/index.js, press Ctrl+C, and echo $? prints 0 with no error line. Run node ../../scripts/run-server.mjs dist/index.js instead, press Ctrl+C, and echo $? prints 130. Only the wrapper differs.

Where it is

At staging ac14dd704:

  • scripts/run-server.mjs:13, in the signal handler: process.exitCode = 128 + (constants.signals[signal] ?? 0);
  • scripts/run-server.mjs:37, in the wait loop: process.exitCode ??= code;
  • start-termux.sh:711-716 (the status check and the [ERROR] echo), with the session log tee armed at start-termux.sh:15-17 and restored at :719
  • package.json:25 ("start": "node scripts/run-server.mjs ..."), the pnpm surface
  • start.bat:406-412 (if errorlevel 1 then pause)
  • start.sh:445 (exec node ../../scripts/run-server.mjs dist/index.js, exits 130 but prints nothing)
  • packages/server/src/index.ts:108-109: the server logs Shutdown complete and exits 0
  • scripts/regressions/server-signal-shutdown.regression.ts:111: assert.equal(await exited, 130, "The launcher should retain its signal exit code");

What's happening

The launcher wrapper sets its own exit code to 128 plus the signal number (130 for Ctrl+C) the instant the signal arrives, before the server has even started shutting down. The server then shuts down gracefully and exits 0, but line 37 uses ??=, so the already-set 130 can never be lowered back to the child's 0. The wrapper therefore exits normally with status 130, and every launcher that checks the status treats that as a failure: start-termux.sh prints its [ERROR] line (and the tee is still armed, so it lands in the saved log), pnpm prints ELIFECYCLE, start.sh exits 130 silently, and start.bat would take its errorlevel branch.

Suggested fix

Do not set process.exitCode in the signal handler. Set it from the child's own close status instead: use the child's code when it exited on its own (0 after a graceful shutdown), and fall back to 128 plus the signal number only when the child was actually killed by the signal, that is when the close status is null. Then the Termux error line, the pnpm failure, and the Windows errorlevel branch all disappear on a normal stop.

If you would rather keep the 128+n convention for the wrapper, the alternative is to teach the two launchers that inspect the status to treat 130 and 143 as normal stops: one condition at start-termux.sh:714 and one at start.bat:407.

Either way, scripts/regressions/server-signal-shutdown.regression.ts:111 currently pins the present behaviour by asserting the launcher exits 130, so it has to change with the fix or the lane will look like a new regression.

Context

Introduced by PR #5962 ("Issue Sweep: assigned runtime, agents, and setup fixes"), which added scripts/run-server.mjs while fixing issue #5934 (Restart Server wedging or orphaning the replacement). #5934 never mentioned exit codes. PR #6137 did touch this file, but only the Windows kill path for issue #6119, replacing child?.kill(signal) with a win32 guard. The exit-code line right above it is unchanged, and #6137 did not touch start-termux.sh, start.sh, start.bat, package.json, or the server. Note that #6137 slightly raises the stakes on Windows: now that the server shuts down gracefully there, start.bat's errorlevel branch would fire after a fully successful stop. The Windows half (start.bat printing "Server exited unexpectedly" and blocking on pause) was not verified here, because cmd.exe may show its own "Terminate batch job (Y/N)?" prompt first and skip that branch. Everything else above was reproduced on Linux through a real terminal. Unreleased on staging: PR #5962 landed after v2.4.4.

Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6154 Originally assigned to: @SpicyMarinara on GitHub. Pressing Ctrl+C to stop Marinara Engine now finishes cleanly and then prints an error anyway. The server says "Shutdown complete", and right after that the launcher says the server exited with status 130, or pnpm prints a red ELIFECYCLE failure. Nothing is actually broken, but every normal stop looks like a crash, and on Termux that fake error line is also written into the saved session log people attach to support reports. ## How to reproduce (try it yourself) Use a spare checkout and a throwaway data folder, not the copy you normally run on port 7860. 1. In the checkout root, run `pnpm start`. 2. Wait for the line `Server listening at http://...`. 3. Press Ctrl+C once, the ordinary way you stop the app. **What you'll see:** the server logs `Received SIGINT; shutting down Marinara Engine` and then `Shutdown complete`, and immediately after that pnpm prints ` ELIFECYCLE Command failed with exit code 130.` Running `echo $?` prints 130. **What should happen:** after `Shutdown complete` the command should end quietly with status 0, because the stop succeeded. The same thing on Termux, where it is louder: 4. Run `./start-termux.sh`, wait for `Server listening`, press Ctrl+C once. 5. Run `tail -3 ~/.marinara-engine/logs/server-*.log`. **What you'll see:** on screen and in that saved log, ` [ERROR] Marinara Engine server exited with status 130.` after a completely normal stop. **What should happen:** no error line on screen and none in the saved log. To confirm it is the new wrapper and not the server: from `packages/server` run `node dist/index.js`, press Ctrl+C, and `echo $?` prints 0 with no error line. Run `node ../../scripts/run-server.mjs dist/index.js` instead, press Ctrl+C, and `echo $?` prints 130. Only the wrapper differs. ## Where it is At staging ac14dd704: - `scripts/run-server.mjs:13`, in the signal handler: `process.exitCode = 128 + (constants.signals[signal] ?? 0);` - `scripts/run-server.mjs:37`, in the wait loop: `process.exitCode ??= code;` - `start-termux.sh:711-716` (the status check and the `[ERROR]` echo), with the session log tee armed at `start-termux.sh:15-17` and restored at `:719` - `package.json:25` (`"start": "node scripts/run-server.mjs ..."`), the pnpm surface - `start.bat:406-412` (`if errorlevel 1` then `pause`) - `start.sh:445` (`exec node ../../scripts/run-server.mjs dist/index.js`, exits 130 but prints nothing) - `packages/server/src/index.ts:108-109`: the server logs `Shutdown complete` and exits 0 - `scripts/regressions/server-signal-shutdown.regression.ts:111`: `assert.equal(await exited, 130, "The launcher should retain its signal exit code");` ## What's happening The launcher wrapper sets its own exit code to 128 plus the signal number (130 for Ctrl+C) the instant the signal arrives, before the server has even started shutting down. The server then shuts down gracefully and exits 0, but line 37 uses `??=`, so the already-set 130 can never be lowered back to the child's 0. The wrapper therefore exits normally with status 130, and every launcher that checks the status treats that as a failure: start-termux.sh prints its `[ERROR]` line (and the tee is still armed, so it lands in the saved log), pnpm prints ELIFECYCLE, start.sh exits 130 silently, and start.bat would take its errorlevel branch. ## Suggested fix Do not set `process.exitCode` in the signal handler. Set it from the child's own close status instead: use the child's code when it exited on its own (0 after a graceful shutdown), and fall back to 128 plus the signal number only when the child was actually killed by the signal, that is when the close status is null. Then the Termux error line, the pnpm failure, and the Windows errorlevel branch all disappear on a normal stop. If you would rather keep the 128+n convention for the wrapper, the alternative is to teach the two launchers that inspect the status to treat 130 and 143 as normal stops: one condition at `start-termux.sh:714` and one at `start.bat:407`. Either way, `scripts/regressions/server-signal-shutdown.regression.ts:111` currently pins the present behaviour by asserting the launcher exits 130, so it has to change with the fix or the lane will look like a new regression. ## Context Introduced by PR #5962 ("Issue Sweep: assigned runtime, agents, and setup fixes"), which added `scripts/run-server.mjs` while fixing issue #5934 (Restart Server wedging or orphaning the replacement). #5934 never mentioned exit codes. PR #6137 did touch this file, but only the Windows kill path for issue #6119, replacing `child?.kill(signal)` with a win32 guard. The exit-code line right above it is unchanged, and #6137 did not touch start-termux.sh, start.sh, start.bat, package.json, or the server. Note that #6137 slightly raises the stakes on Windows: now that the server shuts down gracefully there, start.bat's errorlevel branch would fire after a fully successful stop. The Windows half (start.bat printing "Server exited unexpectedly" and blocking on `pause`) was not verified here, because cmd.exe may show its own "Terminate batch job (Y/N)?" prompt first and skip that branch. Everything else above was reproduced on Linux through a real terminal. Unreleased on staging: PR #5962 landed after v2.4.4. Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:02:59 +07:00
Author
Owner

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

Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.

<!-- gh-comment-id:5654636097 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.
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#3427
No description provided.