Skip to content

fix(tui): zero-counter regression in workspace mode (#1447 follow-up) - #1507

Merged
namastex888 merged 1 commit into
devfrom
fix/tui-zero-agent-counter
Apr 29, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/tui-zero-agent-counter

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Summary

Fixes the 0/0 nav-header regression introduced by #1447. computeNavCounts returned zero whenever workspaceRoot was set but the workspace scan came up empty (stale workspaceRoot, no agents resolved, or every node was an orphan session) — even when tmux had live panes.

  • Falls back to live tmux pane inventory when workspace mode produces zero agents
  • Exports computeNavCounts for unit-test coverage — the missing test on this helper is exactly why the regression slipped through feat(tui): canonical agent visibility + sub-agent kind distinction #1447's review
  • Adds 8 regression tests: workspaceRoot+agents, workspaceRoot+empty fallback, no-workspaceRoot tmux sum, mixed orphan/agent counting, running filter, diagnostic-snapshot edges

Test plan

  • bun test src/tui/components/Nav.test.tsx — 8 new tests pass
  • Manual: launch with stale workspaceRoot + live tmux panes → header shows pane count instead of 0/0

@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fed7748b-2ba8-4324-acea-2589ced88ce9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tui-zero-agent-counter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves the agent counting logic in the navigation sidebar by introducing a recursive countAgents function to correctly include sub-agents and adding fallback logic to prevent '0/0' displays when workspace scans fail. Comprehensive unit tests were added to cover these scenarios. Feedback suggests optimizing the recursion in countAgents to only process children of agent nodes and improving the UI clarity when the fallback logic is triggered to avoid misleading 'Agents' counts.

Comment on lines +215 to +218
for (const n of nodes) {
if (n.type === 'agent' && predicate(n)) count++;
if (n.children.length > 0) count += countAgents(n.children, predicate);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This recursive function is a good solution for counting nested agents. However, it currently recurses into the children of all nodes, including non-agent nodes like orphan sessions. Since only nodes of type agent can contain sub-agents, you can make this more efficient and precise by only recursing into the children of agent nodes.

  for (const n of nodes) {
    if (n.type === 'agent') {
      if (predicate(n)) count++;
      if (n.children.length > 0) count += countAgents(n.children, predicate);
    }
  }

Comment on lines 242 to 253
if (workspaceRoot) {
return {
agentCount: sessionTree.filter((n) => n.type === 'agent').length,
runningCount: sessionTree.filter((n) => n.wsAgentState === 'running').length,
};
const agentCount = countAgents(sessionTree, () => true);
if (agentCount > 0) {
return {
agentCount,
runningCount: countAgents(sessionTree, (n) => n.wsAgentState === 'running'),
};
}
// Workspace mode but no agent nodes resolved (stale workspaceRoot, empty
// scan, or every node is an orphan session). Fall back to the live tmux
// inventory so the header still reflects the user's reality.
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this fallback logic correctly prevents the '0/0' display, it introduces a potentially confusing UI for users in workspace mode. When a fallback occurs, agentCount becomes the number of sessions and runningCount becomes the total number of panes. The Nav component will then display this as 'Agents <pane_count>/<session_count>', which can be misleading (e.g., 'Agents 2/1').

To improve clarity, consider signaling to the caller that a fallback occurred so a different display format can be used. A clean way to do this is to add a boolean flag to the return object (e.g., isWorkspace: boolean) and adjust the Nav component to use the appropriate label and format.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 017b857bb0

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +244 to +249
if (agentCount > 0) {
return {
agentCount,
runningCount: countAgents(sessionTree, (n) => n.wsAgentState === 'running'),
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude internal tmux session in workspace fallback counts

When workspaceRoot is set and agentCount is zero, this branch falls through to the legacy diagnostics counters, which include every tmux session. In workspace mode the tree intentionally filters out the internal genie-tui session (buildWorkspaceTree excludes it), so the header can report counts that don’t exist in the visible tree (for example, a stale workspace with only the TUI session can show 1/1). The fallback should be based on the filtered workspace tree/orphans or explicitly exclude the internal session before counting.

Useful? React with 👍 / 👎.

`computeNavCounts` returned `{ agentCount: 0, runningCount: 0 }` whenever
the workspace scan came up empty (stale workspaceRoot, no agents resolved,
or every node was an orphan session) — even when tmux had live panes. Users
saw `0/0` in the nav header despite running agents.

Fix: when workspaceRoot mode produces zero agents, fall back to the live
tmux pane inventory so the header reflects reality. Export `computeNavCounts`
so the helper is unit-testable — the missing test on this helper is exactly
why the regression slipped through PR #1447's review.

Adds 8 regression tests covering: workspaceRoot+agents, workspaceRoot+empty
fallback, no-workspaceRoot tmux sum, mixed orphan/agent counting, running
filter, and diagnostic-snapshot edge cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@namastex888
namastex888 force-pushed the fix/tui-zero-agent-counter branch from 017b857 to 84ed146 Compare April 29, 2026 13:49
@namastex888 namastex888 added the sprint:next Queued for next execution sprint label Apr 29, 2026
@namastex888

Copy link
Copy Markdown
Contributor Author

Tracked by #1509 (orphan-recovery sprint).

@namastex888
namastex888 merged commit 39963a3 into dev Apr 29, 2026
13 of 15 checks passed
@automagik-genie
automagik-genie deleted the fix/tui-zero-agent-counter branch September 25, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint:next Queued for next execution sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant