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

address review (codex): kill before spawn, toast terminal SSE error, honor XDG_CACHE_HOME

[._.]/ Adam Eivybba51a4cc516
diff --git a/client/src/hooks/useModelDownloadStatus.js b/client/src/hooks/useModelDownloadStatus.js
index 477fe5cd01..51772511a4 100644
--- a/client/src/hooks/useModelDownloadStatus.js
+++ b/client/src/hooks/useModelDownloadStatus.js
@@ -1,5 +1,6 @@
-import { useEffect, useState, useCallback, useMemo, useRef } from 'react';
+import { useEffect, useState, useCallback, useMemo } from 'react';
import { useSseProgress } from './useSseProgress.js';
+import toast from '../components/ui/Toast';
import { getImageModelStatuses, getVideoModelStatuses } from '../services/apiImageVideo.js';
// Sentinel `modelId` used to drive a text-encoder download instead of a model
@@ -58,12 +59,19 @@ export function useModelDownloadStatus({ kind = 'image' } = {}) {
// Refetch on natural stream close. useSseProgress flips `closed:true` once
// per subscription and resets to false when the URL changes; that single
// transition is the safe signal — no extra `wasClosed` ref needed.
+ // A terminal error frame (gated repo, missing HF token, broken venv) is
+ // routed to a toast here because the active-badge state vanishes the moment
+ // we clear `activeModelId`; without this, the UI silently snaps back to the
+ // Download button and the actionable server message is lost.
useEffect(() => {
if (sse.closed) {
+ if (sse.latest?.type === 'error' && sse.latest?.message) {
+ toast.error(sse.latest.message);
+ }
fetchStatuses();
setActiveModelId(null);
}
- }, [sse.closed, fetchStatuses]);
+ }, [sse.closed, sse.latest, fetchStatuses]);
const start = useCallback((modelId) => {
setActiveModelId(modelId);
diff --git a/server/lib/hfCache.js b/server/lib/hfCache.js
index d9437f40b9..1bb407fcbc 100644
--- a/server/lib/hfCache.js
+++ b/server/lib/hfCache.js
@@ -25,12 +25,14 @@ import { homedir } from 'node:os';
import { join } from 'node:path';
// HF cache root resolution mirrors huggingface_hub's own precedence:
-// HF_HUB_CACHE > HF_HOME/hub > ~/.cache/huggingface/hub. We never set
-// HF_HOME ourselves (see imageGen/local.js header), so the third branch
-// is the common path for PortOS installs.
+// HF_HUB_CACHE > HF_HOME/hub > $XDG_CACHE_HOME/huggingface/hub
+// > ~/.cache/huggingface/hub. Skipping the XDG branch (the python lib does
+// honor it) would silently report a freshly-downloaded model as not cached
+// on Linux installs that set XDG_CACHE_HOME to a non-default location.
export const getHfCacheRoot = () => {
if (process.env.HF_HUB_CACHE) return process.env.HF_HUB_CACHE;
if (process.env.HF_HOME) return join(process.env.HF_HOME, 'hub');
+ if (process.env.XDG_CACHE_HOME) return join(process.env.XDG_CACHE_HOME, 'huggingface', 'hub');
return join(homedir(), '.cache', 'huggingface', 'hub');
};
diff --git a/server/lib/hfCache.test.js b/server/lib/hfCache.test.js
index 8e0710f4cd..650ce71a79 100644
--- a/server/lib/hfCache.test.js
+++ b/server/lib/hfCache.test.js
@@ -31,17 +31,21 @@ describe('hfCache', () => {
let originalEnv;
beforeEach(() => {
- originalEnv = { HF_HUB_CACHE: process.env.HF_HUB_CACHE, HF_HOME: process.env.HF_HOME };
+ originalEnv = {
+ HF_HUB_CACHE: process.env.HF_HUB_CACHE,
+ HF_HOME: process.env.HF_HOME,
+ XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
+ };
});
afterEach(() => {
- process.env.HF_HUB_CACHE = originalEnv.HF_HUB_CACHE;
- process.env.HF_HOME = originalEnv.HF_HOME;
- if (originalEnv.HF_HUB_CACHE === undefined) delete process.env.HF_HUB_CACHE;
- if (originalEnv.HF_HOME === undefined) delete process.env.HF_HOME;
+ for (const key of Object.keys(originalEnv)) {
+ if (originalEnv[key] === undefined) delete process.env[key];
+ else process.env[key] = originalEnv[key];
+ }
});
- it('resolves cache root with precedence HF_HUB_CACHE > HF_HOME/hub > ~/.cache', () => {
+ it('resolves cache root with precedence HF_HUB_CACHE > HF_HOME/hub > XDG_CACHE_HOME/huggingface/hub > ~/.cache', () => {
process.env.HF_HUB_CACHE = '/explicit/hub';
expect(getHfCacheRoot()).toBe('/explicit/hub');
@@ -50,6 +54,10 @@ describe('hfCache', () => {
expect(getHfCacheRoot()).toBe('/custom/hf/hub');
delete process.env.HF_HOME;
+ process.env.XDG_CACHE_HOME = '/xdg/cache';
+ expect(getHfCacheRoot()).toBe('/xdg/cache/huggingface/hub');
+
+ delete process.env.XDG_CACHE_HOME;
expect(getHfCacheRoot()).toMatch(/\.cache\/huggingface\/hub$/);
});
diff --git a/server/lib/hfDownload.js b/server/lib/hfDownload.js
index c46135e53c..3084379e80 100644
--- a/server/lib/hfDownload.js
+++ b/server/lib/hfDownload.js
@@ -53,12 +53,20 @@ export function downloadHfRepo({ repo, revision = null, onEvent }) {
const promise = (async () => {
const pythonPath = await resolveHfDownloadPython();
+ // Cancel-before-spawn check. resolveHfDownloadPython runs an
+ // isFlux2VenvHealthy() probe (several hundred ms cold) and getHfTokenInfo
+ // does file I/O; a kill() landing inside either await otherwise still
+ // lets the spawn fire below, leaving a multi-GB HF download running with
+ // no SSE client to consume progress and holding the inFlight slot until
+ // the whole snapshot finishes.
+ if (killed) return { ok: false, errorKind: 'cancelled', errorMessage: 'Cancelled' };
if (!pythonPath) {
const msg = 'No Python venv with huggingface_hub found. Install the FLUX.2 venv from Image Gen settings first.';
onEvent({ type: 'error', message: msg, kind: 'venv_missing' });
return { ok: false, errorKind: 'venv_missing', errorMessage: msg };
}
const { token } = await getHfTokenInfo();
+ if (killed) return { ok: false, errorKind: 'cancelled', errorMessage: 'Cancelled' };
const env = { ...process.env };
// The Python helper looks up the token by env-var name so we don't have
// to pass secrets on argv. Strip any stale value when the user has
@@ -73,6 +81,10 @@ export function downloadHfRepo({ repo, revision = null, onEvent }) {
return new Promise((resolve) => {
proc = spawn(pythonPath, args, { env, stdio: ['ignore', 'pipe', 'pipe'] });
+ // Window: kill() could have fired between the second `if (killed)`
+ // check and the spawn returning the proc handle. Re-check now that we
+ // own a proc — if it raced, kill it immediately.
+ if (killed) proc.kill('SIGTERM');
const handleLine = (raw) => {
const line = raw.trim();