Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ccfb598
fix(cli): let ESC cancel ongoing work before popping queued messages
C0d3N1nja97342 Aug 2, 2026
556a8aa
fix: narrow ESC fall-through to empty buffer + add regression tests
C0d3N1nja97342 Aug 2, 2026
06592cb
fix: correct ESC comment to reflect KeypressContext broadcast model
C0d3N1nja97342 Aug 2, 2026
427bd96
fix: correct comment to accurately describe return false -> BaseTextI…
C0d3N1nja97342 Aug 2, 2026
26c6927
test(ui): add positive AppContainer ESC cancel regression test
C0d3N1nja97342 Aug 3, 2026
d2dceb6
test(ui): clarify ESC cancel test scope vs end-to-end drain
C0d3N1nja97342 Aug 3, 2026
4cfcb9a
test(ui): pin ESC return-false branch and dedupe getGlobalKeypress
C0d3N1nja97342 Aug 4, 2026
b82068a
test(ui): escape raw ESC byte in cancel test fixture
C0d3N1nja97342 Aug 4, 2026
e8dd99b
Merge remote-tracking branch 'upstream/main' into fix/esc-cancel-work…
C0d3N1nja97342 Aug 4, 2026
ef3d6c2
Merge branch 'main' into fix/esc-cancel-work-while-responding
wenshao Aug 4, 2026
8487882
test(ui): assert buffer stays empty on ESC cancel + fix test comment
C0d3N1nja97342 Aug 4, 2026
9c04426
test(ui): cover queue+text ESC and double-ESC-clear while responding
C0d3N1nja97342 Aug 5, 2026
3f24262
test(ui): dedupe escKey fixture and tighten double-ESC timing
C0d3N1nja97342 Aug 5, 2026
e31d4aa
test(ui): add missing removeGoalTurns to cancel-handler queue mock
C0d3N1nja97342 Aug 5, 2026
045c827
test(ui): reuse getGlobalKeypress in vim-INSERT cancel test
C0d3N1nja97342 Aug 5, 2026
43e89c4
test+docs(ui): escape ESC byte in shared fixture and document Respond…
C0d3N1nja97342 Aug 5, 2026
1ac1d27
docs(ui): correct ESC/Up-Arrow queue-pop description to match code
C0d3N1nja97342 Aug 5, 2026
42017c6
Merge branch 'main' into fix/esc-cancel-work-while-responding
wenshao Aug 6, 2026
e83cbf3
refactor(ui): drop dead Responding ESC guard per maintainer review
C0d3N1nja97342 Aug 6, 2026
8cdf2e0
docs(ui): correct four review comments in ESC cancel path
C0d3N1nja97342 Aug 6, 2026
05a4aa0
docs(ui): correct subscription-order and double-ESC-cancel comments
C0d3N1nja97342 Aug 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/cli/src/ui/components/InputPrompt.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js
import stripAnsi from 'strip-ansi';
import { renderSoftwareCursor } from '../utils/software-cursor.js';
import { useUIState } from '../contexts/UIStateContext.js';
import { StreamingState } from '../types.js';
import { useUIActions } from '../contexts/UIActionsContext.js';
import {
useAgentViewActions,
Expand Down Expand Up @@ -5689,6 +5690,58 @@ describe('InputPrompt', () => {
unmountEdited();
});
});

describe('ESC during active agent response (#8201)', () => {
it('does not pop queued messages into input when responding', async () => {
mockedUseUIState.mockReturnValue({
isFeedbackDialogOpen: false,
messageQueue: ['queued message'],
pendingGeminiHistoryItems: [],
streamingState: StreamingState.Responding,
} as unknown as ReturnType<typeof useUIState>);
const mockPopAllQueued = vi.fn(() => null);
mockedUseUIActions.mockReturnValue({
handleRetryLastPrompt: vi.fn(),
temporaryCloseFeedbackDialog: vi.fn(),
popAllQueuedMessages: mockPopAllQueued,
invalidateSubmittedPromptProvenance: vi.fn(),
} as unknown as ReturnType<typeof useUIActions>);

const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
);
await wait();

stdin.write('\x1B');
await wait();

// popAllQueuedMessages must NOT be called when agent is responding
expect(mockPopAllQueued).not.toHaveBeenCalled();
unmount();
});

it('does not silently clear typed input on single ESC when responding', async () => {
mockedUseUIState.mockReturnValue({
isFeedbackDialogOpen: false,
messageQueue: [],
pendingGeminiHistoryItems: [],
streamingState: StreamingState.Responding,
} as unknown as ReturnType<typeof useUIState>);

props.buffer.setText('half typed message');
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
);
await wait();

stdin.write('\x1B');
await wait();

// Buffer must NOT be cleared - double-ESC confirmation still applies
expect(props.buffer.text).toBe('half typed message');
unmount();
});
});
});
function clean(str: string | undefined): string {
if (!str) return '';
Expand Down
31 changes: 28 additions & 3 deletions packages/cli/src/ui/components/InputPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useFollowupSuggestionsCLI } from '../hooks/useFollowupSuggestions.js';
import type { Key } from '../hooks/useKeypress.js';
import { keyMatchers, Command } from '../keyMatchers.js';
import type { CommandContext, SlashCommand } from '../commands/types.js';
import { StreamingState } from '../types.js';
import {
ApprovalMode,
type Config,
Expand Down Expand Up @@ -1197,16 +1198,40 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
return true;
}

// Pop queued messages into input on ESC (before double-ESC clear)
if (!isAttachmentMode && uiState.messageQueue.length > 0) {
// Pop queued messages into input on ESC (before double-ESC clear).
// Skip when the agent is actively responding: popQueueIntoInput()
// fills the shared buffer, which makes AppContainer's broadcast ESC
// handler take its "input has content -> double-press to clear"
// branch instead of the cancel-work branch. #8201.
if (
!isAttachmentMode &&
uiState.messageQueue.length > 0 &&
uiState.streamingState !== StreamingState.Responding
) {
if (popQueueIntoInput()) {
resetEscapeState();
return true;
}
// returned false (queue already cleared) — fall through
}

// Handle double ESC for clearing input
// Handle double ESC for clearing input.
// When the agent is actively responding AND the input buffer is
// empty, defer to AppContainer's broadcast ESC handler so it takes
// its cancel-work branch (KeypressContext broadcasts to all handlers
// regardless of this return value; returning false here simply avoids
// BaseTextInput's default ESC wiping the buffer, which would have
// already been empty anyway). Gate on empty buffer to prevent
// BaseTextInput's default ESC from silently wiping typed input
// without the double-press confirmation. #8201.
if (
uiState.streamingState === StreamingState.Responding &&
buffer.text === ''
) {
resetEscapeState();
return false;
}

if (escPressCount === 0) {
if (buffer.text === '') {
return true;
Expand Down
Loading