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

fix: sync agent cards after notification feedback

[._.]/ Adam Eivyd141b3016af1
diff --git a/client/src/components/cos/tabs/AgentsTab.jsx b/client/src/components/cos/tabs/AgentsTab.jsx
index 7aeec55e23..cc41b40ae4 100644
--- a/client/src/components/cos/tabs/AgentsTab.jsx
+++ b/client/src/components/cos/tabs/AgentsTab.jsx
@@ -8,6 +8,8 @@ import ResumeAgentModal from './ResumeAgentModal';
import RelaunchAgentModal from './RelaunchAgentModal';
import InfiniteScrollFooter from '../../ui/InfiniteScrollFooter';
import { usePagedCollection } from '../../../hooks/usePagedCollection';
+import { useSocketResource } from '../../../hooks/useSocketResource';
+import socket from '../../../services/socket';
import InlineConfirmRow from '../../ui/InlineConfirmRow';
import { agentResumeMessage } from '../../../lib/agentResumeOutcome';
import { isAgentFeedbackEligible } from '../../../lib/cosAgentFeedback';
@@ -34,6 +36,7 @@ const RESUME_MESSAGES = {
};
const needsAgentFeedback = isAgentFeedbackEligible;
+const FEEDBACK_EVENTS = ['cos:agent:feedback', 'cos:agent:completed'];
export default function AgentsTab({ agentsLoaded = true, agentsError = null, onRetryAgents, completedRevision = 0, agents, onRefresh, liveOutputs, providers, providersLoaded, apps }) {
const { agentId } = useParams();
@@ -55,7 +58,15 @@ export default function AgentsTab({ agentsLoaded = true, agentsError = null, onR
const [searchQuery, setSearchQuery] = useState('');
const [feedbackUpdates, setFeedbackUpdates] = useState({});
- const [pendingFeedbackCount, setPendingFeedbackCount] = useState(null);
+ // The durable reference index is the bounded source of truth for feedback
+ // actions. It brings older eligible runs into the filter without walking every
+ // historical date bucket; the response uses the same predicate as the server
+ // queue and supplies a count even when those cards are not otherwise loaded.
+ const pendingFeedback = useSocketResource(
+ ({ signal }) => api.getCosPendingAgentFeedback({ countOnly: true, silent: true, signal }),
+ { namespace: 'cos', events: FEEDBACK_EVENTS },
+ );
+ const pendingFeedbackCount = Number.isFinite(pendingFeedback.data?.count) ? pendingFeedback.data.count : null;
const [confirmingClear, setConfirmingClear] = useState(false);
// Filter selection is URL-backed so actionable insights can open the exact
@@ -81,21 +92,6 @@ export default function AgentsTab({ agentsLoaded = true, agentsError = null, onR
api.getCosLearningDurations().then(setDurations).catch(() => {});
}, []);
- // The durable reference index is the bounded source of truth for feedback
- // actions. It brings older eligible runs into the filter without walking every
- // historical date bucket; the response uses the same predicate as the server
- // queue and supplies a count even when those cards are not otherwise loaded.
- useEffect(() => {
- let cancelled = false;
- api.getCosPendingAgentFeedback({ countOnly: true, silent: true })
- .then((result) => {
- if (cancelled) return;
- setPendingFeedbackCount(Number.isFinite(result?.count) ? result.count : null);
- })
- .catch(() => {});
- return () => { cancelled = true; };
- }, []);
-
const handleKill = async (agentId) => {
const result = await api.killCosAgent(agentId, { silent: true }).catch(err => { toast.error(err.message); return null; });
if (!result) return;
@@ -136,15 +132,22 @@ export default function AgentsTab({ agentsLoaded = true, agentsError = null, onR
// fetches the rest itself if the reader expands it.
const handleRelaunchClick = useCallback((agent) => setRelaunchingAgent(agent), []);
- const handleFeedbackChange = useCallback((updatedAgent, previousAgent) => {
- if (updatedAgent?.id && updatedAgent.feedback) {
- setFeedbackUpdates(prev => ({ ...prev, [updatedAgent.id]: updatedAgent.feedback }));
- }
- if (needsAgentFeedback(previousAgent) && !needsAgentFeedback(updatedAgent)) {
- setPendingFeedbackCount(count => count == null ? count : Math.max(0, count - 1));
- }
+ const applyFeedback = useCallback((id, feedback) => {
+ if (!id || !feedback?.rating) return;
+ setFeedbackUpdates(prev => ({ ...prev, [id]: feedback }));
}, []);
+ useEffect(() => {
+ const handleFeedback = ({ agentId, feedback }) => applyFeedback(agentId, feedback);
+ socket.on('cos:agent:feedback', handleFeedback);
+ return () => socket.off('cos:agent:feedback', handleFeedback);
+ }, [applyFeedback]);
+
+ const handleFeedbackChange = useCallback((updatedAgent) => {
+ applyFeedback(updatedAgent?.id, updatedAgent?.feedback);
+ pendingFeedback.refetch();
+ }, [applyFeedback, pendingFeedback.refetch]);
+
// A PAUSED agent resumes IN PLACE (see `resumeAgent` in agentManagement.js):
// the server requeues that agent's own task on the worktree its run left behind.
// A COMPLETED agent's task is long settled, so it still gets a fresh one.
@@ -233,7 +236,9 @@ export default function AgentsTab({ agentsLoaded = true, agentsError = null, onR
? locallyVisibleNeedsFeedback
: Math.max(pendingFeedbackCount, locallyVisibleNeedsFeedback);
- const selectedAgent = agents.find(agent => agent.id === agentId) || (focusedAgent?.id === agentId ? focusedAgent : null);
+ const selectedRecord = agents.find(agent => agent.id === agentId) || (focusedAgent?.id === agentId ? focusedAgent : null);
+ const selectedAgent = selectedRecord && feedbackUpdates[agentId]
+ ? { ...selectedRecord, feedback: feedbackUpdates[agentId] } : selectedRecord;
return (
<div className="space-y-6">
diff --git a/client/src/components/cos/tabs/AgentsTab.test.jsx b/client/src/components/cos/tabs/AgentsTab.test.jsx
index e2740741b7..30c128f967 100644
--- a/client/src/components/cos/tabs/AgentsTab.test.jsx
+++ b/client/src/components/cos/tabs/AgentsTab.test.jsx
@@ -4,6 +4,21 @@ import userEvent from '@testing-library/user-event';
import { act } from 'react';
import { MemoryRouter, Routes, Route } from 'react-router';
+const socket = vi.hoisted(() => {
+ const handlers = new Map();
+ return {
+ on: (event, handler) => {
+ if (!handlers.has(event)) handlers.set(event, new Set());
+ handlers.get(event).add(handler);
+ },
+ off: (event, handler) => handlers.get(event)?.delete(handler),
+ emit: vi.fn(),
+ receive: (event, payload) => handlers.get(event)?.forEach(handler => handler(payload)),
+ listenerCount: event => handlers.get(event)?.size || 0,
+ };
+});
+vi.mock('../../../services/socket', () => ({ default: socket }));
+
vi.mock('../../../services/api', () => ({
getCosLearningDurations: vi.fn(),
getCosAgent: vi.fn(),
@@ -30,6 +45,7 @@ vi.mock('./AgentCard', () => ({
{onRelaunch && (
<button type="button" onClick={() => onRelaunch(agent)}>Relaunch {agent.id}</button>
)}
+ {agent.feedback?.rating && <span>Feedback: {agent.feedback.rating}</span>}
{!agent.feedback?.rating && (
<button
type="button"
@@ -274,6 +290,58 @@ describe('AgentsTab resume routing', () => {
});
describe('AgentsTab feedback review queue', () => {
+ it('applies notification feedback to live, archived and selected cards without reloading history', async () => {
+ const live = completedAgent('live', 'Recent task');
+ const archived = completedAgent('archived', 'Archived task');
+ api.getCosCompletedAgents.mockResolvedValue({ items: [archived], total: 1, nextCursor: null });
+ api.getCosAgent.mockResolvedValue(archived);
+ api.getCosPendingAgentFeedback.mockResolvedValue({ count: 2 });
+ const onRefresh = vi.fn();
+ const view = render(
+ <MemoryRouter initialEntries={['/cos/agents/archived']}>
+ <Routes><Route path="/cos/agents/:agentId" element={
+ <AgentsTab agents={[live]} onRefresh={onRefresh} liveOutputs={{}} providers={[]} apps={[]} />
+ } /></Routes>
+ </MemoryRouter>,
+ );
+ await waitFor(() => expect(screen.getAllByRole('button', { name: 'Rate Archived task' })).toHaveLength(2));
+ const pageReads = api.getCosCompletedAgents.mock.calls.length;
+ api.getCosPendingAgentFeedback.mockResolvedValue({ count: 1 });
+ await act(async () => socket.receive('cos:agent:feedback', {
+ agentId: 'archived', feedback: { rating: 'positive', comment: null, submittedAt: '2026-07-13T12:00:00.000Z' },
+ }));
+ expect(screen.getAllByText('Feedback: positive')).toHaveLength(2);
+ expect(screen.queryByRole('button', { name: 'Rate Archived task' })).not.toBeInTheDocument();
+ await screen.findByRole('button', { name: 'Needs feedback: 1' });
+
+ api.getCosPendingAgentFeedback.mockResolvedValue({ count: 0 });
+ await act(async () => socket.receive('cos:agent:feedback', {
+ agentId: 'live', feedback: { rating: 'negative', comment: null, submittedAt: '2026-07-13T12:01:00.000Z' },
+ }));
+ expect(screen.getByText('Feedback: negative')).toBeInTheDocument();
+ await screen.findByRole('button', { name: 'Needs feedback: 0' });
+ expect(api.getCosCompletedAgents).toHaveBeenCalledTimes(pageReads);
+ expect(onRefresh).not.toHaveBeenCalled();
+ view.unmount();
+ expect(socket.listenerCount('cos:agent:feedback')).toBe(0);
+ });
+
+ it('removes externally rated runs from the feedback filter and reconciles repeated ratings without double-counting', async () => {
+ const archived = completedAgent('archived', 'Archived task');
+ api.getCosCompletedAgents.mockResolvedValue({ items: [archived], total: 1, nextCursor: null });
+ api.getCosPendingAgentFeedback.mockResolvedValue({ count: 2 });
+ renderTab([], vi.fn(), '/cos/agents?feedback=needs-feedback');
+ await screen.findByText('Archived task');
+ await screen.findByRole('button', { name: 'Needs feedback: 2' });
+ api.getCosPendingAgentFeedback.mockResolvedValue({ count: 1 });
+ const event = { agentId: 'archived', feedback: { rating: 'positive' } };
+ await act(async () => socket.receive('cos:agent:feedback', event));
+ expect(screen.queryByText('Archived task')).not.toBeInTheDocument();
+ await screen.findByRole('button', { name: 'Needs feedback: 1' });
+ await act(async () => socket.receive('cos:agent:feedback', event));
+ await screen.findByRole('button', { name: 'Needs feedback: 1' });
+ });
+
it('renders an older durable pending run and uses its server count', async () => {
const archived = completedAgent('agent-archived', 'An older pending run');
api.getCosPendingAgentFeedback.mockResolvedValue({ agents: [archived], count: 1 });
diff --git a/server/lib/socketEventContracts.js b/server/lib/socketEventContracts.js
index c6f7cc42c2..027ffe1a73 100644
--- a/server/lib/socketEventContracts.js
+++ b/server/lib/socketEventContracts.js
@@ -44,6 +44,24 @@ const loomRunSnapshot = (production) => Object.freeze({
});
export const SOCKET_EVENT_CONTRACTS = Object.freeze({
+ 'cos:agent:feedback': {
+ direction: 'server-to-client',
+ summary: 'Persisted agent feedback after the pending-feedback index has been updated; CoS subscribers only.',
+ payloadSchema: {
+ type: 'object', required: ['agentId', 'feedback'],
+ properties: {
+ agentId: { type: 'string' },
+ feedback: {
+ type: 'object', required: ['rating', 'comment', 'submittedAt'],
+ properties: {
+ rating: { type: 'string', enum: ['positive', 'negative', 'neutral'] },
+ comment: { type: ['string', 'null'] },
+ submittedAt: { type: 'string' },
+ },
+ },
+ },
+ },
+ },
'peer-execution:changed': Object.freeze({ direction: 'server-to-client', summary: 'Invalidate authenticated peer execution setup and status; no credentials or operation data.', payloadSchema: { type: 'null' } }),
'genome:clinvar-progress': {
direction: 'server-to-client', summary: 'ClinVar download and indexing progress for an optional client request ID.',
diff --git a/server/services/cosAgentFeedback.js b/server/services/cosAgentFeedback.js
index a4535b7628..7ce5767138 100644
--- a/server/services/cosAgentFeedback.js
+++ b/server/services/cosAgentFeedback.js
@@ -318,7 +318,6 @@ export async function submitAgentFeedback(agentId, feedback) {
}
emitLog('info', `Feedback received for agent ${agentId}: ${feedback.rating}`, { agentId, rating: feedback.rating });
- cosEvents.emit('agent:feedback', { agentId, feedback: feedbackData });
return { success: true, agent: state.agents[agentId], feedbackData, clearPendingRef: archived.kind === 'found' };
}
@@ -336,7 +335,6 @@ export async function submitAgentFeedback(agentId, feedback) {
await atomicWrite(archived.metadataPath, updated);
emitLog('info', `Feedback received for agent ${agentId}: ${feedback.rating}`, { agentId, rating: feedback.rating });
- cosEvents.emit('agent:feedback', { agentId, feedback: feedbackData });
return { success: true, agent: { ...updated, id: agentId }, feedbackData, clearPendingRef: true };
});
@@ -345,6 +343,7 @@ export async function submitAgentFeedback(agentId, feedback) {
// A rated archive is no longer an eligible target; clearing the projected bit
// keeps the scalar badge correct without re-reading the record.
await markCompletionFeedbackResolved(agentId);
+ cosEvents.emit('agent:feedback', { agentId, feedback: feedbackData });
await recordUserAction({
type: 'cos.agent.feedback',
target: agentId,
diff --git a/server/services/cosAgentFeedback.test.js b/server/services/cosAgentFeedback.test.js
index b0ecc99308..9b0976f125 100644
--- a/server/services/cosAgentFeedback.test.js
+++ b/server/services/cosAgentFeedback.test.js
@@ -436,6 +436,27 @@ describe('pending feedback served from the eligibility projection', () => {
await expect(getPendingAgentFeedbackCount()).resolves.toBe(1);
});
+ it('publishes feedback only after the pending count reflects the saved rating', async () => {
+ const agent = pendingAgent('agent-feedback-event', '2026-08-10T10:00:00.000Z');
+ await enrollThenEvict([agent]);
+ await seedProjection([[agent.id, { completedAt: agent.completedAt, completed: true, feedbackEligible: true }]]);
+ const dir = join(mockCosState.agentsDir, agent.completedAt.slice(0, 10), agent.id);
+ await mkdir(dir, { recursive: true });
+ await writeFile(join(dir, 'metadata.json'), JSON.stringify(agent));
+ await expect(getPendingAgentFeedbackCount()).resolves.toBe(1);
+ let countAtEvent;
+ const onFeedback = vi.fn(() => { countAtEvent = getPendingAgentFeedbackCount(); });
+ cosEvents.on('agent:feedback', onFeedback);
+ await submitAgentFeedback(agent.id, { rating: 'positive' }).finally(() => {
+ cosEvents.off('agent:feedback', onFeedback);
+ });
+ expect(onFeedback).toHaveBeenCalledExactlyOnceWith({
+ agentId: agent.id,
+ feedback: { rating: 'positive', comment: null, submittedAt: expect.any(String) },
+ });
+ await expect(countAtEvent).resolves.toBe(0);
+ });
+
it('stops counting a run the projection records as already rated', async () => {
const agent = pendingAgent('agent-projected-rated', '2026-08-11T10:00:00.000Z');
await enrollThenEvict([agent]);
diff --git a/server/services/socket.js b/server/services/socket.js
index 0c60edd777..82db6f2b34 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -519,6 +519,7 @@ function setupCosEventForwarding() {
cosEvents.on('agent:updated', (data) => broadcastToCos('cos:agent:updated', toAgentListItem(data)));
cosEvents.on('agent:completed', (data) => broadcastToCos('cos:agent:completed', toAgentListItem(data)));
cosEvents.on('agent:output', (data) => broadcastToCos('cos:agent:output', data));
+ cosEvents.on('agent:feedback', (data) => broadcastToCos('cos:agent:feedback', data));
cosEvents.on('agent:btw', (data) => broadcastToCos('cos:agent:btw', data));
cosEvents.on('persistent-mind:status', (data) => broadcastToCos('cos:mind:status', data));
diff --git a/server/services/socket.test.js b/server/services/socket.test.js
index 71ad928cd2..9f6e0d2fcb 100644
--- a/server/services/socket.test.js
+++ b/server/services/socket.test.js
@@ -556,6 +556,21 @@ describe('socket.js — initSocket', () => {
expect(socket.emitted.some(([ev]) => ev === 'cos:unsubscribed')).toBe(true);
});
+ it('forwards submitted feedback only to CoS subscribers', () => {
+ const subscriber = makeSocket('feedback-subscriber');
+ const other = makeSocket('feedback-other');
+ createdSockets.push(subscriber, other);
+ io.connect(subscriber);
+ io.connect(other);
+ subscriber.handlers['cos:subscribe']();
+ const payload = { agentId: 'example-agent', feedback: { rating: 'positive', comment: null, submittedAt: '2026-07-13T12:00:00.000Z' } };
+ const listener = queueListeners.cos.find(([event]) => event === 'agent:feedback')?.[1];
+ listener(payload);
+ expect(subscriber.emitted).toContainEqual(['cos:agent:feedback', payload]);
+ expect(other.emitted.some(([event]) => event === 'cos:agent:feedback')).toBe(false);
+ expect(io.emitted.some(([event]) => event === 'cos:agent:feedback')).toBe(false);
+ });
+
it('forwards task lifecycle changes with the task payload to CoS subscribers', () => {
const socket = makeSocket('task-events');
createdSockets.push(socket);