Skip to content

fix(test): wait for the TUI to be idle before the next input and drain the pty before asserting (#877) - #881

Merged
ajianaz merged 2 commits into
developfrom
fix/flaky-tui-and-stress-tests
Nov 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/flaky-tui-and-stress-tests

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes the intermittent failures of the TUI pty e2e tests (tui_streams_approves_cancels_and_leaves_an_ordinary_session, tui_steers_queues_and_returns_the_queue_on_cancel) and a third race in tui_bracketed_paste_is_one_block_that_waits_for_enter. Test code only; no product change.

Why

Root cause, reproduced under taskset -c 0 with busy loops and high --test-threads:

  1. The answer text (STREAM-ANSWER) renders before the turn's Msg::Done is processed, so running is still true when the test sends its next input.
  2. A prompt typed while running goes through the steer path instead of starting a turn. In the streams test, slow\r steered the finishing turn, expect("working") matched a stale frame, Esc cancelled an already-finished turn, the steered text ran as a fresh 20 s turn, and (turn cancelled) never rendered (60 s timeout).
  3. /quit is ignored while a turn runs, so in the steers test the quit was lost and wait_exit() timed out.
  4. wait_exit returned as soon as the child exited, before the pty reader thread had copied the child's last output, so the bracketed-paste restore assertion (\x1b[?2004l) raced it.

Changes

  • idle() (the idle hint, rendered only when running is false) is awaited before the next prompt and before /quit at four points in the two cancel-family tests.
  • Pty gets an eof flag set by the reader thread; wait_exit waits for it after the child exits (same 60 s bound; expiry is not masked because the caller's assertion still checks the content).
  • No assertion loosened, no fixed sleeps added.

Testing

Stress runs of the whole tui_e2e binary under taskset -c 0 plus busy loops:

Condition Before After
1 stream, --test-threads 16 4/15 runs failed (1x quit lost, 3x paste) 0/30
paste test, same condition 3/12 0/30
3 parallel streams x 25, --test-threads 32 4/75 (1x cancel timeout, 2x quit lost, 1x startup stall) 0/75
3 parallel streams x 40, after fix n/a 0/120

Refs #877, #702, #712, #738

…pty EOF after exit

The TUI pty e2e tests sent the next prompt, /quit or Esc as soon as the
answer text appeared, but the answer lands before the turn is over. A prompt
typed then steers the running turn instead of starting one (the Esc then
cancels a finished turn and (turn cancelled) never renders), and /quit is
ignored while a turn runs (wait_exit times out). wait_exit also returned
before the pty reader thread had copied the child's last output, so the
bracketed-paste restore assertion raced it.

Wait for the idle hint before each next input and for the reader's EOF after
the child exits. Waits stay event based with the shared 60 s bound; nothing
an assertion checks is loosened.

Refs #877
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

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.

2 participants