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: share Runway catalog load and honor cancel before paid submit

[._.]/ Adam Eivy00f39a73e5f0
diff --git a/server/services/imageGen/runway.js b/server/services/imageGen/runway.js
index 8cba7e7545..8a60692a82 100644
--- a/server/services/imageGen/runway.js
+++ b/server/services/imageGen/runway.js
@@ -194,7 +194,7 @@ async function runRunway(job, jobId, {
const referenceImages = [];
for (const ref of references) referenceImages.push({ uri: await encodeInputImage(ref.path), ...(family.referenceTags ? { tag: ref.tag } : {}) });
if (entry.aborted) return finalizeCanceled(job, jobId);
- entry.taskId = await submitRunwayTask({ apiKey, endpoint: 'text_to_image', body: { ...request.body, ...(referenceImages.length ? { referenceImages } : {}) } });
+ entry.taskId = await submitRunwayTask({ apiKey, endpoint: 'text_to_image', body: { ...request.body, ...(referenceImages.length ? { referenceImages } : {}) }, signal: entry.controller.signal });
// THROTTLED waits on this accepted task. A failed/moderated task is terminal, never resubmitted.
const polled = await awaitRunwayTask({
entry, apiKey, deadline, timeoutMs: RUNWAY_IMAGE_TIMEOUT_MS, verbatimFailure: true,
diff --git a/server/services/runwayApi.js b/server/services/runwayApi.js
index 8508dbb91e..190e1819dd 100644
--- a/server/services/runwayApi.js
+++ b/server/services/runwayApi.js
@@ -109,8 +109,9 @@ export async function cancelRunwayTask(entry) {
}
/** Submit one paid generation to a generation endpoint. Resolves to the task id. */
-export async function submitRunwayTask({ apiKey, endpoint, body }) {
+export async function submitRunwayTask({ apiKey, endpoint, body, signal }) {
await assertRunwayCatalogModel(endpoint, body.model);
+ signal?.throwIfAborted(); // a cancel during the catalog load must not start a paid render
const res = await fetchWithTimeout(`${RUNWAY_API_BASE}/v1/${endpoint}`, {
method: 'POST', headers: headers(apiKey, true), body: JSON.stringify(body),
}, RUNWAY_SUBMIT_TIMEOUT_MS).catch((err) => {
diff --git a/server/services/runwayApi.test.js b/server/services/runwayApi.test.js
new file mode 100644
index 0000000000..e4c8c70421
--- /dev/null
+++ b/server/services/runwayApi.test.js
@@ -0,0 +1,14 @@
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock('../lib/fetchWithTimeout.js', () => ({ fetchWithTimeout: vi.fn() }));
+const { fetchWithTimeout } = await import('../lib/fetchWithTimeout.js');
+const { submitRunwayTask } = await import('./runwayApi.js');
+
+describe('submitRunwayTask', () => {
+ it('does not start a paid POST for a job canceled before submission', async () => {
+ const controller = new AbortController();
+ controller.abort();
+ await expect(submitRunwayTask({ apiKey: 'k', endpoint: 'text_to_image', body: { model: 'gpt_image_2' }, signal: controller.signal })).rejects.toThrow();
+ expect(fetchWithTimeout).not.toHaveBeenCalled();
+ });
+});
diff --git a/server/services/runwayModelCatalog.js b/server/services/runwayModelCatalog.js
index 86a786a176..8bcd5cd08f 100644
--- a/server/services/runwayModelCatalog.js
+++ b/server/services/runwayModelCatalog.js
@@ -71,7 +71,7 @@ export function _createRunwayModelCatalog({
cachePath = join(PATHS.installRoot, '.cache', 'runway-model-catalog.json'), now = Date.now,
} = {}) {
let cached = null;
- let loaded = false;
+ let loading = null;
let pending = null;
let pendingForced = false;
let retryAt = 0;
@@ -82,9 +82,9 @@ export function _createRunwayModelCatalog({
stale: !cached || now() - cached.fetchedAt >= TTL || !!error,
bundled: !cached, error,
});
- async function read() {
- if (loaded) return;
- loaded = true;
+ // One shared promise: an overlapping caller waits for the disk load instead of seeing the bundled list.
+ const read = () => (loading ||= load());
+ async function load() {
const disk = await readFile(cachePath, 'utf8').then(JSON.parse).catch(() => null);
if (disk?.version === VERSION && Number.isFinite(disk.fetchedAt) && disk.fetchedAt <= now()
&& Object.keys(fallback).every((key) => Array.isArray(disk.catalog?.available?.[key])
diff --git a/server/services/runwayModelCatalog.test.js b/server/services/runwayModelCatalog.test.js
index e5daf0d5d6..8131a2d488 100644
--- a/server/services/runwayModelCatalog.test.js
+++ b/server/services/runwayModelCatalog.test.js
@@ -98,4 +98,11 @@ describe('Runway public catalog cache', () => {
expect(restarted.current()).toMatchObject({ bundled: false });
expect(fetchSchema).toHaveBeenCalledTimes(1);
});
+
+ it("makes overlapping readiness callers wait for the same disk load", async () => {
+ const { cache, options } = await setup();
+ await cache.get();
+ const restarted = _createRunwayModelCatalog(options);
+ await Promise.all([restarted.ready(), restarted.ready().then(() => expect(restarted.current().bundled).toBe(false))]);
+ });
});
diff --git a/server/services/videoGen/runway.js b/server/services/videoGen/runway.js
index d5ea3d81e4..7b10a5d9f2 100644
--- a/server/services/videoGen/runway.js
+++ b/server/services/videoGen/runway.js
@@ -279,7 +279,7 @@ async function runRunwayVideo(job, jobId, {
const build = special ? buildRunwaySpecialVideoRequest : buildRunwayVideoRequest;
const { body, endpoint } = build({ ...requestSpec, videoUri, characterVideoUri, imageUri: frame?.dataUri ?? null, endImageUri: endFrame?.dataUri ?? null });
if (entry.aborted) return finishFailure('Canceled');
- entry.taskId = await submitRunwayTask({ apiKey, endpoint, body });
+ entry.taskId = await submitRunwayTask({ apiKey, endpoint, body, signal: entry.controller.signal });
const polled = await awaitRunwayTask({
entry, apiKey, deadline, timeoutMs: RUNWAY_RENDER_TIMEOUT_MS,