Repository navigation
fix(runtime): return authoritative visible TUI output - #9078
Conversation
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
|
Caution Review failedAn 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. Comment |
|
CI follow-up for the generated manifest refresh:
|
Co-authored-by: Orca <[email protected]>
be885dc to
e4c4f96
Compare
|
Rebase update: force-pushed |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4a24ec1f-a060-4c7a-83fc-a9c417178b06
📒 Files selected for processing (2)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
| 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') |
There was a problem hiding this comment.
🎯 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.
| 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) |
| this.providerBufferAcquisitionsByPtyId.delete(ptyId) | ||
| this.providerVisibleStateByPtyId.delete(ptyId) | ||
| this.providerVisibleRetryAtByPtyId.delete(ptyId) |
There was a problem hiding this comment.
🩺 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: addthis.ptyLifecycleGenerationById.delete(ptyId)alongside the provider-cache deletions inonPtyExit.src/main/runtime/orca-runtime.ts#L21592-L21594: add the same delete alongside the provider-cache deletions indropDisconnectedPtyRecord.
🩹 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.
| 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
Summary
Reworks #8854 around a single terminal-state authority.
terminal readandterminal shownow 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
terminal showkeeps its existing six-line/300-character preview contract, but sources that preview from the current TUI screen.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 currentmainase4c4f9626.orca-dev terminal create ... --command "claude --model haiku"Reply with exactly this one line and then remain open: ORCA_VISIBLE_OUTPUT_8854_REBASEDterminal readreturnedORCA_VISIBLE_OUTPUT_8854_REBASEDfrom Claude's live alternate screen.terminal showreturned the current Claude prompt/status footer rather than stale pre-launch history.terminal read --cursor 0stayed transcript-only and returned no reconstructed TUI frame.Fresh no-renderer matrix on the same commit:
orca serveclient with Less: visible read/show correct; read p50 6.609 ms, p95 7.894 ms.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 currentmain.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.