Skip to content

fix(kiro_cli): detect TUI Initializing... to prevent false IDLE (#211)#215

Merged
haofeif merged 1 commit into
mainfrom
fix/kiro-cli-tui-initializing-false-idle
Apr 28, 2026
Merged

fix(kiro_cli): detect TUI Initializing... to prevent false IDLE (#211)#215
haofeif merged 1 commit into
mainfrom
fix/kiro-cli-tui-initializing-false-idle

Conversation

@haofeif

@haofeif haofeif commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #211. The new Kiro CLI TUI renders the idle-prompt placeholder (Ask a question or describe a task) before the ● Initializing... phase completes. CAO's get_status() matched the placeholder and declared IDLE ~1s into launch, so the first user message was sent before Kiro could accept input — the message was silently dropped and the session appeared stuck.

Root cause

get_status() had three processing-related checks:

  1. TUI_PROCESSING_PATTERN (Kiro is working) — position-aware (lingers as ghost text in buffer after in-place redraws).
  2. Idle-prompt presence check — if absent, return PROCESSING.
  3. Default IDLE.

Nothing covered the startup phase: the TUI paints the full layout (separator, agent header, idle-prompt line) while Initializing... is still animating, so the naive idle match fires and the caller sees IDLE before Kiro is ready.

Fix

Add TUI_INITIALIZING_PATTERN = r"Initializing\.\.\." and check for it at the top of get_status() — before any idle-prompt match. Unlike Kiro is working, Initializing... is always cleared by Kiro once startup completes, so its presence unconditionally means PROCESSING. No position-aware logic needed.

Failing session (before fix)

19:43:16 - send_keys: kiro-cli chat --agent agent-ops
19:43:17 - Waiting for {idle, completed}, status: PROCESSING
19:43:18 - Waiting for {idle, completed}, status: IDLE        ← false IDLE
19:43:28 - ERROR: No Kiro CLI response found - no Credits marker or green arrow detected

After fix

19:55:08 - send_keys: kiro-cli chat --model claude-sonnet-4.6 --agent agent-ops
19:55:08 - PROCESSING
19:55:09 - PROCESSING    ← correctly stays PROCESSING during Initializing
19:55:11 - IDLE          ← real IDLE after init completed (~3s)

Changes

src/cli_agent_orchestrator/providers/kiro_cli.py:

  • Add TUI_INITIALIZING_PATTERN constant with a comment explaining the asymmetry with Kiro is working.
  • In get_status(), add a pre-idle check: if Initializing... is present anywhere in the buffer, return PROCESSING.

test/providers/test_kiro_cli_unit.py:

  • test_tui_initializing_yields_processing_despite_idle_placeholder — reproduces issue fix(kiro_cli): false IDLE detection during TUI initialization #211: buffer contains Initializing... + separator + idle-prompt placeholder, must return PROCESSING.
  • test_tui_initializing_cleared_allows_idle — once Initializing... is gone, IDLE resolves normally.
  • test_tui_initializing_pattern — pattern matches expected forms; rejects bare Initializing / Initialized to avoid false positives on agent output.

Test plan

  • test/providers/test_kiro_cli_unit.py passes (94 tests, +3 new)
  • Full unit/integration suite passes (1522 passed, 14 skipped)
  • black --check clean on changed files
  • Live cao launch on a fresh kiro-cli 2.x session: first user message arrives after the real idle, not during Initializing...

The new Kiro CLI TUI renders the idle-prompt placeholder ("Ask a
question or describe a task") before the "● Initializing..." phase
completes. CAO's get_status() matched the placeholder and declared IDLE
~1s into launch, so the first user message was sent before Kiro could
accept input and was silently dropped.

Add TUI_INITIALIZING_PATTERN and check for it before the idle check in
get_status(). Unlike "Kiro is working" (which lingers as ghost text after
in-place redraws and needs position-aware handling), "Initializing..."
is always cleared once startup finishes, so its presence unconditionally
means PROCESSING.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@haofeif

haofeif commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@ci-duarte would you like to review ?

@carlosiduarte carlosiduarte left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix! I was able to reproduce the false IDLE issue — the TUI renders the idle prompt placeholder before Initializing... completes, causing CAO to send the first message too early and the session to appear stuck. This fix correctly blocks IDLE detection while the initializing indicator is present. Tested locally and confirmed it works. 🙌

@haofeif haofeif merged commit 0c73f52 into main Apr 28, 2026
21 checks passed
@haofeif haofeif deleted the fix/kiro-cli-tui-initializing-false-idle branch April 28, 2026 13:04
haofeif added a commit that referenced this pull request Apr 30, 2026
…220) (#221)

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
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.

fix(kiro_cli): false IDLE detection during TUI initialization

2 participants