Skip to content

fix(tests): reap leaked TUI notification pollers between tests - #86427

Merged
teknium1 merged 1 commit into
mainfrom
fix/tui-poller-test-leak
Aug 14, 2026
Merged

teknium1 merged 1 commit into
mainfrom
fix/tui-poller-test-leak

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Summary

Kills the flaky test_run_prompt_submit_requeues_all_unstarted_notifications_with_real_threading — it failed on CI twice in one hour on two unrelated PRs (#86371, #86374) with assert set() == {'proc_batch_2', 'proc_batch_3'} while passing locally 14/14.

Root cause: session.init/create tests earlier in the file start real per-session notification poller daemon threads and never stop them. Leaked pollers keep polling the process-global process_registry.completion_queue and steal-and-requeue the target test's events mid-assertion, starving its bounded drain loop.

Reproduced deterministically-ish: 30 leaked foreign-session pollers injected via a sabotage conftest → target test fails standalone ~1 in 3 with the exact CI assertion; with the reap fixture active it passed 8/8 under the same sabotage.

Changes

  • tui_gateway/server.py: _start_notification_poller() registers (stop_event, thread) in a module-level _notification_pollers list (dead entries pruned on each spawn); poller threads get a stable tui-notif-poller-<sid> name.
  • tests/test_tui_gateway_server.py: autouse fixture sets every registered live poller's stop event after each test and joins under ONE shared 3s budget. No per-thread timeouts, no session-dict mutation (a first draft that did both hung the file).

Validation

Before After
target test with 30 leaked pollers fails ~1 in 3 8/8 pass
full file (scripts/run_tests.sh) 13.2s baseline 555/555 in 16.1s
CI hits on unrelated PRs 2 in one hour poller leak class removed

Infographic

Ghost threads reaped between tests

test_run_prompt_submit_requeues_all_unstarted_notifications_with_real_threading
failed twice in one hour on CI slices for two UNRELATED PRs (86371,
86374) with `assert set() == {proc_batch_2, proc_batch_3}`. Root cause:
session.init/create tests earlier in the file start real per-session
notification poller daemon threads and never stop them. Those pollers
outlive their test and keep polling the PROCESS-GLOBAL
process_registry.completion_queue, stealing-and-requeuing the target
test's events mid-assertion so its bounded drain loop can starve.

Reproduced: with 30 leaked foreign-session pollers injected via a
sabotage conftest, the target test fails standalone ~1 in 3 runs with
the exact CI assertion; with the reap fixture active it passed 8/8
under the same sabotage.

Fix:
- tui_gateway/server.py: _start_notification_poller registers
  (stop_event, thread) in module-level _notification_pollers (pruned of
  dead threads on each spawn; threads get a stable
  tui-notif-poller-<sid> name for debugging).
- tests/test_tui_gateway_server.py: autouse fixture sets every
  registered live poller's stop event after each test and joins them
  under ONE shared 3s budget (the poller loop wakes at least every
  0.5s), so no poller survives into the next test. No per-thread
  timeout, no session-dict mutation — a first draft that mutated
  session state and joined per-thread hung the file; full-file runtime
  with this version is 15.2s vs 13.2s baseline.
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on ce6786e — fix(tests): reap leaked TUI notification pollers between tes

⚠️ Warnings

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 3m13s vs 6m6s (-47.3%). 13 job(s) slower, 8 faster, 3 unchanged.

  • OS-specific tests / Windows-only tests: +117.0s
  • Python tests / Run tests slice 3/12: -58.0s
  • Python tests / Run tests slice 11/12: -36.0s
  • Python tests / Run tests slice 10/12: +24.0s
  • Python tests / Run tests slice 4/12: +22.0s

@alt-glitch alt-glitch added type/test Test coverage or test infrastructure comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have labels Aug 14, 2026
@teknium1
teknium1 merged commit 452465b into main Aug 14, 2026
48 checks passed
@teknium1
teknium1 deleted the fix/tui-poller-test-leak branch August 14, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants