Repository navigation
fix(ssh): stop a request that never left the client from tombstoning its operation id - #17928
Conversation
|
the model provider had a temporary upstream failure. The provider refused or dropped the request mid-run — nothing in your repo or your credentials is at fault. Re-trigger Pullfrog; if it keeps happening, check the provider's status page.
|
23d0539 to
c54be7e
Compare
fa9543b to
2f62120
Compare
There was a problem hiding this comment.
ℹ️ No critical issues — the fence fix and the verdict carve-out are correct, with one minor robustness concern on the relay pause wrapper inline.
Reviewed changes
- Fenced undispatched spawns —
SshChannelMultiplexer.requestnow marks its two pre-dispatch rejections (disposed mux, pre-aborted signal) with ansshRequestUndispatchedflag, andrequestSshAgentSessionCreateskips the 24h replay tombstone when that flag is present, so a spawn that provably never left the client is no longer fenced. - Undispatched carve-out on the unverifiable verdict —
isSshRequestOutcomeUnverifiablereturnsfalsefor marked-undispatched errors, so the three lost-link verdict call sites report "not reached" rather than "may still be running" when the peer provably never saw the request. - Relay reaper backpressure guard —
RelayClientgains areadsPausedflag set insidecreateClient's decoder wiring, andreapSilentClientsskips a client whose reads the relay itself paused, mirroring the client-sidedecoderReadPausedguard.
The regression tests drive a real mux/transport and a real FrameDecoder backpressure pause (with setImmediate left unfaked) rather than poking private state, so both guards are meaningfully covered.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| // Why the flag is set here rather than inside the reaper: the decoder owns the pause, and | ||
| // the reaper must not count silence it caused itself. | ||
| pause: () => { | ||
| client.readsPaused = true |
There was a problem hiding this comment.
A pauseReads() throw leaves readsPaused stuck true, silently exempting that client from the reaper forever. The wrapper sets the flag before calling sourceOptions?.pauseReads?.(), but FrameDecoder.acquirePause reverts its own paused to false and rethrows on that throw, so the decoder recovers while this flag does not. The resume side is fine — releasePause clears the decoder's paused before invoking it — but pause has the opposite ordering. The client-side mirror (pauseDecoderReads) routes these throws to handleProtocolError rather than trusting the flag.
Technical details
# readsPaused can diverge from FrameDecoder.paused on a pause throw
## Affected sites
- src/relay/dispatcher-client-lifecycle.ts:151 — `pause: () => { client.readsPaused = true; sourceOptions?.pauseReads?.() }`
- src/shared/relay-frame-decoder.ts:243 — `acquirePause` sets `paused = true`, calls `pause()`, and on throw reverts `paused = false` and rethrows
## Required outcome
- `readsPaused` must track `FrameDecoder.paused` (a throw leaves both `false`), or the throw must be routed somewhere that disposes the client.
## Suggested approach
- Set `client.readsPaused = true` only after `sourceOptions?.pauseReads?.()` returns, or wrap the call in try/finally that reverts the flag on throw; alternatively adopt the client-side pattern (catch and treat as a protocol error).c54be7e to
c58e8bb
Compare
2f62120 to
36859d0
Compare
c58e8bb to
0632910
Compare
36859d0 to
4545e6c
Compare
30918e1
into
fix/ssh-link-wedge-and-probe-verdict

Found while auditing whether #17817/#17838/#17871 make reconnect lossy: they make three transports declare death faster, so anything fragile about in-flight RPCs gets hit more often.
First, a correction to the premise I was working from
"Before #17817 a wedged link hung forever" is not true at the RPC layer.
ssh-channel-multiplexer.tsgives every request a 30s client-local deadline that fires regardless of link state, so callers already got a definite-looking failure. What #17817 actually changes is 30s → 20s, a different error code, and all in-flight requests torn down at once instead of one at a time. A real widening, not a new class.The bug
SshChannelMultiplexer.requestrejects a disposed mux and an already-aborted signal synchronously — beforenextRequestId++, beforesendMessage. Nothing is ever framed.requestSshAgentSessionCreatetagged thoseagentSessionOperationOutcome: 'unknown'anyway. Its comment says "after request dispatch", but the catch covers pre-dispatch too. That setsretainReplayFenceand tombstones the operation id for 24 hours, so a create that provably never left the client becomes permanently unissuable under its own id — every mobile reconnect replay rethrowsSSH connection lost, reconnecting...for a day.Reachable because
SshAgentSessionCapabilities.supportsCreateOperationsmemoizes its probe per-mux (ssh-agent-session-capabilities.ts:34-49): once primed,SshPtyProvider.spawngoes straight to the dispatch seam with no round trip, so a dispose landing duringcreateAgentSession's async preflight arrives at an already-disposed mux. #17817 widens this directly.What ships here
1. The fence fix. Mark the two pre-dispatch rejections in the multiplexer — the only place that knows whether a request was framed — and have the caller read that fact rather than infer it. Mid-flight losses carry an identical code and message and keep the fence, because a PTY may genuinely be live on the host.
Two regression tests against a real mux and transport. Reverting the fix makes the first fail (
expected … to not have property "agentSessionOperationOutcome") while keeps the fence after dispatch still passes — so it is not just disabling the fence.A note on shape: my first attempt pre-checked
mux.isDisposed()at the call site, and it brokessh-pty-provider-claim-incarnation.test.tsagainst five partial mux stubs. That was the design saying the caller should not be the one asking.2. The undispatched carve-out on the unverifiable verdict. #17817 introduces
isSshRequestOutcomeUnverifiable, used by the three call sites that phrase a lost-link verdict to a user. Once the multiplexer can say a request was never framed, that predicate should sayfalsefor it — the peer provably never saw it, so it is notunverifiable, it is un-run. One test.3. A reaper guard for a pause the relay caused itself. While the frame decoder holds reads paused for backpressure no frame can decode, so
lastReceivedAtfreezes. #17817's silence reaper would then reap a client the relay itself stopped listening to. The client-side multiplexer already guards the mirror case withdecoderReadPaused; this is the relay half, and the flag is set insidecreateClient's decoder wiring rather than in the reaper, because the decoder is what owns the pause.The tests drive a real pause — a chunk carrying more frames than the decoder delivers in one turn, with
setImmediateleft unfaked so the continuation cannot run insideadvanceTimersByTime— rather than poking the private flag. That is what makes thecreateClientwiring itself covered: swallowing either thepauseReadsor theresumeReadsforward fails a test, as does deleting the reaper's guard.Verification
One finding this audit produced that is NOT fixed here
pty.spawncan leak an agent process unboundedly. Filed separately — the host holds an idempotency ledger open for 24h while the client memoizes the rejection for 24h and never re-issues, so an agent CLI keeps running on the user's machine, invisible to the client. Closing it is the general replay layer, which was explicitly out of scope.(An earlier revision of this body listed the three
unverifiableverdict call sites here as unfixed. They are fixed — in #17817, where the regression originates. This PR only adds the undispatched carve-out on top.)Also audited: the socket-takeover TOCTOU — verdict is do not convert
An architectural review flagged
relay-socket-ownership.ts:100-113as probe → unlink → listen with a race, and recommended bind-temp +link(). The cited race is already closed — the review stopped before the fence at:191-205:blockedIdentityis captured at:151before the probe, andunlinkIfStillStalere-stats at:192and compares dev + ino + ctimeNs immediately before theunlinkSyncat:200, refusing on any mismatch. For a third party to bind there it must first unlink the stale inode and create a fresh one — new ctimeNs — so unlinking its socket cannot happen.Three reasons not to convert anyway:
bind()on an AF_UNIX path already haslink()'s atomicity — create-or-EADDRINUSE— so the retrylisten()at:72already refuses a racer..tmpsockets on crash and spendsun_pathbudget on a path already ~83 of 104 bytes.Nothing in #17821 becomes unnecessary — it answers "is the incumbent process live and does it hold PTYs" via
lsof+ argv re-verification, whichEEXISTcannot answer.One thing for whoever owns #17821:
RelaySocketOwnershiphas no direct test file. Since that PR elevates this class to the authority, its "refuse to steal a socket that accepts" and "refuse when the inode changed" invariants deserve pinning.