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

fix: add timeouts to Gemini model + Civitai metadata/search fetches (#1827)

[._.]/ Adam Eivy63d893a91d38
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index dece5b56f7..ce6c3cbd70 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -17,5 +17,6 @@
## Fixed
+- **External API model/metadata fetches now time out instead of stalling callers indefinitely** — `_fetchGeminiModels` (Gemini model refresh in `aiToolkit/providers.js`) made a `fetch` with no `AbortSignal`, unlike every other provider model-fetch in that file, so a hung Google endpoint could block a model-refresh request forever; it now uses the same `AbortSignal.timeout(8000)`. `fetchCivitaiModel` and `searchCivitaiLoras` (`server/lib/civitai.js`) likewise passed no signal, so a Civitai hang stalled LoRA metadata/search callers; both now default to `AbortSignal.timeout(10000)` and accept a caller-provided `signal` override. (#1827)
- **Unguarded async `child_process` handlers can no longer crash the Node process** — several `close`/`error` event handlers were `async` and `await`ed disk writes / completion bookkeeping with no `try/catch`, so a single failed write (e.g. a full disk) or a throwing completion hook surfaced as an unhandled rejection and took down the whole server. Wrapped the at-risk handler bodies in `server/services/runner.js` (both `close` and `error`), `videoTimeline/local.js`, `agentCliSpawning.js` (both `close` and `error`), and both the CLI `close` handler and the detached `processStream().catch` in `aiToolkit/runner.js`. The recovery paths now still settle callers waiting on `onComplete` with failure metadata (so a finalization failure surfaces as a failed run instead of hanging forever), with the completion hook isolated from `onComplete` so a throwing `onRunFailed` can't block the caller from settling. Also replaced the two silent recovery-critical `.catch(() => {})` swallows in `cos-runner/index.js` with logged failures so a lost completion-metadata write is visible instead of silently dropping a finished task. (#1825)
- Catalog "Appears in" panel no longer renders dangling chips that deep-link to soft-deleted universe/series/creative-director targets — the detail page filters refs to live targets only (the orphan stays recoverable via the "Orphaned" album). Also fixed a stale resolver bug where soft-deleted Creative Director projects (#1564) wrongly resolved as live, and extended orphan-bucket detection so a deleted CD project's ex-cast surfaces as orphaned rather than unlinked. (#1812)
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index 4303795e46..ce411d458c 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -674,7 +674,8 @@ export function createProviderService(config = {}) {
}
const response = await fetch(
- `https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`
+ `https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`,
+ { signal: AbortSignal.timeout(8000) }
).catch(() => null);
if (!response?.ok) {
diff --git a/server/lib/civitai.js b/server/lib/civitai.js
index 039c97769f..420f44e54e 100644
--- a/server/lib/civitai.js
+++ b/server/lib/civitai.js
@@ -200,12 +200,12 @@ export const buildAuthHeaders = (apiKey) => {
// Fetch model metadata. `fetchImpl` is injectable for tests — defaults to
// global fetch which is available in Node 18+. Returns the parsed JSON
// body; throws ServerError on HTTP failures with a helpful message.
-export const fetchCivitaiModel = async (modelId, { apiKey, fetchImpl = fetch } = {}) => {
+export const fetchCivitaiModel = async (modelId, { apiKey, fetchImpl = fetch, signal = AbortSignal.timeout(10000) } = {}) => {
if (!/^\d+$/.test(String(modelId))) {
throw new ServerError(`Invalid Civitai model id: ${modelId}`, { status: 400, code: 'CIVITAI_BAD_URL' });
}
const url = `${CIVITAI_API}/models/${modelId}`;
- const res = await fetchImpl(url, { headers: { Accept: 'application/json', ...buildAuthHeaders(apiKey) } });
+ const res = await fetchImpl(url, { headers: { Accept: 'application/json', ...buildAuthHeaders(apiKey) }, signal });
if (!res.ok) {
if (res.status === 404) {
throw new ServerError(`Civitai model ${modelId} not found`, { status: 404, code: 'CIVITAI_NOT_FOUND' });
@@ -337,7 +337,7 @@ const RUNNER_TO_BASE_MODELS = {
// suggestion service shape them); `nextCursor` is Civitai's cursor token for
// the next page (null when exhausted). Pass `query` to filter by keyword and
// `cursor` to page forward. fetchImpl is injectable for tests.
-export const searchCivitaiLoras = async ({ runnerFamily, limit = 12, sort = 'Most Downloaded', nsfw = false, query, cursor, apiKey, fetchImpl = fetch } = {}) => {
+export const searchCivitaiLoras = async ({ runnerFamily, limit = 12, sort = 'Most Downloaded', nsfw = false, query, cursor, apiKey, fetchImpl = fetch, signal = AbortSignal.timeout(10000) } = {}) => {
const baseModels = RUNNER_TO_BASE_MODELS[runnerFamily];
if (!baseModels) {
throw new ServerError(`Unknown runner family for Civitai search: ${runnerFamily}`, { status: 400, code: 'CIVITAI_BAD_RUNNER' });
@@ -358,7 +358,7 @@ export const searchCivitaiLoras = async ({ runnerFamily, limit = 12, sort = 'Mos
// back here to fetch the next page. Cursor is opaque (string or number).
if (cursor != null && cursor !== '') params.set('cursor', String(cursor));
const url = `${CIVITAI_API}/models?${params.toString()}`;
- const res = await fetchImpl(url, { headers: { Accept: 'application/json', ...buildAuthHeaders(apiKey) } });
+ const res = await fetchImpl(url, { headers: { Accept: 'application/json', ...buildAuthHeaders(apiKey) }, signal });
if (!res.ok) {
if (res.status === 401 || res.status === 403) {
throw new ServerError(
diff --git a/server/lib/civitai.test.js b/server/lib/civitai.test.js
index b3a19439bb..8cc52f79ba 100644
--- a/server/lib/civitai.test.js
+++ b/server/lib/civitai.test.js
@@ -13,6 +13,7 @@ import {
pickPrimaryFile,
pickPreviewImage,
pickVersion,
+ searchCivitaiLoras,
slugifyForFilename,
} from './civitai.js';
@@ -305,6 +306,35 @@ describe('fetchCivitaiModel', () => {
await expect(fetchCivitaiModel('abc', { fetchImpl })).rejects.toThrow(/Invalid Civitai model id/);
expect(called).toBe(false);
});
+ it('passes a default abort signal so a hung Civitai response times out', async () => {
+ let opts = null;
+ const fetchImpl = async (_url, o) => { opts = o; return mockJsonResponse({ id: 1 }); };
+ await fetchCivitaiModel('123', { fetchImpl });
+ expect(opts.signal).toBeInstanceOf(AbortSignal);
+ });
+ it('honors a caller-provided abort signal', async () => {
+ let opts = null;
+ const fetchImpl = async (_url, o) => { opts = o; return mockJsonResponse({ id: 1 }); };
+ const signal = AbortSignal.timeout(5000);
+ await fetchCivitaiModel('123', { fetchImpl, signal });
+ expect(opts.signal).toBe(signal);
+ });
+});
+
+describe('searchCivitaiLoras', () => {
+ it('passes a default abort signal so a hung search times out', async () => {
+ let opts = null;
+ const fetchImpl = async (_url, o) => { opts = o; return mockJsonResponse({ items: [], metadata: {} }); };
+ await searchCivitaiLoras({ runnerFamily: 'mflux', fetchImpl });
+ expect(opts.signal).toBeInstanceOf(AbortSignal);
+ });
+ it('honors a caller-provided abort signal', async () => {
+ let opts = null;
+ const fetchImpl = async (_url, o) => { opts = o; return mockJsonResponse({ items: [], metadata: {} }); };
+ const signal = AbortSignal.timeout(5000);
+ await searchCivitaiLoras({ runnerFamily: 'mflux', fetchImpl, signal });
+ expect(opts.signal).toBe(signal);
+ });
});
describe('buildSidecar', () => {