Skip to content

perf(runtime): skip full wait scans for ordinary PTY output - #8113

Closed
nwparker wants to merge 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-18
Closed

nwparker wants to merge 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-18

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

OrcaRuntimeService.onPtyData maintains a retained terminal tail (up to 2,000 lines / 256 KB) so terminal.wait can recognize Codex trust, migration, hook-review, and other blocked prompts. The prior memoization removed one of two scans, but every raw PTY chunk still rebuilt the full tail with map/trim/filter/join, lowercased it, and searched every prompt pattern.

This change gives anchor-free tails a compact state:

  • A cold/authoritative scan proves that none of the blocked-prompt anchors are present.
  • The state keeps only a 1 KB raw suffix, enough to recognize an anchor split across PTY chunks.
  • Ordinary append-only output advances that null-signal state from the suffix plus the new chunk.
  • Any prompt anchor, partial/split anchor, CR/backspace/ANSI redraw, preview-backed prompt, or prompt-bearing tail falls back to the existing authoritative full scan.

The fallback detection logic itself is unchanged. The focused tests enumerate all six blocked reasons and cover split prompts, ready-after-blocked ordering, redraws, transcript pruning, and eviction beyond the 2,000-line cap.

Performance evidence

Isolated steady-state Vitest benchmark through the real exported wait-state functions on arm64 macOS 26.3.1, Node 24.18.0:

  1. Build a 2,000-line retained build log (236,889 characters, near the production tail ceiling).
  2. Seed its current wait state once, as a live terminal already would have done while accumulating the tail.
  3. Process 1,000 ordinary progress N% chunks.
  4. Run seven timed samples and compare medians.

Before used computeTerminalTailWaitState per chunk, matching the old onPtyData path. After used advanceTerminalTailWaitState per chunk, matching the new path.

Version Seven samples (ms) Median Per chunk
Before 982.91, 984.32, 986.78, 987.15, 994.48, 996.16, 997.11 987.15 ms 0.987 ms
After 2.33, 2.38, 2.39, 2.40, 2.41, 2.42, 2.51 2.40 ms 0.0024 ms

That is a 99.76% reduction / 411.7x speedup for ordinary chunks with a long retained tail. The cached anchor-free state also shrinks from a 236,889-character duplicate wait string in this workload to a suffix capped at 1,024 characters.

This is an isolated main-process helper benchmark, not an end-to-end typing-latency claim. Its hot-path relevance is direct: these functions run synchronously inside onPtyData, potentially hundreds of times per second under terminal output load.

Verification:

  • Runtime + wait-state + transcript-prune tests: 611 passed.
  • Full suite: 26,468 passed, 33 skipped.
  • Full node/CLI/web typecheck passed.
  • Targeted Oxlint and formatting passed.
  • Max-lines ratchet passed with no new bypasses.

ELI5

Orca watches terminal history for a handful of “the agent needs you” messages. It used to reread a whole book every time one new progress line arrived. Once Orca has proved the book contains none of those messages, it now checks only the last page plus the new line. If the new text starts looking like a real prompt—or rewrites old terminal text—Orca rereads the authoritative history.

End-user trade-offs / regressions

  • No intended prompt-detection change: all six blocked reasons, split anchors, ready overrides, redraws, pruning, and tail eviction retain regression coverage.
  • Prompt-bearing or cursor-redrawn output still pays the existing full-scan cost for correctness; the optimization targets the common anchor-free append-only stream.
  • The compact state stores a 1 KB suffix instead of a duplicate full wait string only when its signal is guaranteed null. That string is internal and never crosses an RPC boundary.
  • Adding a future blocked-prompt pattern also requires adding an anchor to the fast-path pattern; the focused all-reasons tests make a mismatch visible.
  • No platform, SSH/runtime-host, mobile protocol, or git-provider behavior changes.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7121566c-ca9b-4b51-b5cc-bbb42b57c326

📥 Commits

Reviewing files that changed from the base of the PR and between c5669cc and 0a620b1.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime-tail-wait-memo.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/terminal-tail-wait-state.ts

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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Closing: superseded by the sentinel-index gating in terminal-wait-tail-state.ts, which already skips full-tail wait scans for output that can't hold a prompt.

@nwparker nwparker closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant