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 (codex): clear stale logs when switching process/tail

[._.]/ Adam Eivy6a08e9860cc1
diff --git a/client/src/components/ui/ProcessLogModal.jsx b/client/src/components/ui/ProcessLogModal.jsx
index 1a2881d937..7575bcc32a 100644
--- a/client/src/components/ui/ProcessLogModal.jsx
+++ b/client/src/components/ui/ProcessLogModal.jsx
@@ -32,9 +32,13 @@ export default function ProcessLogModal({ open, onClose, processName, title = 'S
// slow response can't clobber the newer process's logs.
const reqIdRef = useRef(0);
- // Seed the selected process from the caller's hint whenever the modal opens.
+ // Seed the selected process from the caller's hint whenever the modal opens,
+ // and drop any prior run's logs so they never flash under the new title.
useEffect(() => {
- if (open) setSelected(processName || '');
+ if (!open) return;
+ setSelected(processName || '');
+ setLogs('');
+ setError('');
}, [open, processName]);
// Load the PM2 process picker options once per open (static across a session).
@@ -52,6 +56,9 @@ export default function ProcessLogModal({ open, onClose, processName, title = 'S
const reqId = ++reqIdRef.current;
setLoading(true);
setError('');
+ // Clear the prior logs so the in-flight fetch shows the spinner instead of
+ // the previous process/tail's output (which could sit under a new title).
+ setLogs('');
const res = await api.getProcessLogs(selected, tailLines).catch((err) => {
if (reqId === reqIdRef.current) setError(err?.message || 'Failed to load logs');
return null;
diff --git a/client/src/components/ui/ProcessLogModal.test.jsx b/client/src/components/ui/ProcessLogModal.test.jsx
index 3f58e5b7f2..78639cec09 100644
--- a/client/src/components/ui/ProcessLogModal.test.jsx
+++ b/client/src/components/ui/ProcessLogModal.test.jsx
@@ -35,6 +35,23 @@ describe('ProcessLogModal', () => {
await waitFor(() => expect(getProcessLogs).toHaveBeenCalledWith('portos-server', 500));
});
+ it('does not keep showing the prior process logs while the next fetch is in flight', async () => {
+ let resolveSecond;
+ getProcessLogs
+ .mockResolvedValueOnce({ logs: 'server logs here' })
+ .mockImplementationOnce(() => new Promise((r) => { resolveSecond = r; }));
+ render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);
+ expect(await screen.findByText('server logs here')).toBeInTheDocument();
+
+ fireEvent.change(screen.getByLabelText('Process'), { target: { value: 'portos-cos' } });
+ await waitFor(() => expect(getProcessLogs).toHaveBeenLastCalledWith('portos-cos', 200));
+ // The stale portos-server logs must be gone while portos-cos is still loading.
+ expect(screen.queryByText('server logs here')).not.toBeInTheDocument();
+
+ resolveSecond({ logs: 'cos logs here' });
+ expect(await screen.findByText('cos logs here')).toBeInTheDocument();
+ });
+
it('surfaces a fetch error instead of log text', async () => {
getProcessLogs.mockRejectedValueOnce(new Error('daemon down'));
render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);