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: address review round 2 — concurrency-safe revert + stronger test contracts (#2519)

Adam Eivy11b57928deab
diff --git a/client/src/components/cos/tabs/ConfigTab.jsx b/client/src/components/cos/tabs/ConfigTab.jsx
index bcfc9a2f56..6d6a745cb0 100644
--- a/client/src/components/cos/tabs/ConfigTab.jsx
+++ b/client/src/components/cos/tabs/ConfigTab.jsx
@@ -280,11 +280,8 @@ export default function ConfigTab({ config, onUpdate, onEvaluate, avatarStyle, s
});
const handleLevelChange = async (params, label) => {
- // Optimistically reflect the new params via a functional update, but revert
- // ONLY the keys we set if the PUT fails — snapshotting and restoring the whole
- // formData would clobber unrelated edits (or a later level pick) the user made
- // while this request was in flight. Success toast / refresh only fire after the
- // request resolves.
+ // Optimistically reflect the new params via a functional update. Success toast
+ // / refresh only fire after the request resolves.
const revertKeys = Object.fromEntries(Object.keys(params).map(k => [k, formData[k]]));
setFormData(prev => ({ ...prev, ...params }));
try {
@@ -292,7 +289,16 @@ export default function ConfigTab({ config, onUpdate, onEvaluate, avatarStyle, s
if (label) toast.success(`Autonomy level set to ${label}`);
onUpdate();
} catch (err) {
- setFormData(prev => ({ ...prev, ...revertKeys }));
+ // Roll back only keys still holding THIS request's optimistic value — a newer
+ // successful level pick (or edit) to the same key must win, so a late-failing
+ // request can't clobber it with the stale value it captured at click time.
+ setFormData(prev => {
+ const next = { ...prev };
+ for (const key of Object.keys(params)) {
+ if (prev[key] === params[key]) next[key] = revertKeys[key];
+ }
+ return next;
+ });
toast.error(err.message);
}
};
diff --git a/client/src/components/cos/tabs/ConfigTab.test.jsx b/client/src/components/cos/tabs/ConfigTab.test.jsx
index 8a64befbd7..cc2431869c 100644
--- a/client/src/components/cos/tabs/ConfigTab.test.jsx
+++ b/client/src/components/cos/tabs/ConfigTab.test.jsx
@@ -70,6 +70,8 @@ describe('ConfigTab handleSave', () => {
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Configuration updated'));
expect(onUpdate).toHaveBeenCalled();
+ // The PUT must pass { silent: true } so the custom catch is the only error toast.
+ expect(api.updateCosConfig).toHaveBeenCalledWith(expect.any(Object), { silent: true });
// Editor closed — the Edit button is back.
expect(screen.getByRole('button', { name: /Edit/i })).toBeInTheDocument();
});
@@ -104,7 +106,7 @@ describe('ConfigTab handleLevelChange', () => {
expect(rowValue('Max Concurrent Agents')('3')).toBeInTheDocument();
});
- it('keeps the optimistic params and toasts the label after the change resolves', async () => {
+ it('keeps the optimistic params and toasts the label (silently) after the change resolves', async () => {
api.updateCosConfig.mockResolvedValue({ success: true });
render(<ConfigTab config={config} onUpdate={vi.fn()} onEvaluate={vi.fn()} avatarStyle="svg" setAvatarStyle={vi.fn()} />);
@@ -113,5 +115,35 @@ describe('ConfigTab handleLevelChange', () => {
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Autonomy level set to Standby'));
// Optimistic value persisted (Standby → maxConcurrentAgents: 1).
expect(rowValue('Max Concurrent Agents')('1')).toBeInTheDocument();
+ // The PUT must pass { silent: true } so the custom catch is the only error toast.
+ expect(api.updateCosConfig).toHaveBeenCalledWith(
+ expect.objectContaining({ maxConcurrentAgents: 1 }),
+ { silent: true },
+ );
+ });
+
+ it('does not clobber a newer successful preset when an earlier request fails late', async () => {
+ // Standby's PUT stays pending; YOLO's resolves first. When Standby then
+ // rejects, its rollback must NOT restore stale values over YOLO's now-
+ // persisted preset — only keys still holding Standby's optimistic value revert.
+ let rejectStandby;
+ api.updateCosConfig.mockImplementation((params) => {
+ if (params.maxConcurrentAgents === 1) {
+ return new Promise((_, reject) => { rejectStandby = () => reject(new Error('boom')); });
+ }
+ return Promise.resolve({ success: true });
+ });
+ render(<ConfigTab config={config} onUpdate={vi.fn()} onEvaluate={vi.fn()} avatarStyle="svg" setAvatarStyle={vi.fn()} />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Standby' })); // optimistic → 1 (pending)
+ fireEvent.click(screen.getByRole('button', { name: 'YOLO' })); // optimistic → 5 (resolves)
+
+ await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Autonomy level set to YOLO'));
+ expect(rowValue('Max Concurrent Agents')('5')).toBeInTheDocument();
+
+ rejectStandby();
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('boom'));
+ // YOLO's value survives — the stale Standby rollback must not reset it to 3.
+ expect(rowValue('Max Concurrent Agents')('5')).toBeInTheDocument();
});
});
diff --git a/client/src/components/cos/tabs/TasksTab.test.jsx b/client/src/components/cos/tabs/TasksTab.test.jsx
index a93e1e09e3..f1108152f6 100644
--- a/client/src/components/cos/tabs/TasksTab.test.jsx
+++ b/client/src/components/cos/tabs/TasksTab.test.jsx
@@ -42,5 +42,7 @@ describe('TasksTab Run Now', () => {
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Evaluation triggered'));
expect(toast.error).not.toHaveBeenCalled();
+ // Must pass { silent: true } so the custom catch is the only error toast.
+ expect(api.forceCosEvaluate).toHaveBeenCalledWith({ silent: true });
});
});
diff --git a/client/src/pages/ChiefOfStaff.test.jsx b/client/src/pages/ChiefOfStaff.test.jsx
index d2228f1c8f..0e75b8f333 100644
--- a/client/src/pages/ChiefOfStaff.test.jsx
+++ b/client/src/pages/ChiefOfStaff.test.jsx
@@ -71,7 +71,7 @@ const renderConfigTab = () => render(
);
describe('ChiefOfStaff handleForceEvaluate', () => {
- it('does not toast success when the evaluate request fails', async () => {
+ it('does not toast success or advance the status message when the evaluate fails', async () => {
api.forceCosEvaluate.mockRejectedValue(new Error('evaluate failed'));
renderConfigTab();
@@ -80,9 +80,13 @@ describe('ChiefOfStaff handleForceEvaluate', () => {
await waitFor(() => expect(toast.error).toHaveBeenCalledWith('evaluate failed'));
expect(toast.success).not.toHaveBeenCalled();
+ // State contract: a failed evaluate must NOT switch the status bubble to the
+ // "Evaluating tasks..." (thinking) message — it stays on the idle message.
+ expect(screen.queryAllByText('Evaluating tasks...')).toHaveLength(0);
+ expect(screen.queryAllByText('Idle - waiting for tasks...').length).toBeGreaterThan(0);
});
- it('toasts success only after the evaluate request resolves', async () => {
+ it('toasts success and advances the status message after the evaluate resolves', async () => {
api.forceCosEvaluate.mockResolvedValue({ success: true });
renderConfigTab();
@@ -91,5 +95,9 @@ describe('ChiefOfStaff handleForceEvaluate', () => {
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Evaluation triggered'));
expect(toast.error).not.toHaveBeenCalled();
+ // State contract: success advances the status bubble to the evaluating message.
+ await waitFor(() => expect(screen.queryAllByText('Evaluating tasks...').length).toBeGreaterThan(0));
+ // Must pass { silent: true } so the custom catch is the only error toast.
+ expect(api.forceCosEvaluate).toHaveBeenCalledWith({ silent: true });
});
});