From 943fc781bb7d6b88e90851a9be2ba98ffe7402b7 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:52:17 -0700 Subject: [PATCH] perf(runtime): reuse unchanged PTY path history (#8163) --- config/reliability-gates.jsonc | 34 +++++++++++--- ...rca-runtime-path-candidate-history.test.ts | 47 +++++++++++++++++++ src/main/runtime/orca-runtime.ts | 8 +++- 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/main/runtime/orca-runtime-path-candidate-history.test.ts diff --git a/config/reliability-gates.jsonc b/config/reliability-gates.jsonc index 309404761..0c4df07a2 100644 --- a/config/reliability-gates.jsonc +++ b/config/reliability-gates.jsonc @@ -1221,6 +1221,7 @@ "surfaces": [ "daemon stream", "main PTY batching", + "runtime path provenance", "renderer ACK", "xterm scheduler", "hidden output" @@ -1240,20 +1241,22 @@ "macos" ], "coveredProviders": [], - "coverageNotes": "Local macOS evidence over the main-process pending-output caps that exist on main@1282f5c2d. Daemon stream write(false)/drain contracts, cross-session drain priority, and bounded queued tails arrive with the pending perf slice; live flood/latency artifacts remain gaps.", + "coverageNotes": "Local macOS evidence covers the existing main-process pending-output caps plus deterministic runtime path-provenance history reuse. Daemon stream write(false)/drain contracts, cross-session drain priority, and bounded queued tails arrive with the pending perf slice; live flood/latency artifacts remain gaps.", "motivatingLinks": [ "https://github.com/stablyai/orca/pull/6836", "https://github.com/stablyai/orca/pull/6858", "https://github.com/stablyai/orca/pull/7002", "https://github.com/stablyai/orca/pull/7054" ], - "invariant": "High-volume terminal output must stay bounded across daemon socket writes, main-to-renderer in-flight bytes, renderer scheduler queues, and hidden-output restore without starving focused input.", - "oracle": "The current executable slice injects daemon socket backpressure and main-process renderer backlog pressure, then asserts write(false)/drain ordering, bounded queued daemon bytes, per-PTY and total pending-output caps, preserved sequenced-tail metadata, active-pending protection ahead of background trimming, and ACK-gated in-flight bounds. The live Electron perf oracle adds hidden-output floods, renderer scheduler queue depth, dropped-output-zero normal scenarios, and active key latency budgets before promotion.", + "invariant": "High-volume terminal output must stay bounded across daemon socket writes, main runtime metadata, main-to-renderer in-flight bytes, renderer scheduler queues, and hidden-output restore without starving focused input.", + "oracle": "The current executable slice injects daemon socket backpressure and main-process renderer backlog pressure, then asserts write(false)/drain ordering, bounded queued daemon bytes, unchanged path-provenance history reuse for pathless output, per-PTY and total pending-output caps, preserved sequenced-tail metadata, active-pending protection ahead of background trimming, and ACK-gated in-flight bounds. The live Electron perf oracle adds hidden-output floods, renderer scheduler queue depth, dropped-output-zero normal scenarios, and active key latency budgets before promotion.", "commands": [ - "pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts" + "pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts", + "pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime-path-candidate-history.test.ts" ], "testFiles": [ - "src/main/ipc/pty.test.ts" + "src/main/ipc/pty.test.ts", + "src/main/runtime/orca-runtime-path-candidate-history.test.ts" ], "assertionRefs": [ { @@ -1263,6 +1266,13 @@ "active PTY pending output is prioritized during renderer backpressure", "combined pending output exceeding the interactive size limit is batched" ] + }, + { + "file": "src/main/runtime/orca-runtime-path-candidate-history.test.ts", + "assertions": [ + "reuses path-candidate history across repeated pathless PTY output", + "copies history when new output adds a path candidate" + ] } ], "evidenceRuns": [ @@ -1274,6 +1284,15 @@ "result": "passed", "durationSeconds": 1.5, "summary": "1 test file(s) passed, 209 tests passed on main@1282f5c2d in a clean checkout." + }, + { + "date": "2026-07-10", + "runner": "local", + "platform": "macos", + "command": "pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime-path-candidate-history.test.ts", + "result": "passed", + "durationSeconds": 3.49, + "summary": "1 test file passed, 2 tests passed on the exact rebased tree based on main@dc468f0ded." } ], "runtimeBudget": { @@ -1286,11 +1305,11 @@ }, "redGreenEvidence": { "status": "partial", - "evidence": "Tests assert daemon stream writes pause after socket write(false), later stream data queues behind the pressured socket, flush-immediate output from another session is prioritized ahead of unrelated queued background backlog on drain while preserving per-session order, queued lines resume on drain, global cleanup clears clients that only have backpressured writes, queued daemon stream bytes are bounded by keeping priority output and the newest tail under sustained pressure, main pending renderer output is capped per PTY and in total, total-pressure trimming prefers background pending output before active pending output, trimmed pending tails preserve seq/rawLength metadata, and ACK-gated in-flight output remains bounded. Existing renderer tests cover replay/backlog slices. Needs intentional-break proof and broader hidden-output/input-latency perf artifacts before promotion." + "evidence": "Tests assert daemon stream writes pause after socket write(false), later stream data queues behind the pressured socket, flush-immediate output from another session is prioritized ahead of unrelated queued background backlog on drain while preserving per-session order, queued lines resume on drain, global cleanup clears clients that only have backpressured writes, queued daemon stream bytes are bounded by keeping priority output and the newest tail under sustained pressure, pathless runtime output reuses unchanged path-provenance history with zero old-candidate byte scans, main pending renderer output is capped per PTY and in total, total-pressure trimming prefers background pending output before active pending output, trimmed pending tails preserve seq/rawLength metadata, and ACK-gated in-flight output remains bounded. Intentionally restoring the old path-history shape failed the focused scale test after 774ms and 4,096 replacements; the fixed shape passed in 6ms. Existing renderer tests cover replay/backlog slices. Needs broader hidden-output/input-latency perf artifacts before promotion." }, "performanceBudget": { "required": true, - "evidence": "Suggested ceilings: renderer in-flight <=8MB total, <=512KB per PTY plus active reserve, renderer queued chars <=2MB, dropped backlogs 0, hidden restore <=1000ms, active key median/worst <=75ms/300ms in perf scenarios." + "evidence": "Suggested ceilings: renderer in-flight <=8MB total, <=512KB per PTY plus active reserve, renderer queued chars <=2MB, dropped backlogs 0, hidden restore <=1000ms, active key median/worst <=75ms/300ms in perf scenarios. With 1,024 retained provenance candidates, 4,096 pathless chunks dropped from 78.84ms and 4,096 array replacements to 1.74ms and zero replacements." }, "promotionCriteria": [ "Split daemon stream backpressure into a deterministic provider/IPC contract if full E2E is flaky.", @@ -1299,6 +1318,7 @@ ], "knownGaps": [ "Current command asserts daemon stream write(false)/drain/cleanup at the batcher contract layer and main pending renderer caps at the IPC contract layer.", + "Runtime provenance coverage is deterministic and does not include a live high-throughput provider artifact.", "Current command does not prove renderer parse pressure, scheduler queue depth, event-loop delay, or active key latency.", "Live hidden-output pressure, active input latency, and full Electron perf artifacts remain unproved." ], diff --git a/src/main/runtime/orca-runtime-path-candidate-history.test.ts b/src/main/runtime/orca-runtime-path-candidate-history.test.ts new file mode 100644 index 000000000..80b09ed81 --- /dev/null +++ b/src/main/runtime/orca-runtime-path-candidate-history.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it, vi } from 'vitest' +import { appendRecentPtyPathCandidates } from './orca-runtime' + +function fullCandidateHistory(): string[] { + return Array.from( + { length: 1024 }, + (_, index) => `/tmp/artifact-${index.toString().padStart(4, '0')}.json` + ) +} + +describe('PTY path candidate history', () => { + it('reuses path-candidate history across repeated pathless PTY output', () => { + const previous = fullCandidateHistory() + const byteLengthSpy = vi.spyOn(Buffer, 'byteLength') + let candidates = previous + let replacements = 0 + let byteLengthCalls = 0 + try { + for (let index = 0; index < 4096; index += 1) { + const next = appendRecentPtyPathCandidates( + candidates, + 'ordinary compiler progress without a path\n' + ) + if (next !== candidates) { + replacements += 1 + } + candidates = next + } + } finally { + byteLengthCalls = byteLengthSpy.mock.calls.length + byteLengthSpy.mockRestore() + } + + expect(candidates).toBe(previous) + expect(replacements).toBe(0) + expect(byteLengthCalls).toBe(0) + }) + + it('copies history when new output adds a path candidate', () => { + const previous = fullCandidateHistory() + const changed = appendRecentPtyPathCandidates(previous, 'wrote /tmp/new-artifact.json\n') + + expect(changed).not.toBe(previous) + expect(changed).toContain('/tmp/new-artifact.json') + expect(previous).not.toContain('/tmp/new-artifact.json') + }) +}) diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index b7e4c1d2c..ddeb56f9a 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -24208,8 +24208,14 @@ export function appendRecentPtyPathCandidates( previous: string[] | undefined, data: string ): string[] { + const extractedCandidates = extractTerminalOutputPathCandidates(data) + if (extractedCandidates.length === 0) { + // Why: pathless output is the common hot path. Reuse immutable history so + // each PTY chunk does not clone and byte-scan up to 1,024 old candidates. + return previous ?? [] + } const next = previous ? previous.slice() : [] - for (const candidate of extractTerminalOutputPathCandidates(data)) { + for (const candidate of extractedCandidates) { if (Buffer.byteLength(candidate, 'utf8') > RECENT_PTY_PATH_CANDIDATE_MAX_BYTES) { continue }