deepline 0.3.583 → 0.4.0

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 (194) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +79 -36
  2. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  3. package/dist/bundling-sources/sdk/src/release.ts +7 -3
  4. package/dist/bundling-sources/sdk/src/types.ts +37 -0
  5. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +22 -3
  6. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +94 -5
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +66 -12
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-topology.ts +6 -1
  10. package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-tuple-recovery.ts +9 -3
  11. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +86 -20
  12. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +17 -6
  13. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +22 -6
  14. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +54 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +2 -1
  16. package/dist/bundling-sources/shared_libs/play-runtime/row-failure-summary.ts +1 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +4 -1
  18. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +12 -3
  19. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +197 -19
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +25 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +5 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +73 -3
  23. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-wake-policy.ts +419 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +20 -6
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +24 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +1 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +36 -19
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +380 -51
  29. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +21 -10
  30. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +32 -0
  31. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -0
  32. package/dist/bundling-sources/shared_libs/plays/deploy/api-client.ts +3 -1
  33. package/dist/bundling-sources/shared_libs/plays/deploy/run-deployment.ts +34 -4
  34. package/dist/bundling-sources/shared_libs/plays/docflow-recording-lint.ts +512 -0
  35. package/dist/bundling-sources/shared_libs/plays/docflow-requirement.ts +346 -0
  36. package/dist/bundling-sources/shared_libs/plays/docflow-rule-codes.ts +38 -0
  37. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +42 -2
  38. package/dist/bundling-sources/shared_libs/plays/docflow.ts +223 -32
  39. package/dist/bundling-sources/shared_libs/plays/play-check-compact.ts +14 -1
  40. package/dist/bundling-sources/shared_libs/plays/run-result.ts +35 -0
  41. package/dist/cli/{agents-G344SPW2.mjs → agents-AHXB7N7Y.mjs} +4 -4
  42. package/dist/cli/{agents-ZPDXVPEE.js → agents-KBZ7OUZS.js} +33 -33
  43. package/dist/cli/{auth-V66RP2A6.mjs → auth-3CACO52T.mjs} +5 -5
  44. package/dist/cli/auth-UOHCO5K6.js +44 -0
  45. package/dist/cli/{billing-ROYUQF67.js → billing-5KXPGKMO.js} +105 -105
  46. package/dist/cli/{billing-BTMGZJCR.mjs → billing-TSTK63NB.mjs} +9 -9
  47. package/dist/cli/{chunk-ROWROMXD.mjs → chunk-2GWKBQJZ.mjs} +1 -1
  48. package/dist/cli/{chunk-VXEZKZU4.mjs → chunk-3DJMPID5.mjs} +11 -11
  49. package/dist/cli/{chunk-VH45GV3T.js → chunk-3ET6NRXP.js} +7 -3
  50. package/dist/cli/{chunk-43MKV6E4.mjs → chunk-3MWTAM3F.mjs} +3 -3
  51. package/dist/cli/{chunk-U6BTY4WS.mjs → chunk-4ANDW2OT.mjs} +1 -1
  52. package/dist/cli/{chunk-H4BYWEV5.js → chunk-4BSCSQ6I.js} +4 -4
  53. package/dist/cli/{chunk-ACS6BYE5.mjs → chunk-4UEXAMDU.mjs} +2 -2
  54. package/dist/cli/{chunk-QPN662ZP.js → chunk-5XGLDVSD.js} +100 -100
  55. package/dist/cli/{chunk-MFPHCUHK.js → chunk-7XXJJVSI.js} +5 -5
  56. package/dist/cli/{chunk-QGOHEJVJ.js → chunk-7ZCD7OPO.js} +5 -5
  57. package/dist/cli/{chunk-AXKFZIXC.mjs → chunk-AJJSKKH4.mjs} +2 -2
  58. package/dist/cli/{chunk-KSXBLXLV.mjs → chunk-BHF5UW34.mjs} +1 -1
  59. package/dist/cli/{chunk-AHQDUMDM.js → chunk-BO2TXH5Y.js} +20 -20
  60. package/dist/cli/{chunk-W5WLWRKL.mjs → chunk-BUC2TNF2.mjs} +2 -2
  61. package/dist/cli/{chunk-6GYGMWQV.js → chunk-BUUAFSSN.js} +68 -50
  62. package/dist/cli/{chunk-WUVDJSZE.js → chunk-C45E47KC.js} +23 -23
  63. package/dist/cli/{chunk-BUMCOVBP.js → chunk-D4R3AL4F.js} +5 -5
  64. package/dist/cli/{chunk-PVDP3AZY.mjs → chunk-DAZRIAXW.mjs} +4 -4
  65. package/dist/cli/{chunk-W3ECB7GC.js → chunk-DNOZQGJF.js} +3 -3
  66. package/dist/cli/{chunk-HYT5B2NL.js → chunk-DUL6UQ2T.js} +2 -2
  67. package/dist/cli/{chunk-P2YNTAGL.mjs → chunk-ES3S6UXR.mjs} +2 -2
  68. package/dist/cli/{chunk-K6GDSCFL.mjs → chunk-FDAYUP3M.mjs} +3 -3
  69. package/dist/cli/{chunk-23LYXVI4.js → chunk-FEVUIT2U.js} +6 -6
  70. package/dist/cli/{chunk-6S3OAJCJ.mjs → chunk-FSPEUU3V.mjs} +49 -6
  71. package/dist/cli/{chunk-2QIVGZKS.mjs → chunk-FZZMCVOS.mjs} +5 -5
  72. package/dist/cli/{chunk-73IZARR5.js → chunk-GHOB72U6.js} +13 -13
  73. package/dist/cli/{chunk-LVJAHM2I.mjs → chunk-GLYWRTEL.mjs} +3 -3
  74. package/dist/cli/{chunk-AXOQ2FMS.mjs → chunk-HNTIGYRT.mjs} +1 -1
  75. package/dist/cli/{chunk-C7UCDL2K.js → chunk-IGPHYKEJ.js} +41 -41
  76. package/dist/cli/{chunk-PULU5YGX.js → chunk-ISSYN3DJ.js} +20 -20
  77. package/dist/cli/{chunk-ZHIJA4MW.mjs → chunk-JKQPITEE.mjs} +54 -36
  78. package/dist/cli/{chunk-EHV52KUV.mjs → chunk-KMLACXI2.mjs} +7 -3
  79. package/dist/cli/{chunk-WAZR72D5.js → chunk-KQXACHYA.js} +26 -26
  80. package/dist/cli/{chunk-PGUK5VPC.js → chunk-LW2GKYZW.js} +2 -2
  81. package/dist/cli/{chunk-J54DMFV5.mjs → chunk-O2KSPI2M.mjs} +2 -2
  82. package/dist/cli/{chunk-CCC3NIYB.js → chunk-O6GT6JD7.js} +9 -9
  83. package/dist/cli/{chunk-DNYFNOWG.mjs → chunk-OCXWUWUI.mjs} +5 -5
  84. package/dist/cli/{chunk-MEAWK5G7.js → chunk-QKRDAJ3T.js} +53 -53
  85. package/dist/cli/{chunk-N5XRUZRS.js → chunk-QQESWF6D.js} +16 -16
  86. package/dist/cli/{chunk-2D5YISAL.js → chunk-REX5SUYU.js} +2 -2
  87. package/dist/cli/{chunk-RO2LTLJA.js → chunk-RXIQWG2N.js} +48 -48
  88. package/dist/cli/{chunk-VXDKL434.js → chunk-S33BN7GZ.js} +3 -3
  89. package/dist/cli/{chunk-72MEXMSH.mjs → chunk-SGRJJLNV.mjs} +1 -1
  90. package/dist/cli/{chunk-HOGRT5X6.mjs → chunk-TCNYSNVU.mjs} +1 -1
  91. package/dist/cli/{chunk-H7F3ROT3.mjs → chunk-TFPMVSGK.mjs} +2 -2
  92. package/dist/cli/{chunk-GFX6CDAB.mjs → chunk-V73WDQEA.mjs} +5 -5
  93. package/dist/cli/{chunk-LHD3HOYN.js → chunk-VYERVFGB.js} +49 -6
  94. package/dist/cli/{chunk-C233ZRNX.mjs → chunk-WBRSVML3.mjs} +4 -4
  95. package/dist/cli/{chunk-7AFTLM74.mjs → chunk-WW52ANX4.mjs} +2 -2
  96. package/dist/cli/{chunk-ZFJNIZHI.js → chunk-XZS35M3Y.js} +10 -10
  97. package/dist/cli/{chunk-YRNWA2IL.js → chunk-YNYHYL5C.js} +15 -15
  98. package/dist/cli/{chunk-JQT3SHXL.mjs → chunk-ZHE5E2WJ.mjs} +1 -1
  99. package/dist/cli/{chunk-N5RCXI3M.mjs → chunk-ZJ2H77VV.mjs} +5 -5
  100. package/dist/cli/{chunk-GQHZV7EQ.js → chunk-ZX6UVPGZ.js} +7 -7
  101. package/dist/cli/command-docs.js +2 -2
  102. package/dist/cli/command-docs.mjs +1 -1
  103. package/dist/cli/concurrent-runs-help-H5SZUA5J.js +22 -0
  104. package/dist/cli/{concurrent-runs-help-A2Y33OQ5.mjs → concurrent-runs-help-IYELSCHB.mjs} +6 -6
  105. package/dist/cli/{csv-PS74WVXE.mjs → csv-ENEC3APZ.mjs} +4 -4
  106. package/dist/cli/{csv-TKSR2LFV.js → csv-X6CP57R4.js} +13 -13
  107. package/dist/cli/{db-R6GOM4VC.js → db-6HLRSE2M.js} +27 -27
  108. package/dist/cli/{db-EXLBRZ7K.mjs → db-YGKRFK4T.mjs} +6 -6
  109. package/dist/cli/{describe-JJBXFPVQ.mjs → describe-4SGQEX7K.mjs} +18 -18
  110. package/dist/cli/describe-Q2OYHDVZ.js +50 -0
  111. package/dist/cli/describe-core.d.mts +2 -2
  112. package/dist/cli/describe-core.d.ts +2 -2
  113. package/dist/cli/{executions-474U7R3Y.js → executions-IC55YJ67.js} +8 -8
  114. package/dist/cli/{executions-5PEODJQG.mjs → executions-PO2IOSZ7.mjs} +6 -6
  115. package/dist/cli/{feedback-QUQVRDBD.mjs → feedback-6BUD5F4I.mjs} +6 -6
  116. package/dist/cli/{feedback-URTCAOXP.js → feedback-BCGQLZ5T.js} +14 -14
  117. package/dist/cli/git-5X3MLBIP.js +26 -0
  118. package/dist/cli/{git-AQF23KKU.mjs → git-IN4IBL2K.mjs} +5 -5
  119. package/dist/cli/index.js +148 -148
  120. package/dist/cli/index.mjs +47 -47
  121. package/dist/cli/{integrations-NMFOOSS4.js → integrations-R2Z2MDO3.js} +29 -29
  122. package/dist/cli/{integrations-5POBI72U.mjs → integrations-ZMGB6NQA.mjs} +7 -7
  123. package/dist/cli/{legacy-noops-6YVCOSFO.mjs → legacy-noops-GIC5OZKP.mjs} +6 -6
  124. package/dist/cli/{legacy-noops-V75T5LHV.js → legacy-noops-X4JPRPTJ.js} +9 -9
  125. package/dist/cli/{mcp-7WEYQ5V7.mjs → mcp-G4IRJIKK.mjs} +4 -4
  126. package/dist/cli/{mcp-N6GYXCUQ.js → mcp-USZKTVL2.js} +24 -24
  127. package/dist/cli/{monitors-TAK4M5Y4.mjs → monitors-SNFZPSCY.mjs} +7 -7
  128. package/dist/cli/{monitors-HW4H4PE5.js → monitors-T7LRP7OB.js} +100 -100
  129. package/dist/cli/{org-FULXOXNE.js → org-2L2ZZL2P.js} +121 -121
  130. package/dist/cli/{org-3C2RN36N.mjs → org-YTXLKW52.mjs} +6 -6
  131. package/dist/cli/{outcomes-4KRZL6OL.mjs → outcomes-CJWBIFTA.mjs} +6 -6
  132. package/dist/cli/{outcomes-O3HDQWGN.js → outcomes-O63F57JF.js} +14 -14
  133. package/dist/cli/{play-ZTRWUODW.mjs → play-6UWPUHC6.mjs} +331 -70
  134. package/dist/cli/{play-HA4RGX7T.js → play-T353SULJ.js} +930 -669
  135. package/dist/cli/{providers-FAKWWJE2.mjs → providers-LZABK2UW.mjs} +6 -6
  136. package/dist/cli/{providers-DXMKWBZN.js → providers-XORJH2VW.js} +9 -9
  137. package/dist/cli/{quickstart-YWGBTW77.mjs → quickstart-O4RF7J55.mjs} +4 -4
  138. package/dist/cli/{quickstart-MA74UPNI.js → quickstart-QBNUNPZR.js} +6 -6
  139. package/dist/cli/{run-4DXSGXRB.js → run-2CPMFC6W.js} +44 -44
  140. package/dist/cli/{run-QHCYMSBP.mjs → run-GBRPFC6P.mjs} +23 -23
  141. package/dist/cli/{search-N4ZOK5XX.mjs → search-G7TS7OFB.mjs} +7 -7
  142. package/dist/cli/search-M3AHFCKQ.js +32 -0
  143. package/dist/cli/{search-output-F2OYLVK2.mjs → search-output-BIIJRUCP.mjs} +4 -4
  144. package/dist/cli/{search-output-D5VAC52B.js → search-output-NRKLNWSD.js} +6 -6
  145. package/dist/cli/{secrets-LD4FVAQI.mjs → secrets-DN3XEZNH.mjs} +6 -6
  146. package/dist/cli/{secrets-3KETOTDS.js → secrets-FUXYSEL5.js} +15 -15
  147. package/dist/cli/{sessions-LPLI4Z4O.mjs → sessions-PMUTPCTT.mjs} +6 -6
  148. package/dist/cli/sessions-VMBMBGVJ.js +23 -0
  149. package/dist/cli/{settings-NCGPJG3Z.mjs → settings-N6GNS2KA.mjs} +12 -12
  150. package/dist/cli/{settings-NFBTCOMB.js → settings-ZDTWCQ6B.js} +85 -85
  151. package/dist/cli/{setup-NH6MRYXZ.mjs → setup-LJ3KWPSA.mjs} +9 -9
  152. package/dist/cli/{setup-ATBSUSH4.js → setup-PN5TSSJE.js} +49 -49
  153. package/dist/cli/{skills-ITPBPIXD.mjs → skills-7J42K6VC.mjs} +7 -7
  154. package/dist/cli/skills-CXDENBLF.js +37 -0
  155. package/dist/cli/{tools-2XZPR65V.mjs → tools-M3S6D6DA.mjs} +17 -17
  156. package/dist/cli/tools-WY2GMOC7.js +57 -0
  157. package/dist/cli/{update-VFB22FWO.mjs → update-XTVFG74E.mjs} +9 -9
  158. package/dist/cli/update-ZB2IBGXG.js +37 -0
  159. package/dist/cli/{views-WJUZOQM2.js → views-B4X2FWTF.js} +21 -21
  160. package/dist/cli/{views-MRN3HWTG.mjs → views-UFYRDO4X.mjs} +6 -6
  161. package/dist/cli/{workflow-Q4JFBTVH.js → workflow-I2RM2J2J.js} +17 -17
  162. package/dist/cli/{workflow-A6P7YV5W.mjs → workflow-ZLMS3PDE.mjs} +7 -7
  163. package/dist/{client-QznpkWrk.d.ts → client-2QWMJInp.d.ts} +1 -1
  164. package/dist/{client-CmG8MT0x.d.mts → client-7H8TXmLa.d.mts} +1 -1
  165. package/dist/{client-core-CY0jNW0e.d.mts → client-core-BraEuxbg.d.mts} +67 -4
  166. package/dist/{client-core-CXDqfeiB.d.ts → client-core-DRglY5xa.d.ts} +67 -4
  167. package/dist/index.d.mts +3 -3
  168. package/dist/index.d.ts +3 -3
  169. package/dist/index.js +9 -9
  170. package/dist/index.mjs +6 -6
  171. package/dist/install-integrity.json +125 -120
  172. package/dist/plays/bundle-play-file.mjs +5 -0
  173. package/dist/plays/play-description.d.mts +1 -1
  174. package/dist/plays/play-description.d.ts +1 -1
  175. package/dist/plays/run-request.d.mts +1 -1
  176. package/dist/plays/run-request.d.ts +1 -1
  177. package/dist/release.d.mts +3 -3
  178. package/dist/release.d.ts +3 -3
  179. package/dist/release.js +2 -2
  180. package/dist/release.mjs +1 -1
  181. package/dist/server.d.mts +2 -2
  182. package/dist/server.d.ts +2 -2
  183. package/dist/server.js +5 -5
  184. package/dist/server.mjs +3 -3
  185. package/package.json +1 -1
  186. package/dist/cli/auth-VU6VIPVY.js +0 -44
  187. package/dist/cli/concurrent-runs-help-6WUNDV77.js +0 -22
  188. package/dist/cli/describe-CA2FL2OS.js +0 -50
  189. package/dist/cli/git-WJ4V2B4T.js +0 -26
  190. package/dist/cli/search-V765JH2H.js +0 -32
  191. package/dist/cli/sessions-XC65OMDS.js +0 -23
  192. package/dist/cli/skills-4NQBTGOL.js +0 -37
  193. package/dist/cli/tools-ZVOFATX2.js +0 -57
  194. package/dist/cli/update-QME3KPOP.js +0 -37
@@ -14,6 +14,9 @@ import type {
14
14
  } from './ctx-types';
15
15
  import {
16
16
  RUNTIME_RECEIPT_GATEWAY_BATCH_MAX_BYTES,
17
+ RUNTIME_RECEIPT_MANIFEST_RESPONSE_BYTES,
18
+ RUNTIME_RECEIPT_READ_TARGET_RESPONSE_BYTES,
19
+ RUNTIME_RECEIPT_READ_UNKNOWN_OUTPUT_BYTES,
17
20
  RUNTIME_RECEIPT_WRITER_TARGET_BATCH_BYTES,
18
21
  } from './output-size-limits';
19
22
  import {
@@ -50,7 +53,13 @@ type ReceiptOutput =
50
53
  type ReceiptCommand =
51
54
  | {
52
55
  kind: 'get';
53
- input: { key: string; runId: string; hydrateOutput?: boolean };
56
+ input: {
57
+ key: string;
58
+ runId: string;
59
+ hydrateOutput?: boolean;
60
+ /** Batch sizing only; never sent to the gateway. */
61
+ expectedOutputBytes?: number;
62
+ };
54
63
  }
55
64
  | {
56
65
  kind: 'claim';
@@ -163,6 +172,8 @@ export class RuntimeReceiptStoreAdapter {
163
172
  maxBatchSize?: number;
164
173
  maxBatchBytes?: number;
165
174
  targetBatchBytes?: number;
175
+ /** Expected decoded bytes one read request may return. */
176
+ maxReadResponseBytes?: number;
166
177
  maxFlushMs?: number;
167
178
  maxBufferedItems?: number;
168
179
  maxBufferedBytes?: number;
@@ -232,6 +243,10 @@ export class RuntimeReceiptStoreAdapter {
232
243
  options.maxBatchBytes ?? RUNTIME_RECEIPT_GATEWAY_BATCH_MAX_BYTES,
233
244
  targetBatchBytes:
234
245
  options.targetBatchBytes ?? RUNTIME_RECEIPT_WRITER_TARGET_BATCH_BYTES,
246
+ estimateResponseBytes: receiptCommandExpectedResponseBytes,
247
+ maxBatchResponseBytes:
248
+ options.maxReadResponseBytes ??
249
+ RUNTIME_RECEIPT_READ_TARGET_RESPONSE_BYTES,
235
250
  maxFlushMs: options.maxFlushMs,
236
251
  maxBufferedItems: options.maxBufferedItems,
237
252
  maxBufferedBytes: options.maxBufferedBytes,
@@ -252,6 +267,13 @@ export class RuntimeReceiptStoreAdapter {
252
267
  context: { ...context, signal },
253
268
  playName: options.playName,
254
269
  commands,
270
+ onReadSplit: (split) =>
271
+ emitReceiptReadSplitTelemetry({
272
+ ...split,
273
+ playName: options.playName,
274
+ runId: options.runId,
275
+ onTelemetry: options.onRetryTelemetry,
276
+ }),
255
277
  }),
256
278
  });
257
279
 
@@ -279,25 +301,34 @@ export class RuntimeReceiptStoreAdapter {
279
301
  input,
280
302
  serial: this.#nextSerial(),
281
303
  }),
282
- getRuntimeStepReceipt: ({ key, hydrateOutput }) =>
304
+ getRuntimeStepReceipt: ({ key, hydrateOutput, expectedOutputBytes }) =>
283
305
  write({
284
306
  kind: 'get',
285
307
  input: {
286
308
  key,
287
309
  runId: options.runId,
288
310
  ...(hydrateOutput === false ? { hydrateOutput: false } : {}),
311
+ ...(expectedOutputBytes === undefined
312
+ ? {}
313
+ : { expectedOutputBytes }),
289
314
  },
290
315
  }),
291
- getRuntimeStepReceipts: ({ keys, hydrateOutput }) =>
316
+ getRuntimeStepReceipts: ({ keys, hydrateOutput, expectedOutputBytes }) =>
292
317
  writeMany(
293
- keys.map((key) => ({
294
- kind: 'get' as const,
295
- input: {
296
- key,
297
- runId: options.runId,
298
- ...(hydrateOutput === false ? { hydrateOutput: false } : {}),
299
- },
300
- })),
318
+ keys.map((key, index) => {
319
+ const expected = expectedOutputBytes?.[index];
320
+ return {
321
+ kind: 'get' as const,
322
+ input: {
323
+ key,
324
+ runId: options.runId,
325
+ ...(hydrateOutput === false ? { hydrateOutput: false } : {}),
326
+ ...(expected === undefined
327
+ ? {}
328
+ : { expectedOutputBytes: expected }),
329
+ },
330
+ };
331
+ }),
301
332
  ),
302
333
  claimRuntimeStepReceipt: (input) => write({ kind: 'claim', input }),
303
334
  claimRuntimeStepReceipts: (input) =>
@@ -493,10 +524,63 @@ function emitReceiptWriterRetryTelemetry(input: {
493
524
  }
494
525
  }
495
526
 
527
+ /**
528
+ * What one read is expected to return, for read batch sizing. A manifest is
529
+ * small; a full read costs its known output size, or a conservative prior.
530
+ * Claims stay count-bounded: almost every claim is a miss that returns no
531
+ * body, and pricing them would split the hot path of every new row. Cache
532
+ * hits are read through manifests and priced full reads instead.
533
+ */
534
+ function receiptCommandExpectedResponseBytes(command: ReceiptCommand): number {
535
+ if (command.kind !== 'get') return 0;
536
+ if (command.input.hydrateOutput === false) {
537
+ return RUNTIME_RECEIPT_MANIFEST_RESPONSE_BYTES;
538
+ }
539
+ const expected = command.input.expectedOutputBytes;
540
+ return (
541
+ RUNTIME_RECEIPT_MANIFEST_RESPONSE_BYTES +
542
+ (expected !== undefined && Number.isFinite(expected) && expected >= 0
543
+ ? expected
544
+ : RUNTIME_RECEIPT_READ_UNKNOWN_OUTPUT_BYTES)
545
+ );
546
+ }
547
+
548
+ const RECEIPT_READ_SPLIT_TELEMETRY_TAG = '[runtime.receipt_read.split]';
549
+
550
+ function emitReceiptReadSplitTelemetry(input: {
551
+ keys: number;
552
+ halves: [number, number];
553
+ hydrateOutput: boolean;
554
+ playName: string;
555
+ runId: string;
556
+ onTelemetry?: (line: string) => void;
557
+ }): void {
558
+ try {
559
+ const serialized = JSON.stringify({
560
+ event: 'runtime.receipt_read.split',
561
+ playName: input.playName,
562
+ runId: input.runId,
563
+ keys: input.keys,
564
+ halves: input.halves,
565
+ hydrateOutput: input.hydrateOutput,
566
+ });
567
+ input.onTelemetry?.(`${RECEIPT_READ_SPLIT_TELEMETRY_TAG} ${serialized}`);
568
+ console.warn(RECEIPT_READ_SPLIT_TELEMETRY_TAG, serialized);
569
+ } catch {
570
+ // Telemetry must never affect a receipt read.
571
+ }
572
+ }
573
+
496
574
  function receiptCommandBatchKey(command: ReceiptCommand): string {
497
575
  switch (command.kind) {
498
576
  case 'get':
499
- return JSON.stringify([command.kind, command.input.runId]);
577
+ // Manifest and full reads never share a request: one full read must not
578
+ // turn a batch of bounded manifests into a batch of bodies.
579
+ return JSON.stringify([
580
+ command.kind,
581
+ command.input.runId,
582
+ command.input.hydrateOutput !== false,
583
+ ]);
500
584
  case 'claim':
501
585
  return JSON.stringify([
502
586
  command.kind,
@@ -507,6 +591,7 @@ function receiptCommandBatchKey(command: ReceiptCommand): string {
507
591
  command.input.forceRefresh === true,
508
592
  command.input.forceFailedRefresh === true,
509
593
  command.input.leaseId !== undefined,
594
+ command.input.hydrateOutput !== false,
510
595
  ]);
511
596
  case 'settle':
512
597
  return command.outcome === 'complete' ||
@@ -579,10 +664,101 @@ function classifyReceiptRetry(
579
664
  return null;
580
665
  }
581
666
 
667
+ /**
668
+ * A receipt read that ran past the store's query deadline. The gateway maps
669
+ * node-postgres's uncoded `Query read timeout` to a retryable 503 and keeps
670
+ * the message as the response detail. Retrying the same keys asks the store
671
+ * for the same bytes, so a multi-key read splits instead.
672
+ */
673
+ export function isReceiptReadTimeoutError(error: unknown): boolean {
674
+ if (error instanceof AppRuntimeApiResponseError) {
675
+ return error.retryable && error.detail.includes('Query read timeout');
676
+ }
677
+ // Headers arrived but the body did not: the gateway is still assembling a
678
+ // response too large to deliver in time.
679
+ return (
680
+ error instanceof AppRuntimeApiTransportError &&
681
+ error.responseReceived === true
682
+ );
683
+ }
684
+
685
+ export type ReceiptReadSplitEvent = {
686
+ /** Keys in the read that timed out, and in each half sent instead. */
687
+ keys: number;
688
+ halves: [number, number];
689
+ hydrateOutput: boolean;
690
+ };
691
+
692
+ /**
693
+ * Wall-clock budget for splitting one timed-out read. Past it, the timeout
694
+ * goes back to the writer, whose own retry deadline then governs, so a read
695
+ * that keeps timing out is bounded by time rather than by split depth.
696
+ */
697
+ export const RUNTIME_RECEIPT_READ_SPLIT_BUDGET_MS = 90_000;
698
+
699
+ /**
700
+ * Read receipts, halving any multi-key read that times out. Reads are pure,
701
+ * so a half can be sent without the other; results keep request order. A
702
+ * single key that times out, or any timeout after the split budget is spent,
703
+ * is left to the writer's ordinary retry budget.
704
+ */
705
+ async function readReceiptsSplittingOnTimeout(input: {
706
+ context: WorkerRuntimeApiContext;
707
+ playName: string;
708
+ runId: string;
709
+ keys: readonly string[];
710
+ hydrateOutput: boolean;
711
+ onReadSplit?: (event: ReceiptReadSplitEvent) => void;
712
+ /** Epoch ms after which no further split starts; set by the first read. */
713
+ splitDeadlineMs?: number;
714
+ }): Promise<Array<RuntimeStepReceipt | null>> {
715
+ const splitDeadlineMs =
716
+ input.splitDeadlineMs ?? Date.now() + RUNTIME_RECEIPT_READ_SPLIT_BUDGET_MS;
717
+ try {
718
+ return await getRuntimeStepReceiptsViaAppRuntime(input.context, {
719
+ playName: input.playName,
720
+ runId: input.runId,
721
+ keys: [...input.keys],
722
+ ...(input.hydrateOutput ? {} : { hydrateOutput: false }),
723
+ });
724
+ } catch (error) {
725
+ if (
726
+ input.keys.length < 2 ||
727
+ input.context.signal?.aborted ||
728
+ !isReceiptReadTimeoutError(error) ||
729
+ Date.now() >= splitDeadlineMs
730
+ ) {
731
+ throw error;
732
+ }
733
+ const middle = Math.ceil(input.keys.length / 2);
734
+ const left = input.keys.slice(0, middle);
735
+ const right = input.keys.slice(middle);
736
+ input.onReadSplit?.({
737
+ keys: input.keys.length,
738
+ halves: [left.length, right.length],
739
+ hydrateOutput: input.hydrateOutput,
740
+ });
741
+ // Sequential: the halves share whatever made the whole read slow.
742
+ const first = await readReceiptsSplittingOnTimeout({
743
+ ...input,
744
+ keys: left,
745
+ splitDeadlineMs,
746
+ });
747
+ if (Date.now() >= splitDeadlineMs) throw error;
748
+ const second = await readReceiptsSplittingOnTimeout({
749
+ ...input,
750
+ keys: right,
751
+ splitDeadlineMs,
752
+ });
753
+ return [...first, ...second];
754
+ }
755
+ }
756
+
582
757
  async function sendReceiptCommands(input: {
583
758
  context: WorkerRuntimeApiContext;
584
759
  playName: string;
585
760
  commands: readonly ReceiptCommand[];
761
+ onReadSplit?: (event: ReceiptReadSplitEvent) => void;
586
762
  }): Promise<readonly ReceiptOutput[]> {
587
763
  const first = input.commands[0];
588
764
  if (!first) return [];
@@ -592,16 +768,18 @@ async function sendReceiptCommands(input: {
592
768
  ReceiptCommand,
593
769
  { kind: 'get' }
594
770
  >[];
595
- return await getRuntimeStepReceiptsViaAppRuntime(input.context, {
771
+ // The batch key separates manifest reads from full reads, so a batch is
772
+ // uniform. Keep the conservative check: a full read is never narrowed
773
+ // to a manifest because one command in its batch asked for one.
774
+ return await readReceiptsSplittingOnTimeout({
775
+ context: input.context,
596
776
  playName: input.playName,
597
777
  runId: first.input.runId,
598
778
  keys: commands.map((command) => command.input.key),
599
- // A mixed writer batch must preserve normal full reads. The manifest
600
- // probe safely falls back to its byte-admitted path when it receives a
601
- // body, so never omit an output a concurrent caller requested.
602
- ...(commands.every((command) => command.input.hydrateOutput === false)
603
- ? { hydrateOutput: false }
604
- : {}),
779
+ hydrateOutput: !commands.every(
780
+ (command) => command.input.hydrateOutput === false,
781
+ ),
782
+ ...(input.onReadSplit ? { onReadSplit: input.onReadSplit } : {}),
605
783
  });
606
784
  }
607
785
  case 'claim': {
@@ -17,6 +17,8 @@ type PendingWrite<Input, Output> = {
17
17
  lane: string;
18
18
  keyIds: readonly unknown[];
19
19
  bytes: number;
20
+ /** Expected response bytes; 0 unless `estimateResponseBytes` is set. */
21
+ responseBytes: number;
20
22
  signal: AbortSignal | null;
21
23
  state: 'queued' | 'active' | 'settled';
22
24
  aborted: unknown;
@@ -168,6 +170,8 @@ export class RuntimeReceiptWriter<Input, Output> {
168
170
  error: unknown,
169
171
  ) => RetryableReceiptError | null;
170
172
  readonly #estimateBytes: (input: Input) => number;
173
+ readonly #estimateResponseBytes: ((input: Input) => number) | null;
174
+ readonly #maxBatchResponseBytes: number;
171
175
  readonly #maxBatchSize: number;
172
176
  readonly #maxBatchBytes: number;
173
177
  readonly #targetBatchBytes: number;
@@ -239,6 +243,14 @@ export class RuntimeReceiptWriter<Input, Output> {
239
243
  ) => Promise<readonly Output[]>;
240
244
  classifyRetryableError?: (error: unknown) => RetryableReceiptError | null;
241
245
  estimateBytes?: (input: Input) => number;
246
+ /**
247
+ * Expected size of the response a command asks for. A read request is a
248
+ * few hundred bytes, but what it returns can be megabytes: request bytes
249
+ * alone cannot bound it. Batches close before their summed estimate passes
250
+ * `maxBatchResponseBytes`; a single command always forms a batch.
251
+ */
252
+ estimateResponseBytes?: (input: Input) => number;
253
+ maxBatchResponseBytes?: number;
242
254
  maxBatchSize?: number;
243
255
  maxBatchBytes?: number;
244
256
  targetBatchBytes?: number;
@@ -283,6 +295,11 @@ export class RuntimeReceiptWriter<Input, Output> {
283
295
  this.#classifyRetryableError =
284
296
  options.classifyRetryableError ?? (() => null);
285
297
  this.#estimateBytes = options.estimateBytes ?? estimateJsonBytes;
298
+ this.#estimateResponseBytes = options.estimateResponseBytes ?? null;
299
+ this.#maxBatchResponseBytes = normalizePositiveInteger(
300
+ options.maxBatchResponseBytes,
301
+ Number.MAX_SAFE_INTEGER,
302
+ );
286
303
  this.#maxBatchSize = normalizePositiveInteger(options.maxBatchSize, 100);
287
304
  this.#maxBufferedBytes = normalizePositiveInteger(
288
305
  options.maxBufferedBytes,
@@ -457,6 +474,9 @@ export class RuntimeReceiptWriter<Input, Output> {
457
474
  ...new Set(this.#orderingKeys(input).map(orderingKeyIdentity)),
458
475
  ],
459
476
  bytes,
477
+ responseBytes: this.#estimateResponseBytes
478
+ ? Math.max(0, Math.ceil(this.#estimateResponseBytes(input)))
479
+ : 0,
460
480
  signal: options.signal ?? null,
461
481
  state: 'queued',
462
482
  aborted: null,
@@ -771,6 +791,7 @@ export class RuntimeReceiptWriter<Input, Output> {
771
791
  let selectedBatchKey: unknown;
772
792
  let selectedLane: string | null = null;
773
793
  let batchBytes = 0;
794
+ let batchResponseBytes = 0;
774
795
 
775
796
  for (;;) {
776
797
  // The oldest command among the open lanes.
@@ -803,6 +824,7 @@ export class RuntimeReceiptWriter<Input, Output> {
803
824
  selectedBatchKey = this.#batchKey(pending.input);
804
825
  selectedLane = pending.lane;
805
826
  batchBytes = pending.bytes;
827
+ batchResponseBytes = pending.responseBytes;
806
828
  continue;
807
829
  }
808
830
 
@@ -816,12 +838,14 @@ export class RuntimeReceiptWriter<Input, Output> {
816
838
  selectedLane !== pending.lane ||
817
839
  !Object.is(this.#batchKey(pending.input), selectedBatchKey) ||
818
840
  selected.length >= this.#maxBatchSize ||
819
- batchBytes + pending.bytes > this.#targetBatchBytes
841
+ batchBytes + pending.bytes > this.#targetBatchBytes ||
842
+ batchResponseBytes + pending.responseBytes > this.#maxBatchResponseBytes
820
843
  ) {
821
844
  break;
822
845
  }
823
846
  selected.push(pending);
824
847
  batchBytes += pending.bytes;
848
+ batchResponseBytes += pending.responseBytes;
825
849
  }
826
850
  return selected;
827
851
  }
@@ -54,6 +54,11 @@ export function isIsolatedRuntimeSchedulerSchema(
54
54
  * correctness. Isolated schemas deliberately share a small direct-connection
55
55
  * budget across preview workers, so they use that polling path and leave
56
56
  * direct sessions to the production topology.
57
+ *
58
+ * The same answer decides whether the schema sends NOTIFY at all
59
+ * (`postgresSchedulerNotifySql`, `absurd-wake-policy.ts`): every notifying
60
+ * commit serializes on one cluster-wide lock, heard or not, so a schema that
61
+ * nobody LISTENs on stays silent, and one that gains listeners notifies again.
57
62
  */
58
63
  export function shouldUseRuntimeSchedulerDirectNotify(
59
64
  schedulerSchema: string | null | undefined,
@@ -133,6 +133,7 @@ import {
133
133
  selectRuntimeSandboxCanary,
134
134
  } from '../runtime-sandbox-placement-policy';
135
135
  import {
136
+ isIsolatedRuntimeSchedulerSchema,
136
137
  resolvePreviewWorkerClaimAffinityReader,
137
138
  resolvePreviewWorkerListenerElection,
138
139
  shouldUseRuntimeSchedulerDirectNotify,
@@ -333,6 +334,12 @@ import {
333
334
  withRuntimeSchedulerClient,
334
335
  } from './postgres-pool';
335
336
  import { runWithAbsurdSchedulerQuerySignal } from './absurd-pool';
337
+ import {
338
+ absurdWorkerWakeLeaderLockKey,
339
+ clearAbsurdQueueWakeUnheard,
340
+ clearAbsurdQueueWakeUnheardForListener,
341
+ markAbsurdQueueWakeUnheard,
342
+ } from './absurd-wake-policy';
336
343
  import {
337
344
  createEarlySandboxClaimGate,
338
345
  EARLY_SANDBOX_CLAIM_AFFINITY_READER,
@@ -11764,7 +11771,7 @@ export function createAbsurdWorkerWakeHook(input: {
11764
11771
  url: input.poolOptions.url,
11765
11772
  channel: ABSURD_WAKE_CHANNEL,
11766
11773
  applicationName: 'deepline-absurd-worker-wake',
11767
- leaderLockKey: `deepline:absurd-wake:${input.queue}`,
11774
+ leaderLockKey: absurdWorkerWakeLeaderLockKey(input.queue),
11768
11775
  });
11769
11776
  if (!lease) return () => wakeHandlers.delete(wake);
11770
11777
  const unsubscribeNotify = lease.hub.subscribe((payload) => {
@@ -12230,6 +12237,33 @@ export async function startRuntimeWorkerHost(
12230
12237
  previewDirectNotifyWake: PREVIEW_WORKER_DIRECT_NOTIFY_WAKE,
12231
12238
  previewListenerElection,
12232
12239
  });
12240
+ // An isolated lane whose workers will not LISTEN marks its queue so the
12241
+ // engine stops sending wakes nobody hears (`absurd-wake-policy.ts`). A
12242
+ // listener that wins the election clears it below. Production never marks.
12243
+ const isolatedQueueWakePolicy = isIsolatedRuntimeSchedulerSchema(
12244
+ schedulerOptions.schema,
12245
+ );
12246
+ if (isolatedQueueWakePolicy && (!useDirectNotify || drainExit)) {
12247
+ // A failed mark leaves the queue notifying, which is today's behavior;
12248
+ // it must not stop the lane from serving.
12249
+ try {
12250
+ const outcome = await withRuntimeSchedulerClient(poolOptions, (client) =>
12251
+ markAbsurdQueueWakeUnheard(client, queue),
12252
+ );
12253
+ console.info('[absurd-runtime.worker] queue_wake_policy', {
12254
+ event: 'mark_unheard',
12255
+ queue,
12256
+ outcome,
12257
+ });
12258
+ } catch (error) {
12259
+ console.error('[absurd-runtime.worker] queue_wake_policy', {
12260
+ event: 'mark_unheard_failed',
12261
+ queue,
12262
+ error: error instanceof Error ? error.message : String(error),
12263
+ });
12264
+ }
12265
+ }
12266
+ let restoreQueueWakesForListener: (() => void) | null = null;
12233
12267
  // LH: this process's listener generations for its queue (in memory).
12234
12268
  const listenerLeadership = createEarlySandboxListenerLeadership({ queue });
12235
12269
  const onWake = createAbsurdWorkerWakeHook({
@@ -12249,8 +12283,33 @@ export async function startRuntimeWorkerHost(
12249
12283
  queue,
12250
12284
  generation: listening ? listenerLeadership.generation() : ended,
12251
12285
  });
12286
+ if (listening) restoreQueueWakesForListener?.();
12252
12287
  },
12253
12288
  });
12289
+ if (isolatedQueueWakePolicy && onWake) {
12290
+ restoreQueueWakesForListener = () => {
12291
+ void clearAbsurdQueueWakeUnheardForListener({
12292
+ clear: () =>
12293
+ withRuntimeSchedulerClient(poolOptions, (client) =>
12294
+ clearAbsurdQueueWakeUnheard(client, queue),
12295
+ ),
12296
+ stillListening: () => onWake.isListening(),
12297
+ wake: () => onWake.wake(),
12298
+ onError: (error) =>
12299
+ console.error('[absurd-runtime.worker] queue_wake_policy', {
12300
+ event: 'clear_unheard_failed',
12301
+ queue,
12302
+ error: error instanceof Error ? error.message : String(error),
12303
+ }),
12304
+ }).then((outcome) =>
12305
+ console.info('[absurd-runtime.worker] queue_wake_policy', {
12306
+ event: 'clear_unheard',
12307
+ queue,
12308
+ outcome,
12309
+ }),
12310
+ );
12311
+ };
12312
+ }
12254
12313
  claimAffinityWake = onWake ? () => onWake.wake() : null;
12255
12314
  let ownerProbeStopped = false;
12256
12315
  const earlySandboxClaimOwner: RuntimeWorkerHost['earlySandboxClaimOwner'] =
@@ -12617,14 +12676,25 @@ export async function startRuntimeWorkerHost(
12617
12676
  // One bounded read: a slow or failed check creates as before.
12618
12677
  ...earlySandboxOrgCapacityCheckForAdmissionMode(
12619
12678
  runtimeSandboxCapacityAdmissionMode(),
12620
- ({ orgId, runId }: { orgId: string; runId: string }) =>
12679
+ ({
12680
+ orgId,
12681
+ runId,
12682
+ entitlementLimit,
12683
+ }: {
12684
+ orgId: string;
12685
+ runId: string;
12686
+ entitlementLimit: number | null;
12687
+ }) =>
12621
12688
  withEarlySandboxOrgCapacityDeadline(
12622
12689
  withRuntimeSchedulerClient(
12623
12690
  poolOptions,
12624
12691
  (client) =>
12625
12692
  precheckRuntimeSandboxCapacity(
12626
12693
  client,
12627
- { orgId, runId },
12694
+ // The hint's carried entitlement, as the launch passes
12695
+ // `concurrentRunsLimit`: a plan-limited org has no cache
12696
+ // row, so without it the check would judge the default.
12697
+ { orgId, runId, entitlementLimit },
12628
12698
  schedulerOptions.schema
12629
12699
  ? { schema: schedulerOptions.schema }
12630
12700
  : {},