Skip to content

fix(orcad): keep terminal models at the daemon's live depth and bound provider snapshot waits - #35679

Merged
nwparker merged 5 commits into
mainfrom
fix/orcad-pty-memory-cap
Oct 29, 2026
Merged

nwparker merged 5 commits into
mainfrom
fix/orcad-pty-memory-cap

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​118 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​118
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65

ELI5

orcad, the Orca server that runs on remote hosts, keeps its own in-memory copy of every terminal. That copy held 5x more history than the terminal daemon it mirrors. Nothing on a server ever reads that extra history, so it was wasted memory on every terminal. Separately, one step waited on the daemon with no time limit. While it waited, every byte of new output piled up behind it in memory.

What Changed

  • History depth. orcad's per-terminal copy now keeps the same number of rows as the daemon's live window: 1,000 instead of 5,000. Both read that number from the daemon's existing resolver, so they can't drift apart. Desktop keeps 5,000, because a hidden desktop pane is repainted from that copy when you reveal it.
    • Clients that ask for more history still get it from the daemon first: requested and recovery snapshots already read the provider before falling back.
    • Phone and desktop subscribe snapshots already read at most 1,000 rows.
  • Bounded snapshot wait. serializeProviderTerminalBuffer now applies the authoritative snapshot timeout (8s) to every caller that doesn't pass its own. Before, those callers waited only on the daemon client's 30s request timeout, plus a 5s durable-history deadline. The timeout lives in that one function, so every caller gets it. The new awaitProviderTerminalBuffer also reports the capture that is still running when the wait gives up.
  • Execution-context reseed. This path rebuilds a terminal's copy from the daemon, for example after a WSL distro correction. It used to wait on that snapshot with no bound, so live output queued behind it. Now:
    • It is bounded by the timeout above.
    • If the snapshot times out, the copy stays marked "prefer the provider", so readers never trust a partial copy.
    • When the late snapshot arrives, the copy reseeds once from a fresh capture.
    • If the provider returns nothing, the copy is trusted again.
    • If that one retry also fails, the terminal stays on the provider until a generation change or exit. This is deliberate: reads stay correct and each one is bounded at 8s.

No wire or protocol changes. Mixed client and server versions are unaffected.

Why

orcad runs on remote hosts and holds one copy per terminal, so 5,000 rows each grows quickly with many terminals. This is part of the #34410 / #33870 investigation into orcad freezing under memory pressure.

Alternatives considered:

  • Drop orcad's copy entirely. Not possible. Agent-status observers, tui-idle and screen-rule reads, hidden-PTY query replies, and shell-ownership tracking all need an in-process model that is read synchronously and updated in byte order.
  • Screen-only copy, with all history read from the daemon. Rejected. Daemons outlive orcad upgrades, and an older daemon that can't snapshot would leave subscribers with no history.
  • A byte cap on queued output plus reseed. Rejected as fallback machinery. The real cause was the unbounded wait, which this PR fixes.

Measured with a scripted 50-terminal flood in vitest, origin/main vs this branch:

  • 50 terminals x 6,000 lines of output: retained heap went from 129.1 MiB to 51.2 MiB.

Refs #34410
Refs #33870

Thanks to @tux86 and @taichimori-netizen for the reports.

Linked Issue

Refs #34410, Refs #33870. This PR is part of the fix for each; it does not close them.

Visual Proof

N/A. This changes no UI: it lowers server-side memory and bounds an internal wait.

Testing

  • Automated tests added. src/main/runtime/headless-terminal-memory-bound.test.ts covers:

    • the configured depth is honored;
    • a hung provider snapshot releases queued live output, then reseeds once it lands;
    • a late "no snapshot" trusts the live copy;
    • a failed retry keeps preferring the provider;
    • every reader of a hung provider is bounded.

    Each test fails on the base, either by assertion or by hanging until the test timeout.

  • Full static job passes locally.

  • Unit tests selected by import graph (src/main) pass. The only failures also fail on the base commit: real-git, filesystem-watcher, packaged-CLI, orcad forked-child, and timing-sensitive tests.

  • Managed-orcad Docker specs: 9 passed, 1 skipped (ssh-orcad-terminal-journeys, -terminal-network-outage, -terminal-reconnect-idle-frame, -terminal-root-owner, -terminal-browser-link, -relay-tab-only-shell; -phone-feed-list skips outside an ORCA_SIDEBAR_INPUTS=main build), with a locally built linux-arm64 orcad template. The full 40-spec lane runs in CI.

  • Platforms: macOS host with a Linux (arm64) Docker SSH host.

Review

Independent Codex and Opus reviews on the final head report no P0–P2 findings.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Cross-platform. One known limit: a native Windows orcad that reads more than about 1,000 lines through ConPTY terminal read now gets about 1,000 plus a screen. The daemon's live window is the same size.
  • Degraded orcad without a daemon also keeps 1,000 rows.
  • SSH, remote, and mobile: no wire changes.
  • Desktop: unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f394a01-da0b-4ea1-adbc-5a49df48b577
Commits

Reviewing files that changed from the base of the PR and between 502413d and bcabc53.

Files selected for processing: 11
  • src/main/orcad/orcad-entry.ts
  • src/main/runtime/construction/runtime-composition-parity.test.ts
  • src/main/runtime/construction/runtime-construction-dependencies.ts
  • src/main/runtime/construction/runtime-construction.ts
  • src/main/runtime/headless-hydration-ownership-test-fixture.ts
  • src/main/runtime/headless-terminal-memory-bound.test.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/terminal/output/headless-terminal-hydration.ts
  • src/main/runtime/terminal/output/headless-terminal-state.ts
  • src/main/runtime/terminal/output/terminal-buffer-operations.ts
  • src/main/runtime/terminal/output/terminal-buffer-selection.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

orcad's per-PTY headless terminal model kept 5,000 rows of scrollback, but
orcad has no renderer to reveal from: requested snapshots read the daemon
first and subscribe snapshots read at most 1,000 rows. The model now
mirrors the daemon's live window, from the same resolver the daemon uses.

The execution-context reseed also awaited its provider snapshot with no
bound, so a provider that never answered held every live chunk queued
behind it. It now uses the authoritative snapshot timeout.

Refs #34410
Refs #33870
serializeProviderTerminalBuffer now applies the authoritative snapshot
timeout when a caller passes none, so no reader can wait on a provider that
never answers. The execution-context reseed relies on that bound; when its
capture times out it keeps the PTY provider-preferred and reseeds again once
the capture lands, instead of staying on the provider path.

Refs #34410
Refs #33870
…odel on none

awaitProviderTerminalBuffer reports the capture still running when the
bounded wait gives up, instead of callers inferring it from the acquisition
map. The execution-context reseed retries once when that capture lands with
a snapshot, and stops preferring the provider when it lands with none, so a
slow provider can neither loop reseeds nor pin the PTY to the provider path.

Refs #34410
Refs #33870
The once-only retry disposes a model that had parsed the live bytes since
the timeout. If its own capture then fails, the replacement holds less than
its predecessor, so the PTY keeps preferring the provider instead of
treating that model as complete.

Refs #34410
Refs #33870
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect terminal history and provider snapshot reads across runtime workflows.

The PR still needs a fix before merging because reconnects can receive a partial terminal screen after a reseed times out.

Findings

  1. P1 Reconnect restores a partial screen ▶

Summary

This PR lowers orcad’s terminal history depth and bounds waits for provider snapshots.

  • Orcad keeps terminal history at the daemon’s live depth.
  • Provider snapshot readers stop waiting after eight seconds by default.
  • Terminal reseeds recover when provider snapshots arrive late.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Replace terminal model] --> B[Wait for provider snapshot]
  B -->|Snapshot arrives| C[Seed model]
  B -->|Wait times out| D[Release queued output and prefer provider]
  D --> E{Late capture result}
  E -->|No snapshot| F[Trust live model]
  E -->|Snapshot arrives| G[Try one fresh capture]
  G -->|Seed succeeds| C
  G -->|Capture fails or times out| H[Keep preferring provider]
Loading

Reviews (2) · Last reviewed commit: "fix(runtime): never trust a late-reseed ..." · Reviewed by Greptile

Comment on lines +137 to +138
if (!snapshot) {
seedTimedOut = late !== null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Reconnect restores a partial screen

After an execution-context reseed times out, queued output now runs on an empty model. Keeping providerSnapshotPreferredPtys set does not stop snapshot readers from using it: serializeTerminalBufferFromAvailableState falls through to serializeHeadlessTerminalBuffer when the provider times out and no renderer answers.

On orcad, a reconnect can therefore receive a partial screen and missing history. Cursor-relative output can also appear in the wrong place because the model never received the earlier screen. Keep releasing queued writes, but prevent snapshot readers from returning this unseeded model until a seed succeeds or the provider confirms there is no snapshot.

Knowledge Base Used: Terminal runtime and interaction

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@nwparker
nwparker force-pushed the fix/orcad-pty-memory-cap branch from b698eab to bcabc53 Compare October 29, 2026 04:51
@nwparker
nwparker merged commit e22e976 into main Oct 29, 2026
62 checks passed
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