fix(escrow): stop losing sessions when the retrieve handoff runs late - #244
Merged
Conversation
Three compounding defects in the session-escrow retrieve path could lose a terminal session across an app relaunch: - Client recv timeout (0.5s) was shorter than the holder's own per-request drain-stop budget (3s), so the client could abandon and close its socket while the holder was still doing legitimate work. Raised to 5s with an explicit invariant documented alongside retrieveDrainStopTimeout. - The holder never ignored SIGPIPE and never set SO_NOSIGPIPE on its sockets, so a late send into an abandoned connection could raise SIGPIPE and kill the whole holder process, dropping every other escrowed session it still held. Now ignored process-wide in the holder's run() before any socket work, plus SO_NOSIGPIPE on every escrow socket (connect/bind/accept) as defense in depth. - handleRetrieveRequest marked a session handed off before confirming the response send actually succeeded. sendRetrieveResponse now returns whether the send landed; on failure the session is reinserted into the registry and a fresh drain thread is started on the same fd instead of leaking it. Also adds dilog (Release-safe) instrumentation across the retrieve path so a future incident like this is diagnosable outside DEBUG builds.
Reproduces the exact socket sequence SessionEscrowHolder.run()'s accept loop uses (bindListening -> connect -> accept -> suppressSigPipe) against a peer that already hung up, and asserts the retrieve-response send fails cleanly (false/EPIPE) instead of the process being killed by SIGPIPE. Confirmed separately (not committed) that omitting suppressSigPipe reproduces a hard SIGPIPE crash on this exact sequence; not committed as a literal failing-first commit because that would crash the shared XCTest process for the whole bundle, not just this test.
Member
Author
|
cross-model review notes, for the record: two residual windows are accepted rather than fixed here. (1) a successful sendmsg still only proves the kernel queued the fd, not that the client read it; with the 5s/3s budget invariant the client no longer abandons live handoffs, so hitting this now requires the client process dying inside a microsecond window, which an ack roundtrip would only mirror, not close. (2) a holder that is alive but frozen costs 5s per session serially at launch; previously it cost 0.5s and the session. a per-socket-path circuit breaker (first timeout skips remaining retrieves against that holder) is filed as follow-up. |
2 tasks
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.
What this does
Fixes running agent sessions dying during app relaunch (reported today: 3 workspaces updating, 1 came back as a bare shell). The reclaim protocol let the app give up on a holder after 0.5s while the holder's own handoff budget was 3.0s. A holder finishing in that gap sent the PTY fd into a connection the app had abandoned, which either killed the holder outright (uncaught SIGPIPE, taking every remaining session with it) or let the kernel destroy the fd in flight (child gets SIGHUP, dies). Either way the holder had already marked the session handed off before confirming the send, so there was no way back.
Four changes:
Review order
Test plan