@agent-native/core 0.76.4 → 0.76.5
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.
- package/corpus/core/CHANGELOG.md +19 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/production-agent.ts +147 -56
- package/corpus/core/src/agent/run-store.ts +36 -0
- package/corpus/core/src/deploy/build.ts +31 -14
- package/dist/agent/production-agent.d.ts +47 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +112 -56
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-store.d.ts +21 -0
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +32 -0
- package/dist/agent/run-store.js.map +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +31 -14
- package/dist/deploy/build.js.map +1 -1
- package/package.json +1 -1
package/corpus/core/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @agent-native/core
|
|
2
2
|
|
|
3
|
+
## 0.76.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ba634f4: Durable background agent runs: add a foreground **circuit-breaker** so a dead
|
|
8
|
+
background worker can no longer break chat. A Netlify async background function
|
|
9
|
+
returns `202` the instant it enqueues the invocation, but the worker may never
|
|
10
|
+
execute — e.g. the generated function wrapper fails to import `./main.mjs` or
|
|
11
|
+
hand off to the Nitro `_process-run` route, so it never reaches
|
|
12
|
+
`claimBackgroundRun` and the run is reaped as "worker never claimed the run".
|
|
13
|
+
After a successful dispatch the foreground now polls briefly for the worker to
|
|
14
|
+
actually claim the run; if it doesn't within the grace window, the turn is
|
|
15
|
+
recovered **inline** (the same safe atomic-claim path used for a fast dispatch
|
|
16
|
+
failure), so a dead worker degrades to a working synchronous turn instead of a
|
|
17
|
+
reaped failure. Also harden the generated background-function wrapper to pass
|
|
18
|
+
Netlify's `context` through to the Nitro handler and wrap the handoff in
|
|
19
|
+
try/catch so a pre-route failure is logged loudly instead of silently swallowed
|
|
20
|
+
behind the async 202.
|
|
21
|
+
|
|
3
22
|
## 0.76.4
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/corpus/core/package.json
CHANGED
|
@@ -109,6 +109,7 @@ import {
|
|
|
109
109
|
updateRunHeartbeat,
|
|
110
110
|
updateRunStatusIfRunning,
|
|
111
111
|
claimBackgroundRun,
|
|
112
|
+
readBackgroundRunClaim,
|
|
112
113
|
recordRunDiagnostic,
|
|
113
114
|
RUN_DIAG_STAGE,
|
|
114
115
|
} from "./run-store.js";
|
|
@@ -149,6 +150,96 @@ registerBuiltinEngines();
|
|
|
149
150
|
|
|
150
151
|
export { PROVIDER_TO_ENV };
|
|
151
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Grace window + poll interval for the foreground circuit-breaker that confirms
|
|
155
|
+
* a background worker actually CLAIMED a 202-dispatched run before recovering
|
|
156
|
+
* inline. The grace is long enough for a cold-start worker to win the claim
|
|
157
|
+
* (~1-2s typical) and short enough to recover quickly within the foreground's
|
|
158
|
+
* ~40s soft-timeout.
|
|
159
|
+
*/
|
|
160
|
+
export const BACKGROUND_CLAIM_GRACE_MS = 8_000;
|
|
161
|
+
export const BACKGROUND_CLAIM_POLL_MS = 400;
|
|
162
|
+
|
|
163
|
+
export type BackgroundDispatchOutcome =
|
|
164
|
+
| { action: "stream" }
|
|
165
|
+
| { action: "subscribe" }
|
|
166
|
+
| {
|
|
167
|
+
action: "inline";
|
|
168
|
+
reason: "dispatch-failed" | "worker-never-claimed" | "no-row";
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Decide what the foreground should do after attempting a durable background
|
|
173
|
+
* dispatch. A Netlify async background function returns 202 the instant it
|
|
174
|
+
* ENQUEUES the invocation — that is NOT proof the worker executed. If the
|
|
175
|
+
* generated wrapper fails to import/hand off to the route, the worker never
|
|
176
|
+
* reaches `claimBackgroundRun` and the run is reaped as "worker never claimed".
|
|
177
|
+
*
|
|
178
|
+
* So after a successful dispatch we poll briefly for the worker to CLAIM the run:
|
|
179
|
+
* - claimed within grace → "stream" (subscribe to the worker)
|
|
180
|
+
* - dispatch failed OR no claim → recover inline by atomically claiming the
|
|
181
|
+
* run ourselves: if we win → "inline"; if a (delayed) worker already won
|
|
182
|
+
* it → "subscribe" (never double-run).
|
|
183
|
+
*
|
|
184
|
+
* Pure except for the injected `readClaim`/`claim`/`now`/`sleep` deps, so each
|
|
185
|
+
* branch is unit-testable.
|
|
186
|
+
*/
|
|
187
|
+
export async function resolveBackgroundDispatchOutcome(opts: {
|
|
188
|
+
dispatched: boolean;
|
|
189
|
+
backgroundRowInserted: boolean;
|
|
190
|
+
runId: string;
|
|
191
|
+
graceMs: number;
|
|
192
|
+
pollIntervalMs: number;
|
|
193
|
+
readClaim: (
|
|
194
|
+
runId: string,
|
|
195
|
+
) => Promise<{ dispatchMode: string | null; status: string | null } | null>;
|
|
196
|
+
claim: (runId: string) => Promise<boolean>;
|
|
197
|
+
now?: () => number;
|
|
198
|
+
sleep?: (ms: number) => Promise<void>;
|
|
199
|
+
}): Promise<BackgroundDispatchOutcome> {
|
|
200
|
+
const now = opts.now ?? (() => Date.now());
|
|
201
|
+
const sleep =
|
|
202
|
+
opts.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
203
|
+
|
|
204
|
+
if (opts.dispatched) {
|
|
205
|
+
const deadline = now() + opts.graceMs;
|
|
206
|
+
for (;;) {
|
|
207
|
+
const claim = await opts.readClaim(opts.runId).catch(() => null);
|
|
208
|
+
if (
|
|
209
|
+
claim &&
|
|
210
|
+
((claim.dispatchMode && claim.dispatchMode !== "background") ||
|
|
211
|
+
(claim.status && claim.status !== "running"))
|
|
212
|
+
) {
|
|
213
|
+
return { action: "stream" };
|
|
214
|
+
}
|
|
215
|
+
if (now() >= deadline) break;
|
|
216
|
+
await sleep(opts.pollIntervalMs);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Dispatch fast-failed OR no worker claimed within grace → recover inline.
|
|
221
|
+
if (!opts.backgroundRowInserted) {
|
|
222
|
+
// No row to reconcile (insert failed / non-duplicate) — run a fresh inline
|
|
223
|
+
// turn; `startRun` inserts the row.
|
|
224
|
+
return { action: "inline", reason: "no-row" };
|
|
225
|
+
}
|
|
226
|
+
let claimedInline = false;
|
|
227
|
+
try {
|
|
228
|
+
claimedInline = await opts.claim(opts.runId);
|
|
229
|
+
} catch {
|
|
230
|
+
claimedInline = false;
|
|
231
|
+
}
|
|
232
|
+
if (claimedInline) {
|
|
233
|
+
return {
|
|
234
|
+
action: "inline",
|
|
235
|
+
reason: opts.dispatched ? "worker-never-claimed" : "dispatch-failed",
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// The atomic claim was lost: a (delayed) background worker already owns the
|
|
239
|
+
// run — subscribe to it, never run a second copy.
|
|
240
|
+
return { action: "subscribe" };
|
|
241
|
+
}
|
|
242
|
+
|
|
152
243
|
const SAFE_BROWSER_TAB_ID_RE = /^[A-Za-z0-9_-]{1,96}$/;
|
|
153
244
|
|
|
154
245
|
function normalizeBrowserTabId(value: unknown): string | undefined {
|
|
@@ -4425,7 +4516,33 @@ export function createProductionAgentHandler(
|
|
|
4425
4516
|
);
|
|
4426
4517
|
}
|
|
4427
4518
|
|
|
4428
|
-
|
|
4519
|
+
// ─── Circuit-breaker: a 202 only ENQUEUES the background invocation ─────
|
|
4520
|
+
// It is NOT proof the worker executed. If the generated background-function
|
|
4521
|
+
// wrapper fails to import `./main.mjs` or hand off to the Nitro
|
|
4522
|
+
// `_process-run` route, the worker never reaches `claimBackgroundRun`: the
|
|
4523
|
+
// row sits at `dispatch_mode='background'` until the reaper errors it
|
|
4524
|
+
// ("worker never claimed the run"). `resolveBackgroundDispatchOutcome`
|
|
4525
|
+
// polls briefly for the claim and decides:
|
|
4526
|
+
// - "stream": a worker claimed the run → subscribe to it.
|
|
4527
|
+
// - "subscribe": a (delayed) worker already owns it → subscribe, NEVER
|
|
4528
|
+
// run a second copy.
|
|
4529
|
+
// - "inline": dispatch failed OR no worker claimed within grace → we
|
|
4530
|
+
// atomically own the run; recover by running it inline so a
|
|
4531
|
+
// dead worker degrades to a working synchronous turn.
|
|
4532
|
+
const backgroundOutcome = await resolveBackgroundDispatchOutcome({
|
|
4533
|
+
dispatched,
|
|
4534
|
+
backgroundRowInserted,
|
|
4535
|
+
runId,
|
|
4536
|
+
graceMs: BACKGROUND_CLAIM_GRACE_MS,
|
|
4537
|
+
pollIntervalMs: BACKGROUND_CLAIM_POLL_MS,
|
|
4538
|
+
readClaim: readBackgroundRunClaim,
|
|
4539
|
+
claim: claimBackgroundRun,
|
|
4540
|
+
});
|
|
4541
|
+
|
|
4542
|
+
if (
|
|
4543
|
+
backgroundOutcome.action === "stream" ||
|
|
4544
|
+
backgroundOutcome.action === "subscribe"
|
|
4545
|
+
) {
|
|
4429
4546
|
const stream = subscribeToRun(runId, 0);
|
|
4430
4547
|
if (stream) {
|
|
4431
4548
|
setResponseHeader(event, "Content-Type", "text/event-stream");
|
|
@@ -4434,65 +4551,39 @@ export function createProductionAgentHandler(
|
|
|
4434
4551
|
setResponseHeader(event, "X-Run-Id", runId);
|
|
4435
4552
|
return stream;
|
|
4436
4553
|
}
|
|
4437
|
-
//
|
|
4438
|
-
// rather than
|
|
4439
|
-
|
|
4554
|
+
// A background worker owns this run but we cannot subscribe — surface an
|
|
4555
|
+
// error rather than risk a double-run by falling through to inline.
|
|
4556
|
+
await updateRunStatusIfRunning(runId, "errored").catch(() => {});
|
|
4440
4557
|
setResponseStatus(event, 500);
|
|
4441
|
-
return {
|
|
4558
|
+
return {
|
|
4559
|
+
error:
|
|
4560
|
+
backgroundOutcome.action === "stream"
|
|
4561
|
+
? "Failed to subscribe to background run"
|
|
4562
|
+
: "Failed to dispatch background run",
|
|
4563
|
+
};
|
|
4442
4564
|
}
|
|
4443
4565
|
|
|
4444
|
-
//
|
|
4445
|
-
//
|
|
4446
|
-
//
|
|
4447
|
-
//
|
|
4448
|
-
//
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
let claimedInline = false;
|
|
4464
|
-
try {
|
|
4465
|
-
claimedInline = await claimBackgroundRun(runId);
|
|
4466
|
-
} catch (err) {
|
|
4467
|
-
console.error(
|
|
4468
|
-
"[agent-chat] inline-fallback claim failed:",
|
|
4469
|
-
err instanceof Error ? err.message : err,
|
|
4470
|
-
);
|
|
4471
|
-
}
|
|
4472
|
-
if (!claimedInline) {
|
|
4473
|
-
// A background worker already owns this run (a delayed delivery landed
|
|
4474
|
-
// after our fast throw). Stream its events instead of running a second
|
|
4475
|
-
// copy. If we somehow can't subscribe, surface an error rather than
|
|
4476
|
-
// risk a double-run.
|
|
4477
|
-
const stream = subscribeToRun(runId, 0);
|
|
4478
|
-
if (stream) {
|
|
4479
|
-
setResponseHeader(event, "Content-Type", "text/event-stream");
|
|
4480
|
-
setResponseHeader(event, "Cache-Control", "no-cache");
|
|
4481
|
-
setResponseHeader(event, "Connection", "keep-alive");
|
|
4482
|
-
setResponseHeader(event, "X-Run-Id", runId);
|
|
4483
|
-
return stream;
|
|
4484
|
-
}
|
|
4485
|
-
await updateRunStatusIfRunning(runId, "errored").catch(() => {});
|
|
4486
|
-
setResponseStatus(event, 500);
|
|
4487
|
-
return { error: "Failed to dispatch background run" };
|
|
4488
|
-
}
|
|
4489
|
-
// We own the run. `startRun` (below) calls `insertRun` again, but its
|
|
4490
|
-
// duplicate-PK collision is swallowed (`insertRun(...).catch(() => {})`),
|
|
4491
|
-
// so the existing `background-processing` row is reused — no double row.
|
|
4566
|
+
// backgroundOutcome.action === "inline": we atomically own the run (or
|
|
4567
|
+
// there was no row to reconcile), so falling through to the inline
|
|
4568
|
+
// `startRun` path below cannot double-execute. `startRun` calls `insertRun`
|
|
4569
|
+
// again, but its duplicate-PK collision is swallowed, so an existing
|
|
4570
|
+
// `background-processing` row is reused — no double row.
|
|
4571
|
+
if (backgroundOutcome.reason === "worker-never-claimed") {
|
|
4572
|
+
// The async 202 landed but no worker claimed within grace — the generated
|
|
4573
|
+
// wrapper never reached the route. Record it so the failure is visible on
|
|
4574
|
+
// the run even though the user still gets a working (inline) turn.
|
|
4575
|
+
console.error(
|
|
4576
|
+
"[agent-chat] background worker did not claim the 202-dispatched run " +
|
|
4577
|
+
"within grace; recovering inline:",
|
|
4578
|
+
runId,
|
|
4579
|
+
);
|
|
4580
|
+
await recordRunDiagnostic(
|
|
4581
|
+
runId,
|
|
4582
|
+
RUN_DIAG_STAGE.foregroundInlineRecovery,
|
|
4583
|
+
"202 dispatched but no worker claimed within the foreground grace window",
|
|
4584
|
+
).catch(() => {});
|
|
4492
4585
|
}
|
|
4493
|
-
// Fall through to the inline `startRun` path below
|
|
4494
|
-
// flag-off branch uses). If the row was never inserted, `startRun` inserts
|
|
4495
|
-
// it fresh; if it was, the claim above made us the sole owner.
|
|
4586
|
+
// Fall through to the inline `startRun` path below.
|
|
4496
4587
|
}
|
|
4497
4588
|
|
|
4498
4589
|
const trackedProgressOwner =
|
|
@@ -378,6 +378,35 @@ export async function claimBackgroundRun(runId: string): Promise<boolean> {
|
|
|
378
378
|
return (rowsAffected ?? 0) > 0;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Read the claim/lifecycle state of a single run by id — for the foreground
|
|
383
|
+
* circuit-breaker that confirms a background worker actually CLAIMED a run that
|
|
384
|
+
* was dispatched with a Netlify async 202. A 202 only means the invocation was
|
|
385
|
+
* ENQUEUED; if the generated background-function wrapper fails to import/hand off
|
|
386
|
+
* to the route it never reaches `claimBackgroundRun`, leaving the row stuck at
|
|
387
|
+
* `dispatch_mode = 'background'`. `'background-processing'` means a worker won
|
|
388
|
+
* the claim; a terminal `status` means the run already resolved. Returns null if
|
|
389
|
+
* the row is missing.
|
|
390
|
+
*/
|
|
391
|
+
export async function readBackgroundRunClaim(
|
|
392
|
+
runId: string,
|
|
393
|
+
): Promise<{ dispatchMode: string | null; status: string | null } | null> {
|
|
394
|
+
await ensureRunTables();
|
|
395
|
+
const client = getDbExec();
|
|
396
|
+
const { rows } = await client.execute({
|
|
397
|
+
sql: `SELECT dispatch_mode, status FROM agent_runs WHERE id = ? LIMIT 1`,
|
|
398
|
+
args: [runId],
|
|
399
|
+
});
|
|
400
|
+
const row = rows?.[0] as
|
|
401
|
+
| { dispatch_mode?: string | null; status?: string | null }
|
|
402
|
+
| undefined;
|
|
403
|
+
if (!row) return null;
|
|
404
|
+
return {
|
|
405
|
+
dispatchMode: row.dispatch_mode ?? null,
|
|
406
|
+
status: row.status ?? null,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
381
410
|
/**
|
|
382
411
|
* Atomically acquire a run lease for a thread. Succeeds (returns true) only
|
|
383
412
|
* when no other run for the same thread is currently status='running' with a
|
|
@@ -481,6 +510,13 @@ export const RUN_DIAG_STAGE = {
|
|
|
481
510
|
workerThrew: "worker_threw",
|
|
482
511
|
/** The route handler caught an error from the worker invocation. */
|
|
483
512
|
routeThrew: "route_threw",
|
|
513
|
+
/**
|
|
514
|
+
* The foreground circuit-breaker fired: a Netlify async 202 was returned but
|
|
515
|
+
* no background worker CLAIMED the run within the foreground grace window
|
|
516
|
+
* (the generated function wrapper never reached the route), so the foreground
|
|
517
|
+
* recovered by running the turn inline. The run still completes for the user.
|
|
518
|
+
*/
|
|
519
|
+
foregroundInlineRecovery: "foreground_inline_recovery",
|
|
484
520
|
} as const;
|
|
485
521
|
|
|
486
522
|
export type RunDiagStage = (typeof RUN_DIAG_STAGE)[keyof typeof RUN_DIAG_STAGE];
|
|
@@ -1617,20 +1617,37 @@ let cachedHandler;
|
|
|
1617
1617
|
// PROCESS_RUN_PATH before delegating. Method, ALL headers (the HMAC
|
|
1618
1618
|
// Authorization: Bearer MUST survive — the plugin verifies it) and the body are
|
|
1619
1619
|
// preserved by cloning the incoming Request with only its URL pathname set.
|
|
1620
|
-
export default async function handler(request) {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1620
|
+
export default async function handler(request, context) {
|
|
1621
|
+
try {
|
|
1622
|
+
cachedHandler ??= (await import("./main.mjs")).default;
|
|
1623
|
+
const url = new URL(request.url);
|
|
1624
|
+
url.pathname = PROCESS_RUN_PATH;
|
|
1625
|
+
// Read the body once and pass it through. GET/HEAD have no body.
|
|
1626
|
+
const method = request.method || "POST";
|
|
1627
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
1628
|
+
const body = hasBody ? await request.text() : undefined;
|
|
1629
|
+
const rewritten = new Request(url.toString(), {
|
|
1630
|
+
method,
|
|
1631
|
+
headers: request.headers,
|
|
1632
|
+
body,
|
|
1633
|
+
});
|
|
1634
|
+
// Netlify Functions v2 invokes the handler as (request, context); the Nitro
|
|
1635
|
+
// netlify handler accepts (request[, context]). Pass context through so a
|
|
1636
|
+
// handler that uses it (e.g. waitUntil) does not trip over an undefined arg
|
|
1637
|
+
// before it ever routes the request.
|
|
1638
|
+
return await cachedHandler(rewritten, context);
|
|
1639
|
+
} catch (err) {
|
|
1640
|
+
// Netlify already returned 202 for this background invocation and DISCARDS
|
|
1641
|
+
// this return, so a throw here is otherwise INVISIBLE — it would only surface
|
|
1642
|
+
// downstream as the reaper's "worker never claimed the run". Log it loudly
|
|
1643
|
+
// for the function log; the FOREGROUND circuit-breaker (production-agent.ts)
|
|
1644
|
+
// is what recovers the run by executing it inline when no worker claims.
|
|
1645
|
+
console.error(
|
|
1646
|
+
"[agent-background] wrapper failed before reaching the route:",
|
|
1647
|
+
(err && err.stack) || err,
|
|
1648
|
+
);
|
|
1649
|
+
throw err;
|
|
1650
|
+
}
|
|
1634
1651
|
}
|
|
1635
1652
|
|
|
1636
1653
|
export const config = {
|
|
@@ -7,6 +7,53 @@ import type { ActiveRun } from "./run-manager.js";
|
|
|
7
7
|
import { type ReasoningEffort } from "../shared/reasoning-effort.js";
|
|
8
8
|
import { type Processor } from "./processors.js";
|
|
9
9
|
export { PROVIDER_TO_ENV };
|
|
10
|
+
/**
|
|
11
|
+
* Grace window + poll interval for the foreground circuit-breaker that confirms
|
|
12
|
+
* a background worker actually CLAIMED a 202-dispatched run before recovering
|
|
13
|
+
* inline. The grace is long enough for a cold-start worker to win the claim
|
|
14
|
+
* (~1-2s typical) and short enough to recover quickly within the foreground's
|
|
15
|
+
* ~40s soft-timeout.
|
|
16
|
+
*/
|
|
17
|
+
export declare const BACKGROUND_CLAIM_GRACE_MS = 8000;
|
|
18
|
+
export declare const BACKGROUND_CLAIM_POLL_MS = 400;
|
|
19
|
+
export type BackgroundDispatchOutcome = {
|
|
20
|
+
action: "stream";
|
|
21
|
+
} | {
|
|
22
|
+
action: "subscribe";
|
|
23
|
+
} | {
|
|
24
|
+
action: "inline";
|
|
25
|
+
reason: "dispatch-failed" | "worker-never-claimed" | "no-row";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Decide what the foreground should do after attempting a durable background
|
|
29
|
+
* dispatch. A Netlify async background function returns 202 the instant it
|
|
30
|
+
* ENQUEUES the invocation — that is NOT proof the worker executed. If the
|
|
31
|
+
* generated wrapper fails to import/hand off to the route, the worker never
|
|
32
|
+
* reaches `claimBackgroundRun` and the run is reaped as "worker never claimed".
|
|
33
|
+
*
|
|
34
|
+
* So after a successful dispatch we poll briefly for the worker to CLAIM the run:
|
|
35
|
+
* - claimed within grace → "stream" (subscribe to the worker)
|
|
36
|
+
* - dispatch failed OR no claim → recover inline by atomically claiming the
|
|
37
|
+
* run ourselves: if we win → "inline"; if a (delayed) worker already won
|
|
38
|
+
* it → "subscribe" (never double-run).
|
|
39
|
+
*
|
|
40
|
+
* Pure except for the injected `readClaim`/`claim`/`now`/`sleep` deps, so each
|
|
41
|
+
* branch is unit-testable.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveBackgroundDispatchOutcome(opts: {
|
|
44
|
+
dispatched: boolean;
|
|
45
|
+
backgroundRowInserted: boolean;
|
|
46
|
+
runId: string;
|
|
47
|
+
graceMs: number;
|
|
48
|
+
pollIntervalMs: number;
|
|
49
|
+
readClaim: (runId: string) => Promise<{
|
|
50
|
+
dispatchMode: string | null;
|
|
51
|
+
status: string | null;
|
|
52
|
+
} | null>;
|
|
53
|
+
claim: (runId: string) => Promise<boolean>;
|
|
54
|
+
now?: () => number;
|
|
55
|
+
sleep?: (ms: number) => Promise<void>;
|
|
56
|
+
}): Promise<BackgroundDispatchOutcome>;
|
|
10
57
|
/**
|
|
11
58
|
* Look up a user's persisted API key for the given provider. Returns
|
|
12
59
|
* `undefined` for unauthenticated callers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EAEV,mBAAmB,EAEnB,cAAc,EACd,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAmB3B,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAShE,OAAO,EAEL,cAAc,EACd,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EAET,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAA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