deepline 0.3.537 → 0.3.539

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 (205) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +22 -5
  2. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  3. package/dist/bundling-sources/sdk/src/plays/client-core.ts +18 -1
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +33 -4
  6. package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +1 -1
  7. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +18 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +9 -1
  9. package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +392 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +717 -133
  11. package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +7 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +22 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +123 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +480 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +24 -16
  16. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +293 -53
  17. package/dist/bundling-sources/shared_libs/play-runtime/governor/block-reserving-budget-state-backend.ts +57 -2
  18. package/dist/bundling-sources/shared_libs/play-runtime/governor/budget-state-backend.ts +43 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +141 -9
  20. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +4 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +6 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/modal-supervisor-sidecar.ts +556 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +27 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +19 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +54 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +5 -0
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +155 -7
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/relay-connection-counter.ts +103 -0
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +75 -6
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +59 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +544 -73
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +8 -1
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +19 -1
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2399 -110
  35. package/dist/bundling-sources/shared_libs/play-runtime/runtime-flow.ts +42 -8
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-read-through.ts +287 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-finish.ts +606 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +274 -119
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +136 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-traffic-policy.ts +54 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/runtime-work-counters.ts +10 -1
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +22 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +18 -1
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +18 -4
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +219 -7
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +340 -0
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +1 -0
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +10 -1
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +623 -7
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +340 -5
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +61 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -1
  54. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +269 -2
  55. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +238 -5
  56. package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +47 -0
  57. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +5 -4
  58. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +6 -0
  59. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +11 -0
  60. package/dist/cli/auth-O5Y2VYXK.js +43 -0
  61. package/dist/cli/{auth-4SUPGDIM.mjs → auth-QD7QGD3B.mjs} +5 -5
  62. package/dist/cli/{billing-5JUA3ZM3.mjs → billing-FIZXMHBW.mjs} +31 -7
  63. package/dist/cli/{billing-SQU726P7.js → billing-KOQAF6WS.js} +114 -90
  64. package/dist/cli/{chunk-R7JYG6XO.mjs → chunk-2XMFT44N.mjs} +1 -1
  65. package/dist/cli/{chunk-XDS26J7Z.js → chunk-3YDI2PTN.js} +10 -10
  66. package/dist/cli/{chunk-KH27B2HJ.mjs → chunk-55ITVU2V.mjs} +2 -2
  67. package/dist/cli/{chunk-2Q7VXTMS.js → chunk-5QL4GJB2.js} +2 -2
  68. package/dist/cli/{chunk-D77W6Q67.js → chunk-5RUB53KG.js} +26 -26
  69. package/dist/cli/{chunk-JS2SBCWD.js → chunk-5YF35HAV.js} +6 -6
  70. package/dist/cli/{chunk-C37VELBR.mjs → chunk-6KG4KVTH.mjs} +5 -5
  71. package/dist/cli/{chunk-AX2OAXDL.mjs → chunk-6NZBLFL4.mjs} +1 -1
  72. package/dist/cli/{chunk-C3XD2WHM.mjs → chunk-6V3LNYK5.mjs} +2 -2
  73. package/dist/cli/{chunk-GPMS6OPX.mjs → chunk-ADV2IB2C.mjs} +5 -5
  74. package/dist/cli/{chunk-ZUAMXZXC.mjs → chunk-APKZGUTU.mjs} +4 -4
  75. package/dist/cli/{chunk-IQOIT6E3.js → chunk-CQJCLHBE.js} +41 -41
  76. package/dist/cli/{chunk-W3J3LT22.mjs → chunk-DZFVVP3S.mjs} +5 -5
  77. package/dist/cli/{chunk-V5IIBG2E.mjs → chunk-E4QHTDPF.mjs} +1 -1
  78. package/dist/cli/{chunk-CXTW7SRW.mjs → chunk-E7D37PLM.mjs} +8 -0
  79. package/dist/cli/{chunk-KULT6O5K.js → chunk-EAZS52DL.js} +15 -15
  80. package/dist/cli/{chunk-L3JVGNAT.mjs → chunk-F43MXIN3.mjs} +2 -2
  81. package/dist/cli/{chunk-WBTYWJLN.js → chunk-FH3P3E4S.js} +2 -2
  82. package/dist/cli/{chunk-K4WJ4BYO.mjs → chunk-FIRV7BXJ.mjs} +1 -1
  83. package/dist/cli/{chunk-NXGLJGPB.js → chunk-FSQCB5SJ.js} +2 -2
  84. package/dist/cli/{chunk-AVQET3NR.js → chunk-FTBWFDF3.js} +7 -7
  85. package/dist/cli/{chunk-QDBGPRR2.mjs → chunk-G3UFDUYU.mjs} +3 -1
  86. package/dist/cli/{chunk-ZHPSJ3LJ.mjs → chunk-GEO2EMM7.mjs} +29 -16
  87. package/dist/cli/{chunk-CGDW2CRR.mjs → chunk-GLEGINSP.mjs} +2 -2
  88. package/dist/cli/{chunk-EEFSUCYP.mjs → chunk-GLKUC5PO.mjs} +2 -2
  89. package/dist/cli/{chunk-BFHR7IC2.mjs → chunk-GNCIMHO2.mjs} +10 -10
  90. package/dist/cli/{chunk-PU42VOBI.js → chunk-ISXX5DUD.js} +3 -3
  91. package/dist/cli/{chunk-Y6AMMXWS.mjs → chunk-JBCQFG7G.mjs} +3 -3
  92. package/dist/cli/{chunk-Z2PPB3IO.mjs → chunk-JHEZQMOM.mjs} +1 -1
  93. package/dist/cli/{chunk-WBFOV5HT.js → chunk-K22EKW6L.js} +5 -5
  94. package/dist/cli/{chunk-CHIGEDAE.js → chunk-K5MZHTK7.js} +3 -3
  95. package/dist/cli/{chunk-L6QAIZNZ.js → chunk-KAEVL62Q.js} +44 -44
  96. package/dist/cli/{chunk-PJ4ZGZAN.js → chunk-KQTX545E.js} +13 -13
  97. package/dist/cli/{chunk-VP2K5B3R.mjs → chunk-LE5KN7CZ.mjs} +3 -3
  98. package/dist/cli/{chunk-BGXEMTIG.js → chunk-LEREPTAE.js} +19 -19
  99. package/dist/cli/{chunk-QPDLG7DQ.js → chunk-MI53W4DN.js} +53 -53
  100. package/dist/cli/{chunk-RMVZTBI5.mjs → chunk-MKESK3SW.mjs} +4 -4
  101. package/dist/cli/{chunk-NU7B5X6J.mjs → chunk-N3LPGGWD.mjs} +1 -1
  102. package/dist/cli/{chunk-VRYX2BR4.js → chunk-NR5PLMNG.js} +107 -107
  103. package/dist/cli/{chunk-JMHYDDBQ.js → chunk-Q4HNK7JX.js} +292 -279
  104. package/dist/cli/{chunk-37AZHCTP.mjs → chunk-RULRGMMM.mjs} +5 -5
  105. package/dist/cli/{chunk-GI3V4D7K.mjs → chunk-SDAP5MCO.mjs} +2 -2
  106. package/dist/cli/{chunk-5EOEJKSV.js → chunk-TZBCJHV6.js} +1 -1
  107. package/dist/cli/{chunk-3PMCQ3LK.js → chunk-V7DEGIYO.js} +7 -5
  108. package/dist/cli/{chunk-ALHKB3AE.js → chunk-VK5UTS5B.js} +9 -9
  109. package/dist/cli/{chunk-ZFSB7GXF.js → chunk-W32KT6LM.js} +5 -5
  110. package/dist/cli/{chunk-6BBGUQJJ.js → chunk-XTYHZEJ2.js} +8 -0
  111. package/dist/cli/{chunk-UGA5KI4A.js → chunk-XZBXQCRJ.js} +22 -22
  112. package/dist/cli/{chunk-BRRCWUOW.mjs → chunk-Y66ZMOJI.mjs} +1 -1
  113. package/dist/cli/{chunk-CFND2ACL.js → chunk-YMQFQO3K.js} +16 -16
  114. package/dist/cli/command-docs.js +2 -2
  115. package/dist/cli/command-docs.mjs +1 -1
  116. package/dist/cli/{csv-JITYN27L.js → csv-BWWJYV2C.js} +13 -13
  117. package/dist/cli/{csv-HZP6QMG7.mjs → csv-G5RQQ74W.mjs} +4 -4
  118. package/dist/cli/{db-FYSRB7O4.js → db-5KNDLADE.js} +27 -27
  119. package/dist/cli/{db-QRIRTOMM.mjs → db-AJZHWB3V.mjs} +6 -6
  120. package/dist/cli/describe-B6CN6CFJ.js +49 -0
  121. package/dist/cli/{describe-REXJVJC3.mjs → describe-QY5TKWVD.mjs} +17 -17
  122. package/dist/cli/describe-core.d.mts +3 -3
  123. package/dist/cli/describe-core.d.ts +3 -3
  124. package/dist/cli/{executions-BSTF4DDS.js → executions-BCCW76BI.js} +8 -8
  125. package/dist/cli/{executions-53KJAFOW.mjs → executions-SJPH3MZT.mjs} +6 -6
  126. package/dist/cli/{feedback-6MW3QOXX.js → feedback-GF65JKK6.js} +14 -14
  127. package/dist/cli/{feedback-CWUJJF3J.mjs → feedback-S6SZOFGK.mjs} +6 -6
  128. package/dist/cli/git-DX6NB7VF.js +25 -0
  129. package/dist/cli/{git-CKVZTJFS.mjs → git-F5FT5YVB.mjs} +5 -5
  130. package/dist/cli/index.js +143 -143
  131. package/dist/cli/index.mjs +42 -42
  132. package/dist/cli/{legacy-noops-QBL4PNGB.js → legacy-noops-ECR6FS6U.js} +9 -9
  133. package/dist/cli/{legacy-noops-USTBRFRX.mjs → legacy-noops-NOA4P5NE.mjs} +6 -6
  134. package/dist/cli/{monitors-6UCG5D7W.mjs → monitors-CTYSAGP4.mjs} +7 -7
  135. package/dist/cli/{monitors-VCR6SUZD.js → monitors-DEWBSURN.js} +100 -100
  136. package/dist/cli/{org-GSRBOJVO.mjs → org-EKSKKT7H.mjs} +6 -6
  137. package/dist/cli/{org-HPILTEG4.js → org-ZM2UUMZZ.js} +86 -86
  138. package/dist/cli/{play-TK7WOP5H.js → play-6JQOM6DE.js} +317 -317
  139. package/dist/cli/{play-QRTYQNG4.mjs → play-R2BH374J.mjs} +17 -17
  140. package/dist/cli/{providers-HEXNJ5QC.js → providers-CMIYHEMN.js} +9 -9
  141. package/dist/cli/{providers-OAQJWVBS.mjs → providers-X7WMIWO4.mjs} +6 -6
  142. package/dist/cli/{quickstart-PYZTFXZX.js → quickstart-6HVPAMSW.js} +6 -6
  143. package/dist/cli/{quickstart-FFVHTPSP.mjs → quickstart-ZZ7L6VZJ.mjs} +4 -4
  144. package/dist/cli/{run-HLN6YYZH.mjs → run-FP32RKBU.mjs} +22 -22
  145. package/dist/cli/{run-4DWJXJRO.js → run-OOHYH3GI.js} +42 -42
  146. package/dist/cli/search-34C6LFOJ.js +32 -0
  147. package/dist/cli/{search-ZHRCXGEL.mjs → search-BDDNC23Z.mjs} +7 -7
  148. package/dist/cli/{search-output-2KY6PFDH.js → search-output-5VZIQQAM.js} +6 -6
  149. package/dist/cli/{search-output-N7QXACVK.mjs → search-output-QXJ6CV5G.mjs} +4 -4
  150. package/dist/cli/{secrets-WXQ7XO5C.js → secrets-EN2HQCO3.js} +15 -15
  151. package/dist/cli/{secrets-FKMWBLHU.mjs → secrets-Z7CQSQGC.mjs} +6 -6
  152. package/dist/cli/{sessions-3YDTEDA5.mjs → sessions-I2H37OTJ.mjs} +6 -6
  153. package/dist/cli/sessions-RYQX3NDD.js +22 -0
  154. package/dist/cli/{settings-67TWLQ6E.js → settings-CTRAPFNZ.js} +85 -85
  155. package/dist/cli/{settings-JTPASUZN.mjs → settings-IYSC5PPQ.mjs} +12 -12
  156. package/dist/cli/{setup-VYNGXUJ6.mjs → setup-PU3HOVI3.mjs} +9 -9
  157. package/dist/cli/{setup-KUERQJUX.js → setup-XIN53GEW.js} +49 -49
  158. package/dist/cli/skills-576CX7DK.js +36 -0
  159. package/dist/cli/{skills-KI4KYHH6.mjs → skills-TYBML2ZO.mjs} +7 -7
  160. package/dist/cli/tools-EXMUWA3Z.js +56 -0
  161. package/dist/cli/{tools-UQDJS2RS.mjs → tools-ZVNE6M6J.mjs} +16 -16
  162. package/dist/cli/{update-7FQQUBOD.mjs → update-54WENBNT.mjs} +9 -9
  163. package/dist/cli/update-RAHETNL2.js +34 -0
  164. package/dist/cli/{views-MJK7JGZG.js → views-7L75EZOJ.js} +21 -21
  165. package/dist/cli/{views-JAM4MNNV.mjs → views-EUBB4ONT.mjs} +6 -6
  166. package/dist/cli/{workflow-AQPRIWQX.js → workflow-EZVYCR6Y.js} +17 -17
  167. package/dist/cli/{workflow-TQRV5FGO.mjs → workflow-GUKGFJ72.mjs} +7 -7
  168. package/dist/{client-BlLYQDNo.d.mts → client-D0uDBybG.d.mts} +1 -1
  169. package/dist/{client-DSQlkIDO.d.ts → client-DZTnAv4B.d.ts} +1 -1
  170. package/dist/{client-core-rX7n2H8U.d.mts → client-core-BhWf8Y1b.d.mts} +15 -2
  171. package/dist/{client-core-CDwapXy5.d.ts → client-core-og3AP1LL.d.ts} +15 -2
  172. package/dist/{compiler-manifest-BHNC4RL-.d.ts → compiler-manifest-Bes3OVA3.d.mts} +1 -1
  173. package/dist/{compiler-manifest-BHNC4RL-.d.mts → compiler-manifest-Bes3OVA3.d.ts} +1 -1
  174. package/dist/{errors-lhtIWG5Z.d.ts → errors-BJm4lLWc.d.ts} +1 -1
  175. package/dist/{errors-D7sPXrvB.d.mts → errors-Dc5r42ks.d.mts} +1 -1
  176. package/dist/{index-CQTBHXHr.d.ts → index-BfV7mRPF.d.ts} +1 -1
  177. package/dist/{index-NaDZq2xf.d.mts → index-DTkiz_Ur.d.mts} +1 -1
  178. package/dist/index.d.mts +7 -7
  179. package/dist/index.d.ts +7 -7
  180. package/dist/index.js +9 -9
  181. package/dist/index.mjs +6 -6
  182. package/dist/install-integrity.json +121 -112
  183. package/dist/plays/bundle-play-file.d.mts +3 -3
  184. package/dist/plays/bundle-play-file.d.ts +3 -3
  185. package/dist/plays/play-description.d.mts +2 -2
  186. package/dist/plays/play-description.d.ts +2 -2
  187. package/dist/plays/run-request.d.mts +2 -2
  188. package/dist/plays/run-request.d.ts +2 -2
  189. package/dist/release.d.mts +1 -1
  190. package/dist/release.d.ts +1 -1
  191. package/dist/release.js +2 -2
  192. package/dist/release.mjs +1 -1
  193. package/dist/server.d.mts +4 -4
  194. package/dist/server.d.ts +4 -4
  195. package/dist/server.js +5 -5
  196. package/dist/server.mjs +3 -3
  197. package/package.json +1 -1
  198. package/dist/cli/auth-Y2K2ZYYA.js +0 -43
  199. package/dist/cli/describe-LSOHOLFI.js +0 -49
  200. package/dist/cli/git-S7SWUZ3T.js +0 -25
  201. package/dist/cli/search-WERQBC6V.js +0 -32
  202. package/dist/cli/sessions-LXQ4Q6BS.js +0 -22
  203. package/dist/cli/skills-EFRLHY3F.js +0 -36
  204. package/dist/cli/tools-C3EIGFFP.js +0 -56
  205. package/dist/cli/update-KCY72RXH.js +0 -34
@@ -167,6 +167,9 @@ export type PlayRunLedgerWorkCounters = {
167
167
  providerRequests: number;
168
168
  provider429s: number;
169
169
  final: boolean;
170
+ reusableResultCalls?: number;
171
+ completedReusableResultCalls?: number;
172
+ reuseConsistent?: boolean;
170
173
  completedLogicalCalls: number;
171
174
  completedProviderRequests: number;
172
175
  completedProvider429s: number;
@@ -395,6 +398,7 @@ export type PlayRunLedgerEvent =
395
398
  attempt: number;
396
399
  invocationSeq: number;
397
400
  segmentId: string;
401
+ reusableResultCalls?: number;
398
402
  logicalCalls: number;
399
403
  providerRequests: number;
400
404
  provider429s: number;
@@ -550,6 +554,23 @@ export function hasConfirmedPlayRunLedgerWorkCounters(
550
554
  );
551
555
  }
552
556
 
557
+ /** Verified new retained-result consumers; missing/gapped reports stay unknown. */
558
+ export function confirmedReusableResultCalls(
559
+ snapshot: PlayRunLedgerSnapshot,
560
+ ): number | null {
561
+ const counters = snapshot.workCounters;
562
+ if (
563
+ !hasConfirmedPlayRunLedgerWorkCounters(snapshot) ||
564
+ counters?.reuseConsistent !== true ||
565
+ !nonnegativeSafeInteger(counters.reusableResultCalls) ||
566
+ !nonnegativeSafeInteger(counters.completedReusableResultCalls)
567
+ )
568
+ return null;
569
+ const total =
570
+ counters.reusableResultCalls! + counters.completedReusableResultCalls!;
571
+ return Number.isSafeInteger(total) ? total : null;
572
+ }
573
+
553
574
  function normalizeWorkCounters(
554
575
  value: unknown,
555
576
  ): PlayRunLedgerWorkCounters | undefined {
@@ -621,6 +642,20 @@ function advanceNextWorkCounterSegment(
621
642
  logicalCalls: event.logicalCalls,
622
643
  providerRequests: event.providerRequests,
623
644
  provider429s: event.provider429s,
645
+ reusableResultCalls: nonnegativeSafeInteger(event.reusableResultCalls)
646
+ ? event.reusableResultCalls
647
+ : undefined,
648
+ completedReusableResultCalls:
649
+ nonnegativeSafeInteger(current.completedReusableResultCalls) &&
650
+ nonnegativeSafeInteger(current.reusableResultCalls) &&
651
+ Number.isSafeInteger(
652
+ current.completedReusableResultCalls! + current.reusableResultCalls!,
653
+ )
654
+ ? current.completedReusableResultCalls! + current.reusableResultCalls!
655
+ : undefined,
656
+ reuseConsistent:
657
+ current.reuseConsistent === true &&
658
+ nonnegativeSafeInteger(event.reusableResultCalls),
624
659
  final: event.final === true,
625
660
  completedLogicalCalls: Math.min(
626
661
  completedLogicalCalls,
@@ -667,6 +702,11 @@ function advanceWorkCounters(
667
702
  logicalCalls: event.logicalCalls,
668
703
  providerRequests: event.providerRequests,
669
704
  provider429s: event.provider429s,
705
+ reusableResultCalls: nonnegativeSafeInteger(event.reusableResultCalls)
706
+ ? event.reusableResultCalls
707
+ : undefined,
708
+ completedReusableResultCalls: 0,
709
+ reuseConsistent: nonnegativeSafeInteger(event.reusableResultCalls),
670
710
  final: event.final === true,
671
711
  completedLogicalCalls: 0,
672
712
  completedProviderRequests: 0,
@@ -698,6 +738,20 @@ function advanceWorkCounters(
698
738
  event.providerRequests,
699
739
  ),
700
740
  provider429s: Math.max(current.provider429s, event.provider429s),
741
+ reusableResultCalls: nonnegativeSafeInteger(event.reusableResultCalls)
742
+ ? Math.max(current.reusableResultCalls ?? 0, event.reusableResultCalls!)
743
+ : current.reusableResultCalls,
744
+ reuseConsistent:
745
+ current.reuseConsistent === true &&
746
+ nonnegativeSafeInteger(event.reusableResultCalls) &&
747
+ !(
748
+ event.final &&
749
+ event.reusableResultCalls! < (current.reusableResultCalls ?? 0)
750
+ ) &&
751
+ !(
752
+ current.final &&
753
+ event.reusableResultCalls! > (current.reusableResultCalls ?? 0)
754
+ ),
701
755
  final: current.final || event.final === true,
702
756
  consistent:
703
757
  current.consistent &&
@@ -6,6 +6,7 @@ import {
6
6
  import {
7
7
  LOG_TAIL_LIMIT,
8
8
  hasConfirmedPlayRunLedgerWorkCounters,
9
+ confirmedReusableResultCalls,
9
10
  normalizePlayRunLedgerSnapshot,
10
11
  summarizeRunRowOutcomes,
11
12
  type PlayRunLedgerSnapshot,
@@ -128,6 +129,8 @@ export type PlayRunLiveSnapshot = {
128
129
  providerRequests: number;
129
130
  provider429s: number;
130
131
  confirmed: boolean;
132
+ /** Present only when this metric has complete accepted-terminal evidence. */
133
+ reusableResultCalls?: number;
131
134
  };
132
135
  };
133
136
 
@@ -273,6 +276,7 @@ function buildSnapshotFromLedger(
273
276
  ? terminalRowOutcomes
274
277
  : null;
275
278
  const workCounters = snapshot.workCounters;
279
+ const reusableResultCalls = confirmedReusableResultCalls(snapshot);
276
280
  const calls = workCounters
277
281
  ? {
278
282
  logicalCalls:
@@ -285,6 +289,7 @@ function buildSnapshotFromLedger(
285
289
  confirmed:
286
290
  isTerminalPlayRunLiveStatus(liveStatus) &&
287
291
  hasConfirmedPlayRunLedgerWorkCounters(snapshot),
292
+ ...(reusableResultCalls !== null ? { reusableResultCalls } : {}),
288
293
  }
289
294
  : null;
290
295
  return {
@@ -10,6 +10,11 @@ import {
10
10
  import { createFixtureEgressFetch } from '../fixture-egress-fetch';
11
11
  import { RUN_EVENT_KIND } from '../run-event-catalog';
12
12
  import { hydratePlayRunnerConfig } from '../protocol';
13
+ import { DURABLE_RUNS_ROLLOUT } from '../durable-runs-rollout';
14
+ import {
15
+ readStartupReadToolIds,
16
+ staticPipelineStartupReadToolIds,
17
+ } from '../startup-read-tool-ids';
13
18
  import { appendFileSync, createReadStream, writeFileSync } from 'node:fs';
14
19
  import { readFile } from 'node:fs/promises';
15
20
  import { dirname, isAbsolute, resolve } from 'node:path';
@@ -87,6 +92,10 @@ import {
87
92
  type RunnerProgressPusher,
88
93
  } from './runtime-progress-push';
89
94
  import { collectStartupEgressProbeLines } from './egress-probe';
95
+ import {
96
+ startRelayConnectionCounter,
97
+ type RelayConnectionCounter,
98
+ } from './relay-connection-counter';
90
99
  import {
91
100
  pushRunnerTerminal,
92
101
  runnerTerminalResultForTransport,
@@ -230,6 +239,7 @@ async function safeNodeOutboundFetch(
230
239
 
231
240
  function fixtureCtxFetch(
232
241
  config: Pick<PlayRunnerExecutionConfig, 'context'>,
242
+ envelope: 'fixture' | 'broker' = 'fixture',
233
243
  ): ReturnType<typeof createFixtureEgressFetch> {
234
244
  const baseUrl =
235
245
  config.context.executionGatewayBaseUrl?.trim() || config.context.baseUrl;
@@ -245,6 +255,7 @@ function fixtureCtxFetch(
245
255
  baseUrl,
246
256
  executorToken,
247
257
  extraHeaders: () => vercelBypassHeaders(config),
258
+ envelope,
248
259
  });
249
260
  }
250
261
 
@@ -596,6 +607,91 @@ export class RunnerRuntimeControlRedirectError extends Error {
596
607
  }
597
608
  }
598
609
 
610
+ /**
611
+ * Read-only startup lookups issued during the park fence
612
+ * (`DURABLE_RUNS_ROLLOUT.runnerStartupReadPrefetch`). Keyed by exact URL; a
613
+ * GET for that URL consumes one successful (200) answer once. Anything else,
614
+ * including a failed or non-200 prefetch, falls through to the unchanged
615
+ * request path with its own retries and errors.
616
+ */
617
+ const runnerStartupReadPrefetch = new Map<
618
+ string,
619
+ Promise<{ status: number; headers: [string, string][]; body: string } | null>
620
+ >();
621
+
622
+ export function prefetchRunnerRuntimeControlGet(
623
+ url: string,
624
+ headers: Record<string, string>,
625
+ fetchImpl: typeof fetch = fetch,
626
+ ): void {
627
+ if (runnerStartupReadPrefetch.has(url)) return;
628
+ runnerStartupReadPrefetch.set(
629
+ url,
630
+ fetchImpl(url, {
631
+ method: 'GET',
632
+ headers,
633
+ redirect: 'manual',
634
+ signal: AbortSignal.timeout(RUNNER_RUNTIME_CONTROL_REQUEST_TIMEOUT_MS),
635
+ }).then(
636
+ async (response) =>
637
+ response.status === 200
638
+ ? {
639
+ status: response.status,
640
+ headers: [...response.headers.entries()],
641
+ body: await response.text(),
642
+ }
643
+ : (await response.text().catch(() => ''), null),
644
+ () => null,
645
+ ),
646
+ );
647
+ }
648
+
649
+ async function takeRunnerStartupRead(
650
+ url: string,
651
+ init: RequestInit,
652
+ ): Promise<Response | null> {
653
+ if ((init.method ?? 'GET').toUpperCase() !== 'GET') return null;
654
+ const pending = runnerStartupReadPrefetch.get(url);
655
+ if (!pending) return null;
656
+ runnerStartupReadPrefetch.delete(url);
657
+ const answer = await pending;
658
+ return answer
659
+ ? new Response(answer.body, {
660
+ status: answer.status,
661
+ headers: answer.headers,
662
+ })
663
+ : null;
664
+ }
665
+
666
+ /**
667
+ * Prefetch the read-only metadata and auth-scope lookups for the tools the
668
+ * worker named (`startupReadToolIds`) or, absent that, the static plan names.
669
+ */
670
+ export async function prefetchStaticToolStartupReads(
671
+ config: PlayRunnerExecutionConfig,
672
+ ): Promise<void> {
673
+ const baseUrl = config.context.baseUrl;
674
+ const token = config.context.executorToken;
675
+ const pipeline = config.context.staticPipeline;
676
+ const namedToolIds = readStartupReadToolIds(
677
+ config.context.startupReadToolIds,
678
+ );
679
+ if (!baseUrl || !token || (!pipeline && !namedToolIds)) return;
680
+ const toolIds = new Set(
681
+ namedToolIds ?? staticPipelineStartupReadToolIds(pipeline),
682
+ );
683
+ if (toolIds.size === 0) return;
684
+ const headers = {
685
+ Authorization: `Bearer ${token}`,
686
+ ...(await vercelBypassHeaders(config)),
687
+ };
688
+ for (const id of toolIds) {
689
+ const base = `${baseUrl}/api/v2/plays/runtime-tools/${encodeURIComponent(id)}`;
690
+ prefetchRunnerRuntimeControlGet(base, headers);
691
+ prefetchRunnerRuntimeControlGet(`${base}/auth-scope`, headers);
692
+ }
693
+ }
694
+
599
695
  export async function fetchRunnerRuntimeControl(input: {
600
696
  url: string;
601
697
  init: RequestInit;
@@ -610,6 +706,10 @@ export async function fetchRunnerRuntimeControl(input: {
610
706
  }): Promise<Response> {
611
707
  const fetchImpl = input.fetchImpl ?? fetch;
612
708
  const sleepImpl = input.sleepImpl ?? sleepRunnerRuntimeControlRetry;
709
+ if (!input.fetchImpl) {
710
+ const prefetched = await takeRunnerStartupRead(input.url, input.init);
711
+ if (prefetched) return prefetched;
712
+ }
613
713
  const startedAt = Date.now();
614
714
  // Header/body retries and no-response retries use independent ordinary
615
715
  // budgets. Classified network cuts can also use the bounded outage budget.
@@ -2547,11 +2647,14 @@ async function run(
2547
2647
  scope,
2548
2648
  }),
2549
2649
  // A fixture run answers ctx.fetch from the fixture egress route; it must
2550
- // never reach the network.
2650
+ // never reach the network. A runner without outbound network
2651
+ // (`modal_sidecar`) sends ctx.fetch through its gateway to the broker.
2551
2652
  fetchImpl:
2552
2653
  config.context.integrationMode === 'fixture'
2553
2654
  ? fixtureCtxFetch(config)
2554
- : safeNodeStreamingOutboundFetch,
2655
+ : config.context.egressViaRuntimeBroker === true
2656
+ ? fixtureCtxFetch(config, 'broker')
2657
+ : safeNodeStreamingOutboundFetch,
2555
2658
  vercelProtectionBypassToken: config.context.vercelProtectionBypassToken,
2556
2659
  orgId: config.context.orgId,
2557
2660
  userEmail: config.context.userEmail,
@@ -3068,10 +3171,6 @@ async function run(
3068
3171
  playName,
3069
3172
  tableNamespace,
3070
3173
  sheetContract,
3071
- contractSnapshot: {
3072
- staticPipeline:
3073
- input.staticPipeline ?? config.context.staticPipeline ?? null,
3074
- },
3075
3174
  runId,
3076
3175
  userEmail,
3077
3176
  updates: checkpointUpdates,
@@ -4171,6 +4270,9 @@ export async function materializeTransportedArtifact(
4171
4270
 
4172
4271
  async function main() {
4173
4272
  const runnerPhaseTimingsMs: RunnerPhaseTimingsMs = {};
4273
+ if (DURABLE_RUNS_ROLLOUT.runnerTerminalDiagnostics) {
4274
+ runnerTerminalPhaseTimingsMs = runnerPhaseTimingsMs;
4275
+ }
4174
4276
  const emitStartupRunnerTiming = (line: string) => {
4175
4277
  recordRunnerPhaseTiming(runnerPhaseTimingsMs, line);
4176
4278
  emitWorkerLog(line);
@@ -4206,6 +4308,14 @@ async function main() {
4206
4308
  // artifact materialization can then report its terminal whenever the gateway
4207
4309
  // is reachable instead of relying only on the detached ceiling salvage.
4208
4310
  runnerTerminalPushContext = terminalPushContextFromConfig(parsedConfig);
4311
+ // Internal diagnostic for the terminal push: count relay connections from
4312
+ // the first customer request onward. Never written to customer run logs.
4313
+ runnerRelayConnectionCounter =
4314
+ runnerTerminalPushContext && DURABLE_RUNS_ROLLOUT.runnerTerminalDiagnostics
4315
+ ? startRelayConnectionCounter(
4316
+ parsedConfig.context.executionGatewayBaseUrl ?? null,
4317
+ )
4318
+ : null;
4209
4319
  const executionController = new AbortController();
4210
4320
  const rowAdmissionController = new AbortController();
4211
4321
  let runtimeState:
@@ -4273,7 +4383,8 @@ async function main() {
4273
4383
  let executionError: unknown = undefined;
4274
4384
  try {
4275
4385
  result = await executePlayRunner(config, {
4276
- ...(config.context.runtimeLogIdentity === 'origin'
4386
+ ...(DURABLE_RUNS_ROLLOUT.runnerTerminalDiagnostics ||
4387
+ config.context.runtimeLogIdentity === 'origin'
4277
4388
  ? { runnerPhaseTimingsMs }
4278
4389
  : {}),
4279
4390
  signal: executionController.signal,
@@ -4458,6 +4569,12 @@ export async function materializeTransportedArtifactWhileRunnerParks(
4458
4569
  // The first gateway heartbeat is the durable readiness fence. The worker
4459
4570
  // observes that same Postgres fact directly. It still gates every call to
4460
4571
  // executePlayRunner; only file I/O overlaps the handoff.
4572
+ if (DURABLE_RUNS_ROLLOUT.runnerStartupReadPrefetch) {
4573
+ void materialization.then((outcome) => {
4574
+ if ('config' in outcome)
4575
+ void prefetchStaticToolStartupReads(outcome.config);
4576
+ });
4577
+ }
4461
4578
  await heartbeat?.firstHeartbeat;
4462
4579
  await waitForRunnerExecutionAcknowledgement(heartbeat);
4463
4580
 
@@ -4529,6 +4646,13 @@ export function writeRunnerStartupDiagnostic(
4529
4646
  }
4530
4647
  }
4531
4648
 
4649
+ /** Phase timings for the terminal push's internal diagnostic (set in main). */
4650
+ let runnerTerminalPhaseTimingsMs: Readonly<Record<string, number>> | null =
4651
+ null;
4652
+
4653
+ /** Relay connection counter for the terminal push (set once in main). */
4654
+ let runnerRelayConnectionCounter: RelayConnectionCounter | null = null;
4655
+
4532
4656
  /** Terminal push wiring (set once in main after the config loads). */
4533
4657
  let runnerTerminalPushContext: {
4534
4658
  gatewayBaseUrl: string;
@@ -4563,11 +4687,19 @@ async function pushRunnerTerminalIfConfigured(
4563
4687
  ): Promise<void> {
4564
4688
  const context = runnerTerminalPushContext;
4565
4689
  if (!context) return;
4690
+ const relayConnectionsOpened = runnerRelayConnectionCounter?.read() ?? null;
4566
4691
  await pushRunnerTerminal({
4567
4692
  gatewayBaseUrl: context.gatewayBaseUrl,
4568
4693
  executorToken: context.executorToken,
4569
4694
  runId: context.runId,
4570
4695
  result,
4696
+ ...(relayConnectionsOpened !== null ? { relayConnectionsOpened } : {}),
4697
+ ...(runnerTerminalPhaseTimingsMs
4698
+ ? { runnerPhaseTimingsMs: runnerTerminalPhaseTimingsMs }
4699
+ : {}),
4700
+ ...(DURABLE_RUNS_ROLLOUT.runnerTerminalDiagnostics
4701
+ ? { runnerProcessStartedAtMs: performance.timeOrigin }
4702
+ : {}),
4571
4703
  runtimeCompletedPath:
4572
4704
  process.env.DEEPLINE_PLAY_RUNNER_RUNTIME_COMPLETED_PATH,
4573
4705
  ...options,
@@ -4614,12 +4746,28 @@ function startRunnerPushHeartbeatFromConfig(
4614
4746
  if (!push || !gatewayBaseUrl || !executorToken) {
4615
4747
  return null;
4616
4748
  }
4749
+ const executionGatewayBaseUrl =
4750
+ config.context.executionGatewayBaseUrl?.trim();
4617
4751
  return startRunnerHeartbeatLoop({
4618
4752
  gatewayBaseUrl,
4619
4753
  executorToken,
4620
4754
  runId: push.runId,
4621
4755
  leaseSeconds: push.leaseSeconds,
4622
4756
  waitForSchedulerPark: true,
4757
+ // The supervisor sidecar starts beside the runner; wait for both roles.
4758
+ ...(config.context.awaitRuntimeSupervisor === true
4759
+ ? {
4760
+ awaitGatewayListening: {
4761
+ urls: [
4762
+ gatewayBaseUrl,
4763
+ ...(executionGatewayBaseUrl ? [executionGatewayBaseUrl] : []),
4764
+ ],
4765
+ deadlineMs: 30_000,
4766
+ probeTimeoutMs:
4767
+ config.context.runtimeSupervisorProbeTimeoutMs ?? 100,
4768
+ },
4769
+ }
4770
+ : {}),
4623
4771
  onSelfTerminate: (stop) => {
4624
4772
  onSelfTerminate?.(stop);
4625
4773
  void terminateRunnerForHeartbeatStop(stop);
@@ -0,0 +1,103 @@
1
+ import * as diagnosticsChannel from 'node:diagnostics_channel';
2
+
3
+ /**
4
+ * Counts the TCP/TLS connections the runner opens to its execution relay, from
5
+ * undici's `undici:client:connected` diagnostics channel (the same source the
6
+ * opt-in egress probe uses). The total travels as the optional internal
7
+ * `relayConnectionsOpened` scalar on the terminal push, where the gateway's
8
+ * internal lifecycle line records it. It never reaches customer run logs.
9
+ *
10
+ * Diagnostics only: a counter that cannot subscribe reports `null`, and no
11
+ * failure here may affect the run.
12
+ */
13
+ export type RelayConnectionCounter = {
14
+ /** Connections opened to the relay so far, or null when unobservable. */
15
+ read: () => number | null;
16
+ stop: () => void;
17
+ };
18
+
19
+ type UndiciConnectedMessage = {
20
+ connectParams?: {
21
+ protocol?: unknown;
22
+ hostname?: unknown;
23
+ host?: unknown;
24
+ port?: unknown;
25
+ };
26
+ };
27
+
28
+ function defaultPort(protocol: string): string {
29
+ return protocol === 'http:' ? '80' : protocol === 'https:' ? '443' : '';
30
+ }
31
+
32
+ function relayOrigin(
33
+ baseUrl: string,
34
+ ): { protocol: string; hostname: string; port: string } | null {
35
+ try {
36
+ const url = new URL(baseUrl);
37
+ return {
38
+ protocol: url.protocol,
39
+ hostname: url.hostname.toLowerCase(),
40
+ port: url.port || defaultPort(url.protocol),
41
+ };
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ /** True when an undici connect message names the relay's origin. */
48
+ export function undiciConnectionTargetsOrigin(
49
+ message: unknown,
50
+ origin: { protocol: string; hostname: string; port: string },
51
+ ): boolean {
52
+ const params = (message as UndiciConnectedMessage | null)?.connectParams;
53
+ if (!params || typeof params !== 'object') return false;
54
+ const protocol = typeof params.protocol === 'string' ? params.protocol : '';
55
+ if (protocol !== origin.protocol) return false;
56
+ const hostname =
57
+ typeof params.hostname === 'string'
58
+ ? params.hostname
59
+ : typeof params.host === 'string'
60
+ ? params.host.replace(/:\d+$/, '')
61
+ : '';
62
+ if (hostname.toLowerCase() !== origin.hostname) return false;
63
+ const rawPort =
64
+ typeof params.port === 'string' || typeof params.port === 'number'
65
+ ? String(params.port)
66
+ : '';
67
+ return (rawPort || defaultPort(protocol)) === origin.port;
68
+ }
69
+
70
+ export function startRelayConnectionCounter(
71
+ relayBaseUrl: string | null | undefined,
72
+ ): RelayConnectionCounter | null {
73
+ const trimmed = relayBaseUrl?.trim();
74
+ if (!trimmed) return null;
75
+ const origin = relayOrigin(trimmed);
76
+ if (!origin) return null;
77
+ let connections = 0;
78
+ const onConnect = (message: unknown) => {
79
+ try {
80
+ if (undiciConnectionTargetsOrigin(message, origin)) connections += 1;
81
+ } catch {
82
+ // Diagnostics must not affect a customer run.
83
+ }
84
+ };
85
+ try {
86
+ diagnosticsChannel.subscribe('undici:client:connected', onConnect);
87
+ } catch {
88
+ return null;
89
+ }
90
+ let live = true;
91
+ return {
92
+ read: () => connections,
93
+ stop: () => {
94
+ if (!live) return;
95
+ live = false;
96
+ try {
97
+ diagnosticsChannel.unsubscribe('undici:client:connected', onConnect);
98
+ } catch {
99
+ // Diagnostics teardown must not affect a customer run.
100
+ }
101
+ },
102
+ };
103
+ }
@@ -1,4 +1,5 @@
1
1
  import { RUNTIME_CLAIM_HEARTBEAT_DIVISOR } from '../runtime-constants';
2
+ import { DURABLE_RUNS_ROLLOUT } from '../durable-runs-rollout';
2
3
  import { PLAY_RUNTIME_TRANSPORT_ATTEMPT_HEADER } from '../runtime-contract';
3
4
  import {
4
5
  createRunnerGatewayTransportAttemptId,
@@ -61,6 +62,17 @@ export interface RunnerHeartbeatLoopOptions {
61
62
  leaseSeconds: number;
62
63
  /** Keep managed startup heartbeats active until the scheduler parks the attempt. */
63
64
  waitForSchedulerPark?: boolean;
65
+ /**
66
+ * Sandbox-local gateway origins (the `modal_sidecar` supervisor) that may
67
+ * still be starting when the runner starts. The first heartbeat waits until
68
+ * each answers any HTTP request, polling every 10 ms up to the deadline,
69
+ * then the loop runs exactly as without it. Absent: start immediately.
70
+ */
71
+ awaitGatewayListening?: {
72
+ urls: string[];
73
+ deadlineMs: number;
74
+ probeTimeoutMs?: number;
75
+ };
64
76
  /**
65
77
  * Invoked once when the loop decides the runner must self-terminate (terminal
66
78
  * cancellation channel, or gateway unreachable past the lease window). The
@@ -74,6 +86,8 @@ export interface RunnerHeartbeatLoopOptions {
74
86
  runId: string;
75
87
  leaseSeconds: number;
76
88
  attempt?: number;
89
+ /** Optional park-ack long-poll bound (runnerParkAckLongPoll). */
90
+ awaitSchedulerWaitingMs?: number;
77
91
  }) => Promise<RunnerHeartbeatResponse>;
78
92
  /** Injectable timer for tests. Defaults to setInterval. */
79
93
  setIntervalImpl?: (fn: () => void, ms: number) => { unref?: () => void };
@@ -112,6 +126,8 @@ export const RUNNER_HEARTBEAT_REQUEST_TIMEOUT_MS = 10_000;
112
126
  // Retry initial transport failures while customer execution remains fenced.
113
127
  const RUNNER_STARTUP_HEARTBEAT_INTERVAL_MS = 1_000;
114
128
  const RUNNER_PARK_ACK_INTERVAL_MS = 100;
129
+ /** Park-ack long-poll bound requested from the gateway (runnerParkAckLongPoll). */
130
+ const RUNNER_PARK_ACK_LONG_POLL_REQUEST_MS = 500;
115
131
  const RUNNER_PARK_ACK_FAST_WINDOW_MS = 1_000;
116
132
 
117
133
  export async function sendRunnerHeartbeat(
@@ -121,6 +137,7 @@ export async function sendRunnerHeartbeat(
121
137
  runId: string;
122
138
  leaseSeconds: number;
123
139
  attempt?: number;
140
+ awaitSchedulerWaitingMs?: number;
124
141
  },
125
142
  options: {
126
143
  fetchImpl?: typeof fetch;
@@ -174,6 +191,9 @@ export async function sendRunnerHeartbeat(
174
191
  body: JSON.stringify({
175
192
  action: 'runner_heartbeat',
176
193
  runId: input.runId,
194
+ ...(input.awaitSchedulerWaitingMs
195
+ ? { awaitSchedulerWaitingMs: input.awaitSchedulerWaitingMs }
196
+ : {}),
177
197
  }),
178
198
  redirect: 'manual',
179
199
  signal: controller.signal,
@@ -269,6 +289,34 @@ export async function sendRunnerHeartbeat(
269
289
  }
270
290
  }
271
291
 
292
+ /**
293
+ * Resolve once every origin answers any HTTP response, or at the deadline
294
+ * (then the ordinary loop surfaces the failure). Each probe gives up after
295
+ * 100 ms, so a connect that hangs while the sandbox network comes up costs
296
+ * one short probe, not a second. The pending timer keeps the process alive
297
+ * while waiting.
298
+ */
299
+ async function awaitGatewaysListening(
300
+ input: { urls: string[]; deadlineMs: number; probeTimeoutMs?: number },
301
+ now: () => number,
302
+ ): Promise<number> {
303
+ const startedAt = now();
304
+ for (const url of input.urls) {
305
+ for (;;) {
306
+ try {
307
+ await fetch(`${url.replace(/\/$/, '')}/healthz`, {
308
+ signal: AbortSignal.timeout(input.probeTimeoutMs ?? 100),
309
+ });
310
+ break;
311
+ } catch {
312
+ if (now() - startedAt > input.deadlineMs) return now() - startedAt;
313
+ await new Promise((resolve) => setTimeout(resolve, 10));
314
+ }
315
+ }
316
+ }
317
+ return now() - startedAt;
318
+ }
319
+
272
320
  export function startRunnerHeartbeatLoop(
273
321
  options: RunnerHeartbeatLoopOptions,
274
322
  ): RunnerHeartbeatLoopHandle {
@@ -315,6 +363,7 @@ export function startRunnerHeartbeatLoop(
315
363
  runId: string;
316
364
  leaseSeconds: number;
317
365
  attempt?: number;
366
+ awaitSchedulerWaitingMs?: number;
318
367
  }) => sendRunnerHeartbeat(input, { onTransport }));
319
368
 
320
369
  const leaseMs = Math.max(1_000, Math.floor(options.leaseSeconds * 1_000));
@@ -373,6 +422,13 @@ export function startRunnerHeartbeatLoop(
373
422
  runId: options.runId,
374
423
  leaseSeconds: options.leaseSeconds,
375
424
  attempt: heartbeatAttempt,
425
+ // Optional, switch off: while still fenced, ask the gateway to hold the
426
+ // answer until the scheduler reports the durable park (bounded).
427
+ ...(DURABLE_RUNS_ROLLOUT.runnerParkAckLongPoll &&
428
+ options.waitForSchedulerPark &&
429
+ resolveExecutionAcknowledged
430
+ ? { awaitSchedulerWaitingMs: RUNNER_PARK_ACK_LONG_POLL_REQUEST_MS }
431
+ : {}),
376
432
  })
377
433
  .finally(() => {
378
434
  // A caller may request the park acknowledgement as soon as the first
@@ -435,12 +491,25 @@ export function startRunnerHeartbeatLoop(
435
491
  });
436
492
  };
437
493
 
438
- // Keep this timer referenced until the first accepted heartbeat: a pending
439
- // Promise alone does not keep Node alive after an initial transport failure.
440
- setCadence(intervalMs);
441
- // Fire one immediately so a cancel that landed before the first interval is
442
- // observed within a cadence, not a full lease window.
443
- tick();
494
+ const startLoop = () => {
495
+ if (stopped) return;
496
+ // Keep this timer referenced until the first accepted heartbeat: a pending
497
+ // Promise alone does not keep Node alive after an initial transport failure.
498
+ setCadence(intervalMs);
499
+ // Fire one immediately so a cancel that landed before the first interval is
500
+ // observed within a cadence, not a full lease window.
501
+ tick();
502
+ };
503
+ if (options.awaitGatewayListening?.urls.length) {
504
+ void awaitGatewaysListening(options.awaitGatewayListening, now).then(
505
+ (waitedMs) => {
506
+ warn('gateway_listening', { runId: options.runId, waitedMs });
507
+ startLoop();
508
+ },
509
+ );
510
+ } else {
511
+ startLoop();
512
+ }
444
513
 
445
514
  return {
446
515
  stop: stopLoop,