Skip to content

fix(tui): auto-undo interrupted prompt when turn has no output#553

Open
MicroGery wants to merge 3 commits into
MoonshotAI:mainfrom
MicroGery:feat/user-cancel-improvements
Open

fix(tui): auto-undo interrupted prompt when turn has no output#553
MicroGery wants to merge 3 commits into
MoonshotAI:mainfrom
MicroGery:feat/user-cancel-improvements

Conversation

@MicroGery

@MicroGery MicroGery commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Resolve part of #481

Problem

When the user interrupts a turn (Esc or Ctrl-C) before the model has produced any substantial content, the prompt is now automatically withdrawn from the transcript and its text is restored to the editor.

Previously, interrupting during the model's "thinking" phase only cancelled the stream — the prompt stayed in the context. The user would then type a new prompt, and the model would see both the abandoned one and the new one stitched together. This addresses that case from #481.
image

What changed

A semantic guard scans the current turn before undoing:

  • If an assistant message with non-empty text, or any tool_call, already exists in this turn → cancel only stops the stream, prompt stays (unchanged behavior).
  • If nothing substantial was produced yet → withdraw the prompt and refill its text into the editor.

Esc and Ctrl-C share identical semantics here — both are user-initiated interrupts, so the decision rests solely on the guard, not on which key was pressed.

The transcript-cleanup logic was extracted from handleUndoCommand into a reusable applyUndoToTranscriptState, shared by the new auto-undo path.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e375ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@7e375ed
npx https://pkg.pr.new/@moonshot-ai/kimi-code@7e375ed

commit: 7e375ed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9897231f7b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/controllers/session-event-handler.ts Outdated
Comment thread apps/kimi-code/src/tui/controllers/session-event-handler.ts Outdated
When the user interrupts a turn (Esc or Ctrl-C) before the model has
produced any substantial content, automatically withdraw the prompt
from the transcript and restore its text to the editor.

A semantic guard scans the current turn: if an assistant message with
non-empty text or any tool_call already exists, the cancel only stops
the stream and leaves the prompt in place (unchanged behavior). Esc and
Ctrl-C share the same semantics -- both are user-initiated interrupts, so
the decision rests solely on the guard, not on which key was pressed.

Extracts the transcript-cleanup logic from handleUndoCommand into a
reusable applyUndoToTranscriptState so the auto-undo path can share it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MicroGery MicroGery force-pushed the feat/user-cancel-improvements branch from 9897231 to 61f9e0c Compare June 8, 2026 13:49
- Fix semantic guard: check for any assistant entry (not non-empty
  content), since content is flushed into the entry object in place
  and may still be empty at guard evaluation time
- Add four unit tests covering the auto-undo scenarios: no-output
  cancel withdraws prompt and refills editor; streamed text and
  tool_call prevent auto-undo; completed turns are not affected
- Add changeset for @moonshot-ai/kimi-code (minor bump)
- Update en/zh interaction guide and keyboard reference to document
  the new Esc/Ctrl-C behaviour

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MicroGery MicroGery force-pushed the feat/user-cancel-improvements branch from 61f9e0c to 2728e69 Compare June 8, 2026 13:55
@MicroGery MicroGery changed the title bug(tui): auto-undo interrupted prompt when turn has no output fix(tui): auto-undo interrupted prompt when turn has no output Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant