Skip to content

fix(shell): show active agent task count in prompt status bar#2041

Merged
wbxl2000 merged 1 commit intomainfrom
fix/shell-agent-task-badge
Apr 24, 2026
Merged

fix(shell): show active agent task count in prompt status bar#2041
wbxl2000 merged 1 commit intomainfrom
fix/shell-agent-task-badge

Conversation

@wbxl2000
Copy link
Copy Markdown
Collaborator

@wbxl2000 wbxl2000 commented Apr 23, 2026

Related Issue

Related to #1768 — users report multi-agent runs making the CLI feel stalled. This PR doesn't fix the underlying provider-saturation behavior described there, but it addresses one clear symptom: when many background Agent subagents are running, the prompt status bar gives no indication that work is in progress, making the CLI look frozen.

Description

The existing ⚙ bash: N badge (introduced in #1477) counts only Shell(run_in_background=true) tasks — _bg_task_count in src/kimi_cli/ui/shell/__init__.py:430 explicitly filters with v.spec.kind == ""bash"". When a root agent dispatches many background Agent subagents, the prompt shows no count and no hint, so the user reasonably concludes the shell has frozen.

Change

Render two independent badges side by side:

agent (Kimi-k2.6 ●)  ~/code/empty  ⚙ bash: 3  ⚙ agent: 1  /feedback: ...
  • _bg_task_count_bg_task_counts, now returns a frozen BgTaskCounts(bash, agent) dataclass.
  • Provider signature in CustomPromptSession changes from Callable[[], int] to Callable[[], BgTaskCounts].
  • The rendering block in prompt.py walks (bash, agent) in order: each kind only renders when its count > 0 and there's room left; if space runs out after rendering bash, the agent badge is dropped (preserves the existing overflow priority).
  • BgTaskCounts is exported from kimi_cli.ui.shell.prompt for reuse in tests.

No changes to task manager, agent runner, or notification paths — this is purely a UI surface change.

Tests

  • Updated the one stale lambda: 2 stub in tests/ui_and_conv/test_prompt_tips.py to the new shape.
  • Added 3 regression tests: both-visible, agent-alone (no bash), and narrow-terminal drop-priority.
  • Full suite: 2552 passed, 9 skipped, 1 xfailed (+ 52 passed, 4 skipped e2e). make check-kimi-cli reports 0 errors introduced by this PR.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue (Background multi-agent runs can stall the CLI and cascade into provider timeouts / event-loop errors #1768 — related context, not resolved by this PR).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog equivalent — Unreleased entries added manually to CHANGELOG.md and docs/zh/release-notes/changelog.md, with the EN docs synced via node docs/scripts/sync-changelog.mjs.
  • I have run make gen-docs to update the user documentation. N/A — no user-facing docs reference the ⚙ bash: / ⚙ agent: status bar badges (grep of docs/en,zh/** confirms only MCP, YOLO, plan, display_name badges are documented).

Open in Devin Review

Copilot AI review requested due to automatic review settings April 23, 2026 13:58
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the shell prompt status bar to reflect background work more accurately during multi-agent runs by showing separate counts for background bash tasks and background agent tasks.

Changes:

  • Introduces BgTaskCounts and changes the prompt session’s background-task provider from a single int to (bash, agent) counts.
  • Renders up to two badges (⚙ bash: N, ⚙ agent: N) with overflow behavior that prefers keeping the bash badge.
  • Updates/extends prompt-toolbar tests and adds changelog entries (root + synced docs).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/kimi_cli/ui/shell/prompt.py Adds BgTaskCounts, updates provider type, and renders separate bash/agent badges in the toolbar.
src/kimi_cli/ui/shell/__init__.py Updates background task counting logic to return BgTaskCounts (bash + agent) with a 1s cache.
tests/ui_and_conv/test_prompt_tips.py Updates existing stub and adds regression tests for both badges, agent-only, and narrow-width behavior.
CHANGELOG.md Adds an Unreleased entry describing the new agent badge in the status bar.
docs/en/release-notes/changelog.md Synced changelog entry for the new status bar badges.
docs/zh/release-notes/changelog.md Adds the corresponding zh changelog entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2166 to +2173
for kind_label, kind_count in (("bash", bg_counts.bash), ("agent", bg_counts.agent)):
if kind_count <= 0:
continue
bg_text = f"⚙ {kind_label}: {kind_count}"
bg_width = _display_width(bg_text)
if remaining >= bg_width + 2:
fragments.extend([(tc.bg_tasks, bg_text), ("", " ")])
remaining -= bg_width + 2
if remaining < bg_width + 2:
break
fragments.extend([(tc.bg_tasks, bg_text), ("", " ")])
Comment on lines +380 to +393
# With only ~width budget for one badge after CWD/mode, keeping bash and
# dropping agent is the documented priority.
prompt_session = _make_toolbar_session(tips=[])
prompt_session._background_task_count_provider = lambda: BgTaskCounts(bash=5, agent=5)

lines = _render_toolbar_lines(prompt_session, 40, monkeypatch)

# Must never overflow and the bash badge is preferred over the agent badge.
assert _display_width(lines[1]) <= 40
if "⚙ agent" in lines[1]:
# Only acceptable if bash also fit — otherwise priority is violated.
assert "⚙ bash" in lines[1], (
f"agent badge appeared without bash badge at narrow width: {lines[1]!r}"
)
@wbxl2000
Copy link
Copy Markdown
Collaborator Author

image

The existing `⚙ bash: N` badge only counted background Shell tasks and
filtered out background Agent subagents, so when many subagents were
running the prompt looked idle and users could not tell work was in
progress. The toolbar now renders `⚙ bash: N` and `⚙ agent: N` as two
independent badges (each hidden when its count is 0) and drops the
agent badge first when the terminal is too narrow to fit both.
@wbxl2000 wbxl2000 force-pushed the fix/shell-agent-task-badge branch from 002a5c8 to 54abb59 Compare April 24, 2026 07:04
@wbxl2000
Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000 wbxl2000 merged commit e32568c into main Apr 24, 2026
14 checks passed
@wbxl2000 wbxl2000 deleted the fix/shell-agent-task-badge branch April 24, 2026 07:23
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