Skip to content

perf(terminal): let main's model rest for agents that read no screen - #27185

Closed
outof-place wants to merge 12 commits into
stablyai:mainfrom
outof-place:perf/agent-model-dormancy
Closed

outof-place wants to merge 12 commits into
stablyai:mainfrom
outof-place:perf/agent-model-dormancy

Conversation

@outof-place

@outof-place outof-place commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca's main process keeps its own copy of every terminal's screen. #27086 and #27123 let main drop that copy for plain terminals when nothing needs it, and rebuild it from the terminal daemon when something does. Agent panes were left out, because some agents' readiness checks read main's copy of the screen. This PR lets main drop the copy for the agents whose checks never read it, Claude Code among them. Background agents produce most of the terminal output, so that is where the saving is.

What Changed

Before: main parsed every byte of every agent pane, visible or hidden, even when no reader needed its screen.

After: an agent pane is treated like a plain terminal unless its agent reads main's screen. These agents still keep main's model, as today:

  • agents whose readiness rules read the screen: Codex, Cline, Antigravity, Prime Agent, and unidentified panes that report agent status (the unknown-pane rules read the screen);
  • Qoder, whose composer readiness is a screen read outside its rules;
  • OMP, whose screen can veto input;
  • Freebuff, whose status is read from main's screen on every chunk.

Every other agent (Claude Code, Gemini, OpenCode and the rest) gets its readiness from hooks, titles and the text tail, which main keeps without its model. The rule reads the agent's rule files, so a rule that starts reading the screen keeps its agent live without a change here.

Two readers could still read an agent's screen and treated a missing model as an empty screen. Both now wait for the rebuilt model instead:

  • The tui-idle poll's dialog check. Claude Code's workspace-trust dialog parks the cursor above its options, so only the screen shows them. With the model gone, the read returned nothing, and a weak-ready wait could settle on the trust dialog. The poll now asks for the model first, and the read waits for the daemon seed.
  • A fresh worker's composer check before Orca pastes its brief. A dialog painted before the model went dormant is only on the screen. The check now awaits the rebuilt model before deciding.

Freebuff identification also takes the foreground agent, so a model rebuilt after dormancy still recognizes a Freebuff started by hand, after the title that identified it has passed.

For a hidden agent pane, #27123's daemon delegation now applies too: the daemon answers the pane's terminal queries and main's model rests.

Why

Most of the terminal bytes in an agent-heavy workspace come from hidden agent panes. Main parsed all of them, synchronously on the main thread, for a screen nothing read.

Alternatives considered:

  • Make every screen reader asynchronous, so any agent could rest. Agent readiness runs in many synchronous places (title transitions, delivery checks, graph sync), and the agents whose rules read the screen would need a rebuild on almost every check. Keeping those agents live is simpler and costs nothing for the rest.
  • Pin the model during waits instead of awaiting it at the two readers. A pin taken when a wait starts still leaves the first read racing the rebuild. Awaiting the model at the read closes that.

Stacked on #27123

This branch sits on #27123 (the daemon answers hidden queries), which sits on #27086 and #27129. The diff here includes their commits until they land.

Linked Issue

Part of #27023 (phase 2b: agent panes)

Visual Proof

N/A: no UI or behavior change. Agent readiness, dialogs and query replies stay the same, which the tests below check.

Testing

  • Captured transcript: Claude Code's workspace-trust dialog, replayed into a pane whose main model then went dormant. A tui-idle wait must still report the dialog. Without the poll fix the wait times out instead.

  • Per agent: after 5 s of quiet, main's model rests for Claude Code, Gemini and OpenCode panes, and stays live for Codex, Cline, Antigravity, Qoder, OMP and Freebuff. The rest cases fail on the previous rule.

  • Settled screen read: for a dormant Claude pane, the synchronous read reports no screen while the model is rebuilt, and the settled read returns the rebuilt screen with its dialog text.

  • In-app A/B: headless E2E on minified builds; nobody used the app by hand. A stand-in Claude Code process (a small compiled launcher whose foreground process reads as claude, running a shell script as its child) cats 16 MiB of agent-TUI frames into a hidden pane. Main's process.cpuUsage() is recorded until main goes quiet; the daemon's CPU time and RSS come from ps; main's heap is read after a forced GC. Runs alternated between a build of perf(terminal): let the daemon answer hidden local terminals' queries #27123's head and a build of this branch, n=10 each, with host load between 5 and 12 on 16 cores (medians, p25–p75):

    Hidden Claude pane perf(terminal): let the daemon answer hidden local terminals' queries #27123 This PR Change
    Main CPU 44.9 ms/MB (44.3–45.2) 33.2 ms/MB (32.5–33.7) −11.7 ms/MB (−26%)
    Daemon CPU 36.9 ms/MB (36.2–36.9) 35.6 ms/MB (35.6–36.2) −1.3 ms/MB
    Daemon RSS after the flood 190.4 MiB (188.7–192.1) 129.9 MiB (129.6–130.2) −60.5 MiB
    Main RSS after the flood 443.6 MiB (442.4–446.8) 420.5 MiB (419.1–420.7) −23.1 MiB
    Main heap after GC 49.3 MiB (49.1–49.6) 48.3 MiB (48.3–48.3) −1.0 MiB

    The delivery debug snapshot showed the daemon answering the pane's queries in every run of this branch and in none of perf(terminal): let the daemon answer hidden local terminals' queries #27123's. Before this PR, an agent pane kept main as its responder. An earlier batch of the same A/B, without the daemon and memory sampling, gave main CPU 46.9 → 32.5 ms/MB (−31%).

  • No committed agent-pane E2E. A headless E2E can mark a tab as a Claude launch through the renderer store (queueTabStartupCommand with launchAgent, also with a launch token or launch config), but that path never gives main's PTY record a launchAgent: such a test passed on perf(terminal): let the daemon answer hidden local terminals' queries #27123's build too, so it proved nothing and was dropped. The runtime tests above register the launch identity the way a real launch does, and the in-app A/B uses the foreground-process path.

  • Unit suites for src/main/runtime, src/main/ipc and src/shared: 29,792 pass (pnpm test src/main/runtime src/main/ipc src/shared). The 2 failures in run-terminal-shell-alone.node-pty.test.ts fail the same way on the base commit in this environment. Four built-CLI subprocess tests failed against a stale out/cli from another branch and pass against this branch's build.

  • pnpm tc and the changed-code quality gate (ORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changed) pass. The full pnpm test, pnpm lint and pnpm build were left to CI.

  • I manually tested these changes locally (not done: only the headless E2E runs and tests listed above ran)

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implemented with Claude Opus 5.5 via Claude Code: design, code, tests and measurements. A human (outof-place) directed the work.

Review

Suggested reading order:

  1. main-terminal-model-agent-rest.ts, the per-agent rule.
  2. canMainTerminalModelRest in orca-runtime-main-terminal-model-dormancy.ts.
  3. The two readers: readVisibleScreen in orca-runtime-runtime-id.ts and the composer accept in orca-runtime-activate-managed-worktree.ts.

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.

Trade-offs

  • Merge risk. This changes which agent panes keep main's model. A wrong rule would let a reader see no screen for an agent that needs one, and misjudge its readiness: settle a wait too early, or paste into a dialog. Mitigations:
    • the rule reads the agents' own rule files (any rule on the screen region keeps the agent live), plus an explicit list for the screen readers outside the rules (Qoder's composer, OMP's input veto, Freebuff's status);
    • per-agent tests for both outcomes, which fail on the previous rule;
    • the two readers that still read an agent's screen now wait for the rebuilt model, tested with a captured Claude Code trust-dialog transcript;
    • kill switches: terminalMainModelDormancy: false keeps every pane's model live, as before perf(terminal): let main skip parsing visible local daemon terminals #27086; terminalDaemonQueryAuthority: false keeps main as the responder.
  • CPU. Main −26% for a hidden Claude pane in the app (table above). Daemon CPU is flat (−1.3 ms/MB): it parses every byte with or without this PR, and answering a pane's queries is small next to that. Each wake costs one daemon snapshot and one seed write, measured in a micro-benchmark at about 3 ms and 1.5 ms of CPU for a 1,000-row seed of 70–108 K characters, plus the local socket round trip.
  • Memory. A resting agent pane frees main's model. A full model (120 columns, 5,000 rows of scrollback) holds 8.4–8.9 MiB; a model rebuilt from the 1,000-row seed holds 0.4–1.0 MiB (micro-benchmark with --expose-gc, heap plus array buffers). In the app, one hidden flood left main's RSS 23 MiB lower. The daemon's RSS was also 60 MiB lower after the flood; a likely reason is that the daemon buffers less output while main keeps up, and RSS is a high-water mark. The daemon holds no new state per pane beyond the responder flag.
  • Latency. The first screen read after a rest waits for the rebuild: the snapshot request, the seed write, and live chunks past the seed. The two readers that need the screen await it; other readers of agent panes read no screen. The rebuild gives up after 2 s and falls back to main's partial model.
  • Disk. None.
  • Maintenance. +85/−13 lines in eight source files, +147 lines of tests, plus a 30-line daemon-model test fixture and a 10-line harness option. New concepts: the per-agent rest rule driven by rule regions, and the settled screen read. A new agent that reads main's screen outside its rule file must be added to the list in main-terminal-model-agent-rest.ts; the per-agent tests sit next to it.
  • Verdict: substantial: about a quarter of main's CPU for hidden agent output, where most terminal bytes are, and several MiB of main memory per resting pane. The costs are a rebuild of a few milliseconds on the next screen read and a list to keep current.

Notes

  • SSH and remote. Unchanged: SSH and relay panes keep main's model, as in perf(terminal): let main skip parsing visible local daemon terminals #27086.
  • Kill switches. terminalMainModelDormancy and terminalDaemonQueryAuthority cover agent panes too.
  • Hot-reloaded rules. The rule is read on every chunk, so an agent whose new rules read the screen wakes main's model on its next output.

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)

🤖 Generated with Claude Code

outof-place and others added 10 commits October 10, 2026 01:40
…renderers can't pace agents

A hidden pane whose PTY a raw-byte sidecar watches (background-launched and
automation agents) kept the hidden-delivery gate off for the whole PTY, so
its hidden xterm parsed every byte and main paced the producer to that
parse. The parse runs on renderer timers, which Chromium throttles for
hidden pages (one wake-up a minute after ~5 minutes), so a flooding agent
slowed to tens of KB/s and blocked on its own writes.

Delivery interest now only decides who receives the bytes, not whether the
view is gated. For a hidden PTY with interest, main sends chunks flagged
sidecarOnly. The renderer hands them to sidecars only and credits them on
receipt. The view skips them like a gated drop and restores from the model
on reveal, and main answers the PTY's terminal queries meanwhile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…flip

Main decides who answers a terminal query when it ingests the chunk: the
pane's view while the view parses, main's model while the view is gated.
Delivery decided again at send time, so a flip while the chunk was still
queued broke that:

- Queued while visible, then hidden before the flush: the gate dropped the
  bytes (or sent them to sidecars only), the view never parsed them, and
  main had not answered. The program waited for a reply that never came.
- Queued while gated, then revealed before the flush: main had answered,
  and the now-visible view parsed the bytes and answered again.

Each pending entry now carries the gate state it was ingested under, and
an entry never mixes states. Bytes the view was to answer but will skip
have their queries handed to the view the way a pending-cap drop already
does. Bytes ingested gated go to sidecars only even after a reveal, and
the view restores from main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rendererPtyViewDelivery now owns how main delivers a PTY's bytes to the
renderer ('parse', 'sidecarsOnly' or 'drop'). The drop and sidecar-only
predicates and the query responder read it, and every pending entry
records the mode it was ingested under instead of a gated bit. Main's
model owns the replies of any mode other than 'parse', so a later mode
such as parse-once's native-view skip slots into the same function and
the same stamp without another ownership rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The e2e holds the renderer's delivery credit while it fills main's window.
Under heavy load the old 8 KB pacing could stretch the hold past main's
10 s ack-silence heal, which writes the window off and drains the queue
the test needs. The filler now writes 16 KB per tick, still far below
the queue size at which main pauses the PTY, and the probe writes its
reply counts atomically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main fed every PTY byte into its own HeadlessEmulator, even for a visible
pane whose renderer and daemon already parse the same bytes. For a visible
local daemon terminal with no viewer, agent or gate drop, main now drops
that emulator after 5 s without demand. A hide, a viewer, a screen read or
a snapshot rebuilds it from the daemon's settled snapshot (protocol v36+),
skipping live bytes the snapshot covers. The hidden-delivery gate stays
open until the rebuilt model catches up, so main never owes a query reply
for a byte it skipped. Restores of such terminals read the daemon at full
depth.

Phase 1 of #27023. Kill switch: terminalMainModelDormancy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An in-process consumer that reads main's emulator, or relies on main
answering a PTY's queries, can now hold the model live with
acquireTerminalOutputReader(ptyId, { kind: 'model' }) and release it when
done. A pin holds across a PTY respawn and releasing it restarts the
dormancy grace period. The reader kind leaves room for a later bytes-only
reader that does not need main's emulator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main hands a chunk to the view only when the view answers its queries; main
answers none of them. The renderer still discarded such bytes without
replies in several places:
- a hidden view with a restore latched;
- backlog bytes a restored snapshot already covers, fully or in part, both
  on arrival and in the restore queue's drain;
- a seq gap that forces a fresh restore;
- an unmappable hidden filter;
- unparsed writes a snapshot apply or a backlog cap discards.

A program that sent CPR or DA there waited forever. This mostly hits the
dormancy handoff, where a hidden view answers until main's rebuilt model
catches up, and the reveal restore after it. Every discard path now
salvages the bytes' queries, the way the pending-cap and restore-queue
overflow drops already do. As there, CPR reports the cursor where the view
is, which keeps the program alive rather than being exact.

The E2E test runs rounds of CPR, DA1 and DSR 5n across hiding and revealing
a dormant pane, quiet and with output in flight. It checks for exactly one
reply each, with the right cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
which keeps that model parsing every hidden pane. A v45 daemon now answers
them instead: main delegates with setSessionQueryResponder, the daemon
flags its emulator writes and queues an in-order sessionQueryResponderMarker
on the client stream, and main flips the delivery gate only at that marker.

resolveTerminalQueryResponder picks exactly one of view, main or daemon per
live chunk. Until the daemon confirms, main's live model keeps answering (the
view does only when main's model is already dormant); after a take-back the
view stays gated, and its reveal restore is deferred, until the daemon's
false marker. Main takes the role back (and wakes its model) for agents,
remote viewers, model readers, the kill switch, unconfirmed requests and
daemon reattaches. Main pushes the renderer's view attributes so OSC 4/12,
?996n and cursor replies match. Old daemons, degraded routes, SSH, relay
and agent panes keep main as the responder. Kill switch:
terminalDaemonQueryAuthority.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… caught up

When a hidden, delegated PTY stops qualifying (an agent starts, a reader
registers, the kill switch flips), main takes its queries back. If main's
model was dormant, the take-back used to land before the rebuilt model had
caught up. The hidden view then had to answer in between, and a view with a
latched restore does not parse.

Main now wakes its model first and sends the take-back only once that model
has caught up. The daemon keeps answering until then, so main answers from
an exact model the moment the daemon lets go. A remote viewer still takes
over at once, since main will not answer for it.

The handoff E2E now runs with the daemon answering and with main answering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0326cce-e418-4e47-b3fc-1d6e38bcfbdd

📥 Commits

Reviewing files that changed from the base of the PR and between 2a3d70a0c83aa9013683a231d49e1d81e627c93d and ee5a177.


📒 Files selected for processing (2)
  • src/shared/local-build-compatibility-contract.json
  • src/shared/local-build-compatibility-contract.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

The daemon protocol now supports settled buffer snapshots and terminal-query responder delegation. The runtime can make eligible main terminal models dormant and rebuild them from provider snapshots. IPC tracks query ownership and routes hidden output to the view, sidecars, or drop handling. Renderer changes preserve terminal queries in discarded output and support sidecar-only delivery. The changes add unit and end-to-end tests for these paths.


Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to ee5a1

The protocol version update is consistent, but daemon reattachment can leave hidden terminal queries unanswered, and repeated backlog drops can lose query bytes. These remaining failure paths should be fixed or explicitly accepted before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 51 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: allowing main’s terminal model to rest for agents that do not read the screen.
Description check Passed The description is complete and well structured. It covers the user impact, implementation, rationale, linked issue, visual proof, testing, AI disclosure, trade-offs, compatibility considerations, and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 36.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 51 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
  • 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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6651e2cb-79be-469f-af11-3cd8bc80452c
📥 Commits

Reviewing files that changed from the base of the PR and between f4c4eae and 2a3d70a0c83aa9013683a231d49e1d81e627c93d.

📒 Files selected for processing (103)
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter-protocol-compatibility.test.ts
  • src/main/daemon/daemon-pty-adapter-query-responder.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-connection-lifecycle.ts
  • src/main/daemon/daemon-pty-owner-query-protocol.ts
  • src/main/daemon/daemon-pty-router-test-fixture.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-pty-runtime-state.ts
  • src/main/daemon/daemon-query-responder-routing.test.ts
  • src/main/daemon/daemon-request-router.ts
  • src/main/daemon/daemon-session-background-routing.ts
  • src/main/daemon/daemon-stream-events.ts
  • src/main/daemon/daemon-view-attributes.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/headless-emulator.ts
  • src/main/daemon/session-output-pipeline.ts
  • src/main/daemon/session-output-plane.ts
  • src/main/daemon/session-query-responder.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-session-inspection-operations.ts
  • src/main/daemon/terminal-host.ts
  • src/main/daemon/types.ts
  • src/main/ipc/pty-buffer-snapshot-dispatch.test.ts
  • src/main/ipc/pty-hidden-delivery-gate.test.ts
  • src/main/ipc/pty-hidden-delivery-gate.ts
  • src/main/ipc/pty-ipc-daemon-query-responder.test.ts
  • src/main/ipc/pty-ipc-hidden-delivery-flip-replies.test.ts
  • src/main/ipc/pty-ipc-hidden-delivery-gate.test.ts
  • src/main/ipc/pty-ipc-provider-fixtures.ts
  • src/main/ipc/pty-pending-data-drain-contract.ts
  • src/main/ipc/pty/delivery/accept.ts
  • src/main/ipc/pty/delivery/debug.ts
  • src/main/ipc/pty/delivery/exit.ts
  • src/main/ipc/pty/delivery/flush.ts
  • src/main/ipc/pty/delivery/payload.ts
  • src/main/ipc/pty/delivery/pending-delivery-stamp.ts
  • src/main/ipc/pty/delivery/pending.ts
  • src/main/ipc/pty/delivery/wire-session.ts
  • src/main/ipc/pty/ipc/resize-visibility.ts
  • src/main/ipc/pty/ipc/snapshot.ts
  • src/main/ipc/pty/ipc/terminal-view-attributes-ipc.test.ts
  • src/main/ipc/pty/ipc/terminal-view-attributes-ipc.ts
  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/ipc/pty/provider/registry.ts
  • src/main/ipc/pty/runtime/controller.ts
  • src/main/ipc/pty/session.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/providers/pty-provider-events.ts
  • src/main/runtime/agent-state-rules/agent-state-rules-engine.ts
  • src/main/runtime/agent-transcript-pane-test-harness.ts
  • src/main/runtime/claude-trust-dialog-transcript.test.ts
  • src/main/runtime/daemon-query-responder-delegation.test.ts
  • src/main/runtime/daemon-query-responder-delegation.ts
  • src/main/runtime/fake-daemon-terminal-model.test-fixture.ts
  • src/main/runtime/main-terminal-model-agent-dormancy.test.ts
  • src/main/runtime/main-terminal-model-agent-rest.ts
  • src/main/runtime/main-terminal-model-dormancy.test.ts
  • src/main/runtime/main-terminal-model-dormancy.ts
  • src/main/runtime/orca-runtime-activate-managed-worktree.ts
  • src/main/runtime/orca-runtime-attach-remote-terminal-source-range-consumer.ts
  • src/main/runtime/orca-runtime-fit-override-listeners.ts
  • src/main/runtime/orca-runtime-main-terminal-model-dormancy.ts
  • src/main/runtime/orca-runtime-maybe-hydrate-headless-from-renderer.ts
  • src/main/runtime/orca-runtime-on-pty-data.ts
  • src/main/runtime/orca-runtime-on-pty-exit.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-serialize-headless-terminal-buffer.ts
  • src/main/runtime/orca-runtime-serialize-main-terminal-buffer.ts
  • src/main/runtime/orca-runtime-tests/main-terminal-model-dormancy.spec.ts
  • src/main/runtime/orca-runtime-verify-orchestration-compatibility-caller.ts
  • src/main/runtime/orca-runtime-visible-snapshot-preview.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/screen-input-veto.ts
  • src/main/runtime/terminal-model-query-authority.test.ts
  • src/main/runtime/terminal-model-query-authority.ts
  • src/main/runtime/terminal-query-responder.test.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-session-control.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hidden-backlog-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher-sidecar-only.test.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher.ts
  • src/renderer/src/components/terminal-pane/pty-sidecar-only-delivery.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler-discarded-queries.test.ts
  • src/renderer/src/web/preload-api/web-terminal-api.ts
  • src/shared/default-global-settings.ts
  • src/shared/global-settings-types.ts
  • tests/e2e/terminal-hidden-sidecar-pacing.spec.ts
  • tests/e2e/terminal-main-model-dormancy.spec.ts
  • tests/e2e/terminal-query-reply-visibility-flip.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines +115 to +116
// Why: a delegation outlives a quit main; the attaching one starts as responder and delegates again.
this.answersQueries = false

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C4 '\battachClient\s*\(' src/main/daemon
rg -nP -C3 'sessionQueryResponderMarker' src/main/daemon
rg -nP -C3 'releaseQueryResponderSessions|queryResponderSessionIds' src/main/daemon

Repository: stablyai/orca

Length of output: 30503


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- daemon-pty-connection-lifecycle.ts ---'
nl -ba src/main/daemon/daemon-pty-connection-lifecycle.ts | sed -n '1,125p'
printf '%s\n' '--- terminal-host-session-create.ts ---'
nl -ba src/main/daemon/terminal-host-session-create.ts | sed -n '1,220p'
printf '%s\n' '--- setSessionQueryResponder references ---'
rg -n -F -- 'setSessionQueryResponder' src/main/daemon src/main/ipc src/shared || test "$?" -eq 1
printf '%s\n' '--- create/attach session routing references ---'
rg -n -P -C4 'createOrAttach|createSession|attachClient|streamClient' src/main/daemon/daemon-pty-adapter.ts src/main/daemon/daemon-pty-connection-lifecycle.ts src/main/daemon/daemon-session-background-routing.ts src/main/daemon || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 45657


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- session-output-plane.ts ---'
nl -ba src/main/daemon/session-output-plane.ts | sed -n '1,205p'
printf '%s\n' '--- session.ts query delegation ---'
nl -ba src/main/daemon/session.ts | sed -n '175,225p'
printf '%s\n' '--- background routing ---'
nl -ba src/main/daemon/daemon-session-background-routing.ts | sed -n '1,115p'
printf '%s\n' '--- query responder tests ---'
nl -ba src/main/daemon/session-query-responder.test.ts | sed -n '1,240p'
printf '%s\n' '--- adapter responder tests ---'
nl -ba src/main/daemon/daemon-pty-adapter-query-responder.test.ts | sed -n '1,125p'

Repository: stablyai/orca

Length of output: 25696


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- adapter spawn/attach path ---'
rg -n -P -C8 'async spawn|spawn\(|createOrAttach|createSession' src/main/daemon/daemon-pty-adapter.ts src/main/daemon/daemon-pty-router.ts src/main/daemon/daemon-request-router.ts src/main/daemon/daemon-server.ts src/main/daemon/daemon-session-attachments.ts || test "$?" -eq 1
printf '%s\n' '--- adapter implementation block ---'
nl -ba src/main/daemon/daemon-pty-adapter.ts | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 10075


Emit a take-back marker when reattaching an existing session.

When createOrAttachTerminalSession reuses a live session, attachClient clears the daemon's answersQueries flag. The adapter still considers the session delegated because releaseQueryResponderSessions runs only for a fresh connection. If main still gates the hidden PTY, its model does not answer and the daemon no longer answers. Terminal queries can then time out.

Emit an in-order sessionQueryResponderMarker with responder: false for the affected session whenever an existing session is reattached. Clear the adapter's delegated-session tracking in the same transition. SessionOutputPlane.attachClient alone cannot emit this marker because it does not have the stream-routing context.

@@ -58,6 +59,7 @@ export function replaceBacklogWithWarning(
break
}
}
const droppedData = shouldNotify ? queuedTerminalOutputData(entry) : ''

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:

#!/bin/bash
rg -nP -C4 'backgroundBacklogDropped\s*=|replaceBacklogWithWarning\s*\(' src/renderer/src/lib/pane-manager

Repository: stablyai/orca

Length of output: 5955


🏁 Script executed:

set -e
printf '%s\n' '--- backlog helper ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts
printf '%s\n' '--- queue entry and callback references ---'
rg -n -F --glob '*.ts' -- 'onBackgroundBacklogDropped' src/renderer/src/lib/pane-manager src/renderer/src | head -80
printf '%s\n' '--- helper diff against merge base ---'
git diff -- src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts 9d94a20f84d10641f217b9539b0aefeff8d9b1ed 2a3d70a0c83aa9013683a231d49e1d81e627c93d

Repository: stablyai/orca

Length of output: 7613


🏁 Script executed:

set -e
printf '%s\n' '--- backlog helper ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts
printf '%s\n' '--- callback references ---'
rg -n -F --glob '*.ts' -- 'onBackgroundBacklogDropped' src/renderer/src/lib/pane-manager src/renderer/src | head -80
printf '%s\n' '--- helper diff against merge base ---'
git diff 9d94a20f84d10641f217b9539b0aefeff8d9b1ed 2a3d70a0c83aa9013683a231d49e1d81e627c93d -- src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts

Repository: stablyai/orca

Length of output: 8689


🏁 Script executed:

set -e
printf '%s\n' '--- callback consumer ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '90,125p'
printf '%s\n' '--- queued data helper and QueueEntry ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts | sed -n '1,95p'
rg -n -F --glob '*.ts' -- 'queuedTerminalOutputData' src/renderer/src/lib/pane-manager
printf '%s\n' '--- discarded-query test ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler-discarded-queries.test.ts | sed -n '1,110p'

Repository: stablyai/orca

Length of output: 10192


Preserve query bytes on every backlog drop.

backgroundBacklogDropped remains true after the first drop. A later overflow can therefore clear queued data without calling onBackgroundBacklogDropped, so query bytes in that data can miss the salvage path and leave the program waiting for a reply.

Suggested fix
-  const droppedData = shouldNotify ? queuedTerminalOutputData(entry) : ''
+  // Why always: every discard can carry queries the view still owes replies for.
+  const droppedData = queuedTerminalOutputData(entry)
 ...
-  if (shouldNotify) {
-    entry.onBackgroundBacklogDropped?.(droppedData)
-  }
+  entry.onBackgroundBacklogDropped?.(droppedData)

outof-place and others added 2 commits October 11, 2026 01:26
…tract

This PR raises PROTOCOL_VERSION to 45, so the packaged local-build
contract has to name 45 as the daemon protocol and list it as
attachable. local-build-compatibility-contract.test.ts failed without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Agent panes kept main's terminal model live, because some agents'
readiness rules read main's screen. Only those agents need it: Codex,
Cline, Antigravity, Prime Agent and unidentified agent panes (screen
rules), Qoder (composer screen), OMP (screen input veto) and Freebuff
(per-chunk screen status). Every other agent now rests like a plain
terminal, and a hidden one is handed to the daemon's query responder.

Two readers treated a missing model as an empty screen; both now wait
for the rebuilt model: the tui-idle poll's dialog check, and a fresh
worker's composer check before the brief is pasted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@outof-place
outof-place force-pushed the perf/agent-model-dormancy branch from 2a3d70a to ee5a177 Compare October 10, 2026 23:26
@nwparker

Copy link
Copy Markdown
Contributor

Closing as not planned. This extends the declined dormant-model/responder stack to selected agents and depends on its rebuild latency, history and query-ownership changes. Maintaining a policy of every screen consumer adds another correctness dependency, while the first screen read now waits for reconstruction. No independent small material performance fix remains after removing those trade-offs.

@nwparker nwparker closed this Oct 11, 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.

2 participants