fix(consult): a warm that cannot be scheduled no longer fails the save (BUG-1305)
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:
co-authored by
Claude Opus 5.5
parent
cd625e8a35
commit
b4eedb7725
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user