mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix: use useShallow for childAgents selector to prevent infinite loop
The childAgents selector in the agent screen was creating a new array on every render, causing an infinite loop when combined with zustand's store subscription. Added useShallow wrapper to perform shallow comparison and prevent unnecessary re-renders. Also updated plan.md with test results: - PARTIAL PASS: Fixed infinite loop, agent screen loads correctly - Sub-Agents menu section displays properly - Parent/child MCP creation works but parentAgentId not auto-injected - Added fix task for auto-injecting parentAgentId in MCP server 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useCallback, useState } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
@@ -154,18 +155,21 @@ function AgentScreenContent({ serverId, agentId, onBack }: AgentScreenContentPro
|
||||
);
|
||||
|
||||
// Select child agents (agents where parentAgentId === current agentId)
|
||||
const childAgents = useSessionStore((state) => {
|
||||
if (!resolvedAgentId) return [];
|
||||
const agents = state.sessions[serverId]?.agents;
|
||||
if (!agents) return [];
|
||||
const children: Array<{ id: string; title: string | null }> = [];
|
||||
for (const [id, a] of agents) {
|
||||
if (a.parentAgentId === resolvedAgentId) {
|
||||
children.push({ id, title: a.title });
|
||||
// Use useShallow to avoid creating new array references on every render
|
||||
const childAgents = useSessionStore(
|
||||
useShallow((state) => {
|
||||
if (!resolvedAgentId) return [];
|
||||
const agents = state.sessions[serverId]?.agents;
|
||||
if (!agents) return [];
|
||||
const children: Array<{ id: string; title: string | null }> = [];
|
||||
for (const [id, a] of agents) {
|
||||
if (a.parentAgentId === resolvedAgentId) {
|
||||
children.push({ id, title: a.title });
|
||||
}
|
||||
}
|
||||
}
|
||||
return children;
|
||||
});
|
||||
return children;
|
||||
})
|
||||
);
|
||||
|
||||
// Select only the specific stream state - use stable empty array to avoid infinite loop
|
||||
const streamItemsRaw = useSessionStore((state) =>
|
||||
|
||||
20
plan.md
20
plan.md
@@ -334,7 +334,7 @@ Files requiring modification:
|
||||
- Run typecheck after changes.
|
||||
- **Done (2025-12-21 22:00)**: Added Sub-Agents section to agent info menu in `[agentId].tsx`. Added `childAgents` selector to query agents with matching `parentAgentId`. Added `handleNavigateToChildAgent` callback for navigation. UI shows "No sub-agents" when empty, or clickable list of child agents with chevron icons. Typecheck passes.
|
||||
|
||||
- [ ] **Test**: Verify parent/child hierarchy end-to-end.
|
||||
- [x] **Test**: Verify parent/child hierarchy end-to-end.
|
||||
|
||||
- Create a root agent via the UI
|
||||
- Use MCP to spawn a child agent from within the root agent
|
||||
@@ -343,6 +343,24 @@ Files requiring modification:
|
||||
- Click child agent in menu, verify navigation works
|
||||
- Verify back button returns to parent agent screen
|
||||
- If issues found: add fix tasks + re-test task.
|
||||
- **Done (2025-12-21 22:30)**: PARTIAL PASS with issues found. Fixed infinite loop bug (added `useShallow` to `childAgents` selector). Agent screen loads correctly. Sub-Agents menu section shows "No sub-agents". Parent agent successfully created child via MCP `create_agent`. However, child appears on homepage because `parentAgentId` not set - MCP server doesn't auto-inject calling agent's ID. Fix task added.
|
||||
|
||||
- [ ] **Fix**: Auto-inject parentAgentId in MCP create_agent tool.
|
||||
|
||||
- The MCP server needs to know which agent is calling it
|
||||
- Explore passing agent ID context when MCP transport is created
|
||||
- Or: Have each agent's MCP session be scoped to that agent
|
||||
- Update `create_agent` handler to automatically set `parentAgentId`
|
||||
- Run typecheck after changes.
|
||||
|
||||
- [ ] **Test**: Re-verify parent/child hierarchy after MCP fix.
|
||||
|
||||
- Create a root agent via the UI
|
||||
- Use MCP to spawn a child agent from within the root agent
|
||||
- Verify child agent has `parentAgentId` set automatically
|
||||
- Verify homepage only shows the root agent (not the child)
|
||||
- Verify root agent's menu shows the child in "Sub-Agents" section
|
||||
- Click child agent in menu, verify navigation works
|
||||
|
||||
- [ ] **Plan**: Re-audit agent hierarchy after initial implementation.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user