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): paginate brain links to 5000 cap, include HiDream aux text encoder in download status + prefetch
[._.]/ Adam Eivy3e4478487352
diff --git a/client/src/components/brain/tabs/LinksTab.jsx b/client/src/components/brain/tabs/LinksTab.jsxindex f10f87614a..5d9c3664e4 100644--- a/client/src/components/brain/tabs/LinksTab.jsx+++ b/client/src/components/brain/tabs/LinksTab.jsx@@ -77,10 +77,13 @@ export default function LinksTab({ onRefresh }) {const [scanningId, setScanningId] = useState(null);const inputRef = useRef(null);- // Fetch the full link set; filtering happens client-side so the bucket board- // always sees every link regardless of the list filter.+ // Fetch the full link set; filtering, search, and bucket membership are all+ // computed client-side, so we need every link in one round-trip — the prior+ // `limit: 100` silently truncated power-user collections (>100 links lost+ // from list views, search, and bucket boards). The server schema caps at+ // 5000, which is ample headroom for a single-user bookmark collection.const fetchLinks = useCallback(async () => {- const data = await api.getBrainLinks({ limit: 100, silent: true }).catch(() => ({ links: [] }));+ const data = await api.getBrainLinks({ limit: 5000, silent: true }).catch(() => ({ links: [] }));setLinks(data.links || []);setLoading(false);}, []);diff --git a/server/lib/brainValidation.js b/server/lib/brainValidation.jsindex 36a2520601..818ffc2405 100644--- a/server/lib/brainValidation.js+++ b/server/lib/brainValidation.js@@ -383,7 +383,11 @@ export const linksQuerySchema = z.object({v => (typeof v === 'string' ? v === 'true' : v),z.boolean()).optional(),- limit: z.coerce.number().int().min(1).max(100).optional().default(50),+ // LinksTab does its own filtering, search, and bucket assignment client-side+ // over the full set — so the upper cap has to be large enough to return every+ // saved link in one round-trip. 5000 is plenty of headroom for a single-user+ // bookmark collection without being unbounded.+ limit: z.coerce.number().int().min(1).max(5000).optional().default(50),offset: z.coerce.number().int().min(0).optional().default(0)});diff --git a/server/lib/mediaModels.js b/server/lib/mediaModels.jsindex f6de660a88..4b24cb2229 100644--- a/server/lib/mediaModels.js+++ b/server/lib/mediaModels.js@@ -691,6 +691,21 @@ export const repoForModel = (model) => {return null;};+// Full list of HF repos a model needs cached on disk before the runner can+// inference. For HiDream entries this includes the separate Llama-3.1 text+// encoder (`textEncoderRepo`) the Diffusers pipeline loads as `text_encoder_4`+// — otherwise the cache-status badge says "Available" while the renderer+// silently kicks off a second multi-GB gated download at start-up. Result is+// `null` when the main repo itself isn't known (model is misconfigured / a+// custom mflux third-party entry).+export const requiredReposForModel = (model) => {+ const main = repoForModel(model);+ if (!main) return null;+ const aux = [];+ if (isNonEmptyString(model?.textEncoderRepo)) aux.push(model.textEncoderRepo);+ return [main, ...aux];+};+// `getTextEncoderRepo()` can return either an HF repo id (`org/name`) or a// resolved local filesystem path when the registry entry has a `localPath`// override. Only `org/name` is a valid input to HF-cache inspection /diff --git a/server/lib/sseDownload.js b/server/lib/sseDownload.jsindex c30af7a191..4305f7e829 100644--- a/server/lib/sseDownload.js+++ b/server/lib/sseDownload.js@@ -17,39 +17,80 @@ const SSE_HEADERS = {Connection: 'keep-alive',};-export async function startHfDownloadStream({ req, res, repo, alreadyDownloadedMessage }) {+export async function startHfDownloadStream({ req, res, repo, repos, alreadyDownloadedMessage }) {+ // Caller passes either `repo` (single string, legacy callers) OR `repos`+ // (ordered array, used when a model has auxiliary repos that must be+ // present alongside the main weights — e.g. HiDream's separate Llama-3.1+ // text encoder). Multi-repo runs are sequential and short-circuit on any+ // single-repo error.+ const targets = Array.isArray(repos)+ ? repos.filter((r) => typeof r === 'string' && r.length > 0)+ : (typeof repo === 'string' && repo.length > 0 ? [repo] : []);res.writeHead(200, SSE_HEADERS);const send = (event) => {if (!res.writableEnded) res.write(`data: ${JSON.stringify(event)}\n\n`);};const safeEnd = () => { if (!res.writableEnded) res.end(); };+ if (targets.length === 0) {+ send({ type: 'error', message: 'No repo specified for download.' });+ return safeEnd();+ }+// Disconnect bookkeeping wired BEFORE the cache-inspection await. The// inspection can take double-digit ms on a cold cache; without this the// client closing mid-await would land after spawn with no kill path.- let handle = null;+ let currentHandle = null;let aborted = false;req.on('close', () => {aborted = true;- if (handle) handle.kill();+ if (currentHandle) currentHandle.kill();safeEnd();});- const existing = await inspectModelCache(repo);- if (aborted) return;- if (existing.cached) {- send({ type: 'complete', message: alreadyDownloadedMessage || `${repo} already downloaded.`, repo, sizeBytes: existing.sizeBytes });- return safeEnd();- }- if (inFlight.has(repo)) {- send({ type: 'error', message: `Another download for ${repo} is already running.`, kind: 'already_running' });- return safeEnd();+ let downloadedAny = false;+ let totalSize = 0;+ for (let i = 0; i < targets.length; i += 1) {+ const r = targets[i];+ if (aborted) return;+ const existing = await inspectModelCache(r);+ if (aborted) return;+ if (existing.cached) {+ totalSize += existing.sizeBytes || 0;+ send({ type: 'log', message: `${r} already cached (${existing.sizeBytes} bytes).`, repo: r, sizeBytes: existing.sizeBytes });+ continue;+ }+ if (inFlight.has(r)) {+ send({ type: 'error', message: `Another download for ${r} is already running.`, kind: 'already_running', repo: r });+ return safeEnd();+ }+ const handle = downloadHfRepo({ repo: r, onEvent: (ev) => send({ ...ev, repo: r }) });+ currentHandle = handle;+ inFlight.set(r, handle);+ try {+ await handle.promise;+ downloadedAny = true;+ } finally {+ inFlight.delete(r);+ currentHandle = null;+ }}- handle = downloadHfRepo({ repo, onEvent: send });- inFlight.set(repo, handle);- handle.promise.finally(() => {- inFlight.delete(repo);- safeEnd();- });+ if (!aborted) {+ let message;+ if (targets.length === 1) {+ // Preserve legacy single-repo `complete` message semantics: if it was+ // already cached on entry, surface the caller's `alreadyDownloadedMessage`+ // (or the default already-downloaded line).+ message = !downloadedAny+ ? (alreadyDownloadedMessage || `${targets[0]} already downloaded.`)+ : `${targets[0]} downloaded.`;+ } else {+ message = downloadedAny+ ? `Downloaded ${targets.length} repos: ${targets.join(', ')}`+ : `All ${targets.length} repos already cached: ${targets.join(', ')}`;+ }+ send({ type: 'complete', message, repos: targets, sizeBytes: totalSize });+ }+ safeEnd();}diff --git a/server/routes/imageGen.js b/server/routes/imageGen.jsindex 023c9aeff6..71c56c5a0e 100644--- a/server/routes/imageGen.js+++ b/server/routes/imageGen.js@@ -23,7 +23,7 @@ import { local, IMAGE_GEN_MODE, IMAGE_GEN_MODES, resolveImageCleaners } from '..import { enqueueJob, attachSseClient as attachQueueSseClient, cancelJob, listJobs } from '../services/mediaJobQueue/index.js';import { getSettings, saveSettings } from '../services/settings.js';import { getHfToken, getHfTokenInfo, HF_TOKEN_REGEX } from '../lib/hfToken.js';-import { getImageModels, isFlux2, repoForModel } from '../lib/mediaModels.js';+import { getImageModels, isFlux2, repoForModel, requiredReposForModel } from '../lib/mediaModels.js';import { usesDiffusersRunner } from '../lib/runners.js';import { inspectModelCache } from '../lib/hfCache.js';import { startHfDownloadStream } from '../lib/sseDownload.js';@@ -391,10 +391,17 @@ router.get('/models', (_req, res) => {// "not downloaded" state. Lazy generation still works regardless of badge.router.get('/models/status', asyncHandler(async (_req, res) => {const statuses = await Promise.all(getImageModels().map(async (m) => {- const repo = repoForModel(m);- if (!repo) return { id: m.id, repo: null, cached: null, sizeBytes: 0 };- const { cached, sizeBytes } = await inspectModelCache(repo);- return { id: m.id, repo, cached, sizeBytes };+ const required = requiredReposForModel(m);+ if (!required) return { id: m.id, repo: null, cached: null, sizeBytes: 0 };+ // Inspect every required repo (main + any aux text encoders). The badge+ // is `cached: true` only when ALL are cached; sizeBytes is the sum. The+ // `pendingRepos` field lets the UI explain WHICH repos still need a pull+ // so the user isn't surprised when clicking "Download" triggers >1 fetch.+ const inspections = await Promise.all(required.map((r) => inspectModelCache(r)));+ const cached = inspections.every((i) => i.cached);+ const sizeBytes = inspections.reduce((sum, i) => sum + (i.sizeBytes || 0), 0);+ const pendingRepos = required.filter((_, i) => !inspections[i].cached);+ return { id: m.id, repo: required[0], cached, sizeBytes, requiredRepos: required, pendingRepos };}));res.json(statuses);}));@@ -408,14 +415,17 @@ router.get('/models/:modelId/download', asyncHandler(async (req, res) => {if (!model) {return res.status(404).json({ error: `Unknown model id: ${req.params.modelId}` });}- const repo = repoForModel(model);- if (!repo) {+ const repos = requiredReposForModel(model);+ if (!repos) {return res.status(400).json({error: `Model "${model.id}" has no HuggingFace repo on file — cannot pre-download.`,code: 'NO_REPO_FOR_MODEL',});}- await startHfDownloadStream({ req, res, repo });+ // Sequentially fetch every required repo (main + aux text encoders for+ // HiDream). The SSE stream tags each event with `repo` so the client can+ // show per-repo progress / log lines.+ await startHfDownloadStream({ req, res, repos });}));router.get('/loras', asyncHandler(async (_req, res) => {