Skip to content

core: add BlitConnection.awaitSessionExit#70

Merged
mgasner merged 1 commit into
mainfrom
indent-2026-06-23-await-session-exit
Jun 24, 2026
Merged

core: add BlitConnection.awaitSessionExit#70
mgasner merged 1 commit into
mainfrom
indent-2026-06-23-await-session-exit

Conversation

@mgasner

@mgasner mgasner commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add BlitConnection.awaitSessionExit(sessionId, { timeoutMs? }) that resolves with the session's exitStatus once it transitions to state === "exited" or state === "closed", immediately if it's already there, with { exitStatus: null, timedOut: true } on timeout, and unsubscribes either way.
  • Add focused BlitConnection.test.ts coverage for normal exit, signal exit, already-exited fast path, CLOSED-without-status, legacy frames mapped to EXIT_STATUS_UNKNOWN, the timeout path (asserting the listener is dropped so a late EXITED doesn't re-resolve), and the unknown-session fast path.

Motivation
The downstream BashSessionRegistry in indent-com/neo#872 needs a per-session "wait for exit" primitive. Today it gets there by dual-subscribing — connection.subscribe() for the state === "closed" edge, plus a hand-rolled S2C_EXITED frame listener bolted onto the transport for the exit-code edge — and a near-line-for-line copy of NodeUnixSocketTransport (~184 LOC) exists in neo only to expose that frame hook. BlitConnection already parses the wire frame, maps ptyId → sessionId, and writes updateSession({ 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 in BlitConnection.test.ts.
  • Prettier and TypeScript on the touched files clean (the only tsc errors in the sandbox come from the stubbed @blit-sh/browser package, not from this change).

This PR adds the method only; a 0.36.0 release tag is the follow-up so neo can pin @blit-sh/core@^0.36.0 and delete its transport copy in the stacked PR on top of #872.

Open in Indent
Tag @indent to continue the conversation here.

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>
@mgasner mgasner added the indent label Jun 23, 2026 — with indent
@github-actions

Copy link
Copy Markdown

🔗 Preview: https://blit-nupkqjyvk-indent.vercel.app

@github-actions

Copy link
Copy Markdown

Coverage

Crate Lines Functions Regions
alacritty-driver 63.7% (626/982) 67.1% (49/73) 64.3% (919/1429)
browser 0.0% (0/807) 0.0% (0/65) 0.0% (0/1370)
cli 28.1% (1208/4299) 41.3% (171/414) 31.1% (2182/7019)
compositor 1.0% (93/9234) 2.0% (8/400) 1.2% (146/12408)
fonts 76.8% (486/633) 85.5% (47/55) 77.9% (922/1183)
gateway 25.7% (362/1411) 29.0% (36/124) 19.4% (449/2318)
proxy 18.3% (150/818) 20.9% (24/115) 20.4% (260/1277)
remote 71.5% (1975/2763) 81.4% (188/231) 74.1% (3737/5045)
sd-notify 73.9% (68/92) 100.0% (6/6) 83.2% (109/131)
server 18.7% (2186/11701) 33.6% (251/748) 20.1% (3660/18180)
ssh 1.9% (7/374) 3.2% (1/31) 0.7% (4/613)
webrtc-forwarder 2.7% (72/2624) 2.1% (4/187) 1.2% (50/4335)
webserver 63.5% (753/1185) 70.8% (121/171) 67.8% (1380/2034)
Total 21.6% (7986/36923) 34.6% (906/2620) 24.1% (13818/57342)

@mgasner mgasner requested a review from pcarrier June 23, 2026 21:21
@mgasner mgasner merged commit 86b9fcc into main Jun 24, 2026
11 of 12 checks passed
@mgasner mgasner deleted the indent-2026-06-23-await-session-exit branch June 24, 2026 17:15
@indent indent Bot mentioned this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants