Repository navigation
fix(relay): guard all three delivery release paths, and explain a restoring source - #18038
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Relay ownership guard —
activate()insrc/relay/relay-pty-source-publication.tsnow derivesownedonce and scopes all three bail-outs (the!context?.onResponseSettledandunadmitted/subscriberfence releases, and thelegacy-ownercancel) to the record the caller actually owns, so a superseded transport can no longer release or cancel the delivery its own replacement opened. - Toast handling —
SSH_PTY_SOURCE_RESTORE_REQUIREDgets a widened match pattern, anisExplainedTerminalErrorentry, ahumanizeTerminalErrorreplacement, and an i18nsourceRestoringkey, deliberately kept out ofUNREATTACHABLE_SESSION_SOURCES. - Tests — a new superseded-activation integration test plus two toast tests; I confirmed the relay test genuinely fails (
expected true to be false) with the guard reverted, so the coverage is real. - Line budget — the
deliveryClosedUnderRecordwrapper was inlined to stay under the 300-linemax-linescap (file sits at 298 counted lines, no new bypass).
The guard is complete (the two remaining current?.clientId === context.clientId paths were already owner-checked), the deliberately non-ported items are clearly documented, and the residual legacy-owner behavior change is intentional and matches the lease stack's ownership model.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…r owns Two of the three release/cancel sites in RelayPtySourcePublication.activate() acted on `current` unconditionally. A superseded transport re-entering activate() therefore released — or cancelled and deleted — the delivery its own replacement had just opened: releasing the fence resumes a send the replacement is still rotating, and retiring it blanks the pane that owns it. The live path is the unadmitted/subscriber branch, so guarding only the first site leaves the defect exactly as it was; all three now act only on a record the caller still owns. Also give the restore-required token its own toast copy. It must not join UNREATTACHABLE_SESSION_SOURCES: that copy says "Open a new terminal", which here abandons a running agent on a PTY the relay has just proven alive (docs/reference/ssh-execution-boundary.md).
2f53970 to
1fc250a
Compare
|
Retargeted to Note for readers: on |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe relay now limits rotation-fence release, cancellation, and wake operations to the delivery owner. Superseded activation coverage verifies that replacement deliveries remain active. The renderer now recognizes Merge Risk: 🔵 Low · up to The PR prevents superseded clients from releasing or cancelling another client's PTY delivery and replaces a raw restoration marker with clear user messaging. A bounded follow-up risk remains for reconnects that reuse the same client identity, where stale cleanup could briefly disrupt that client's delivery; merge is reasonable with owner awareness. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed context, rationale, linked issue information, implementation scope, exclusions, and test results. It does not include the template's explicit Visual Proof, AI Disclosure, Review, Notes, or Checklist sections, but the core description is substantially complete. Full details: Linked Issues checkExplanation The PR implements the three-site delivery ownership guard and restore-required toast handling from [ Resolution Implement the remaining [ Full details: Docstring CoverageExplanation Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…r owns (stablyai#18038) Two of the three release/cancel sites in RelayPtySourcePublication.activate() acted on `current` unconditionally. A superseded transport re-entering activate() therefore released — or cancelled and deleted — the delivery its own replacement had just opened: releasing the fence resumes a send the replacement is still rotating, and retiring it blanks the pane that owns it. The live path is the unadmitted/subscriber branch, so guarding only the first site leaves the defect exactly as it was; all three now act only on a record the caller still owns. Also give the restore-required token its own toast copy. It must not join UNREATTACHABLE_SESSION_SOURCES: that copy says "Open a new terminal", which here abandons a running agent on a PTY the relay has just proven alive (docs/reference/ssh-execution-boundary.md). Mirror-Of: 3d3b4f9
…r owns (stablyai#18038) Two of the three release/cancel sites in RelayPtySourcePublication.activate() acted on `current` unconditionally. A superseded transport re-entering activate() therefore released — or cancelled and deleted — the delivery its own replacement had just opened: releasing the fence resumes a send the replacement is still rotating, and retiring it blanks the pane that owns it. The live path is the unadmitted/subscriber branch, so guarding only the first site leaves the defect exactly as it was; all three now act only on a record the caller still owns. Also give the restore-required token its own toast copy. It must not join UNREATTACHABLE_SESSION_SOURCES: that copy says "Open a new terminal", which here abandons a running agent on a PTY the relay has just proven alive (docs/reference/ssh-execution-boundary.md).

Replaces #18016. Ports only what the #17951 lease stack does not already have, expressed in the stack's existing vocabulary.
Why this exists: #18016 and the #17951 stack independently fixed the same defect with parallel vocabularies (
SSH_SOURCE_RESTORE_REQUIREDvsSSH_PTY_SOURCE_RESTORE_REQUIRED_ERROR, retry 3 vs 2,isProvenSshSessionGoneErrorvsisSshSessionGoneError), conflicting on six files. #17951 is an ancestor of four PRs, so its vocabulary wins and #18016 should close in favour of this.Item 1 — the three-site ownership guard. Zero sites were guarded, not one.
I reported that the stack guarded one of three release/cancel sites in
activate(). Checked:src/relay/relay-pty-source-publication.tsat the stack tip is byte-identical tomainfor this file. None of the three were guarded.All three now derive ownership once and act only on a record the caller still owns:
Three configurations of the same new test, verbatim:
AssertionError: expected true to be falseatrelay-pty-source-superseded-activation.test.ts:151:81So the one-site fix #18016 shipped would not have closed the bug it targeted. The live path is the
unadmitted/subscriberbranch: a superseded transport released the rotation fence of the delivery its own replacement had opened, so a publish landed on a delivery still rotating.Two deliberate non-ports, both flagged rather than silently dropped:
clientTransportGeneration/sameClientTransport— that is fix(ssh): stop treating a live PTY's retired source delivery as proof of death #18016's second root cause (delivery record keyed on client id alone) and needs a newRequestContext.transportGenerationfield the stack lacks. Ownership here is expressed with the stack's existingrecord.clientId === context.clientId, the same comparisonactivate()already makes twice below.context.isStale()in the first bail-out — a separate behavior change; out of scope.One forced adjustment: the guard pushed the file to 301 counted lines against the 300
max-linescap. Rather than a disable (forbidden), the one-line private wrapperdeliveryClosedUnderRecordwas inlined at its two call sites.Residual behavior note, stated: an unowned record whose calling client is a
legacy-owneris no longer cancelled by that caller. It stays owned by its actual source-owner client and is retired by that client's own settlement/exit path — which is the point.Item 2 — toast handling. Was missing, ported.
SSH_PTY_SOURCE_RESTORE_REQUIREDwas matched nowhere inTerminalErrorToast.tsx, so the raw marker reached the user. It now has its own pattern, anisExplainedTerminalErrorentry, its ownhumanizeTerminalErrorreplacement, and asourceRestoringkey.Kept deliberately out of
UNREATTACHABLE_SESSION_SOURCES— that copy says "Open a new terminal", which here abandons a running agent.The pattern is widened over #18016's, because the stack's message carries a trailing reason word that #18016's did not:
Both new tests fail before / pass after:
describes a retired output source as reconnecting, not as a lost session— before:expected 'SSH_PTY_SOURCE_RESTORE_REQUIRED: remo…' not to contain 'SSH_PTY_SOURCE_RESTORE_REQUIRED'suppresses the issue link while a live session restores its output source— before:expected false to be trueItem 3 — render-time humanization. Already present, skipped, no code written.
grep -rn "humanizeTerminalError" src/returns exactly two hits, both inTerminalErrorToast.tsx: the definition andconst displayError = humanizeTerminalError(error)at render. Nothing humanizes before storing,remote-runtime-pty-transport.tsstores the raw message, andmarkRecoveryHealthyreplays those raw strings — soclearPaneTerminalError's match still lines up. #18016's change to that file was an import swap only.User-facing regressions
None expected. The stack's token, retry count and predicate are untouched. Nothing certifies death from a
pty.attachnot-found (see #18029, which reverts exactly that).Testing
Both new/changed suites: 36 passed. Full relay
pty-sourceset (12 files) +dispatcher+ssh-pty-consumer-session-adapter: 148 passed. All 421terminal-panesuites: 4120 passed.tc:nodeandtc:webclean;check:code-quality:changed0 new findings across 47 files;check:max-lines-ratchetOK with no new bypasses.Not ported
src/shared/ssh-pty-failure-tokens.ts,isProvenSshSessionGoneError(a no-op over the stack's predicate once tokens are disjoint), the= 3retry constant, and the duplicate reattach/absence-verdict tests.