fix(dashboard): dedupe agents to stop duplicate-key warning storm

A duplicate agent id slipping through useAgents (race between initial fetch
and an SSE refresh, or backend pagination edge case) was flooding React with
"Encountered two children with the same key" warnings. With the active panel
re-rendering on every transcript event the warning fired every few ms and
snowballed the console buffer until the page crashed with OOM.

Dedupe by id at the hook (so every consumer benefits) and again in
ActiveAgentsPanel as belt-and-braces.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-24 23:22:46 -07:00
parent 28eef80b26
commit 8c9dfc2f56
2 changed files with 15 additions and 4 deletions

View File

@@ -80,16 +80,22 @@ interface ActiveAgentsPanelProps {
}
export function ActiveAgentsPanel({ agents, projectId, onAgentSelect }: ActiveAgentsPanelProps) {
if (agents.length === 0) return null;
// Dedupe by id defensively. The store should return unique agents but a race
// between the initial fetch and an SSE refresh can briefly surface the same
// agent twice — without this guard React floods the console with duplicate
// key warnings (which previously snowballed into OOM).
const uniqueAgents = Array.from(new Map(agents.map((a) => [a.id, a])).values());
if (uniqueAgents.length === 0) return null;
return (
<div className="active-agents-panel">
<div className="active-agents-panel-header">
<Activity size={16} />
<span>Active Agents ({agents.length})</span>
<span>Active Agents ({uniqueAgents.length})</span>
</div>
<div className="active-agents-grid">
{agents.map(agent => (
{uniqueAgents.map(agent => (
<LiveAgentCard key={agent.id} agent={agent} projectId={projectId} onSelect={onAgentSelect} />
))}
</div>

View File

@@ -34,7 +34,12 @@ export function useAgents(projectId?: string, options?: UseAgentsOptions) {
},
projectId,
);
setAgents(data);
// Defensive dedupe: a race between the initial fetch and an SSE refresh
// (or a backend that returned the same agent twice) would otherwise put
// duplicate ids into every list rendered from this hook, flooding React
// with duplicate-key warnings until the dashboard runs out of heap.
const unique = Array.from(new Map(data.map((a) => [a.id, a])).values());
setAgents(unique);
} catch (err) {
console.error("Failed to load agents:", err);
} finally {