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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): serialize API access saves to avoid stale overwrites
Adam Eivy0ec1fda312a0
diff --git a/client/src/components/settings/ApiAccessTab.jsx b/client/src/components/settings/ApiAccessTab.jsxindex 0a980483cc..e1333f86d7 100644--- a/client/src/components/settings/ApiAccessTab.jsx+++ b/client/src/components/settings/ApiAccessTab.jsx@@ -119,7 +119,13 @@ export function ApiAccessTab() {{API_CARDS.map((card) => {const entry = entryFor(card.id);- const busy = savingId === card.id;+ // Disable EVERY card's toggles while ANY save is in flight, not just+ // this card's. Each PUT sends a full apiAccess snapshot and the server+ // replaces the whole key, so two overlapping saves could let the older+ // one land last and clobber the newer toggle. Serializing to one save+ // at a time removes the race. `cardBusy` still drives this card's spinner.+ const cardBusy = savingId === card.id;+ const busy = savingId !== null;return (<div key={card.id} className="bg-port-card border border-port-border rounded-xl p-4 sm:p-6 space-y-4"><div className="flex items-start justify-between gap-3">@@ -136,7 +142,7 @@ export function ApiAccessTab() {</div><p className="text-xs text-gray-500 mt-1">{card.description}</p></div>- {busy && <BrailleSpinner />}+ {cardBusy && <BrailleSpinner />}</div><div className="grid grid-cols-1 sm:grid-cols-2 gap-3">diff --git a/client/src/components/settings/ApiAccessTab.test.jsx b/client/src/components/settings/ApiAccessTab.test.jsxindex c6e1684dae..9b95000fc2 100644--- a/client/src/components/settings/ApiAccessTab.test.jsx+++ b/client/src/components/settings/ApiAccessTab.test.jsx@@ -64,6 +64,29 @@ describe('ApiAccessTab', () => {expect(sentBody.apiAccess.voice.exposed).toBe(true);});+ it('CONTRACT: disables ALL toggles while a save is in flight (serialize saves)', async () => {+ // Overlapping saves could let an older full-snapshot PUT land last and+ // clobber a newer toggle. While one save is pending, every toggle (this+ // card's and the other card's) must be disabled so saves serialize.+ getSettings.mockResolvedValue({+ apiAccess: { voice: { exposed: false, requireAuth: false }, sdapi: { exposed: false, requireAuth: false } },+ });+ let resolveSave;+ updateSettings.mockReturnValue(new Promise((res) => { resolveSave = res; }));+ await renderTab();++ const exposeToggles = screen.getAllByLabelText(/Expose on the network/i);+ fireEvent.click(exposeToggles[0]); // start voice save (never resolves yet)++ // While the voice save is in flight, the OTHER card's expose toggle is disabled.+ await waitFor(() => {+ const toggles = screen.getAllByLabelText(/Expose on the network/i);+ expect(toggles[1].disabled).toBe(true);+ });++ resolveSave({}); // let the save settle so the test exits cleanly+ });+it('reverts optimistic state when the save fails', async () => {getSettings.mockResolvedValue({ apiAccess: { voice: { exposed: false, requireAuth: false }, sdapi: { exposed: false, requireAuth: false } } });updateSettings.mockRejectedValue(new Error('boom'));