Repository navigation
fix(ssh): restore the reconnect model-paint gate dropped by #15166 - #16361
Conversation
#15166 split pty-connection.ts and dropped the "paint from main's model on SSH reconnect" half of the reattach gate that shipped in v1.4.188 (#14844), leaving only the park-reveal half. A non-park SSH reconnect has repainted from the ~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose start it no longer holds. Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel, the exited-transition veto computed before the probe, and the kitty scanReplay layered after the snapshot baseline. Adds a call-site test over createReattachPayloadHandlers, because the surviving pure-function test stayed green through the entire removal. Fixes STA-5395
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughDirect SSH reattach handling now tracks reconnect-specific model-paint eligibility. Reattach payload application checks replay transitions and snapshot width before using a main-process model snapshot. Park snapshots remain prioritized for terminal-park reveals. Structural payload application now uses Merge Risk: ⚪ Minimal · up to The change restores model-backed SSH reconnect rendering while preserving park and replay behavior, with targeted tests and validation passing; no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and directly explains the regression, restoration approach, tests, verification results, and linked issue. It does not reproduce every template heading or checklist item, but it provides the critical required information and is mostly complete. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5dcbed5d-be8f-4d2a-8d1f-43fd0910a322
📒 Files selected for processing (7)
src/renderer/src/components/terminal-pane/pty-connection-direct-ssh-reattach-retry.test.tssrc/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.tssrc/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-ssh-reconnect-model-paint.test.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Independent QA — SSH reconnect model-paint gateVerdict: LAND HEAD: Target shape: Throwaway Linux Docker User action: Add Project → Add remote host → Add SSH host ( Negative/safety path: New Terminal (Terminal 2) painted Visible result: After Retry, Terminal 1 restored the full alt-screen frame ( Restored post-reconnect (Terminal 1, model paint): Outage overlay before Retry: Negative path (Terminal 2, readable alt-screen exit during outage → relay/shell, not a restored TUI frame): Remote backing / process continuity: Bash PTY Logs inspected: Playwright console 0 errors. Renderer: Cleanup: Docker container Remaining gap: While the container was isolated, the auto-reconnect ladder ended at Connection lost before handshake instead of recovering on its own; the user-visible Retry after the network returned is what remounted the pane. That ladder behavior is outside this restore. The |
Final review status — LANDReviewed and validated at exact HEAD Review loops
Verification
Real SSH / Electron proofIndependent QA used a throwaway Linux Docker SSH target and real remote repo, built the relay from this head, launched an isolated Electron instance, verified its worktree identity over CDP, and drove the complete UI flow:
Screenshots, process continuity, logs, and cleanup evidence: #16361 (comment) Residual risk
Worktree and upstream are clean and synchronized at |
…15166 (stablyai#16361) * fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166 stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving only the park-reveal half. A non-park SSH reconnect has repainted from the ~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose start it no longer holds. Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel, the exited-transition veto computed before the probe, and the kitty scanReplay layered after the snapshot baseline. Adds a call-site test over createReattachPayloadHandlers, because the surviving pure-function test stayed green through the entire removal. Fixes STA-5395 * fix(ssh): restore empty-tail reconnect snapshots (cherry picked from commit 656e489)
…15166 (stablyai#16361) * fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166 stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving only the park-reveal half. A non-park SSH reconnect has repainted from the ~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose start it no longer holds. Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel, the exited-transition veto computed before the probe, and the kitty scanReplay layered after the snapshot baseline. Adds a call-site test over createReattachPayloadHandlers, because the surviving pure-function test stayed green through the entire removal. Fixes STA-5395 * fix(ssh): restore empty-tail reconnect snapshots
…15166 (stablyai#16361) * fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166 stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving only the park-reveal half. A non-park SSH reconnect has repainted from the ~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose start it no longer holds. Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel, the exited-transition veto computed before the probe, and the kitty scanReplay layered after the snapshot baseline. Adds a call-site test over createReattachPayloadHandlers, because the surviving pure-function test stayed green through the entire removal. Fixes STA-5395 * fix(ssh): restore empty-tail reconnect snapshots



What broke
#15166 split
pty-connection.tsinto modules and dropped the "paint from main's model on SSH reconnect" half of the reattach gate. Only the park-reveal half survived:So on a plain SSH reconnect — network drop, wake, reload — that is not a park-reveal,
modelSnapshotis unconditionallynulland the pane repaints from the relay replay tail alone. That tail is capped atREPLAY_BUFFER_MAX = 100*1024(src/relay/pty-handler.ts) and cannot rebuild a full-screen frame whose start it no longer holds.This regressed v1.4.188's #14844 (
feat(ssh): verify host keys, and restore panes correctly across a reconnect) — the exact fragmentation that PR fixed. Gate-identifier occurrences:v1.4.18826 →origin/main21.sshReconnectPaintsFromModelandlastAlternateScreenTransitionsurvived inssh-reattach-model-restore.tswith zero production callers.git log -Son both identifiers returns exactly two commits —24e662adc1(#14844, added) and7a72f341f7(#15166, removed the callers). Nothing since; there was no fix anywhere to cherry-pick.Live A/B evidence
Docker
node:20-bullseye+ sshd, real repo, relay built and deployed by Orca, SSH target connected from inside the app. In the SSH pane: enter alt screen, paint a full-screen frame once, then emit ~171 KB of cursor-addressed updates with no repaint — sized against the 100 KiB relay cap so the frame start is evicted. Then a real network drop (docker network disconnect), waitreconnecting→connected, read the xterm buffer.main(gate-less)bufType:"normal"— not even alt screen. Row 0 is literal garbage30;1Hupd-0003312(tail begins mid-escape and prints as text). Frame marker gone, both static rows gonebufType:"alternate", frame marker intact,STATIC-ROW-3,STATIC-ROW-45, full frame restoredDecisive detail: a pre-drop probe of
window.api.pty.getMainBufferSnapshotreturned{source:'headless', alternateScreen:true, holdsMarker:true}— main's model held the good payload at reconnect time and the code discarded it.What this restores
followsDirectSshReconnect— a PENDING-only read ofdirectSshPaneRetryByTabId[tabId]. Deliberately notdirectSshRetryAttempt, which also accepts the live binding and so stays truthy for every later remount of the generation.reconnectMayUseModel = followsDirectSshReconnect && !revealFollowsTerminalPark— keeps park and reconnect mutually exclusive.replayTransition === 'exited'veto, computed before the probe. Ordering is load-bearing: probing first spends the 750 msSSH_REATTACH_MODEL_SNAPSHOT_TIMEOUT_MSinside the structural-replay coordinator, with live PTY bytes deferred, only to discard the answer.ctx.fetchSshMainModelReattachSnapshot— the same memoized single-flight probe the park path uses, so no second timeout.sshReconnectPaintsFromModel({snapshot, hasReplay, replayTransition, altFrameWouldBeSkipped}).modelSnapshot = revealSnapshot ?? (paintsReconnectFromModel ? reconnectSnapshot : null)— park precedence preserved.kittyKeyboardModes.scanReplay(replay)placed afterapplySnapshotKittyKeyboardModes. Note this is not a bug on main today — the degraded relay path does its ownresetForSnapshot()+scanReplay(). But any fix that restores model painting must re-add the layered scan, or the fix itself introduces a stale-flag-stack bug: the snapshot sets the pre-outage baseline and the replay layers the outage's kitty pushes on top. Omitted, Option/Alt chords encode against stale flags; inverted, the baseline clobbers the outage pushes.The original
Why:comments from617f7c8de3are transplanted verbatim — including the second paragraph of the model-snapshot comment that #15166 deleted, which is the only signal a future reader has that the reconnect case exists at all.apply-reattach-payload.tslands at 356 lines, under the split's 400 budget. Nomax-linessuppression added.The test — and why the old one could not catch this
The only prior coverage was
ssh-reconnect-model-paint-gate.test.ts, which calls the pure function directly. It stayed green through the entire removal, validating a gate nothing consulted. The full suite was green on a tree carrying this bug.This PR adds
pty-connection/reattach-payload-ssh-reconnect-model-paint.test.ts, a call-site test overcreateReattachPayloadHandlers:scanReplayfires after the snapshot kitty baseline.\x1b[?1049l⇒ probe never issued (proves the veto precedes the fetch), relay bytes painted.RED — case (a) on unfixed
main4 production files reverted to
origin/main@2960fe9193, test files kept. Assertions areexpect.softso an unhooked gate reports every invariant it broke:The
Receivedvalue is the bug verbatim: the pane paints30;1Hupd-0003312, the same garbled mid-escape tail the live A/B captured in row 0.GREEN — with the fix
One existing test changed — please read this bit
pty-connection-direct-ssh-reattach-retry.test.tshad a case named "uses the SSH relay replay for a reconnect even when main has an alt-screen model".git log -Sshows it was added by #15166 itself (7a72f341f7), in the same PR that removed the gate — its commit log reads "Simplify reconnect model restoration by removing the conditional model snapshot probe and using relay replay directly." No pre-split counterpart existed. It pins the regressed behavior, so it blocks the restore.Its fixture is a reconnect whose replay is
'9l\r\n$ real-shell-output'— a tail whose\x1b[?1049llost its ESC to byte eviction.lastAlternateScreenTransitioncannot read a transition there (documented in its own comment: "A tail can begin mid-escape, so the first chunk is ordinary text and simply fails to match"), so under #14844's shipped contract the model wins.I rewrote it into two cases against a shared fixture rather than deleting it:
paints a reconnect from the alt-screen model when the replay shows no alt-screen exit— the original fixture, expectation flipped to v1.4.188's contract. This one is also RED on main (expected "vi.fn()" to be called at least once).uses the SSH relay replay for a reconnect once the replay shows the app left alt screen— same fixture with a readable\x1b[?1049l. Pins that the relay still wins and the probe is never issued.Net that file goes 7 → 8 tests, all passing.
Known limitation, pre-existing in v1.4.188, not addressed here: in that first fixture the shell really did leave alt screen, and painting the model discards
real-shell-output. The gate cannot see it because the ESC was evicted. Closing that hole means new heuristics #14844 never had, which is outside a restore — flagging it rather than smuggling it in.Verification
oxfmtclean;oxlintclean.check:code-quality:changed: 0 new findings (code quality, type-aware, React Doctor) across 7 changed files.check:max-lines-ratchet: OK, no new bypasses.src/renderer/src/components/terminal-pane/suite: 392 files / 3780 tests passed.Fixes STA-5395