@agent-native/core 0.84.5 → 0.84.6

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.
@@ -1,5 +1,11 @@
1
1
  # @agent-native/core
2
2
 
3
+ ## 0.84.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 126ccac: Claim durable background agent-chat runs before expensive worker setup so hosted apps stay on the 15-minute background-function path instead of falling back to 40-second inline chunks.
8
+
3
9
  ## 0.84.5
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.84.5",
3
+ "version": "0.84.6",
4
4
  "description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -4025,6 +4025,58 @@ export function shouldChainBackgroundContinuation(opts: {
4025
4025
  );
4026
4026
  }
4027
4027
 
4028
+ export async function claimBackgroundWorkerRunEarly(opts: {
4029
+ runId: string;
4030
+ threadId?: string | null;
4031
+ markerTurnId?: string | null;
4032
+ requestTurnId?: string | null;
4033
+ continuationCount: number;
4034
+ runsInBackgroundFunction: boolean;
4035
+ deps?: {
4036
+ recordRunDiagnostic?: typeof recordRunDiagnostic;
4037
+ insertRun?: typeof insertRun;
4038
+ claimBackgroundRun?: typeof claimBackgroundRun;
4039
+ updateRunHeartbeat?: typeof updateRunHeartbeat;
4040
+ };
4041
+ }): Promise<{ claimed: true } | { claimed: false; skipped: string }> {
4042
+ const record = opts.deps?.recordRunDiagnostic ?? recordRunDiagnostic;
4043
+ const insert = opts.deps?.insertRun ?? insertRun;
4044
+ const claim = opts.deps?.claimBackgroundRun ?? claimBackgroundRun;
4045
+ const heartbeat = opts.deps?.updateRunHeartbeat ?? updateRunHeartbeat;
4046
+ const threadId =
4047
+ typeof opts.threadId === "string" && opts.threadId.trim()
4048
+ ? opts.threadId.trim()
4049
+ : opts.runId;
4050
+ const turnId =
4051
+ typeof opts.markerTurnId === "string" && opts.markerTurnId.trim()
4052
+ ? opts.markerTurnId.trim()
4053
+ : typeof opts.requestTurnId === "string" && opts.requestTurnId.trim()
4054
+ ? opts.requestTurnId.trim()
4055
+ : opts.runId;
4056
+
4057
+ await record(
4058
+ opts.runId,
4059
+ RUN_DIAG_STAGE.workerEntered,
4060
+ `runsInBackgroundFunction=${opts.runsInBackgroundFunction} continuationCount=${opts.continuationCount}`,
4061
+ ).catch(() => {});
4062
+
4063
+ if (opts.continuationCount > 0) {
4064
+ await insert(opts.runId, threadId, turnId, {
4065
+ dispatchMode: "background",
4066
+ }).catch(() => {});
4067
+ }
4068
+
4069
+ const won = await claim(opts.runId);
4070
+ if (!won) {
4071
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => {});
4072
+ return { claimed: false, skipped: "already-claimed" };
4073
+ }
4074
+
4075
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimed).catch(() => {});
4076
+ await heartbeat(opts.runId).catch(() => {});
4077
+ return { claimed: true };
4078
+ }
4079
+
4028
4080
  function progressStepFromAgentChatEvent(event: AgentChatEvent): string | null {
4029
4081
  switch (event.type) {
4030
4082
  case "activity":
@@ -4175,6 +4227,24 @@ export function createProductionAgentHandler(
4175
4227
  Number.isFinite(backgroundRunMarker.continuationCount)
4176
4228
  ? Math.max(0, Math.floor(backgroundRunMarker.continuationCount))
4177
4229
  : 0;
4230
+ let backgroundRunClaimedEarly = false;
4231
+ if (isBackgroundWorker && bgRunId) {
4232
+ const earlyClaim = await claimBackgroundWorkerRunEarly({
4233
+ runId: bgRunId,
4234
+ threadId,
4235
+ markerTurnId:
4236
+ typeof backgroundRunMarker?.turnId === "string"
4237
+ ? backgroundRunMarker.turnId
4238
+ : null,
4239
+ requestTurnId,
4240
+ continuationCount: backgroundContinuationCount,
4241
+ runsInBackgroundFunction,
4242
+ });
4243
+ if (!earlyClaim.claimed) {
4244
+ return { ok: true, skipped: earlyClaim.skipped };
4245
+ }
4246
+ backgroundRunClaimedEarly = true;
4247
+ }
4178
4248
  // The foreground POST decides whether to dispatch into a background
4179
4249
  // function. The background worker itself never re-dispatches.
4180
4250
  const dispatchToBackground =
@@ -5254,48 +5324,37 @@ export function createProductionAgentHandler(
5254
5324
  }
5255
5325
  : undefined;
5256
5326
 
5257
- // Background worker: claim the pre-inserted run idempotently before
5258
- // executing. A duplicate Netlify delivery loses the claim and no-ops here,
5259
- // so the run can never be double-executed. Bump the heartbeat immediately
5260
- // on entry so a slow cold-start doesn't leave the row looking stale to the
5261
- // reaper before startRun's 1.5s heartbeat timer takes over.
5327
+ // Background worker: the run was claimed immediately after the authenticated
5328
+ // `_process-run` body was parsed, before owner/model/prompt/tool setup. That
5329
+ // early claim is what lets the foreground subscribe to the real background
5330
+ // worker instead of racing slow setup and falling back to the 40s inline
5331
+ // path. This late block is a defensive fallback for older/custom callers
5332
+ // that somehow reach here without the early claim.
5262
5333
  if (isBackgroundWorker) {
5263
- // DIAGNOSTIC: the re-entered handler recognized itself as the background
5264
- // worker. Record the runtime regime too — `isInBackgroundFunctionRuntime()`
5265
- // reads a globalThis marker set by the bg-fn entry, which may NOT be set in
5266
- // this isolate; recording the ACTUAL resolved value reveals whether the
5267
- // worker is on the 13-min `-background` budget or the 40s clamp. This is
5268
- // the proof the worker reached its own code (vs. dying at auth before it).
5269
- await recordRunDiagnostic(
5270
- runId,
5271
- RUN_DIAG_STAGE.workerEntered,
5272
- `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`,
5273
- ).catch(() => {});
5274
- // A chained continuation chunk's runId was minted by the prior chunk and
5275
- // never inserted, so insert its background row now (idempotently — a
5276
- // duplicate Netlify delivery that already inserted it just PK-collides and
5277
- // the claim below dedups). The first chunk's row was inserted by the
5278
- // foreground, so skip the insert there.
5279
- if (isChainedBackgroundContinuation) {
5280
- await insertRun(runId, effectiveThreadId, effectiveTurnId, {
5281
- dispatchMode: "background",
5282
- }).catch(() => {});
5283
- }
5284
- const won = await claimBackgroundRun(runId);
5285
- if (!won) {
5286
- // Already claimed by an earlier delivery — return a benign ack so
5287
- // Netlify doesn't retry a successful handoff.
5288
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(
5334
+ if (!backgroundRunClaimedEarly) {
5335
+ await recordRunDiagnostic(
5336
+ runId,
5337
+ RUN_DIAG_STAGE.workerEntered,
5338
+ `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`,
5339
+ ).catch(() => {});
5340
+ if (isChainedBackgroundContinuation) {
5341
+ await insertRun(runId, effectiveThreadId, effectiveTurnId, {
5342
+ dispatchMode: "background",
5343
+ }).catch(() => {});
5344
+ }
5345
+ const won = await claimBackgroundRun(runId);
5346
+ if (!won) {
5347
+ await recordRunDiagnostic(
5348
+ runId,
5349
+ RUN_DIAG_STAGE.workerClaimLost,
5350
+ ).catch(() => {});
5351
+ return { ok: true, skipped: "already-claimed" };
5352
+ }
5353
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(
5289
5354
  () => {},
5290
5355
  );
5291
- return { ok: true, skipped: "already-claimed" };
5356
+ await updateRunHeartbeat(runId).catch(() => {});
5292
5357
  }
5293
- // DIAGNOSTIC: this worker won the claim and now OWNS the run. If a run
5294
- // ever stalls at this stage it means the loop below failed to start.
5295
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(
5296
- () => {},
5297
- );
5298
- await updateRunHeartbeat(runId).catch(() => {});
5299
5358
  }
5300
5359
 
5301
5360
  // DIAGNOSTIC-ONLY: build the pre-startRun setup-timing breakdown now (so the
@@ -64,6 +64,23 @@ export const UNCLAIMED_BACKGROUND_RUN_ERROR_EVENT = {
64
64
  "A background-dispatched run was acknowledged (HTTP 202) but its worker never claimed the run, so no progress was produced. The run was reaped early (it had no live worker to protect) so the turn can be retried.",
65
65
  } as const;
66
66
 
67
+ /**
68
+ * Terminal error for a background worker that DID claim the run, then failed
69
+ * during route/handler setup before `startRun` could emit its own error event.
70
+ * Claimed runs are no longer eligible for foreground inline recovery, so the
71
+ * route boundary must fail them loudly instead of leaving subscribers to wait
72
+ * for stale-run recovery.
73
+ */
74
+ export const CLAIMED_BACKGROUND_WORKER_FAILED_ERROR_EVENT = {
75
+ type: "error",
76
+ error:
77
+ "The background agent worker stopped before it could start the turn. You can retry from the preserved chat context.",
78
+ errorCode: "background_worker_failed",
79
+ recoverable: true,
80
+ details:
81
+ "The durable background worker claimed the run but threw during setup before it could emit agent events.",
82
+ } as const;
83
+
67
84
  /**
68
85
  * Grace period before a never-claimed background run (dispatch_mode still
69
86
  * 'background', no worker claim) is treated as a dead handoff and reaped.
@@ -62,7 +62,15 @@ import {
62
62
  import { runAgentLoopDirectWithSoftTimeout } from "../agent/run-loop-with-resume.js";
63
63
  import { callerOwnsRun, callerOwnsThread } from "../agent/run-ownership.js";
64
64
  import type { AgentRunSummary } from "../agent/run-store.js";
65
- import { readBackgroundRunClaim } from "../agent/run-store.js";
65
+ import {
66
+ CLAIMED_BACKGROUND_WORKER_FAILED_ERROR_EVENT,
67
+ ensureTerminalRunEvent,
68
+ readBackgroundRunClaim,
69
+ recordRunDiagnostic,
70
+ RUN_DIAG_STAGE,
71
+ setRunError,
72
+ updateRunStatusIfRunning,
73
+ } from "../agent/run-store.js";
66
74
  import { buildRuntimeContextPrompt } from "../agent/runtime-context.js";
67
75
  import {
68
76
  buildAssistantMessage,
@@ -3864,6 +3872,50 @@ export function shouldDisableRecurringJobsRuntime(
3864
3872
  return isLocalRuntime;
3865
3873
  }
3866
3874
 
3875
+ type AgentChatProcessRunFailureDeps = {
3876
+ readBackgroundRunClaim?: typeof readBackgroundRunClaim;
3877
+ recordRunDiagnostic?: typeof recordRunDiagnostic;
3878
+ setRunError?: typeof setRunError;
3879
+ updateRunStatusIfRunning?: typeof updateRunStatusIfRunning;
3880
+ ensureTerminalRunEvent?: typeof ensureTerminalRunEvent;
3881
+ };
3882
+
3883
+ export async function finalizeClaimedAgentChatProcessRunFailure(
3884
+ runId: string,
3885
+ err: unknown,
3886
+ deps: AgentChatProcessRunFailureDeps = {},
3887
+ ): Promise<boolean> {
3888
+ const readClaim = deps.readBackgroundRunClaim ?? readBackgroundRunClaim;
3889
+ const record = deps.recordRunDiagnostic ?? recordRunDiagnostic;
3890
+ const setError = deps.setRunError ?? setRunError;
3891
+ const updateStatus =
3892
+ deps.updateRunStatusIfRunning ?? updateRunStatusIfRunning;
3893
+ const ensureTerminal = deps.ensureTerminalRunEvent ?? ensureTerminalRunEvent;
3894
+ const message = err instanceof Error ? err.message : String(err);
3895
+
3896
+ await record(runId, RUN_DIAG_STAGE.routeThrew, message).catch(() => {});
3897
+
3898
+ const claim = await readClaim(runId).catch(() => null);
3899
+ if (
3900
+ claim?.status !== "running" ||
3901
+ claim.dispatchMode !== "background-processing"
3902
+ ) {
3903
+ return false;
3904
+ }
3905
+
3906
+ await setError(
3907
+ runId,
3908
+ CLAIMED_BACKGROUND_WORKER_FAILED_ERROR_EVENT.errorCode,
3909
+ `${CLAIMED_BACKGROUND_WORKER_FAILED_ERROR_EVENT.details} setupError=${message}`,
3910
+ ).catch(() => {});
3911
+ await updateStatus(runId, "errored").catch(() => {});
3912
+ await ensureTerminal(
3913
+ runId,
3914
+ CLAIMED_BACKGROUND_WORKER_FAILED_ERROR_EVENT,
3915
+ ).catch(() => {});
3916
+ return true;
3917
+ }
3918
+
3867
3919
  export function createAgentChatPlugin(
3868
3920
  options?: AgentChatPluginOptions,
3869
3921
  ): NitroPluginDef {
@@ -8030,17 +8082,10 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
8030
8082
  runId: prepared.runId,
8031
8083
  },
8032
8084
  });
8033
- // DIAGNOSTIC: the worker invocation threw at the route boundary —
8034
- // record the message so the failure cause is readable client-side.
8035
- if (diag) {
8036
- await diag
8037
- .record(
8038
- prepared.runId,
8039
- diag.stages.routeThrew,
8040
- err instanceof Error ? err.message : String(err),
8041
- )
8042
- .catch(() => {});
8043
- }
8085
+ await finalizeClaimedAgentChatProcessRunFailure(
8086
+ prepared.runId,
8087
+ err,
8088
+ );
8044
8089
  setResponseStatus(event, 500);
8045
8090
  return { error: "process-run failed" };
8046
8091
  }
@@ -5,6 +5,7 @@ import type { AgentEngine, EngineTool, EngineMessage, EngineContentPart } from "
5
5
  import { type Processor } from "./processors.js";
6
6
  import { subscribeToRun, getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun } from "./run-manager.js";
7
7
  import type { ActiveRun } from "./run-manager.js";
8
+ import { insertRun, updateRunHeartbeat, claimBackgroundRun, recordRunDiagnostic } from "./run-store.js";
8
9
  import type { ActionTool, AgentChatAttachment, AgentChatEvent, AgentChatReference, AgentChatStructuredMessage } from "./types.js";
9
10
  export { PROVIDER_TO_ENV };
10
11
  /**
@@ -477,6 +478,25 @@ export declare function shouldChainBackgroundContinuation(opts: {
477
478
  run: ActiveRun;
478
479
  continuationCount: number;
479
480
  }): boolean;
481
+ export declare function claimBackgroundWorkerRunEarly(opts: {
482
+ runId: string;
483
+ threadId?: string | null;
484
+ markerTurnId?: string | null;
485
+ requestTurnId?: string | null;
486
+ continuationCount: number;
487
+ runsInBackgroundFunction: boolean;
488
+ deps?: {
489
+ recordRunDiagnostic?: typeof recordRunDiagnostic;
490
+ insertRun?: typeof insertRun;
491
+ claimBackgroundRun?: typeof claimBackgroundRun;
492
+ updateRunHeartbeat?: typeof updateRunHeartbeat;
493
+ };
494
+ }): Promise<{
495
+ claimed: true;
496
+ } | {
497
+ claimed: false;
498
+ skipped: string;
499
+ }>;
480
500
  export declare function createProductionAgentHandler(options: ProductionAgentOptions): H3EventHandler;
481
501
  export { getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun, subscribeToRun, };
482
502
  //# sourceMappingURL=production-agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,IAAI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EAAE,MAAM,CAAC;CAC3B,GAAG,OAAO,CAOV;AAED,wBAAsB,6BAA6B,CAAC,IAAI,EAAE;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wBAAwB,EAAE,OAAO,CAAC;IAClC,IAAI,CAAC,EAAE;QACL,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAC;QACjD,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;QAC7B,kBAAkB,CAAC,EAAE,OAAO,kBAAkB,CAAC;QAC/C,kBAAkB,CAAC,EAAE,OAAO,kBAAkB,CAAC;KAChD,CAAC;CACH,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCnE;AA+BD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAmrDhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
@@ -3046,6 +3046,34 @@ export function shouldChainBackgroundContinuation(opts) {
3046
3046
  endsAtInternalContinuationBoundary(opts.run) &&
3047
3047
  opts.continuationCount < MAX_BACKGROUND_RUN_CONTINUATIONS);
3048
3048
  }
3049
+ export async function claimBackgroundWorkerRunEarly(opts) {
3050
+ const record = opts.deps?.recordRunDiagnostic ?? recordRunDiagnostic;
3051
+ const insert = opts.deps?.insertRun ?? insertRun;
3052
+ const claim = opts.deps?.claimBackgroundRun ?? claimBackgroundRun;
3053
+ const heartbeat = opts.deps?.updateRunHeartbeat ?? updateRunHeartbeat;
3054
+ const threadId = typeof opts.threadId === "string" && opts.threadId.trim()
3055
+ ? opts.threadId.trim()
3056
+ : opts.runId;
3057
+ const turnId = typeof opts.markerTurnId === "string" && opts.markerTurnId.trim()
3058
+ ? opts.markerTurnId.trim()
3059
+ : typeof opts.requestTurnId === "string" && opts.requestTurnId.trim()
3060
+ ? opts.requestTurnId.trim()
3061
+ : opts.runId;
3062
+ await record(opts.runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${opts.runsInBackgroundFunction} continuationCount=${opts.continuationCount}`).catch(() => { });
3063
+ if (opts.continuationCount > 0) {
3064
+ await insert(opts.runId, threadId, turnId, {
3065
+ dispatchMode: "background",
3066
+ }).catch(() => { });
3067
+ }
3068
+ const won = await claim(opts.runId);
3069
+ if (!won) {
3070
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
3071
+ return { claimed: false, skipped: "already-claimed" };
3072
+ }
3073
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
3074
+ await heartbeat(opts.runId).catch(() => { });
3075
+ return { claimed: true };
3076
+ }
3049
3077
  function progressStepFromAgentChatEvent(event) {
3050
3078
  switch (event.type) {
3051
3079
  case "activity":
@@ -3164,6 +3192,23 @@ export function createProductionAgentHandler(options) {
3164
3192
  Number.isFinite(backgroundRunMarker.continuationCount)
3165
3193
  ? Math.max(0, Math.floor(backgroundRunMarker.continuationCount))
3166
3194
  : 0;
3195
+ let backgroundRunClaimedEarly = false;
3196
+ if (isBackgroundWorker && bgRunId) {
3197
+ const earlyClaim = await claimBackgroundWorkerRunEarly({
3198
+ runId: bgRunId,
3199
+ threadId,
3200
+ markerTurnId: typeof backgroundRunMarker?.turnId === "string"
3201
+ ? backgroundRunMarker.turnId
3202
+ : null,
3203
+ requestTurnId,
3204
+ continuationCount: backgroundContinuationCount,
3205
+ runsInBackgroundFunction,
3206
+ });
3207
+ if (!earlyClaim.claimed) {
3208
+ return { ok: true, skipped: earlyClaim.skipped };
3209
+ }
3210
+ backgroundRunClaimedEarly = true;
3211
+ }
3167
3212
  // The foreground POST decides whether to dispatch into a background
3168
3213
  // function. The background worker itself never re-dispatches.
3169
3214
  const dispatchToBackground = !isBackgroundWorker &&
@@ -4061,40 +4106,28 @@ export function createProductionAgentHandler(options) {
4061
4106
  }
4062
4107
  }
4063
4108
  : undefined;
4064
- // Background worker: claim the pre-inserted run idempotently before
4065
- // executing. A duplicate Netlify delivery loses the claim and no-ops here,
4066
- // so the run can never be double-executed. Bump the heartbeat immediately
4067
- // on entry so a slow cold-start doesn't leave the row looking stale to the
4068
- // reaper before startRun's 1.5s heartbeat timer takes over.
4109
+ // Background worker: the run was claimed immediately after the authenticated
4110
+ // `_process-run` body was parsed, before owner/model/prompt/tool setup. That
4111
+ // early claim is what lets the foreground subscribe to the real background
4112
+ // worker instead of racing slow setup and falling back to the 40s inline
4113
+ // path. This late block is a defensive fallback for older/custom callers
4114
+ // that somehow reach here without the early claim.
4069
4115
  if (isBackgroundWorker) {
4070
- // DIAGNOSTIC: the re-entered handler recognized itself as the background
4071
- // worker. Record the runtime regime too — `isInBackgroundFunctionRuntime()`
4072
- // reads a globalThis marker set by the bg-fn entry, which may NOT be set in
4073
- // this isolate; recording the ACTUAL resolved value reveals whether the
4074
- // worker is on the 13-min `-background` budget or the 40s clamp. This is
4075
- // the proof the worker reached its own code (vs. dying at auth before it).
4076
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`).catch(() => { });
4077
- // A chained continuation chunk's runId was minted by the prior chunk and
4078
- // never inserted, so insert its background row now (idempotently — a
4079
- // duplicate Netlify delivery that already inserted it just PK-collides and
4080
- // the claim below dedups). The first chunk's row was inserted by the
4081
- // foreground, so skip the insert there.
4082
- if (isChainedBackgroundContinuation) {
4083
- await insertRun(runId, effectiveThreadId, effectiveTurnId, {
4084
- dispatchMode: "background",
4085
- }).catch(() => { });
4086
- }
4087
- const won = await claimBackgroundRun(runId);
4088
- if (!won) {
4089
- // Already claimed by an earlier delivery — return a benign ack so
4090
- // Netlify doesn't retry a successful handoff.
4091
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
4092
- return { ok: true, skipped: "already-claimed" };
4116
+ if (!backgroundRunClaimedEarly) {
4117
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`).catch(() => { });
4118
+ if (isChainedBackgroundContinuation) {
4119
+ await insertRun(runId, effectiveThreadId, effectiveTurnId, {
4120
+ dispatchMode: "background",
4121
+ }).catch(() => { });
4122
+ }
4123
+ const won = await claimBackgroundRun(runId);
4124
+ if (!won) {
4125
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
4126
+ return { ok: true, skipped: "already-claimed" };
4127
+ }
4128
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
4129
+ await updateRunHeartbeat(runId).catch(() => { });
4093
4130
  }
4094
- // DIAGNOSTIC: this worker won the claim and now OWNS the run. If a run
4095
- // ever stalls at this stage it means the loop below failed to start.
4096
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
4097
- await updateRunHeartbeat(runId).catch(() => { });
4098
4131
  }
4099
4132
  // DIAGNOSTIC-ONLY: build the pre-startRun setup-timing breakdown now (so the
4100
4133
  // marks reflect the work done BEFORE the loop), but EMIT it from inside