deepline 0.3.502 → 0.3.504

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 (211) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +26 -0
  2. package/dist/bundling-sources/sdk/src/index.ts +1 -0
  3. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  4. package/dist/bundling-sources/sdk/src/types.ts +9 -0
  5. package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +35 -0
  6. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +1 -1
  7. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-public-aliases.ts +13 -0
  8. package/dist/bundling-sources/shared_libs/monitors/starter-templates.ts +0 -8
  9. package/dist/bundling-sources/shared_libs/observability/dlq.ts +174 -0
  10. package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
  11. package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
  12. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +18 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +20 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +62 -2
  15. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +667 -62
  16. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +55 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +20 -2
  18. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +46 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/execution-gateway-invocation-fence.ts +80 -4
  20. package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +95 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +292 -45
  22. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +15 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +3 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/play-http-request.ts +7 -3
  25. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-semantics.ts +31 -1
  26. package/dist/bundling-sources/shared_libs/play-runtime/post-code-recovery-policy.ts +231 -0
  27. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +4 -0
  28. package/dist/bundling-sources/shared_libs/play-runtime/run-ending-event.ts +55 -0
  29. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +126 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +38 -1
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +2 -9
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +51 -19
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/local-process.ts +9 -4
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +2 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +12 -1
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +3 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +42 -0
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +7 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +26 -1
  41. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +13 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +53 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +631 -19
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-inventory.ts +719 -0
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +206 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/latest-cache-result.ts +83 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +1432 -157
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +61 -0
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +29 -8
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-queue-health.ts +27 -2
  51. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +45 -0
  52. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +18 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +129 -14
  54. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +2 -0
  55. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +10 -1
  56. package/dist/cli/{auth-EFHLOVG4.mjs → auth-3L5AA5AX.mjs} +5 -5
  57. package/dist/cli/auth-UPK4IIIN.js +43 -0
  58. package/dist/cli/{billing-Q5XKEYPP.mjs → billing-E7EASVPO.mjs} +19 -12
  59. package/dist/cli/{billing-SKT2VE34.js → billing-HOGXVE2V.js} +92 -85
  60. package/dist/cli/{chunk-L5CTJY74.mjs → chunk-22OCKCYS.mjs} +2 -2
  61. package/dist/cli/{chunk-YWOQYYYS.mjs → chunk-2ABRDH3B.mjs} +2 -2
  62. package/dist/cli/{chunk-IL666WJE.js → chunk-2W77YCKH.js} +5 -5
  63. package/dist/cli/{chunk-2MVIS2UI.mjs → chunk-3MLFFWDM.mjs} +2 -2
  64. package/dist/cli/{chunk-HMZF2CSP.mjs → chunk-4CC67XH5.mjs} +2 -2
  65. package/dist/cli/{chunk-NXVYLX3F.mjs → chunk-5CHBIJIM.mjs} +10 -6
  66. package/dist/cli/chunk-5LUF4LAR.mjs +209 -0
  67. package/dist/cli/{chunk-JL6H4H3G.js → chunk-5Z6EULD5.js} +6 -6
  68. package/dist/cli/{chunk-32YQBJON.js → chunk-67OI26OE.js} +7 -7
  69. package/dist/cli/{chunk-LA3UYRVZ.js → chunk-6JNBMTCZ.js} +1 -1
  70. package/dist/cli/{chunk-DYHTXGLX.js → chunk-6SMR7LU7.js} +2 -2
  71. package/dist/cli/{chunk-OFBLT2LQ.mjs → chunk-7F4OEHQK.mjs} +1 -1
  72. package/dist/cli/{chunk-DRBD4IYQ.mjs → chunk-7MJYZ33I.mjs} +2 -6
  73. package/dist/cli/{chunk-UOANF3DR.js → chunk-7P2QVMBP.js} +26 -7
  74. package/dist/cli/{chunk-GINKIZ7S.js → chunk-A6LA42JY.js} +16 -16
  75. package/dist/cli/{chunk-FVM4PS5Q.js → chunk-BN5VKY4X.js} +25 -12
  76. package/dist/cli/{chunk-Z2H7OQ6E.mjs → chunk-BTWUNKKX.mjs} +2 -2
  77. package/dist/cli/{chunk-R5F7JXT4.mjs → chunk-BX45XMXZ.mjs} +2 -2
  78. package/dist/cli/{chunk-NKLM4J4X.mjs → chunk-DEAJVQEG.mjs} +1 -1
  79. package/dist/cli/{chunk-JFBJLNBI.js → chunk-FISP4LCK.js} +53 -53
  80. package/dist/cli/{chunk-OEUMXKR5.js → chunk-FTRVCIGC.js} +26 -26
  81. package/dist/cli/{chunk-YL2CCF6T.mjs → chunk-GGBXNQCR.mjs} +4 -4
  82. package/dist/cli/{chunk-YPTZJ7LO.js → chunk-GJ2DA35C.js} +100 -17
  83. package/dist/cli/{chunk-2S2F6YSI.js → chunk-GRAGUYIE.js} +41 -41
  84. package/dist/cli/{chunk-2JS3H6H6.mjs → chunk-HUX5DZO6.mjs} +3 -3
  85. package/dist/cli/{chunk-4CCMD7QM.mjs → chunk-IGNQKOWT.mjs} +32 -15
  86. package/dist/cli/{chunk-WKFAX2K7.js → chunk-IPAMOMGP.js} +21 -21
  87. package/dist/cli/{chunk-SAW3FBCA.mjs → chunk-ITJ7NB2D.mjs} +6 -0
  88. package/dist/cli/{chunk-Q3NM6ZL3.js → chunk-JPR2546F.js} +23 -21
  89. package/dist/cli/{chunk-X5MGQ7UT.js → chunk-KCKAFTPY.js} +10 -10
  90. package/dist/cli/{chunk-TAK3MVXY.js → chunk-KGUGNEKL.js} +284 -267
  91. package/dist/cli/{chunk-OVZOMSH2.js → chunk-LHXYCZYO.js} +8 -8
  92. package/dist/cli/{chunk-QOJBRCAS.js → chunk-MJTK6Q3G.js} +3 -3
  93. package/dist/cli/{chunk-MYUISF3P.mjs → chunk-MLMWM5DV.mjs} +5 -5
  94. package/dist/cli/{chunk-JO5FFSR7.js → chunk-NTLBZUHD.js} +6 -0
  95. package/dist/cli/{chunk-MP5QY4A2.mjs → chunk-NZ7Z7WNM.mjs} +2 -2
  96. package/dist/cli/{chunk-HIVRCTDR.mjs → chunk-OX2D6BG4.mjs} +20 -1
  97. package/dist/cli/{chunk-YDXEXVBV.js → chunk-QKKU2FH4.js} +7 -7
  98. package/dist/cli/{chunk-3KEZVGGV.mjs → chunk-QOLX2O2S.mjs} +4 -4
  99. package/dist/cli/{chunk-JFUXUSKB.mjs → chunk-R2VZVHJP.mjs} +15 -2
  100. package/dist/cli/chunk-R7J7CJPZ.js +209 -0
  101. package/dist/cli/{chunk-XMKUJ44Z.js → chunk-SMSQVRHE.js} +5 -5
  102. package/dist/cli/{chunk-54QXWK3C.mjs → chunk-SVFTZTCI.mjs} +1 -1
  103. package/dist/cli/{chunk-FWDAEWCD.js → chunk-TMQUMILM.js} +19 -23
  104. package/dist/cli/{chunk-TFFJ2PRN.mjs → chunk-UFYJTRSF.mjs} +98 -15
  105. package/dist/cli/{chunk-EUWRKWT4.js → chunk-UJMBG5JU.js} +5 -4
  106. package/dist/cli/{chunk-DKAMCJIT.js → chunk-USTJEEND.js} +17 -13
  107. package/dist/cli/{chunk-AJL2Q6IQ.js → chunk-UXQQPMYO.js} +2 -2
  108. package/dist/cli/{chunk-7ZYSXSJJ.mjs → chunk-VJVJWZ6I.mjs} +5 -5
  109. package/dist/cli/{chunk-JLYDLK6X.js → chunk-WBIDPDKJ.js} +3 -3
  110. package/dist/cli/{chunk-QNELA7SX.js → chunk-WZSFIJMG.js} +53 -53
  111. package/dist/cli/{chunk-NZXB27TP.mjs → chunk-XHZSPMNC.mjs} +4 -4
  112. package/dist/cli/{chunk-W5CHE5Q2.mjs → chunk-Y6XKCEPK.mjs} +1 -1
  113. package/dist/cli/{chunk-4WTC5SSN.mjs → chunk-Y7VEHKID.mjs} +10 -8
  114. package/dist/cli/{chunk-3MJSWVQ2.mjs → chunk-YOQ2NNDO.mjs} +2 -1
  115. package/dist/cli/{chunk-ZNB6GR3P.mjs → chunk-Z6FXUDIL.mjs} +1 -1
  116. package/dist/cli/command-docs.d.mts +2 -1
  117. package/dist/cli/command-docs.d.ts +2 -1
  118. package/dist/cli/command-docs.js +6 -2
  119. package/dist/cli/command-docs.mjs +5 -1
  120. package/dist/cli/{csv-OXGSCV75.js → csv-2XWGPITO.js} +13 -13
  121. package/dist/cli/{csv-6AEPKKCO.mjs → csv-433JEHLQ.mjs} +4 -4
  122. package/dist/cli/{db-K3KRK4CZ.mjs → db-K747DH43.mjs} +6 -6
  123. package/dist/cli/{db-6NVHDUZY.js → db-PJJMD4VH.js} +27 -27
  124. package/dist/cli/describe-OYS7LZJD.js +49 -0
  125. package/dist/cli/{describe-P3ZJS7TQ.mjs → describe-VEDDYW4P.mjs} +20 -20
  126. package/dist/cli/describe-core.d.mts +8 -4
  127. package/dist/cli/describe-core.d.ts +8 -4
  128. package/dist/cli/describe-core.js +4 -4
  129. package/dist/cli/describe-core.mjs +3 -3
  130. package/dist/cli/{executions-2C2FFG52.js → executions-HM5T72H6.js} +8 -8
  131. package/dist/cli/{executions-I7XW6WWK.mjs → executions-JWRX3XCT.mjs} +6 -6
  132. package/dist/cli/{feedback-47B57A5Y.js → feedback-34UG4BO3.js} +8 -8
  133. package/dist/cli/{feedback-RSTNBJAI.mjs → feedback-MNSIA63Y.mjs} +4 -4
  134. package/dist/cli/git-5YQJSJFR.js +25 -0
  135. package/dist/cli/{git-3G5AFKBT.mjs → git-ZKEOXV3A.mjs} +5 -5
  136. package/dist/cli/index.js +144 -142
  137. package/dist/cli/index.mjs +44 -42
  138. package/dist/cli/{legacy-noops-NQ262TKL.mjs → legacy-noops-5M4T4ZVT.mjs} +5 -5
  139. package/dist/cli/{legacy-noops-P665PBG4.js → legacy-noops-YXSI4FVU.js} +8 -8
  140. package/dist/cli/{monitors-KUPZODZS.mjs → monitors-C65OC4AW.mjs} +7 -7
  141. package/dist/cli/{monitors-IPWAD7LS.js → monitors-O25GDOYE.js} +95 -95
  142. package/dist/cli/{org-WFC3N672.js → org-2GSPLY2A.js} +72 -72
  143. package/dist/cli/{org-ZCQGEM3L.mjs → org-ZRMG5NS2.mjs} +6 -6
  144. package/dist/cli/{pages-N5BNC67L.js → pages-45DPADK6.js} +18 -18
  145. package/dist/cli/{pages-VE66IU7B.mjs → pages-TZZUFBRO.mjs} +6 -6
  146. package/dist/cli/{play-EIMDIAJB.mjs → play-3D7HH273.mjs} +138 -226
  147. package/dist/cli/{play-NKIRJSKX.js → play-RCGMND6X.js} +454 -542
  148. package/dist/cli/{providers-XU3AGY2F.js → providers-3N3ECMTY.js} +9 -9
  149. package/dist/cli/{providers-KDTJ63ED.mjs → providers-PSAKV6CJ.mjs} +6 -6
  150. package/dist/cli/{quickstart-TXFXUODF.mjs → quickstart-2A35SMGC.mjs} +4 -4
  151. package/dist/cli/{quickstart-OSCHOSXU.js → quickstart-6R6AIXM6.js} +6 -6
  152. package/dist/cli/{run-ODGML35U.mjs → run-F3TLDGUO.mjs} +25 -25
  153. package/dist/cli/{run-ET2KVTPK.js → run-F6ZXTASZ.js} +44 -44
  154. package/dist/cli/{search-DK67K6PR.mjs → search-CZLCY3D2.mjs} +7 -7
  155. package/dist/cli/search-R5VEWJO2.js +32 -0
  156. package/dist/cli/{search-output-6SOKQTCW.mjs → search-output-MQTSTLN5.mjs} +5 -5
  157. package/dist/cli/{search-output-KXP4FA62.js → search-output-R5XDNILW.js} +7 -7
  158. package/dist/cli/{secrets-C6SYTMU7.mjs → secrets-D3GF4B2Z.mjs} +6 -6
  159. package/dist/cli/{secrets-WPS6NMNK.js → secrets-DCJYHDSY.js} +15 -15
  160. package/dist/cli/{sessions-PXVOH34X.mjs → sessions-QGEQ2UYZ.mjs} +5 -5
  161. package/dist/cli/{sessions-IP562J5Z.js → sessions-Z4JYJSDP.js} +6 -6
  162. package/dist/cli/{settings-FBUQGYVJ.mjs → settings-G7QEXA4N.mjs} +11 -11
  163. package/dist/cli/{settings-SUDUIVMY.js → settings-UVXXAT4A.js} +78 -78
  164. package/dist/cli/{setup-I5H6IOEY.js → setup-5I42W7D4.js} +49 -49
  165. package/dist/cli/{setup-JSIMTR73.mjs → setup-QHJU3DUI.mjs} +9 -9
  166. package/dist/cli/{skills-FJQ3LX6N.mjs → skills-5LRF4UKX.mjs} +7 -7
  167. package/dist/cli/skills-FB6TV52O.js +36 -0
  168. package/dist/cli/tools-L2364RPA.js +56 -0
  169. package/dist/cli/{tools-IGBK4BVE.mjs → tools-PUT6STVG.mjs} +18 -18
  170. package/dist/cli/{update-7MTT6F5K.mjs → update-CJ2GA64X.mjs} +9 -9
  171. package/dist/cli/update-ESYJGYVZ.js +34 -0
  172. package/dist/cli/{workflow-PM2J2OU3.mjs → workflow-HVEWRTXD.mjs} +7 -7
  173. package/dist/cli/{workflow-UX3ZX6BQ.js → workflow-O67MEBCP.js} +17 -17
  174. package/dist/{client-Bn8FwKGO.d.ts → client-CIwenMFS.d.ts} +1 -1
  175. package/dist/{client-CfNRmjLK.d.mts → client-DYAfJpaN.d.mts} +1 -1
  176. package/dist/{client-core-B91EV0WS.d.ts → client-core-CRjtyMAI.d.ts} +25 -2
  177. package/dist/{client-core-BG8Cgrmk.d.mts → client-core-DlzP8vEs.d.mts} +25 -2
  178. package/dist/{compiler-manifest-DlXDyndN.d.mts → compiler-manifest-DaJrA2KV.d.mts} +1 -1
  179. package/dist/{compiler-manifest-DlXDyndN.d.ts → compiler-manifest-DaJrA2KV.d.ts} +1 -1
  180. package/dist/{errors-BtriA2ld.d.mts → errors-BKnSYueU.d.mts} +1 -1
  181. package/dist/{errors-DmcLykM7.d.ts → errors-KLga4bLr.d.ts} +1 -1
  182. package/dist/{index-DI0sR_fX.d.mts → index-C-8AFpWy.d.mts} +1 -1
  183. package/dist/{index--Jw-slHY.d.ts → index-C5nAZ-VS.d.ts} +1 -1
  184. package/dist/index.d.mts +7 -7
  185. package/dist/index.d.ts +7 -7
  186. package/dist/index.js +9 -9
  187. package/dist/index.mjs +6 -6
  188. package/dist/install-integrity.json +125 -116
  189. package/dist/plays/bundle-play-file.d.mts +3 -3
  190. package/dist/plays/bundle-play-file.d.ts +3 -3
  191. package/dist/plays/bundle-play-file.mjs +12 -5
  192. package/dist/plays/play-description.d.mts +2 -2
  193. package/dist/plays/play-description.d.ts +2 -2
  194. package/dist/plays/run-request.d.mts +2 -2
  195. package/dist/plays/run-request.d.ts +2 -2
  196. package/dist/release.d.mts +1 -1
  197. package/dist/release.d.ts +1 -1
  198. package/dist/release.js +2 -2
  199. package/dist/release.mjs +1 -1
  200. package/dist/server.d.mts +4 -4
  201. package/dist/server.d.ts +4 -4
  202. package/dist/server.js +5 -5
  203. package/dist/server.mjs +3 -3
  204. package/package.json +1 -1
  205. package/dist/cli/auth-VM3IKP5F.js +0 -43
  206. package/dist/cli/describe-JOUAXXPE.js +0 -49
  207. package/dist/cli/git-OPKIC6JQ.js +0 -25
  208. package/dist/cli/search-6U54Y3OK.js +0 -32
  209. package/dist/cli/skills-VHININXC.js +0 -36
  210. package/dist/cli/tools-XMBMHVKF.js +0 -56
  211. package/dist/cli/update-H7JVW43I.js +0 -34
@@ -0,0 +1,206 @@
1
+ /**
2
+ * SQL fragments shared by the durable-run operator inventory and its queue
3
+ * health projection. Read-only; no value imports from the scheduler module,
4
+ * so the health observer stays light.
5
+ */
6
+ import {
7
+ isDurableRunFailureCauseFilter,
8
+ type DurableRunFailureCauseFilter,
9
+ type DurableRunFailureClass,
10
+ } from '../../observability/dlq';
11
+ import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
12
+
13
+ export type DurableRunSqlOptions = { readonly schema?: string };
14
+ type Options = DurableRunSqlOptions;
15
+
16
+ function quoteIdent(value: string): string {
17
+ return `"${value.replace(/"/g, '""')}"`;
18
+ }
19
+
20
+ export function durableRunTable(name: string, options?: Options): string {
21
+ const schema =
22
+ options?.schema?.trim() ||
23
+ resolveRuntimeSchedulerSchemaEnv() ||
24
+ 'runtime_scheduler';
25
+ return `${quoteIdent(schema)}.${quoteIdent(name)}`;
26
+ }
27
+
28
+ /** SQL: whether the queued run `runs` is waiting out a recovery delay. */
29
+ export function durableRunRecoveringSql(options?: Options): string {
30
+ return `(
31
+ runs.status = 'queued'
32
+ AND (
33
+ runs.recovery_json #>> '{postCode,nextRetryAtMs}' IS NOT NULL
34
+ OR runs.recovery_json ->> 'nextRetryAtMs' IS NOT NULL
35
+ )
36
+ AND EXISTS (
37
+ SELECT 1 FROM (
38
+ SELECT latest.status, latest.error_json
39
+ FROM ${durableRunTable('attempts', options)} AS latest
40
+ WHERE latest.run_id = runs.run_id
41
+ ORDER BY latest.attempt DESC
42
+ LIMIT 1
43
+ ) AS last_attempt
44
+ WHERE last_attempt.status = 'stale'
45
+ AND last_attempt.error_json ->> 'kind' IN (
46
+ 'platform_post_code_recovery', 'platform_pre_code_recovery'
47
+ )
48
+ )
49
+ )`;
50
+ }
51
+
52
+ export {
53
+ DURABLE_RUN_FAILURE_CLASSES,
54
+ type DurableRunFailureClass,
55
+ } from '../../observability/dlq';
56
+
57
+ /** `list --state failed --cause` → the classes it keeps. */
58
+ export const DURABLE_RUN_FAILURE_CAUSES = {
59
+ platform: ['platform_recovery_exhausted', 'platform_failure'],
60
+ play: ['play_error'],
61
+ } as const satisfies Record<
62
+ DurableRunFailureCauseFilter,
63
+ readonly DurableRunFailureClass[]
64
+ >;
65
+ export type DurableRunFailureCause = DurableRunFailureCauseFilter;
66
+ export const isDurableRunFailureCause = isDurableRunFailureCauseFilter;
67
+
68
+ const PLATFORM_RECOVERY_EXHAUSTED_PREFIX = 'PLATFORM_RECOVERY_EXHAUSTED:';
69
+ /**
70
+ * The exhausted-recovery message is a fixed Deepline template
71
+ * (`platformRecoveryExhaustedMessage` and the pre-code variant), well under
72
+ * this. A stored message longer than this, or spanning lines, is not shown.
73
+ */
74
+ export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
75
+
76
+ /**
77
+ * SQL: `LEFT JOIN LATERAL ... AS failure` over `runs`, yielding
78
+ * `failure.failure_class`, `failure_code`, `failure_message` and
79
+ * `failure_at_ms` (exhausted time; null otherwise). Reads only fields the
80
+ * scheduler already stores: `terminal_error_json` ({ message, code? }, also the
81
+ * cancel reason), and the exhausted markers of `recovery_json`
82
+ * (`postCode.exhaustedAtMs`, pre-code `exhaustedAtMs`, cleared on resume).
83
+ *
84
+ * The Play's error text never leaves Postgres: `failure_message` is only the
85
+ * fixed exhausted-recovery template. Platform-vs-Play mirrors
86
+ * `runtimeTerminalReasonFromError`: sandbox killed/lost and lost leases are
87
+ * platform; runtime limit and sandbox OOM are the Play's; scheduler-written
88
+ * codes (`SCHEDULER_*`, `CTX_RUN_PLAY_INLINE_ONLY`) are platform.
89
+ */
90
+ export function durableRunFailureLateralSql(): string {
91
+ return `LEFT JOIN LATERAL (
92
+ SELECT
93
+ CASE
94
+ WHEN runs.status = 'cancelled' THEN 'cancelled'
95
+ WHEN runs.status <> 'failed' THEN NULL
96
+ WHEN parsed.exhausted_at_ms IS NOT NULL
97
+ OR starts_with(parsed.message, '${PLATFORM_RECOVERY_EXHAUSTED_PREFIX}')
98
+ THEN 'platform_recovery_exhausted'
99
+ WHEN parsed.message IS NULL THEN 'unknown'
100
+ WHEN parsed.terminal_reason IN ('sandbox_killed', 'sandbox_missing', 'lease_expired')
101
+ OR parsed.code = 'CTX_RUN_PLAY_INLINE_ONLY'
102
+ OR starts_with(parsed.code, 'SCHEDULER_')
103
+ THEN 'platform_failure'
104
+ ELSE 'play_error'
105
+ END AS failure_class,
106
+ CASE
107
+ WHEN runs.status NOT IN ('failed', 'cancelled') THEN NULL
108
+ ELSE coalesce(
109
+ parsed.code,
110
+ CASE
111
+ WHEN runs.status = 'failed' AND parsed.exhausted_at_ms IS NOT NULL
112
+ THEN 'PLATFORM_RECOVERY_EXHAUSTED'
113
+ END,
114
+ CASE WHEN runs.status = 'failed' THEN parsed.terminal_reason END
115
+ )
116
+ END AS failure_code,
117
+ CASE
118
+ WHEN runs.status = 'failed'
119
+ AND starts_with(parsed.message, '${PLATFORM_RECOVERY_EXHAUSTED_PREFIX}')
120
+ AND char_length(parsed.message) <= ${DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS}
121
+ AND strpos(parsed.message, chr(10)) = 0
122
+ AND strpos(parsed.message, chr(13)) = 0
123
+ THEN parsed.message
124
+ END AS failure_message,
125
+ CASE WHEN runs.status = 'failed' THEN parsed.exhausted_at_ms END
126
+ AS failure_at_ms
127
+ FROM (
128
+ SELECT
129
+ raw.message,
130
+ raw.exhausted_at_ms,
131
+ coalesce(
132
+ CASE WHEN raw.stored_code ~ '^[A-Z][A-Z0-9_]{2,63}$' THEN raw.stored_code END,
133
+ substring(raw.message FROM '^([A-Z][A-Z0-9_]{2,63}):')
134
+ ) AS code,
135
+ CASE
136
+ WHEN raw.message ~* 'RUNTIME_LIMIT_EXCEEDED' THEN 'runtime_limit'
137
+ WHEN raw.message ~* 'RUNTIME_SANDBOX_OOM|javascript heap out of memory|fatal error:[^\\n]*(heap|allocation)[^\\n]*memory'
138
+ THEN 'sandbox_oom'
139
+ WHEN raw.message ~* 'RUNTIME_SANDBOX_KILLED' THEN 'sandbox_killed'
140
+ WHEN raw.message ~* 'RUNTIME_SANDBOX_LOST' THEN 'sandbox_missing'
141
+ WHEN raw.message ~* 'lost lease|lease expired|AB001' THEN 'lease_expired'
142
+ END AS terminal_reason
143
+ FROM (
144
+ SELECT
145
+ CASE WHEN jsonb_typeof(runs.terminal_error_json -> 'message') = 'string'
146
+ THEN runs.terminal_error_json ->> 'message' END AS message,
147
+ CASE WHEN jsonb_typeof(runs.terminal_error_json -> 'code') = 'string'
148
+ THEN runs.terminal_error_json ->> 'code' END AS stored_code,
149
+ coalesce(
150
+ runs.recovery_json #>> '{postCode,exhaustedAtMs}',
151
+ CASE WHEN runs.recovery_json ->> 'kind' = 'platform_pre_code'
152
+ THEN runs.recovery_json ->> 'exhaustedAtMs' END
153
+ ) AS exhausted_at_ms
154
+ ) AS raw
155
+ ) AS parsed
156
+ ) AS failure ON true`;
157
+ }
158
+
159
+ /**
160
+ * Bounded counts for the operations queue catalog row `durable-play-runs`.
161
+ * Each bucket reads at most `sampleLimit + 1` index rows; a larger bucket is
162
+ * reported truncated (a lower bound). Ages are not measured: a long sleep
163
+ * or a scheduled retry is not late work, and queued-task age is already the
164
+ * `play-runtime-tasks` signal.
165
+ */
166
+ export function durableRunsHealthProjectionSql(options?: Options): string {
167
+ return `
168
+ WITH queued AS (
169
+ SELECT ${durableRunRecoveringSql(options)} AS recovering
170
+ FROM ${durableRunTable('runs', options)} AS runs
171
+ WHERE runs.status = 'queued'
172
+ AND $1::timestamptz IS NOT NULL
173
+ ORDER BY runs.created_at DESC, runs.run_id
174
+ LIMIT $2::int
175
+ ), in_flight AS (
176
+ SELECT 1
177
+ FROM ${durableRunTable('runs', options)} AS runs
178
+ WHERE runs.status IN ('running', 'waiting')
179
+ LIMIT $2::int
180
+ )
181
+ SELECT
182
+ least((SELECT count(*) FILTER (WHERE NOT recovering) FROM queued), $3) AS ready,
183
+ least((SELECT count(*) FILTER (WHERE recovering) FROM queued), $3) AS delayed,
184
+ least((SELECT count(*) FROM in_flight), $3) AS in_flight,
185
+ 0::bigint AS blocked,
186
+ 0::bigint AS dead_lettered,
187
+ NULL::bigint AS oldest_ready_ms,
188
+ NULL::bigint AS oldest_delayed_ms,
189
+ NULL::bigint AS oldest_in_flight_ms,
190
+ NULL::bigint AS oldest_blocked_ms,
191
+ NULL::bigint AS oldest_dead_lettered_ms,
192
+ (SELECT count(*) FROM queued) > $3 AS ready_truncated,
193
+ (SELECT count(*) FROM queued) > $3 AS delayed_truncated,
194
+ (SELECT count(*) FROM in_flight) > $3 AS in_flight_truncated,
195
+ false AS blocked_truncated,
196
+ false AS dead_lettered_truncated,
197
+ 0::bigint AS admitted,
198
+ 0::bigint AS started,
199
+ 0::bigint AS completed,
200
+ 0::bigint AS failed,
201
+ 0::bigint AS retried,
202
+ false AS dead_lettered_available,
203
+ false AS flow_available,
204
+ 'Durable run inventory has no bounded exact rolling flow projection'::text AS flow_unavailable_reason
205
+ `;
206
+ }
@@ -0,0 +1,83 @@
1
+ import type { PostgresSchedulerQueryClient } from './postgres';
2
+ import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
3
+
4
+ /** Matches the scheduler's default receipt schema. */
5
+ const DEFAULT_RECEIPT_SCHEMA = 'runtime_scheduler';
6
+
7
+ function receiptsTable(schema: string | null | undefined): string {
8
+ const name =
9
+ schema?.trim() ||
10
+ resolveRuntimeSchedulerSchemaEnv() ||
11
+ DEFAULT_RECEIPT_SCHEMA;
12
+ return `"${name.replace(/"/g, '""')}"."receipts"`;
13
+ }
14
+
15
+ /**
16
+ * Newest-wins write of one shared read result (`ctx:{org}:cache:v1:*`).
17
+ *
18
+ * Ordinary receipts are write-once. This row is the one exception: it holds
19
+ * the newest result for a request, so a later publish replaces it. The time
20
+ * comes from the database clock, never from the caller, so a Play cannot
21
+ * plant a future timestamp that would pin its result. A row whose stored time
22
+ * is not older is left unchanged and reported as `older`.
23
+ */
24
+ export async function publishPostgresLatestCacheResult(
25
+ client: PostgresSchedulerQueryClient,
26
+ input: {
27
+ orgId: string;
28
+ key: string;
29
+ runId: string;
30
+ /** Sanitized JSON object without `recordedAtMs`. */
31
+ outputJson: string;
32
+ },
33
+ options: { schema?: string | null },
34
+ ): Promise<{ published: true; recordedAtMs: number } | { published: false }> {
35
+ const orgId = input.orgId.trim();
36
+ if (!orgId) {
37
+ throw new Error('Shared read cache publish requires orgId.');
38
+ }
39
+ const result = await client.query<{ recorded_at_ms: string | number }>(
40
+ `
41
+ INSERT INTO ${receiptsTable(options.schema)} AS receipt (
42
+ org_id, k, status, output_json, output_ref, error, error_payload, failure_kind, run_id,
43
+ lease_id, lease_owner_run_id, lease_owner_attempt, lease_expires_at
44
+ ) VALUES (
45
+ $1, $2, 'completed',
46
+ jsonb_set(
47
+ $3::jsonb,
48
+ '{recordedAtMs}',
49
+ to_jsonb((extract(epoch FROM clock_timestamp()) * 1000)::bigint)
50
+ ),
51
+ NULL, NULL, NULL, 0, $4, NULL, NULL, NULL, NULL
52
+ )
53
+ ON CONFLICT (org_id, k) DO UPDATE
54
+ SET status = 'completed',
55
+ output_json = EXCLUDED.output_json,
56
+ output_ref = NULL,
57
+ error = NULL,
58
+ error_payload = NULL,
59
+ failure_kind = 0,
60
+ run_id = EXCLUDED.run_id,
61
+ lease_id = NULL,
62
+ lease_owner_run_id = NULL,
63
+ lease_owner_attempt = NULL,
64
+ lease_expires_at = NULL,
65
+ updated_at = now()
66
+ WHERE (
67
+ CASE WHEN jsonb_typeof(receipt.output_json -> 'recordedAtMs') = 'number'
68
+ THEN (receipt.output_json ->> 'recordedAtMs')::numeric
69
+ ELSE -1
70
+ END
71
+ ) < (EXCLUDED.output_json ->> 'recordedAtMs')::numeric
72
+ RETURNING (output_json ->> 'recordedAtMs') AS recorded_at_ms
73
+ `,
74
+ [orgId, input.key, input.outputJson, input.runId],
75
+ );
76
+ const row = result.rows[0];
77
+ if (!row) return { published: false };
78
+ const recordedAtMs = Number(row.recorded_at_ms);
79
+ if (!Number.isSafeInteger(recordedAtMs)) {
80
+ throw new Error('Shared read cache publish returned an invalid time.');
81
+ }
82
+ return { published: true, recordedAtMs };
83
+ }