Skip to content

fix(terminal): answer queries split across dropped chunks, and CPR from the snapshot that covers them - #27299

Closed
outof-place wants to merge 9 commits into
stablyai:mainfrom
outof-place:fix/salvaged-query-replies
Closed

outof-place wants to merge 9 commits into
stablyai:mainfrom
outof-place:fix/salvaged-query-replies

Conversation

@outof-place

Copy link
Copy Markdown
Contributor

ELI5

Programs in a terminal sometimes ask the terminal a question, such as "where is the cursor?", and wait for the answer. When Orca throws away output it no longer needs to draw (because a fresh snapshot of the screen replaces it), it still answers the questions in that output. It missed two cases: a question cut in half between two thrown-away pieces got no answer at all, so the program hung, and a cursor question answered while a snapshot was being applied got the old cursor position instead of the one the snapshot shows.

What Changed

Before:

  • A query split across two dropped pieces (one PTY read ending in \e[6, the next starting with n) went unanswered. Each piece was scanned on its own, and neither held a whole query.
  • Queued writes that a snapshot apply throws away were salvaged before the snapshot was written. Their CPR reply reported the cursor of the stale screen the snapshot was about to replace.

After:

  • The salvage keeps the unfinished query a dropped piece ends in, together with that piece's raw seq end. It joins the query to the next dropped piece only if that piece starts at exactly that seq on the same PTY. A discard without seq metadata, or one that does not start there, clears it.
  • Replies for writes a snapshot apply discards (CPR, DA1, OSC color) wait until the replay has parsed, so CPR reads the snapshot's cursor. If the replay aborts, its finally still sends them.

The mechanism:

  • salvageRendererQueriesFromDiscardedRestoreData(data, range?, cursorAfter?) in hidden-startup-renderer-query-write.ts. range is the dropped bytes' raw seq span. It feeds the existing pending input of extractHiddenStartupRendererQueryData, which already carries unfinished queries for hidden startup output. cursorAfter holds the direct replies (OSC color, CPR, DA1) until the promise resolves. Rarer queries still replay into xterm at once, as before.
  • Every discard that knows its seq passes range: drop-duplicate and the covered prefix after a restore, the restore drain's covered chunks, and its refetch and overflow discards.
  • applyMainBufferSnapshot passes a promise that resolves after waitForTerminalReplayWritesParsed, or in its finally.

A query split at the snapshot seq itself is left as it was. The snapshot then ends mid-escape, so it carries pendingEscapeTailAnsi. Its replay re-arms xterm's parser with the first half, and the written rest of the chunk completes the query in xterm. Also answering it from the covered prefix would answer it twice.

Why

A lost reply leaves the program that asked waiting for it, until its own timeout if it has one. A query is a few bytes, so a PTY read boundary inside one is rare. It does happen under load, and the dropped-chunk paths run mostly under load: floods and restores.

Alternatives considered:

  • Extend the covered prefix to the end of an escape open at the snapshot seq. The snapshot's escape tail already lets xterm finish that query, so extending the prefix would reply twice. The test "leaves a query split at the snapshot seq to xterm" pins this.
  • Join any two consecutive discards, without seq. Bytes lost in a gap between them could glue two unrelated halves into a query that was never sent. The reply would then arrive as input the program never asked for. Requiring exact seq adjacency rules that out; the test "does not join query halves across a seq gap" checks it.
  • Exact CPR for every dropped byte, through a seq-exact responder hand-over. Main or the daemon would answer up to the restore snapshot's seq and the view after it, so the responder flip and the snapshot meet at one byte. That is a protocol change across main, the daemon and the renderer. This PR covers the case the renderer can answer exactly by itself: bytes a parsed snapshot already covers. A program that waits on its CPR prints nothing after the query, so the snapshot's cursor is the cursor at the query.

Stacked on #27086

This branch sits on #27086 (b814bec), which added the salvage at every discard; that sits on #27129 and #27033. The diff here includes their commits until they land. This PR's own change is the last commit.

Linked Issue

Part of #27023 (follow-up to #27086's query salvage)

Visual Proof

N/A: no UI change. What changes is the reply a program gets to a terminal query in dropped output, which the tests below check.

Testing

  • New tests in pty-connection-hidden-backlog-reconciliation.test.ts. The first three fail on b814bec, and the other two pass on both:

    • "answers a query split across two queued chunks the snapshot covers": a restore queue holding one\e[6 (seq 44–50) and ntwo (50–54), both covered by a snapshot at 63, gets exactly one CPR reply. Before: none.
    • "answers a query split across two backlog chunks the snapshot covers": the same split across two post-restore duplicates (52–58, 58–60) gets one CPR reply. Before: none.
    • "answers CPR in writes a snapshot apply discards from the snapshot cursor": a held write with \e[6n is still queued when the snapshot applies, and the snapshot moves the cursor to row 6, column 8. The reply is exactly \e[6;8R. Before: \e[1;1R, the stale cursor.
    • "does not join query halves across a seq gap": one\e[6 ends at 50, ntwo starts at 52, so there is no reply.
    • "leaves a query split at the snapshot seq to xterm": the chunk 60–70 holds one\e[6ntwo, and the snapshot at 66 carries the tail \e[6. There is no salvage reply, and ntwo is written after the replayed tail.
  • Unit suites on macOS at bc9b0ec (pnpm test --maxWorkers=4 src/renderer/src/components/terminal-pane src/renderer/src/lib/pane-manager): 6,077 pass, 2 skipped.

  • pnpm tc and the changed-code quality gate (ORCA_CODE_QUALITY_BASE=b814beccf7 pnpm run check:code-quality:changed) pass.

  • Not run: the full pnpm test, pnpm lint, pnpm build, and the E2E suites (left to CI). No E2E was added: a query split across two PTY reads cannot be placed on demand in a real PTY, so the unit tests drive the renderer's data path with chosen seqs instead.

  • I manually tested these changes locally (not done: only the unit tests and checks 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. salvageRendererQueriesFromDiscardedRestoreData in hidden-startup-renderer-query-write.ts: the seq-adjacent carry and cursorAfter.
  2. The range arguments at the discard sites: live-data-callback.ts, hidden-output-restore-drain.ts and hidden-output-restore-chunk.ts.
  3. discardedRepliesReady in hidden-output-restore-snapshot.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 replies the renderer sends for output it drops. A wrong join would send a reply nobody asked for, which the program reads as input. Mitigations:
    • a join needs the same PTY and an exact raw seq match between the two pieces;
    • any discard without seq metadata, or not adjacent, clears the carry;
    • tests cover the gap case and the snapshot-boundary case, where a reply must not be sent.
      The deferred replies are released after the replay parses, or in the apply's finally if it aborts, so a thrown replay cannot leave them unsent.
  • CPU. Nothing changes on the path for written chunks. Each salvage call (discards only) adds a PTY id read and one comparison. Joining a split query runs the existing extractor over a few more bytes.
  • Memory. At most one unfinished query per pane, capped at 64 characters, held only while a dropped piece ends inside one.
  • Latency. Replies for writes a snapshot apply discards now leave after the replay has parsed, not before it was written. In @xterm/headless that parse takes 2.6 ms for a 1,000-row replay and 10.3 ms for 10,000 rows (120 columns, median of 7, host load 17–20). The renderer's xterm parses the same bytes; the wait does not include painting. Every other salvage path replies as before.
  • Disk. None.
  • Maintenance. +106/−28 lines in six source files and +113 lines of tests. New concepts: a seq range on discards and one session field for the carried query, plus an optional "reply after" promise on the salvage. A new discard site should pass its seq range, or it simply never joins a split query.
  • Verdict: free win. It removes a hang (an unanswered query) and a wrong cursor reply, and costs nothing on the hot path. The only cost is that one rare path waits a few milliseconds for the right answer.

Notes

  • Still current-cursor: bytes dropped before any snapshot covers them still answer CPR from the view's cursor: a hidden pane behind a latched restore, a seq gap, a backlog cap, a restore-queue overflow. Waiting for the next snapshot there would hold a hidden pane's reply until the user reveals it, so liveness stays first. The hand-over above is what would make those exact.
  • SSH and remote. Same code path for every PTY kind. Chunks without seq metadata never join.
  • Cross-platform. Renderer-only, no platform-specific code.

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 9 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]>
…om the snapshot that covers them

The renderer salvages the queries in chunks it drops, but it scanned each
dropped piece on its own. A CPR or DA split across two dropped pieces
(one PTY read ending in "\e[6", the next starting with "n") parsed as
nothing in either, and the program that sent it waited forever.

The salvage now keeps the unfinished query a dropped piece ends in, with
that piece's raw seq end. It joins the query to the next dropped piece
only if that piece starts at exactly that seq; any other discard, or one
without seq metadata, clears the carry. A query split at the snapshot seq
itself is left alone: the snapshot's escape tail re-arms xterm's parser,
and the written rest completes the query there.

Queued writes that a snapshot apply discards used to be salvaged before
the snapshot was written, so their CPR reported xterm's stale cursor.
Those writes are older than the snapshot, so their CPR, DA1 and OSC color
replies now wait until the replay has parsed and CPR reads the snapshot's
cursor. A replay that aborts still sends them from its finally.

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 →

📝 Walkthrough

Walkthrough

The change adds protocol support checks for settled daemon snapshots and a runtime that can drop and rebuild eligible main terminal models. Hidden PTY delivery now distinguishes parsing, sidecar-only delivery, and dropping. Main and renderer paths track delivery ownership and salvage terminal queries from data discarded during visibility changes, snapshot restoration, or output-queue handling. Tests cover protocol boundaries, dormancy, sidecar delivery, query replies, and end-to-end visibility changes.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to bc9b0

Most hidden-output query handling works as intended. However, a terminal flooded repeatedly while in the background can lose replies to cursor or device queries after its first backlog drop. Programs that are waiting for those replies may stall. This is a small fix that can be made before or shortly after merge.

Pre-merge checks | Passed 4 | Inconclusive 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 50 files. (17 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 main change: handling queries split across dropped terminal chunks and CPR replies during snapshot restoration.
Description check Passed The description is detailed and mostly complete. It explains the user impact, implementation, rationale, linked issue, testing, limitations, trade-offs, platform considerations, and checklist status.
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 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 50 files. (17 skipped: 17 over the file limit.)


  • 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c90ca319-193b-4175-8404-9c200a50cce0
📥 Commits

Reviewing files that changed from the base of the PR and between ca1aac6 and bc9b0ec.

📒 Files selected for processing (67)
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter-protocol-compatibility.test.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/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.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-hidden-delivery-flip-replies.test.ts
  • src/main/ipc/pty-ipc-hidden-delivery-gate.test.ts
  • src/main/ipc/pty-pending-data-drain-contract.ts
  • src/main/ipc/pty/delivery/accept.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/runtime/controller.ts
  • src/main/ipc/pty/session.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/runtime/main-terminal-model-dormancy.test.ts
  • src/main/runtime/main-terminal-model-dormancy.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-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/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-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/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.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/hidden-startup-renderer-query-write.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/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; 8 remain after this review.

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*=' src/renderer/src/lib/pane-manager
rg -nP -C3 '\breplaceBacklogWithWarning\s*\(' src/renderer/src/lib/pane-manager

Repository: stablyai/orca

Length of output: 4890


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- backlog helper ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts | sed -n '1,130p'
printf '%s\n' '--- writer relevant declarations and calls ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-writer.ts | sed -n '1,270p'
printf '%s\n' '--- callback definitions/usages ---'
rg -n -F --glob '*.ts' -- 'onBackgroundBacklogDropped' src/renderer/src/lib/pane-manager src/renderer/src | head -80

Repository: stablyai/orca

Length of output: 19958


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- queue registry ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts | sed -n '1,130p'
printf '%s\n' '--- PTY callback consumer ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '70,145p'
printf '%s\n' '--- discarded-query tests ---'
nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler-discarded-queries.test.ts | sed -n '1,130p'
printf '%s\n' '--- query-related callback/parser references ---'
rg -n -P -C4 'discarded|BackgroundBacklog|\\x1b\\[6n|\\x1b\\[c|onBackgroundBacklogDropped|queuedTerminalOutputData' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/lib/pane-manager

Repository: stablyai/orca

Length of output: 14200


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- queued data helper ---'
rg -n -F -- 'function queuedTerminalOutputData' src/renderer/src/lib/pane-manager
rg -n -F -C8 -- 'queuedTerminalOutputData' src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts
printf '%s\n' '--- salvage implementation ---'
rg -n -F -- 'salvageRendererQueriesFromDiscardedRestoreData' src/renderer/src
printf '%s\n' '--- query salvage identifiers ---'
rg -n -F -C6 -- 'salvageRendererQueries' src/renderer/src
rg -n -F -C6 -- 'RendererQueriesFromDiscarded' src/renderer/src

Repository: stablyai/orca

Length of output: 41520


🏁 Script executed:

nl -ba src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts | sed -n '115,245p'

Repository: stablyai/orca

Length of output: 4630


🏁 Script executed:

set -u
rg -n -F -- 'function extractHiddenStartupRendererQueryData' src/renderer/src
rg -n -F -C8 -- 'extractHiddenStartupRendererQueryData' src/renderer/src/components/terminal-pane/pty-connection

Repository: stablyai/orca

Length of output: 8399


🏁 Script executed:

set -u
nl -ba src/shared/terminal-reply-query-extraction.ts | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 6071


🏁 Script executed:

set -u
printf '%s\n' '--- enqueue helper ---'
rg -n -F -- 'function enqueueChunk' src/renderer/src/lib/pane-manager
rg -n -F -C12 -- 'enqueueChunk' src/renderer/src/lib/pane-manager/pane-terminal-output-queue-chunks.ts
printf '%s\n' '--- backlog-drop flag assignments ---'
rg -n -F -- 'backgroundBacklogDropped' src/renderer/src/lib/pane-manager

Repository: stablyai/orca

Length of output: 1813


🏁 Script executed:

nl -ba src/renderer/src/lib/pane-manager/pane-terminal-output-queue-chunks.ts | sed -n '178,245p'

Repository: stablyai/orca

Length of output: 1580


Preserve dropped bytes on every backlog replacement.

After the first overflow, later writes remain queued and can trigger another cap check while backgroundBacklogDropped is already true. The current code then discards those bytes without invoking the query-salvage callback. A dropped \x1b[6n or \x1b[c can therefore receive no reply.

Keep the breadcrumb and debug counter gated by shouldNotify, but collect and forward every non-empty dropped payload.

Suggested fix
-  const droppedData = shouldNotify ? queuedTerminalOutputData(entry) : ''
+  const droppedData = queuedTerminalOutputData(entry)
...
-  if (shouldNotify) {
+  if (droppedData) {
    entry.onBackgroundBacklogDropped?.(droppedData)
  }

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