Coach: der Server-Fetch wartet so lange wie der Job, nicht 300 s wie undici
Nodes eingebauter fetch bricht nach fuenf Minuten mit 'fetch failed' ab — egal, welches Job-Timeout gesetzt ist. Ollama hatte den 8k-Prompt tatsaechlich fertig, die API hatte nur schon aufgelegt. Jetzt ein undici-Dispatcher, dessen Timeouts aus dem Job-Timeout abgeleitet sind; AbortController gewinnt weiterhin.
This commit is contained in:
1 parent
3fe39fde2f
commit
0d38bc07f0
5 files changed
+91
-16
No files matched your search
+4
-2
@@ -23,6 +23,7 @@ import { extractJSON } from './core/parse.js';
|
||||
import { hashPlan } from './core/plan-hash.js';
|
||||
import { buildPrompt } from './core/prompt.js';
|
||||
import { handleFor } from './handle.js';
|
||||
import { fetchFor } from './node-fetch.js';
|
||||
import { canDropPrivileges, unprivilegedIds } from './adapters/spawn.js';
|
||||
|
||||
// The prompt assembly, the plan fingerprint and the invoke→parse→validate→repair loop all
|
||||
@@ -266,7 +267,8 @@ async function execute(job) {
|
||||
|
||||
const attempt = await runPipeline({
|
||||
adapter, cfg, kind: job.kind, payload, model: cfgStore.modelFor(cfg), timeoutMs: TIMEOUT_MS,
|
||||
invokeOpts: { jobDir, env }
|
||||
// The HTTP adapters take the fetch they are given; the runtime adapters ignore it.
|
||||
invokeOpts: { jobDir, env, fetch: fetchFor(TIMEOUT_MS) }
|
||||
});
|
||||
if (!attempt.ok) {
|
||||
return finish(job, { outcome: 'failed', errorClass: attempt.errorClass, detail: attempt.detail });
|
||||
@@ -323,7 +325,7 @@ export async function testRun() {
|
||||
const check = await adapter.check(cfg, env);
|
||||
if (!check.ok) return { ok: false, error: check.error || 'the provider runtime could not be run' };
|
||||
const r = await adapter.invoke({
|
||||
cfg, jobDir, env, model: cfgStore.modelFor(cfg), timeoutMs: 90000,
|
||||
cfg, jobDir, env, model: cfgStore.modelFor(cfg), timeoutMs: 90000, fetch: fetchFor(90000),
|
||||
prompt: 'Reply with exactly this JSON object and nothing else: {"coach_contract":1,"ok":true}'
|
||||
});
|
||||
if (r.timedOut) return { ok: false, version: check.version, error: 'the provider did not answer in time' };
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* A fetch for the server that waits as long as a job may.
|
||||
*
|
||||
* Node's global fetch is undici with its defaults, and one of those defaults is a hard
|
||||
* 300-second headers timeout — the connection is torn down and the adapter sees a generic
|
||||
* "fetch failed", however long the job's own timeout was. A cloud API answers well inside
|
||||
* that; a local model on a small box legitimately does not, and COACH_JOB_TIMEOUT_MS exists
|
||||
* precisely for it. So the job runner hands the HTTP adapters this fetch instead, with the
|
||||
* transport timeouts derived from the job timeout rather than from undici's idea of patience.
|
||||
*
|
||||
* Node-only by design: the phone's transport is capacitor-fetch.js, and the core adapters
|
||||
* take whichever fetch they are given. */
|
||||
// undici's own fetch alongside its Agent, so the dispatcher option is honoured by the same
|
||||
// undici version on every Node the image or a dev box happens to run.
|
||||
import { fetch as undiciFetch, Agent } from 'undici';
|
||||
|
||||
const GRACE_MS = 15000;
|
||||
|
||||
let agent = null;
|
||||
/** The dispatcher, built once for the job timeout in force. */
|
||||
export function dispatcherFor(timeoutMs) {
|
||||
const budget = Math.max(60000, +timeoutMs || 0) + GRACE_MS;
|
||||
if (!agent || agent._coachBudget !== budget) {
|
||||
agent = new Agent({ headersTimeout: budget, bodyTimeout: budget, connectTimeout: 30000 });
|
||||
agent._coachBudget = budget;
|
||||
}
|
||||
return agent;
|
||||
}
|
||||
|
||||
/** fetch(url, init) that will wait `timeoutMs` for the provider; AbortController still wins. */
|
||||
export function fetchFor(timeoutMs) {
|
||||
const dispatcher = dispatcherFor(timeoutMs);
|
||||
return (url, init = {}) => undiciFetch(url, { ...init, dispatcher });
|
||||
}
|
||||
Reference in new issue
Block a user