Skip to content

fix(terminal): mark captured shortcut input interactive - #13800

Merged
OrcaWin merged 3 commits into
stablyai:mainfrom
itisvincent:fix/terminal-shift-enter-latency
Aug 21, 2026
Merged

OrcaWin merged 3 commits into
stablyai:mainfrom
itisvincent:fix/terminal-shift-enter-latency

Conversation

@itisvincent

@itisvincent itisvincent commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A captured terminal shortcut (Shift+Enter and friends) now refreshes the interactive-redraw timestamp once its transport accepts the bytes, so the agent's composer redraw that follows renders promptly instead of waiting out the 1s coalesce fallback.

Fixes #10203. Independent of #13598, which decides which bytes Shift+Enter sends; this PR decides how fast Orca paints what those bytes produce.

Root cause

Ordinary typing reaches xterm's onData, which calls markAcceptedTerminalInputSent() and stamps lastTerminalInputAt. Orca's captured-shortcut path deliberately sends straight through the captured pane transport to preserve pane, PTY and transport identity — so it bypasses onData and never stamped anything.

That timestamp gates latencySensitive output. Without it, an idle pane treats the post-Shift+Enter redraw as ordinary throughput: pane-terminal-output-scheduler.ts keeps FOREGROUND_COALESCE_DELAY_MS (1000 ms) instead of clamping to LATENCY_SENSITIVE_FOREGROUND_COALESCE_DELAY_MS (16 ms). Redraws at or below 2048 chars take an unconditional immediate path, which is why a small pi-starline composer masks the bug and a default Pi composer (~2.3–3.3 KB) does not.

Measured, in the real app

Windows, real Pi 0.84.2 pane, same pane and same redraw size across both arms, 8 samples each, measured with the repo's own window.__orcaTypingDiagnostic echo probe:

build echo parse p50 redraw p50
main 1028.9 ms 2338 bytes
this PR 15.6–20.3 ms 2338–2528 bytes

That matches the two constants almost exactly (1000 ms coalesce vs the 16 ms clamp), which is the independent check that the mechanism is understood correctly and not merely correlated.

Implementation

  • sendCapturedTerminalInput() takes an optional onAccepted callback, invoked only after sendInput() returns true.
  • The keyboard handler passes one that runs only while the captured pane binding is still current.
  • PanePtyBinding.markShortcutTerminalInputSent() stamps the redraw window.

No input bytes and no routing decisions change.

Second commit: a regression the first commit introduced

lastTerminalInputAt had two readers, and only one of them was meant to change. onExit reads !Number.isFinite(lastTerminalInputAt) as "the user never typed into this pane" to keep a newborn pane mounted when its shell dies during startup — the failing-.envrc direnv case — so the error stays visible and the worktree stays active.

Stamping it from a captured shortcut meant one Shift+Enter before such an exit closed the tab and dropped the user on Landing. On every platform, since captured shortcuts are not Windows-only.

The second commit splits the redraw window onto its own lastInteractiveRedrawInputAt, leaving onExit byte-identical to main, with a regression test that fails if the two are merged again.

Scope and risk

  • Raises no ceiling. The interactive branch consumes the same consumeForegroundImmediateBudget as the pre-existing ≤2048-char branch: 128 KB per 500 ms per pane, and a 150 ms window. Holding Shift+Enter is bounded exactly as holding any character key already was, because ordinary keystrokes have always refreshed the same timestamp. The OpenTUI small-burst fairness path is untouched (those frames are ≤2048 chars and never consult the timestamp).
  • All platforms, by design — this is a consistency fix that makes captured shortcuts behave like ordinary keys.
  • Local, WSL, SSH and remote transports keep their existing delivery behaviour; main slices foreground IPC at 16 KB, so the realistic immediate write is well under the per-chunk gate.
  • Hibernation is unaffected: the keyboard handler already recorded user input for the same pane key on this send.

Testing

  • src/renderer/src/components/terminal-pane + store/slices + lib/pane-manager: 7094 passed, 2 skipped, 0 failed.
  • pnpm typecheck clean; oxlint and oxfmt clean on changed files; max-lines ratchet clean.
  • Every new test is mutation-checked: each fails when its production change is reverted.
  • A review pass found that deleting the onAccepted wiring entirely, or replacing its binding-identity check with true, both left the whole suite green — nothing pinned the part of this PR that actually ships. A third commit covers both against the existing IME keyboard harness; each mutation now kills exactly one test.
  • Live A/B in a real Pi pane as above.

Takeover notes

Rebased onto current main and taken over. pty-connection.test.ts no longer exists on main (it was split into per-topic files), so the scheduler regression moved into pty-connection-foreground-write-path.test.ts. Original authorship preserved on the first commit.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Captured terminal input now uses the shared TerminalCapturedInputBinding type. Successful captured-input delivery invokes an acceptance callback that records shortcut input in the PTY connection. The PTY binding exposes markShortcutTerminalInputSent, which updates interactive-input bookkeeping without recording ordinary terminal input. Tests cover accepted and rejected sends, replacement transports, immediate handling of large ANSI redraws, binding replacement, and PTY-exit teardown behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes directly address issue #10203 by reducing Shift+Enter redraw latency while preserving input routing and pane-exit behavior.
Out of Scope Changes check ✅ Passed The code and tests remain focused on captured shortcut input timing, binding validity, redraw behavior, and related PTY teardown regressions.
Title check ✅ Passed The title clearly identifies the main change: captured shortcut input is marked as interactive for faster terminal redraws.
Description check ✅ Passed The description covers the change, cause, issue, implementation, testing, risk, and linked issue; the required visual proof or N/A statement is missing.

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.

@AmethystLiang
AmethystLiang requested a review from OrcaWin August 11, 2026 16:48
@itisvincent
itisvincent force-pushed the fix/terminal-shift-enter-latency branch from be1b32c to ffe4475 Compare August 13, 2026 12:35
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker nwparker removed the P1 label Aug 19, 2026
@OrcaWin
OrcaWin force-pushed the fix/terminal-shift-enter-latency branch from ffe4475 to bb9b318 Compare August 20, 2026 03:42
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

itisvincent and others added 2 commits August 19, 2026 23:00
Refresh the interactive-redraw timestamp after a captured shortcut send
succeeds, so the composer redraw that follows takes the low-latency
foreground path instead of waiting out the 1s coalesce fallback.

Orca's captured shortcut path sends directly through the captured pane
transport to preserve pane, PTY and transport identity, and so bypasses
xterm's onData -- the only place that previously stamped the timestamp.
An idle pane therefore scheduled the post-Shift+Enter redraw as ordinary
throughput. Measured in a real Pi pane on Windows: ~1029ms before,
~16-20ms after, at an identical ~2.3KB redraw.

Stale pane bindings and rejected transport sends cannot refresh it.

Fixes stablyai#10203
Refs stablyai#13598
lastTerminalInputAt has two readers, and the previous commit only meant
to change one of them. onExit reads it as "the user never typed into
this pane" to keep a newborn pane mounted when its shell dies on startup
(the failing-.envrc direnv case, pty-connection.ts onExit) so the error
stays visible and the worktree stays active.

Stamping it from a captured shortcut therefore made a single Shift+Enter
before that exit close the tab and bounce the user to Landing -- on every
platform, since captured shortcuts are not Windows-only.

Split the redraw window onto its own timestamp so captured shortcuts open
the fast path without arming the teardown, and leave onExit's behaviour
byte-identical to main.
@OrcaWin
OrcaWin force-pushed the fix/terminal-shift-enter-latency branch from bb9b318 to 8d5dc41 Compare August 20, 2026 06:46
Deleting the onAccepted block, or replacing its binding-identity check
with true, both left the whole suite green — so nothing pinned the part
of this PR that actually ships. Cover both against the existing IME
keyboard harness.

@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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/keyboard-handlers-ime.test.tsx (1)

199-202: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a real binding replacement in the stale-binding test.

The test changes Map.get based on a read counter instead of replacing the map entry. An additional lookup before the send can change the scenario and make the test fail for the wrong reason. Mutate the binding at the send boundary, then use the normal Map.get implementation for the identity check.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 603bb61a-b247-4a2b-be8b-ac3938c2e430

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5dc41 and e3efb06.

📒 Files selected for processing (1)
  • src/renderer/src/components/terminal-pane/keyboard-handlers-ime.test.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@OrcaWin
OrcaWin merged commit a0cc9f3 into stablyai:main Aug 21, 2026
97 of 99 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
* fix(terminal): mark captured shortcut input interactive

Refresh the interactive-redraw timestamp after a captured shortcut send
succeeds, so the composer redraw that follows takes the low-latency
foreground path instead of waiting out the 1s coalesce fallback.

Orca's captured shortcut path sends directly through the captured pane
transport to preserve pane, PTY and transport identity, and so bypasses
xterm's onData -- the only place that previously stamped the timestamp.
An idle pane therefore scheduled the post-Shift+Enter redraw as ordinary
throughput. Measured in a real Pi pane on Windows: ~1029ms before,
~16-20ms after, at an identical ~2.3KB redraw.

Stale pane bindings and rejected transport sends cannot refresh it.

Fixes stablyai#10203
Refs stablyai#13598

* fix(terminal): keep captured shortcuts out of the pane-teardown signal

lastTerminalInputAt has two readers, and the previous commit only meant
to change one of them. onExit reads it as "the user never typed into
this pane" to keep a newborn pane mounted when its shell dies on startup
(the failing-.envrc direnv case, pty-connection.ts onExit) so the error
stays visible and the worktree stays active.

Stamping it from a captured shortcut therefore made a single Shift+Enter
before that exit close the tab and bounce the user to Landing -- on every
platform, since captured shortcuts are not Windows-only.

Split the redraw window onto its own timestamp so captured shortcuts open
the fast path without arming the teardown, and leave onExit's behaviour
byte-identical to main.

* test(terminal): pin the captured-shortcut wiring and its staleness guard

Deleting the onAccepted block, or replacing its binding-identity check
with true, both left the whole suite green — so nothing pinned the part
of this PR that actually ships. Cover both against the existing IME
keyboard harness.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
(cherry picked from commit a0cc9f3)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
* fix(terminal): mark captured shortcut input interactive

Refresh the interactive-redraw timestamp after a captured shortcut send
succeeds, so the composer redraw that follows takes the low-latency
foreground path instead of waiting out the 1s coalesce fallback.

Orca's captured shortcut path sends directly through the captured pane
transport to preserve pane, PTY and transport identity, and so bypasses
xterm's onData -- the only place that previously stamped the timestamp.
An idle pane therefore scheduled the post-Shift+Enter redraw as ordinary
throughput. Measured in a real Pi pane on Windows: ~1029ms before,
~16-20ms after, at an identical ~2.3KB redraw.

Stale pane bindings and rejected transport sends cannot refresh it.

Fixes stablyai#10203
Refs stablyai#13598

* fix(terminal): keep captured shortcuts out of the pane-teardown signal

lastTerminalInputAt has two readers, and the previous commit only meant
to change one of them. onExit reads it as "the user never typed into
this pane" to keep a newborn pane mounted when its shell dies on startup
(the failing-.envrc direnv case, pty-connection.ts onExit) so the error
stays visible and the worktree stays active.

Stamping it from a captured shortcut therefore made a single Shift+Enter
before that exit close the tab and bounce the user to Landing -- on every
platform, since captured shortcuts are not Windows-only.

Split the redraw window onto its own timestamp so captured shortcuts open
the fast path without arming the teardown, and leave onExit's behaviour
byte-identical to main.

* test(terminal): pin the captured-shortcut wiring and its staleness guard

Deleting the onAccepted block, or replacing its binding-identity check
with true, both left the whole suite green — so nothing pinned the part
of this PR that actually ships. Cover both against the existing IME
keyboard harness.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(terminal): mark captured shortcut input interactive

Refresh the interactive-redraw timestamp after a captured shortcut send
succeeds, so the composer redraw that follows takes the low-latency
foreground path instead of waiting out the 1s coalesce fallback.

Orca's captured shortcut path sends directly through the captured pane
transport to preserve pane, PTY and transport identity, and so bypasses
xterm's onData -- the only place that previously stamped the timestamp.
An idle pane therefore scheduled the post-Shift+Enter redraw as ordinary
throughput. Measured in a real Pi pane on Windows: ~1029ms before,
~16-20ms after, at an identical ~2.3KB redraw.

Stale pane bindings and rejected transport sends cannot refresh it.

Fixes stablyai#10203
Refs stablyai#13598

* fix(terminal): keep captured shortcuts out of the pane-teardown signal

lastTerminalInputAt has two readers, and the previous commit only meant
to change one of them. onExit reads it as "the user never typed into
this pane" to keep a newborn pane mounted when its shell dies on startup
(the failing-.envrc direnv case, pty-connection.ts onExit) so the error
stays visible and the worktree stays active.

Stamping it from a captured shortcut therefore made a single Shift+Enter
before that exit close the tab and bounce the user to Landing -- on every
platform, since captured shortcuts are not Windows-only.

Split the redraw window onto its own timestamp so captured shortcuts open
the fast path without arming the teardown, and leave onExit's behaviour
byte-identical to main.

* test(terminal): pin the captured-shortcut wiring and its staleness guard

Deleting the onAccepted block, or replacing its binding-identity check
with true, both left the whole suite green — so nothing pinned the part
of this PR that actually ships. Cover both against the existing IME
keyboard harness.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
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.

[Bug]: Pi agent input freezes briefly on Shift+Enter newline (other CLI agents unaffected)

4 participants