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: key single-flight reads by error-handling options (#13180)

Adam Eivy6baff485dfb8
diff --git a/client/src/services/apiCore.js b/client/src/services/apiCore.js
index 7012a314d8..f09788548f 100644
--- a/client/src/services/apiCore.js
+++ b/client/src/services/apiCore.js
@@ -60,7 +60,10 @@ export function request(endpoint, options = {}) {
// the entry clears on settle so later calls (e.g. after a socket push) refetch.
// Each caller gets its own clone so one consumer's mutation can't leak into another.
const inflightReads = new Map();
-export function singleFlightRead(key, start) {
+// Options that change error handling are part of the key, so a silent caller never
+// joins (or starts) a flight whose failure toasts, and vice versa.
+export function singleFlightRead(endpoint, start, options = {}) {
+ const key = `${endpoint}|silent:${!!options.silent}|hco:${!!options.hostControlOptional}`;
let pending = inflightReads.get(key);
if (!pending) {
pending = start().finally(() => inflightReads.delete(key));
diff --git a/client/src/services/apiCore.test.js b/client/src/services/apiCore.test.js
index 7e6af305b3..76c80e7438 100644
--- a/client/src/services/apiCore.test.js
+++ b/client/src/services/apiCore.test.js
@@ -163,7 +163,7 @@ it('streams Blob uploads with a browser boundary and retains legacy JSON callers
describe('shell bootstrap reads are single-flight', () => {
it('shares one request across concurrent consumers, then refetches after settle', async () => {
global.fetch.mockImplementation(async () => makeResponse({ status: 200, ok: true, json: { n: 1 } }));
- const [a, b] = await Promise.all([getSettings(), getSettings({ silent: true })]);
+ const [a, b] = await Promise.all([getSettings({ silent: true }), getSettings({ silent: true })]);
await Promise.all([getVoiceConfig(), getVoiceConfig(), getCapabilities(), getCapabilities()]);
expect(global.fetch.mock.calls.map(([url]) => url)).toEqual(['/api/settings', '/api/voice/config', '/api/capabilities']);
expect(a).toEqual({ n: 1 });
@@ -172,6 +172,14 @@ describe('shell bootstrap reads are single-flight', () => {
expect(global.fetch).toHaveBeenCalledTimes(4);
});
+ it('keeps silent and non-silent callers on separate flights so error handling is not inherited', async () => {
+ global.fetch.mockImplementation(async () => makeResponse({ status: 500, json: { error: 'boom' } }));
+ const results = await Promise.allSettled([getSettings(), getSettings({ silent: true }), getSettings({ silent: true })]);
+ expect(results.every((r) => r.status === 'rejected')).toBe(true);
+ expect(global.fetch).toHaveBeenCalledTimes(2);
+ expect(toast.error).toHaveBeenCalledTimes(1);
+ });
+
it('does not cache a failure', async () => {
global.fetch.mockResolvedValueOnce(makeResponse({ status: 500, json: { error: 'boom' } }));
await expect(getSettings({ silent: true })).rejects.toMatchObject({ status: 500 });
diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.js
index 701a3766cd..3fed9a08ce 100644
--- a/client/src/services/apiSystem.js
+++ b/client/src/services/apiSystem.js
@@ -31,7 +31,7 @@ export const getSystemActivity = (options) => request('/system/activity', option
// nvidia-smi samples. Polled only while the live-activity inspector is visible.
export const getGpuTelemetry = (options) => request('/system/gpu-telemetry', options);
export const getNetworkExposure = (options) => request('/network-exposure/status', options);
-export const getCapabilities = (options) => singleFlightRead('/capabilities', () => request('/capabilities', options));
+export const getCapabilities = (options) => singleFlightRead('/capabilities', () => request('/capabilities', options), options);
// Machine-local hardware facts used for UI fit and recommendation surfaces.
// This endpoint deliberately stays outside peer-synced health payloads.
export const getSystemCapabilities = (options) => request('/system/capabilities', options);
@@ -85,7 +85,7 @@ export const syncPortosFork = (opts = {}, requestOpts = {}) => request('/update/
});
// Settings
-export const getSettings = (options) => singleFlightRead('/settings', () => request('/settings', options));
+export const getSettings = (options) => singleFlightRead('/settings', () => request('/settings', options), options);
export const getInstanceFeatures = (options) => request('/settings/features', options);
export const getCredentialInventory = (options) => request('/settings/credentials', options);
// `enabled` accepts `null` — the tri-state override going back to "inherit" for
diff --git a/client/src/services/apiVoice.js b/client/src/services/apiVoice.js
index cbb47f5143..16743a4900 100644
--- a/client/src/services/apiVoice.js
+++ b/client/src/services/apiVoice.js
@@ -4,7 +4,7 @@ import api, { singleFlightRead } from './apiCore';
// doesn't fire when the caller owns its own error UI (custom catch /
// useAsyncAction).
export const getVoiceStatus = (options) => api.get('/voice/status', options);
-export const getVoiceConfig = (options) => singleFlightRead('/voice/config', () => api.get('/voice/config', options));
+export const getVoiceConfig = (options) => singleFlightRead('/voice/config', () => api.get('/voice/config', options), options);
export const updateVoiceConfig = (patch, options) => api.put('/voice/config', patch, options);
export const listVoices = (engine, options) => api.get(`/voice/voices${engine ? `?engine=${engine}` : ''}`, options);
export const fetchPiperVoice = (voice, options) => api.post('/voice/piper/fetch', { voice }, options);