Skip to content

fix(runtime): exit once the invocation is complete - #306

Open
pcbeingused333 wants to merge 1 commit into
modelstudioai:mainfrom
pcbeingused333:fix/exit-after-run
Open

pcbeingused333 wants to merge 1 commit into
modelstudioai:mainfrom
pcbeingused333:fix/exit-after-run

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #294

Cause

packages/cli/src/main.ts ends with void createCli(...).run(). process.exit is 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 by globalThis.fetch keep 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?) to bailian-cli-runtime: it awaits run(), drains stdout and stderr, and exits with process.exitCode ?? 0. The bl and kscli entries use it. All background work (update check, telemetry flush) is already awaited inside run(), so nothing is cut short, and errors still exit through handleError. 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 after run() resolves with code 0, keeps a code set by the run, does not exit while run() is pending). Fails before the change (runToExit does not exist) and passes after; the full packages/runtime suite passes (504 tests), the subprocess e2e suites that spawn main.ts (registry smoke, update notice, usage summary) still pass, and vp fmt --check is clean.

Not verified here: the Windows release binary itself. It would be worth confirming on the binary with bl usage token-plan --output json that the exit now follows the output immediately.

Disclosure

This change and its tests were prepared with an AI coding agent (Claude).

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

No deployments
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.

[bug]: bl lingers ~50 s after answering (Windows)

1 participant