Skip to content

fix(tui): keep Next cancel and quit working under an event flood - #450

Open
BunsDev wants to merge 1 commit into
test/411-approval-edgesfrom
test/408-event-flood
Open

BunsDev wants to merge 1 commit into
test/411-approval-edgesfrom
test/408-event-flood

Conversation

@BunsDev

@BunsDev BunsDev commented Nov 4, 2026

Copy link
Copy Markdown
Member

Summary

Sends a real flood of text deltas through the real client and query loop, and fixes the two problems it found in Next. Classic's behaviour is unchanged.

Problem Before After
Quitting during a running turn Nothing from that turn was saved. In a new conversation that meant no session file at all, so the prompt and the partial answer were both gone. The turn is stopped, then the prompt and what it delivered so far are saved.
Deltas still queued when a turn is cancelled Each one restarted the turn on screen, so further Ctrl+C presses cancelled again and never reached the exit sequence. They no longer touch the screen. Ctrl+C reaches the exit sequence straight away.

The second fix also makes a cancelled flood much cheaper (release build, Next, one host, 120x40, 1,000,000 deltas, 2 runs each):

main b3c952f This branch
Settled after Escape 16.5-17.4 s 7.2 s
RSS after settling about 1.7 GB 330-363 MB
Typed key painted during the burst 29-33 ms 30-31 ms
Escape acknowledged 30-36 ms 39-44 ms

Two runs are too few to read anything into the Escape difference, and these rates are far beyond any real provider.

Context

Behaviour to check

  • Quitting can now take up to 2 seconds longer. The terminal is handed back first, then the process waits up to 2 s for the turn to stop. A cancelled flood stops at once. A running sleep did not react to cancellation: exit took about 2.3 s against 0.3 s on main, and only the prompt was saved because the tool had produced no result yet. The tool did not finish after quit, on either build.
  • Ctrl+C and Ctrl+D do nothing while an approval panel is open. Both were tried: the process stays open and the tool does not run. Answer the panel first. This PR doesn't change that, but it means the exit path isn't reached with a panel open through those keys.

Docs

docs/keybindings.md said one Ctrl+D exits and that it signals EOF when the prompt has content. It takes two presses within 2 seconds, and it does nothing while the prompt has content. docs/commands.md said unsaved state is flushed on exit, which wasn't true of a running turn. It now says what each renderer does.

Validation

  • Failing first: deltas_still_queued_when_a_turn_is_cancelled_cannot_restart_it, and the two "keeps the prompt" and "keeps the partial answer" checks, failed before their fixes.
  • Control: with the delta guard disabled on a debug build, exactly the three "Ctrl+C twice more" checks fail and the other 16 pass.
  • scripts/tui-tests/run.sh event_flood: 19 passed, 0 failed.
  • cargo fmt --all --check, cargo clippy --workspace --all-targets --locked -- -D warnings.
  • cargo test --workspace --locked: 2916 passed, 0 failed.
  • Full tmux suite: 145 passed, 0 failed. The flood case also passed on its own under bash and zsh.
  • Test scripts' unit tests pass, and git diff --check is clean.

Not tested: Windows, Linux, or a real provider. On a fast release build a 300,000-delta burst can settle before the later Ctrl+C presses, so that part of the case only has teeth on a debug build, which is what tui-tests.yml runs. The unit test covers the same logic on any build.

Quitting during a running turn saved nothing from that turn, so a new
conversation lost its prompt and partial answer. Next now stops the
worker, waits up to 2 seconds and saves what it holds.

Deltas still queued after a cancel restarted the turn on screen, so
further Ctrl+C presses cancelled again instead of reaching the exit
sequence. Next now ignores them until the runtime settles, which also
makes a cancelled flood cheaper to drain.

Adds a tmux case that sends a real burst through the client and query
loop, and corrects the docs on how Ctrl+D exits and what is saved.
Classic is unchanged.

Refs #408
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 4, 2026 4:25pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 9ab7a496 Deployed Nov 4, 2026 by vercel[bot]
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