core: add BlitConnection.awaitSessionExit#70
Merged
Conversation
Lets callers wait on a single session's exit without rolling their own
listener stack on top of `connection.subscribe()` (or, worse, parsing
S2C_EXITED frames at the transport layer). The connection already
records exit state via S2C_EXITED → updateSession({state:"exited",
exitStatus}); this exposes that as a per-session promise with an
optional timeout, honouring EXIT_STATUS_UNKNOWN for legacy frames.
The downstream motivation is neo's BashSessionRegistry (PR
indent-com/neo#872), which currently dual-subscribes via subscribe() +
a hand-rolled transport-level exit-frame listener; adopting this API
removes ~50 LOC and a hand-rolled NodeIpcBlitTransport copy of
NodeUnixSocketTransport.
Generated with [Indent](https://indent.com)
Co-Authored-By: Indent <noreply@indent.com>
|
🔗 Preview: https://blit-nupkqjyvk-indent.vercel.app |
Coverage
|
pcarrier
approved these changes
Jun 23, 2026
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.
Summary
BlitConnection.awaitSessionExit(sessionId, { timeoutMs? })that resolves with the session'sexitStatusonce it transitions tostate === "exited"orstate === "closed", immediately if it's already there, with{ exitStatus: null, timedOut: true }on timeout, and unsubscribes either way.BlitConnection.test.tscoverage for normal exit, signal exit, already-exited fast path,CLOSED-without-status, legacy frames mapped toEXIT_STATUS_UNKNOWN, the timeout path (asserting the listener is dropped so a lateEXITEDdoesn't re-resolve), and the unknown-session fast path.Motivation
The downstream
BashSessionRegistryin indent-com/neo#872 needs a per-session "wait for exit" primitive. Today it gets there by dual-subscribing —connection.subscribe()for thestate === "closed"edge, plus a hand-rolledS2C_EXITEDframe listener bolted onto the transport for the exit-code edge — and a near-line-for-line copy ofNodeUnixSocketTransport(~184 LOC) exists in neo only to expose that frame hook.BlitConnectionalready parses the wire frame, mapsptyId → sessionId, and writesupdateSession({ state: "exited", exitStatus }); this just surfaces the existing state machine as a promise. Once it ships, neo can drop both the bespoke transport and the dual-subscribe shim.Testing
cd js/core && pnpm test— full core suite green (354 tests, 10 skipped); 7 new cases inBlitConnection.test.ts.tscerrors in the sandbox come from the stubbed@blit-sh/browserpackage, not from this change).This PR adds the method only; a
0.36.0release tag is the follow-up so neo can pin@blit-sh/core@^0.36.0and delete its transport copy in the stacked PR on top of #872.Tag
@indentto continue the conversation here.