fix(launch): wait for idle before tmux attach on non-headless launch …#221
Merged
Conversation
…220) Addresses issue #220. cao launch (non-headless) attached to the tmux session the moment the API returned, before the provider's TUI had finished wiring its input handler. The attach-time pty resize would then race with init and the TUI would silently drop keystrokes — most visible on profiles with many MCP servers where init takes longer. The headless-with-message path already waits via wait_until_terminal_status(IDLE/COMPLETED, timeout=120). This change mirrors that wait on the non-headless path. When the wait times out we still attach so the user can inspect a slow-initializing session rather than orphan it in tmux; a yellow warning is printed. With PR #215 (false-IDLE during Initializing...) already landed, this wait reliably blocks through init instead of returning early on the idle-prompt placeholder. Changes - src/cli_agent_orchestrator/cli/commands/launch.py: insert wait_until_terminal_status before subprocess.run(["tmux", "attach-session", ...]) with a warn-and-proceed fallback on timeout. - test/cli/commands/test_launch.py: add regression guards (test_launch_non_headless_waits_for_idle_before_attach, test_launch_non_headless_attaches_even_if_wait_times_out); update the four existing non-headless tests to patch wait_until_terminal_status and include the terminal id in their mocked API response. Verification - 21/21 test/cli/commands/test_launch.py - 1523 passed, 1 skipped under CI's ignore set - black --check and isort --check-only clean on touched files
Contributor
Author
|
@carlosiduarte can you pls help to check this fix ? |
carlosiduarte
approved these changes
Apr 30, 2026
carlosiduarte
left a comment
There was a problem hiding this comment.
Thanks @haofeif! This is exactly the fix we've been running locally — confirmed it resolves the input-drop race on non-headless launch. LGTM ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #220.
Problem
cao launch(non-headless) attached to the tmux session the moment the API returned, before the provider's TUI had finished wiring its input handler. The attach-time pty resize would race with init and the TUI silently dropped keystrokes — most visible on agents with many MCP servers where init takes longer.Root cause
cli/commands/launch.pyhad asymmetric wait semantics:The headless-with-message path already had the wait. The non-headless path needed the same guard.
Fix
Add
wait_until_terminal_statusbeforetmux attach-session:The wait is advisory — on timeout we warn and still attach, because orphaning a slow-initializing session in tmux is worse than letting the user watch it come alive.
Why this is reliable now
PR #215 (false-IDLE during
Initializing...) already landed, which meanswait_until_terminal_statusactually blocks through init instead of returning early on the idle-prompt placeholder that kiro-cli's TUI v2 paints before init completes.Relationship to recent fixes
Initializing...to prevent false IDLE during initAll three address the same symptom (input dropped after launch) from different angles. They compose cleanly.
Changes
src/cli_agent_orchestrator/cli/commands/launch.pywait_until_terminal_statusbeforesubprocess.run(["tmux", "attach-session", ...])with a warn-and-proceed fallback on timeout.test/cli/commands/test_launch.pytest_launch_non_headless_waits_for_idle_before_attach— asserts the wait is called with the terminal id and runs before the attach.test_launch_non_headless_attaches_even_if_wait_times_out— asserts warn-and-proceed on timeout.wait_until_terminal_statusand include the terminal id in their mocked API response (previously the mock dict omittedid, which would now KeyError on the real code path).Provider-agnostic
Although #220 was filed for kiro-cli, the wait applies to every provider. opencode_cli and others with slow TUI init also benefit.
Verification
uv run pytest test/cli/commands/test_launch.py -q— 21/21 pass--ignore=test/providers/test_q_cli_integration.py --ignore=test/providers/test_kiro_cli_integration.py --ignore=test/e2e -m "not e2e") — 1523 passed, 1 skippedblack --check src/.../launch.py test/.../test_launch.py— cleanisort --check-only src/.../launch.py test/.../test_launch.py— cleanTest plan
cao launchwaits for IDLE before attachcao launch --agents developer --yoloon a profile with multiple MCP servers — keystrokes land reliably after attach