deepline 0.3.530 → 0.3.532

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.
Files changed (144) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +6 -0
  3. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +10 -8
  4. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +95 -9
  5. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +7 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-execution-relay.ts +139 -35
  7. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-receipt-gateway.ts +438 -38
  8. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/runtime-topology.ts +17 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machine-lifecycle.ts +2 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-transient-retry.ts +279 -20
  11. package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +615 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +16 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +26 -8
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +27 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/tool-call-retry-facts.ts +317 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +129 -39
  17. package/dist/cli/auth-7YWTPQSQ.js +43 -0
  18. package/dist/cli/{auth-LRWNDQFT.mjs → auth-ZB3NN4E7.mjs} +5 -5
  19. package/dist/cli/{billing-5FDPWGCG.js → billing-32EF4HJM.js} +82 -82
  20. package/dist/cli/{billing-7T73MRYF.mjs → billing-5GGO7DQS.mjs} +7 -7
  21. package/dist/cli/{chunk-7WGMCOM6.js → chunk-2T7YE5UH.js} +2 -2
  22. package/dist/cli/{chunk-L4QR7CYL.js → chunk-2ZGZBN6D.js} +14 -14
  23. package/dist/cli/{chunk-J6XSBTEX.mjs → chunk-3NUYO5QO.mjs} +1 -1
  24. package/dist/cli/{chunk-MVF7ZBJX.mjs → chunk-47UF3DDN.mjs} +1 -1
  25. package/dist/cli/{chunk-2FLODRM2.js → chunk-4S3ONSLF.js} +13 -13
  26. package/dist/cli/{chunk-4WPIORJX.js → chunk-64CEFPF4.js} +1 -1
  27. package/dist/cli/{chunk-QI2LKPW5.mjs → chunk-6LBD6G6U.mjs} +2 -2
  28. package/dist/cli/{chunk-WWLIDAVT.js → chunk-7S3DJFW5.js} +11 -11
  29. package/dist/cli/{chunk-BVY4QRVT.mjs → chunk-AOAXIJL2.mjs} +82 -31
  30. package/dist/cli/{chunk-KUHH7RW4.js → chunk-AQHMHYXX.js} +44 -44
  31. package/dist/cli/{chunk-WAWOMHWO.mjs → chunk-B77ZRM6M.mjs} +2 -2
  32. package/dist/cli/{chunk-5B37ER3C.js → chunk-BQ2KAFVQ.js} +3 -3
  33. package/dist/cli/{chunk-VQMGCNX2.mjs → chunk-C6VCDDDD.mjs} +5 -5
  34. package/dist/cli/{chunk-3MAHDV5C.mjs → chunk-CRWX26LR.mjs} +1 -1
  35. package/dist/cli/{chunk-7E7CP5KA.js → chunk-CSMLW5VE.js} +4 -4
  36. package/dist/cli/{chunk-HCWPX2UP.mjs → chunk-DSNTHXR7.mjs} +2 -2
  37. package/dist/cli/{chunk-4VQ63Y6S.mjs → chunk-EJLCIQA4.mjs} +5 -5
  38. package/dist/cli/{chunk-7FCD34YS.mjs → chunk-EVXRQXNV.mjs} +3 -2
  39. package/dist/cli/{chunk-K4Y6CNFV.mjs → chunk-F2YLC4ZG.mjs} +1 -1
  40. package/dist/cli/{chunk-YI7QOP6L.js → chunk-FU4MMUGM.js} +16 -16
  41. package/dist/cli/{chunk-6NG3FRJB.mjs → chunk-GABQIZJR.mjs} +5 -5
  42. package/dist/cli/{chunk-V4EK7ZZX.js → chunk-GBVTSWL3.js} +98 -98
  43. package/dist/cli/{chunk-WYI3VMTO.js → chunk-H6OYTU2Y.js} +6 -6
  44. package/dist/cli/{chunk-C44RZGM5.js → chunk-HR2RDDAC.js} +26 -26
  45. package/dist/cli/{chunk-XNWS2WJG.mjs → chunk-HREGFD2I.mjs} +1 -1
  46. package/dist/cli/{chunk-GW76IDID.js → chunk-JJSJ47CA.js} +22 -22
  47. package/dist/cli/{chunk-32NTC5UD.js → chunk-KEE57BF2.js} +7 -7
  48. package/dist/cli/{chunk-SJQ7Z3NI.js → chunk-KQW27FSR.js} +132 -81
  49. package/dist/cli/{chunk-D7Y7I4EE.js → chunk-L5V5SLI7.js} +2 -2
  50. package/dist/cli/{chunk-VKVLJTW5.js → chunk-MHTKWZM3.js} +9 -9
  51. package/dist/cli/{chunk-EADHDZW2.js → chunk-NBIDYAN6.js} +6 -6
  52. package/dist/cli/{chunk-E6L3NEFV.js → chunk-NQDUXVBK.js} +41 -41
  53. package/dist/cli/{chunk-QWEPCX6L.mjs → chunk-O2A4C4WP.mjs} +2 -2
  54. package/dist/cli/{chunk-KEXGBXUG.js → chunk-O7JU5GUR.js} +5 -5
  55. package/dist/cli/{chunk-MVFKZQ7E.js → chunk-QZINISXP.js} +3 -3
  56. package/dist/cli/{chunk-YVLPGYRS.mjs → chunk-RRCSFOF3.mjs} +1 -1
  57. package/dist/cli/{chunk-A5MYJM4K.mjs → chunk-S2HHY26V.mjs} +2 -2
  58. package/dist/cli/{chunk-M4Q4LEMM.js → chunk-SMDX4BM5.js} +2 -2
  59. package/dist/cli/{chunk-5KX3TWBK.mjs → chunk-T2QY36E3.mjs} +1 -1
  60. package/dist/cli/{chunk-OUM2V7R6.mjs → chunk-TFWREZYG.mjs} +6 -6
  61. package/dist/cli/{chunk-QQ4LNSY5.mjs → chunk-THQPLSJD.mjs} +1 -1
  62. package/dist/cli/{chunk-MHR3XVJD.js → chunk-TS6XF2QP.js} +5 -5
  63. package/dist/cli/{chunk-WL6GAZBD.js → chunk-V6LUMGVI.js} +3 -2
  64. package/dist/cli/{chunk-5DJUNUHN.mjs → chunk-VCRCMK7M.mjs} +5 -5
  65. package/dist/cli/{chunk-VYSQ76RP.js → chunk-VHHD5D44.js} +7 -7
  66. package/dist/cli/{chunk-KI63L5H3.mjs → chunk-VIC2MI4W.mjs} +2 -2
  67. package/dist/cli/{chunk-ERMDXXP5.mjs → chunk-VN432I4S.mjs} +1 -1
  68. package/dist/cli/{chunk-LNZILMVK.mjs → chunk-VWEDIFHT.mjs} +4 -4
  69. package/dist/cli/{chunk-I2YXEHDO.mjs → chunk-VZKCZO4J.mjs} +3 -3
  70. package/dist/cli/{chunk-2LKVNWRA.mjs → chunk-W5KSUNTE.mjs} +10 -10
  71. package/dist/cli/{chunk-X547OW3I.js → chunk-WU33X2QL.js} +16 -16
  72. package/dist/cli/{chunk-2FLRKNME.mjs → chunk-YM6JAKYP.mjs} +2 -2
  73. package/dist/cli/command-docs.js +2 -2
  74. package/dist/cli/command-docs.mjs +1 -1
  75. package/dist/cli/{csv-EFIEDJA2.js → csv-4JBCPMEH.js} +13 -13
  76. package/dist/cli/{csv-VY2S7KKV.mjs → csv-LM44ZFL3.mjs} +4 -4
  77. package/dist/cli/{db-D32CBDTN.mjs → db-IFJEGJ6M.mjs} +6 -6
  78. package/dist/cli/{db-3DLI5TYW.js → db-UVNXGK6L.js} +27 -27
  79. package/dist/cli/describe-AF73GGH6.js +50 -0
  80. package/dist/cli/{describe-6MYKK2P3.mjs → describe-TWTOPGII.mjs} +18 -18
  81. package/dist/cli/{executions-QG3DEEY3.js → executions-3I6RU7AO.js} +8 -8
  82. package/dist/cli/{executions-U6TPX4RX.mjs → executions-NEV2P5MX.mjs} +6 -6
  83. package/dist/cli/{feedback-YZ6H4VMQ.mjs → feedback-IO5ZAWKK.mjs} +6 -6
  84. package/dist/cli/{feedback-ZSPW6NXL.js → feedback-NHO56EWZ.js} +14 -14
  85. package/dist/cli/git-AOKC6WL3.js +25 -0
  86. package/dist/cli/{git-ENN72IK4.mjs → git-MQISNZ5F.mjs} +5 -5
  87. package/dist/cli/index.js +145 -145
  88. package/dist/cli/index.mjs +44 -44
  89. package/dist/cli/{legacy-noops-MNA6LWJU.mjs → legacy-noops-DNRJHNQB.mjs} +6 -6
  90. package/dist/cli/{legacy-noops-Q6EVYIGN.js → legacy-noops-SLAQE7HN.js} +9 -9
  91. package/dist/cli/{monitors-BUH54HXJ.js → monitors-JRNATYS2.js} +100 -100
  92. package/dist/cli/{monitors-KENWEEWC.mjs → monitors-NAX7SUAR.mjs} +7 -7
  93. package/dist/cli/{org-HWOHKYP3.mjs → org-34VCNPUD.mjs} +6 -6
  94. package/dist/cli/{org-AHWQJMV7.js → org-BHOREX5D.js} +86 -86
  95. package/dist/cli/{pages-Z5R7NYEF.js → pages-GB337AQG.js} +18 -18
  96. package/dist/cli/{pages-I7DYTCW6.mjs → pages-ZWVHNJOE.mjs} +6 -6
  97. package/dist/cli/{play-3LXZB4ED.js → play-DAUQ7OAO.js} +317 -317
  98. package/dist/cli/{play-ET7CRVWJ.mjs → play-GJ7OEYSB.mjs} +18 -18
  99. package/dist/cli/{providers-GZSAZVHZ.mjs → providers-KA2RKD6E.mjs} +6 -6
  100. package/dist/cli/{providers-ZV2E7NGX.js → providers-W7QY5FUK.js} +9 -9
  101. package/dist/cli/{quickstart-5746NBS2.mjs → quickstart-7KOAL3BD.mjs} +4 -4
  102. package/dist/cli/{quickstart-VJZAT4RY.js → quickstart-D4DPUR7R.js} +6 -6
  103. package/dist/cli/{run-WOQ6XMTT.mjs → run-AYJSQED7.mjs} +23 -23
  104. package/dist/cli/{run-WGUAVYZC.js → run-QFVN2WUQ.js} +41 -41
  105. package/dist/cli/search-JVCK5AB4.js +33 -0
  106. package/dist/cli/{search-NNPFJYEW.mjs → search-MEE7OV2B.mjs} +8 -8
  107. package/dist/cli/{search-output-65HDEEFS.mjs → search-output-G36JH6D6.mjs} +4 -4
  108. package/dist/cli/{search-output-K4ISMPKD.js → search-output-OW6UPOI6.js} +6 -6
  109. package/dist/cli/{secrets-NBKGWMF4.js → secrets-CJJQJUJC.js} +15 -15
  110. package/dist/cli/{secrets-RK44OV3X.mjs → secrets-OFNYIJT6.mjs} +6 -6
  111. package/dist/cli/{sessions-ULQJJN3J.mjs → sessions-B6VCVU4Z.mjs} +6 -6
  112. package/dist/cli/sessions-DXN6BQ7Q.js +22 -0
  113. package/dist/cli/{settings-IHNA7X3Y.js → settings-H4Q524LF.js} +86 -86
  114. package/dist/cli/{settings-V5ZRL2EF.mjs → settings-PPFLSXDP.mjs} +13 -13
  115. package/dist/cli/{setup-HTEBFMOQ.js → setup-SJAM7XHR.js} +78 -63
  116. package/dist/cli/{setup-54VZPJGM.mjs → setup-WI3WDRRE.mjs} +28 -13
  117. package/dist/cli/skills-6MNJK2VQ.js +37 -0
  118. package/dist/cli/{skills-3FCPWMHX.mjs → skills-QSRYGMG2.mjs} +8 -8
  119. package/dist/cli/tools-OT43MSZE.js +57 -0
  120. package/dist/cli/{tools-2NTDNUQT.mjs → tools-RUC4ULAD.mjs} +17 -17
  121. package/dist/cli/{update-25MTBTGU.mjs → update-DPWNL2UB.mjs} +10 -10
  122. package/dist/cli/update-PHOSO3TL.js +35 -0
  123. package/dist/cli/{views-37K4JNNS.js → views-CVDVQALA.js} +18 -18
  124. package/dist/cli/{views-OBE5LUSW.mjs → views-JP66QRA3.mjs} +6 -6
  125. package/dist/cli/{workflow-6YTIHHJH.js → workflow-JM6JUI7I.js} +17 -17
  126. package/dist/cli/{workflow-HAPCL4K6.mjs → workflow-MVTX2PY3.mjs} +7 -7
  127. package/dist/index.js +9 -9
  128. package/dist/index.mjs +6 -6
  129. package/dist/install-integrity.json +108 -106
  130. package/dist/release.d.mts +1 -1
  131. package/dist/release.d.ts +1 -1
  132. package/dist/release.js +2 -2
  133. package/dist/release.mjs +1 -1
  134. package/dist/server.js +5 -5
  135. package/dist/server.mjs +3 -3
  136. package/package.json +1 -1
  137. package/dist/cli/auth-QFIXECQV.js +0 -43
  138. package/dist/cli/describe-U6HM52X6.js +0 -50
  139. package/dist/cli/git-OBV73OVY.js +0 -25
  140. package/dist/cli/search-IGHNMXI4.js +0 -33
  141. package/dist/cli/sessions-ZJNV4SEL.js +0 -22
  142. package/dist/cli/skills-ZCJ6FOOK.js +0 -37
  143. package/dist/cli/tools-Q75XC2BS.js +0 -57
  144. package/dist/cli/update-3G3GO7IE.js +0 -35
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.530',
208
+ version: '0.3.532',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -25,3 +25,9 @@ export const FLEET_REFUSAL = {
25
25
  } as const;
26
26
  export const MAX_MEMBER_DEFINITION_BYTES = 2_048;
27
27
  export const MAX_FLEET_SETTLE_ITEMS = 100;
28
+ /**
29
+ * How long a convergence claim leases its members. The create path posts
30
+ * only well inside it (KAR-260): a pass past it may have lost its members to
31
+ * a reclaim, and a POST then races the release that reclaim makes.
32
+ */
33
+ export const FLEET_CONVERGENCE_LEASE_MS = 90_000;
@@ -227,10 +227,10 @@ export async function uploadBufferToR2(input: {
227
227
  const bucketKind = input.bucketKind ?? 'default';
228
228
  const configStartedAt = Date.now();
229
229
  const config = getR2Config(bucketKind);
230
- logR2Perf('config', input.key, configStartedAt, { kind: bucketKind });
230
+ const configMs = Date.now() - configStartedAt;
231
231
  const clientStartedAt = Date.now();
232
232
  const client = getR2Client(config);
233
- logR2Perf('client', input.key, clientStartedAt, { kind: bucketKind });
233
+ const clientMs = Date.now() - clientStartedAt;
234
234
 
235
235
  const sendStartedAt = Date.now();
236
236
  const result = await client.send(
@@ -242,15 +242,17 @@ export async function uploadBufferToR2(input: {
242
242
  ContentType: input.contentType,
243
243
  }),
244
244
  );
245
- logR2Perf('put-send', input.key, sendStartedAt, {
246
- attempts: result.$metadata.attempts ?? null,
247
- retryDelayMs: result.$metadata.totalRetryDelay ?? null,
248
- kind: bucketKind,
249
- bytes: input.body.byteLength,
250
- });
245
+ // One line per upload. Separate config/client/put-send lines quadrupled the
246
+ // most frequent R2 record (~315K extra Axiom rows/day) for sub-millisecond
247
+ // phases; their timings ride on the single `put` record instead.
251
248
  logR2Perf('put', input.key, startedAt, {
252
249
  kind: bucketKind,
253
250
  bytes: input.body.byteLength,
251
+ configMs,
252
+ clientMs,
253
+ sendMs: Date.now() - sendStartedAt,
254
+ attempts: result.$metadata.attempts ?? null,
255
+ retryDelayMs: result.$metadata.totalRetryDelay ?? null,
254
256
  });
255
257
 
256
258
  if (bucketKind === 'playArtifacts') {
@@ -28,6 +28,18 @@ import {
28
28
  * - onBatchComplete: called after each provider batch for scheduler checkpointing
29
29
  */
30
30
  import { AsyncLocalStorage } from 'async_hooks';
31
+ import {
32
+ createToolCallRetryFacts,
33
+ recordToolCallError,
34
+ recordToolCallRetry,
35
+ recordToolCallSend,
36
+ toolCallFailureLogFields,
37
+ toolCallRetryFactsLogFields,
38
+ toolCallRetryFactsScope,
39
+ toolCallRetryFactsTargetList,
40
+ type ToolCallRetryFacts,
41
+ type ToolCallRetryFactsTargets,
42
+ } from './tool-call-retry-facts';
31
43
  import { isDatasetPayloadField } from '../play-data-plane/sheet-contract';
32
44
  import {
33
45
  createDeferredPlayDataset,
@@ -739,6 +751,17 @@ function newToolCallPhaseClock(): ToolCallPhaseClock {
739
751
  };
740
752
  }
741
753
 
754
+ /** The retry facts of the calls a dispatched request sends for. */
755
+ function toolCallRetryFactsOf(
756
+ requests: readonly ToolCallRequest[],
757
+ ): readonly ToolCallRetryFacts[] {
758
+ const facts: ToolCallRetryFacts[] = [];
759
+ for (const request of requests) {
760
+ if (request.retryFacts) facts.push(request.retryFacts);
761
+ }
762
+ return facts;
763
+ }
764
+
742
765
  function recordToolCallReceiptWall(startedAt: number): void {
743
766
  const clock = toolCallPhaseClock.getStore();
744
767
  if (!clock) return;
@@ -2183,6 +2206,13 @@ type ToolExecutionApiOptions = {
2183
2206
  * inside a row's async scope, where the scope is read from there instead.
2184
2207
  */
2185
2208
  memoryLedgerRowScopes?: readonly (MemoryLedgerRowScope | null | undefined)[];
2209
+ /**
2210
+ * The logical calls this physical request sends for, whose retry facts it
2211
+ * records. The batched dispatcher runs outside its members' async scope and
2212
+ * names them here, an empty list for none; omitted, the call records into
2213
+ * the calling `executeTool` scope. Runner-local; never on the wire.
2214
+ */
2215
+ retryFactsTargets?: readonly ToolCallRetryFacts[];
2186
2216
  /** Runner-local map ownership; this must never be serialized to the gateway. */
2187
2217
  providerBackpressureMapRows?: boolean;
2188
2218
  /**
@@ -4398,7 +4428,6 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4398
4428
  );
4399
4429
  }
4400
4430
 
4401
-
4402
4431
  private async executeFreshnessControlledCall<T>(input: {
4403
4432
  operation: DurableCtxOperation;
4404
4433
  id: string;
@@ -7676,6 +7705,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
7676
7705
  */
7677
7706
  resultReceipts?: ToolResultReceipts;
7678
7707
  apiOptions: ToolExecutionApiOptions;
7708
+ /**
7709
+ * Every logical call this physical request sends for: a native batch's
7710
+ * members. Omitted, the request sends for `request` alone.
7711
+ */
7712
+ retryFactsMembers?: readonly ToolCallRequest[];
7679
7713
  }): Promise<ToolExecuteResult> {
7680
7714
  const providerActionVersion =
7681
7715
  (
@@ -7733,6 +7767,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
7733
7767
  },
7734
7768
  }
7735
7769
  : {}),
7770
+ // Likewise the calls whose retry facts this request records.
7771
+ retryFactsTargets: toolCallRetryFactsOf(
7772
+ input.retryFactsMembers ?? [input.request],
7773
+ ),
7736
7774
  // The dispatcher runs outside the row's async scope, so the row
7737
7775
  // and column that will retain this body have to be named here.
7738
7776
  // This is a runner-local accounting field: it never reaches the
@@ -14788,12 +14826,17 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14788
14826
  // an async-context clock would not belong to one call.
14789
14827
  const phaseClock =
14790
14828
  this.#callSplitTrace && !row ? newToolCallPhaseClock() : null;
14829
+ // Fixed-size counters the retry loop fills in for this logical call. A
14830
+ // queued row call carries the same object to the dispatcher.
14831
+ const retryFacts = createToolCallRetryFacts();
14791
14832
  try {
14792
- result = phaseClock
14793
- ? await toolCallPhaseClock.run(phaseClock, () =>
14794
- this.executeToolInternal(key, toolId, input, options),
14795
- )
14796
- : await this.executeToolInternal(key, toolId, input, options);
14833
+ result = await toolCallRetryFactsScope.run(retryFacts, () =>
14834
+ phaseClock
14835
+ ? toolCallPhaseClock.run(phaseClock, () =>
14836
+ this.executeToolInternal(key, toolId, input, options),
14837
+ )
14838
+ : this.executeToolInternal(key, toolId, input, options),
14839
+ );
14797
14840
  } catch (error) {
14798
14841
  // Parking is control flow, not a failed tool execution.
14799
14842
  if (
@@ -14824,6 +14867,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14824
14867
  ...(savedKey ? { receipt_key: savedKey } : {}),
14825
14868
  status: 'failed',
14826
14869
  duration_ms: Math.max(0, Date.now() - startedAt),
14870
+ ...toolCallRetryFactsLogFields(retryFacts),
14871
+ ...toolCallFailureLogFields(error),
14827
14872
  }),
14828
14873
  { level: 'error' },
14829
14874
  );
@@ -14844,6 +14889,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14844
14889
  // Caller wall time includes queueing/reuse and result delivery. It is
14845
14890
  // deliberately not described as provider request duration.
14846
14891
  duration_ms: Math.max(0, Date.now() - startedAt),
14892
+ ...toolCallRetryFactsLogFields(retryFacts),
14847
14893
  }),
14848
14894
  );
14849
14895
  const split = phaseClock
@@ -15372,8 +15418,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15372
15418
  const toolCachePolicy = this.effectiveToolCallCachePolicy(options);
15373
15419
  const store = rowContext.getStore();
15374
15420
  const callIndexKey = this.toolCallIndexKey(normalizedKey, toolId, input);
15375
- const callIndex =
15376
- reservedCallIndex ?? this.nextToolCallIndex(callIndexKey);
15421
+ const callIndex = reservedCallIndex ?? this.nextToolCallIndex(callIndexKey);
15377
15422
  const logicalCallId =
15378
15423
  logicalCallIdOverride ?? stableDigest(`${callIndexKey}:${callIndex}`);
15379
15424
  // Reserved with its operation slot (or a fresh replay identity): its forced
@@ -16186,6 +16231,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
16186
16231
  tableNamespace: store.tableNamespace,
16187
16232
  rowKey: store.rowKey ?? null,
16188
16233
  description: normalizeStepDescription(options?.description),
16234
+ // The dispatcher sends outside this call's async scope; it records
16235
+ // into the calling `executeTool`'s facts through this reference.
16236
+ retryFacts: toolCallRetryFactsScope.getStore(),
16189
16237
  };
16190
16238
  const pendingToolCall = new Promise((resolve, reject) => {
16191
16239
  this.toolCallResolvers.set(callId, { resolve, reject });
@@ -19312,6 +19360,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
19312
19360
  ],
19313
19361
  completedResultCache: true,
19314
19362
  batchResultView: detail.compiled.resultView,
19363
+ retryFactsTargets: toolCallRetryFactsOf(detail.members),
19315
19364
  memoryLedgerRowScopes: detail.members.map((member) => ({
19316
19365
  rowKey: member.rowKey,
19317
19366
  fieldName: member.fieldName,
@@ -19908,6 +19957,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
19908
19957
  const execution =
19909
19958
  await this.executeMappedToolCallThroughModule({
19910
19959
  request: batch.memberRequests[0]!,
19960
+ retryFactsMembers: batch.memberRequests,
19911
19961
  dispatchToolId: batch.batchOperation,
19912
19962
  dispatchPayload: batch.batchPayload,
19913
19963
  resultReceiptKey: aggregateReceiptKey,
@@ -20486,6 +20536,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20486
20536
  startInput: Record<string, unknown>;
20487
20537
  startResponse: ParsedToolExecuteResponse;
20488
20538
  batchResultView?: 'rawV2';
20539
+ /**
20540
+ * The launch request's retry-fact targets. Poll and finish requests send
20541
+ * for the same logical calls, and the batched dispatcher runs outside
20542
+ * their async scope, so they are named here too.
20543
+ */
20544
+ retryFactsTargets: readonly ToolCallRetryFacts[];
20489
20545
  }): Promise<ParsedToolExecuteResponse> {
20490
20546
  const startResult = input.startResponse.toolResponse?.raw;
20491
20547
  const startClassificationFallback = input.startResponse.toolResponse?.rawV2;
@@ -20565,6 +20621,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20565
20621
  abortSignal,
20566
20622
  skipAsyncOperationResolution: true,
20567
20623
  uncachedAsyncLifecycleCall: true,
20624
+ retryFactsTargets: input.retryFactsTargets,
20568
20625
  }),
20569
20626
  responseValue: (response) =>
20570
20627
  input.batchResultView === 'rawV2' &&
@@ -20847,6 +20904,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20847
20904
  // body over to it.
20848
20905
  const nativeBatchBodyAttribution =
20849
20906
  options?.nativeBatchBodyAttribution ?? null;
20907
+ // The logical calls whose retry facts this request records: named by the
20908
+ // batched dispatcher, else the calling `executeTool`'s own.
20909
+ const retryFactsTargets: ToolCallRetryFactsTargets =
20910
+ options?.retryFactsTargets ?? toolCallRetryFactsScope.getStore();
20850
20911
  let retryActivityEmitted = false;
20851
20912
  let toolCallSucceeded = false;
20852
20913
 
@@ -21411,6 +21472,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21411
21472
  }): Promise<void> => {
21412
21473
  if (!input.connectionNeverOpened)
21413
21474
  earlierDeliveryMayHaveArrived = true;
21475
+ recordToolCallError(retryFactsTargets, {
21476
+ reason: input.connectionNeverOpened ? 'connect' : 'transport',
21477
+ status: null,
21478
+ knownNotDispatched:
21479
+ input.connectionNeverOpened === true ||
21480
+ input.knownNotDispatched === true,
21481
+ });
21414
21482
  let connectRetryDelayMs: number | null = null;
21415
21483
  if (input.connectionNeverOpened) {
21416
21484
  connectFailures += 1;
@@ -21445,6 +21513,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21445
21513
  this.runtimeLog(
21446
21514
  `Tool ${toolId} could not open a connection for ${url}; this attempt sent no request; retrying after ${connectRetryDelayMs}ms: ${diagnostic.message ?? 'unknown transport error'}`,
21447
21515
  );
21516
+ recordToolCallRetry(retryFactsTargets, connectRetryDelayMs);
21448
21517
  await waitForToolRetry(connectRetryDelayMs, false);
21449
21518
  return;
21450
21519
  }
@@ -21474,6 +21543,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21474
21543
  this.runtimeLog(
21475
21544
  `Tool ${toolId} transport failed calling ${url} on attempt ${transportAttempt}/${TOOL_EXECUTE_TRANSPORT_MAX_ATTEMPTS}; retrying after ${retryAfterMs}ms: ${diagnostic.message ?? 'unknown transport error'}`,
21476
21545
  );
21546
+ recordToolCallRetry(retryFactsTargets, retryAfterMs);
21477
21547
  await options?.parkProviderCall?.();
21478
21548
  await this.sleepWithCheckpointHeartbeat(retryAfterMs);
21479
21549
  return;
@@ -21598,6 +21668,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21598
21668
  if (providerDispatchCounted) return;
21599
21669
  providerDispatchCounted = true;
21600
21670
  this.resourceGovernor.recordProviderDispatch();
21671
+ recordToolCallSend(retryFactsTargets, provider);
21601
21672
  };
21602
21673
  // A provider 429 must be reported while its server-minted
21603
21674
  // admission lease is still live. Keep its parsed outcome here so
@@ -22791,6 +22862,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22791
22862
  ? { providerLatencyMs: providerCallElapsedMs }
22792
22863
  : {}),
22793
22864
  });
22865
+ recordToolCallError(retryFactsTargets, {
22866
+ reason: failure.reason,
22867
+ status: response.status,
22868
+ error: failure.error,
22869
+ retryAfterPresent: Boolean(
22870
+ response.headers.get('retry-after')?.trim(),
22871
+ ),
22872
+ knownNotDispatched: failure.knownNotDispatched,
22873
+ });
22794
22874
  let surfacedError = failure.error;
22795
22875
  if (
22796
22876
  response.status === 429 &&
@@ -22921,10 +23001,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22921
23001
  // turns straight into customer row failures. A scheduler refusal
22922
23002
  // proves only that this delivery went nowhere: an earlier delivery
22923
23003
  // of the same attempt may have a row, so the attempt must not move.
23004
+ // A billing-plane refusal is the same: the charge for this
23005
+ // request identity may already be open, and the resend keeps both.
22924
23006
  const shedKnownNotDispatched =
22925
23007
  failure.reason === 'concurrency_backpressure' ||
22926
23008
  failure.reason === 'provider_pacing_wait' ||
22927
- failure.reason === 'runtime_scheduler_capacity';
23009
+ failure.reason === 'runtime_scheduler_capacity' ||
23010
+ failure.reason === 'billing_unavailable_before_dispatch';
22928
23011
  if (
22929
23012
  failure.shouldRetry &&
22930
23013
  (failure.knownNotDispatched ||
@@ -22969,6 +23052,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22969
23052
  }
22970
23053
  const retryDelayMs =
22971
23054
  remainingProviderWaitMs ?? failure.retryDelayMs;
23055
+ recordToolCallRetry(retryFactsTargets, retryDelayMs);
22972
23056
  const retryAttributePrefix =
22973
23057
  failure.reason === 'provider_pacing_wait'
22974
23058
  ? 'provider_pacing_wait'
@@ -23082,6 +23166,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
23082
23166
  startInput: toolInputSnapshot,
23083
23167
  startResponse: parsed,
23084
23168
  batchResultView: options?.batchResultView,
23169
+ retryFactsTargets:
23170
+ toolCallRetryFactsTargetList(retryFactsTargets),
23085
23171
  })
23086
23172
  : parsed;
23087
23173
  // Only the configured execution relay may mint this header. The
@@ -12,6 +12,7 @@ import type { PlayDatasetColumnTypes } from '../play-data-plane/contracts';
12
12
  import type { PlayStructuredDefinition } from '../plays/definition';
13
13
  import type { PlayStaticPipeline } from '../plays/static-pipeline';
14
14
  import type { PlayLogContext, PlayLogMetadata } from './log-context';
15
+ import type { ToolCallRetryFacts } from './tool-call-retry-facts';
15
16
  import type { RuntimeSheetDatasetPageReader } from './runtime-api';
16
17
  import type {
17
18
  AsyncPlayRunRef,
@@ -156,6 +157,12 @@ export interface ToolCallRequest {
156
157
  * closed at the row's delivery site. Measurement only.
157
158
  */
158
159
  deliveryCompletionSettledAtMs?: number | null;
160
+ /**
161
+ * The calling `executeTool`'s retry counters. The dispatcher records the
162
+ * requests it sends for this call into them. Runner-local and in memory
163
+ * only; absent when the call was not made through `executeTool`.
164
+ */
165
+ retryFacts?: ToolCallRetryFacts;
159
166
  }
160
167
 
161
168
  export interface ToolBatchResult {
@@ -16,7 +16,10 @@ import {
16
16
  classifyFlyRequestError,
17
17
  createWithReadBeforeRetry,
18
18
  describeMachineFailures,
19
+ FLY_CREATE_NONCE_METADATA_KEY,
19
20
  runFlyctlWithTransientRetry,
21
+ type FlyCreateReadBackOptions,
22
+ type FlyCreateResult,
20
23
  } from '../fly-transient-retry';
21
24
  import { machineIsServingRuntimeGateway } from '../runtime-gateway-capacity';
22
25
  import {
@@ -301,6 +304,128 @@ function candidates(machines: FlyMachine[], sha: string): FlyMachine[] {
301
304
  export function serving(machines: FlyMachine[]): FlyMachine[] {
302
305
  return machines.filter(machineIsServingRuntimeGateway);
303
306
  }
307
+ /**
308
+ * More candidates exist for this SHA than the serving fleet has Machines.
309
+ * `POST /machines` cannot be made idempotent (see
310
+ * `createWithReadBeforeRetry`), so an ambiguous create can still leave a
311
+ * duplicate. Waiting never resolves one, so name every Machine and fail now.
312
+ *
313
+ * Unlike the receipt gateway, this rollout does not remove the duplicate by
314
+ * itself: it keeps no durable activation phase, so a cordoned candidate is
315
+ * not proof that it was never admitted (a rolled-back generation is cordoned
316
+ * again). Cleanup for this SHA stays the one path that deletes candidates.
317
+ */
318
+ export class ExecutionRelayCandidateSurplusError extends Error {
319
+ readonly machineIds: readonly string[];
320
+ constructor(input: { sha: string; count: number; green: FlyMachine[] }) {
321
+ super(
322
+ `Execution relay rollout ${input.sha} has ${input.green.length} candidate Machine(s) where ${input.count} are expected: ${input.green
323
+ .map(
324
+ (machine) =>
325
+ `${machine.id} ${machine.name ?? '<no-name>'} state=${machine.state ?? '<no-state>'} cordoned=${machine.cordoned ?? '<unknown>'} created_at=${machine.created_at ?? '<unknown>'}`,
326
+ )
327
+ .join(
328
+ ' | ',
329
+ )}. The rollout's cleanup command for this SHA removes only its still-cordoned candidates; run it, then prepare again.`,
330
+ );
331
+ this.name = 'ExecutionRelayCandidateSurplusError';
332
+ this.machineIds = input.green.map((machine) => machine.id);
333
+ }
334
+ }
335
+
336
+ export function assertNoExecutionRelayCandidateSurplus(input: {
337
+ sha: string;
338
+ count: number;
339
+ green: FlyMachine[];
340
+ }): void {
341
+ if (input.green.length > input.count) {
342
+ throw new ExecutionRelayCandidateSurplusError(input);
343
+ }
344
+ }
345
+
346
+ /**
347
+ * The candidates of one rollout must be one Machine per source Machine. A
348
+ * create that landed after `prepare` finished shows up as a second candidate
349
+ * for a source that already has one. The release runs this before the
350
+ * receipt gateway is activated, so such a duplicate stops the release while
351
+ * both gateways still serve the old generation, instead of at relay
352
+ * activation with receipt already cut over.
353
+ */
354
+ export function assertExecutionRelayCandidatesAreOnePerSource(input: {
355
+ sha: string;
356
+ green: FlyMachine[];
357
+ }): void {
358
+ const sources = new Set(
359
+ input.green.map(
360
+ (machine) =>
361
+ machine.config?.metadata?.[EXECUTION_RELAY_SOURCE_METADATA] ??
362
+ `<no-source:${machine.id}>`,
363
+ ),
364
+ );
365
+ assertNoExecutionRelayCandidateSurplus({
366
+ sha: input.sha,
367
+ count: sources.size,
368
+ green: input.green,
369
+ });
370
+ }
371
+
372
+ /** The two Machines API calls a candidate create needs; a fake in tests. */
373
+ export type ExecutionRelayCandidateFlyClient = Readonly<{
374
+ createMachine: (config: Record<string, unknown>) => Promise<FlyMachine>;
375
+ listMachines: () => Promise<FlyMachine[]>;
376
+ }>;
377
+
378
+ /**
379
+ * Create one cordoned candidate, or adopt the Machine that already carries
380
+ * its identity. The identity is the deterministic name plus this SHA in Fly
381
+ * metadata; each create request also stamps its own nonce there. See
382
+ * `createWithReadBeforeRetry` for what happens when Fly does not answer.
383
+ */
384
+ export async function createExecutionRelayCandidate(input: {
385
+ client: ExecutionRelayCandidateFlyClient;
386
+ sha: string;
387
+ name: string;
388
+ source: FlyMachine;
389
+ options?: FlyCreateReadBackOptions;
390
+ }): Promise<FlyCreateResult<FlyMachine>> {
391
+ const { source } = input;
392
+ return await createWithReadBeforeRetry<FlyMachine>({
393
+ identity: `execution relay candidate ${input.name} (rollout ${input.sha})`,
394
+ create: ({ nonce }) =>
395
+ input.client.createMachine({
396
+ name: input.name,
397
+ region: topology.region,
398
+ skip_service_registration: true,
399
+ config: gatewayMachineConfig({
400
+ profile: 'production',
401
+ role: 'execution',
402
+ image: image(input.sha),
403
+ metadata: {
404
+ deepline_gateway_role: 'execution',
405
+ [EXECUTION_RELAY_ROLLOUT_METADATA]: input.sha,
406
+ [EXECUTION_RELAY_SOURCE_METADATA]: source.id,
407
+ [FLY_CREATE_NONCE_METADATA_KEY]: nonce,
408
+ fly_process_group: topology.processGroup,
409
+ ...(source.config?.metadata?.[
410
+ RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY
411
+ ] === '1' ||
412
+ source.name?.startsWith('execution-relay-autoscale-') === true
413
+ ? { [RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY]: '1' }
414
+ : {}),
415
+ },
416
+ }),
417
+ }),
418
+ findExisting: async () =>
419
+ candidates(await input.client.listMachines(), input.sha).filter(
420
+ (machine) => machine.name === input.name,
421
+ ),
422
+ describe: (machine) =>
423
+ `${machine.id} (create nonce ${machine.config?.metadata?.[FLY_CREATE_NONCE_METADATA_KEY] ?? '<none>'})`,
424
+ classify: classifyFlyRequestError,
425
+ ...(input.options ? { options: input.options } : {}),
426
+ });
427
+ }
428
+
304
429
  async function waitForGreen(
305
430
  client: FlyMachinesClient,
306
431
  sha: string,
@@ -310,6 +435,7 @@ async function waitForGreen(
310
435
  let last = 'waiting for candidates';
311
436
  while (Date.now() < deadline) {
312
437
  const green = candidates(await inventory(client), sha);
438
+ assertNoExecutionRelayCandidateSurplus({ sha, count, green });
313
439
  try {
314
440
  if (green.length !== count)
315
441
  last = `expected ${count} candidates; found ${green.length}`;
@@ -378,29 +504,6 @@ async function prepare(sha: string): Promise<void> {
378
504
  return;
379
505
  }
380
506
  }
381
- const createCandidate = (name: string, source: FlyMachine) =>
382
- client.createMachine({
383
- name,
384
- region: topology.region,
385
- skip_service_registration: true,
386
- config: gatewayMachineConfig({
387
- profile: 'production',
388
- role: 'execution',
389
- image: image(sha),
390
- metadata: {
391
- deepline_gateway_role: 'execution',
392
- [EXECUTION_RELAY_ROLLOUT_METADATA]: sha,
393
- [EXECUTION_RELAY_SOURCE_METADATA]: source.id!,
394
- fly_process_group: topology.processGroup,
395
- ...(source.config?.metadata?.[
396
- RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY
397
- ] === '1' ||
398
- source.name?.startsWith('execution-relay-autoscale-') === true
399
- ? { [RUNTIME_GATEWAY_AUTOSCALED_METADATA_KEY]: '1' }
400
- : {}),
401
- },
402
- }),
403
- });
404
507
  if (existing.length === 0) {
405
508
  if (
406
509
  blue.length < topology.minimumMachines ||
@@ -410,17 +513,11 @@ async function prepare(sha: string): Promise<void> {
410
513
  'Cannot prepare an execution relay generation without a healthy serving fleet.',
411
514
  );
412
515
  for (const [index, source] of blue.entries()) {
413
- const name = candidateName(sha, index);
414
- // A transient create failure is ambiguous; re-read before any retry
415
- // so a candidate Fly already created is adopted, never duplicated.
416
- await createWithReadBeforeRetry({
417
- create: () => createCandidate(name, source),
418
- findExisting: async () =>
419
- candidates(await inventory(client), sha).find(
420
- (machine) => machine.name === name,
421
- ),
422
- classify: classifyFlyRequestError,
423
- options: { label: `Create execution relay candidate ${name}` },
516
+ await createExecutionRelayCandidate({
517
+ client,
518
+ sha,
519
+ name: candidateName(sha, index),
520
+ source,
424
521
  });
425
522
  }
426
523
  }
@@ -566,7 +663,14 @@ export async function main(): Promise<void> {
566
663
  if (command === 'activate') return await activate(sha);
567
664
  if (command === 'rollback') return await rollback(sha);
568
665
  if (command === 'cleanup') return await cleanup(sha);
666
+ if (command === 'assert-no-surplus') {
667
+ // Read-only: one inventory read, no provider mutation.
668
+ return assertExecutionRelayCandidatesAreOnePerSource({
669
+ sha,
670
+ green: candidates(await inventory(releaseFlyClient()), sha),
671
+ });
672
+ }
569
673
  throw new Error(
570
- 'Usage: roll-execution-relay.ts prepare|activate|rollback|cleanup --environment production --sha <sha> --apply',
674
+ 'Usage: roll-execution-relay.ts prepare|activate|rollback|cleanup|assert-no-surplus --environment production --sha <sha> --apply',
571
675
  );
572
676
  }