deepline 0.3.545 → 0.3.547

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 (222) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +13 -0
  2. package/dist/bundling-sources/sdk/src/errors.ts +1 -1
  3. package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
  4. package/dist/bundling-sources/sdk/src/index.ts +7 -1
  5. package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
  6. package/dist/bundling-sources/sdk/src/play.ts +71 -0
  7. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
  9. package/dist/bundling-sources/sdk/src/types.ts +33 -0
  10. package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
  11. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
  12. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
  13. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +21 -3
  14. package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
  15. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
  16. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
  18. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +299 -52
  19. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +18 -1
  20. package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
  24. package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +40 -3
  26. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
  31. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
  32. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
  33. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
  34. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +53 -2
  35. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
  36. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +11 -3
  39. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +30 -2
  40. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
  41. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
  42. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +36 -2
  43. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
  44. package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
  45. package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
  46. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
  47. package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
  48. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
  49. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +41 -2
  50. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
  51. package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
  52. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +35 -1
  53. package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
  54. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +58 -0
  55. package/dist/cli/auth-AC5277PI.js +43 -0
  56. package/dist/cli/{auth-VZAMAMFW.mjs → auth-WJEY4IDX.mjs} +6 -6
  57. package/dist/cli/{billing-ASZJDFH2.js → billing-IJITDDRQ.js} +99 -99
  58. package/dist/cli/{billing-DADQUQEZ.mjs → billing-PHJUDYF3.mjs} +11 -11
  59. package/dist/cli/{chunk-FB7UPZ6M.js → chunk-2AHY47SI.js} +3 -3
  60. package/dist/cli/{chunk-CJ7DBYEQ.js → chunk-2HPTLBNB.js} +8 -8
  61. package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
  62. package/dist/cli/{chunk-LTCEZWPZ.mjs → chunk-56MEAGWA.mjs} +2 -2
  63. package/dist/cli/{chunk-YWTRCKGD.mjs → chunk-5SFHPMBY.mjs} +11 -11
  64. package/dist/cli/{chunk-D3SXB2NX.js → chunk-ABLTVG3J.js} +41 -41
  65. package/dist/cli/{chunk-KRW727W6.mjs → chunk-AEQ5VWZ5.mjs} +4 -4
  66. package/dist/cli/{chunk-Z7QM244Q.mjs → chunk-CKIRKYW7.mjs} +3 -3
  67. package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
  68. package/dist/cli/{chunk-OGQYAJSO.js → chunk-D6OIEH47.js} +5 -5
  69. package/dist/cli/{chunk-2HFSYH7V.mjs → chunk-DIUNDLSX.mjs} +2 -2
  70. package/dist/cli/{chunk-3M2QH3KA.mjs → chunk-DJI5CLLW.mjs} +22 -12
  71. package/dist/cli/{chunk-N4LADLCO.js → chunk-DZC7LMYM.js} +6 -6
  72. package/dist/cli/{chunk-CXETRZ3G.js → chunk-E2OIYPB4.js} +10 -10
  73. package/dist/cli/{chunk-Z4Y4BLW7.mjs → chunk-ECUD4QPD.mjs} +3 -3
  74. package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
  75. package/dist/cli/{chunk-NAN3A4IF.mjs → chunk-ESCVHDNY.mjs} +5 -5
  76. package/dist/cli/{chunk-C6XYSTBW.js → chunk-FFBXLFKV.js} +1 -1
  77. package/dist/cli/{chunk-HLUNTJBO.mjs → chunk-FMQXAOVE.mjs} +4 -4
  78. package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
  79. package/dist/cli/{chunk-4NZ3OZNO.mjs → chunk-G6KW764N.mjs} +1 -1
  80. package/dist/cli/{chunk-LWPFMYSO.mjs → chunk-G6XTCG3J.mjs} +2 -2
  81. package/dist/cli/{chunk-NCX2JH2F.js → chunk-GIGAYLY6.js} +12 -12
  82. package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
  83. package/dist/cli/{chunk-G5TV6WLV.js → chunk-GJOGFWX3.js} +20 -20
  84. package/dist/cli/{chunk-7MFATEUC.mjs → chunk-GPAWLXW3.mjs} +2 -2
  85. package/dist/cli/{chunk-DZTVDL2X.js → chunk-GZFZZQL4.js} +289 -268
  86. package/dist/cli/{chunk-XBYQZEUE.mjs → chunk-HARZ4AAX.mjs} +1 -1
  87. package/dist/cli/{chunk-QI57XUGA.js → chunk-HFIFKP3A.js} +5 -5
  88. package/dist/cli/{chunk-WP36UBRY.mjs → chunk-IGAK22XO.mjs} +1 -1
  89. package/dist/cli/{chunk-XMUPZINS.mjs → chunk-IKYN6PLO.mjs} +5 -5
  90. package/dist/cli/{chunk-HPX7LLAM.mjs → chunk-ITLZBDSR.mjs} +3 -3
  91. package/dist/cli/{chunk-QM7PHHYZ.js → chunk-IVFFCAV2.js} +44 -44
  92. package/dist/cli/{chunk-IYJO3RWR.js → chunk-K3GMDSUX.js} +5 -5
  93. package/dist/cli/{chunk-EK5C2R7S.js → chunk-L5J6UJ2X.js} +15 -15
  94. package/dist/cli/{chunk-EWA3M54M.mjs → chunk-L6QE2XVM.mjs} +1 -1
  95. package/dist/cli/{chunk-3NG43NXB.js → chunk-LMLSOHTU.js} +53 -53
  96. package/dist/cli/{chunk-7MHBJU73.js → chunk-MBQELFL7.js} +22 -22
  97. package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
  98. package/dist/cli/{chunk-DGKDCZGC.js → chunk-MO7TGNXB.js} +13 -13
  99. package/dist/cli/{chunk-7P72EGLK.mjs → chunk-MOZEAGSR.mjs} +1 -1
  100. package/dist/cli/{chunk-34UKDHRL.js → chunk-N63U5CRG.js} +26 -26
  101. package/dist/cli/{chunk-5YYWZ43J.js → chunk-NBYFQZ6O.js} +2 -2
  102. package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
  103. package/dist/cli/{chunk-TQKHXMV3.js → chunk-OVYXYTEP.js} +16 -16
  104. package/dist/cli/{chunk-XGEUPU3L.mjs → chunk-PBMO36BP.mjs} +2 -2
  105. package/dist/cli/{chunk-4JQEAYN3.js → chunk-PVQCX6KQ.js} +55 -8
  106. package/dist/cli/{chunk-KYO2FICL.mjs → chunk-QLE3QKJ2.mjs} +5 -5
  107. package/dist/cli/{chunk-2FF3O2Y2.js → chunk-QU3K3IY6.js} +12 -12
  108. package/dist/cli/{chunk-HR5BT42R.js → chunk-REAFIEV5.js} +99 -99
  109. package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-RMCCB3XY.mjs} +55 -8
  110. package/dist/cli/{chunk-3TCHX7YK.mjs → chunk-RXRC2COC.mjs} +2 -2
  111. package/dist/cli/{chunk-YRQKRQDU.js → chunk-SAJWYN4B.js} +36 -26
  112. package/dist/cli/{chunk-JL5JU3LD.mjs → chunk-TNJG4ZPN.mjs} +3 -3
  113. package/dist/cli/{chunk-NZDZGK35.js → chunk-VNOQEDVC.js} +7 -7
  114. package/dist/cli/{chunk-2CBX43LP.mjs → chunk-VPF54TXQ.mjs} +5 -5
  115. package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
  116. package/dist/cli/{chunk-GWDPNOA7.mjs → chunk-XMBVHJPR.mjs} +29 -8
  117. package/dist/cli/{chunk-52C6W7FG.mjs → chunk-XNTDTAKC.mjs} +1 -1
  118. package/dist/cli/{chunk-ERLW6RPA.js → chunk-YURGAKI3.js} +2 -2
  119. package/dist/cli/{chunk-GFRJU2KB.js → chunk-YVKLF7RW.js} +2 -2
  120. package/dist/cli/{chunk-7JZ27AFH.mjs → chunk-Z2YGQZWV.mjs} +2 -2
  121. package/dist/cli/command-docs.js +2 -2
  122. package/dist/cli/command-docs.mjs +1 -1
  123. package/dist/cli/{concurrent-runs-help-YP7ALTDB.mjs → concurrent-runs-help-ZNGP563R.mjs} +7 -7
  124. package/dist/cli/concurrent-runs-help-ZYISYOQA.js +21 -0
  125. package/dist/cli/{csv-D5ITFSYI.mjs → csv-VAHQHYYV.mjs} +5 -5
  126. package/dist/cli/{csv-67WT5EGR.js → csv-X6D4ZELE.js} +14 -14
  127. package/dist/cli/{db-SZYBRFYG.mjs → db-4G4S2VOV.mjs} +8 -8
  128. package/dist/cli/{db-GZS76X7R.js → db-YA5ZGVEX.js} +33 -33
  129. package/dist/cli/{describe-YJ7ZLLLI.mjs → describe-EVXEM2S6.mjs} +20 -20
  130. package/dist/cli/describe-GYYSLZLV.js +50 -0
  131. package/dist/cli/describe-core.d.mts +4 -4
  132. package/dist/cli/describe-core.d.ts +4 -4
  133. package/dist/cli/describe-core.js +1 -1
  134. package/dist/cli/describe-core.mjs +1 -1
  135. package/dist/cli/{executions-O5USTYGL.js → executions-5YC7ABF6.js} +10 -10
  136. package/dist/cli/{executions-HMYGR32E.mjs → executions-HR6CTN5M.mjs} +8 -8
  137. package/dist/cli/{feedback-Z3NXWYUO.mjs → feedback-GEU5SPLR.mjs} +7 -7
  138. package/dist/cli/{feedback-RHLFDCRS.js → feedback-MJHSYLFF.js} +15 -15
  139. package/dist/cli/git-FZIQZNI4.js +25 -0
  140. package/dist/cli/{git-CLFKXELB.mjs → git-NPFF6QUS.mjs} +6 -6
  141. package/dist/cli/index.js +150 -150
  142. package/dist/cli/index.mjs +46 -46
  143. package/dist/cli/{integrations-TZ4QEQGV.js → integrations-YPHFI77G.js} +20 -18
  144. package/dist/cli/{integrations-FOACOBQB.mjs → integrations-Z7EGVBHF.mjs} +12 -10
  145. package/dist/cli/{legacy-noops-QRDOS33V.js → legacy-noops-246E3KKG.js} +10 -10
  146. package/dist/cli/{legacy-noops-6F6Y3BV7.mjs → legacy-noops-5IYCFWWX.mjs} +7 -7
  147. package/dist/cli/{mcp-UXRCWOZU.mjs → mcp-WUYGZXPI.mjs} +5 -5
  148. package/dist/cli/{mcp-ETMMDDGB.js → mcp-YTYTW67G.js} +25 -25
  149. package/dist/cli/{monitors-6XEWR46R.mjs → monitors-73DQKCU7.mjs} +27 -9
  150. package/dist/cli/{monitors-DITT7QTV.js → monitors-SA6ILD6Z.js} +121 -103
  151. package/dist/cli/{org-CVSSH73G.mjs → org-WVQRB2KX.mjs} +8 -8
  152. package/dist/cli/{org-4DE37X3L.js → org-X7ELDV7B.js} +90 -90
  153. package/dist/cli/{play-Y5NCHOKK.mjs → play-QI6V2EUQ.mjs} +296 -68
  154. package/dist/cli/{play-RH6P45CI.js → play-QTYOAJPE.js} +898 -670
  155. package/dist/cli/{providers-VHUHC4IZ.mjs → providers-DPVMVDS4.mjs} +8 -8
  156. package/dist/cli/{providers-DU42DLOL.js → providers-XXFLVREV.js} +11 -11
  157. package/dist/cli/{quickstart-XJ43JLEC.js → quickstart-33ISXQJU.js} +7 -7
  158. package/dist/cli/{quickstart-HJY5YYE5.mjs → quickstart-YWGNHULM.mjs} +5 -5
  159. package/dist/cli/{run-JXUS7QFI.js → run-BWHZXLTD.js} +46 -46
  160. package/dist/cli/{run-JAIXHVH7.mjs → run-J6FCAKQC.mjs} +26 -26
  161. package/dist/cli/search-JCWJX2XD.js +32 -0
  162. package/dist/cli/{search-RDMNM2AX.mjs → search-Z3UU3WBB.mjs} +9 -9
  163. package/dist/cli/{search-output-ZKTR3WTJ.mjs → search-output-OJYY4J7E.mjs} +5 -5
  164. package/dist/cli/{search-output-RKAM2HBH.js → search-output-YIPV74ME.js} +7 -7
  165. package/dist/cli/{secrets-TKFVMAYX.js → secrets-UXRJCEN4.js} +17 -17
  166. package/dist/cli/{secrets-WSW3FTF6.mjs → secrets-YZZN2WST.mjs} +8 -8
  167. package/dist/cli/{sessions-724BK6VP.mjs → sessions-ITCGPD7Z.mjs} +7 -7
  168. package/dist/cli/sessions-NA4SJH6Q.js +22 -0
  169. package/dist/cli/{settings-5LJZDAZU.js → settings-LAFYMILP.js} +87 -87
  170. package/dist/cli/{settings-YRC7J75G.mjs → settings-ZP2LSVNM.mjs} +14 -14
  171. package/dist/cli/{setup-2F3DBSOS.js → setup-4AL3XYM5.js} +50 -50
  172. package/dist/cli/{setup-STNPX5MK.mjs → setup-WEQAQSYC.mjs} +10 -10
  173. package/dist/cli/{skills-D5PK56FO.mjs → skills-NQH4HFW2.mjs} +8 -8
  174. package/dist/cli/skills-XZ4Y6SZ7.js +36 -0
  175. package/dist/cli/{tools-WOGWMBA3.mjs → tools-CXK2GSI4.mjs} +19 -19
  176. package/dist/cli/tools-WJQ6Y7E4.js +57 -0
  177. package/dist/cli/{update-PC6XSWMI.mjs → update-3ROF3Z75.mjs} +10 -10
  178. package/dist/cli/update-ZLRLTBRD.js +34 -0
  179. package/dist/cli/{views-IIHT4RYQ.mjs → views-AOUHVGV2.mjs} +8 -8
  180. package/dist/cli/{views-HLCLAPWN.js → views-XJFO5CEH.js} +23 -23
  181. package/dist/cli/{workflow-CCZ2A7DI.js → workflow-GY3DBHXX.js} +19 -19
  182. package/dist/cli/{workflow-HK4MZ7LK.mjs → workflow-KBS2QJK6.mjs} +9 -9
  183. package/dist/{client-DfdUc_MY.d.mts → client-D1uWA2Vc.d.mts} +1 -1
  184. package/dist/{client-BQ6yuSjM.d.ts → client-Hz7SsBXs.d.ts} +1 -1
  185. package/dist/{client-core-3GQ8WMuk.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
  186. package/dist/{client-core-ClsNRytk.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
  187. package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-BqwVrOri.d.mts} +73 -18
  188. package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-BqwVrOri.d.ts} +73 -18
  189. package/dist/{errors-Lm9_vJHZ.d.ts → errors-BU8FB99X.d.mts} +2 -2
  190. package/dist/{errors-CwKXXtuu.d.mts → errors-DfVN_FUG.d.ts} +2 -2
  191. package/dist/{index-3vJ-V9yw.d.ts → index-BGnvtYGc.d.ts} +6 -1
  192. package/dist/{index-DjwsAt82.d.mts → index-DjZgwpGw.d.mts} +6 -1
  193. package/dist/index.d.mts +28 -8
  194. package/dist/index.d.ts +28 -8
  195. package/dist/index.js +65 -40
  196. package/dist/index.mjs +33 -8
  197. package/dist/install-integrity.json +137 -130
  198. package/dist/plays/bundle-play-file.d.mts +3 -3
  199. package/dist/plays/bundle-play-file.d.ts +3 -3
  200. package/dist/plays/bundle-play-file.mjs +640 -125
  201. package/dist/plays/play-description.d.mts +3 -3
  202. package/dist/plays/play-description.d.ts +3 -3
  203. package/dist/plays/run-request.d.mts +2 -2
  204. package/dist/plays/run-request.d.ts +2 -2
  205. package/dist/release.d.mts +1 -1
  206. package/dist/release.d.ts +1 -1
  207. package/dist/release.js +2 -2
  208. package/dist/release.mjs +1 -1
  209. package/dist/server.d.mts +4 -4
  210. package/dist/server.d.ts +4 -4
  211. package/dist/server.js +11 -11
  212. package/dist/server.mjs +5 -5
  213. package/package.json +1 -1
  214. package/dist/cli/auth-455MB4K6.js +0 -43
  215. package/dist/cli/concurrent-runs-help-GFWXOKF5.js +0 -21
  216. package/dist/cli/describe-ZRGYAEBT.js +0 -50
  217. package/dist/cli/git-RC4XDATD.js +0 -25
  218. package/dist/cli/search-O5VVMXII.js +0 -32
  219. package/dist/cli/sessions-3PWFWCHO.js +0 -22
  220. package/dist/cli/skills-RFOMVXIT.js +0 -36
  221. package/dist/cli/tools-CAO6EVUW.js +0 -57
  222. package/dist/cli/update-L4DQZY3G.js +0 -34
@@ -273,9 +273,11 @@ export type PlaySchedulerSubmitInput = RetainedPipelineCarrier & {
273
273
  experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
274
274
  /**
275
275
  * The runtime speed profile (`runtime-speed-profile.ts`) the run was
276
- * admitted with, such as `fast_launch@1`. Attribution only: its switch map
277
- * is already in `experimentSwitchOverrides`, and no reader branches on this
278
- * id. Absent on every run admitted without a profile.
276
+ * admitted with, such as `fast_launch@1`. Its switch map is already in
277
+ * `experimentSwitchOverrides`, and no reader resolves a switch from this id.
278
+ * The worker relays it to the executor-token route, which accepts the
279
+ * profile's exact frozen map without the experiment-override capability.
280
+ * Absent on every run admitted without a profile.
279
281
  */
280
282
  runtimeSpeedProfile?: string | null;
281
283
  /**
@@ -150,6 +150,7 @@ import { createFleetSandboxSweep } from '../fleet-sandbox-sweep';
150
150
  import {
151
151
  earlySandboxFleetSweepAdapter,
152
152
  earlySandboxSweepAdapters,
153
+ type EarlySandboxWorkerCapacity,
153
154
  } from './early-sandbox-lane';
154
155
  import {
155
156
  resolveDetachedRunnerRuntimeLimitSeconds,
@@ -775,10 +776,23 @@ function isTransientHeartbeatTimeout(error: unknown): boolean {
775
776
  );
776
777
  }
777
778
 
778
- function capacityDeferralSeconds(error: unknown, runId: string): number {
779
+ export function capacityDeferralSeconds(
780
+ error: unknown,
781
+ runId: string,
782
+ generation?: number,
783
+ ): number {
779
784
  if (!isRuntimeSchedulerCapacityError(error)) return 5;
785
+ // A run repeatedly rejected at the workspace cap does not need to claim
786
+ // another generation every 15 seconds. Preserve short retries on young
787
+ // runs and use the existing durable task defer for older generations.
788
+ const workspaceCapFloorSeconds =
789
+ error instanceof RuntimeSandboxCapacityLimitError &&
790
+ generation !== undefined &&
791
+ generation >= 5
792
+ ? 60
793
+ : 1;
780
794
  const baseSeconds = Math.max(
781
- 1,
795
+ workspaceCapFloorSeconds,
782
796
  Math.ceil(runtimeSchedulerCapacityRetryAfterMs(error) / 1_000),
783
797
  );
784
798
  // Keep a saturated fleet from waking every parked run in the same second.
@@ -1388,6 +1402,14 @@ export async function requestAttemptExecutorToken(input: {
1388
1402
  input.launch.experimentSwitchOverrides,
1389
1403
  }
1390
1404
  : {}),
1405
+ // The runtime speed profile those overrides came from, so the
1406
+ // route accepts the profile's exact frozen map without the
1407
+ // experiment-override capability (refused on Production). Optional:
1408
+ // the route also matches an old worker's map without it.
1409
+ ...(input.launch.experimentSwitchOverrides &&
1410
+ input.launch.runtimeSpeedProfile
1411
+ ? { runtimeSpeedProfile: input.launch.runtimeSpeedProfile }
1412
+ : {}),
1391
1413
  // Expand-before-enable rollout fence. An old worker never sends this,
1392
1414
  // so a newly deployed app cannot activate direct terminal reduction
1393
1415
  // before the owning Fly lane has the cleanup controller.
@@ -4112,6 +4134,12 @@ async function executeAbsurdAttemptAdapter(
4112
4134
  options,
4113
4135
  ),
4114
4136
  );
4137
+ if (error instanceof RuntimeSandboxCapacityLimitError) {
4138
+ throw new DeferTask(
4139
+ error.message,
4140
+ capacityDeferralSeconds(error, runId, generation),
4141
+ );
4142
+ }
4115
4143
  throw error;
4116
4144
  }
4117
4145
  await salvageAbsurdFinalAttemptTerminal({
@@ -11522,6 +11550,12 @@ export type RuntimeWorkerHost = {
11522
11550
  id: string;
11523
11551
  startOwnerProbe(): void;
11524
11552
  };
11553
+ /**
11554
+ * E2: the drain and claim-slot state an early-sandbox hint is admitted
11555
+ * against (`startWorkerLaneEarlySandbox`). A draining worker or one with
11556
+ * no idle claim slot refuses the hint.
11557
+ */
11558
+ earlySandboxCapacity?: EarlySandboxWorkerCapacity;
11525
11559
  };
11526
11560
 
11527
11561
  /** Own shutdown ordering across the primary queue, listener and maintenance.
@@ -11532,16 +11566,29 @@ export function createAbsurdRuntimeWorkerHostLifecycle(input: {
11532
11566
  closeWake: () => void;
11533
11567
  wake?: () => boolean;
11534
11568
  earlySandboxClaimOwner?: RuntimeWorkerHost['earlySandboxClaimOwner'];
11569
+ earlySandboxCapacity?: RuntimeWorkerHost['earlySandboxCapacity'];
11535
11570
  stopControllers: () => void;
11536
11571
  controllers: readonly (Promise<unknown> | null)[];
11537
11572
  }): RuntimeWorkerHost {
11538
11573
  let closing: Promise<void> | null = null;
11539
11574
  let wake = input.wake;
11575
+ const capacity = input.earlySandboxCapacity;
11540
11576
  return {
11541
11577
  ...(wake ? { wake: () => wake?.() ?? false } : {}),
11542
11578
  ...(input.earlySandboxClaimOwner
11543
11579
  ? { earlySandboxClaimOwner: input.earlySandboxClaimOwner }
11544
11580
  : {}),
11581
+ // A closing host claims nothing more, so it reports itself draining.
11582
+ ...(capacity
11583
+ ? {
11584
+ earlySandboxCapacity: {
11585
+ get draining() {
11586
+ return closing !== null || capacity.draining;
11587
+ },
11588
+ hasIdleSlot: () => closing === null && capacity.hasIdleSlot(),
11589
+ },
11590
+ }
11591
+ : {}),
11545
11592
  close: () => {
11546
11593
  if (closing) return closing;
11547
11594
  wake = undefined;
@@ -12075,6 +12122,10 @@ export async function startRuntimeWorkerHost(
12075
12122
  worker,
12076
12123
  ...(onWake ? { wake: () => onWake.wake() } : {}),
12077
12124
  ...(earlySandboxClaimOwner ? { earlySandboxClaimOwner } : {}),
12125
+ earlySandboxCapacity: {
12126
+ draining: drainExit,
12127
+ hasIdleSlot: claimLoop.hasIdleSlot,
12128
+ },
12078
12129
  // Release LISTEN before joining accepted work, so a replacement can elect
12079
12130
  // its listener without exhausting primary scheduler sessions.
12080
12131
  closeWake: () => onWake?.close(),
@@ -6,6 +6,8 @@ import { modalEarlySandboxAdapter } from '../runner-backends/backends/modal';
6
6
  import {
7
7
  EARLY_SANDBOX_START,
8
8
  EARLY_SANDBOX_SWEEP_INTERVAL_MS,
9
+ EARLY_SANDBOX_SWEEP_JITTER_RATIO,
10
+ earlySandboxRequiredCapabilities,
9
11
  PREBOOT_RUNNER_IN_EARLY_SANDBOX,
10
12
  startEarlySandbox,
11
13
  type EarlySandboxAdapter,
@@ -15,10 +17,18 @@ import {
15
17
  import { resolveExperimentSwitch } from '../experiment-switches';
16
18
  import type { FleetSandboxSweepAdapter } from '../fleet-sandbox-sweep';
17
19
  import {
20
+ isKnownRuntimeSandboxPlacementPolicyId,
21
+ resolveRuntimeSandboxPlacementPolicy,
22
+ } from '../runtime-sandbox-placement-policy';
23
+ import {
24
+ assertRuntimeSandboxProvidersSupport,
18
25
  runtimeSandboxProviderProfile,
19
26
  type RuntimeSandboxProviderId,
20
27
  } from '../runtime-sandbox-provider-profile';
21
- import { assertEarlySandboxLaneSupported } from './absurd-worker-required-env';
28
+ import {
29
+ assertEarlySandboxLaneSupported,
30
+ runtimeSandboxPlacementPoliciesRunnableByWorker,
31
+ } from './absurd-worker-required-env';
22
32
  import { CLAIM_AFFINITY_FOR_EARLY_SANDBOX } from './early-sandbox-claim-affinity';
23
33
 
24
34
  /**
@@ -35,13 +45,55 @@ export const EARLY_SANDBOX_ADAPTERS: Readonly<
35
45
  modal: modalEarlySandboxAdapter,
36
46
  };
37
47
 
48
+ /**
49
+ * The only provider a hinted placement policy may lead with. Daytona-led
50
+ * policies (`daytona_modal_canary@1` included: its canary is chosen per run
51
+ * at launch, after the hint) and the Preview-only Vercel policy are refused.
52
+ */
53
+ export const EARLY_SANDBOX_POLICY_LEAD_PROVIDER: RuntimeSandboxProviderId =
54
+ 'modal';
55
+
56
+ /**
57
+ * Early sandboxes one worker process may hold unadopted at once, summed over
58
+ * its Adapters' registries. A hint past it is refused; its run creates its
59
+ * own sandbox at launch.
60
+ */
61
+ export const EARLY_SANDBOX_MAX_OUTSTANDING_PER_WORKER = 16;
62
+
63
+ export type EarlySandboxAdapterSelectionRefusal =
64
+ | 'lane_lead_not_single'
65
+ | 'adapter_missing'
66
+ | 'policy_unknown'
67
+ | 'policy_not_on_lane'
68
+ | 'policy_lead_not_modal';
69
+
38
70
  export class EarlySandboxAdapterSelectionError extends Error {
39
- constructor(message: string) {
71
+ readonly reason: EarlySandboxAdapterSelectionRefusal;
72
+ constructor(message: string, reason: EarlySandboxAdapterSelectionRefusal) {
40
73
  super(message);
41
74
  this.name = 'EarlySandboxAdapterSelectionError';
75
+ this.reason = reason;
42
76
  }
43
77
  }
44
78
 
79
+ /** Why a worker refuses a hint before selecting an Adapter or creating. */
80
+ export type EarlySandboxHintRefusal =
81
+ | 'worker_draining'
82
+ | 'no_idle_slot'
83
+ | 'outstanding_cap';
84
+
85
+ /**
86
+ * The worker's own state a hint is admitted against. Each refusal is one
87
+ * `play-runner.early.hint_refused` line; the run's launch then creates its
88
+ * own sandbox.
89
+ */
90
+ export type EarlySandboxWorkerCapacity = {
91
+ /** Drain mode (`DEEPLINE_ABSURD_DRAIN_EXIT`): the lane is retiring. */
92
+ readonly draining: boolean;
93
+ /** Whether the claim loop has a free slot to claim the hinted run with. */
94
+ hasIdleSlot(): boolean;
95
+ };
96
+
45
97
  /** A hinted run's early-sandbox switches (E2, PB, CA). */
46
98
  export function resolveRunEarlySandboxSwitches(
47
99
  overrides: EarlySandboxStartRequest['experimentSwitchOverrides'],
@@ -62,20 +114,33 @@ export function resolveRunEarlySandboxSwitches(
62
114
  }
63
115
 
64
116
  /**
65
- * The Adapter this lane starts a run's early sandbox with. Throws
66
- * `RuntimeSandboxCapabilityUnsupportedError` when a lane provider's profile
117
+ * The Adapter this lane starts a run's early sandbox with.
118
+ *
119
+ * Without `sandboxPlacementPolicyId` (every hint from a writer older than the
120
+ * field): the lane's early-sandbox providers must name exactly one
121
+ * implemented Adapter, as before. With it: the policy must be in this
122
+ * worker's placement policy catalog and among the policies this lane runs,
123
+ * and its lead provider must be Modal; the Adapter is the lead provider's.
124
+ *
125
+ * Throws `RuntimeSandboxCapabilityUnsupportedError` when a provider's profile
67
126
  * lacks a capability the switches need, and
68
- * `EarlySandboxAdapterSelectionError` when the lane's providers do not name
69
- * exactly one implemented Adapter.
127
+ * `EarlySandboxAdapterSelectionError` (with its `reason`) otherwise.
70
128
  */
71
129
  export function selectEarlySandboxAdapter(input: {
72
130
  backend: PlayRuntimeBackendId;
73
131
  env: Readonly<Record<string, string | undefined>>;
74
132
  switches: EarlySandboxSwitches;
133
+ /** The hinted run's placement policy id; absent keeps the lane rule. */
134
+ sandboxPlacementPolicyId?: string | null;
75
135
  adapters?: Readonly<
76
136
  Partial<Record<RuntimeSandboxProviderId, EarlySandboxAdapter>>
77
137
  >;
78
138
  }): EarlySandboxAdapter {
139
+ const adapters = input.adapters ?? EARLY_SANDBOX_ADAPTERS;
140
+ const policyId = input.sandboxPlacementPolicyId?.trim();
141
+ if (policyId) {
142
+ return selectEarlySandboxAdapterForPolicy({ ...input, policyId, adapters });
143
+ }
79
144
  const subject = `Early sandbox on the ${input.backend} worker lane`;
80
145
  const providers = assertEarlySandboxLaneSupported({
81
146
  subject,
@@ -89,26 +154,126 @@ export function selectEarlySandboxAdapter(input: {
89
154
  `${subject} needs exactly one lead provider; the lane has ${
90
155
  providers.length === 0 ? 'none' : providers.join(', ')
91
156
  }.`,
157
+ 'lane_lead_not_single',
92
158
  );
93
159
  }
94
160
  // The profile says it is supported; an Adapter must then exist.
95
- const adapter = (input.adapters ?? EARLY_SANDBOX_ADAPTERS)[provider];
161
+ const adapter = adapters[provider];
96
162
  if (!adapter) {
97
163
  throw new EarlySandboxAdapterSelectionError(
98
164
  `${subject}: ${provider} declares early start supported but has no early-sandbox Adapter.`,
165
+ 'adapter_missing',
99
166
  );
100
167
  }
101
168
  return adapter;
102
169
  }
103
170
 
171
+ function selectEarlySandboxAdapterForPolicy(input: {
172
+ backend: PlayRuntimeBackendId;
173
+ env: Readonly<Record<string, string | undefined>>;
174
+ switches: EarlySandboxSwitches;
175
+ policyId: string;
176
+ adapters: Readonly<
177
+ Partial<Record<RuntimeSandboxProviderId, EarlySandboxAdapter>>
178
+ >;
179
+ }): EarlySandboxAdapter {
180
+ const subject = `Early sandbox for placement policy ${input.policyId} on the ${input.backend} worker lane`;
181
+ if (!isKnownRuntimeSandboxPlacementPolicyId(input.policyId)) {
182
+ throw new EarlySandboxAdapterSelectionError(
183
+ `${subject}: the policy is not in this worker's placement policy catalog.`,
184
+ 'policy_unknown',
185
+ );
186
+ }
187
+ const policy = resolveRuntimeSandboxPlacementPolicy(input.policyId);
188
+ const runnable = runtimeSandboxPlacementPoliciesRunnableByWorker(
189
+ input.backend,
190
+ input.env,
191
+ );
192
+ if (!runnable.some((candidate) => candidate.id === policy.id)) {
193
+ throw new EarlySandboxAdapterSelectionError(
194
+ `${subject}: this lane does not run the policy (it runs ${
195
+ runnable.map((candidate) => candidate.id).join(', ') || 'none'
196
+ }).`,
197
+ 'policy_not_on_lane',
198
+ );
199
+ }
200
+ const lead = policy.providers[0];
201
+ if (lead !== EARLY_SANDBOX_POLICY_LEAD_PROVIDER) {
202
+ throw new EarlySandboxAdapterSelectionError(
203
+ `${subject}: the policy leads with ${lead}; only ${EARLY_SANDBOX_POLICY_LEAD_PROVIDER}-led policies start early.`,
204
+ 'policy_lead_not_modal',
205
+ );
206
+ }
207
+ assertRuntimeSandboxProvidersSupport({
208
+ subject,
209
+ providers: [lead],
210
+ required: earlySandboxRequiredCapabilities(input.switches),
211
+ });
212
+ const adapter = input.adapters[lead];
213
+ if (!adapter) {
214
+ throw new EarlySandboxAdapterSelectionError(
215
+ `${subject}: ${lead} has no early-sandbox Adapter.`,
216
+ 'adapter_missing',
217
+ );
218
+ }
219
+ return adapter;
220
+ }
221
+
222
+ /** This process's outstanding early sandboxes, over every Adapter. */
223
+ export function outstandingEarlySandboxes(
224
+ adapters: Readonly<
225
+ Partial<Record<RuntimeSandboxProviderId, EarlySandboxAdapter>>
226
+ > = EARLY_SANDBOX_ADAPTERS,
227
+ ): number {
228
+ const registries = new Set(
229
+ Object.values(adapters).flatMap((adapter) =>
230
+ adapter ? [adapter.registry] : [],
231
+ ),
232
+ );
233
+ let total = 0;
234
+ for (const registry of registries) total += registry.outstanding();
235
+ return total;
236
+ }
237
+
238
+ function refuseEarlySandboxHint(input: {
239
+ reason: EarlySandboxHintRefusal;
240
+ backend: PlayRuntimeBackendId;
241
+ workflowId: string;
242
+ sandboxPlacementPolicyId: string | null;
243
+ outstanding?: number;
244
+ }): false {
245
+ console.error(
246
+ JSON.stringify({
247
+ event: 'play-runner.early.hint_refused',
248
+ reason: input.reason,
249
+ backend: input.backend,
250
+ workflowId: input.workflowId,
251
+ sandboxPlacementPolicyId: input.sandboxPlacementPolicyId,
252
+ ...(input.outstanding === undefined
253
+ ? {}
254
+ : {
255
+ outstanding: input.outstanding,
256
+ cap: EARLY_SANDBOX_MAX_OUTSTANDING_PER_WORKER,
257
+ }),
258
+ }),
259
+ );
260
+ return false;
261
+ }
262
+
104
263
  /**
105
264
  * The worker's early-sandbox hint handler: with E2 off for the run it does
106
- * nothing (no lane read, no provider call, as before). Otherwise it selects
107
- * the lane's Adapter, refusing loudly (logged, hint not started) when the
108
- * lane's providers do not support the run's switches.
265
+ * nothing (no lane read, no provider call, as before). Otherwise it refuses,
266
+ * with one loud line each: a draining worker, a worker with no idle claim
267
+ * slot, a failed Adapter selection (`selectEarlySandboxAdapter`), and a
268
+ * worker already holding `EARLY_SANDBOX_MAX_OUTSTANDING_PER_WORKER` early
269
+ * sandboxes. A refused hint starts nothing; the launch creates its own.
109
270
  */
110
271
  export function startWorkerLaneEarlySandbox(
111
272
  input: EarlySandboxStartRequest & {
273
+ /** The hinted run's placement policy id; absent keeps the lane rule. */
274
+ sandboxPlacementPolicyId?: string | null;
275
+ /** The worker's drain and claim-slot state; absent checks neither. */
276
+ capacity?: EarlySandboxWorkerCapacity | null;
112
277
  env?: Readonly<Record<string, string | undefined>>;
113
278
  adapters?: Readonly<
114
279
  Partial<Record<RuntimeSandboxProviderId, EarlySandboxAdapter>>
@@ -123,26 +288,53 @@ export function startWorkerLaneEarlySandbox(
123
288
  const backend = normalizePlayRuntimeBackend(
124
289
  env.DEEPLINE_PLAY_RUNNER_BACKEND?.trim() || 'daytona',
125
290
  );
291
+ const sandboxPlacementPolicyId =
292
+ input.sandboxPlacementPolicyId?.trim() || null;
293
+ const hint = {
294
+ backend,
295
+ workflowId: input.workflowId,
296
+ sandboxPlacementPolicyId,
297
+ };
298
+ if (input.capacity?.draining) {
299
+ return refuseEarlySandboxHint({ ...hint, reason: 'worker_draining' });
300
+ }
301
+ if (input.capacity && !input.capacity.hasIdleSlot()) {
302
+ return refuseEarlySandboxHint({ ...hint, reason: 'no_idle_slot' });
303
+ }
126
304
  let adapter: EarlySandboxAdapter;
127
305
  try {
128
306
  adapter = selectEarlySandboxAdapter({
129
307
  backend,
130
308
  env,
131
309
  switches,
310
+ sandboxPlacementPolicyId,
132
311
  ...(input.adapters ? { adapters: input.adapters } : {}),
133
312
  });
134
313
  } catch (error) {
135
314
  console.error(
136
315
  JSON.stringify({
137
316
  event: 'play-runner.early.selection_refused',
138
- backend,
139
- workflowId: input.workflowId,
317
+ ...hint,
318
+ reason:
319
+ error instanceof EarlySandboxAdapterSelectionError
320
+ ? error.reason
321
+ : null,
140
322
  errorName: error instanceof Error ? error.name : null,
141
323
  error: error instanceof Error ? error.message : String(error),
142
324
  }),
143
325
  );
144
326
  return false;
145
327
  }
328
+ const outstanding = outstandingEarlySandboxes(
329
+ input.adapters ?? EARLY_SANDBOX_ADAPTERS,
330
+ );
331
+ if (outstanding >= EARLY_SANDBOX_MAX_OUTSTANDING_PER_WORKER) {
332
+ return refuseEarlySandboxHint({
333
+ ...hint,
334
+ reason: 'outstanding_cap',
335
+ outstanding,
336
+ });
337
+ }
146
338
  return startEarlySandbox(adapter, {
147
339
  workflowId: input.workflowId,
148
340
  orgId: input.orgId ?? null,
@@ -193,6 +385,8 @@ export function earlySandboxFleetSweepAdapter(input: {
193
385
  provider,
194
386
  scope: 'unadopted_early_sandboxes',
195
387
  intervalMs: EARLY_SANDBOX_SWEEP_INTERVAL_MS,
388
+ // Every worker runs this pass; a deploy boots them together.
389
+ jitterRatio: EARLY_SANDBOX_SWEEP_JITTER_RATIO,
196
390
  async runPass() {
197
391
  const outcome = await input.adapter.sweepOrphansForWorker({
198
392
  runtimeSchedulerSchema: input.runtimeSchedulerSchema,
@@ -1191,6 +1191,14 @@ export function createPostgresSchedulerProgressReporter(input: {
1191
1191
  return;
1192
1192
  }
1193
1193
  if (event.type === 'docflow.node.completed') {
1194
+ // A decision's completion is re-emitted carrying the arm it took; a
1195
+ // repeat of the same invocation without it must not erase that arm.
1196
+ const decision =
1197
+ event.decision ??
1198
+ (current?.nodeIo?.attempt === event.attempt &&
1199
+ current.nodeIo.invocationId === event.invocationId
1200
+ ? current.nodeIo.decision
1201
+ : undefined);
1194
1202
  setNodeProgress(event.nodeId, {
1195
1203
  startedAt: current?.startedAt ?? event.at,
1196
1204
  completedAt: event.at,
@@ -1202,6 +1210,7 @@ export function createPostgresSchedulerProgressReporter(input: {
1202
1210
  outputs: event.outputs,
1203
1211
  ...(event.outputsTruncated ? { outputsTruncated: true } : {}),
1204
1212
  error: null,
1213
+ ...(decision ? { decision } : {}),
1205
1214
  },
1206
1215
  });
1207
1216
  scheduleFlush(true);
@@ -1560,6 +1569,14 @@ export function createPostgresSchedulerProgressReporter(input: {
1560
1569
  continue;
1561
1570
  }
1562
1571
  const at = observation.settledAt ?? observation.startedAt ?? Date.now();
1572
+ // Durable observations carry no decision arm; the live completion that
1573
+ // recorded one for this same invocation keeps it.
1574
+ const decision =
1575
+ observation.status === 'completed' &&
1576
+ current?.nodeIo?.attempt === observation.attempt &&
1577
+ current.nodeIo.invocationId === (observation.invocationId ?? undefined)
1578
+ ? current.nodeIo.decision
1579
+ : undefined;
1563
1580
  setNodeProgress(nodeId, {
1564
1581
  startedAt: current?.startedAt ?? observation.startedAt ?? at,
1565
1582
  ...(observation.status === 'started' ? {} : { completedAt: at }),
@@ -1581,6 +1598,7 @@ export function createPostgresSchedulerProgressReporter(input: {
1581
1598
  : observation.status === 'completed'
1582
1599
  ? { error: null }
1583
1600
  : {}),
1601
+ ...(decision ? { decision } : {}),
1584
1602
  },
1585
1603
  });
1586
1604
  }
@@ -19815,6 +19815,74 @@ export async function getPostgresSchedulerObservationsForRuns(
19815
19815
  return result.rows.map(mapObservationRow);
19816
19816
  }
19817
19817
 
19818
+ /**
19819
+ * The newest settled observation of EVERY node for a bounded page of runs, in
19820
+ * one org-scoped read over the observations primary key — what a runs grid's
19821
+ * per-step columns summarize. Same winner rule as the one-node read: highest
19822
+ * attempt, then latest invocation.
19823
+ */
19824
+ export async function getPostgresSchedulerSettledObservationsForRuns(
19825
+ client: PostgresSchedulerQueryClient,
19826
+ input: { runIds: readonly string[] },
19827
+ options: PostgresSchedulerReceiptOptions,
19828
+ ): Promise<DocflowObservationRecord[]> {
19829
+ const runIds = [
19830
+ ...new Set(input.runIds.map((runId) => runId.trim()).filter(Boolean)),
19831
+ ];
19832
+ if (runIds.length === 0) return [];
19833
+ const result = await client.query<ObservationRow>(
19834
+ `
19835
+ SELECT DISTINCT ON (run_id, node_id)
19836
+ run_id, attempt, node_id, invocation_seq, invocation_id, status,
19837
+ inputs_json, outputs_json, inputs_truncated, outputs_truncated,
19838
+ error, started_at, settled_at
19839
+ FROM ${tableName('observations', options)}
19840
+ WHERE org_id = $1
19841
+ AND run_id = ANY($2::text[])
19842
+ AND status IN ('completed', 'failed')
19843
+ ORDER BY run_id, node_id, attempt DESC, invocation_seq DESC
19844
+ `,
19845
+ [receiptOrgId(options), runIds],
19846
+ );
19847
+ return result.rows.map(mapObservationRow);
19848
+ }
19849
+
19850
+ /**
19851
+ * The diagram each run of a bounded page pinned at launch: the `docflow` of
19852
+ * the static pipeline frozen into its contract snapshot. A run's steps are
19853
+ * read against the diagram it ran with, not the Play's current one, so an
19854
+ * edited diagram never relabels or drops an old run's recorded steps. Read
19855
+ * through the runs primary key, org-scoped; the JSON path is extracted in the
19856
+ * database so the rest of the launch never leaves it. Runs without a pinned
19857
+ * diagram are absent.
19858
+ */
19859
+ export async function getPostgresSchedulerPinnedDocflowsForRuns(
19860
+ client: PostgresSchedulerQueryClient,
19861
+ input: { runIds: readonly string[] },
19862
+ options: PostgresSchedulerReceiptOptions,
19863
+ ): Promise<Map<string, unknown>> {
19864
+ const runIds = [
19865
+ ...new Set(input.runIds.map((runId) => runId.trim()).filter(Boolean)),
19866
+ ];
19867
+ if (runIds.length === 0) return new Map();
19868
+ const result = await client.query<{ run_id: string; docflow: unknown }>(
19869
+ `
19870
+ SELECT run_id,
19871
+ launch_json #> '{contractSnapshot,staticPipeline,docflow}' AS docflow
19872
+ FROM ${tableName('runs', options)}
19873
+ WHERE org_id = $1
19874
+ AND run_id = ANY($2::text[])
19875
+ `,
19876
+ [receiptOrgId(options), runIds],
19877
+ );
19878
+ const docflows = new Map<string, unknown>();
19879
+ for (const row of result.rows) {
19880
+ if (row.docflow && typeof row.docflow === 'object')
19881
+ docflows.set(row.run_id, row.docflow);
19882
+ }
19883
+ return docflows;
19884
+ }
19885
+
19818
19886
  export async function countPostgresSchedulerReceipts(
19819
19887
  client: PostgresSchedulerQueryClient,
19820
19888
  input: {
@@ -310,8 +310,11 @@ export async function reserveRuntimeSandboxCapacityLease(
310
310
  /** Resume the one unresolved Daytona create for this run, if present. */
311
311
  resumePendingDaytonaOperation?: boolean;
312
312
  /**
313
- * The `play.concurrent_runs` entitlement the launch carries. When set it
314
- * is the limit; otherwise the mirrored cap, then the runtime default.
313
+ * The `play.concurrent_runs` entitlement the launch carries. Any unexpired
314
+ * time-limited row in the mirrored org limit cache wins, raising or
315
+ * lowering the limit, so an operator can resize an org's already-queued
316
+ * runs; otherwise this, then the mirrored cap, then the runtime default.
317
+ * A permanent mirrored row never outranks the launch.
315
318
  */
316
319
  entitlementLimit?: number | null;
317
320
  },
@@ -392,7 +395,12 @@ export async function reserveRuntimeSandboxCapacityLease(
392
395
  `
393
396
  WITH observed AS MATERIALIZED (
394
397
  SELECT
395
- coalesce($14::integer, capacity.configured_limit) AS "limit",
398
+ coalesce((
399
+ SELECT override."limit" FROM ${cache} AS override
400
+ WHERE override.org_id = $1
401
+ AND override.expires_at IS NOT NULL
402
+ AND override.expires_at > clock_timestamp()
403
+ ), $14::integer, capacity.configured_limit) AS "limit",
396
404
  capacity.active_leases,
397
405
  coalesce((
398
406
  SELECT jsonb_agg(pending)
@@ -194,9 +194,21 @@ export type RuntimeWorkerEarlySandboxHint = {
194
194
  * resolves E2/F2 for this run. Absent: static defaults.
195
195
  */
196
196
  experimentSwitchOverrides?: ExperimentSwitchOverrides;
197
+ /**
198
+ * The run's admitted placement policy id. The worker picks the early
199
+ * sandbox's Adapter from this policy's lead provider (Modal only) and
200
+ * refuses a policy its lane does not run. Absent (every writer today): the
201
+ * lane's own providers decide, as before. Reader-first: an older worker or
202
+ * gateway drops it, and its hint takes the absent path.
203
+ */
204
+ sandboxPlacementPolicyId?: string;
197
205
  };
198
206
 
199
- function parseEarlySandboxHint(
207
+ /** Longest placement policy id a hint may carry (catalog ids are ~25). */
208
+ const EARLY_SANDBOX_HINT_POLICY_ID_MAX_LENGTH = 128;
209
+
210
+ /** Unknown fields are dropped, so a newer writer's additions are ignored. */
211
+ export function parseEarlySandboxHint(
200
212
  text: string,
201
213
  ): RuntimeWorkerEarlySandboxHint | null {
202
214
  try {
@@ -211,10 +223,24 @@ function parseEarlySandboxHint(
211
223
  const experimentSwitchOverrides = readCarriedExperimentSwitchOverrides(
212
224
  value.experimentSwitchOverrides,
213
225
  );
226
+ // A present policy id that is not a bounded string is a malformed hint
227
+ // (refused with 400), never silently the absent path.
228
+ let sandboxPlacementPolicyId: string | undefined;
229
+ if (
230
+ value.sandboxPlacementPolicyId !== undefined &&
231
+ value.sandboxPlacementPolicyId !== null
232
+ ) {
233
+ if (typeof value.sandboxPlacementPolicyId !== 'string') return null;
234
+ const trimmed = value.sandboxPlacementPolicyId.trim();
235
+ if (!trimmed || trimmed.length > EARLY_SANDBOX_HINT_POLICY_ID_MAX_LENGTH)
236
+ return null;
237
+ sandboxPlacementPolicyId = trimmed;
238
+ }
214
239
  return {
215
240
  workflowId,
216
241
  orgId,
217
242
  ...(experimentSwitchOverrides ? { experimentSwitchOverrides } : {}),
243
+ ...(sandboxPlacementPolicyId ? { sandboxPlacementPolicyId } : {}),
218
244
  };
219
245
  } catch {
220
246
  return null;
@@ -232,7 +258,9 @@ export function handleRuntimeWorkerEarlySandbox(
232
258
  * CA: after an accepted start, the name this worker claims under when the
233
259
  * hint's run asked for claim affinity; null otherwise (reply unchanged).
234
260
  */
235
- claimOwner?: ((hint: RuntimeWorkerEarlySandboxHint) => string | null) | null;
261
+ claimOwner?:
262
+ | ((hint: RuntimeWorkerEarlySandboxHint) => string | null)
263
+ | null;
236
264
  },
237
265
  ): boolean {
238
266
  if (