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): make the streamed HF install a POST, not a state-changing GET
[._.]/ Adam Eivyf88db4fb34fc
diff --git a/client/src/services/apiImageVideo.js b/client/src/services/apiImageVideo.jsindex 86480c411c..c2af39d8fc 100644--- a/client/src/services/apiImageVideo.js+++ b/client/src/services/apiImageVideo.js@@ -290,16 +290,21 @@ export const installLoraFromHuggingface = ({ url, family, silent = false } = {})// — `progress` is 0..1, or null when the server had no Content-Length to divide.//// Uses fetch() + a stream reader rather than EventSource, mirroring-// streamLocalLlmTest: (1) EventSource auto-reconnects on any transport drop,-// which for this NON-idempotent install would silently start a second multi-GB-// download; a single fetch never retries. (2) it honors session expiry — a 401-// AUTH_REQUIRED bounces to /login via maybeRedirectToLogin exactly like-// request(), instead of dead-ending on a generic stream error. The frames are+// streamLocalLlmTest: (1) a POST (not an EventSource GET) — this install mutates+// state, and a state-changing GET would be CSRF-reachable via a top-level+// cross-origin navigation; (2) EventSource auto-reconnects on any transport+// drop, which for this NON-idempotent install would silently start a second+// multi-GB download — a single fetch never retries; (3) it honors session expiry+// — a 401 AUTH_REQUIRED bounces to /login via maybeRedirectToLogin exactly like+// request(), instead of dead-ending on a generic stream error. Frames are// SSE-encoded (`data: {json}\n\n`).export async function installLoraFromHuggingfaceStream({ url, family, onProgress, signal } = {}) {- const params = new URLSearchParams({ url });- if (family) params.set('family', family);- const response = await fetch(`${API_BASE}/loras/install/huggingface/stream?${params.toString()}`, { signal });+ const response = await fetch(`${API_BASE}/loras/install/huggingface/stream`, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify(family ? { url, family } : { url }),+ signal,+ });if (!response.ok || !response.body?.getReader) {const err = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));maybeRedirectToLogin(response, err);diff --git a/server/routes/loras.js b/server/routes/loras.jsindex a980602de3..5a088bcbb3 100644--- a/server/routes/loras.js+++ b/server/routes/loras.js@@ -142,20 +142,23 @@ router.post('/install/huggingface', asyncHandler(async (req, res) => {}));// Streaming variant of the HF install for the manager UI. Same install, but-// emits byte-level download `progress` frames over SSE so the form can show a-// percentage instead of a static "Downloading…" (matching the image/video-// model download badge UX). EventSource is GET-only, so url/family ride in the-// query string; the HF token always comes from settings/env (never the query,-// to keep it out of URLs and access logs). Terminal frames:+// streams byte-level download `progress` frames (SSE-encoded) so the form can+// show a percentage instead of a static "Downloading…" (matching the image/video+// model download badge UX). POST, not GET: this endpoint mutates state (downloads+// + writes a LoRA), and the client reads the stream body with fetch() (not+// EventSource), so url/family ride in the JSON body — a state-changing GET would+// be reachable by a top-level cross-origin navigation carrying a SameSite=Lax+// session cookie (CSRF), which authGate's Origin check can't see. The HF token+// always comes from settings/env, never the request. Terminal frames:// `{type:'complete', sidecar}` or `{type:'error', message, code}` — the client// re-uses `code` (e.g. HF_UNKNOWN_FAMILY) to drive the inline family-confirm-// retry, exactly as the POST path's thrown error does.+// retry, exactly as the plain POST path's thrown error does.const hfInstallStreamSchema = z.object({url: z.string().min(1).max(1024),family: z.enum(Object.values(VIDEO_LORA_FAMILIES)).optional(),});-router.get('/install/huggingface/stream', asyncHandler(async (req, res) => {- const data = validateRequest(hfInstallStreamSchema, req.query);+router.post('/install/huggingface/stream', asyncHandler(async (req, res) => {+ const data = validateRequest(hfInstallStreamSchema, req.body);const { send, safeEnd } = openSseStream(res);// Headers are already flushed once the stream is open, so an install failure// must NOT bubble to the error middleware (it would try to re-set status on a@@ -164,10 +167,17 @@ router.get('/install/huggingface/stream', asyncHandler(async (req, res) => {// On client disconnect (tab close, navigation, dropped connection) actually// ABORT the download via the controller — not just suppress frames — so a// multi-GB LoRA transfer doesn't keep running unwatched and a retry can't race- // a still-in-flight install.+ // a still-in-flight install. Listen on RES, not REQ: this is a POST, and the+ // request stream emits 'close' the instant its body is fully read (Node+ // auto-destroys the consumed readable) — that is NOT a disconnect and would+ // wrongly abort every install. `res` 'close' while the response is not yet+ // finished is the true "client went away" signal; after a normal safeEnd()+ // it fires with writableEnded already true and is a harmless no-op.const controller = new AbortController();let aborted = false;- req.on('close', () => { aborted = true; controller.abort(); });+ res.on('close', () => {+ if (!res.writableEnded) { aborted = true; controller.abort(); }+ });await installFromHuggingface(data, {signal: controller.signal,onProgress: ({ received, total }) => {diff --git a/server/routes/loras.test.js b/server/routes/loras.test.jsindex 32aef09224..0fa0934746 100644--- a/server/routes/loras.test.js+++ b/server/routes/loras.test.js@@ -56,20 +56,21 @@ const makeApp = () => {return app;};-describe('GET /api/loras/install/huggingface/stream', () => {+describe('POST /api/loras/install/huggingface/stream', () => {it('streams byte-progress frames then a complete frame carrying the sidecar', async () => {const res = await request(makeApp())- .get('/api/loras/install/huggingface/stream?url=fal/ltx2.3-audio-reactive-lora');+ .post('/api/loras/install/huggingface/stream')+ .send({ url: 'fal/ltx2.3-audio-reactive-lora' });expect(res.status).toBe(200);const frames = parseSseFrames(res.text);// The service double emitted 4/8 then 8/8 → progress 0.5 then 1.expect(frames.filter((f) => f.type === 'progress').map((f) => f.progress)).toEqual([0.5, 1]);const complete = frames.find((f) => f.type === 'complete');expect(complete?.sidecar?.runnerFamily).toBe('ltx-video');- // Family override rides the query string through to the service.+ // The body carries through to the service, with an AbortSignal + progress cb.expect(installFromHuggingface).toHaveBeenCalledWith(expect.objectContaining({ url: 'fal/ltx2.3-audio-reactive-lora' }),- expect.objectContaining({ onProgress: expect.any(Function) }),+ expect.objectContaining({ onProgress: expect.any(Function), signal: expect.any(Object) }),);});@@ -78,7 +79,8 @@ describe('GET /api/loras/install/huggingface/stream', () => {Object.assign(new Error('could not classify'), { code: 'HF_UNKNOWN_FAMILY' }),);const res = await request(makeApp())- .get('/api/loras/install/huggingface/stream?url=someone/mystery');+ .post('/api/loras/install/huggingface/stream')+ .send({ url: 'someone/mystery' });expect(res.status).toBe(200); // headers already flushed — error is a frame, not a statusconst err = parseSseFrames(res.text).find((f) => f.type === 'error');expect(err.code).toBe('HF_UNKNOWN_FAMILY');@@ -87,7 +89,8 @@ describe('GET /api/loras/install/huggingface/stream', () => {it('rejects an invalid family override before opening the stream', async () => {const res = await request(makeApp())- .get('/api/loras/install/huggingface/stream?url=x/y&family=bogus');+ .post('/api/loras/install/huggingface/stream')+ .send({ url: 'x/y', family: 'bogus' });expect(res.status).toBe(400);});});