Skip to content

fix(runtime): flush tracked stdout/stderr before exit after run - #348

Merged
hopelynd merged 3 commits into
mainfrom
fix/exit-after-run
Nov 27, 2026
Merged

hopelynd merged 3 commits into
mainfrom
fix/exit-after-run

Conversation

@hopelynd

Copy link
Copy Markdown
Collaborator

Summary

  • Exit promptly after a successful CLI run so Bun keep-alive sockets cannot linger (~50s on Windows release binaries), addressing [bug]: bl lingers ~50 s after answering (Windows) #294 without the Bun pipe truncation from fix(runtime): exit once the invocation is complete #306
  • Track real stdout/stderr write callbacks before process.exit, including error and interrupt paths, so large piped JSON is not silently cut at ~64KB
  • Use a short interrupt flush timeout and a second Ctrl-C force-exit; on flush timeout emit a bilingual diagnostic without changing exit codes

Description

Product entries (bl / kscli) now go through runToExit, which installs write tracking, awaits run(), flushes pending writes, then exits. Empty write("") drain is unreliable on Bun when stdout is a pipe, so each real write's callback is the completion signal, with a timeout fallback.

handleError and the default SIGINT path also flush before exit (500ms on interrupt). A second SIGINT during that flush exits immediately. Flush timeout returns a boolean and writes a stderr warning via writeSync(2, …) so agents can observe truncation risk without flipping a successful exit code.

This is an alternative to #306: same exit-after-run direction, with Bun-safe flushing and coverage for Node/Bun piped large stdout. Update-check registry / failed-check backoff from #294 are left for follow-up PRs—please use Refs #294 semantics rather than closing the whole issue solely via this change.

@hopelynd
hopelynd merged commit 463c756 into main Nov 27, 2026
7 checks passed
hopelynd added a commit that referenced this pull request Nov 27, 2026
Resolve the conflict in packages/core/src/telemetry/sink.ts between
PR #348 (await in-flight local JSONL writes) and PR #349 (per-site
Tracker map):

- Keep both state holders: inflightLocalWrites (from #348) and
  remoteBySite (from #349). Drop remoteClient / remoteInitialized,
  which initRemoteForSite() fully replaced and nothing references.
- flushTelemetry() drains _sendAll() on every site tracker, then waits
  on local writes and remote sends under the same budget; only remote
  work is abortable on timeout.
- Merge both doc-comment variants into one accurate description.

Verified: vp check (0 errors), 101 core telemetry tests, 65 runtime
flush/exit/telemetry-stage tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant