Skip to content

fix(runtime): return authoritative visible TUI output - #9078

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/review-pr-8854-visible-tui-output
Jul 18, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/review-pr-8854-visible-tui-output

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reworks #8854 around a single terminal-state authority.

terminal read and terminal show now use the runtime-owned live terminal model for active full-screen TUIs instead of reconstructing a second xterm snapshot during each query. Restored and partial PTYs can still use one shared provider snapshot, with bounded waits and stale-result rejection.

Closes #8746.

Why this shape

  • Live local, headless, SSH, and remote-runtime PTYs already feed Orca's runtime emulator. Reading that model avoids a second emulator, duplicate provider calls, and races between transcript, provider, and renderer state.
  • Uncursored reads return the current alternate-screen grid. Cursor reads remain transcript pagination and perform no provider snapshot I/O.
  • terminal show keeps its existing six-line/300-character preview contract, but sources that preview from the current TUI screen.
  • Restored/provider-backed snapshots are shared across concurrent read/show calls, limited to 750 ms, backed off after failure, and rejected after PTY generation, handle, graph, or live screen-mode changes.
  • A mounted renderer is only a bounded fallback when a known alternate-screen provider fails.

End-to-end verification

Exact public CLI flow on the pre-rebase runtime commit (5253e731a), using an isolated dev runtime and real Claude Code 2.1.211. The same runtime change is now rebased onto current main as e4c4f9626.

  1. orca-dev terminal create ... --command "claude --model haiku"
  2. Sent: Reply with exactly this one line and then remain open: ORCA_VISIBLE_OUTPUT_8854_REBASED
  3. Uncursored terminal read returned ORCA_VISIBLE_OUTPUT_8854_REBASED from Claude's live alternate screen.
  4. terminal show returned the current Claude prompt/status footer rather than stale pre-launch history.
  5. terminal read --cursor 0 stayed transcript-only and returned no reconstructed TUI frame.

Fresh no-renderer matrix on the same commit:

  • Local headless Vim: visible read/show correct; read p50 0.279 ms, p95 0.602 ms.
  • Encrypted orca serve client with Less: visible read/show correct; read p50 6.609 ms, p95 7.894 ms.
  • Both paths preserved cursor transcript semantics.

Ignored raw evidence: test-results/pr-8854/rework-rebased/results.json.

Automated checks

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts — 733 passed on rebased current main.
  • pnpm run typecheck — passed after cleaning stale project-reference build info from the rebase.
  • pnpm run typecheck:tsc:node — passed.
  • pnpm run typecheck:tsc:cli — passed.
  • pnpm run typecheck:tsc:web — passed.
  • pnpm exec oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts — passed.
  • pnpm exec oxfmt --check src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts — passed.
  • git diff --check — passed.
  • pnpm run build:cli && pnpm run build:electron-vite — passed.

Scope

No renderer, UI, IPC exposure, dependency, command-execution, authentication, or filesystem contract changes. The implementation is provider-neutral and keeps output, wait, and preview sizes bounded.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The runtime now tracks PTY lifecycle generations and invalidates provider snapshot caches across resets, exits, and disconnections. Provider and renderer snapshots support timeout-bounded, shared acquisition with alternate-screen reconciliation and visible-line parsing. Terminal reads and previews use visible snapshot fallbacks and reject stale handle mappings. Integration tests cover snapshot precedence, concurrency, failures, timeouts, fallback rendering, lifecycle resets, and output bounds.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The skill manifest version refresh is unrelated to #8746 and should be split out or justified separately. Move the manifest refresh to a separate PR or explain why it is required for this terminal-state change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning It covers summary and testing, but omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections, including screenshots/no visual change, testing checklist, AI review report, security audit, and notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The runtime now uses live terminal state first, falls back to shared provider snapshots with bounds and rejection, and mirrors preview behavior, matching #8746.
Title check ✅ Passed The title is concise and matches the main runtime-visible TUI output change.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

CI follow-up for the generated manifest refresh:

  • The primary PR Checks / verify job is green, including lint, manifest verification, typecheck, the full test step, unpacked-app build, and packaged-CLI smoke test.
  • The skill round-trip matrix passed 11/13 cases on attempt 1. I reran the failed jobs; the same two macOS + legacy [email protected] + autocrlf=false cases failed again.
  • The rerun failures are external/legacy fetch-update failures, before any terminal code is exercised:
    • copy: Failed to fetch tree for stablyai/orca
    • symlink: discovered the update, then [email protected] update orca-cli --global timed out after about 2 minutes
  • The corresponding Linux and Windows legacy cases pass, both macOS autocrlf=true cases pass, and the current-CLI case passes.

Rerun: https://github.com/stablyai/orca/actions/runs/29539490760/attempts/2

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/review-pr-8854-visible-tui-output branch from be885dc to e4c4f96 Compare July 17, 2026 17:52
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Rebase update: force-pushed e4c4f9626 onto current main (1c54171c5). The earlier generated-manifest commit was dropped because #9119 changed the manifest contract and current main is authoritative; the legacy skill-matrix failures documented above apply only to the previous head. The rebased runtime suite passes 733/733, with Node typecheck, oxlint, oxfmt, and git diff --check also passing.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4a24ec1f-a060-4c7a-83fc-a9c417178b06

📥 Commits

Reviewing files that changed from the base of the PR and between 1c54171 and e4c4f96.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment on lines +12888 to +12953
it.each([
{
name: 'live exit wins over an alternate provider snapshot',
snapshotData: '\x1b[?1049h\x1b[2J\x1b[HStale TUI\r\n',
snapshotMode: true,
liveData: '\x1b[?1049lreturned shell\r\n',
expectedMode: false,
expectedLine: 'shell history'
},
{
name: 'live entry wins over a primary provider snapshot',
snapshotData: 'stale shell\r\n',
snapshotMode: false,
liveData: '\x1b[?1049h\x1b[2J\x1b[HLive TUI\r\nnew frame\r\n',
expectedMode: true,
expectedLine: 'Live TUI'
}
])('$name', async ({ snapshotData, snapshotMode, liveData, expectedMode, expectedLine }) => {
type Snapshot = {
data: string
cols: number
rows: number
seq: number
source: 'headless'
alternateScreen: boolean
}
let resolveSnapshot!: (snapshot: Snapshot) => void
const serializeProviderBuffer = vi.fn(
() =>
new Promise<Snapshot>((resolve) => {
resolveSnapshot = resolve
})
)
const runtime = new OrcaRuntimeService(store)
runtime.setPtyController({
write: () => true,
kill: () => true,
getForegroundProcess: async () => null,
serializeProviderBuffer,
hasRendererSerializer: () => false
})
syncSinglePty(runtime)
runtime.onPtyData('pty-1', 'shell history\r\n', 100)
runtime.synchronizePtyOutputSequenceFromProvider(
'pty-1',
{ value: 900, generation: 'continued' },
0
)
const [terminal] = (await runtime.listTerminals()).terminals

const readPromise = runtime.readTerminal(terminal.handle)
await vi.waitFor(() => expect(serializeProviderBuffer).toHaveBeenCalledOnce())
runtime.onPtyData('pty-1', liveData, 101)
resolveSnapshot({
data: snapshotData,
cols: 80,
rows: 24,
seq: 900,
source: 'headless',
alternateScreen: snapshotMode
})

const read = await readPromise
expect(runtime.isTerminalAlternateScreen('pty-1')).toBe(expectedMode)
expect(read.tail.join('\n')).toContain(expectedLine)
expect(read.tail.join('\n')).not.toContain('Stale TUI')

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert each case’s actual stale snapshot text.

The second case contains stale shell, but the shared assertion only excludes Stale TUI. It therefore passes if stale provider content leaks alongside the live frame.

Proposed fix
       expectedMode: false,
-      expectedLine: 'shell history'
+      expectedLine: 'shell history',
+      staleLine: 'Stale TUI'
...
       expectedMode: true,
-      expectedLine: 'Live TUI'
+      expectedLine: 'Live TUI',
+      staleLine: 'stale shell'
...
-  ])('$name', async ({ snapshotData, snapshotMode, liveData, expectedMode, expectedLine }) => {
+  ])('$name', async ({
+    snapshotData,
+    snapshotMode,
+    liveData,
+    expectedMode,
+    expectedLine,
+    staleLine
+  }) => {
...
-    expect(read.tail.join('\n')).not.toContain('Stale TUI')
+    expect(read.tail.join('\n')).not.toContain(staleLine)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it.each([
{
name: 'live exit wins over an alternate provider snapshot',
snapshotData: '\x1b[?1049h\x1b[2J\x1b[HStale TUI\r\n',
snapshotMode: true,
liveData: '\x1b[?1049lreturned shell\r\n',
expectedMode: false,
expectedLine: 'shell history'
},
{
name: 'live entry wins over a primary provider snapshot',
snapshotData: 'stale shell\r\n',
snapshotMode: false,
liveData: '\x1b[?1049h\x1b[2J\x1b[HLive TUI\r\nnew frame\r\n',
expectedMode: true,
expectedLine: 'Live TUI'
}
])('$name', async ({ snapshotData, snapshotMode, liveData, expectedMode, expectedLine }) => {
type Snapshot = {
data: string
cols: number
rows: number
seq: number
source: 'headless'
alternateScreen: boolean
}
let resolveSnapshot!: (snapshot: Snapshot) => void
const serializeProviderBuffer = vi.fn(
() =>
new Promise<Snapshot>((resolve) => {
resolveSnapshot = resolve
})
)
const runtime = new OrcaRuntimeService(store)
runtime.setPtyController({
write: () => true,
kill: () => true,
getForegroundProcess: async () => null,
serializeProviderBuffer,
hasRendererSerializer: () => false
})
syncSinglePty(runtime)
runtime.onPtyData('pty-1', 'shell history\r\n', 100)
runtime.synchronizePtyOutputSequenceFromProvider(
'pty-1',
{ value: 900, generation: 'continued' },
0
)
const [terminal] = (await runtime.listTerminals()).terminals
const readPromise = runtime.readTerminal(terminal.handle)
await vi.waitFor(() => expect(serializeProviderBuffer).toHaveBeenCalledOnce())
runtime.onPtyData('pty-1', liveData, 101)
resolveSnapshot({
data: snapshotData,
cols: 80,
rows: 24,
seq: 900,
source: 'headless',
alternateScreen: snapshotMode
})
const read = await readPromise
expect(runtime.isTerminalAlternateScreen('pty-1')).toBe(expectedMode)
expect(read.tail.join('\n')).toContain(expectedLine)
expect(read.tail.join('\n')).not.toContain('Stale TUI')
it.each([
{
name: 'live exit wins over an alternate provider snapshot',
snapshotData: '\x1b[?1049h\x1b[2J\x1b[HStale TUI\r\n',
snapshotMode: true,
liveData: '\x1b[?1049lreturned shell\r\n',
expectedMode: false,
expectedLine: 'shell history',
staleLine: 'Stale TUI'
},
{
name: 'live entry wins over a primary provider snapshot',
snapshotData: 'stale shell\r\n',
snapshotMode: false,
liveData: '\x1b[?1049h\x1b[2J\x1b[HLive TUI\r\nnew frame\r\n',
expectedMode: true,
expectedLine: 'Live TUI',
staleLine: 'stale shell'
}
])('$name', async ({
snapshotData,
snapshotMode,
liveData,
expectedMode,
expectedLine,
staleLine
}) => {
type Snapshot = {
data: string
cols: number
rows: number
seq: number
source: 'headless'
alternateScreen: boolean
}
let resolveSnapshot!: (snapshot: Snapshot) => void
const serializeProviderBuffer = vi.fn(
() =>
new Promise<Snapshot>((resolve) => {
resolveSnapshot = resolve
})
)
const runtime = new OrcaRuntimeService(store)
runtime.setPtyController({
write: () => true,
kill: () => true,
getForegroundProcess: async () => null,
serializeProviderBuffer,
hasRendererSerializer: () => false
})
syncSinglePty(runtime)
runtime.onPtyData('pty-1', 'shell history\r\n', 100)
runtime.synchronizePtyOutputSequenceFromProvider(
'pty-1',
{ value: 900, generation: 'continued' },
0
)
const [terminal] = (await runtime.listTerminals()).terminals
const readPromise = runtime.readTerminal(terminal.handle)
await vi.waitFor(() => expect(serializeProviderBuffer).toHaveBeenCalledOnce())
runtime.onPtyData('pty-1', liveData, 101)
resolveSnapshot({
data: snapshotData,
cols: 80,
rows: 24,
seq: 900,
source: 'headless',
alternateScreen: snapshotMode
})
const read = await readPromise
expect(runtime.isTerminalAlternateScreen('pty-1')).toBe(expectedMode)
expect(read.tail.join('\n')).toContain(expectedLine)
expect(read.tail.join('\n')).not.toContain(staleLine)

Comment on lines +9049 to +9051
this.providerBufferAcquisitionsByPtyId.delete(ptyId)
this.providerVisibleStateByPtyId.delete(ptyId)
this.providerVisibleRetryAtByPtyId.delete(ptyId)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Add ptyLifecycleGenerationById.delete(ptyId) to both PTY teardown paths. The lifecycle-generation map is populated for every PTY (getPtyLifecycleGeneration / advancePtyLifecycleGeneration) but is the only per-PTY map with no eviction, so it grows unbounded across a long-lived host. Both teardown paths already advance the generation (clearing provider caches) before these deletes, so removing the entry is safe — a subsequent lookup re-mints a fresh generation that still fails any captured-generation equality check, preserving stale-response rejection.

  • src/main/runtime/orca-runtime.ts#L9049-L9051: add this.ptyLifecycleGenerationById.delete(ptyId) alongside the provider-cache deletions in onPtyExit.
  • src/main/runtime/orca-runtime.ts#L21592-L21594: add the same delete alongside the provider-cache deletions in dropDisconnectedPtyRecord.
🩹 Proposed fix (apply at both sites)
     this.providerBufferAcquisitionsByPtyId.delete(ptyId)
     this.providerVisibleStateByPtyId.delete(ptyId)
     this.providerVisibleRetryAtByPtyId.delete(ptyId)
+    this.ptyLifecycleGenerationById.delete(ptyId)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.providerBufferAcquisitionsByPtyId.delete(ptyId)
this.providerVisibleStateByPtyId.delete(ptyId)
this.providerVisibleRetryAtByPtyId.delete(ptyId)
this.providerBufferAcquisitionsByPtyId.delete(ptyId)
this.providerVisibleStateByPtyId.delete(ptyId)
this.providerVisibleRetryAtByPtyId.delete(ptyId)
this.ptyLifecycleGenerationById.delete(ptyId)
📍 Affects 1 file
  • src/main/runtime/orca-runtime.ts#L9049-L9051 (this comment)
  • src/main/runtime/orca-runtime.ts#L21592-L21594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant