Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/daemon/serialize-grid-transcript-replay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const KNOWN_PREEXISTING_I2_FAILURES: Record<string, number> = {
less: 6,
nano: 2,
opencode: 5,
// OpenCode boot captures: rows on its true-colour background, and the row a shrink leaves
// behind, restore inexactly after a resize. Pre-existing: they landed with no serializer change.
'opencode-1-18-32-timed-boot-hidden-pane': 16,
'opencode-1-18-32-timed-boot-slow': 16,
'opencode-1-18-32-timed-first-launch': 16,
'opencode-2-0-18-timed-boot-hidden-pane': 14,
Comment on lines +38 to +43

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

🔎 Supported by static analysis

🏁 Script executed:

rg -n -C 10 'new-fail|KNOWN_PREEXISTING_I2_FAILURES' src/main/daemon/serialize-grid-transcript-replay.test.ts
rg -n -C 8 'I2|checkpoint|new-fail' src/main/daemon/serialize-grid-roundtrip.ts
sed -n '180,245p' src/main/daemon/serialize-grid-transcript-replay.test.ts

Repository: stablyai/orca

Length of output: 7757


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- replay test: setup and assertion path ---'
sed -n '1,80p' src/main/daemon/serialize-grid-transcript-replay.test.ts
sed -n '150,230p' src/main/daemon/serialize-grid-transcript-replay.test.ts
printf '%s\n' '--- roundtrip classification ---'
sed -n '296,345p' src/main/daemon/serialize-grid-roundtrip.ts
printf '%s\n' '--- PR diff for the reviewed file ---'
git diff --no-ext-diff --unified=25 8cc28545a2514cf14cd25187b9bd24a6d9e03ba1 5ff7d779449c6f97aedce9f3092bad2583eb7c23 -- src/main/daemon/serialize-grid-transcript-replay.test.ts

Repository: stablyai/orca

Length of output: 12143


Assert OpenCode I2 failure identities, not only their count.

For the default two-seed run, each non-null gridDiff.new adds one new-fail. The OpenCode entries compare only the aggregate count. A different I2 mismatch can therefore replace the known resize mismatch and still pass. Store and compare the expected failureSignatures for each OpenCode transcript.

// Shrink leaves the cursor one column short; also present in the pre-Qoder serializer.
'qoder-no-account': 2,
'qoder-ready': 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:40:33.073309Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: answered like a hidden Orca pane (silent on OSC colour queries), as a background worker pane is. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'headless' = Orca's hidden-pane replies, silent on OSC colour queries. Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 42.8 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":42761.8,"chunks":[[785.0,205],[786.9,71],[791.9,8],[793.5,57],[793.9,32],[794.0,16],[794.0,16],[794.1,24],[794.2,24],[794.2,24],[794.3,36],[794.4,24],[794.5,24],[795.2,1024],[795.8,1024],[796.3,1024],[796.7,1024],[796.9,1024],[797.2,961],[811.9,1024],[812.5,1024],[813.1,1024],[813.6,1024],[814.1,1024],[814.7,937],[2523.9,1024],[2524.9,1024],[2525.2,1024],[2525.5,1024],[2525.8,1024],[2526.1,1024],[2526.3,353],[2541.6,13],[2609.5,934],[2610.0,938],[2610.6,871],[2611.3,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:39:12.532885Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: the slowest recorded boot: 3.9 s of silence after bracketed paste is enabled, and the longest gap (161 ms) between the bare OpenCode title and the input box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'xterm' = xterm.js 6.0 replies incl. OSC 10/11/12/4 colours (a visible Orca pane). Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 76.9 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":76886.4,"chunks":[[2454.9,276],[2478.3,8],[2513.8,1024],[2518.9,1024],[2531.6,1024],[2539.1,1024],[2581.2,1024],[2583.9,1024],[2587.4,411],[2593.0,1024],[2602.3,1024],[2607.8,1024],[2621.8,1024],[2622.5,1024],[2623.3,937],[6479.2,1024],[6485.0,1024],[6487.5,1024],[6490.0,1024],[6499.8,1024],[6502.7,1024],[6509.0,353],[6538.4,13],[6685.0,934],[6686.4,938],[6697.9,871],[6699.1,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:33:44.169427Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: first launch on an empty home: no first-run dialog appears before the input box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'xterm' = xterm.js 6.0 replies incl. OSC 10/11/12/4 colours (a visible Orca pane). Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 14.9 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":14932.3,"chunks":[[894.6,205],[897.3,71],[906.1,8],[909.0,57],[909.3,32],[909.4,16],[909.5,16],[909.6,24],[909.6,24],[909.8,24],[909.9,36],[910.0,24],[910.1,24],[911.8,134],[915.0,1024],[916.4,1024],[917.0,1024],[917.5,1024],[918.0,1024],[918.6,1024],[933.4,1024],[934.1,1024],[934.7,1024],[935.3,1024],[935.8,1024],[936.4,937],[2731.2,1024],[2731.8,1024],[2732.2,1024],[2732.7,1024],[2733.1,1024],[2734.0,1024],[2734.4,353],[2766.9,13],[2847.0,934],[2847.6,938],[2848.1,871],[2848.6,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:50:47.405221Z",
"platform": "darwin",
"command": ["opencode", "--standalone"],
"cols": 120,
"rows": 40,
"note": "opencode v2.0.18 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: OpenCode 2 answered like a hidden Orca pane; show-cursor repeats on every frame after the box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'headless' = Orca's hidden-pane replies, silent on OSC colour queries. Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 41.5 s; no bytes after the last chunk. Run as `opencode --standalone` from a 2.0.18 binary; Orca's opencode2 row launches `opencode2 --standalone`. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":41502.8,"chunks":[[307.5,280],[316.3,1024],[316.7,1024],[317.0,1024],[317.4,1024],[317.7,1024],[318.0,1022],[318.3,164],[318.3,24],[318.3,24],[326.8,1024],[327.5,1024],[328.0,1024],[328.6,1024],[329.1,1024],[329.7,937],[1339.7,1024],[1340.4,1024],[1341.1,1024],[1341.8,1024],[1342.5,1024],[1343.1,1024],[1343.8,353],[1348.0,13],[1387.9,934],[1388.4,938],[1388.7,832],[1418.2,483],[1436.2,483],[1453.8,488],[1471.8,497],[1489.7,498],[1508.0,504],[1525.8,504],[1543.2,504],[1560.9,504]]}

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions src/main/runtime/agent-prompt-launch-submit-retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { resolveAgentPromptSubmitDelayForAgent } from '../../shared/agent-prompt-injection'
import type { TuiAgent } from '../../shared/tui-agent'
import { TUI_AGENT_CONFIG } from '../../shared/tui-agent-config'
import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture'
import { dispatchPreambleSendOptions } from './orchestration/preamble'

vi.mock('../git/worktree', () => ({
listWorktrees: vi.fn().mockResolvedValue([
{
path: '/tmp/worktree-a',
head: 'abc',
branch: 'feature/launch-submit-retry',
isBare: false,
isMainWorktree: false
}
]),
listWorktreesStrict: vi.fn().mockResolvedValue([
{
path: '/tmp/worktree-a',
head: 'abc',
branch: 'feature/launch-submit-retry',
isBare: false,
isMainWorktree: false
}
])
}))

const PROMPT = 'Task: reply with OK'

async function sendDispatch(agent: TuiAgent, retrySubmitAfterLaunch: boolean) {
const { runtime, handle, writes } = await createAgentPromptSubmissionRuntime(() => {}, agent)
const sent = runtime.sendTerminalAgentPrompt(handle, PROMPT, {
...dispatchPreambleSendOptions('request-1'),
retrySubmitAfterLaunch
})
return { runtime, sent, enters: () => writes.filter((data) => data === '\r').length }
}

// Why: OpenCode 2 drops an Enter sent before its mode row is drawn, so a worker's first dispatch
// gets one more Enter; every other send keeps exactly one.
describe('retry Enter on a launched worker first dispatch', () => {
afterEach(() => vi.useRealTimers())

it.each(['opencode', 'opencode2'] as const)(
'%s gets a second Enter after its row delay',
async (agent) => {
vi.useFakeTimers()
const submitDelayMs = resolveAgentPromptSubmitDelayForAgent(process.platform, PROMPT, agent)
const retryDelayMs = TUI_AGENT_CONFIG[agent].submitRetryDelayMs ?? 0
const { sent, enters } = await sendDispatch(agent, true)

await vi.advanceTimersByTimeAsync(submitDelayMs)
expect(enters()).toBe(1)
await vi.advanceTimersByTimeAsync(retryDelayMs - 1)
expect(enters()).toBe(1)
await vi.advanceTimersByTimeAsync(1)

await expect(sent).resolves.toMatchObject({
accepted: true,
bytesWritten: expect.any(Number),
prompt: { stages: ['input_accepted'] }
})
expect(enters()).toBe(2)
}
)

it('keeps one Enter for dispatches that did not launch the agent', async () => {
vi.useFakeTimers()
const { sent, enters } = await sendDispatch('opencode', false)

await vi.runAllTimersAsync()
await sent
expect(enters()).toBe(1)
})

it.each(['codex', 'claude', 'aider'] as const)(
'%s keeps one Enter on a launched worker first dispatch',
async (agent) => {
vi.useFakeTimers()
const { sent, enters } = await sendDispatch(agent, true)

await vi.runAllTimersAsync()
await sent
expect(enters()).toBe(1)
}
)

it('leaves the first Enter standing when the pane exits before the retry', async () => {
vi.useFakeTimers()
const submitDelayMs = resolveAgentPromptSubmitDelayForAgent(
process.platform,
PROMPT,
'opencode'
)
const { runtime, sent, enters } = await sendDispatch('opencode', true)

await vi.advanceTimersByTimeAsync(submitDelayMs)
expect(enters()).toBe(1)
await runtime.onPtyExit('pty-prompt', 0)
await vi.runAllTimersAsync()

await expect(sent).resolves.toMatchObject({ accepted: true })
expect(enters()).toBe(1)
})
})
35 changes: 35 additions & 0 deletions src/main/runtime/agent-transcript-replay-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,41 @@ export function readRuntimeFixture(name: string): string {
return readFileSync(join(__dirname, '__fixtures__', `${name}.txt`), 'utf8')
}

export type TimedRuntimeFixture = {
/** The recorded PTY reads, in order; they concatenate to the whole `.txt`. */
chunks: string[]
/** ms since spawn at which each read arrived. */
times: number[]
promptSentAtMs?: number
/** When recording stopped; no bytes arrived between the last read and this. */
recordedUntilMs?: number
}

/** `<name>.timing.json` holds each read as [ms since spawn, UTF-16 length]. */
export function readTimedRuntimeFixture(name: string): TimedRuntimeFixture {
const data = readRuntimeFixture(name)
const timing: {
chunks: [number, number][]
promptSentAtMs?: number
recordedUntilMs?: number
} = JSON.parse(readFileSync(join(__dirname, '__fixtures__', `${name}.timing.json`), 'utf8'))
const chunks: string[] = []
let offset = 0
for (const [, length] of timing.chunks) {
chunks.push(data.slice(offset, offset + length))
offset += length
}
if (offset !== data.length) {
throw new Error(`${name}.timing.json covers ${offset} of ${data.length} chars`)
}
return {
chunks,
times: timing.chunks.map(([at]) => at),
...(timing.promptSentAtMs !== undefined ? { promptSentAtMs: timing.promptSentAtMs } : {}),
...(timing.recordedUntilMs !== undefined ? { recordedUntilMs: timing.recordedUntilMs } : {})
}
}

/** A string is cut into fixed 64-char chunks; an array replays the recorded PTY chunks as-is. */
export async function* replayTranscript(
data: string | readonly string[],
Expand Down
20 changes: 5 additions & 15 deletions src/main/runtime/codex-quiet-ready-screen.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { TuiAgent } from '../../shared/tui-agent'
import { createTranscriptPane } from './agent-transcript-pane-test-harness'
import {
readRuntimeFixture,
readTimedRuntimeFixture,
replayTranscript,
type TranscriptReplayFrame
} from './agent-transcript-replay-test-harness'
Expand Down Expand Up @@ -204,21 +203,12 @@ describe('Codex composer ready screen, frame by frame', () => {
})
})

type Timing = { promptSentAtMs: number; chunks: [number, number][] }

function readTimedFixture(name: string): { chunks: string[]; times: number[]; promptAt: number } {
const data = readRuntimeFixture(name)
const timing: Timing = JSON.parse(
readFileSync(join(__dirname, '__fixtures__', `${name}.timing.json`), 'utf8')
)
const chunks: string[] = []
let offset = 0
for (const [, length] of timing.chunks) {
chunks.push(data.slice(offset, offset + length))
offset += length
const { chunks, times, promptSentAtMs } = readTimedRuntimeFixture(name)
if (promptSentAtMs === undefined) {
throw new Error(`${name}.timing.json has no promptSentAtMs`)
}
expect(offset).toBe(data.length)
return { chunks, times: timing.chunks.map(([at]) => at), promptAt: timing.promptSentAtMs }
return { chunks, times, promptAt: promptSentAtMs }
}

describe('the quiet lane over recorded chunk timing (default animations)', () => {
Expand Down
Loading
Loading