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
perf: single-flight shell bootstrap reads for settings, voice config and capabilities (#13180)
Adam Eivya4a26ba403c6
diff --git a/client/src/services/apiCore.js b/client/src/services/apiCore.jsindex 755dfd563b..7012a314d8 100644--- a/client/src/services/apiCore.js+++ b/client/src/services/apiCore.js@@ -55,6 +55,20 @@ export function request(endpoint, options = {}) {return trackRequest(performRequest(endpoint, options));}+// Shell bootstrap reads (settings, voice config, capabilities) are fetched by+// several concurrently mounted components. Share one in-flight request per key;+// 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) {+ let pending = inflightReads.get(key);+ if (!pending) {+ pending = start().finally(() => inflightReads.delete(key));+ inflightReads.set(key, pending);+ }+ return pending.then((value) => (value && typeof value === 'object' ? structuredClone(value) : value));+}+async function performRequest(endpoint, options = {}) {// `hostControlOptional` marks a background read whose caller renders its own// "needs operator authority" state, so a host-control refusal does not toast.diff --git a/client/src/services/apiCore.test.js b/client/src/services/apiCore.test.jsindex b5a180685e..7e6af305b3 100644--- a/client/src/services/apiCore.test.js+++ b/client/src/services/apiCore.test.js@@ -14,6 +14,8 @@ vi.mock('../components/ui/Toast', () => {import toast from '../components/ui/Toast';import { throwApiError, request, uploadBody, isServerUnreachable } from './apiCore.js';+import { getSettings, getCapabilities } from './apiSystem.js';+import { getVoiceConfig } from './apiVoice.js';const makeResponse = ({ status = 400, ok = false, json = null } = {}) => ({status,@@ -157,3 +159,23 @@ it('streams Blob uploads with a browser boundary and retains legacy JSON callersexpect(await options.body.get('file').text()).toBe('video bytes');expect(JSON.parse(uploadBody('YWJj', 'old.mp4'))).toEqual({ data: 'YWJj', filename: 'old.mp4' });});++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 })]);+ 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 });+ expect(a).not.toBe(b);+ await getSettings();+ expect(global.fetch).toHaveBeenCalledTimes(4);+ });++ 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 });+ global.fetch.mockResolvedValueOnce(makeResponse({ status: 200, ok: true, json: { ok: 1 } }));+ await expect(getSettings({ silent: true })).resolves.toEqual({ ok: 1 });+ });+});diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.jsindex e318cf2629..701a3766cd 100644--- a/client/src/services/apiSystem.js+++ b/client/src/services/apiSystem.js@@ -1,4 +1,4 @@-import { uploadBody, request, API_BASE, throwApiError } from './apiCore.js';+import { uploadBody, request, singleFlightRead, API_BASE, throwApiError } from './apiCore.js';import { downloadBlob } from '../lib/downloadBlob.js';export const rectifyModelDuplicates = (payload, options = {}) => request('/system-resources/duplicates/rectify', {@@ -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) => request('/capabilities', options);+export const getCapabilities = (options) => singleFlightRead('/capabilities', () => request('/capabilities', 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) => request('/settings', options);+export const getSettings = (options) => singleFlightRead('/settings', () => request('/settings', 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" fordiff --git a/client/src/services/apiVoice.js b/client/src/services/apiVoice.jsindex 66e2dd5d77..cbb47f5143 100644--- a/client/src/services/apiVoice.js+++ b/client/src/services/apiVoice.js@@ -1,10 +1,10 @@-import api from './apiCore';+import api, { singleFlightRead } from './apiCore';// `options` lets callers pass `{ silent: true }` so apiCore's default toast// 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) => api.get('/voice/config', options);+export const getVoiceConfig = (options) => singleFlightRead('/voice/config', () => api.get('/voice/config', 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);