Skip to content

fix(ssh): redeploy a managed server another desktop stopped; forget one whose host is gone (P1-D, P1-E) - #26628

Merged
OrcaWin merged 7 commits into
OrcaWin/phase37from
OrcaWin/p37-multi-desktop-stop-dead-host-removal
Oct 9, 2026
Merged

OrcaWin merged 7 commits into
OrcaWin/phase37from
OrcaWin/p37-multi-desktop-stop-dead-host-removal

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​793 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​788
Prod 43 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​595 $\color{#cf222e}{\Huge{\mathbf{−}}}$​106 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​489

ELI5

Two ways a managed SSH server could get stuck for good:

  • P1-D: Two desktops share one managed server on a host. Desktop B presses Stop. Desktop A stays "connected" to a server that no longer exists, and reconnecting doesn't help.
  • P1-E: The host itself is deleted. There's then no way to remove its managed server or the SSH host from Orca: Stop needs the host to answer, and every other remove path tells you to use Stop.

After this change, Desktop A's next connect puts the server back. A host that is gone can be "forgotten" on this desktop, which then lets you remove the SSH host.

What Changed

P1-D: a server another desktop stopped is redeployed on connect

  • Before:
    • Desktop B's Stop clears the host's shared record of which server version is active (~/.orca-remote/orcad-active.json).
    • On Desktop A's next connect, the "is the server running?" check found no active version and reported unverifiable: "This host has no activated managed server to start."
    • The connect then returned right away and never reached the update step. Terminals failed with "Could not connect to the remote Orca runtime".
  • After: when the host reports that specific state, the connect goes on to the normal managed-server update. That update already handles "no active version":
    • The update planner treats a null active as "needs update".
    • The terminal count is zero by definition, since there is no server.
    • It installs and activates this desktop's build, refreshes the pairing, and the desktop keeps its existing server entry, so its workspaces stay as they were.
  • If the update can't run (it fails, or another desktop holds the host), the connect still reports the "not activated" note along with the update's note. Nothing pretends to be serving.
  • The fence recheck loop goes through the same gate.
  • Never older than the stopped build. Stop now keeps the stopped build's Orca version in the record as activeAppVersion (and any rolledBackFrom), even though nothing is active. That field is the one already-released desktops check: their planner skips a host whose activeAppVersion is newer than theirs, so an older desktop in the field also won't downgrade the host. On a stopped host the new planner:
    • restarts the exact build that was stopped, which is always safe;
    • otherwise skips as host-newer when the stopped build came from a newer Orca, so an older desktop never starts an older server on state a newer build may have migrated;
    • skips (stopped-version-unknown) when the stop was written by a build that did not record the version, rather than guessing. That host keeps the pre-PR "not activated" note.
  • A failed redeploy is retried. The once-per-app-version "an update failed here before" suppression does not apply when nothing is active, so a transient upload failure does not strand the desktop. A host that still serves keeps the suppression.
  • The version check is repeated under the host lock. Another desktop can activate or stop a newer build while this one uploads. The auto-update now re-applies its version and rollback policy to the record it reads after taking the host lock, and refuses without touching anything if that record no longer allows this build. The terminal count it was given is tied to the record it was counted against. If a different server is active by the time the lock is held, the count is treated as unknown, so the update waits for a later connect instead of restarting a server whose terminals were never counted.
  • Mid-session stops recover without a reconnect. When a runtime call (e.g. terminal create) finds the server "not activated", it awaits the same redeploy before the call, not limited by the once-per-session restore check. Concurrent calls share one attempt. The SSH port forward is then rebuilt, because the redeployed server may bind a different port.
  • Mechanism:
    • orcad-managed-serving.ts now exports that detail as MANAGED_ORCAD_NOT_ACTIVATED_DETAIL.
    • A new managed-server-serving-gate.ts decides whether a serving result ends the connect or lets the update run. Both ssh-host-server-on-connect.ts and managed-server-fence-recheck.ts use it.
    • The Stop journal's recordAfter stays exactly what released desktops compute (withDeactivatedVersion, no optional fields), so an older desktop can still read and recover an interrupted Stop. Only the record written when the Stop commits adds the version fields (withDeactivatedVersionCommitted); recovery rebuilds them from recordBefore.
    • planManagedOrcadAutoUpdate has a stopped-host branch. deployOrcad takes an admitRecord callback and a censusRecord, both checked in activateInstalledOrcad against the record read under the lock.
    • resolveManagedRuntimeEnvironment calls redeployStoppedManagedOrcad (orcad-managed-update-on-restore.ts) on the not-activated verdict, then rebuilds the tunnel.

P1-E: Forget a managed server whose host is gone

  • Before:

    • orca environment stop → connect ECONNREFUSED.
    • ssh:removeTarget → "Use Stop… first".
    • orca environment rm → "pairing cannot be replaced or removed here".
  • After: a new, explicitly confirmed Forget runs only the local half of Stop:

    • remove the server entry
    • retire its client state
    • close the tunnel
    • release the SSH host's claim
    • clear the update deferral and migration journals

    It never contacts the host, and it never says the server exited. Its verdict is unverifiable, per the SSH execution-boundary rules. Afterwards the SSH host is a plain target and can be removed. If the host comes back, a connect relinks it.

  • Where it is available:

    • Settings › Managed servers row: a "Forget…" button, shown only when the server's status could not be loaded, with a second confirmation and an explanation.
    • CLI: orca environment forget --environment <name> --yes.
    • Runtime RPC: a new managedServer.forget method (host-admin), plus the IPC channel runtimeEnvironments:forgetOrcad.
  • The guard messages for Remove host and environment rm now point to Forget.

  • Mechanism: forgetManagedOrcadEnvironment in orcad-runtime-decommission.ts reuses Stop's local unlink, renamed unlinkEnvironmentLocally. It refuses the active server, just as Stop does.

Why

  • P1-D:
    • The connect path already has a safe redeploy: the auto-update, which is census-gated and journaled. The bug was only that the "not activated" verdict ended the connect before that step ran.
    • Unlinking A's server instead would drop its workspace session and create a new server identity.
    • Blocking Stop while other desktops are paired would need a cross-desktop pairing census, which the host doesn't track.
  • P1-E:
    • Proof of exit from a deleted host is impossible, so the only honest option is an explicit, confirmed "unlink here without a verdict".
    • It is a new RPC method rather than a forget flag on stop, for mixed-version safety. An older desktop would silently drop the unknown flag and run a real decommission against a reachable host. With a new method, it answers method_not_found, which the CLI already reports as "update Orca there".
    • Forget is not limited to unreachable hosts at the API level, because "unreachable now" can't be proven either. The Settings UI offers it only when status failed to load, and both surfaces spell out that the server may still be running.

Linked Issue

Phase 3.7 adversarial-testing findings P1-D and P1-E, workstream w37-04. No GitHub issue matches.

Visual Proof

The UI change is a "Forget…" / "Forget on this desktop" / "Keep linked" button set on a Managed servers row whose status failed to load. It is covered by ManagedServerRow.test.tsx; no screenshot was captured. The behavior proof is the real-host runs below.

Testing

Real-host runs. Both arms used Docker SSH hosts (p3-debian:arm64), isolated profiles and HOME, ORCA_BACKGROUND_LAUNCH=1, --use-mock-keychain, and token/API-key env unset. Windows were never shown.

  • The base arm used the packaged build of ef00191c7c. None of the files this PR touches changed between that commit and OrcaWin/phase37.
  • The fix arm used a packaged arm64 build of this branch.
Step Base This PR
Two desktops connect managed to one host managed / managed managed / managed
Desktop 2: orca environment stop --yes host active: null, no orcad same
Desktop 1: disconnect + connect managed, serving: unverifiable "This host has no activated managed server to start."; host still active: null managed with no note, in 18 s; host active: 0.1.0+64b806382b9e, orcad running
Desktop 1: use the server terminal list → "Could not connect to the remote Orca runtime." environment status answers (live terminals 0); repo add + terminal create succeed
docker rm -f host, then environment stop --yes connect ECONNREFUSED connect ECONNREFUSED (unchanged)
ssh:removeTarget refused, "Use Stop… first" refused, message now points to Forget
environment forget without --yes Unknown command asks for --yes
environment forget --yes n/a "Unlinked … Its host was not contacted, so orcad may still be running there."
ssh:removeTarget again n/a removed; environment list empty

Automated tests. These fail on the base source and pass here (7 cases, plus 8 for the first review follow-up: mixed-version stop, legacy stop record, retry after failure, rollback hold after stop, journal from a peer without version fields, mid-session redeploy and its de-duplication, and the runtime-call wiring; plus the second follow-up: a new Stop journal checked by a frozen copy of the released journal check, the released planner on a new stopped record, a newer peer activating or stopping before and during the upload, a different server becoming active mid-upload, and the port-forward rebuild):

  • ssh-host-server-on-connect-stopped-elsewhere.test.ts covers:
    • redeploy on connect
    • keeping the note when the update did not run
    • the fence recheck
    • the plan for a stopped record
  • orcad-runtime-forget.test.ts checks that Forget unlinks without connecting, frees the SSH target, and refuses the active server.
  • The CLI, RPC and ManagedServerRow tests cover forget.

Checks run:

  • pnpm test on src/main/ssh, src/main/ipc, src/main/runtime, src/cli, src/shared and settings:

    • Everything passes except remote-runtime-shared-control-connection.test.ts, which fails identically on the base source.
    • A few timing tests that failed once under machine load passed on rerun.
  • pnpm tc, oxlint and pnpm run check:code-quality:changed are clean.

  • The RPC catalog and localization verifiers pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: Forget never reports exited. The redeploy goes through the existing census-gated, journaled update, so live or unverifiable terminals still defer it.
  • Mixed versions: managedServer.forget is a new method, so older hosts answer method_not_found. There is no new stream opcode and no change to what the host publishes.
  • Folder workspaces: not affected. The redeploy keeps the existing server entry.
  • Cross-platform: no platform-specific code.
  • Activation record: the committed stopped record now carries activeAppVersion/rolledBackFrom with active: null. Released planners honour activeAppVersion and released recovery compares only core fields, so both stay correct. The Stop journal is unchanged in shape. A stop written by an older peer omits the version and is treated as "version unknown" (no automatic redeploy).

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@OrcaWin
OrcaWin requested a review from brennanb2025 as a code owner October 8, 2026 17:02
@OrcaWin
OrcaWin force-pushed the OrcaWin/p37-multi-desktop-stop-dead-host-removal branch from f753930 to fa6d6f8 Compare October 9, 2026 04:44
m4air added 7 commits October 8, 2026 22:18
…ed host be forgotten

P1-D: a connect whose linked server the host reports as not activated (another desktop
stopped it) now goes on to the update check, which redeploys it in place.
P1-E: add Forget (managedServer.forget, orca environment forget, Settings row) that runs
Stop's local unlink without contacting the host; the verdict stays unverifiable.
… retry after a failure

A stop now keeps the stopped build's Orca version, so an older desktop's
reconnect skips as host-newer instead of starting an older server on a
store a newer build migrated. A stop recorded without that version is not
guessed at. A stopped host retries the redeploy on each connect instead of
the once-per-version failure suppression, and a runtime call that finds
the server stopped mid-session redeploys it before the call.
A redeploy can bind a different port than the reused forward targets.
…ersion policy under the fence

- The stop journal's recordAfter is the core deactivated record older peers compute; the
  committed record keeps activeAppVersion (which released planners already honour) and
  rolledBackFrom, rebuilt from recordBefore on recovery.
- Auto-update re-applies its version policy to the record read under the host fence, and a
  census counted against another incumbent is treated as unverifiable.
…t, so their recovery never drops the version guard
… desktop stopped

The unlinked deploy path never consulted the stopped record's activeAppVersion, so a desktop
without a link to the host could activate its older build over state a newer build migrated.
Both the auto-update planner and the fresh deploy now apply one downgrade rule under the fence.
@OrcaWin
OrcaWin force-pushed the OrcaWin/p37-multi-desktop-stop-dead-host-removal branch from fa6d6f8 to 411d20b Compare October 9, 2026 05:20
@OrcaWin
OrcaWin merged commit c4bdafe into OrcaWin/phase37 Oct 9, 2026
71 checks passed
OrcaWin added a commit that referenced this pull request Oct 9, 2026
…ting (#26847)

* fix(remote-terminal): keep a reconnected pane's size after an SSH outage (P1-4) (#26625)

* fix(remote-terminal): keep a reconnected pane's grid when its stale stream is reaped (P1-4)

The host's width floor only handed ownership to viewers that had claimed
since subscribing. A reconnecting desktop pane re-subscribes without
claiming, so when the heartbeat later reaped the dead socket that owned the
floor, the host reclaimed the PTY to its spawn size (120x40) and held the
pane there. The owner's same-client replacement stream now inherits the
floor, and a pane whose stream was reaped before it reconnected resumes
ownership on re-register unless the host or another viewer claimed since.

* fix(remote-terminal): host typing during an outage revokes the reaped owner's resume

Host input reaches the PTY without a renderer viewport claim once the host has
reclaimed its grid, so the orphaned-owner entitlement survived and a passive
reconnect resized the host pane back to the remote grid. The host write path
now clears that entitlement on driving input (query replies, focus reports and
launch writes excluded).

* test(pty): stub the runtime's host-input note in write-path handler tests

---------

Co-authored-by: m4air <[email protected]>

* fix(remote): an oversized RPC reply fails that request instead of closing the host connection (#26624)

Expanding a folder with ~80k entries on a managed SSH host produced a
files.readDir reply over the 4 MiB encrypted-reply cap. The channel treated
that as a transport fault and closed the whole control socket (1013), and the
explorer rendered the failed folder as empty.

- The WebSocket RPC transport now answers an over-cap reply with a
  reply_too_large error for that request id, so the channel never sees it.
- files.readDir checks remote listings against the request's content budget
  and names the entry count.
- The explorer shows a subfolder's read error on its expanded row.

Finding: HH-2 (Phase 3.7 hostile-host).

Co-authored-by: m4air <[email protected]>

* fix(ssh): let a slow host finish installing the pinned Node runtime (HH-3) (#26631)

* fix(ssh): let a slow host finish installing the pinned Node runtime

The POSIX promote (extract, hash, self-test and publish the ~110 MiB node
binary) ran under the 30 s default exec timeout. On slow home storage it
timed out, the remote work kept running, and the runtime store lock it held
stayed until the 20-minute stale rule, so relay rung A queued behind it past
its own deploy bound.

Give both platforms the 300 s promote bound and have the host release the
store lock itself when the promote exits, with owner-checked releases so a
late release never removes a lock someone else took. (HH-3)

* fix(ssh): let the host release the store lock after a slow under-lock re-hash

The under-lock re-check of a sibling-published runtime hashed the ~110 MiB
executable as its own command under the 30 s exec default and outside the
host-side lock release. On slow storage it timed out, the client correctly
kept the lock, and nothing on the host freed it until the 20-minute stale
rule, so later installers ran out their deploy bound.

Run the re-hash and the conditional promote as one host command wrapped in
the host release, and give every full-runtime hash, including the initial
probe, the slow-storage bound. (HH-3)

* test(ssh): count the combined under-lock re-probe and promote as one host command

---------

Co-authored-by: m4air <[email protected]>

* fix(ssh): shell startup output on stdout no longer breaks SSH connect (HH-1) (#26617)

* fix(ssh): fence captured exec stdout so shell rc output cannot break connect

sshd runs the user's login shell before Orca's /bin/sh wrapper, so any
startup-file stdout (fish/tcsh/zsh/bash echo, or a bare terminal-title escape)
was glued onto every captured answer. The home probe read "banner\n/home/u"
and connect failed with "Remote home is not a valid path".

execCommand now wraps wrapped POSIX commands in a per-call nonce fence and
returns only the payload between the markers; the SSH folder browser gets the
same fence. The fence is the existing WSL captured-login-shell fence, moved to
src/shared/posix-stdout-fence.ts so both transports share it.

Finding: HH-1 (phase 3.7 hostile-host). Refs #8324.

* fix(ssh): fence the login-shell Node probe and fall back from a noisy SFTP handshake

The login-shell 'command -v node' probe ran unwrapped, so output from sshd's
shell and the nested login profile became the Node path. It now prints a
one-line fence every login shell parses, inside that shell.

An external sftp-server is started through the user's shell, so startup output
corrupts the SFTP handshake. ssh2 reports that parse failure only before the
session is ready, so SshConnection.sftp tags it, and relay install transfers
treat it as SFTP unavailable and stream over exec stdin.

Finding: HH-1 follow-up (phase 3.7 hostile-host). Refs #8324.

* fix(ssh): keep the stdout fence marker out of the command text

The runtime-store inventory lists processes with ps, which prints its own
script, so a literal marker in the script was read as the fence and the
store GC skipped every pass. printf now joins the marker from two halves.

---------

Co-authored-by: m4air <[email protected]>

* fix(orcad): finish an abandoned update on connect, and refresh renderers after a main-side re-pair (P1-A, P1-C) (#26635)

* fix(orcad): finish an update or rollback its client abandoned, and tell renderers about main-side re-pairs

P1-A: a wake that finds the activation fence now runs crash recovery, which takes
only a stale, previous-boot or exited-own fence. Recovery of an activation
interrupted after the candidate launched resumes it: the candidate commits if it
passes the readiness gate, else the activation is undone as before.

P1-C: invalidating a still-linked environment's transport restarts its status
owner, and a renderer that sees status under a newer pairing revision re-reads
the catalog before applying it.

* fix(orcad): a resumed update keeps the app version that started it

Recovery that commits an abandoned candidate stamped no activeAppVersion, so an
older desktop read the host as pre-tracking and downgraded it over state the
newer build had migrated. The activate journal now records the initiating app
version; recovery stamps it, and a journal too old to carry it is undone instead
of committed.

* test(runtime-env): answer nothing for the status restart a re-pair now triggers

* fix(orcad): recovery leaves running an update server a too-old journal cannot commit

A journal without candidateAppVersion was sent to undo, which stopped a
healthy candidate that had already migrated state and then refused to
restart the incumbent, leaving the host serving nothing. Refuse instead,
keeping the fence and the candidate, until the operator accepts Restore.

---------

Co-authored-by: m4air <[email protected]>

* fix(terminal): a remote recovery never splices stale history above the new screen (P2-5, P2-7) (#26647)

* fix(terminal): a remote recovery never splices stale history above the new screen

A pushed remote snapshot (overflow recovery, seq-gap resync, first attach) is
sent because the client's stream broke, so the pane's own history ends before
that image. Since #26319 a screen-only image kept that history, splicing a
stale block directly above the final screen with a silent gap of up to ~270k
lines (P2-5), and a first attach to an older host left silent holes (P2-7).

- Host: the ACK-overflow recovery serializes up to 1000 history rows.
- Client: the seq-gap resync asks for the same 1000 rows.
- Client: a pushed snapshot always replaces the pane's scrollback; the
  keep-local-scrollback path is removed. A screen-only image from an older host
  now shows only its screen, which is lossy but never misleading.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(terminal): a pushed image replaces the normal buffer over a live alt screen too

Over a pane already on the alternate screen, an image that also ended on alt
repainted only its alt frame and kept the pane's normal buffer, inferring the two
had frozen together. Inside the gap the TUI can exit, the shell print and a second
TUI start, so once that TUI exited the pane showed its stale history where the host
had the missed output. A pushed image now always rebuilds the normal buffer and
history from the host before entering alt itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(terminal): bound recovery history by link slack and keep pre-TUI scrollback under screen-only images

A recovery that carries history now goes out only when the stream's ACK
window has drained; under a sustained flood recoveries stay screen-only and
the owed history follows once the client catches up, so snapshot bytes no
longer outgrow the client's intake.

A pushed image without history (scrollbackRows absent or 0) over a live alt
screen repaints only the alt frame again, so a reconnect to an older host
no longer wipes the pane's pre-TUI scrollback.

---------

Co-authored-by: m4air <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>

* fix(source-control): Stage All stages every change when the listing hit the 1,000 cap (HH-4) (#26618)

* fix(source-control): Stage All stages every change when the listing hit the 1,000 cap

The status listing stops at 1,000 rows, but Stage All built its path list
from those rows, so it staged 1,000 of 20,000 changes and the next commit
was silently partial. When the listing is capped, Stage All (and the
Changes header Stage all) now asks the host to stage the whole worktree
via an optional scope on git.bulkStage; unresolved conflicts stay
unstaged. Older hosts ignore the field and stage the listed paths.

Fixes HH-4.

* fix(source-control): whole-worktree Stage All needs a host receipt, skips shared links, and reaches mobile

- Scoped stage sends no paths and requires a stagedScope receipt, so an older
  runtime or relay stages nothing and the client reports it instead of a
  silent partial stage.
- Scoped 'all' skips Orca's shared symlinks (configured and really a link),
  matching the status listing.
- The capped-listing banner offers Stage All, reachable when the visible
  prefix is entirely staged.
- Mobile reads didHitLimit and uses the same scoped stage and receipt.

* test(source-control): type the Stage All test stubs so lint and the mobile test typecheck pass

* fix(source-control): match Shared Paths saved as ./name or name/ against git's spelling

The Shared Paths setting keeps entries as typed, but git prints worktree paths
without a leading ./ or trailing /. Stage All's conflict path compared the raw
spelling to git's untracked list and staged the shared node_modules link, and
an exclude pathspec ending in / made git refuse the add after tracked changes
were already staged. Status listing had the same mismatch. getSafeRelativePath
now returns git's spelling, so every caller gets it, including saved settings.

---------

Co-authored-by: m4air <[email protected]>

* fix(ssh): redeploy a managed server another desktop stopped; forget one whose host is gone (P1-D, P1-E) (#26628)

* fix(ssh): redeploy a server another desktop stopped; let a dead managed host be forgotten

P1-D: a connect whose linked server the host reports as not activated (another desktop
stopped it) now goes on to the update check, which redeploys it in place.
P1-E: add Forget (managedServer.forget, orca environment forget, Settings row) that runs
Stop's local unlink without contacting the host; the verdict stays unverifiable.

* test(ssh): type the forget test's hoisted store without an assertion

* fix(ssh): never downgrade a stopped host; redeploy it mid-session and retry after a failure

A stop now keeps the stopped build's Orca version, so an older desktop's
reconnect skips as host-newer instead of starting an older server on a
store a newer build migrated. A stop recorded without that version is not
guessed at. A stopped host retries the redeploy on each connect instead of
the once-per-version failure suppression, and a runtime call that finds
the server stopped mid-session redeploys it before the call.

* fix(ssh): rebuild the managed forward after redeploying a stopped host

A redeploy can bind a different port than the reused forward targets.

* fix(ssh): keep stop journals readable by older desktops and recheck version policy under the fence

- The stop journal's recordAfter is the core deactivated record older peers compute; the
  committed record keeps activeAppVersion (which released planners already honour) and
  rolledBackFrom, rebuilt from recordBefore on recovery.
- Auto-update re-applies its version policy to the record read under the host fence, and a
  census counted against another incumbent is treated as unverifiable.

* fix(ssh): file a dispatched stop where older desktops cannot commit it, so their recovery never drops the version guard

* fix(ssh): refuse a fresh deploy of an older orcad onto a host a newer desktop stopped

The unlinked deploy path never consulted the stopped record's activeAppVersion, so a desktop
without a link to the host could activate its older build over state a newer build migrated.
Both the auto-update planner and the fresh deploy now apply one downgrade rule under the fence.

---------

Co-authored-by: m4air <[email protected]>

* fix(ssh): redeploy a managed server a pre-version Stop left; let a forced deploy run over a newer one (#26766)

A stopped activation record without activeAppVersion is what every Stop on
main writes, so refusing it stranded those hosts behind an unforceable
policy refusal. Only a provably newer host is now refused; a forced fresh
deploy runs this version anyway, and the refusal names both versions.

Co-authored-by: m4air <[email protected]>

* fix(remote-terminal): no keystroke lost, duplicated or split across a silent outage (P1-1, P1-2, P1-3) (#26630)

* fix(remote-terminal): no keystroke lost, duplicated or split across a silent outage

Remote pane input was fire-and-forget: keys handed to a socket that had
silently died were gone, keys still in the 8 ms debounce at detection were
cleared, and held keys were discarded when the auto-recovery window ran out.

- New negotiated `inputAck` capability: the client names an input session
  and sequences Input frames (existing frame header `seq`); the host records
  the last applied sequence per (PTY, session) across connections, writes
  each sequence once and acks it with new opcode InputAck (18), sent only
  to clients that advertised the capability.
- The pane keeps sent-but-unacked input and replays it to the same
  terminal on reattach; the host dedupes. Old hosts keep current behavior.
- Debounced and claim-queued input at detection is held, not cleared.
- Held input survives the 'disconnected' phase; the hold coalesces keys so
  minutes of typing do not hit the per-entry cap.
- Banner copy no longer claims a one-minute retry window.

Fixes P1-1, P1-2, P1-3 (phase 3.7 network findings).

* fix(remote-terminal): never replay into a restarted runtime; keep Ctrl+C and validating paste in order

- Host publishes inputLedgerId with inputAck; the client drops unacknowledged input sent to a
  different ledger (runtime restart with the same PTY) instead of running it twice.
- A replayed duplicate is acked only after the original write settles.
- Accepted input (Ctrl+C, Escape, paste) rides the sequenced stream and resolves on the host ack.
- Keys typed while held queue behind a paste still in size validation.

* fix(remote-terminal): parse subscribed capabilities into a typed shape instead of Reflect.get

* fix(remote-terminal): ack only applied input; withdraw writes their caller gave up on

- Host ledger records each write's outcome: a refused write is rolled back and
  never acked, so the client's replay writes it; nothing queued behind it runs or
  is acked. A write that threw is acked as delivery-unknown, so the client
  reports it failed and never replays it.
- Paste and file-drop timeouts abort their accepted write: a copy still held for
  an outage is withdrawn, and a journaled copy is left out of the replay.
- A batch of sequenced input keeps one endpoint and ledger, so a send that
  retires the stream mid-batch no longer discards earlier unacked input.

* fix(remote-terminal): host writes sequenced input strictly in order and asks the live stream to resend after a refusal

- The ledger admits only the next sequence; a refusal or gap answers with an InputAck resend request instead of WriteUnavailable, so the pane keeps its journal and resends on the same stream (no remount, no carrier bookkeeping).
- Sequenced input uses the provider's settled write; an unverifiable handoff is delivery-unknown, not refused.
- Replays fill given-up slots with empty input so the host can continue; the client remounts only after every resend backoff is refused.
- Typing batched ahead of a paste goes out as its own sequences, so cancelling the paste keeps it.

* refactor(remote-terminal): deliver sequenced input with standard go-back-N

Replace the hand-built "block on refusal" bookkeeping with go-back-N:

- Host: per (PTY, input session) the ledger keeps only appliedSeq, the
  highest contiguous confirmed write. Frames run one at a time in arrival
  order: a duplicate is re-acked, the next sequence is written and acked
  on confirmed success, and a refusal or gap is answered with a resend
  request carrying appliedSeq. No blocked state; every stream is equal.
  A settlement that proves no byte left is a refusal; one that may have
  written advances as delivery-unknown and is never retried.
- Client: one journal keeps unacked input in order and resends from
  appliedSeq + 1 on a resend request (with backoff), on a new stream, or
  when acks stall. Refusals never remount the pane. Withdrawn pastes,
  stale query replies and over-budget bytes resend as empty slots.
- The recovery hold pauses (keeps the rest) when a release is cut short
  by another outage, and keeps delivering typing after an accepted write
  a sequenced stream withdrew or could not confirm.
- Add a seeded model-based test that drives the real pane transport,
  multiplexer and journal against the real host dispatcher and ledger
  through 2,000 random fault schedules.

* test(remote-terminal): cover the refusal remount on a stream without sequenced input

A sequenced stream now resends refused input on the same stream instead of remounting, so the end-to-end remount check negotiates no inputAck, as an older peer does.

* fix(remote-terminal): escalate persistent input refusals, drop input once recovery gives up, and never report a lost unknown ack as applied

- The pane falls back to its remount path when the host keeps refusing input past the resend backoff ladder.
- Held and journaled input is discarded when auto-recovery gives up, and input typed under the disconnected banner is not held.
- The host ledger answers a duplicate for its own sequence and remembers delivery-unknown outcomes; the client settles a write as applied only from its own ack.
- The input model now requires a write reported applied to have reached the PTY whole, and covers a refusal that never clears.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: m4air <[email protected]>
Co-authored-by: m4air <[email protected]>
Co-authored-by: Claude <[email protected]>

* fix(remote-terminal): keep input typed past the auto-recovery window for the same terminal, within a bounded grace (P1-3) (#26832)

The last round of #26630 discarded held and journaled input as soon as auto-recovery gave up,
and refused input under the disconnected banner. On a real host a 200 s outage lost 102 of
120 keystrokes, although the pane reattached the same terminal on its own seconds later.

Input now stays held for the same handle and incarnation while the pane is disconnected, for
up to 5 minutes after it gave up. Past that grace it is discarded, and typing into the dead
pane is refused, so stale keys never run at an arbitrary later reconnect. The grace is a
timestamp checked when input moves, so a latched pane stays free of timers.

Co-authored-by: m4air <[email protected]>
Co-authored-by: Claude <[email protected]>

---------

Co-authored-by: m4air <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: m4air <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant