diff --git a/config/reliability-gates.jsonc b/config/reliability-gates.jsonc index 2bcba7cb737..72bcb4b4d7f 100644 --- a/config/reliability-gates.jsonc +++ b/config/reliability-gates.jsonc @@ -10,6 +10,75 @@ } }, "gates": [ + { + "id": "terminal-performance.padded-fullscreen-redraw", + "title": "Fullscreen redraw padding does not stall terminal delivery", + "maturity": "experimental", + "protection": "partial", + "owner": "terminal-runtime", + "layer": "runtime-unit-and-electron-cdp", + "surfaces": ["terminal transcript preview", "fullscreen TUI scrolling"], + "platforms": ["macos", "linux", "windows"], + "providers": ["local", "daemon", "ssh", "remote-runtime"], + "coveredPlatforms": ["macos"], + "coveredProviders": ["local", "daemon"], + "coverageNotes": "The trim operation is platform-independent and preserves the same spaces/tabs policy for all providers. Real Pi 0.84.2 was exercised in a hidden macOS Electron renderer through CDP using a folder workspace.", + "motivatingLinks": ["https://github.com/stablyai/orca/issues/14770"], + "invariant": "Transcript preview trimming preserves internal whitespace and terminal read contents without quadratic main-process work on padded fullscreen redraws.", + "oracle": "Preserve 32,000 spaces before a marker while trimming trailing spaces/tabs in both retained-row and carried-prefix redraw paths; four redraws must finish within 500 ms. Existing tail equivalence tests preserve cursor, retention, and pagination behavior.", + "commands": [ + "ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/runtime/terminal-tail-whitespace.test.ts src/main/runtime/terminal-tail-buffer.test.ts src/main/runtime/retained-tail-redraw-window.equivalence.test.ts" + ], + "testFiles": [ + "src/main/runtime/terminal-tail-whitespace.test.ts", + "src/main/runtime/terminal-tail-buffer.test.ts", + "src/main/runtime/retained-tail-redraw-window.equivalence.test.ts" + ], + "assertionRefs": [ + { + "file": "src/main/runtime/terminal-tail-whitespace.test.ts", + "assertions": [ + "handles padded redraws across %i retained rows without stalling", + "preserves terminal text while trimming spaces and tabs: %j" + ] + } + ], + "evidenceRuns": [ + { + "date": "2026-09-06", + "runner": "local", + "platform": "macos", + "command": "ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/runtime/terminal-tail-whitespace.test.ts src/main/runtime/terminal-tail-buffer.test.ts src/main/runtime/retained-tail-redraw-window.equivalence.test.ts", + "result": "passed", + "durationSeconds": 3.96, + "summary": "17 tests passed. Before the fix both padding budget cases failed, taking approximately 1.7 seconds each." + } + ], + "runtimeBudget": { + "p95Seconds": 30, + "scope": "Three unit test files; padding cases allow 500 ms for four redraws." + }, + "flakeHistory": { + "status": "not-started", + "evidence": "Initial local red/green validation; no CI soak history yet." + }, + "redGreenEvidence": { + "status": "complete", + "evidence": "Both padding budget cases fail with regex trimming and pass with the existing linear trim. A 60-event CDP wheel stream in Pi fullscreen had about 2.1 seconds of output tail before the fix and 14 ms after rebuilding." + }, + "performanceBudget": { + "required": true, + "evidence": "The main CPU profile attributed 3.1 seconds to redraw-row whitespace trimming. Reusing the linear trim adds no timers, caches, provider calls, or output dropping." + }, + "knownGaps": [ + "The user manually compared the fixed dev app with production and confirmed improved responsiveness. A live Terminal.app comparison was not exercised; timing measurements used CDP wheel events.", + "Linux, Windows, and live SSH rendering were not exercised; the shared trimming behavior is covered by unit tests." + ], + "promotionCriteria": [ + "Complete CI soak requirements and retain the padding budget and tail equivalence oracles." + ], + "demotionRule": "Keep experimental until CI soak is stable; investigate any budget failure without weakening transcript preservation." + }, { "id": "ssh.localhost-terminal-agent-hooks", "title": "Localhost SSH terminal and agent hooks reach the owning pane", diff --git a/src/main/runtime/terminal-tail-buffer.ts b/src/main/runtime/terminal-tail-buffer.ts index 141b14da6ec..b3e15d1f375 100644 --- a/src/main/runtime/terminal-tail-buffer.ts +++ b/src/main/runtime/terminal-tail-buffer.ts @@ -293,7 +293,7 @@ function appendNormalizedToMultilineTailBuffer( const line = rewritten[index]! const lastChar = line.charCodeAt(line.length - 1) if (lastChar === 32 || lastChar === 9) { - rewritten[index] = line.replace(/[ \t]+$/g, '') + rewritten[index] = trimTerminalLineRight(line) } } for (const line of windowed.lines) { diff --git a/src/main/runtime/terminal-tail-redraw-buffer.ts b/src/main/runtime/terminal-tail-redraw-buffer.ts index cf90605fcd1..7ebb06753dd 100644 --- a/src/main/runtime/terminal-tail-redraw-buffer.ts +++ b/src/main/runtime/terminal-tail-redraw-buffer.ts @@ -185,7 +185,7 @@ function finalizeRetainedTerminalRows( newlyCompletedLines: string[] } { let truncated = initialTruncated - let retainedRows = rows.map((row) => ({ ...row, text: row.text.replace(/[ \t]+$/g, '') })) + let retainedRows = rows.map((row) => ({ ...row, text: trimTerminalLineRight(row.text) })) if (retainedRows.length > MAX_TAIL_LINES + 1) { const removeCount = retainedRows.length - (MAX_TAIL_LINES + 1) diff --git a/src/main/runtime/terminal-tail-whitespace.test.ts b/src/main/runtime/terminal-tail-whitespace.test.ts new file mode 100644 index 00000000000..280d3a02d50 --- /dev/null +++ b/src/main/runtime/terminal-tail-whitespace.test.ts @@ -0,0 +1,32 @@ +import { performance } from 'node:perf_hooks' +import { describe, expect, it } from 'vitest' +import { appendNormalizedToTailBuffer } from './terminal-tail-buffer' +import { trimTerminalLineRight } from './terminal-tail-line-controls' + +describe('terminal redraw whitespace', () => { + it.each([ + ['hello \t', 'hello'], + [' \thello \t world \t', ' \thello \t world'], + [' \t', ''], + ['hello\u00a0 \t', 'hello\u00a0'], + ['hello\n', 'hello\n'] + ])('preserves terminal text while trimming spaces and tabs: %j', (input, expected) => { + expect(trimTerminalLineRight(input)).toBe(expected) + }) + + it.each([2, 20])('handles padded redraws across %i retained rows without stalling', (rows) => { + const padded = `${' '.repeat(32_000)}marker \t` + const previousLines = Array.from({ length: rows }, (_, index) => + index === 0 ? padded : `row ${index}` + ) + const start = performance.now() + let result: ReturnType | undefined + for (let frame = 0; frame < 4; frame += 1) { + result = appendNormalizedToTailBuffer(previousLines, 'footer', '\x1b[1A\rupdated') + } + const elapsedMs = performance.now() - start + expect(result?.lines[0]).toBe(`${' '.repeat(32_000)}marker`) + // Interior padding made the trailing-whitespace regex backtrack quadratically. + expect(elapsedMs).toBeLessThan(500) + }) +})