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: stream live agent output in Feature agent Output tab (#8424)

[._.]/ Adam Eivy4ccce60b4b43
diff --git a/client/src/components/feature-agents/OutputTab.jsx b/client/src/components/feature-agents/OutputTab.jsx
index 502ddea9d9..0aadc7067e 100644
--- a/client/src/components/feature-agents/OutputTab.jsx
+++ b/client/src/components/feature-agents/OutputTab.jsx
@@ -3,6 +3,8 @@ import { Terminal, RefreshCw } from 'lucide-react';
import * as api from '../../services/api';
import socket from '../../services/socket';
+const MAX_LIVE_LINES = 500;
+
export default function OutputTab({ agent }) {
const [output, setOutput] = useState('');
const [agentId, setAgentId] = useState(null);
@@ -37,16 +39,23 @@ export default function OutputTab({ agent }) {
loadOutput(agent.id);
const handler = (data) => {
- if (data.agentId === agent.currentAgentId || data.featureAgentId === agent.id) {
- setOutput(prev => prev + (data.chunk || data.output || ''));
+ if (data.agentId === agent.currentAgentId && data.line) {
+ setOutput(prev => {
+ // The fetched snapshot may not end in a newline; keep the first
+ // streamed line from gluing onto its last line.
+ const sep = prev && !prev.endsWith('\n') ? '\n' : '';
+ const next = `${prev}${sep}${data.line}\n`;
+ // Keep the last MAX_LIVE_LINES lines (the trailing newline leaves one
+ // empty entry after the split) so a long run can't grow unbounded.
+ const lines = next.split('\n');
+ return lines.length > MAX_LIVE_LINES + 1 ? lines.slice(-(MAX_LIVE_LINES + 1)).join('\n') : next;
+ });
}
};
socket.on('cos:agent:output', handler);
- socket.on('cos:feature-agent:output', handler);
return () => {
socket.off('cos:agent:output', handler);
- socket.off('cos:feature-agent:output', handler);
};
}, [agent.id, agent.currentAgentId, loadOutput]);
diff --git a/client/src/components/feature-agents/OutputTab.test.jsx b/client/src/components/feature-agents/OutputTab.test.jsx
index 2a9d89e894..8de48480a6 100644
--- a/client/src/components/feature-agents/OutputTab.test.jsx
+++ b/client/src/components/feature-agents/OutputTab.test.jsx
@@ -1,7 +1,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { act, fireEvent, render, screen } from '@testing-library/react';
-const getFeatureAgentOutput = vi.fn();
+const { getFeatureAgentOutput, mockSocketOn, mockSocketOff } = vi.hoisted(() => {
+ return {
+ getFeatureAgentOutput: vi.fn(),
+ mockSocketOn: vi.fn(),
+ mockSocketOff: vi.fn(),
+ };
+});
vi.mock('../../services/api', () => ({
getFeatureAgentOutput: (...args) => getFeatureAgentOutput(...args),
@@ -9,8 +15,8 @@ vi.mock('../../services/api', () => ({
vi.mock('../../services/socket', () => ({
default: {
- on: vi.fn(),
- off: vi.fn(),
+ on: mockSocketOn,
+ off: mockSocketOff,
},
}));
@@ -18,6 +24,8 @@ import OutputTab from './OutputTab.jsx';
beforeEach(() => {
getFeatureAgentOutput.mockReset();
+ mockSocketOn.mockReset();
+ mockSocketOff.mockReset();
});
describe('OutputTab staleness', () => {
@@ -120,3 +128,87 @@ describe('OutputTab staleness', () => {
expect(screen.getByText(/B output/)).toBeInTheDocument();
});
});
+
+describe('OutputTab live socket output', () => {
+ it('appends cos:agent:output frames with matching agentId', async () => {
+ getFeatureAgentOutput.mockResolvedValue({ output: 'initial', agentId: 'run-1' });
+
+ render(<OutputTab agent={{ id: 'agent-a', currentAgentId: 'run-1' }} />);
+ await act(async () => {});
+
+ expect(screen.getByText(/initial/)).toBeInTheDocument();
+
+ // Get the socket handler that was registered
+ const handler = mockSocketOn.mock.calls.find(call => call[0] === 'cos:agent:output')?.[1];
+ expect(handler).toBeDefined();
+
+ // Emit a line from the agent
+ await act(async () => {
+ handler({ agentId: 'run-1', line: 'line 1' });
+ });
+
+ expect(screen.getByText(/line 1/).textContent).toBe('initial\nline 1\n');
+
+ // Emit another line
+ await act(async () => {
+ handler({ agentId: 'run-1', line: 'line 2' });
+ });
+
+ expect(screen.getByText(/line 1/)).toBeInTheDocument();
+ expect(screen.getByText(/line 2/)).toBeInTheDocument();
+ });
+
+ it('ignores cos:agent:output frames for other agent ids', async () => {
+ getFeatureAgentOutput.mockResolvedValue({ output: 'initial', agentId: 'run-1' });
+
+ render(<OutputTab agent={{ id: 'agent-a', currentAgentId: 'run-1' }} />);
+ await act(async () => {});
+
+ const handler = mockSocketOn.mock.calls.find(call => call[0] === 'cos:agent:output')?.[1];
+
+ // Emit a line from a different agent
+ await act(async () => {
+ handler({ agentId: 'run-2', line: 'other agent output' });
+ });
+
+ // Should still only show initial output
+ expect(screen.getByText(/initial/)).toBeInTheDocument();
+ expect(screen.queryByText(/other agent output/)).not.toBeInTheDocument();
+ });
+
+ it('caps output to 500 lines to prevent unbounded growth', async () => {
+ getFeatureAgentOutput.mockResolvedValue({ output: '', agentId: 'run-1' });
+
+ render(<OutputTab agent={{ id: 'agent-a', currentAgentId: 'run-1' }} />);
+ await act(async () => {});
+
+ const handler = mockSocketOn.mock.calls.find(call => call[0] === 'cos:agent:output')?.[1];
+
+ // Emit 510 lines
+ await act(async () => {
+ for (let i = 0; i < 510; i++) {
+ handler({ agentId: 'run-1', line: `line ${i}` });
+ }
+ });
+
+ const text = screen.getByText(/line 509/).textContent;
+ expect(text.split('\n').filter(Boolean)).toHaveLength(500);
+ expect(text).not.toMatch(/line 9\n/);
+ });
+
+ it('unsubscribes from socket when component unmounts', async () => {
+ getFeatureAgentOutput.mockResolvedValue({ output: 'test', agentId: 'run-1' });
+
+ const { unmount } = render(<OutputTab agent={{ id: 'agent-a', currentAgentId: 'run-1' }} />);
+ await act(async () => {});
+
+ const registerCall = mockSocketOn.mock.calls.find(call => call[0] === 'cos:agent:output');
+ expect(registerCall).toBeDefined();
+
+ unmount();
+ await act(async () => {});
+
+ const unregisterCall = mockSocketOff.mock.calls.find(call => call[0] === 'cos:agent:output');
+ expect(unregisterCall).toBeDefined();
+ });
+});