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 (copilot): generation-guard the failure revert path too

Adam Eivy5906409999a3
diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsx
index 0fbbfd62d7..fe92a82e16 100644
--- a/client/src/pages/Dashboard.jsx
+++ b/client/src/pages/Dashboard.jsx
@@ -113,6 +113,9 @@ export default function Dashboard() {
})
.catch(() => {
if (cancelled) return;
+ // A user switch (even to this same id) supersedes the auto-switch
+ // and owns the displayed state — don't revert out from under it.
+ if (switchGenerationRef.current !== switchGen) return;
setActiveLayoutId((current) => (current === desiredActiveId ? data.activeLayoutId : current));
});
}
@@ -235,6 +238,10 @@ export default function Dashboard() {
await api.setActiveDashboardLayout(id)
.then(() => { if (switchGenerationRef.current === switchGen) serverConfirmedLayoutIdRef.current = id; })
.catch(() => {
+ // Only the latest switch may revert. A newer switch — even to this
+ // SAME id (which leaves `current === id` true) — supersedes this one
+ // and owns the displayed state; its own resolution will settle it.
+ if (switchGenerationRef.current !== switchGen) return;
setActiveLayoutId((current) => (current === id ? serverConfirmedLayoutIdRef.current : current));
});
};
@@ -273,6 +280,10 @@ export default function Dashboard() {
await api.setActiveDashboardLayout(id)
.then(() => { if (switchGenerationRef.current === switchGen) serverConfirmedLayoutIdRef.current = id; })
.catch(() => {
+ // Only the latest switch may revert. A newer switch — even to this
+ // SAME id (which leaves `current === id` true) — supersedes this one
+ // and owns the displayed state; its own resolution will settle it.
+ if (switchGenerationRef.current !== switchGen) return;
setActiveLayoutId((current) => (current === id ? serverConfirmedLayoutIdRef.current : current));
});
};
diff --git a/client/src/pages/Dashboard.layoutRevert.test.js b/client/src/pages/Dashboard.layoutRevert.test.js
index 0622619f50..97b92d8b96 100644
--- a/client/src/pages/Dashboard.layoutRevert.test.js
+++ b/client/src/pages/Dashboard.layoutRevert.test.js
@@ -10,7 +10,8 @@ import { describe, it, expect } from 'vitest';
// - optimistic setActiveLayoutId(id)
// - on PUT success: stamp serverConfirmedLayoutIdRef = id ONLY if this is
// still the latest generation (guards against out-of-order resolution)
-// - on PUT failure: revert via functional setState, current === id ? confirmed : current
+// - on PUT failure: revert ONLY if still the latest generation (a newer
+// switch — even to the same id — owns the display) AND current === id
function createLayoutSwitcher(serverActiveId) {
let displayed = serverActiveId; // activeLayoutId
const serverConfirmed = { current: serverActiveId }; // serverConfirmedLayoutIdRef
@@ -27,6 +28,9 @@ function createLayoutSwitcher(serverActiveId) {
if (generation.current === myGen) serverConfirmed.current = id;
})
.catch(() => {
+ // only the latest switch may revert — a newer switch (even to the
+ // same id) supersedes this one and owns the displayed state
+ if (generation.current !== myGen) return;
// functional setState — only revert if still showing the failed id
displayed = displayed === id ? serverConfirmed.current : displayed;
});
@@ -97,4 +101,21 @@ describe('Dashboard active-layout revert', () => {
expect(sw.displayed).toBe('C'); // functional-setState guard preserves C
expect(sw.confirmed).toBe('C');
});
+
+ it('an earlier failed switch does not revert a newer switch to the SAME id', async () => {
+ // Copilot scenario: the user re-selects the layout that is already
+ // optimistically displayed while the first PUT is still in flight. The
+ // first PUT then fails. `current === id` is still true (same id shown), so
+ // the `current === id` guard alone would wrongly revert — but the newer
+ // switch (higher generation) owns the display and its PUT may yet succeed.
+ const sw = createLayoutSwitcher('A');
+ let failB1;
+ const pB1 = sw.selectLayout('B', new Promise((_, reject) => { failB1 = reject; })); // gen 1
+ const pB2 = sw.selectLayout('B', Promise.resolve()); // gen 2, re-select same id
+ await pB2; // newer switch confirms B
+ failB1(new Error('boom')); // older switch's PUT fails late
+ await pB1;
+ expect(sw.displayed).toBe('B'); // NOT reverted to A
+ expect(sw.confirmed).toBe('B');
+ });
});