Skip to content

fix(terminal): preserve Shift+Enter during routing confirmation - #13598

Merged
OrcaWin merged 8 commits into
stablyai:mainfrom
itisvincent:fix/pi-shift-enter-reconfirmation
Aug 21, 2026
Merged

OrcaWin merged 8 commits into
stablyai:mainfrom
itisvincent:fix/pi-shift-enter-reconfirmation

Conversation

@itisvincent

@itisvincent itisvincent commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

While a Windows foreground revalidation is genuinely in flight, keep Shift+Enter on the CSI-u route a provider read already proved, instead of dropping to the Alt+Enter fallback for the length of the gap.

Closes #13597. Follow-up to #12541; addresses the pending-confirmation behaviour after #12618, on the Pi CSI-u routing from #11769.

The state machine

requestKnownWindowsShiftEnterReconfirmation revokes routing and starts an asynchronous provider read. Between those two things the entry was {agent, routingRevoked: true}, which resolves to alt-enter — so during the gap Shift+Enter sent ESC CR rather than the CSI 13;2u the pane had been sending a moment earlier.

This adds routingConfirmationPending, published only while a confirmation read is actually in flight, so the resolver keeps the proven capability for exactly as long as the read that justifies it.

The second commit routes shellOverride through resolveWindowsShellOverride in isForegroundTrackingAllowed, matching the sibling call site. This strictly narrows: a user whose global Windows shell is WSL no longer gets native-ConPTY process scans on panes that can never authorize ConPTY bytes.

Third commit: bounding the capability

Review found the first commit let one old provider read authorize CSI-u indefinitely, in two ways:

  1. routingConfirmationPending satisfied its own precondition, so a pending entry re-published itself on every reconfirmation request. Only one of the five callers is the Shift+Enter burst timer — the others fire on accepted submit/interrupt bytes, on focus and visibility changes, and on onAgentExited, which runs precisely when a shell title proves the agent is gone. On cmd.exe and Git Bash there is no OSC boundary to publish over the entry, so nothing decayed it.
  2. The flag was published even when no read was scheduled — hidden pane, a command read already in flight, or a null pty id — while only the read's inconclusive settle clears it.

The fix requires routingTrusted to grant the capability and publishes the flag only after sampling reports a read in flight. That also makes the canConfirmRouting gate redundant: the tracker already refuses WSL, SSH and remote pty ids.

Fourth and fifth commits: bounding it correctly

A second review round found the third commit's gate asked the wrong question. onVisiblePtyBound deliberately returns false while a higher-authority command read owns the pane, and reading that as "no read is coming" dropped CSI-u for the length of that window — reintroducing the very gap this PR exists to close, and regressing against the PR's own earlier behaviour. The tracker now exposes hasReadInFlight() so the question asked is "will anything confirm this pane?" rather than "did I just schedule something?".

Landing alongside it: the command-finished branch that returns without publishing now settles the visible confirmation it replaced, so the flag cannot outlive the read that justifies it. The two had to land together — fixing either alone widens the other's window.

Sixth commit: closing the flag's lifetime for good

Two further review rounds found the same root cause twice more: the flag could outlive the read it is tied to. cancelPendingRead bumps the read generation before anything can settle, and dispose() plus three untrackable early returns schedule no successor to settle for them — while the store entry outlives the tracker, because detach/remount emits no PTY exit. A visible remount self-heals, but a hidden pane does not, since the dashboard card resolves the encoding for any pane key regardless of visibility.

Rather than patch a third site, every exit that ends a read without scheduling a successor now releases the capability. A final review enumerated all 22 exits from the tracker and confirmed each one releases the flag — by wholesale publish replacement, by settle, or by a successor read — and that the flag is minted in exactly one place, gated on a live read.

Reproduced on Pi 0.84.2 — the state matters

The symptom only appears while Pi is working, which is what #13597 meant by "submit in the affected state". With Pi idle the fallback looks harmless, and an idle-pane test wrongly clears it.

The reason is in Pi's own keymap (@earendil-works/pi-coding-agent/dist/core/keybindings.js): alt+enter is bound to app.message.followUp — "Queue follow-up message", backed by a real _followUpMessages queue in core/agent-session.js. Idle, there is no turn to follow up, so it degrades to a newline. Busy, it consumes the composer.

Live A/B, same pane, same Pi build, Pi mid-task:

bytes written to the PTY result
ESC CR — what main sends during the gap composer consumed; the half-written draft was submitted and the pane title changed to it
CSI 13;2u — what this PR preserves newline; both lines stayed in the composer, nothing submitted

So the gap is a real data-loss path: a Shift+Enter landing inside the revalidation window sends your unfinished message to the model. That is the user-visible bug this PR fixes.

Surface matrix

  • macOS / Linux: no change. terminal-shortcut-policy.ts only consults the Windows encoding behind isWindowsTerminalHost(), and the routing side is separately gated on a Windows user agent.
  • WSL / SSH / remote runtime: no change. The tracker refuses those pty ids, so they stay on revoked-only, exactly as before.
  • Folder workspaces vs git worktrees: nothing on this path distinguishes them.
  • Paired web / mobile: dashboard-card-terminal-input.ts publishes windowsShiftEnterEncoding to remote clients, so the corrected value reaches them too. Wire-safe — existing field, existing value domain, no new opcode — but worth knowing the blast radius includes those surfaces.
  • Other agents: only pi, prime-agent and droid carry windowsShiftEnterEncoding: 'csi-u'; every other agent still resolves to alt-enter. The gate is a pure TUI_AGENT_CONFIG table lookup, so it is agent-agnostic and pi/droid exercise the identical branch.

Known gap, deliberately not fixed here

Ctrl+Enter has the same shape and is not covered. terminal-ctrl-enter.ts denies authority on routingRevoked, and terminal-shortcut-policy.ts falls back to plain \r — which really does submit. This is pre-existing and unchanged by this PR, but it means the class is only half-addressed, and the two sibling resolvers now read the same entry differently. Fixing it changes Ctrl+Enter byte output for Droid/Grok and deserves its own PR and its own live validation rather than a rider here.

Testing

  • src/renderer/src/components/terminal-pane + store/slices: 6375 passed, 1 skipped, 0 failed.
  • pnpm typecheck clean; oxlint and oxfmt clean on changed files; max-lines ratchet clean.
  • Every new test mutation-checked — each fails when its production change is reverted. That includes the slice equality comparison, which is load-bearing: without it the clearing publish is swallowed as a no-op and the pane keeps CSI-u forever, and no pty-connection test can catch it because the fixture stubs the store action.

Takeover notes

Rebased onto current main and taken over. pty-connection.test.ts no longer exists on main (split into per-topic files), so the regressions moved into the topic files that now own them, plus a new pty-connection-foreground-routing-confirmation.test.ts to stay under the 800-line cap without a lint suppression. Original authorship preserved on the first two commits.

@coderabbitai

coderabbitai Bot commented Aug 10, 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

Foreground-agent entries now store pending routing confirmation. Foreground tracking reports active reads and settles replaced confirmations as inconclusive. PTY tracking resolves pane-specific and global Windows shell settings. Inconclusive results revoke routing when confirmation is pending. Windows Shift+Enter reconfirmation requires trusted routing and preserves pending state only during an active read. Tests cover routing outcomes, shell detection, sampling, and encoding behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed, but it omits the required Visual Proof section and does not complete the required checklist items. Add before/after evidence or N/A with a reason, then complete applicable testing, review, boundary, notes, and checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The description explicitly closes issue #13597 and identifies related follow-up issues.
Out of Scope Changes check ✅ Passed The changes remain focused on Windows routing confirmation, Shift+Enter encoding, shell resolution, and related tests.
Title check ✅ Passed The title clearly and concisely describes preserving Shift+Enter during routing confirmation.

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: Pro Plus

Run ID: eb7520ad-b054-4589-8eba-30347484b526

📥 Commits

Reviewing files that changed from the base of the PR and between a63df91 and c50b024bbb1a4f633fe2ee69f3f35e0ca8d750f3.

📒 Files selected for processing (6)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.ts
  • src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.ts
  • src/renderer/src/store/slices/pane-foreground-agent.test.ts
  • src/renderer/src/store/slices/pane-foreground-agent.ts

Keep previously trusted CSI-u routing active only while local foreground revalidation is pending. Clear pending authority on inconclusive reads and never promote display-only identity.\n\nRefs stablyai#12541\nRefs stablyai#13597
@OrcaWin
OrcaWin force-pushed the fix/pi-shift-enter-reconfirmation branch from d8744ae to b1c89de Compare August 20, 2026 03:37
@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.

Two holes in the previous commit let one provider read authorize CSI-u
indefinitely.

First, routingConfirmationPending satisfied its own precondition, so a
pending entry re-published itself on every reconfirmation request. Only
one of the five callers is the Shift+Enter burst timer; the others fire
on accepted submit/interrupt bytes, focus and visibility changes, and
onAgentExited -- the last of which runs precisely when a shell title
proves the agent is gone. On cmd.exe and Git Bash there is no OSC
boundary to publish over the entry, so nothing decayed it.

Second, the flag was published even when no confirmation read was
actually scheduled -- a hidden pane, a command read already in flight, or
a null pty id -- and only the read's inconclusive settle clears it.

Require routingTrusted to grant the capability, and publish the flag only
after sampling reports a read in flight, so it cannot outlive the read
that justifies it. This also makes the canConfirmRouting gate redundant:
the tracker already refuses WSL, SSH and remote pty ids.
onVisiblePtyBound refuses to schedule while a higher-authority command
read owns the pane, so gating the pending publish on it mistook 'a
command-finished read already owns this' for 'no read at all' and
dropped CSI-u for >=350ms — the window stablyai#13598 exists to close.

Ask the tracker whether any read is in flight instead, and settle the
visible confirmation from the command-finished branch that publishes
nothing, so the flag cannot outlive the read that justifies it.
hasReadInFlight already covers the visible-pty read that
visibleForegroundSamplePending tracked, so the disjunction was
redundant. Collapse the stacked Why blocks into one.
OrcaWin pushed a commit to itisvincent/orca that referenced this pull request Aug 20, 2026
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

@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/pty-connection.ts (1)

2257-2260: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the new comments. These comments restate nearby control flow over multiple lines. Keep one sentence that states the non-obvious constraint.

  • src/renderer/src/components/terminal-pane/pty-connection.ts#L2257-L2260: reduce the routing-trust explanation to one sentence.
  • src/renderer/src/components/terminal-pane/pty-connection.ts#L2276-L2281: reduce the pending-read explanation to one sentence.
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts#L197-L199: reduce the inconclusive-settlement explanation to one sentence.
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts#L217-L219: reduce the in-flight-read explanation to one sentence.
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts#L58-L60: reduce the test rationale to one sentence.
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts#L77-L78: reduce the test rationale to one sentence.
  • src/renderer/src/store/slices/pane-foreground-agent.test.ts#L47-L49: reduce the test rationale to one sentence.
  • src/renderer/src/components/terminal-pane/pty-connection-foreground-routing-confirmation.test.ts#L238-L239: reduce the test rationale to one sentence.
  • src/renderer/src/components/terminal-pane/pty-connection-foreground-routing-confirmation.test.ts#L254-L255: reduce the test rationale to one sentence.
  • src/renderer/src/components/terminal-pane/pty-connection-foreground-routing-confirmation.test.ts#L273-L273: keep the comment brief.

As per coding guidelines, comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 027d2020-ee65-4606-9914-77b1b1a88376

📥 Commits

Reviewing files that changed from the base of the PR and between b1c89de and 1d90ad6.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts
  • src/renderer/src/components/terminal-pane/pty-connection-foreground-routing-confirmation.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/store/slices/pane-foreground-agent.test.ts

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

Every outcome path now clears routingConfirmationPending, but the two
abort guards in readForeground return without publishing or settling. A
pty rebind during the multi-second inspection RPC — a detach/remount
emits no onExit, so the store entry survives — therefore stranded the
flag permanently, leaving Shift+Enter on CSI-u with nothing left to
revalidate it. Worse, once sampling is suppressed by a live hook row the
pane routes bytes on hook evidence alone, which the resolver excludes
precisely because PTY output can forge it.

Settle an abandoned read unless a newer generation will settle for it.

@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: Pro Plus

Run ID: 1f0f1ae5-59cf-4ced-a274-fbbc01f2edd9

📥 Commits

Reviewing files that changed from the base of the PR and between 1d90ad6 and 42eb500.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts

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

Comment on lines +58 to +80
// Why: an abandoned read publishes nothing, so a capability retained pending its
// answer would otherwise be held forever with no read left to release it.
it('settles the visible confirmation when a pty rebind abandons its read', async () => {
let resolveRead: (value: string | null) => void = () => {}
readForegroundProcess.mockImplementation(
() =>
new Promise<string | null>((resolve) => {
resolveRead = resolve
})
)
const tracker = makeTracker()

tracker.onVisiblePtyBound(true)
await flushSettleRead(VISIBLE_PTY_SETTLE_MS)

// The pane is rebound to a different PTY while the inspection RPC is in flight.
ptyId = 'pty-2'
resolveRead('pi')
await flushSettleRead(1)

expect(publish).not.toHaveBeenCalled()
expect(onVisibleForegroundSettled).toHaveBeenCalledWith('inconclusive')
})

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

Mock the confirmation callback used by this test.

onVisiblePtyBound(true) sets known agent evidence. The tracker therefore selects confirmForegroundProcess at Lines 122-130 of pane-foreground-agent-tracker.ts, not readForegroundProcess. This test only replaces readForegroundProcess, so resolveRead may never control the in-flight promise. Configure confirmForegroundProcess with the pending promise instead.

… a successor

Rounds 2 and 3 closed the outcome paths and the aborted-read paths, but
two review lanes independently proved a third: cancelPendingRead bumps
the generation, so a cancel never settles, and dispose plus the three
untrackable early returns schedule no successor to settle for them. The
store entry outlives the tracker — detach/remount emits no PTY exit — so
the flag latched there with no read left alive.

A visible remount self-heals, but a hidden pane does not: the dashboard
card resolves the encoding for any pane key regardless of visibility.

Release the capability from whichever exit ends the read, and say in the
entry's own doc comment that the flag is Shift+Enter-scoped.
dispose and the command-finished exit were covered; the visible-bind and
command-start variants are the same three-line pattern and were not.
Neutering the release now kills all four.
@nwparker

Copy link
Copy Markdown
Contributor

@itisvincent -- on the PRs I made few commits

Can you double check that they're good on your end?
They're good on mine

If so then I can merge (I'll check back tmrw )

@itisvincent

Copy link
Copy Markdown
Contributor Author

hi @nwparker
can you also merge this one #13800? it is nessarcy one to avoid lagging when press shift+enter. thanks

OrcaWin added a commit that referenced this pull request Aug 21, 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 #10203
Refs #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>
@OrcaWin
OrcaWin merged commit 59892a2 into stablyai:main Aug 21, 2026
50 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)
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
…lyai#13598)

* fix(terminal): preserve Shift+Enter during routing confirmation

Keep previously trusted CSI-u routing active only while local foreground revalidation is pending. Clear pending authority on inconclusive reads and never promote display-only identity.\n\nRefs stablyai#12541\nRefs stablyai#13597

* fix(terminal): respect global WSL routing gate

* fix(terminal): bound the retained routing capability to a live read

Two holes in the previous commit let one provider read authorize CSI-u
indefinitely.

First, routingConfirmationPending satisfied its own precondition, so a
pending entry re-published itself on every reconfirmation request. Only
one of the five callers is the Shift+Enter burst timer; the others fire
on accepted submit/interrupt bytes, focus and visibility changes, and
onAgentExited -- the last of which runs precisely when a shell title
proves the agent is gone. On cmd.exe and Git Bash there is no OSC
boundary to publish over the entry, so nothing decayed it.

Second, the flag was published even when no confirmation read was
actually scheduled -- a hidden pane, a command read already in flight, or
a null pty id -- and only the read's inconclusive settle clears it.

Require routingTrusted to grant the capability, and publish the flag only
after sampling reports a read in flight, so it cannot outlive the read
that justifies it. This also makes the canConfirmRouting gate redundant:
the tracker already refuses WSL, SSH and remote pty ids.

* review round 2: bound the retained capability to any in-flight read

onVisiblePtyBound refuses to schedule while a higher-authority command
read owns the pane, so gating the pending publish on it mistook 'a
command-finished read already owns this' for 'no read at all' and
dropped CSI-u for >=350ms — the window stablyai#13598 exists to close.

Ask the tracker whether any read is in flight instead, and settle the
visible confirmation from the command-finished branch that publishes
nothing, so the flag cannot outlive the read that justifies it.

* review round 2: tighten the reconfirmation gate and its comments

hasReadInFlight already covers the visible-pty read that
visibleForegroundSamplePending tracked, so the disjunction was
redundant. Collapse the stacked Why blocks into one.

* review round 3: release the retained capability when a read is abandoned

Every outcome path now clears routingConfirmationPending, but the two
abort guards in readForeground return without publishing or settling. A
pty rebind during the multi-second inspection RPC — a detach/remount
emits no onExit, so the store entry survives — therefore stranded the
flag permanently, leaving Shift+Enter on CSI-u with nothing left to
revalidate it. Worse, once sampling is suppressed by a live hook row the
pane routes bytes on hook evidence alone, which the resolver excludes
precisely because PTY output can forge it.

Settle an abandoned read unless a newer generation will settle for it.

* review round 4: release the retained capability at every exit without a successor

Rounds 2 and 3 closed the outcome paths and the aborted-read paths, but
two review lanes independently proved a third: cancelPendingRead bumps
the generation, so a cancel never settles, and dispose plus the three
untrackable early returns schedule no successor to settle for them. The
store entry outlives the tracker — detach/remount emits no PTY exit — so
the flag latched there with no read left alive.

A visible remount self-heals, but a hidden pane does not: the dashboard
card resolves the encoding for any pane key regardless of visibility.

Release the capability from whichever exit ends the read, and say in the
entry's own doc comment that the flag is Shift+Enter-scoped.

* test(terminal): pin the remaining capability-release exits

dispose and the command-finished exit were covered; the visible-bind and
command-start variants are the same three-line pattern and were not.
Neutering the release now kills all four.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
(cherry picked from commit 59892a2)
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>
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…lyai#13598)

* fix(terminal): preserve Shift+Enter during routing confirmation

Keep previously trusted CSI-u routing active only while local foreground revalidation is pending. Clear pending authority on inconclusive reads and never promote display-only identity.\n\nRefs stablyai#12541\nRefs stablyai#13597

* fix(terminal): respect global WSL routing gate

* fix(terminal): bound the retained routing capability to a live read

Two holes in the previous commit let one provider read authorize CSI-u
indefinitely.

First, routingConfirmationPending satisfied its own precondition, so a
pending entry re-published itself on every reconfirmation request. Only
one of the five callers is the Shift+Enter burst timer; the others fire
on accepted submit/interrupt bytes, focus and visibility changes, and
onAgentExited -- the last of which runs precisely when a shell title
proves the agent is gone. On cmd.exe and Git Bash there is no OSC
boundary to publish over the entry, so nothing decayed it.

Second, the flag was published even when no confirmation read was
actually scheduled -- a hidden pane, a command read already in flight, or
a null pty id -- and only the read's inconclusive settle clears it.

Require routingTrusted to grant the capability, and publish the flag only
after sampling reports a read in flight, so it cannot outlive the read
that justifies it. This also makes the canConfirmRouting gate redundant:
the tracker already refuses WSL, SSH and remote pty ids.

* review round 2: bound the retained capability to any in-flight read

onVisiblePtyBound refuses to schedule while a higher-authority command
read owns the pane, so gating the pending publish on it mistook 'a
command-finished read already owns this' for 'no read at all' and
dropped CSI-u for >=350ms — the window stablyai#13598 exists to close.

Ask the tracker whether any read is in flight instead, and settle the
visible confirmation from the command-finished branch that publishes
nothing, so the flag cannot outlive the read that justifies it.

* review round 2: tighten the reconfirmation gate and its comments

hasReadInFlight already covers the visible-pty read that
visibleForegroundSamplePending tracked, so the disjunction was
redundant. Collapse the stacked Why blocks into one.

* review round 3: release the retained capability when a read is abandoned

Every outcome path now clears routingConfirmationPending, but the two
abort guards in readForeground return without publishing or settling. A
pty rebind during the multi-second inspection RPC — a detach/remount
emits no onExit, so the store entry survives — therefore stranded the
flag permanently, leaving Shift+Enter on CSI-u with nothing left to
revalidate it. Worse, once sampling is suppressed by a live hook row the
pane routes bytes on hook evidence alone, which the resolver excludes
precisely because PTY output can forge it.

Settle an abandoned read unless a newer generation will settle for it.

* review round 4: release the retained capability at every exit without a successor

Rounds 2 and 3 closed the outcome paths and the aborted-read paths, but
two review lanes independently proved a third: cancelPendingRead bumps
the generation, so a cancel never settles, and dispose plus the three
untrackable early returns schedule no successor to settle for them. The
store entry outlives the tracker — detach/remount emits no PTY exit — so
the flag latched there with no read left alive.

A visible remount self-heals, but a hidden pane does not: the dashboard
card resolves the encoding for any pane key regardless of visibility.

Release the capability from whichever exit ends the read, and say in the
entry's own doc comment that the flag is Shift+Enter-scoped.

* test(terminal): pin the remaining capability-release exits

dispose and the command-finished exit were covered; the visible-bind and
command-start variants are the same three-line pattern and were not.
Neutering the release now kills all four.

---------

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>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#13598)

* fix(terminal): preserve Shift+Enter during routing confirmation

Keep previously trusted CSI-u routing active only while local foreground revalidation is pending. Clear pending authority on inconclusive reads and never promote display-only identity.\n\nRefs stablyai#12541\nRefs stablyai#13597

* fix(terminal): respect global WSL routing gate

* fix(terminal): bound the retained routing capability to a live read

Two holes in the previous commit let one provider read authorize CSI-u
indefinitely.

First, routingConfirmationPending satisfied its own precondition, so a
pending entry re-published itself on every reconfirmation request. Only
one of the five callers is the Shift+Enter burst timer; the others fire
on accepted submit/interrupt bytes, focus and visibility changes, and
onAgentExited -- the last of which runs precisely when a shell title
proves the agent is gone. On cmd.exe and Git Bash there is no OSC
boundary to publish over the entry, so nothing decayed it.

Second, the flag was published even when no confirmation read was
actually scheduled -- a hidden pane, a command read already in flight, or
a null pty id -- and only the read's inconclusive settle clears it.

Require routingTrusted to grant the capability, and publish the flag only
after sampling reports a read in flight, so it cannot outlive the read
that justifies it. This also makes the canConfirmRouting gate redundant:
the tracker already refuses WSL, SSH and remote pty ids.

* review round 2: bound the retained capability to any in-flight read

onVisiblePtyBound refuses to schedule while a higher-authority command
read owns the pane, so gating the pending publish on it mistook 'a
command-finished read already owns this' for 'no read at all' and
dropped CSI-u for >=350ms — the window stablyai#13598 exists to close.

Ask the tracker whether any read is in flight instead, and settle the
visible confirmation from the command-finished branch that publishes
nothing, so the flag cannot outlive the read that justifies it.

* review round 2: tighten the reconfirmation gate and its comments

hasReadInFlight already covers the visible-pty read that
visibleForegroundSamplePending tracked, so the disjunction was
redundant. Collapse the stacked Why blocks into one.

* review round 3: release the retained capability when a read is abandoned

Every outcome path now clears routingConfirmationPending, but the two
abort guards in readForeground return without publishing or settling. A
pty rebind during the multi-second inspection RPC — a detach/remount
emits no onExit, so the store entry survives — therefore stranded the
flag permanently, leaving Shift+Enter on CSI-u with nothing left to
revalidate it. Worse, once sampling is suppressed by a live hook row the
pane routes bytes on hook evidence alone, which the resolver excludes
precisely because PTY output can forge it.

Settle an abandoned read unless a newer generation will settle for it.

* review round 4: release the retained capability at every exit without a successor

Rounds 2 and 3 closed the outcome paths and the aborted-read paths, but
two review lanes independently proved a third: cancelPendingRead bumps
the generation, so a cancel never settles, and dispose plus the three
untrackable early returns schedule no successor to settle for them. The
store entry outlives the tracker — detach/remount emits no PTY exit — so
the flag latched there with no read left alive.

A visible remount self-heals, but a hidden pane does not: the dashboard
card resolves the encoding for any pane key regardless of visibility.

Release the capability from whichever exit ends the read, and say in the
entry's own doc comment that the flag is Shift+Enter-scoped.

* test(terminal): pin the remaining capability-release exits

dispose and the command-finished exit were covered; the visible-bind and
command-start variants are the same three-line pattern and were not.
Neutering the release now kills all four.

---------

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 Shift+Enter can submit while routing confirmation is pending

4 participants