Repository navigation
fix(terminal): preserve Shift+Enter during routing confirmation - #13598
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughForeground-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)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
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.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.tssrc/renderer/src/store/slices/pane-foreground-agent.test.tssrc/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
d8744ae to
b1c89de
Compare
|
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.
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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
2257-2260: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten 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
📒 Files selected for processing (5)
src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.tssrc/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.tssrc/renderer/src/components/terminal-pane/pty-connection-foreground-routing-confirmation.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/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.
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.tssrc/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.
| // 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') | ||
| }) |
There was a problem hiding this comment.
🎯 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.
|
@itisvincent -- on the PRs I made few commits Can you double check that they're good on your end? If so then I can merge (I'll check back tmrw ) |
* 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>
* 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)
…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)
* 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>
…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>
* 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>
…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>
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
requestKnownWindowsShiftEnterReconfirmationrevokes routing and starts an asynchronous provider read. Between those two things the entry was{agent, routingRevoked: true}, which resolves toalt-enter— so during the gap Shift+Enter sentESC CRrather than theCSI 13;2uthe 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
shellOverridethroughresolveWindowsShellOverrideinisForegroundTrackingAllowed, 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:
routingConfirmationPendingsatisfied 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 ononAgentExited, 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.The fix requires
routingTrustedto grant the capability and publishes the flag only after sampling reports a read in flight. That also makes thecanConfirmRoutinggate 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.
onVisiblePtyBounddeliberately returnsfalsewhile 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 exposeshasReadInFlight()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.
cancelPendingReadbumps the read generation before anything can settle, anddispose()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
publishreplacement, 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+enteris bound toapp.message.followUp— "Queue follow-up message", backed by a real_followUpMessagesqueue incore/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:
ESC CR— whatmainsends during the gapCSI 13;2u— what this PR preservesSo 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
terminal-shortcut-policy.tsonly consults the Windows encoding behindisWindowsTerminalHost(), and the routing side is separately gated on a Windows user agent.dashboard-card-terminal-input.tspublisheswindowsShiftEnterEncodingto 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.pi,prime-agentanddroidcarrywindowsShiftEnterEncoding: 'csi-u'; every other agent still resolves toalt-enter. The gate is a pureTUI_AGENT_CONFIGtable lookup, so it is agent-agnostic andpi/droidexercise the identical branch.Known gap, deliberately not fixed here
Ctrl+Enter has the same shape and is not covered.
terminal-ctrl-enter.tsdenies authority onroutingRevoked, andterminal-shortcut-policy.tsfalls 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 typecheckclean; oxlint and oxfmt clean on changed files; max-lines ratchet clean.pty-connectiontest can catch it because the fixture stubs the store action.Takeover notes
Rebased onto current
mainand taken over.pty-connection.test.tsno longer exists onmain(split into per-topic files), so the regressions moved into the topic files that now own them, plus a newpty-connection-foreground-routing-confirmation.test.tsto stay under the 800-line cap without a lint suppression. Original authorship preserved on the first two commits.