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
@@ -71,6 +71,7 @@ import type {
71
71
  import {
72
72
  normalizeRuntimeSchedulerSchema,
73
73
  PROD_DEFAULT_RUNTIME_SCHEDULER_SCHEMA,
74
+ shouldUseRuntimeSchedulerDirectNotify,
74
75
  } from '../runtime-scheduler-topology';
75
76
  import {
76
77
  RUNTIME_EVENT_CANONICAL_RETENTION_INDEX_READY_MARKER,
@@ -265,6 +266,7 @@ import {
265
266
  readAbsurdSchemaNoSchedulerOrgCapCompatibilitySql,
266
267
  readAbsurdSchemaSql,
267
268
  } from './absurd-pool';
269
+ import { installAbsurdQueueWakePolicy } from './absurd-wake-policy';
268
270
  import {
269
271
  isImmutableRuntimeExecutionRecoveryOrigin,
270
272
  runtimeApiBaseUrlFromLaunch,
@@ -1177,6 +1179,59 @@ export function postgresSchedulerNotifyChannel(
1177
1179
  .slice(0, 12);
1178
1180
  return `${channel.slice(0, 63 - fingerprint.length - 1)}_${fingerprint}`;
1179
1181
  }
1182
+ /**
1183
+ * Whether anything LISTENs on this scheduler schema's own channels
1184
+ * (`postgresSchedulerNotifyChannel`). The topology predicate that keeps the
1185
+ * Run Ledger projector and the terminal hub off LISTEN in an isolated
1186
+ * (Preview/dev) schema decides it, so a schema that gains a listener regains
1187
+ * its notifications in the same change.
1188
+ */
1189
+ export function postgresSchedulerSchemaHasNotifyListeners(
1190
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
1191
+ ): boolean {
1192
+ return shouldUseRuntimeSchedulerDirectNotify(schemaName(options));
1193
+ }
1194
+
1195
+ /**
1196
+ * The one way scheduler SQL sends a NOTIFY. PostgreSQL serializes the commit
1197
+ * of every notifying transaction on one cluster-wide lock, listened to or not,
1198
+ * so a schema without listeners must not notify: on the shared Preview
1199
+ * database those unheard wake-ups queued half the active backends behind that
1200
+ * lock. Durable polling owns correctness there.
1201
+ *
1202
+ * The silent form keeps the expression, its row shape and its parameter types
1203
+ * (`$n` stay referenced) while the planner folds the call away. A schema with
1204
+ * listeners, including Production's, gets the exact `pg_notify` call.
1205
+ * `bun run check:runtime-compatibility` rejects a `pg_notify` written anywhere
1206
+ * else in runtime code.
1207
+ */
1208
+ export function postgresSchedulerNotifySql(
1209
+ options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
1210
+ channelSql: string,
1211
+ payloadSql: string,
1212
+ ): string {
1213
+ const call = `pg_notify(${channelSql}, ${payloadSql})`;
1214
+ return postgresSchedulerSchemaHasNotifyListeners(options)
1215
+ ? call
1216
+ : `CASE WHEN false THEN ${call} END`;
1217
+ }
1218
+
1219
+ /**
1220
+ * A scheduler statement that calls an Absurd engine function such as
1221
+ * `absurd.emit_event` also sends its own `absurd_wake` echo. The engine
1222
+ * function already notifies the queue in the same transaction (patch (e)),
1223
+ * and in an isolated schema it consults the queue's wake policy
1224
+ * (`absurd-wake-policy.ts`), which an unconditional echo would defeat. So the
1225
+ * echo is sent only where the scheduler schema has listeners (Production).
1226
+ */
1227
+ export function absurdEngineWakeEchoSql(
1228
+ options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
1229
+ channelSql: string,
1230
+ queueSql: string,
1231
+ ): string {
1232
+ return postgresSchedulerNotifySql(options, channelSql, queueSql);
1233
+ }
1234
+
1180
1235
  const DEFAULT_POLL_INTERVAL_MS = 1_000;
1181
1236
  /**
1182
1237
  * An interactive start stream (`observe({ startupPolling: true })`) reads the
@@ -3141,27 +3196,43 @@ export async function ensurePostgresSchedulerOutboxWakeTrigger(
3141
3196
  ) AS present`,
3142
3197
  [tableName('outbox', options), triggerName],
3143
3198
  );
3144
- if (present.rows[0]?.present === true) return;
3199
+ const triggerPresent = present.rows[0]?.present === true;
3200
+ // Production keeps its installed trigger untouched.
3201
+ const listened = postgresSchedulerSchemaHasNotifyListeners(options);
3202
+ if (triggerPresent && listened) return;
3145
3203
 
3146
3204
  const channel = postgresSchedulerNotifyChannel('outbox', options);
3147
- await client.query(`
3148
- CREATE OR REPLACE FUNCTION ${quotedSchema}.notify_run_ledger_outbox()
3149
- RETURNS trigger
3150
- LANGUAGE plpgsql
3151
- AS $$
3205
+ const body = `
3152
3206
  BEGIN
3153
- PERFORM pg_notify(
3154
- '${channel}',
3155
- json_build_object(
3207
+ PERFORM ${postgresSchedulerNotifySql(
3208
+ options,
3209
+ `'${channel}'`,
3210
+ `json_build_object(
3156
3211
  'eventId', NEW.event_id,
3157
3212
  'runId', NEW.run_id,
3158
3213
  'eventType', NEW.event_type
3159
- )::text
3160
- );
3214
+ )::text`,
3215
+ )};
3161
3216
  RETURN NEW;
3162
3217
  END
3163
- $$
3218
+ `;
3219
+ if (triggerPresent) {
3220
+ // An isolated schema whose trigger predates its silent NOTIFY keeps the
3221
+ // trigger (schema readiness requires it) and swaps only the body, once.
3222
+ const installed = await client.query<{ current: boolean }>(
3223
+ `SELECT prosrc = $1::text AS current FROM pg_proc
3224
+ WHERE oid = to_regprocedure($2)`,
3225
+ [body, `${quotedSchema}.notify_run_ledger_outbox()`],
3226
+ );
3227
+ if (installed.rows[0]?.current === true) return;
3228
+ }
3229
+ await client.query(`
3230
+ CREATE OR REPLACE FUNCTION ${quotedSchema}.notify_run_ledger_outbox()
3231
+ RETURNS trigger
3232
+ LANGUAGE plpgsql
3233
+ AS $$${body}$$
3164
3234
  `);
3235
+ if (triggerPresent) return;
3165
3236
  await client.query(`
3166
3237
  CREATE TRIGGER ${triggerName}
3167
3238
  AFTER INSERT ON ${tableName('outbox', options)}
@@ -5870,15 +5941,30 @@ function absurdSchemaInitAdvisoryLockKey(): readonly [number, number] {
5870
5941
  * This is a separate exported function so the absurd scheduler-backend can call
5871
5942
  * it explicitly; it is NOT wired into `ensurePostgresSchedulerSchema`, so
5872
5943
  * existing postgres-store consumers never pay for absurd DDL.
5944
+ *
5945
+ * `installQueueWakePolicy` is set only by a migration of an isolated
5946
+ * (Preview/dev) scheduler schema. It installs the per-queue wake policy
5947
+ * (`absurd-wake-policy.ts`) on that database's shared engine, guarding the
5948
+ * engine functions as installed. A Production migration never sets it, so
5949
+ * Production's engine functions stay exactly as installed.
5873
5950
  */
5874
5951
  export async function ensureAbsurdSchema(
5875
5952
  client: PostgresSchedulerQueryClient,
5876
- options: { refreshClaimBody?: boolean } = {},
5953
+ options: {
5954
+ refreshClaimBody?: boolean;
5955
+ installQueueWakePolicy?: boolean;
5956
+ } = {},
5877
5957
  ): Promise<void> {
5878
5958
  const [lockClassId, lockObjectId] = absurdSchemaInitAdvisoryLockKey();
5879
5959
  let stage = 'begin transaction';
5880
5960
  let transactionStarted = false;
5881
5961
  let committed = false;
5962
+ // Runs inside the bootstrap transaction, under its advisory lock.
5963
+ const ensureQueueWakePolicy = async () => {
5964
+ if (!options.installQueueWakePolicy) return;
5965
+ stage = 'apply Absurd queue wake policy';
5966
+ await installAbsurdQueueWakePolicy(client);
5967
+ };
5882
5968
  try {
5883
5969
  await client.query('BEGIN');
5884
5970
  transactionStarted = true;
@@ -5959,6 +6045,7 @@ export async function ensureAbsurdSchema(
5959
6045
  readAbsurdSchemaNoSchedulerOrgCapCompatibilityMarkerSql(),
5960
6046
  );
5961
6047
  }
6048
+ await ensureQueueWakePolicy();
5962
6049
  stage = 'commit verified Absurd schema bootstrap';
5963
6050
  await client.query('COMMIT');
5964
6051
  committed = true;
@@ -5983,6 +6070,7 @@ export async function ensureAbsurdSchema(
5983
6070
  await client.query(
5984
6071
  readAbsurdSchemaNoSchedulerOrgCapCompatibilityMarkerSql(),
5985
6072
  );
6073
+ await ensureQueueWakePolicy();
5986
6074
  stage = 'commit newly initialized Absurd schema';
5987
6075
  await client.query('COMMIT');
5988
6076
  committed = true;
@@ -6630,7 +6718,7 @@ async function submitPostgresSchedulerRunTransaction(
6630
6718
  (SELECT launch_json FROM existing_run) AS existing_launch_json,
6631
6719
  CASE WHEN EXISTS (SELECT 1 FROM run_insert)
6632
6720
  OR EXISTS (SELECT 1 FROM run_recovery)
6633
- THEN pg_notify($9, $10)
6721
+ THEN ${postgresSchedulerNotifySql(options, '$9', '$10')}
6634
6722
  END
6635
6723
  FROM admission
6636
6724
  `,
@@ -9734,13 +9822,14 @@ export async function failPostgresSchedulerScheduledChildWaits(
9734
9822
  ON CONFLICT (event_id) DO NOTHING
9735
9823
  RETURNING run_id
9736
9824
  ), notify_terminal AS (
9737
- SELECT pg_notify(
9738
- $3,
9739
- json_build_object(
9825
+ SELECT ${postgresSchedulerNotifySql(
9826
+ options,
9827
+ '$3',
9828
+ `json_build_object(
9740
9829
  'kind', 'scheduled_child_cutover',
9741
9830
  'runs', (SELECT count(*) FROM terminal_runs)
9742
- )::text
9743
- )
9831
+ )::text`,
9832
+ )}
9744
9833
  WHERE EXISTS (SELECT 1 FROM terminal_runs)
9745
9834
  )
9746
9835
  SELECT terminal_runs.run_id
@@ -14495,14 +14584,14 @@ export async function directCompletePostgresSchedulerRunnerTerminal(
14495
14584
  ON CONFLICT (event_id) DO NOTHING
14496
14585
  ),
14497
14586
  notify_terminal AS (
14498
- SELECT run_id, pg_notify($9, $10) FROM run_terminal
14587
+ SELECT run_id, ${postgresSchedulerNotifySql(options, '$9', '$10')} FROM run_terminal
14499
14588
  ),
14500
14589
  engine_wake AS (
14501
14590
  SELECT run_id, absurd.emit_event($12, $13, 'null'::jsonb)
14502
14591
  FROM notify_terminal
14503
14592
  ),
14504
14593
  notify_engine AS (
14505
- SELECT run_id, pg_notify($14, $12) FROM engine_wake
14594
+ SELECT run_id, ${absurdEngineWakeEchoSql(options, '$14', '$12')} FROM engine_wake
14506
14595
  )
14507
14596
  SELECT run_id FROM notify_engine
14508
14597
  `,
@@ -14677,7 +14766,7 @@ export async function directCompletePostgresSchedulerRunnerTerminal(
14677
14766
  FROM stale_attempt
14678
14767
  ),
14679
14768
  notify_engine AS (
14680
- SELECT run_id, pg_notify($7, $5) FROM engine_wake
14769
+ SELECT run_id, ${absurdEngineWakeEchoSql(options, '$7', '$5')} FROM engine_wake
14681
14770
  )
14682
14771
  SELECT run_id FROM notify_engine
14683
14772
  `,
@@ -18447,7 +18536,7 @@ export async function completePostgresSchedulerAttempt(
18447
18536
  ON CONFLICT (event_id) DO NOTHING
18448
18537
  ),
18449
18538
  notify_terminal AS (
18450
- SELECT run_id, pg_notify($6, $7) FROM run_terminal
18539
+ SELECT run_id, ${postgresSchedulerNotifySql(options, '$6', '$7')} FROM run_terminal
18451
18540
  )
18452
18541
  SELECT run_id FROM notify_terminal
18453
18542
  `,
@@ -18855,7 +18944,7 @@ export async function failPostgresSchedulerAttempt(
18855
18944
  ON CONFLICT (event_id) DO NOTHING
18856
18945
  ),
18857
18946
  notify_terminal AS (
18858
- SELECT run_id, pg_notify($6, $7) FROM run_terminal
18947
+ SELECT run_id, ${postgresSchedulerNotifySql(options, '$6', '$7')} FROM run_terminal
18859
18948
  )
18860
18949
  SELECT run_id FROM notify_terminal
18861
18950
  `,
@@ -19208,7 +19297,7 @@ export async function cancelPostgresSchedulerRun(
19208
19297
  ON CONFLICT (event_id) DO NOTHING
19209
19298
  ),
19210
19299
  notify_terminal AS (
19211
- SELECT run_id, pg_notify($3, $4) FROM cancelled_run
19300
+ SELECT run_id, ${postgresSchedulerNotifySql(options, '$3', '$4')} FROM cancelled_run
19212
19301
  )
19213
19302
  SELECT cancelled_run.run_id, cancelled_run.launch_json
19214
19303
  FROM cancelled_run
@@ -20699,13 +20788,176 @@ export async function getPostgresSchedulerReceipt(
20699
20788
  return result.rows[0] ? mapReceiptRow(result.rows[0]) : null;
20700
20789
  }
20701
20790
 
20791
+ /**
20792
+ * Stored (TOAST-compressed) bytes one grouped full-read query may return.
20793
+ * `pg_column_size` reads a stored value's size without decompressing it, so
20794
+ * a multi-key read is priced before any body is fetched. Page and scrape
20795
+ * bodies compress four- to six-fold, so a group decodes to roughly 8-12 MiB.
20796
+ */
20797
+ export const POSTGRES_RECEIPT_READ_GROUP_STORED_BYTES = 2 * 1024 * 1024;
20798
+
20799
+ /**
20800
+ * Split keys, in order, into groups whose stored output stays under the
20801
+ * budget. A key larger than the budget forms its own group; a group always
20802
+ * holds at least one key.
20803
+ */
20804
+ export function groupReceiptKeysByStoredBytes(
20805
+ keys: readonly string[],
20806
+ storedBytesByKey: ReadonlyMap<string, number>,
20807
+ maxGroupStoredBytes: number,
20808
+ ): string[][] {
20809
+ const groups: string[][] = [];
20810
+ let current: string[] = [];
20811
+ let currentBytes = 0;
20812
+ for (const key of keys) {
20813
+ const bytes = storedBytesByKey.get(key) ?? 0;
20814
+ if (current.length > 0 && currentBytes + bytes > maxGroupStoredBytes) {
20815
+ groups.push(current);
20816
+ current = [];
20817
+ currentBytes = 0;
20818
+ }
20819
+ current.push(key);
20820
+ currentBytes += bytes;
20821
+ }
20822
+ if (current.length > 0) groups.push(current);
20823
+ return groups;
20824
+ }
20825
+
20826
+ async function selectPostgresSchedulerReceiptRows(
20827
+ client: PostgresSchedulerQueryClient,
20828
+ keys: readonly string[],
20829
+ options: PostgresSchedulerReceiptOptions,
20830
+ maxGroupStoredBytes?: number,
20831
+ ): Promise<Array<RuntimeStepReceipt | null>> {
20832
+ const result = await client.query<ReceiptRow & { ord: number | string }>(
20833
+ `
20834
+ WITH inputs AS (
20835
+ SELECT key_values.k,
20836
+ key_values.ord
20837
+ FROM unnest($1::text[]) WITH ORDINALITY AS key_values(k, ord)
20838
+ )
20839
+ ${
20840
+ maxGroupStoredBytes === undefined
20841
+ ? ''
20842
+ : `,
20843
+ priced AS (
20844
+ SELECT inputs.ord,
20845
+ SUM(COALESCE(pg_column_size(r.output_json), 0)) OVER (ORDER BY inputs.ord) AS cumulative_bytes
20846
+ FROM inputs
20847
+ LEFT JOIN ${tableName('receipts', options)} AS r
20848
+ ON r.org_id = $2 AND r.k = inputs.k
20849
+ )`
20850
+ }
20851
+ SELECT receipt.k,
20852
+ receipt.status,
20853
+ receipt.output_json,
20854
+ receipt.output_ref,
20855
+ receipt.error,
20856
+ receipt.error_payload,
20857
+ receipt.failure_kind,
20858
+ receipt.run_id,
20859
+ receipt.lease_id,
20860
+ receipt.lease_owner_run_id,
20861
+ receipt.lease_owner_attempt,
20862
+ receipt.lease_expires_at,
20863
+ inputs.ord
20864
+ FROM inputs
20865
+ LEFT JOIN ${tableName('receipts', options)} AS receipt
20866
+ ON receipt.org_id = $2
20867
+ AND receipt.k = inputs.k
20868
+ ${
20869
+ maxGroupStoredBytes === undefined
20870
+ ? ''
20871
+ : `
20872
+ JOIN priced ON priced.ord = inputs.ord
20873
+ AND (priced.ord = 1 OR priced.cumulative_bytes <= $3)`
20874
+ }
20875
+ ORDER BY inputs.ord
20876
+ `,
20877
+ maxGroupStoredBytes === undefined
20878
+ ? [[...keys], receiptOrgId(options)]
20879
+ : [[...keys], receiptOrgId(options), maxGroupStoredBytes],
20880
+ );
20881
+ return result.rows.map((row) => (row.k ? mapReceiptRow(row) : null));
20882
+ }
20883
+
20702
20884
  export async function getPostgresSchedulerReceipts(
20885
+ client: PostgresSchedulerQueryClient,
20886
+ input: GetRuntimeStepReceiptsInput,
20887
+ options: PostgresSchedulerReceiptOptions & {
20888
+ /** Test seam for the stored-byte budget of one grouped query. */
20889
+ maxGroupStoredBytes?: number;
20890
+ },
20891
+ ): Promise<Array<RuntimeStepReceipt | null>> {
20892
+ if (input.keys.length === 0) return [];
20893
+ if (input.keys.length === 1) {
20894
+ return await selectPostgresSchedulerReceiptRows(client, input.keys, options);
20895
+ }
20896
+ // A key-count bound is not a byte bound: 200 page bodies in one statement
20897
+ // ran past the 30 s read timeout on 1 December 2026, for runners of every
20898
+ // version. Price the rows first (no body is decompressed or sent), then
20899
+ // read the bodies in groups under a stored-byte budget.
20900
+ const sizes = await client.query<{ k: string; stored_bytes: number | string }>(
20901
+ `
20902
+ SELECT receipt.k,
20903
+ COALESCE(pg_column_size(receipt.output_json), 0) AS stored_bytes
20904
+ FROM ${tableName('receipts', options)} AS receipt
20905
+ WHERE receipt.org_id = $2
20906
+ AND receipt.k = ANY($1::text[])
20907
+ `,
20908
+ [input.keys, receiptOrgId(options)],
20909
+ );
20910
+ // The size probe is also an existence read. A cold cohort has no bodies
20911
+ // to hydrate. Return its misses from this snapshot without a second trip.
20912
+ if (sizes.rows.length === 0) return input.keys.map(() => null);
20913
+ const storedBytesByKey = new Map(
20914
+ sizes.rows.map((row) => [row.k, Number(row.stored_bytes) || 0]),
20915
+ );
20916
+ const budget =
20917
+ options.maxGroupStoredBytes ?? POSTGRES_RECEIPT_READ_GROUP_STORED_BYTES;
20918
+ const groups = groupReceiptKeysByStoredBytes(
20919
+ input.keys,
20920
+ storedBytesByKey,
20921
+ budget,
20922
+ );
20923
+ const receipts: Array<RuntimeStepReceipt | null> = [];
20924
+ for (const group of groups) {
20925
+ // A running or missing receipt can acquire a body after the size probe.
20926
+ // Check the prefix against the snapshot that supplies the actual bodies.
20927
+ let offset = 0;
20928
+ while (offset < group.length) {
20929
+ const remaining = group.slice(offset);
20930
+ const rows = await selectPostgresSchedulerReceiptRows(
20931
+ client,
20932
+ remaining,
20933
+ options,
20934
+ remaining.length > 1 ? budget : undefined,
20935
+ );
20936
+ if (!rows.length)
20937
+ throw new Error('Receipt read returned no input positions');
20938
+ receipts.push(...rows);
20939
+ offset += rows.length;
20940
+ }
20941
+ }
20942
+ return receipts;
20943
+ }
20944
+
20945
+ /**
20946
+ * Receipt manifests: status, lease facts, error and output reference, never
20947
+ * the inline body. The size is computed in Postgres, so a manifest read moves
20948
+ * no body to the gateway. `outputByteLength` here is the length of the stored
20949
+ * JSON's text form, which can exceed `JSON.stringify` by its separator
20950
+ * spacing: callers use it as an admission price, never as an identity.
20951
+ */
20952
+ export async function getPostgresSchedulerReceiptManifests(
20703
20953
  client: PostgresSchedulerQueryClient,
20704
20954
  input: GetRuntimeStepReceiptsInput,
20705
20955
  options: PostgresSchedulerReceiptOptions,
20706
20956
  ): Promise<Array<RuntimeStepReceipt | null>> {
20707
20957
  if (input.keys.length === 0) return [];
20708
- const result = await client.query<ReceiptRow & { ord: number | string }>(
20958
+ const result = await client.query<
20959
+ ReceiptRow & { ord: number | string; output_text_bytes: number | string | null }
20960
+ >(
20709
20961
  `
20710
20962
  WITH inputs AS (
20711
20963
  SELECT key_values.k,
@@ -20714,7 +20966,11 @@ export async function getPostgresSchedulerReceipts(
20714
20966
  )
20715
20967
  SELECT receipt.k,
20716
20968
  receipt.status,
20717
- receipt.output_json,
20969
+ NULL::jsonb AS output_json,
20970
+ CASE
20971
+ WHEN receipt.output_json IS NULL THEN NULL
20972
+ ELSE octet_length(receipt.output_json::text)
20973
+ END AS output_text_bytes,
20718
20974
  receipt.output_ref,
20719
20975
  receipt.error,
20720
20976
  receipt.error_payload,
@@ -20733,7 +20989,17 @@ export async function getPostgresSchedulerReceipts(
20733
20989
  `,
20734
20990
  [input.keys, receiptOrgId(options)],
20735
20991
  );
20736
- return result.rows.map((row) => (row.k ? mapReceiptRow(row) : null));
20992
+ return result.rows.map((row) => {
20993
+ if (!row.k) return null;
20994
+ const receipt = mapReceiptRow(row);
20995
+ const textBytes =
20996
+ row.output_text_bytes === null || row.output_text_bytes === undefined
20997
+ ? null
20998
+ : Number(row.output_text_bytes);
20999
+ return receipt.outputRef || textBytes === null || !Number.isSafeInteger(textBytes)
21000
+ ? receipt
21001
+ : { ...receipt, outputByteLength: textBytes };
21002
+ });
20737
21003
  }
20738
21004
 
20739
21005
  type ObservationRow = {
@@ -20921,6 +21187,38 @@ export async function getPostgresSchedulerObservationsForRuns(
20921
21187
  return result.rows.map(mapObservationRow);
20922
21188
  }
20923
21189
 
21190
+ /**
21191
+ * Which of a bounded page of runs recorded any settled observation: one
21192
+ * existence probe per run over the observations primary key (`org_id`,
21193
+ * `run_id` prefix), never a scan of each run's rows. Org-scoped like every
21194
+ * observation read.
21195
+ */
21196
+ export async function getPostgresSchedulerObservedRunIds(
21197
+ client: PostgresSchedulerQueryClient,
21198
+ input: { runIds: readonly string[] },
21199
+ options: PostgresSchedulerReceiptOptions,
21200
+ ): Promise<string[]> {
21201
+ const runIds = [
21202
+ ...new Set(input.runIds.map((runId) => runId.trim()).filter(Boolean)),
21203
+ ];
21204
+ if (runIds.length === 0) return [];
21205
+ const result = await client.query<{ run_id: string }>(
21206
+ `
21207
+ SELECT asked.run_id
21208
+ FROM unnest($2::text[]) AS asked(run_id)
21209
+ WHERE EXISTS (
21210
+ SELECT 1
21211
+ FROM ${tableName('observations', options)} observed
21212
+ WHERE observed.org_id = $1
21213
+ AND observed.run_id = asked.run_id
21214
+ AND observed.status IN ('completed', 'failed')
21215
+ )
21216
+ `,
21217
+ [receiptOrgId(options), runIds],
21218
+ );
21219
+ return result.rows.map((row) => row.run_id);
21220
+ }
21221
+
20924
21222
  /**
20925
21223
  * The newest settled observation of EVERY node for a bounded page of runs, in
20926
21224
  * one org-scoped read over the observations primary key — what a runs grid's
@@ -24753,7 +25051,7 @@ function runLedgerOutboxPrefixClaimSql(
24753
25051
  ${
24754
25052
  acknowledgement
24755
25053
  ? `, notified AS MATERIALIZED (
24756
- ${runLedgerDeliveredNotificationsSql('$7', acknowledgement.createdProjectionWake ? { queue: '$8', event: '$9' } : undefined)}
25054
+ ${runLedgerDeliveredNotificationsSql(options, '$7', acknowledgement.createdProjectionWake ? { queue: '$8', event: '$9' } : undefined)}
24757
25055
  )`
24758
25056
  : ''
24759
25057
  }
@@ -25050,8 +25348,13 @@ async function claimRunLedgerOutboxPrefixInBatch(
25050
25348
  false AS delivery_frozen, NULL::float8 AS lease_remaining_ms,
25051
25349
  set_config('deepline.run_ledger_transport_ack_count',
25052
25350
  (SELECT count(*) FROM transport_deliveries)::text, true),
25053
- pg_notify(${escapeLiteral(postgresSchedulerNotifyChannel('terminal', options))},
25054
- json_build_object('eventId', delivered.event_id, 'kind', 'outbox_delivered')::text)::text
25351
+ ${postgresSchedulerNotifySql(
25352
+ options,
25353
+ escapeLiteral(
25354
+ postgresSchedulerNotifyChannel('terminal', options),
25355
+ ),
25356
+ `json_build_object('eventId', delivered.event_id, 'kind', 'outbox_delivered')::text`,
25357
+ )}::text
25055
25358
  FROM transport_deliveries AS delivered
25056
25359
  ${
25057
25360
  recoverTransportDelivery
@@ -26370,13 +26673,14 @@ export async function settlePostgresSchedulerOutboxFailure(
26370
26673
  )
26371
26674
  SELECT event_id,
26372
26675
  blocked,
26373
- pg_notify(
26374
- $5,
26375
- json_build_object(
26676
+ ${postgresSchedulerNotifySql(
26677
+ options,
26678
+ '$5',
26679
+ `json_build_object(
26376
26680
  'eventId', event_id,
26377
26681
  'kind', CASE WHEN blocked THEN 'outbox_failed' ELSE 'outbox_retry' END
26378
- )::text
26379
- )
26682
+ )::text`,
26683
+ )}
26380
26684
  FROM settled
26381
26685
  `,
26382
26686
  [
@@ -26461,13 +26765,16 @@ type RunCreatedProjectionWake = { queueName: string; eventName: string };
26461
26765
 
26462
26766
  /** Both standalone and continuation ACKs publish the same atomic wake. */
26463
26767
  function runLedgerDeliveredNotificationsSql(
26768
+ options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
26464
26769
  terminalChannel: string,
26465
26770
  wake?: { queue: string; event: string },
26466
26771
  ): string {
26467
26772
  return `SELECT delivered.*,
26468
- pg_notify(${terminalChannel},
26469
- json_build_object('eventId', event_id, 'kind', 'outbox_delivered')::text
26470
- ) AS notification
26773
+ ${postgresSchedulerNotifySql(
26774
+ options,
26775
+ terminalChannel,
26776
+ `json_build_object('eventId', event_id, 'kind', 'outbox_delivered')::text`,
26777
+ )} AS notification
26471
26778
  ${
26472
26779
  wake
26473
26780
  ? `,
@@ -26475,7 +26782,7 @@ function runLedgerDeliveredNotificationsSql(
26475
26782
  THEN absurd.emit_event(${wake.queue}, ${wake.event}, 'true'::jsonb)
26476
26783
  END AS engine_wake,
26477
26784
  CASE WHEN event_type = ${RUN_EVENT_KIND_SQL_LITERAL.runCreated}
26478
- THEN pg_notify('absurd_wake', ${wake.queue})
26785
+ THEN ${absurdEngineWakeEchoSql(options, "'absurd_wake'", wake.queue)}
26479
26786
  END AS engine_notification`
26480
26787
  : ''
26481
26788
  }
@@ -26505,7 +26812,7 @@ export async function markPostgresSchedulerOutboxDeliveredRows(
26505
26812
  WITH delivered AS (
26506
26813
  ${runLedgerAcknowledgeSql(options, '$1', '$2')}
26507
26814
  ), notified AS MATERIALIZED (
26508
- ${runLedgerDeliveredNotificationsSql('$3', options?.createdProjectionWake ? { queue: '$4', event: '$5' } : undefined)}
26815
+ ${runLedgerDeliveredNotificationsSql(options, '$3', options?.createdProjectionWake ? { queue: '$4', event: '$5' } : undefined)}
26509
26816
  )
26510
26817
  SELECT event_id, event_type, lag_ms FROM notified
26511
26818
  `,
@@ -26559,10 +26866,11 @@ export async function releasePostgresSchedulerOutboxLease(
26559
26866
  RETURNING outbox.event_id, outbox.delivered_at IS NULL AS pending
26560
26867
  )
26561
26868
  SELECT event_id,
26562
- pg_notify(
26563
- $3,
26564
- json_build_object('eventId', event_id, 'kind', 'outbox_released')::text
26565
- )
26869
+ ${postgresSchedulerNotifySql(
26870
+ options,
26871
+ '$3',
26872
+ `json_build_object('eventId', event_id, 'kind', 'outbox_released')::text`,
26873
+ )}
26566
26874
  FROM released
26567
26875
  WHERE pending
26568
26876
  `,
@@ -28832,6 +29140,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
28832
29140
  events: ledgerEvents,
28833
29141
  deliveryLeaseOwner: leaseOwner,
28834
29142
  beforeBatch: renewDelivery,
29143
+ outboxFacts: events.length,
28835
29144
  // A terminal backlog receipt names its size for the verifier.
28836
29145
  ...(events.length > RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS
28837
29146
  ? { deliveryPrefixFacts: events.length }
@@ -30114,15 +30423,25 @@ function usableRunLedgerExecutorToken(
30114
30423
  return null;
30115
30424
  }
30116
30425
  const receiverOrigin = new URL(runtimeApiBaseUrlFromLaunch(launch)).origin;
30426
+ const receiverImmutable =
30427
+ isImmutableRuntimeExecutionRecoveryOrigin(receiverOrigin);
30117
30428
  const sameImmutableReceiver =
30118
30429
  claims.run_ledger_ingress_prefix_origin === receiverOrigin &&
30119
- isImmutableRuntimeExecutionRecoveryOrigin(receiverOrigin);
30430
+ receiverImmutable;
30431
+ // A mutable receiver (Production's public app) may take a prefix only
30432
+ // because the sender fences every multi-fact receipt to it behind
30433
+ // `project_run_events_prefixed`. Opt in only on the admitting build's
30434
+ // signed statement that it serves that action: the prefix origin alone
30435
+ // is minted by older builds too, so keying on it would freeze receipts
30436
+ // when this runtime deploys before the app or the app rolls back.
30437
+ const fencedMutableReceiver =
30438
+ !receiverImmutable && claims.run_ledger_prefixed_projection === true;
30120
30439
  const terminalBacklogFacts = runLedgerTerminalBacklogFactsAdvertised(
30121
30440
  claims.run_ledger_terminal_backlog_prefix_facts,
30122
30441
  );
30123
30442
  return {
30124
30443
  executorToken: token,
30125
- ...(sameImmutableReceiver
30444
+ ...(sameImmutableReceiver || fencedMutableReceiver
30126
30445
  ? { runLedgerIngressPrefixBatching: true as const }
30127
30446
  : {}),
30128
30447
  ...(sameImmutableReceiver && terminalBacklogFacts !== undefined
@@ -30252,6 +30571,7 @@ async function requestRunLedgerDispatchToken(
30252
30571
  executorToken?: unknown;
30253
30572
  runLedgerIngressPrefixBatching?: unknown;
30254
30573
  runLedgerTerminalBacklogPrefixFacts?: unknown;
30574
+ runLedgerPrefixedProjection?: unknown;
30255
30575
  retainedPipelineGraphs?: unknown;
30256
30576
  error?: unknown;
30257
30577
  code?: unknown;
@@ -30285,9 +30605,15 @@ async function requestRunLedgerDispatchToken(
30285
30605
  : 'invalid response',
30286
30606
  });
30287
30607
  }
30608
+ const receiverImmutable = isImmutableRuntimeExecutionRecoveryOrigin(
30609
+ input.receiverBaseUrl,
30610
+ );
30288
30611
  const reusablePrefix =
30289
- body.runLedgerIngressPrefixBatching === true &&
30290
- isImmutableRuntimeExecutionRecoveryOrigin(input.receiverBaseUrl);
30612
+ body.runLedgerIngressPrefixBatching === true && receiverImmutable;
30613
+ // A mutable receiver opts a receipt in only when the answering build says
30614
+ // it serves the fenced action; older builds never write the field.
30615
+ const fencedMutablePrefix =
30616
+ !receiverImmutable && body.runLedgerPrefixedProjection === true;
30291
30617
  // The receiver answers for its own verifier. Take its terminal backlog
30292
30618
  // receipt size only with the ingress-prefix advertisement it rides beside.
30293
30619
  const terminalBacklogFacts =
@@ -30319,7 +30645,7 @@ async function requestRunLedgerDispatchToken(
30319
30645
  runLedgerDispatchTokens.set(cacheKey, {
30320
30646
  token: body.executorToken,
30321
30647
  expiresAt,
30322
- ...(reusablePrefix
30648
+ ...(reusablePrefix || fencedMutablePrefix
30323
30649
  ? { runLedgerIngressPrefixBatching: true as const }
30324
30650
  : {}),
30325
30651
  ...(reusablePrefix && terminalBacklogFacts !== undefined
@@ -30348,7 +30674,7 @@ async function requestRunLedgerDispatchToken(
30348
30674
  executorToken: body.executorToken,
30349
30675
  reused: false,
30350
30676
  cacheKey,
30351
- ...(body.runLedgerIngressPrefixBatching === true
30677
+ ...(body.runLedgerIngressPrefixBatching === true || fencedMutablePrefix
30352
30678
  ? { runLedgerIngressPrefixBatching: true as const }
30353
30679
  : {}),
30354
30680
  ...(terminalBacklogFacts !== undefined
@@ -30669,6 +30995,9 @@ function acquireTerminalHub(
30669
30995
  // bounded polling fallback; long-lived fixed-cardinality processes may own
30670
30996
  // LISTEN sessions.
30671
30997
  if (process.env.VERCEL?.trim()) return null;
30998
+ // An isolated schema sends no terminal NOTIFY and spends no direct session
30999
+ // from the shared Preview budget; its handles poll.
31000
+ if (!postgresSchedulerSchemaHasNotifyListeners(options)) return null;
30672
31001
  const channel = postgresSchedulerNotifyChannel('terminal', options);
30673
31002
  return acquirePgNotifyHub({
30674
31003
  url: poolOptions.url,