Skip to content

fix: correctly show agents in health page#2857

Merged
moshloop merged 1 commit intomainfrom
agent-health
Feb 17, 2026
Merged

fix: correctly show agents in health page#2857
moshloop merged 1 commit intomainfrom
agent-health

Conversation

@yashmehrotra
Copy link
Member

@yashmehrotra yashmehrotra commented Feb 16, 2026

Summary by CodeRabbit

  • New Features

    • Enhanced local agent identification and filtering capabilities across check management.
  • Bug Fixes

    • Removed quote characters from namespace displays for cleaner formatting.
    • Standardized agent name presentation with updated formatting conventions.
  • Performance

    • Optimized agent data fetching to load only required agent information instead of all agents.

@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aws-preview Ready Ready Preview Feb 16, 2026 10:24am
flanksource-ui Ready Ready Preview Feb 16, 2026 10:24am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Walkthrough

This PR introduces a new isLocalAgent helper function and applies it across canary components to standardize agent identification. It sanitizes namespace values, enriches checks with agent details, and refactors agent fetching and tab construction logic.

Changes

Cohort / File(s) Summary
Agent Service Utilities
src/api/services/agents.ts
Added isLocalAgent exported helper function to identify local agents based on provided agent ID.
Agent Display Components
src/components/Agents/AgentName.tsx
Updated Badge text prop to prefix agent names with agent: for standardized display formatting.
Canary Popup
src/components/Canary/CanaryPopup/CheckTitle.tsx
Sanitized namespace values by stripping double quotes and passed new agent prop to AgentName component alongside existing agentId.
Canary Core Components
src/components/Canary/CanaryTabs.tsx, src/components/Canary/grouping.ts, src/components/Canary/index.tsx
Refactored agent handling: implemented memoized agent name mapping, optimized agent fetching to only retrieve unknown agents, updated local agent detection to use isLocalAgent, and added check enrichment with agent details.
Canary Columns
src/components/Canary/Columns/index.tsx
Sanitized namespace display by removing double quotes and added conditional agent badge rendering for non-local agents using isLocalAgent check.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: correctly show agents in health page' directly aligns with the changeset's main objective of improving agent display on the health page. The changes across multiple files systematically address agent identification, filtering, grouping, and enrichment to ensure agents are properly shown.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch agent-health

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/components/Canary/CanaryTabs.tsx`:
- Around line 153-160: agentTabs is being keyed by label (computed as name ||
id) causing collisions when two agents share the same name; update the
population logic in the agentMap.forEach loop to key agentTabs by the unique id
(use id as the object key) and keep label (name || id) only as the display
property (i.e., set agentTabs[id] = { key: id, value: id, label }); ensure any
downstream consumers that previously used the label as the key now use the agent
id (references: agentTabs, agentMap, label, id).
🧹 Nitpick comments (5)
src/components/Canary/index.tsx (2)

169-175: Unnecessary non-null assertion on check.agent_id.

Line 170 uses check.agent_id! but agent_id can be undefined for local checks. It's harmless here because Map.get(undefined) returns undefined and the guard on line 171 handles it, but the ! is misleading. Consider dropping it.

Suggested fix
-        const agent = agentMap.get(check.agent_id!);
+        const agent = agentMap.get(check.agent_id);

137-190: Agent fetch adds a sequential network call on every refresh cycle.

getAgentByIDs is awaited inside handleFetch, creating a waterfall on each refresh interval. For now this is acceptable since the call is conditional and batched, but consider caching agent data separately (e.g., via useQuery or a simple in-memory cache) so that repeated refreshes don't re-fetch the same agents.

src/components/Canary/Columns/index.tsx (1)

151-168: Namespace quote-stripping is repeated across files.

The .replace(/"/g, "") pattern for sanitizing namespace strings appears here (lines 151, 157, 166) and also in CheckTitle.tsx (lines 20, 61). Consider extracting a small helper (e.g., sanitizeNamespace) to DRY this up.

src/components/Canary/CanaryTabs.tsx (1)

135-141: Query key with spread array may produce unstable keys.

Line 136 spreads agentIDsToFetch into the query key. If the order of IDs changes between renders (e.g., due to Set iteration order varying with insertion order of different fetches), it could cause unnecessary refetches. Consider sorting the IDs for a stable key.

Suggested fix
-    ["db", "agents", ...agentIDsToFetch],
+    ["db", "agents", ...agentIDsToFetch.slice().sort()],
src/components/Canary/CanaryPopup/CheckTitle.tsx (1)

61-61: Use the already-sanitized namespace variable instead of re-sanitizing.

Line 20 assigns const namespace = check?.namespace?.replace(/"/g, ""), but line 61 repeats the .replace(...) on check?.namespace instead of reusing namespace. Use the variable for consistency.

Suggested fix
-              <Badge text={check?.namespace?.replace(/"/g, "") ?? ""} />
+              <Badge text={namespace ?? ""} />

Comment on lines +153 to +160
const agentTabs = {} as Record<
string,
{ key: string; value: string; label: string }
>;
agentMap.forEach((name, id) => {
const label = name || id;
agentTabs[label] = { key: label, value: id, label };
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential tab collision when two agents share the same name.

Line 159 keys the agentTabs object by label (which is name || id). If two distinct agents have the same name, the second will overwrite the first, silently losing a tab. Consider keying by id instead and using label only for display.

Suggested fix
-      agentMap.forEach((name, id) => {
-        const label = name || id;
-        agentTabs[label] = { key: label, value: id, label };
-      });
+      agentMap.forEach((name, id) => {
+        const label = name || id;
+        agentTabs[id] = { key: id, value: id, label };
+      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const agentTabs = {} as Record<
string,
{ key: string; value: string; label: string }
>;
agentMap.forEach((name, id) => {
const label = name || id;
agentTabs[label] = { key: label, value: id, label };
});
const agentTabs = {} as Record<
string,
{ key: string; value: string; label: string }
>;
agentMap.forEach((name, id) => {
const label = name || id;
agentTabs[id] = { key: id, value: id, label };
});
🤖 Prompt for AI Agents
In `@src/components/Canary/CanaryTabs.tsx` around lines 153 - 160, agentTabs is
being keyed by label (computed as name || id) causing collisions when two agents
share the same name; update the population logic in the agentMap.forEach loop to
key agentTabs by the unique id (use id as the object key) and keep label (name
|| id) only as the display property (i.e., set agentTabs[id] = { key: id, value:
id, label }); ensure any downstream consumers that previously used the label as
the key now use the agent id (references: agentTabs, agentMap, label, id).

@moshloop moshloop merged commit beb7374 into main Feb 17, 2026
14 of 16 checks passed
@moshloop moshloop deleted the agent-health branch February 17, 2026 07:45
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