Repository navigation
fix(tui): zero-counter regression in workspace mode (#1447 follow-up) - #1507
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| for (const n of nodes) { | ||
| if (n.type === 'agent' && predicate(n)) count++; | ||
| if (n.children.length > 0) count += countAgents(n.children, predicate); | ||
| } |
There was a problem hiding this comment.
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);
}
}
| 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. | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
| if (agentCount > 0) { | ||
| return { | ||
| agentCount, | ||
| runningCount: countAgents(sessionTree, (n) => n.wsAgentState === 'running'), | ||
| }; | ||
| } |
There was a problem hiding this comment.
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>
017b857 to
84ed146
Compare
|
Tracked by #1509 (orphan-recovery sprint). |
Summary
Fixes the
0/0nav-header regression introduced by #1447.computeNavCountsreturned zero wheneverworkspaceRootwas set but the workspace scan came up empty (staleworkspaceRoot, no agents resolved, or every node was an orphan session) — even when tmux had live panes.computeNavCountsfor 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 reviewTest plan
bun test src/tui/components/Nav.test.tsx— 8 new tests passworkspaceRoot+ live tmux panes → header shows pane count instead of 0/0