Skip to content

fix(tui): drain background process completion notifications - #26084

Closed
Ade5954 wants to merge 1 commit into
NousResearch:mainfrom
Ade5954:fix/tui-process-completion-notifications
Closed

fix(tui): drain background process completion notifications #26084
Ade5954 wants to merge 1 commit into
NousResearch:mainfrom
Ade5954:fix/tui-process-completion-notifications

Conversation

@Ade5954

@Ade5954 Ade5954 commented May 15, 2026

Copy link
Copy Markdown
Contributor

Root cause: the TUI server (tui_gateway/server.py) never drained process_registry.completion_queue, so notify_on_complete events from background processes were silently lost. CLI mode drains the queue in both its idle loop and after-turn paths; gateway mode uses async watcher tasks. Neither path existed for TUI mode.

Fix: after run_conversation() returns in _run_prompt_submit, drain completion_queue and auto-submit formatted notifications as follow-up turns. Follows the exact same pattern as the existing goal continuation code — release session.running in the outer finally, then re-acquire and call _run_prompt_submit with the synthetic notification text.

Uses _format_process_notification from cli (already imported elsewhere in the TUI server via the same lazy-import pattern).

Why Option 1 (After-turn drain)?

Three approaches were proposed in the issue. Option 1 was chosen because:

  1. Minimal & localized — 37 lines in a single file ( tui_gateway/server.py ). No new threads, no lifecycle management.
  2. Proven pattern — the exact same follow-turn dispatch already exists for goal continuation. Just replicate it.
  3. CLI parity — CLI mode drains completion_queue after each agent turn (cli.py L13264). TUI now does the same.
  4. Right timing — after-turn is the right moment: the agent just finished a turn, so it's ready to learn about completed background processes.
  5. Cheap — the queue is almost always empty; no polling overhead.
    Option 2 (polling thread) was rejected as over-engineering. Option 3 (shared helper) was unnecessary since _format_process_notification from cli.py is already importable directly.

How the Fix Works

After run_conversation() returns in _run_prompt_submit :

  1. Drain process_registry.completion_queue
  2. Skip events already consumed by wait() / poll() / log() (prevents duplicates)
  3. Format each completion into a [IMPORTANT: ...] message using _format_process_notification() from cli.py
  4. Dispatch as a synthetic follow-up turn via _run_prompt_submit — same lock/release pattern as goal continuation
  5. If session is already busy (user jumped in mid-drain), put the event back and break — it'll be picked up on the next turn

Related Issue

Closes #26071

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

…h turn

Root cause: the TUI server (tui_gateway/server.py) never drained
process_registry.completion_queue, so notify_on_complete events
from background processes were silently lost.  CLI mode drains the
queue in both its idle loop and after-turn paths; gateway mode uses
async watcher tasks.  Neither path existed for TUI mode.

Fix: after run_conversation() returns in _run_prompt_submit, drain
completion_queue and auto-submit formatted notifications as follow-up
turns.  Follows the exact same pattern as the existing goal continuation
code — release session.running in the outer finally, then re-acquire
and call _run_prompt_submit with the synthetic notification text.

Uses _format_process_notification from cli (already imported elsewhere
in the TUI server via the same lazy-import pattern).

Closes NousResearch#26071
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) tool/terminal Terminal execution and process management labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #26327 (merged). Thanks for the initial approach — the merged PR builds on it with an autonomous poller thread in addition to the after-turn drain.

@alt-glitch alt-glitch closed this May 15, 2026
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/) P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

notify_on_complete notifications silently lost in TUI mode

2 participants