deepline 0.3.524 → 0.3.526

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 (176) hide show
  1. package/dist/bundling-sources/sdk/src/agent-runtime.ts +98 -0
  2. package/dist/bundling-sources/sdk/src/client-core.ts +8 -0
  3. package/dist/bundling-sources/sdk/src/http-core.ts +14 -0
  4. package/dist/bundling-sources/sdk/src/plays/play-description.ts +1 -0
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/types.ts +10 -0
  7. package/dist/bundling-sources/shared_libs/observability/dlq.ts +33 -5
  8. package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
  9. package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +38 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +94 -9
  12. package/dist/bundling-sources/shared_libs/play-runtime/run-failure-class.ts +98 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/run-retry-summary.ts +202 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +60 -8
  15. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +112 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +39 -1
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-inventory.ts +2 -2
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +52 -5
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +10 -1
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-retry-facts.ts +62 -0
  21. package/dist/cli/{auth-QXJMVLPN.mjs → auth-JATW5XZE.mjs} +5 -5
  22. package/dist/cli/auth-L2POG3LL.js +43 -0
  23. package/dist/cli/{billing-N5R4HTHT.js → billing-TSHBJIJS.js} +83 -83
  24. package/dist/cli/{billing-SNSIFM4B.mjs → billing-UT5LIESH.mjs} +8 -8
  25. package/dist/cli/{chunk-PFKWKWUJ.mjs → chunk-26ULNPQ7.mjs} +2 -2
  26. package/dist/cli/{chunk-OQ5G7RFQ.mjs → chunk-2GJW4RAQ.mjs} +70 -3
  27. package/dist/cli/{chunk-HLAFGQPV.mjs → chunk-2JNX3MDG.mjs} +5 -2
  28. package/dist/cli/{chunk-V7KUBDEB.js → chunk-3MYI3IXW.js} +144 -141
  29. package/dist/cli/{chunk-WOEPDSO3.js → chunk-3ZEV5BS5.js} +26 -26
  30. package/dist/cli/{chunk-ATATJNJ6.js → chunk-46HEYGLY.js} +9 -9
  31. package/dist/cli/{chunk-I75VRGQG.js → chunk-477PXM65.js} +22 -22
  32. package/dist/cli/{chunk-RVHUW4TN.js → chunk-5YAJGRWB.js} +17 -17
  33. package/dist/cli/{chunk-T43FF5PF.mjs → chunk-6COGHW7B.mjs} +2 -2
  34. package/dist/cli/{chunk-V4RJ57MA.js → chunk-6DHEV6IA.js} +2 -2
  35. package/dist/cli/{chunk-VHTVXS5A.js → chunk-6H56LKJB.js} +16 -16
  36. package/dist/cli/{chunk-YKFW3NNA.mjs → chunk-6JMWATX5.mjs} +5 -5
  37. package/dist/cli/{chunk-II3BJKCH.mjs → chunk-77RAGJIZ.mjs} +2 -2
  38. package/dist/cli/{chunk-ITJ7NB2D.mjs → chunk-7AOFSZJM.mjs} +3 -1
  39. package/dist/cli/{chunk-OCT4SUJA.js → chunk-7COEN3IR.js} +146 -79
  40. package/dist/cli/{chunk-XURWFEXM.mjs → chunk-7FCD34YS.mjs} +31 -17
  41. package/dist/cli/{chunk-BXVYVIMB.js → chunk-B33J4YCC.js} +3 -3
  42. package/dist/cli/{chunk-RTDX5NNN.mjs → chunk-BFH3DJYV.mjs} +84 -57
  43. package/dist/cli/{chunk-GJYLC4JB.mjs → chunk-BNH4Y35W.mjs} +2 -2
  44. package/dist/cli/{chunk-GMO3JDZA.mjs → chunk-BVITYMBK.mjs} +2 -2
  45. package/dist/cli/{chunk-7QM6DNR4.js → chunk-BYEF4RBX.js} +11 -11
  46. package/dist/cli/{chunk-536TGWR6.mjs → chunk-C3EW6I65.mjs} +2 -2
  47. package/dist/cli/{chunk-HTYT2OHB.js → chunk-CDP3LMDT.js} +6 -6
  48. package/dist/cli/{chunk-YXVYPYIP.js → chunk-CYN2AHR6.js} +10 -10
  49. package/dist/cli/{chunk-CH7JVSA7.mjs → chunk-D2XMFXFM.mjs} +8 -8
  50. package/dist/cli/{chunk-2ZWNIS54.js → chunk-D5OEUPPM.js} +269 -269
  51. package/dist/cli/{chunk-FXTV5B3D.mjs → chunk-DY2AT3JQ.mjs} +12 -12
  52. package/dist/cli/{chunk-Z4MOEQSY.js → chunk-ED2N4NRI.js} +21 -21
  53. package/dist/cli/{chunk-RIX26ZJD.mjs → chunk-EEYZLTXX.mjs} +1 -1
  54. package/dist/cli/{chunk-7E6B7VMS.js → chunk-F5KFGF45.js} +5 -5
  55. package/dist/cli/{chunk-TZTWH53O.js → chunk-FMPGWAIR.js} +1 -1
  56. package/dist/cli/{chunk-R2VZVHJP.mjs → chunk-GESIFFQX.mjs} +1 -1
  57. package/dist/cli/{chunk-YCIXY66B.mjs → chunk-HPACLONQ.mjs} +2 -2
  58. package/dist/cli/{chunk-WCVIPZWX.mjs → chunk-IMP7WR22.mjs} +5 -5
  59. package/dist/cli/{chunk-KSQXBLRW.mjs → chunk-IWLDJQGV.mjs} +3 -3
  60. package/dist/cli/{chunk-EQNAQENZ.js → chunk-J5OXJ4JI.js} +2 -2
  61. package/dist/cli/{chunk-NUC7ZVDG.mjs → chunk-MQB25LMV.mjs} +5 -5
  62. package/dist/cli/{chunk-RUULUCBP.js → chunk-O7WUATQC.js} +97 -70
  63. package/dist/cli/{chunk-NMU3VR5U.js → chunk-PMH4GLMD.js} +1 -0
  64. package/dist/cli/{chunk-S3A4IXBQ.mjs → chunk-PSX3WHIH.mjs} +1 -0
  65. package/dist/cli/{chunk-LRWDZDBS.js → chunk-RZJWHL7L.js} +5 -5
  66. package/dist/cli/{chunk-66N76YZG.js → chunk-SCLRGDF4.js} +44 -44
  67. package/dist/cli/{chunk-SMWFOGUT.js → chunk-SJ6KUCGM.js} +53 -53
  68. package/dist/cli/{chunk-PFKKZVFK.js → chunk-TBQC2XS3.js} +41 -41
  69. package/dist/cli/{chunk-2ZX7XSAQ.mjs → chunk-TCLJXJAG.mjs} +4 -4
  70. package/dist/cli/{chunk-YGOI5ZE5.mjs → chunk-TVHDWS5U.mjs} +1 -1
  71. package/dist/cli/{chunk-MW3YMPD2.mjs → chunk-TXJW6RIM.mjs} +1 -1
  72. package/dist/cli/{chunk-KKPBCB6D.mjs → chunk-U6OUX47C.mjs} +2 -2
  73. package/dist/cli/{chunk-GTGJBZVH.js → chunk-UTCGCES2.js} +7 -7
  74. package/dist/cli/{chunk-V2YIBBVT.mjs → chunk-UUIC2JFZ.mjs} +1 -1
  75. package/dist/cli/{chunk-JDIQBZ6O.js → chunk-UWCEBS7F.js} +14 -14
  76. package/dist/cli/{chunk-ANKD3AIR.js → chunk-WBY3R55B.js} +2 -2
  77. package/dist/cli/{chunk-SF4QJVBE.js → chunk-WITNIMLE.js} +3 -3
  78. package/dist/cli/{chunk-7OQGZBDG.js → chunk-WL6GAZBD.js} +31 -17
  79. package/dist/cli/{chunk-R457IMHJ.mjs → chunk-WOLY6SU4.mjs} +1 -1
  80. package/dist/cli/{chunk-3WWTBQHC.mjs → chunk-XVIMOB2U.mjs} +2 -2
  81. package/dist/cli/{chunk-NTLBZUHD.js → chunk-XYIECA7M.js} +4 -2
  82. package/dist/cli/{chunk-BXIQD2IY.mjs → chunk-Y47OCS5V.mjs} +1 -1
  83. package/dist/cli/{chunk-EO55Y4QW.mjs → chunk-YNFPZVII.mjs} +5 -5
  84. package/dist/cli/{chunk-BN5VKY4X.js → chunk-ZS2WHWWL.js} +7 -7
  85. package/dist/cli/command-docs.js +2 -2
  86. package/dist/cli/command-docs.mjs +1 -1
  87. package/dist/cli/{csv-HT2JBCW2.mjs → csv-4BLFRED6.mjs} +4 -4
  88. package/dist/cli/{csv-Q2LWKXAV.js → csv-KSJB5Z3M.js} +13 -13
  89. package/dist/cli/{db-XEV4WEE4.js → db-G7Z5CKO2.js} +28 -28
  90. package/dist/cli/{db-CS3XQ2LX.mjs → db-OVW6C3DV.mjs} +7 -7
  91. package/dist/cli/describe-KMYR2JBC.js +50 -0
  92. package/dist/cli/describe-OEFTD7WQ.mjs +50 -0
  93. package/dist/cli/describe-core.d.mts +4 -2
  94. package/dist/cli/describe-core.d.ts +4 -2
  95. package/dist/cli/describe-core.js +5 -5
  96. package/dist/cli/describe-core.mjs +4 -4
  97. package/dist/cli/{executions-L6XFG5MP.mjs → executions-7ZKQ4ZU3.mjs} +7 -7
  98. package/dist/cli/{executions-JCC34WAD.js → executions-O7USCBCW.js} +9 -9
  99. package/dist/cli/{feedback-AWBDO5I6.mjs → feedback-KUBL5E3I.mjs} +61 -13
  100. package/dist/cli/{feedback-HV2M2G7N.js → feedback-Y55WCRIQ.js} +65 -17
  101. package/dist/cli/{git-S4LRXTRX.mjs → git-C6ZAU5JA.mjs} +5 -5
  102. package/dist/cli/git-NBVQ3VGW.js +25 -0
  103. package/dist/cli/index.js +145 -145
  104. package/dist/cli/index.mjs +44 -44
  105. package/dist/cli/{legacy-noops-7MOKBL4O.mjs → legacy-noops-MUXD4HRC.mjs} +6 -6
  106. package/dist/cli/{legacy-noops-RGSZUD6V.js → legacy-noops-OVWX4KB3.js} +9 -9
  107. package/dist/cli/{monitors-XQNXDZPQ.mjs → monitors-2ZSGBY52.mjs} +8 -8
  108. package/dist/cli/{monitors-JEFM2C5W.js → monitors-3QVYGYWA.js} +101 -101
  109. package/dist/cli/{org-KTMJZGTN.mjs → org-RDSPE5FB.mjs} +7 -7
  110. package/dist/cli/{org-GYLA5V32.js → org-S6Z3SDLI.js} +87 -87
  111. package/dist/cli/{pages-WOMU2T2O.mjs → pages-K5DSMHLJ.mjs} +7 -7
  112. package/dist/cli/{pages-RY4U7OCL.js → pages-VUWF2OR7.js} +19 -19
  113. package/dist/cli/{play-KOYGGNYS.mjs → play-PZLXOYEX.mjs} +151 -102
  114. package/dist/cli/{play-2Q6MWJ3D.js → play-SQOJTUFC.js} +756 -707
  115. package/dist/cli/{providers-7YKDITJC.mjs → providers-AMIGP3D4.mjs} +7 -7
  116. package/dist/cli/{providers-HOIRHMN2.js → providers-FZBEPUOI.js} +10 -10
  117. package/dist/cli/{quickstart-RDXHSMVX.mjs → quickstart-HNOQKGOF.mjs} +4 -4
  118. package/dist/cli/{quickstart-OWCJOSQA.js → quickstart-QIHZDBGM.js} +6 -6
  119. package/dist/cli/{run-MT2ABKO5.js → run-IQGM3TO2.js} +46 -46
  120. package/dist/cli/{run-RT73NDP5.mjs → run-JDW6BDNT.mjs} +27 -27
  121. package/dist/cli/search-BNWRL3YY.js +33 -0
  122. package/dist/cli/{search-CJPKIGSA.mjs → search-DMVUKJ23.mjs} +9 -9
  123. package/dist/cli/{search-output-AREMA544.mjs → search-output-5UAPUUHH.mjs} +4 -4
  124. package/dist/cli/{search-output-OSBZ7WK6.js → search-output-UUW6UNHF.js} +6 -6
  125. package/dist/cli/{secrets-BTIY2FEJ.mjs → secrets-46KSTPFN.mjs} +7 -7
  126. package/dist/cli/{secrets-OV6KH633.js → secrets-U532KN24.js} +16 -16
  127. package/dist/cli/sessions-JZUONXH4.js +22 -0
  128. package/dist/cli/sessions-RUNWYHYX.mjs +22 -0
  129. package/dist/cli/{settings-7BQIC7QN.mjs → settings-56L3WHCY.mjs} +14 -14
  130. package/dist/cli/{settings-LBIECYDB.js → settings-O2A37FFA.js} +87 -87
  131. package/dist/cli/{setup-QZE7QR3F.js → setup-ETFSMSCH.js} +50 -50
  132. package/dist/cli/{setup-XPTSNNES.mjs → setup-Q27X6JZY.mjs} +10 -10
  133. package/dist/cli/skills-IKDJ5JDN.js +37 -0
  134. package/dist/cli/{skills-TGGKIQLT.mjs → skills-WFQRZL4D.mjs} +8 -8
  135. package/dist/cli/tools-B735AA67.js +57 -0
  136. package/dist/cli/{tools-MKIFX2TQ.mjs → tools-EV6CKJOX.mjs} +20 -20
  137. package/dist/cli/update-CNNURAM3.js +35 -0
  138. package/dist/cli/{update-5R3D3WNH.mjs → update-KIPPFVCH.mjs} +10 -10
  139. package/dist/cli/{views-VPWEINIA.js → views-DNZ2HFTA.js} +19 -19
  140. package/dist/cli/{views-VHKDHHUP.mjs → views-LMJXWD4N.mjs} +7 -7
  141. package/dist/cli/{workflow-D5DF65N6.mjs → workflow-3XKUQ73U.mjs} +8 -8
  142. package/dist/cli/{workflow-7K2VEQ4V.js → workflow-ZUDTIOK6.js} +18 -18
  143. package/dist/{client-C5_6W8yd.d.mts → client-Bd2meveV.d.mts} +1 -1
  144. package/dist/{client-iXW4TOat.d.ts → client-CBCVhL8U.d.ts} +1 -1
  145. package/dist/{client-core-Dob428Z4.d.mts → client-core-CGj8V9mw.d.mts} +67 -0
  146. package/dist/{client-core-B-GPfmaC.d.ts → client-core-CsRRWCFy.d.ts} +67 -0
  147. package/dist/index.d.mts +3 -3
  148. package/dist/index.d.ts +3 -3
  149. package/dist/index.js +10 -10
  150. package/dist/index.mjs +7 -7
  151. package/dist/install-integrity.json +121 -118
  152. package/dist/plays/play-description.d.mts +1 -1
  153. package/dist/plays/play-description.d.ts +1 -1
  154. package/dist/plays/play-description.js +2 -2
  155. package/dist/plays/play-description.mjs +1 -1
  156. package/dist/plays/run-request.d.mts +1 -1
  157. package/dist/plays/run-request.d.ts +1 -1
  158. package/dist/release.d.mts +1 -1
  159. package/dist/release.d.ts +1 -1
  160. package/dist/release.js +2 -2
  161. package/dist/release.mjs +1 -1
  162. package/dist/server.d.mts +2 -2
  163. package/dist/server.d.ts +2 -2
  164. package/dist/server.js +6 -6
  165. package/dist/server.mjs +4 -4
  166. package/package.json +1 -1
  167. package/dist/cli/auth-OKPHHMMP.js +0 -43
  168. package/dist/cli/describe-5G5NXO5E.js +0 -50
  169. package/dist/cli/describe-OUTXLDGZ.mjs +0 -50
  170. package/dist/cli/git-GDPTG52F.js +0 -25
  171. package/dist/cli/search-7VBA6IGS.js +0 -33
  172. package/dist/cli/sessions-3CO3ZFOD.mjs +0 -18
  173. package/dist/cli/sessions-B3WNEWRW.js +0 -18
  174. package/dist/cli/skills-TXBRTWEV.js +0 -37
  175. package/dist/cli/tools-RZJV4X3J.js +0 -57
  176. package/dist/cli/update-YWGGPWUA.js +0 -35
@@ -0,0 +1,202 @@
1
+ /**
2
+ * How often the platform retried one Play run, as a fixed-size summary.
3
+ *
4
+ * Every count comes from the scheduler's durable run and attempt records, read
5
+ * by `readRunRetryFacts`; nothing here is inferred from logs or error text.
6
+ * The summary has the same keys for every run, so its size never grows with
7
+ * rows, calls, attempts or logs. Event-level detail stays in the paginated run
8
+ * events (`runs logs <run-id> --kind activity.observed`).
9
+ *
10
+ * Only failure-driven retries are counted. A durable wait (event wait, long
11
+ * sleep, rate hold) also ends one scheduler attempt and starts another, and the
12
+ * scheduler keeps no per-attempt record that tells such a wait apart from a
13
+ * lost worker or runner. So raw attempt and sandbox counts are deliberately not
14
+ * reported: a run that only slept must not look like it retried.
15
+ *
16
+ * A retried attempt can repeat work a previous attempt already did: Plays are
17
+ * at-least-once. These counts say how many times the platform retried, never
18
+ * that any effect happened exactly once.
19
+ *
20
+ * Provider HTTP retries inside one tool call, runner-to-gateway transport
21
+ * retries, and lost-worker replacements are not counted: no durable record
22
+ * holds an exact per-run count of any of them.
23
+ */
24
+
25
+ export const RUN_RETRY_RECOVERY_OUTCOMES = [
26
+ 'none',
27
+ 'recovering',
28
+ 'recovered',
29
+ 'exhausted',
30
+ ] as const;
31
+ export type RunRetryRecoveryOutcome =
32
+ (typeof RUN_RETRY_RECOVERY_OUTCOMES)[number];
33
+
34
+ export type RunRetrySummary = {
35
+ /**
36
+ * Counts cover the run's current resume epoch. `runs resume` starts a new
37
+ * epoch and clears the recovery counts of the previous one.
38
+ */
39
+ scope: 'current_epoch';
40
+ /** How many times `runs resume` continued this run; 0 if never resumed. */
41
+ resumeEpoch: number;
42
+ /**
43
+ * Automatic platform recoveries in this epoch: an attempt that failed for a
44
+ * platform reason was retired and the run requeued. `preCode` failed before
45
+ * the Play's code started; `postCode` failed after it started. Exact: each
46
+ * is the scheduler's own fenced defer count.
47
+ */
48
+ platformRecoveries: { preCode: number; postCode: number };
49
+ /**
50
+ * `recovering`: waiting out a recovery delay before the next attempt.
51
+ * `exhausted`: the recovery budget ran out, so the run failed.
52
+ * `recovered`: at least one recovery requeued the run and none is pending;
53
+ * it says nothing about how the run itself ended.
54
+ * `none`: no platform recovery in this epoch.
55
+ */
56
+ recoveryOutcome: RunRetryRecoveryOutcome;
57
+ };
58
+
59
+ /** Raw durable scheduler facts for one run, as read from runtime Postgres. */
60
+ export type RunRetryFacts = {
61
+ /** `launch.resumeEpoch`; absent before the first resume. */
62
+ resumeEpoch: unknown;
63
+ /** `runs.recovery_json`, or null for a run that was never recovered. */
64
+ recovery: unknown;
65
+ /** Whether the queued run is waiting out a recovery delay right now. */
66
+ recovering: boolean;
67
+ };
68
+
69
+ function record(value: unknown): Record<string, unknown> | null {
70
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
71
+ ? (value as Record<string, unknown>)
72
+ : null;
73
+ }
74
+
75
+ const MISSING = Symbol('missing');
76
+ /** A stored JSON value the reader could not parse. */
77
+ export const MALFORMED_STORED_JSON = Symbol('malformed-stored-json');
78
+
79
+ /** A stored count; absent is `MISSING`, anything malformed is `null`. */
80
+ function storedCount(value: unknown): number | null | typeof MISSING {
81
+ if (value === undefined || value === null) return MISSING;
82
+ const parsed = typeof value === 'string' ? Number(value) : value;
83
+ return Number.isSafeInteger(parsed) && (parsed as number) >= 0
84
+ ? (parsed as number)
85
+ : null;
86
+ }
87
+
88
+ function storedTime(value: unknown): boolean | null {
89
+ const parsed = storedCount(value);
90
+ if (parsed === MISSING) return false;
91
+ return parsed === null ? null : true;
92
+ }
93
+
94
+ /**
95
+ * Project the scheduler's facts into the summary. Returns undefined when a
96
+ * stored fact is malformed, so a reader reports the summary as unavailable
97
+ * instead of showing an invented zero.
98
+ */
99
+ export function projectRunRetrySummary(
100
+ facts: RunRetryFacts,
101
+ ): RunRetrySummary | undefined {
102
+ const epoch = storedCount(facts.resumeEpoch);
103
+ if (epoch === null) return undefined;
104
+ // Recovery state is an object or absent; anything else is malformed.
105
+ if (
106
+ facts.recovery !== null &&
107
+ facts.recovery !== undefined &&
108
+ !record(facts.recovery)
109
+ )
110
+ return undefined;
111
+ const recovery = record(facts.recovery) ?? {};
112
+ const postCode = record(recovery.postCode) ?? {};
113
+ const preCode = recovery.kind === 'platform_pre_code' ? recovery : {};
114
+ const postCodeDefers = storedCount(postCode.deferCount);
115
+ const preCodeDefers = storedCount(preCode.deferCount);
116
+ const postCodeExhausted = storedTime(postCode.exhaustedAtMs);
117
+ const preCodeExhausted = storedTime(preCode.exhaustedAtMs);
118
+ if (
119
+ postCodeDefers === null ||
120
+ preCodeDefers === null ||
121
+ postCodeExhausted === null ||
122
+ preCodeExhausted === null
123
+ ) {
124
+ return undefined;
125
+ }
126
+ const platformRecoveries = {
127
+ preCode: preCodeDefers === MISSING ? 0 : preCodeDefers,
128
+ postCode: postCodeDefers === MISSING ? 0 : postCodeDefers,
129
+ };
130
+ const recoveryOutcome: RunRetryRecoveryOutcome = facts.recovering
131
+ ? 'recovering'
132
+ : postCodeExhausted || preCodeExhausted
133
+ ? 'exhausted'
134
+ : platformRecoveries.preCode + platformRecoveries.postCode > 0
135
+ ? 'recovered'
136
+ : 'none';
137
+ return {
138
+ scope: 'current_epoch',
139
+ resumeEpoch: epoch === MISSING ? 0 : epoch,
140
+ platformRecoveries,
141
+ recoveryOutcome,
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Read a summary from an API response. Older servers omit it, and a value
147
+ * that does not match the contract is treated as absent.
148
+ */
149
+ export function normalizeRunRetrySummary(
150
+ value: unknown,
151
+ ): RunRetrySummary | undefined {
152
+ const source = record(value);
153
+ const recoveries = record(source?.platformRecoveries);
154
+ const count = (field: unknown): field is number =>
155
+ Number.isSafeInteger(field) && (field as number) >= 0;
156
+ if (
157
+ !source ||
158
+ !recoveries ||
159
+ source.scope !== 'current_epoch' ||
160
+ !count(source.resumeEpoch) ||
161
+ !count(recoveries.preCode) ||
162
+ !count(recoveries.postCode) ||
163
+ !(RUN_RETRY_RECOVERY_OUTCOMES as readonly unknown[]).includes(
164
+ source.recoveryOutcome,
165
+ )
166
+ ) {
167
+ return undefined;
168
+ }
169
+ return {
170
+ scope: 'current_epoch',
171
+ resumeEpoch: source.resumeEpoch,
172
+ platformRecoveries: {
173
+ preCode: recoveries.preCode,
174
+ postCode: recoveries.postCode,
175
+ },
176
+ recoveryOutcome: source.recoveryOutcome as RunRetryRecoveryOutcome,
177
+ };
178
+ }
179
+
180
+ /** Whether the platform retried or someone resumed the run. */
181
+ export function runWasRetried(summary: RunRetrySummary): boolean {
182
+ return (
183
+ summary.resumeEpoch > 0 ||
184
+ summary.recoveryOutcome !== 'none' ||
185
+ summary.platformRecoveries.preCode + summary.platformRecoveries.postCode > 0
186
+ );
187
+ }
188
+
189
+ /** One line for people. */
190
+ export function formatRunRetrySummary(summary: RunRetrySummary): string {
191
+ const { preCode, postCode } = summary.platformRecoveries;
192
+ const parts = [
193
+ preCode + postCode > 0 || summary.recoveryOutcome !== 'none'
194
+ ? `platform recoveries ${preCode} before code, ${postCode} after code (${summary.recoveryOutcome})`
195
+ : 'no platform recovery',
196
+ ];
197
+ if (summary.resumeEpoch > 0)
198
+ parts.push(
199
+ `resumed ${summary.resumeEpoch} ${summary.resumeEpoch === 1 ? 'time' : 'times'}; counts are since the last resume`,
200
+ );
201
+ return parts.join(' · ');
202
+ }
@@ -62,6 +62,8 @@ const MODAL_CAPACITY_RELEASE_RETRY_DELAYS_MS = [0, 100, 500, 2_000] as const;
62
62
  const MODAL_LATE_CREATE_PERSIST_RETRY_DELAYS_MS = [0, 100, 500, 2_000] as const;
63
63
  // The SDK does not export gRPC status codes.
64
64
  const MODAL_GRPC_STATUS_NOT_FOUND = 5;
65
+ const MODAL_GRPC_STATUS_UNKNOWN = 2;
66
+ const MODAL_GRPC_STATUS_INTERNAL = 13;
65
67
  type ModalSandbox = Awaited<ReturnType<ModalClient['sandboxes']['create']>>;
66
68
 
67
69
  class ModalPayloadUploadTimeoutError extends Error {
@@ -74,15 +76,30 @@ class ModalPayloadUploadTimeoutError extends Error {
74
76
  }
75
77
 
76
78
  /**
77
- * A file did not reach the sandbox because Modal reports the sandbox
78
- * unavailable, which another sandbox can outrun. Staging sends no command, so
79
- * nothing could run. By name, as `isModalSandboxNotFoundError` reads the SDK's
80
- * errors. Other write errors stay loud: the SDK folds a refused credential into
81
- * the same `SandboxFilesystemError` as a provider fault, and a stalled upload
82
- * may be input too large for any sandbox.
79
+ * A file did not reach the sandbox for a reason another sandbox can outrun.
80
+ * Staging sends no command, so nothing could run. By exact class name, as
81
+ * `isModalSandboxNotFoundError` reads the SDK's errors:
82
+ *
83
+ * - `NotFoundError`: Modal reports the sandbox unavailable.
84
+ * - `SandboxFilesystemError` itself, not a subclass: the SDK's class for a
85
+ * write that failed for no reason it names. Its translation of an unexpected
86
+ * control-plane answer ("An unexpected error occurred, please contact
87
+ * support@modal.com") is this class; on Nov 13 it failed 77 runs before
88
+ * `upload:done`. A refused credential folds into it too. That is Deepline's
89
+ * credential, so it defers and a persistent one exhausts the bounded budget
90
+ * as `PLATFORM_RECOVERY_EXHAUSTED`.
91
+ *
92
+ * The named subclasses (permission, not a directory, is a directory) describe
93
+ * the write itself, which any sandbox would repeat, so they stay loud. So does
94
+ * a stalled upload: its input may be too large for any sandbox, and Modal
95
+ * starts one sandbox per attempt, so no earlier start failure in the attempt
96
+ * can show otherwise.
83
97
  */
84
98
  function isUndeliveredModalRunnerFailure(error: unknown): boolean {
85
- return error instanceof Error && error.name === 'NotFoundError';
99
+ return (
100
+ error instanceof Error &&
101
+ (error.name === 'NotFoundError' || error.name === 'SandboxFilesystemError')
102
+ );
86
103
  }
87
104
 
88
105
  async function writeModalFileWithDeadline(input: {
@@ -131,6 +148,41 @@ export class ModalSandboxCreateOutcomeUnknownError extends Error {
131
148
  }
132
149
  }
133
150
 
151
+ /**
152
+ * The pre-code recovery for a Modal create that Modal itself rejected. A typed
153
+ * rejection keeps its own reason (capacity, unavailable). A gRPC `INTERNAL` or
154
+ * `UNKNOWN` answer to the create, such as Modal's "unexpected error", returned
155
+ * no sandbox, so no runner and no customer code exist: it defers on the
156
+ * bounded start budget instead of failing the run. Modal does not create a
157
+ * second sandbox inside an attempt, so the deferral is the retry.
158
+ *
159
+ * Everything else stays terminal. `sandboxes.create` builds the image and the
160
+ * request locally before sending it, so a non-gRPC error is our config and a
161
+ * retry would repeat it. A create that never settled
162
+ * (`ModalSandboxCreateOutcomeUnknownError`) may still produce that sandbox, so
163
+ * its intent stays pending for the reconciler.
164
+ */
165
+ function recoveryForModalCreateRejection(
166
+ error: unknown,
167
+ createSent: boolean,
168
+ ): unknown {
169
+ const typed = recoveryForModalSandboxCreateFailure(error);
170
+ if (typed) return typed;
171
+ if (createSent && isModalCreateRejectedByModal(error)) {
172
+ return recoveryForRunnerStartupNotLive(error);
173
+ }
174
+ return error;
175
+ }
176
+
177
+ /** Modal's control plane answered the create with an untyped gRPC failure. */
178
+ function isModalCreateRejectedByModal(error: unknown): boolean {
179
+ if (!(error instanceof Error) || error.name !== 'ClientError') return false;
180
+ const code = (error as { code?: unknown }).code;
181
+ return (
182
+ code === MODAL_GRPC_STATUS_INTERNAL || code === MODAL_GRPC_STATUS_UNKNOWN
183
+ );
184
+ }
185
+
134
186
  export async function awaitModalSandboxCreate<T>(input: {
135
187
  create: Promise<T>;
136
188
  timeoutMs?: number;
@@ -635,7 +687,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
635
687
  // A create rejection proves no sandbox and no customer code exist.
636
688
  // Preserve that fact for the scheduler rather than converting it
637
689
  // into a terminal runner result below.
638
- throw recoveryForModalSandboxCreateFailure(error) ?? error;
690
+ throw recoveryForModalCreateRejection(error, createSent);
639
691
  }
640
692
  const billingStartedAt = Date.now();
641
693
  runtimeTiming.modalCreateMs = billingStartedAt - startedAt;
@@ -235,3 +235,115 @@ export function emitRecoveredSecretResolutionRetry(input: {
235
235
  },
236
236
  });
237
237
  }
238
+
239
+ /**
240
+ * Durability decisions, as fixed-shape telemetry lines.
241
+ *
242
+ * Each line is emitted where the decision is made, through the process's
243
+ * existing log stream (the Fly worker's stdout feeds `deepline-runtime-logs`,
244
+ * the app's feeds `vercel`). A line carries identities, enums, and counts
245
+ * only: never inputs, outputs, provider text, or secrets. Its size does not
246
+ * grow with the run.
247
+ */
248
+ const DURABILITY_DECISION_REASON = /^[a-z][a-z0-9_]{0,95}$/;
249
+
250
+ /** A code-owned snake_case reason, or `unrecognized` for anything else. */
251
+ function durabilityDecisionReason(reason: unknown): string {
252
+ return typeof reason === 'string' && DURABILITY_DECISION_REASON.test(reason)
253
+ ? reason
254
+ : 'unrecognized';
255
+ }
256
+
257
+ function durabilityDecisionCount(value: unknown): number | null {
258
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
259
+ ? value
260
+ : null;
261
+ }
262
+
263
+ export type PlayRunRecoveryDecision = {
264
+ runId: string;
265
+ orgId: string | null;
266
+ /** The scheduler attempt the decision retired. */
267
+ attempt: number;
268
+ /** `pre_code`: no customer code started. `post_code`: it may have. */
269
+ stage: 'pre_code' | 'post_code';
270
+ /** `deferred`: the same run retries later. `exhausted`: its budget ended. */
271
+ outcome: 'deferred' | 'exhausted';
272
+ /** The scheduler's persisted recovery reason. */
273
+ reason: string;
274
+ /** Pre-code only: the dependency whose circuit owns the decision. */
275
+ dependency: 'modal' | 'runtime' | null;
276
+ /** The run's recovery count for this stage after this decision. */
277
+ deferCount: number | null;
278
+ /** Deferred only: how long until the retry is due. */
279
+ delayMs: number | null;
280
+ };
281
+
282
+ /**
283
+ * One line per platform recovery decision: `play.run.recovery_decision`.
284
+ * Exhaustion is an error (the run fails); a deferral is a warning.
285
+ */
286
+ export function emitPlayRunRecoveryDecision(
287
+ input: PlayRunRecoveryDecision,
288
+ ): void {
289
+ emitPlayTelemetry({
290
+ level: input.outcome === 'exhausted' ? 'error' : 'warn',
291
+ event: 'play.run.recovery_decision',
292
+ tag: '[play.run.recovery_decision]',
293
+ fields: {
294
+ orgId: input.orgId,
295
+ runId: input.runId,
296
+ attempt: durabilityDecisionCount(input.attempt),
297
+ stage: input.stage,
298
+ outcome: input.outcome,
299
+ reason: durabilityDecisionReason(input.reason),
300
+ dependency: input.dependency,
301
+ deferCount: durabilityDecisionCount(input.deferCount),
302
+ delayMs:
303
+ input.outcome === 'deferred'
304
+ ? durabilityDecisionCount(input.delayMs)
305
+ : null,
306
+ },
307
+ });
308
+ }
309
+
310
+ export type PlayRunResumeDecision = {
311
+ runId: string;
312
+ orgId: string;
313
+ /**
314
+ * `accepted`: a new epoch was queued. `refused`: a typed refusal (HTTP 400, 403, 404
315
+ * or 409). `failed`: the request errored before a decision (500 or 503).
316
+ */
317
+ outcome: 'accepted' | 'refused' | 'failed';
318
+ /** Refused only: the typed refusal reason. */
319
+ reason: string | null;
320
+ /** Accepted only: the new resume epoch. */
321
+ epoch: number | null;
322
+ };
323
+
324
+ /** One line per `runs resume` decision: `play.run.resume_decision`. */
325
+ export function emitPlayRunResumeDecision(input: PlayRunResumeDecision): void {
326
+ emitPlayTelemetry({
327
+ level:
328
+ input.outcome === 'failed'
329
+ ? 'error'
330
+ : input.outcome === 'refused'
331
+ ? 'warn'
332
+ : 'info',
333
+ event: 'play.run.resume_decision',
334
+ tag: '[play.run.resume_decision]',
335
+ fields: {
336
+ orgId: input.orgId,
337
+ runId: input.runId,
338
+ outcome: input.outcome,
339
+ reason:
340
+ input.outcome === 'refused'
341
+ ? durabilityDecisionReason(input.reason)
342
+ : null,
343
+ epoch:
344
+ input.outcome === 'accepted'
345
+ ? durabilityDecisionCount(input.epoch)
346
+ : null,
347
+ },
348
+ });
349
+ }
@@ -359,7 +359,10 @@ import {
359
359
  createRunLedgerProjectionJob,
360
360
  type RunLedgerProjectionStats,
361
361
  } from '../play-runs/projection';
362
- import { emitPlayRuntimeSpan } from '../runtime-telemetry';
362
+ import {
363
+ emitPlayRunRecoveryDecision,
364
+ emitPlayRuntimeSpan,
365
+ } from '../runtime-telemetry';
363
366
 
364
367
  /**
365
368
  * A token exchange crosses an HTTP boundary, which otherwise erases the
@@ -4210,6 +4213,19 @@ async function executeAssignedAbsurdAttempt(input: {
4210
4213
  delayMs: deferral.delayMs,
4211
4214
  historyRows: deferral.historyRows,
4212
4215
  });
4216
+ if (deferral.deferred || deferral.exhausted) {
4217
+ emitPlayRunRecoveryDecision({
4218
+ runId,
4219
+ orgId: launch.orgId ?? null,
4220
+ attempt: generation,
4221
+ stage: 'post_code',
4222
+ outcome: deferral.deferred ? 'deferred' : 'exhausted',
4223
+ reason: outcome.reason,
4224
+ dependency: null,
4225
+ deferCount: deferral.deferCount,
4226
+ delayMs: deferral.delayMs,
4227
+ });
4228
+ }
4213
4229
  if (deferral.deferred && deferral.delayMs !== null) {
4214
4230
  // The lost attempts' receipt claims would otherwise hold their calls
4215
4231
  // until the leases expire; the retried attempt must claim them now.
@@ -5678,12 +5694,34 @@ async function executeAssignedAbsurdAttempt(input: {
5678
5694
  ...(detail ? { detail } : {}),
5679
5695
  ...(providerText ? { providerText } : {}),
5680
5696
  });
5697
+ emitPlayRunRecoveryDecision({
5698
+ runId,
5699
+ orgId: launch.orgId ?? null,
5700
+ attempt: generation,
5701
+ stage: 'pre_code',
5702
+ outcome: 'deferred',
5703
+ reason: recovery.reason,
5704
+ dependency: recovery.dependency,
5705
+ deferCount: recovery.deferCount,
5706
+ delayMs: recovery.delaySeconds * 1_000,
5707
+ });
5681
5708
  throw new DeferTask(
5682
5709
  `Platform recovery deferred for ${recovery.dependency}: ${recovery.reason}`,
5683
5710
  recovery.delaySeconds,
5684
5711
  );
5685
5712
  }
5686
5713
  if (recovery.kind === 'exhausted') {
5714
+ emitPlayRunRecoveryDecision({
5715
+ runId,
5716
+ orgId: launch.orgId ?? null,
5717
+ attempt: generation,
5718
+ stage: 'pre_code',
5719
+ outcome: 'exhausted',
5720
+ reason: recovery.reason,
5721
+ dependency: recovery.dependency,
5722
+ deferCount: recovery.deferCount,
5723
+ delayMs: null,
5724
+ });
5687
5725
  return finalizeTerminal({
5688
5726
  claim,
5689
5727
  runnerResult: recovery.terminalResult,
@@ -479,8 +479,8 @@ export async function listDurableRuns(
479
479
  limit: number;
480
480
  cursor?: string | null;
481
481
  /**
482
- * `failed` only: keep platform (exhausted recovery or platform failure)
483
- * or Play failures. Filters a bounded index slice like `recovering`.
482
+ * `failed` only: keep platform (exhausted recovery or platform failure),
483
+ * provider, or Play failures. Filters a bounded index slice like `recovering`.
484
484
  */
485
485
  cause?: DurableRunFailureCause | null;
486
486
  },
@@ -10,6 +10,7 @@ import {
10
10
  } from '../../observability/dlq';
11
11
  import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
12
12
  import { RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE } from '../play-admission-outcome';
13
+ import { RUN_FAILURE_CODES_CLASSED_BEFORE_ORIGIN } from '../run-failure-class';
13
14
 
14
15
  export type DurableRunSqlOptions = { readonly schema?: string };
15
16
  type Options = DurableRunSqlOptions;
@@ -58,6 +59,7 @@ export {
58
59
  /** `list --state failed --cause` → the classes it keeps. */
59
60
  export const DURABLE_RUN_FAILURE_CAUSES = {
60
61
  platform: ['platform_recovery_exhausted', 'platform_failure'],
62
+ provider: ['provider_failure'],
61
63
  play: ['play_error'],
62
64
  } as const satisfies Record<
63
65
  DurableRunFailureCauseFilter,
@@ -69,18 +71,24 @@ export const isDurableRunFailureCause = isDurableRunFailureCauseFilter;
69
71
  const PLATFORM_RECOVERY_EXHAUSTED_PREFIX = 'PLATFORM_RECOVERY_EXHAUSTED:';
70
72
  /**
71
73
  * Leading codes the runtime writes when Deepline, not the Play, failed the
72
- * run: the sandbox never started a runner, or the scheduler was unavailable.
74
+ * run: the sandbox never started a runner, the scheduler was unavailable, a
75
+ * Modal create never settled, or the payload upload to a Modal sandbox missed
76
+ * its deadline. None of these ran customer code.
73
77
  */
74
78
  const PLATFORM_RUNTIME_FAILURE_CODES = [
75
79
  'RUNTIME_SANDBOX_START_FAILED',
76
80
  'RUNTIME_SCHEDULER_UNAVAILABLE',
81
+ 'RUNTIME_MODAL_SANDBOX_CREATE_OUTCOME_UNKNOWN',
82
+ 'MODAL_PAYLOAD_UPLOAD_TIMEOUT',
77
83
  ] as const;
78
84
  /**
79
85
  * Runtime error classes whose stored message is `<Class>: <CODE>: ...`. Only
80
86
  * these names are stripped before reading the leading code: a Play's own
81
87
  * `Error: <CODE>: ...` keeps its class prefix and stays the Play's.
82
88
  */
83
- const RUNTIME_ERROR_CLASS_PREFIXES = ['DaytonaRunnerInitializationError'] as const;
89
+ const RUNTIME_ERROR_CLASS_PREFIXES = [
90
+ 'DaytonaRunnerInitializationError',
91
+ ] as const;
84
92
  /**
85
93
  * The exhausted-recovery message is a fixed Deepline template
86
94
  * (`platformRecoveryExhaustedMessage` and the pre-code variant), well under
@@ -88,6 +96,35 @@ const RUNTIME_ERROR_CLASS_PREFIXES = ['DaytonaRunnerInitializationError'] as con
88
96
  */
89
97
  export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
90
98
 
99
+ /**
100
+ * SQL: whether `runs.terminal_result_json` holds a provider-owned structured
101
+ * failure, read exactly as the public run event reads it
102
+ * (`playRunFailureClass` over the first `errors[]` entry, or its ledger
103
+ * summary): a well-formed entry (string `code` and `phase`, boolean or null
104
+ * `retryable`) whose `origin` is `provider` and whose code is not classed
105
+ * before origin (account policy, platform or caller codes). `origin` is set
106
+ * only from a typed `ToolExecutionError`, never from text, so a Play that
107
+ * merely throws or mentions a provider code stays the Play's. Rows written
108
+ * without `errors[]` or `origin` (older runners, string-only failures, or a
109
+ * result too large to store) read as before. `PROVIDER_EXHAUSTED` without an
110
+ * origin is a text-derived code, so it stays the Play's here.
111
+ */
112
+ function durableRunProviderFailureSql(): string {
113
+ // Extract `errors[0]` once per row: every reference to
114
+ // `runs.terminal_result_json` re-reads the whole stored result (up to
115
+ // TERMINAL_RUN_RESULT_MAX_BYTES), while `entry.failure` is the small entry.
116
+ return `EXISTS (
117
+ SELECT 1
118
+ FROM (SELECT runs.terminal_result_json #> '{errors,0}' AS failure) AS entry
119
+ WHERE jsonb_typeof(entry.failure) = 'object'
120
+ AND jsonb_typeof(entry.failure -> 'code') = 'string'
121
+ AND jsonb_typeof(entry.failure -> 'phase') = 'string'
122
+ AND jsonb_typeof(entry.failure -> 'retryable') IN ('boolean', 'null')
123
+ AND entry.failure ->> 'origin' = 'provider'
124
+ AND upper(btrim(entry.failure ->> 'code')) <> ALL (ARRAY[${RUN_FAILURE_CODES_CLASSED_BEFORE_ORIGIN.map((code) => `'${code}'`).join(', ')}]::text[])
125
+ )`;
126
+ }
127
+
91
128
  /**
92
129
  * SQL: `LEFT JOIN LATERAL ... AS failure` over `runs`, yielding
93
130
  * `failure.failure_class`, `failure_code`, `failure_message` and
@@ -106,9 +143,17 @@ export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
106
143
  * admission sessions expired) failed on Deepline's authority, not its code.
107
144
  * So did a sandbox that never started a runner (`RUNTIME_SANDBOX_START_FAILED`,
108
145
  * also behind a known runtime error class such as
109
- * `DaytonaRunnerInitializationError: `) and an unavailable scheduler
110
- * (`RUNTIME_SCHEDULER_UNAVAILABLE`). Only the leading code position counts,
111
- * so stored rows of any age read the same way.
146
+ * `DaytonaRunnerInitializationError: `), an unavailable scheduler
147
+ * (`RUNTIME_SCHEDULER_UNAVAILABLE`), a Modal create that never settled
148
+ * (`RUNTIME_MODAL_SANDBOX_CREATE_OUTCOME_UNKNOWN`) and a Modal payload upload
149
+ * past its deadline (`MODAL_PAYLOAD_UPLOAD_TIMEOUT`). Only the leading code
150
+ * position counts, so stored rows of any age read the same way.
151
+ *
152
+ * A failure no platform rule claims is `provider_failure` when the run's
153
+ * stored terminal result carries a provider-origin structured failure (see
154
+ * `durableRunProviderFailureSql`), the class the public run event gives it;
155
+ * otherwise `play_error`. `terminal_result_json` is read only on that branch,
156
+ * so platform-classed and non-failed rows never load it.
112
157
  */
113
158
  export function durableRunFailureLateralSql(): string {
114
159
  return `LEFT JOIN LATERAL (
@@ -124,6 +169,8 @@ export function durableRunFailureLateralSql(): string {
124
169
  OR parsed.code IN ('CTX_RUN_PLAY_INLINE_ONLY', '${RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE}', ${PLATFORM_RUNTIME_FAILURE_CODES.map((code) => `'${code}'`).join(', ')})
125
170
  OR starts_with(parsed.code, 'SCHEDULER_')
126
171
  THEN 'platform_failure'
172
+ WHEN ${durableRunProviderFailureSql()}
173
+ THEN 'provider_failure'
127
174
  ELSE 'play_error'
128
175
  END AS failure_class,
129
176
  CASE
@@ -27,7 +27,13 @@ export type PlayRunRecoveryOutcome =
27
27
  deadlineAtMs: number | null;
28
28
  delaySeconds: number;
29
29
  }
30
- | { kind: 'exhausted'; terminalResult: PlayRunnerResult };
30
+ | {
31
+ kind: 'exhausted';
32
+ dependency: 'modal' | 'runtime';
33
+ reason: string;
34
+ deferCount: number | null;
35
+ terminalResult: PlayRunnerResult;
36
+ };
31
37
 
32
38
  export async function transitionPreCodePlayRunRecovery(input: {
33
39
  error: unknown;
@@ -81,6 +87,9 @@ export async function transitionPreCodePlayRunRecovery(input: {
81
87
  if (recovery.exhausted) {
82
88
  return {
83
89
  kind: 'exhausted',
90
+ dependency: decision.dependency,
91
+ reason: decision.reason,
92
+ deferCount: recovery.deferCount,
84
93
  terminalResult: {
85
94
  status: 'failed',
86
95
  error: