Description
Summary
Orca has code, and a passing test, that says orca terminal read should fall back to the renderer's visible screen when a full-screen TUI (alt-screen, in-place redraws) leaves the retained transcript looking unhelpful. In practice this fallback is close to unreachable:
- It only triggers when every line in the returned bounded tail is blank — not the full retained transcript, but the last
DEFAULT_TERMINAL_READ_LIMIT(120) lines an uncursored read returns. For a TUI that redraws mostly in place rather than emitting new completed lines (the case we actually observed), pre-launch shell history never ages out of that window, so the condition is effectively unsatisfiable for that whole class of session. - Even when it would trigger, it asks only the Electron renderer's xterm serializer — never the runtime's own headless emulator, which normally exists once PTY data has been ingested, for headless (
orca serve), SSH, and remote-runtime worktrees alike. orca terminal show'spreviewfield goes through neither path. It returns the precomputed retained-transcript preview unconditionally.
The net effect: the runtime already computes an accurate headless screen model for every PTY, but the CLI/preview surface can't reach it except in a narrow, mostly-lab-only condition.
Intent (Orca's own tests establish the intent behind this fallback — within a narrow condition)
// src/main/runtime/orca-runtime.test.ts:11935
it('falls back to renderer visible screen when uncursored TUI tail is blank', async () => {
const serializeBuffer = vi.fn().mockResolvedValue({
data: '\x1b[?1049hClaude Code\r\nWorking on fix\r\nTool: Read\r\n',
cols: 80,
rows: 24
})
const runtime = new OrcaRuntimeService(store)
runtime.setPtyController({
write: () => true,
kill: () => true,
getForegroundProcess: async () => null,
hasRendererSerializer: () => true,
serializeBuffer
})
syncSinglePty(runtime)
const [terminal] = (await runtime.listTerminals()).terminals
runtime.onPtyData('pty-1', `${Array.from({ length: 3000 }, () => ' ').join('\n')}\n`, 100)
const read = await runtime.readTerminal(terminal.handle)
expect(read.tail).toEqual(['Claude Code', 'Working on fix', 'Tool: Read'])
expect(serializeBuffer).toHaveBeenCalledWith('pty-1', {
scrollbackRows: 0,
altScreenForcesZeroRows: false
})
})There's a second, adjacent test ('returns renderer visible screen lines through terminal.read RPC JSON result') asserting the same thing through the RPC JSON shape. The mock content is literally Claude Code with an alt-screen sequence — the fallback is explicitly meant to handle a Claude Code-style full-screen TUI.
But two other adjacent tests pin down how narrow that intent is: 'does not use renderer visible-screen fallback for cursor transcript reads' (orca-runtime.test.ts:12000) asserts the fallback must not fire for a cursor-paginated read, and 'does not use renderer visible-screen fallback for a short blank shell tail' (orca-runtime.test.ts:12028) asserts it must not fire for a blank tail that hasn't reached the substantial-blank threshold. So what the suite actually establishes is: for an uncursored read with a substantial (limited/truncated/≥120-line) all-blank returned tail, and a renderer serializer registered, Orca intends to fall back to the visible screen. The broader claims below — that a nonblank tail, a headless-only source, or terminal show's preview ought to trigger the same fallback — are suggestions consistent with that intent, not something the existing tests already require.
Root cause
1. The trigger condition requires a fully blank tail
// src/main/runtime/orca-runtime.ts:26107-26120
function shouldFallbackToVisibleTerminalSnapshot(
read: RuntimeTerminalRead,
opts: { cursor?: number; limit?: number }
): boolean {
if (typeof opts.cursor === 'number') {
return false
}
if (read.tail.length === 0) {
return false
}
const hasSubstantialBlankTail =
read.limited === true || read.truncated || read.tail.length >= DEFAULT_TERMINAL_READ_LIMIT
return hasSubstantialBlankTail && read.tail.every((line) => line.trim().length === 0)
}DEFAULT_TERMINAL_READ_LIMIT is 120 (orca-runtime.ts:24808), and read.tail here is the bounded tail an uncursored read returns — readTerminalTail's uncursored branch slices the last limit lines out of the full retained buffer (orca-runtime.ts:26080), not the complete retained transcript, which can hold up to MAX_TAIL_LINES (2000) lines. So the condition is: no cursor, a non-empty tail, and either the tail is already limited/truncated or it has reached the 120-line cap — and every one of those returned lines is whitespace-only.
For a TUI that emits plenty of new completed lines, that 120-line window can eventually slide past any pre-launch shell history and land on all-blank content, satisfying the condition. But for a full-screen TUI that redraws mostly in place — moving the cursor and overwriting existing rows rather than completing new ones (the case we actually observed) — the completed-line count barely advances, so the bounded window keeps returning the same pre-launch shell history indefinitely; for that whole class of session the condition is effectively never satisfiable. (The retained buffer itself is not immune to in-place rewrites either — cursor-repositioning sequences can delete or rewrite already-completed rows, which is a separate defect covered in the companion issue (#8745).) The synthetic test fixture (3000 literally-blank lines, no preceding shell history) is the kind of input that satisfies this condition.
2. The fallback only asks the renderer, never the runtime's own headless model
// src/main/runtime/orca-runtime.ts:7054-7069
private async readRendererVisibleSnapshotLines(ptyId: string): Promise<string[]> {
const controller = this.ptyController
if (!controller?.serializeBuffer) {
return []
}
if (controller.hasRendererSerializer && !controller.hasRendererSerializer(ptyId)) {
return []
}
try {
// Why: raw PTY tails can be whitespace-only while a full-screen TUI is
// visibly nonblank in renderer xterm. Ask the renderer for the active
// screen instead of reusing the headless transcript path.
const snapshot = await controller.serializeBuffer(ptyId, {
scrollbackRows: 0,
altScreenForcesZeroRows: false
})
...hasRendererSerializer is backed by a registry that settlePaneSerializer populates when a renderer pane registers for a ptyId (src/main/ipc/pty.ts:5130):
// src/main/ipc/pty.ts:3469-3476
hasRendererSerializer: (ptyId) => {
// Why: the runtime needs a synchronous probe so it can decide whether to
// skip the daemon-snapshot seed (the renderer will hydrate it) or run the
// seed (no renderer authoritative for this PTY). A registry write happens
// when the renderer calls registerPtySerializer; we check via the same
// pendingByPaneKey + ptyId pairing that the cooperation gate uses.
return rendererSerializerByPtyId.has(ptyId)
}That registration doesn't check provider type or focus — an SSH-hosted PTY registers exactly like a local one whenever a renderer pane is mounted for it. The one path that explicitly opts out is a runtime: (remote-runtime) PTY: the renderer's spawn flow gates both the pre-signal and the registration call behind !isRemoteRuntimePtyId(resolvedPtyId) (src/renderer/src/components/terminal-pane/pty-connection.ts:4379).
The registry entry is also stickier than "currently mounted" suggests: the main process only deletes it on PTY teardown (src/main/ipc/pty.ts:1168), not on pane unmount, so hasRendererSerializer() can keep reporting true for a PTY whose renderer view was torn down. The actual serializeBuffer call then resolves to null once it reaches the renderer side: registerPtySerializer's unregister closure runs on unmount (src/renderer/src/components/terminal-pane/pty-buffer-serializer.ts:44), and the pending-request handler falls back to null when no entry is found (:130).
So the fallback depends on whether any renderer serializer is currently registered for that exact ptyId. That fails for a headless orca serve instance (no renderer at all), for a remote-runtime PTY (explicitly excluded above), and for any other PTY that simply has no renderer serializer registered — even though the runtime already has an authoritative headless screen model sitting right there:
// src/main/runtime/orca-runtime.ts:6582
serializeTerminalBuffer(
ptyId: string,
opts: { scrollbackRows?: number } = {}
): Promise<{
data: string
cols: number
rows: number
...
source?: 'headless' | 'renderer'
...
}> {
return this.serializeTerminalBufferFromAvailableState(ptyId, opts)
}This method already resolves to a 'headless' | 'renderer' source and is used by the RPC terminal-serialize endpoints (src/main/runtime/rpc/methods/terminal.ts:566, :623, :635 — the mobile/remote-subscriber terminal snapshot paths). It's just never consulted by readRendererVisibleSnapshotLines.
3. terminal show's preview never goes through the fallback at all
// src/main/runtime/orca-runtime.ts:10156-10180
async showTerminal(handle: string): Promise<RuntimeTerminalShow> {
const pty = this.getLivePtyForHandle(handle)
if (pty) {
const worktreesById = await this.getResolvedWorktreeMap()
return {
...this.buildPtyTerminalSummary(pty.pty, worktreesById),
...
}
}
...
}// src/main/runtime/orca-runtime.ts:21600-21620
private buildPtyTerminalSummary(
pty: RuntimePtyWorktreeRecord,
worktreesById: Map<string, ResolvedWorktree>
): RuntimeTerminalSummary {
...
return {
handle: this.issuePtyHandle(pty),
...
preview: pty.preview
}
}preview: pty.preview is returned unconditionally — no call to withVisibleSnapshotFallback anywhere in this path. Compare with readTerminal, which does route through it:
// src/main/runtime/orca-runtime.ts:10182-10204
async readTerminal(
handle: string,
opts: { cursor?: number; limit?: number } = {}
): Promise<RuntimeTerminalRead> {
const pty = this.getLivePtyForHandle(handle)
if (pty) {
const read = this.readPtyTerminal(handle, pty.pty, opts)
return this.withVisibleSnapshotFallback(pty.pty.ptyId, read, opts)
}
...So even in the narrow case where the fallback would fire for terminal read, terminal show's preview — the field most tools glance at first — never gets it.
Observed behavior (motivating context — root cause of this specific symptom not fully pinned)
We hit this while babysitting a real Claude Code session over SSH: orca terminal show's preview stayed frozen on pre-launch shell history while lastOutputAt kept advancing, and orca terminal read's cursor never moved even though the agent was visibly still working. That's consistent with (1) and (3) above — the tail was never blank (it still held the launch-time shell prompt), and show never tries the fallback regardless. We are not claiming this fully explains every instance of a frozen preview; we didn't capture raw PTY bytes to confirm a single root cause, and the transcript-append path has its own, structurally different defect (see companion issue, #8745). This section is offered as real-world motivation, not as an additional claim requiring separate fix verification.
Expected vs. actual
| Expected (per Orca's own test) | Actual | |
|---|---|---|
terminal read on a full-screen TUI with a non-blank returned tail |
Falls back to a visible-screen snapshot | Never triggers — condition requires every line in the returned (120-line-bounded) tail to be blank |
terminal read on headless, remote-runtime, or any PTY with no renderer serializer registered, tail is blank |
Falls back to the runtime's own headless screen model | Falls back to nothing ([]) — no renderer serializer registered, headless model never consulted |
terminal show's preview on the same conditions |
(untested, but same intent applies) | No fallback attempted under any condition |
Suggested direction (not prescriptive — happy to defer to maintainers' judgment on the right shape)
- Loosen
shouldFallbackToVisibleTerminalSnapshot's all-blank requirement, or reframe the heuristic around "does the tail look like a live redraw region" rather than "is it entirely whitespace." - Prefer the runtime's own
serializeTerminalBuffer()(headless model, normally available once PTY data has been ingested) as the primary/first source for this fallback, with the renderer serializer as an optional freshness upgrade when one happens to be mounted — rather than the renderer being the only source. - Wire
terminal show'spreviewthrough the same fallback pathterminal readuses, so the two surfaces don't disagree about what's visible.
Environment
- Orca
1.4.138-rc.7(commit9a77f5667) - Symptom observed on macOS, agent (Claude Code) running in an SSH worktree; code-path analysis above applies independent of that specific setup
Activity