Skip to content

fix: skip per-command exit logs after a shutdown signal - #628

Open
pintu544 wants to merge 1 commit into
open-cli-tools:mainfrom
pintu544:fix/skip-exit-logs-after-signal
Open

pintu544 wants to merge 1 commit into
open-cli-tools:mainfrom
pintu544:fix/skip-exit-logs-after-signal

Conversation

@pintu544

@pintu544 pintu544 commented Oct 8, 2026

Copy link
Copy Markdown

Fixes #255

Problem

After pressing Ctrl-C, every command logs exited with code SIGINT. When the shell reclaims the terminal before teardown finishes (e.g. the npm/yarn wrapper exits first), those late lines land on the fresh prompt and visually corrupt it — the prompt only reappears after another Ctrl-C or any command that writes to stdout. All reporters describe the same recovery pattern, which points at late output clobbering the prompt rather than a dead terminal.

Fix

Once KillOnSignal catches SIGINT/SIGTERM/SIGHUP, the per-command exit log lines are noise — the user requested the shutdown, so the exits are expected (the codebase already remaps post-SIGINT exits to code 0 for the same reason). This change skips just those log lines:

  • KillOnSignal accepts an optional onSignal callback, invoked synchronously when a signal is caught, before commands are killed.
  • LogExit accepts an optional isShuttingDown predicate; close events arriving while it returns true are not logged.
  • lib/index.ts wires the two together with a shared flag. Both new options are optional, so the public API stays backwards compatible.

Exit codes, kill behavior, and shutdown ordering are unchanged — closes that happen before the signal are still logged, and normal (non-signal) exits log exactly as before.

Verification

  • New unit tests: LogExit skips logging while shutting down / logs when not; KillOnSignal invokes onSignal.
  • Updated bin/index.spec.ts: the SIGINT test now asserts exit code 0 and the absence of the exit log line.
  • Full suite: 647/647 tests pass; eslint and tsc --noEmit clean.
  • Manual end-to-end: group SIGINT on two signal-trapping children → exit code 0 with no late output (previously printed both exited with code SIGINT lines); normal echo/exit 3 run still logs exits and returns code 1.

After the user initiates a shutdown with SIGINT/SIGTERM/SIGHUP, the
per-command 'exited with code ...' lines are noise: the shutdown was
requested, so of course the commands exited. Worse, when the shell
reclaims the terminal before teardown finishes, those late lines land
on the fresh prompt and visually corrupt it.

KillOnSignal now exposes an onSignal hook; LogExit takes an
isShuttingDown predicate wired to it in lib/index.ts. Exit codes and
shutdown behavior are unchanged — only the log lines are skipped, and
only for closes that happen after the signal was caught.

Fixes open-cli-tools#255
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.836% (+0.006%) from 98.83% — pintu544:fix/skip-exit-logs-after-signal into open-cli-tools:main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal input prompt not shown on script exit

2 participants