fix(remote-runtime): make hidden-output recovery reason-driven instead of timer-guessed (#12655)

When a remote terminal tab is hidden, the host stops sending its output and discards what it queued, so on reveal the only way to recover the missed output is to ask the host to serialize its buffer. That reply was ambiguous — one empty answer covered several unrelated situations — so the client inferred "output is lost" from elapsed time, using budgets sized for local IPC. Over a network that guess was routinely wrong: users saw "[Orca skipped hidden terminal output because main recovery was unavailable.]" on a healthy pane and got a permanent scrollback gap, worst exactly when an agent was streaming heavily and there was the most to lose.

The key insight is that there is no provable-absence case at all. A pane with genuinely no retained output returns a SUCCESSFUL snapshot with empty data, because the host serialized fine and found nothing. The real defect was the host sending an untagged empty reply when no serializer answered — reporting an unprovable failure as proven emptiness.

The host now states why a snapshot is unavailable and the client acts on that reason: an empty snapshot is success; retry-worthy retries and then gives up honestly; permanently-unavailable banners immediately with no waiting; and a host too old to say latches that pane to the pre-existing timer heuristic. Local panes are unchanged. The self-heal repaint no longer yanks the viewport of a user scrolled back reading — it waits for the terminal to return to following output.

Retries are bounded by COUNTING REPORTED OUTCOMES, never elapsed time. Independent review found that the single budget also charged attempts for causes returned locally, where the host was never asked — meaning a re-arming resync could exhaust it and banner on a perfectly healthy host, a residual instance of this very bug. Host answers and local gates now have separate budgets; local gates send zero frames, so retrying them cannot pressure the host.

Review also found a duplicate-banner path where a repaint timer armed before a permanent answer survived the abandon; the clear is scoped to the branch that banners, since the retry loop deliberately arms that timer.

Wire change is additive: an optional field on an existing frame, dropped on the success path, so old clients see an unchanged frame. STA-3476 tracks replacing the legacy-host detection (currently inferred from an absent field) with a positive capability signal. Closes STA-3457.
This commit is contained in:
Jinwoo Hong
2026-08-05 00:51:39 -07:00
committed by GitHub
parent aca5e8b5b1
commit 4e370062a8
14 changed files with 2719 additions and 40 deletions
@@ -0,0 +1,24 @@
/**
* Why a host answered a requested terminal-buffer snapshot without a usable buffer image.
*
* Sent as the additive `unavailable` field on the SnapshotStart frame. Hosts that predate
* this field omit it, so an absent value means "the host did not say" — never "nothing exists".
* Both current reasons are transient: the host could not answer *now*, not that the pane has
* no retained output. A pane that genuinely has nothing still comes back as a real snapshot
* whose `data` is empty, because the host successfully serialized and found it empty.
*/
export const TERMINAL_SNAPSHOT_UNAVAILABLE_REASONS = [
// The pending-output buffer overflowed twice while serializing, so the reply was truncated to nothing.
'pending-output-overflowed',
// No serializer (provider, renderer, headless) produced a buffer for this pty at request time.
'no-serializable-buffer'
] as const
export type TerminalSnapshotUnavailableReason =
(typeof TERMINAL_SNAPSHOT_UNAVAILABLE_REASONS)[number]
export function parseTerminalSnapshotUnavailableReason(
value: unknown
): TerminalSnapshotUnavailableReason | undefined {
return TERMINAL_SNAPSHOT_UNAVAILABLE_REASONS.find((reason) => reason === value)
}