fix(consult): a warm that cannot be scheduled no longer fails the save (BUG-1305)
Independent Staging Quality Gate / validate (push) Successful in 13m12s
Independent Staging Quality Gate / publish (push) Successful in 4m16s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
This commit is contained in:
Jesse_Chen
2026-10-09 15:17:00 +08:00
co-authored by Claude Opus 5.5
parent cd625e8a35
commit b4eedb7725
5 changed files with 48 additions and 8 deletions
+14 -7
View File
@@ -54,12 +54,19 @@ export function scheduleConsultPacketWarm(
const body = consultWarmBodyFromColumns(columns);
if (!body) return false;
const apiBase = deps.apiBase ?? "http://127.0.0.1:5200";
deps.after(() => {
return deps.fetch(`${apiBase}/api/consultation_workflow`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
}).then(() => undefined).catch(() => undefined);
});
// Warm is best effort. `after` throws outside a request scope; the save has
// already been written by then, so a scheduling failure must not turn it
// into a 500 (BUG-1305).
try {
deps.after(() => {
return deps.fetch(`${apiBase}/api/consultation_workflow`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
}).then(() => undefined).catch(() => undefined);
});
} catch {
return false;
}
return true;
}
@@ -33,3 +33,19 @@ test("a saved chart becomes a warm request and the caller does not wait", () =>
assert.equal(started, true);
assert.equal(finished, false);
});
test("a warm that cannot be scheduled does not break the save (BUG-1305)", () => {
// Default deps use Next `after`, which throws outside a request scope.
assert.equal(scheduleConsultPacketWarm(columns), false);
let fetched = false;
const scheduled = scheduleConsultPacketWarm(columns, {
after: () => { throw new Error("outside a request scope"); },
fetch: () => {
fetched = true;
return Promise.resolve(new Response(null));
},
apiBase: "http://127.0.0.1:9",
});
assert.equal(scheduled, false);
assert.equal(fetched, false);
});