mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-22 09:34:53 +02:00
[eric] efficiency: preflight classifier stamps cooldown whenever it runs (was re-firing Haiku every turn on concrete prompts); remove warm_prompt_cache (billed N no-op requests/dashboard-mount, warmed nothing: wrong prefix, below cache floor, no cache_control)
This commit is contained in:
@@ -156,34 +156,7 @@ export function useDashboardLifecycle({
|
||||
? (window as any).requestIdleCallback(loadDeferred, { timeout: 2000 })
|
||||
: window.setTimeout(loadDeferred, 200);
|
||||
|
||||
// Pre-warm Anthropic's prompt cache for sessions on this dashboard ~250ms after mount (debounced; AbortController cancels on dashboard switch). Fires a max_tokens=1 ping per session so the user's first real message hits a warm cache instead of paying cold-start TTFT. Cheap (~$0.0001/session) and non-blocking. Skips for non-Anthropic sessions server-side.
|
||||
const warmAbort = new AbortController();
|
||||
const warmTimer = setTimeout(async () => {
|
||||
try {
|
||||
const sessionsState = store.getState().agents.sessions;
|
||||
const dashSessions = Object.values(sessionsState).filter(
|
||||
(s) => s.dashboard_id === dashboardId &&
|
||||
s.status !== 'draft' &&
|
||||
s.mode !== 'browser-agent' &&
|
||||
s.mode !== 'sub-agent' &&
|
||||
s.mode !== 'invoked-agent',
|
||||
);
|
||||
for (const s of dashSessions) {
|
||||
if (warmAbort.signal.aborted) break;
|
||||
// Fire-and-forget, the endpoint always 200s and the side effect is invisible cache population.
|
||||
fetch(`${API_BASE}/agents/sessions/${s.id}/warm-cache`, {
|
||||
method: 'POST',
|
||||
signal: warmAbort.signal,
|
||||
}).catch(() => {});
|
||||
}
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
}, 250);
|
||||
|
||||
return () => {
|
||||
clearTimeout(warmTimer);
|
||||
warmAbort.abort();
|
||||
cleanupBrowserHandler();
|
||||
unsubReconnect();
|
||||
dashboardWs.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user