← Back to PRs

#12987: fix(cli): exit process after successful command completion

by omair445 open 2026-02-10 01:16 View on GitHub →
cli
## Summary Fixes CLI commands hanging indefinitely after completion due to persistent connections from eagerly-imported messaging providers. Closes #12904 ## Changes - **`run-main.ts`**: Added `process.exit(0)` after both `tryRouteCli()` and `program.parseAsync()` success paths ## Why It's Safe Long-lived commands (`gateway start`, `tui`, `agent --interactive`) never return from `parseAsync()` — they run until interrupted. The `process.exit(0)` only fires for short-lived commands that complete normally. Error paths already call `process.exit(1)`. ## Testing - Added test verifying `process.exit(0)` is called after routed command completes - All 5 tests pass (4 existing + 1 new) 🤖 Generated with Claude (AI-assisted) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates the CLI entry flow (`src/cli/run-main.ts`) to force the Node.js process to exit with code 0 after successful command completion. It adds `process.exit(0)` both when a command is handled by the routing layer (`tryRouteCli`) and after `commander` finishes `program.parseAsync()`, addressing hangs caused by eagerly-imported modules keeping the event loop alive. A new unit test was added in `src/cli/run-main.test.ts` to assert that a routed command triggers `process.exit(0)`. <h3>Confidence Score: 3/5</h3> - This PR is close to safe, but the new test setup is likely incorrect and can be flaky due to mocking order. - The `process.exit(0)` behavior change is straightforward and targeted, but the added test registers `vi.mock()` after importing `./run-main.js` at module scope, so the mock may not take effect reliably; this undermines the test’s ability to validate the change and could cause nondeterministic failures. - src/cli/run-main.test.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs