Skip to content

fix(tui): undo latest pending prompt - #41344

Closed
kitlangton wants to merge 1 commit into
v2from
undo-pending-latest
Closed

fix(tui): undo latest pending prompt#41344
kitlangton wants to merge 1 commit into
v2from
undo-pending-latest

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Make /undo remove the newest pending user prompt before reverting projected session history. This applies equally to queued and steering follow-ups and restores the removed prompt to the composer.

Fixes #39736.

Before / After

Before

  1. A queued or steering follow-up was admitted and shown optimistically while a response was active.
  2. /undo selected that user message but sent it to the history revert endpoint.
  3. Because the input had not been promoted into history, revert failed with MessageNotFoundError and the pending prompt remained.

After

  1. /undo selects the newest pending user input by admission order.
  2. It cancels that input through the existing durable pending-input endpoint and restores its content to the composer.
  3. If promotion wins the cancellation race, the expected conflict falls back to normal history revert.
  4. With no pending user input, /undo retains its existing projected-history behavior.

How

  • packages/tui/src/routes/session/index.tsx prioritizes pendingUsers() when selecting the undo target.
  • packages/tui/src/routes/session/undo.ts routes pending targets to cancellation and handles only the expected promotion conflict as a revert fallback.
  • packages/tui/test/cli/tui/undo.test.ts covers projected, pending, promotion-race, and transport-failure paths.

Scope

  • Uses the existing session.pending.cancel API and session.input.cancelled event; no protocol or core lifecycle changes.
  • Synthetic pending inputs and compaction barriers remain untouched.
  • Redo remains specific to staged history reverts; cancelling a pending prompt does not create a redo boundary.

Testing

  • packages/tui: bun run test, 612 passed and 5 skipped.
  • packages/tui: bun typecheck.
  • Push hook: repository Turbo typecheck, 33 packages passed.
  • OpenCode Drive scripted TUI walkthrough with a simulated model, covering queued cancellation, steering cancellation, and projected-history revert.

Demo

The recording uses OpenCode Drive with a simulated streaming model. The first two /undo actions remove and restore a steering prompt, then a queued prompt. After streaming completes, the third /undo follows the existing history-revert path and displays 1 message reverted.

recording-89a775d2-ff93-4bb1-8746-a66298ebc869.mp4

Flow

flowchart TD
    Undo[/undo/] --> Pending{Pending user input?}
    Pending -->|Yes| Cancel[Cancel newest pending input]
    Cancel --> Conflict{Already promoted?}
    Conflict -->|No| Restore[Restore prompt to composer]
    Conflict -->|Yes| Revert[Stage history revert]
    Pending -->|No| Revert
    Revert --> Restore
Loading

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant