Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): settle the CoS page's own Active/Pending cards and stop rendering an unknown queue as zero

[._.]/ Adam Eivyf10358885f3c
diff --git a/client/src/pages/ChiefOfStaff.jsx b/client/src/pages/ChiefOfStaff.jsx
index d8d4f2185d..ba4a8ac516 100644
--- a/client/src/pages/ChiefOfStaff.jsx
+++ b/client/src/pages/ChiefOfStaff.jsx
@@ -11,6 +11,7 @@ import { isRiggedAvatarStyle, riggedRecordForStyle, useAvatarCapabilities } from
import { coalesce } from '../utils/coalesce';
import { sameJsonShape } from '../lib/sameJsonShape';
import { isAgentHandoff } from '../lib/agentOutcome';
+import { runningAgentsByTaskId, withoutSpawningTasks } from '../lib/cosSpawnWindow';
import { WEBGL_AVATAR_STYLE_IDS } from '../lib/avatarStyles';
import { Play, Pause, Square, Clock, CheckCircle, AlertCircle, Cpu, ChevronDown, ChevronUp, Brain, PanelLeftClose, PanelLeftOpen } from 'lucide-react';
import toast from '../components/ui/Toast';
@@ -719,10 +720,20 @@ export default function ChiefOfStaff() {
[agents]
);
- // Memoize pending task count
+ // Memoize pending task count, settled against the live agent list.
+ //
+ // GET /api/cos/tasks already settles `grouped.pending` for the spawn window,
+ // but `activeAgentCount` above reads the SOCKET-fed agent array, which lands on
+ // 'cos:agent:spawned' — ahead of the next task fetch. Counting the payload raw
+ // would tick Active to 1 while Pending still read 1 until that fetch returned,
+ // which is the "1 pending and 1 active" this page is the headline surface for.
+ // Same settlement TasksTab makes from the same two arrays, so the header cards
+ // and the task list below them cannot disagree. See lib/cosSpawnWindow.js.
+ const runningAgentByTaskId = useMemo(() => runningAgentsByTaskId(agents), [agents]);
const pendingTaskCount = useMemo(() =>
- (tasks.user?.grouped?.pending?.length || 0) + (tasks.cos?.grouped?.pending?.length || 0),
- [tasks.user?.grouped?.pending?.length, tasks.cos?.grouped?.pending?.length]
+ withoutSpawningTasks(tasks.user?.grouped?.pending, runningAgentByTaskId).length
+ + withoutSpawningTasks(tasks.cos?.grouped?.pending, runningAgentByTaskId).length,
+ [tasks.user?.grouped?.pending, tasks.cos?.grouped?.pending, runningAgentByTaskId]
);
const hasCanvasAvatar = CANVAS_AVATAR_STYLES.has(avatarStyle) || isRiggedAvatarStyle(avatarStyle);
diff --git a/client/src/pages/ChiefOfStaff.test.jsx b/client/src/pages/ChiefOfStaff.test.jsx
index 2133fdfbbe..b59ef63115 100644
--- a/client/src/pages/ChiefOfStaff.test.jsx
+++ b/client/src/pages/ChiefOfStaff.test.jsx
@@ -769,6 +769,35 @@ describe('ChiefOfStaff stale queue-read guard', () => {
expect(screen.queryByText('STALE pending copy')).not.toBeInTheDocument();
expect(screen.getByText('FRESH in-progress copy')).toBeInTheDocument();
});
+
+ // The header's Active/Pending pair is the surface the "1 pending and 1 active"
+ // report named. `activeAgentCount` reads the SOCKET-fed agent array, which lands
+ // on 'cos:agent:spawned'; the task payload is only settled for the spawn window
+ // once the next GET /api/cos/tasks returns. Between the two, counting the
+ // payload raw showed the one task on both cards.
+ it('does not count a task on both header cards while its spawn event outruns the queue read', async () => {
+ const pendingTask = { id: 'task-1', description: 'Example queued task', status: 'pending', metadata: {} };
+ api.getCosTasks.mockResolvedValue({
+ user: { tasks: [pendingTask], grouped: { pending: [pendingTask], in_progress: [] } },
+ cos: { tasks: [], grouped: { pending: [], in_progress: [] } },
+ });
+ await renderSettledAt('config');
+
+ const statValue = (label) => screen.getAllByText(label)
+ .map((node) => node.parentElement?.parentElement?.textContent)
+ .filter(Boolean);
+ expect(statValue('Pending').some((text) => text.includes('1'))).toBe(true);
+
+ // The agent registers as running; the task list has not been refetched yet,
+ // so it still reads `pending` — exactly the window the settlement covers.
+ api.getCosAgents.mockResolvedValue([
+ { id: 'agent-1', taskId: 'task-1', status: 'running', startedAt: new Date().toISOString() },
+ ]);
+ await act(async () => { getSocketHandler('cos:agent:spawned')({ agentId: 'agent-1', metadata: {} }); });
+
+ await waitFor(() => expect(statValue('Active').some((text) => text.includes('1'))).toBe(true));
+ expect(statValue('Pending').every((text) => !/Pending\s*1/.test(text.replace(/\s+/g, ' ')))).toBe(true);
+ });
});
// A single warning-level health issue parked the avatar on "Investigating
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsx
index 0c186e2561..b46ab05d24 100644
--- a/client/src/pages/Instances.jsx
+++ b/client/src/pages/Instances.jsx
@@ -87,7 +87,9 @@ function HealthSummary({ health, version }) {
{health.cos && (
<div className="flex items-center gap-1.5 text-gray-400 col-span-2">
<Bot size={12} />
- <span>{health.cos.activeAgents ?? 0} agents, {health.cos.queuedTasks ?? 0} queued</span>
+ {/* `queuedTasks: null` means the pending list could not be read, not that
+ nothing is waiting — render it as unknown rather than a confident zero. */}
+ <span>{health.cos.activeAgents ?? 0} agents, {health.cos.queuedTasks ?? '?'} queued</span>
</div>
)}
</div>