@boardwalk-labs/runner 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -208,8 +208,24 @@ export declare class RunnerControlClient {
|
|
|
208
208
|
* Backs {@link InferenceProxyTransport} (inference_transport.ts) — the model swap is invisible to
|
|
209
209
|
* the engine loop, which keeps the runner provider-agnostic (the broker owns model invocation). A
|
|
210
210
|
* non-200 (a failure BEFORE the stream began) throws the broker's already-classified message.
|
|
211
|
+
*
|
|
212
|
+
* Resilience (added because a bare drop here surfaced as a run-fatal `PROVIDER_ERROR: terminated`):
|
|
213
|
+
* a transient failure is retried WHILE it is still safe to re-POST — i.e. before any CONTENT frame
|
|
214
|
+
* has been relayed. Three cases:
|
|
215
|
+
* - the POST never returned a response (connection refused/reset during an api-server rollover),
|
|
216
|
+
* - a load-balancer {@link INFERENCE_RETRYABLE_STATUSES} (no healthy / gateway timeout) before the
|
|
217
|
+
* stream began — NOT 502, which the broker uses for a real upstream model error,
|
|
218
|
+
* - the body dropped MID-stream (undici `terminated` / socket close) but only `ping` heartbeats
|
|
219
|
+
* had been relayed so far (the observed failure: a huge-context turn streamed only pings for
|
|
220
|
+
* ~120s during time-to-first-token, then the connection dropped).
|
|
221
|
+
* Once a `delta`/`reasoning`/`result`/`error` frame has been yielded, the model has already
|
|
222
|
+
* produced output (or the turn finished), so a re-POST would duplicate it: the drop surfaces as
|
|
223
|
+
* before. Re-POST is billing-safe — the broker aborts the abandoned turn on our disconnect and
|
|
224
|
+
* returns before it meters (no `result` frame ⇒ no usage). The body is a reusable string.
|
|
211
225
|
*/
|
|
212
226
|
streamInference(req: InferenceProxyRequest): AsyncGenerator<InferenceFrame, void, undefined>;
|
|
227
|
+
/** Log + wait one backoff step before re-POSTing a transient inference failure (see streamInference). */
|
|
228
|
+
private backoffInferenceRetry;
|
|
213
229
|
private url;
|
|
214
230
|
private headers;
|
|
215
231
|
}
|
|
@@ -20,6 +20,14 @@ const log = createLogger("RunnerControlClient");
|
|
|
20
20
|
* handler error could duplicate a side effect for no healing value.
|
|
21
21
|
*/
|
|
22
22
|
const RETRYABLE_STATUSES = new Set([502, 503, 504]);
|
|
23
|
+
/**
|
|
24
|
+
* Transient statuses worth retrying on the STREAMING inference POST — a narrower set than
|
|
25
|
+
* {@link RETRYABLE_STATUSES}. 502 is EXCLUDED: on `/inference` the broker uses 502 for a real
|
|
26
|
+
* upstream model error (a clean, customer-facing message), so retrying it just re-hits a guaranteed
|
|
27
|
+
* failure. 503/504 are only ever the load balancer during a rollover (no healthy / draining target,
|
|
28
|
+
* gateway timeout) — safe to re-POST since the stream hasn't begun. See {@link streamInference}.
|
|
29
|
+
*/
|
|
30
|
+
const INFERENCE_RETRYABLE_STATUSES = new Set([503, 504]);
|
|
23
31
|
/** Default backoff (ms) between attempts — ~17.5s of spread, sized to ride out the target-group
|
|
24
32
|
* rotation window of an api-server rolling deploy (the observed killer: guests died hard
|
|
25
33
|
* mid-suspend/finalize during TWO deploys, 2026-07-13, and only crash-reclaim saved the runs). */
|
|
@@ -473,20 +481,85 @@ export class RunnerControlClient {
|
|
|
473
481
|
* Backs {@link InferenceProxyTransport} (inference_transport.ts) — the model swap is invisible to
|
|
474
482
|
* the engine loop, which keeps the runner provider-agnostic (the broker owns model invocation). A
|
|
475
483
|
* non-200 (a failure BEFORE the stream began) throws the broker's already-classified message.
|
|
484
|
+
*
|
|
485
|
+
* Resilience (added because a bare drop here surfaced as a run-fatal `PROVIDER_ERROR: terminated`):
|
|
486
|
+
* a transient failure is retried WHILE it is still safe to re-POST — i.e. before any CONTENT frame
|
|
487
|
+
* has been relayed. Three cases:
|
|
488
|
+
* - the POST never returned a response (connection refused/reset during an api-server rollover),
|
|
489
|
+
* - a load-balancer {@link INFERENCE_RETRYABLE_STATUSES} (no healthy / gateway timeout) before the
|
|
490
|
+
* stream began — NOT 502, which the broker uses for a real upstream model error,
|
|
491
|
+
* - the body dropped MID-stream (undici `terminated` / socket close) but only `ping` heartbeats
|
|
492
|
+
* had been relayed so far (the observed failure: a huge-context turn streamed only pings for
|
|
493
|
+
* ~120s during time-to-first-token, then the connection dropped).
|
|
494
|
+
* Once a `delta`/`reasoning`/`result`/`error` frame has been yielded, the model has already
|
|
495
|
+
* produced output (or the turn finished), so a re-POST would duplicate it: the drop surfaces as
|
|
496
|
+
* before. Re-POST is billing-safe — the broker aborts the abandoned turn on our disconnect and
|
|
497
|
+
* returns before it meters (no `result` frame ⇒ no usage). The body is a reusable string.
|
|
476
498
|
*/
|
|
477
499
|
async *streamInference(req) {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
500
|
+
const body = serializeInferenceRequest(req);
|
|
501
|
+
for (let attempt = 0;; attempt += 1) {
|
|
502
|
+
const last = attempt >= this.retryDelaysMs.length;
|
|
503
|
+
let res;
|
|
504
|
+
try {
|
|
505
|
+
res = await this.fetchImpl(this.url("inference"), {
|
|
506
|
+
method: "POST",
|
|
507
|
+
headers: { ...this.headers(true), accept: INFERENCE_NDJSON_CONTENT_TYPE },
|
|
508
|
+
body,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
catch (err) {
|
|
512
|
+
// No response at all — nothing streamed, so a re-POST is always safe.
|
|
513
|
+
if (last)
|
|
514
|
+
throw err;
|
|
515
|
+
await this.backoffInferenceRetry(attempt, "connect", err);
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (res.status !== 200 || res.body === null) {
|
|
519
|
+
// A load-balancer transient (target draining / gateway timeout) before the stream began —
|
|
520
|
+
// safe to re-POST. Any other non-200 is the broker's real, already-classified answer
|
|
521
|
+
// (incl. a 502 upstream model error): surface it as the run's customer-facing error.
|
|
522
|
+
if (!last && res.body !== null && INFERENCE_RETRYABLE_STATUSES.has(res.status)) {
|
|
523
|
+
await res.body.cancel().catch(() => { });
|
|
524
|
+
await this.backoffInferenceRetry(attempt, "status", res.status);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
throw await inferenceHttpError(res);
|
|
528
|
+
}
|
|
529
|
+
// Relay the stream. A mid-stream transport drop throws out of readNdjsonLines; retry it only
|
|
530
|
+
// while nothing but heartbeats has gone out (see the doc-comment). `ping` frames carry no
|
|
531
|
+
// model output, so a drop during the pre-first-token wait stays safely retryable.
|
|
532
|
+
let sawContent = false;
|
|
533
|
+
try {
|
|
534
|
+
for await (const line of readNdjsonLines(res.body)) {
|
|
535
|
+
const frame = parseInferenceFrame(line);
|
|
536
|
+
if (frame.kind !== "ping")
|
|
537
|
+
sawContent = true;
|
|
538
|
+
yield frame;
|
|
539
|
+
}
|
|
540
|
+
return; // the stream ended cleanly
|
|
541
|
+
}
|
|
542
|
+
catch (err) {
|
|
543
|
+
if (last || sawContent)
|
|
544
|
+
throw err;
|
|
545
|
+
await res.body.cancel().catch(() => { });
|
|
546
|
+
await this.backoffInferenceRetry(attempt, "stream", err);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
488
549
|
}
|
|
489
550
|
}
|
|
551
|
+
/** Log + wait one backoff step before re-POSTing a transient inference failure (see streamInference). */
|
|
552
|
+
async backoffInferenceRetry(attempt, reason, detail) {
|
|
553
|
+
log.warn("broker_inference_retry", {
|
|
554
|
+
reason,
|
|
555
|
+
...(reason === "status"
|
|
556
|
+
? { status: detail }
|
|
557
|
+
: { error: detail instanceof Error ? detail.name : "unknown" }),
|
|
558
|
+
attempt: attempt + 1,
|
|
559
|
+
delayMs: this.retryDelaysMs[attempt],
|
|
560
|
+
});
|
|
561
|
+
await sleep(this.retryDelaysMs[attempt] ?? 0);
|
|
562
|
+
}
|
|
490
563
|
url(suffix) {
|
|
491
564
|
return `${this.base}/runner/v1/runs/${encodeURIComponent(this.cfg.runId)}/${suffix}`;
|
|
492
565
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boardwalk-labs/runner",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Boardwalk self-hosted runner: execute cloud-scheduled runs on your own machines. Currently: the canonical runner contract types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|