Skip to content

Restore hidden remote terminal TUIs without typing regressions - #4759

Merged
nwparker merged 1 commit into
mainfrom
nwparker/terminal-hidden-output-restore-perf
Jun 7, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/terminal-hidden-output-restore-perf

Conversation

@nwparker

@nwparker nwparker commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR keeps hidden terminal output off the interactive renderer path while making the restore path robust for remote/runtime terminals.

The previous merged perf work made local hidden panes cheap by skipping renderer writes while the pane is hidden and restoring from the main terminal buffer when the pane becomes visible again. This follow-up closes the corresponding remote/runtime gap: hidden remote terminal streams now request a headless/runtime snapshot and then replay only live output that is newer than that snapshot. That avoids stale hidden output corrupting a full-screen TUI when a workspace is foregrounded again.

It also keeps the foreground scheduler on the proven low-latency path. A broader experiment that added per-write xterm parse callback backpressure measured worse for same-workspace pane storms, so this PR does not include that behavior. Background drains continue to be chunked by the shared scheduler without waiting on parse callbacks.

What Changed

  • Added explicit terminal snapshot request/response support for runtime terminal streams.
  • Added sequence-aware replay so live bytes that arrive while a hidden restore snapshot is in flight are not lost or rendered out of order.
  • Let remote runtime PTY transports serialize their headless buffer for hidden-pane restore.
  • Added visual E2E coverage for hidden full-screen TUI restore and the snapshot/live-output race.
  • Kept latency-sensitive foreground restore coalescing at one frame instead of widening the input path.

Benchmarks

Command:

ORCA_E2E_OPENCODE_SAME_WORKSPACE_PANES=100 \
ORCA_E2E_OPENCODE_CROSS_WORKSPACE_PANES=25 \
ORCA_E2E_OPENCODE_FRAME_COUNT=1000 \
ORCA_E2E_OPENCODE_FRAME_INTERVAL_MS=6 \
npx playwright test tests/e2e/artificial-opencode-terminal-load.spec.ts \
  --config tests/playwright.config.ts \
  --project electron-headless \
  --reporter=json \
  --output=/tmp/orca-pr-bench-output > /tmp/orca-pr-bench.json

Results from this PR branch:

Scenario Panes Median typing latency Worst typing latency Timer drift Notes
Baseline active terminal 1 3.4ms 5.4ms 1.8ms no hidden skips
Same workspace pane storm 100 3.6ms 26.8ms 52.0ms 1584 deferred foreground enqueues, 272 deferred writes
Cross-workspace hidden TUI stream 26 3.4ms 5.4ms 3.3ms 526 hidden skips, 190,940 skipped hidden chars

Comparison against earlier measured points:

Build Same workspace, 100 panes Cross workspace, 26 panes
Merged terminal responsiveness PR 3.4 / 13.5ms 3.3 / 8.0ms
Broader experimental branch before trimming 5.9 / 32.1ms 3.0 / 6.5ms
This PR branch 3.6 / 26.8ms 3.4 / 5.4ms
This PR branch earlier repeat 3.6 / 9.3ms 3.3 / 5.0ms

Takeaway: this preserves the low median typing latency from the merged perf work, improves the cross-workspace worst case in the measured run, and avoids carrying the experimental scheduler backpressure path that made same-workspace storms noisier.

Verification

npx vitest run --config config/vitest.config.ts \
  src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.test.ts \
  src/renderer/src/components/terminal-pane/pty-connection.test.ts \
  src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts \
  src/main/runtime/rpc/terminal-multiplex.test.ts \
  src/shared/terminal-stream-protocol.test.ts

Passed: 5 files, 195 tests.

npx tsgo --noEmit -p config/tsconfig.tc.web.json

Passed.

SKIP_BUILD=1 npx playwright test tests/e2e/terminal-hidden-tui-visual-restore.spec.ts \
  --config tests/playwright.config.ts \
  --project electron-headless \
  --reporter=list \
  --output=/tmp/orca-pr-hidden-visual-output

Passed: 2 visual restore tests.

ORCA_E2E_OPENCODE_SAME_WORKSPACE_PANES=100 \
ORCA_E2E_OPENCODE_CROSS_WORKSPACE_PANES=25 \
ORCA_E2E_OPENCODE_FRAME_COUNT=1000 \
ORCA_E2E_OPENCODE_FRAME_INTERVAL_MS=6 \
npx playwright test tests/e2e/artificial-opencode-terminal-load.spec.ts \
  --config tests/playwright.config.ts \
  --project electron-headless \
  --reporter=json \
  --output=/tmp/orca-pr-bench-output > /tmp/orca-pr-bench.json

Passed with the benchmark numbers above.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — threads snapshot source and sequence metadata through the PTY data pipeline and adds on-demand snapshot requests so hidden remote terminal TUIs restore correctly without typing regressions.

  • Add SnapshotRequest terminal stream opcode — enables renderer-to-runtime snapshot requests for remote terminals, with server-side handler sendRequestedSnapshot in the RPC methods.
  • Thread source, seq, and rawLength metadata from OrcaRuntimeService through subscribeToTerminalData, TerminalOutputBatcher, appendPendingMultiplexOutput, and into transport callbacks — enables sequence-aware replay that prevents live output from being lost or rendered out of order during hidden restore.
  • Add serializeBuffer to PtyTransport and canUseHiddenOutputSnapshot / serializeHiddenOutputSnapshot in pty-connection.ts — unifies local main buffer and remote transport snapshot paths under a single check function.
  • Implement snapshot request lifecycle in remote-runtime-terminal-multiplexer.ts — 10s timeout with timer.unref(), pending-request deduplication, proper cleanup on stream close/error/end, and routing between initial-subscribe and on-demand snapshot responses via snapshotTarget.
  • Add E2E visual restore tests — covers hidden full-screen TUI restore and the snapshot/live-output race condition using deterministic __terminalHiddenSnapshotOverride injection.

✅ No new issues found.

The snapshot request protocol is cleanly layered — SnapshotRequest opcode flows renderer → runtime, response frames flow back through the existing SnapshotStart/Chunk/End pipeline, with snapshotTarget routing to the correct consumer. Threading seq metadata through the output path is backward-compatible (optional meta param on all callbacks) and enables the sequence-aware replay that prevents live TUI output from being lost during a delayed snapshot. The timer.unref() on snapshot request timeouts avoids keeping the process alive during teardown, and the E2E override seam (__terminalHiddenSnapshotOverride) enables deterministic testing of the snapshot/live-output race.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/terminal-hidden-output-restore-perf branch 2 times, most recently from 32833d1 to 4d34d02 Compare June 7, 2026 06:09

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — incremental diff since prior pullfrog review at c7e4228. This force-push threads a source field through all snapshot return types, refactors pendingOutput from string[] to TerminalOutputChunk to carry sequence metadata through the buffering layer, adds the server-side SnapshotRequest handler (sendRequestedSnapshot), and adds client-side snapshot request infrastructure in RemoteRuntimeTerminalMultiplexer.

  • Thread source ('headless' / 'renderer') through snapshot return types — added from OrcaRuntimeService.serializeHeadlessTerminalBuffer up through the preload API, IPC handler, and into the terminal multiplex RPC. renderer-sourced snapshots are tagged in serializeTerminalBufferFromAvailableState.
  • Refactor pendingOutput to TerminalOutputChunk[] — each chunk carries { data, meta } with optional seq/rawLength, enabling sequence-aware replay. trimPendingOutputToBudget now returns { chars, overflowed } for accurate overflow tracking during snapshot requests.
  • Add sendRequestedSnapshot server-side handler — reacts to SnapshotRequest opcode frames, flushes the output batcher, serializes the terminal buffer, sends a truncated empty snapshot on pending output overflow, and replays buffered output through the output batcher after snapshot delivery.
  • Add requestSnapshot / serializeBuffer on the remote transport — RemoteRuntimeTerminalMultiplexer dispatches SnapshotRequest frames with 10s timeout (timer.unref()), pending-request dedup, snapshotTarget routing between initial-subscribe and on-demand snapshots, and cleanup on close/error/end.
  • Add decodeSnapshotInfo — extracts cols, rows, seq, source, requestId, truncated from SnapshotStart payload with explicit type guards; source validates against known literals and defaults to undefined for anything else.
  • Add E2E hidden snapshot override seam — __terminalHiddenSnapshotOverride (setPending/resolve/clear) enables deterministic testing of the snapshot/live-output race.
  • Add tests — 2 visual E2E tests (basic hidden TUI restore + snapshot/live-output race), server-side snapshot request unit test with overflow scenario, client-side serializeBuffer request/response unit test, background drain backpressure test.

✅ No new issues found.

The source threading is backward-compatible (optional field at every layer). The sendFrame optional seq parameter correctly preserves the runtime output sequence on Output frames while letting the internal cursor handle frame-level ordering for control frames. The sendRequestedSnapshot overflow guard (resetting pendingOutputOverflowed before serialization, checking after) correctly captures mid-flight output. decodeSnapshotInfo's literal guard on source and the SnapshotEnd routing (checking requestId match before falling back to initialSnapshotReceived) are clean.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — incremental diff since 32833d1. The server-side sendRequestedSnapshot now retries serialization once when live output overflows during the first attempt, rather than immediately returning a truncated empty snapshot.

  • Retry on overflow in sendRequestedSnapshot — when pendingOutputOverflowed is true after the first serializeTerminalBuffer, the pending output buffer is cleared and a second serialization attempt is made. If the retry succeeds, the full snapshot is delivered to the client. If the retry also overflows, a truncated empty snapshot is sent as before.

✅ No new issues found.

The retry is bounded (one attempt), correctly clears the overflowed state before retrying, and re-checks both stream validity and overflow after the second serialization. The test was updated to verify the retry path — the mock supplies a { data: 'retry snapshot', cols: 120, rows: 40 } on the third serializeTerminalBuffer call and the test asserts the snapshot is untruncated with the retry data.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/terminal-hidden-output-restore-perf branch from 4d34d02 to 15fb7c7 Compare June 7, 2026 06:28
@nwparker
nwparker force-pushed the nwparker/terminal-hidden-output-restore-perf branch from 15fb7c7 to c425701 Compare June 7, 2026 06:33

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — force-push consolidation of the hidden remote terminal snapshot restore pipeline. All substantive features from prior reviews are present (snapshot request protocol, source/seq threading, overflow retry, E2E tests) with one notable behavioral change: a null-snapshot response now triggers an automatic retry instead of writing the unavailable-warning escape sequence.

  • Replaced hidden-output-restore-unavailable warning with automatic retry — when serializeHiddenOutputSnapshot returns null, hiddenOutputRestoreRetryDeferred is set and the restore loop retries on the next foreground output event, rather than writing the [Orca skipped hidden terminal output...] warning banner.
  • Bumped MIN_COMPATIBLE_RUNTIME_SERVER_VERSION to 3 — the new SnapshotRequest opcode requires server support; old servers are rejected upfront.

ℹ️ Protocol version bump rollout sequencing

The MIN_COMPATIBLE_RUNTIME_SERVER_VERSION bump from 2 to 3 means new clients will reject runtime servers running protocol version 2. The SnapshotRequest opcode (11) justifies the bump, but servers must be deployed before or alongside clients to avoid a window where new clients reject still-running v2 servers.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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