Repository navigation
fix(runtime): exit once the invocation is complete - #306
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
A successful run only returned from run(); the process then waited for the event loop to drain. On the Bun release binary the pooled keep-alive sockets of globalThis.fetch held it for ~50 s after the answer was printed. All background work (update check, telemetry flush) is already awaited inside run(), so add runToExit(), which awaits run(), flushes stdout/stderr and exits with the process exit code, and use it in the bl and kscli entries. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #294
Cause
packages/cli/src/main.tsends withvoid createCli(...).run().process.exitis only reached on errors, SIGINT and EPIPE, so after a successful command the process waits for the event loop to drain. On the Bun release binary the keep-alive sockets pooled byglobalThis.fetchkeep it alive for ~50 s after the answer is printed (undici on Node drops them after ~4 s, as the timings in the issue show).Fix
Add
runToExit(cli, argv?)tobailian-cli-runtime: it awaitsrun(), drains stdout and stderr, and exits withprocess.exitCode ?? 0. Theblandksclientries use it. All background work (update check, telemetry flush) is already awaited insiderun(), so nothing is cut short, and errors still exit throughhandleError.run()itself is unchanged, so the in-process e2e harness is unaffected. The update-check registry question from the issue is a separate ask and is not touched here.Test
New
packages/runtime/tests/run-to-exit.test.ts(exits afterrun()resolves with code 0, keeps a code set by the run, does not exit whilerun()is pending). Fails before the change (runToExitdoes not exist) and passes after; the fullpackages/runtimesuite passes (504 tests), the subprocess e2e suites that spawnmain.ts(registry smoke, update notice, usage summary) still pass, andvp fmt --checkis clean.Not verified here: the Windows release binary itself. It would be worth confirming on the binary with
bl usage token-plan --output jsonthat the exit now follows the output immediately.Disclosure
This change and its tests were prepared with an AI coding agent (Claude).