Skip to content

fix: graceful SIGINT/SIGTERM signal handling + 22 tests#486

Merged
bradygaster merged 2 commits intobradygaster:devfrom
diberry:squad/fix-sigint-handling
Mar 22, 2026
Merged

fix: graceful SIGINT/SIGTERM signal handling + 22 tests#486
bradygaster merged 2 commits intobradygaster:devfrom
diberry:squad/fix-sigint-handling

Conversation

@diberry
Copy link
Copy Markdown
Collaborator

@diberry diberry commented Mar 21, 2026

fix: graceful SIGINT/SIGTERM signal handling

Adds signal handlers to prevent orphaned processes when users press Ctrl+C.

Problem

The CLI had no signal handlers. Pressing Ctrl+C during long operations (shell sessions, watch mode, remote bridge) could leave child processes running indefinitely.

Changes

3 files, 379 lines added:

  1. packages/squad-cli/src/cli-entry.ts — Top-level safety net handler

    • Registers SIGINT/SIGTERM handlers early in bootstrap
    • 3s cleanup timeout (unref'd so it doesn't block exit)
    • Double-signal force-exits immediately
    • Exit codes: 130 (SIGINT), 143 (SIGTERM)
  2. packages/squad-cli/src/cli/shell/index.ts — Shell-specific handler

    • Calls Ink's unmount() to flow through existing cleanup (session close, client disconnect, telemetry shutdown)
    • Ensures readline interface is properly closed
  3. test/cli/signal-handling.test.ts22 tests

    • Exit code verification (130/143)
    • Double-signal force-exit behavior
    • 3s cleanup timeout with unref()
    • Handler registration validation
    • Shell-specific unmount flow

Risk

Low. Only adds behavior on signal — doesn't change any existing code paths. Follows existing patterns in the repo. Build passes clean.

@diberry
Copy link
Copy Markdown
Collaborator Author

diberry commented Mar 21, 2026

@bradygaster — Critical fix: CLI had no signal handlers — Ctrl+C during shell/watch/serve could orphan child processes. 44 lines of code + 22 tests. Low risk, high impact.

Copilot AI added 2 commits March 21, 2026 23:55
Add signal handlers to prevent orphaned processes when users press
Ctrl+C during long-running CLI operations.

Changes:
- cli-entry.ts: Top-level safety-net handler with 3s cleanup timeout
  and double-signal force-exit (130 for SIGINT, 143 for SIGTERM)
- shell/index.ts: Shell-specific handler that calls Ink's unmount()
  to trigger the existing cleanup path (session close, client
  disconnect, telemetry shutdown), then exits with signal code

Follows existing repo patterns (aspire.ts, watch.ts, rc.ts).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests for SIGINT/SIGTERM handlers added in previous commit:
- Exit code verification (130 for SIGINT, 143 for SIGTERM)
- Double-signal force-exit behavior
- 3s cleanup timeout with unref
- Handler registration validation
- Shell-specific unmount flow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bradygaster bradygaster force-pushed the squad/fix-sigint-handling branch from c04ab63 to 0571d45 Compare March 22, 2026 06:56
Copy link
Copy Markdown
Owner

@bradygaster bradygaster left a comment

Choose a reason for hiding this comment

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

EECOM review: Signal handling fix looks solid. Top-level safety net + shell-specific unmount path are both well-structured. 22 new tests cover exit codes, double-signal force-exit, cleanup timeout, and handler registration. Rebased on dev (includes #483 timeout fix + #480 race fix). CI failure was pre-existing platform-adapter timeouts — now resolved by the rebase.

@bradygaster bradygaster merged commit aa01a0e into bradygaster:dev Mar 22, 2026
1 of 2 checks passed
chrislomonico pushed a commit to clomonico/squad that referenced this pull request Mar 26, 2026
…dygaster#486)

Add E2E journey test covering session persistence across shell restarts:

- Session-store unit tests (create, save, load, list, 24h expiry, rehydration)
- /sessions command integration (empty state, listing with counts)
- /resume command integration (usage hint, unknown ID, prefix match)
- Full day-1/day-2 journey: save on exit, detect on return, resume with history

Closes bradygaster#398

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants