deepline 0.3.522 → 0.3.524

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/client-core.ts +178 -60
  2. package/dist/bundling-sources/sdk/src/index.ts +3 -0
  3. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  4. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +60 -14
  5. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +9 -3
  6. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +406 -40
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +1 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/db-session-renewal.ts +209 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -6
  11. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +388 -13
  12. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +28 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +5 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +1 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +38 -5
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +92 -10
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +96 -25
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +29 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +139 -17
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +26 -3
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +145 -5
  22. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +190 -10
  23. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +85 -5
  24. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +21 -11
  25. package/dist/cli/auth-OKPHHMMP.js +43 -0
  26. package/dist/cli/{auth-YIBY5IKT.mjs → auth-QXJMVLPN.mjs} +5 -5
  27. package/dist/cli/{billing-UDKL53GI.js → billing-N5R4HTHT.js} +82 -82
  28. package/dist/cli/{billing-G3IX3SNY.mjs → billing-SNSIFM4B.mjs} +7 -7
  29. package/dist/cli/{chunk-EJBW7Y6Z.js → chunk-2ZWNIS54.js} +108 -96
  30. package/dist/cli/{chunk-3KMGVOBM.mjs → chunk-2ZX7XSAQ.mjs} +4 -4
  31. package/dist/cli/{chunk-4TUMKJZX.mjs → chunk-3WWTBQHC.mjs} +2 -2
  32. package/dist/cli/{chunk-MD524MRB.mjs → chunk-536TGWR6.mjs} +1 -1
  33. package/dist/cli/{chunk-37SXIFIU.js → chunk-66N76YZG.js} +44 -44
  34. package/dist/cli/{chunk-BZY335JP.js → chunk-7E6B7VMS.js} +5 -5
  35. package/dist/cli/{chunk-HYR34KFA.js → chunk-7OQGZBDG.js} +109 -24
  36. package/dist/cli/{chunk-GVKW3LCA.js → chunk-7QM6DNR4.js} +11 -11
  37. package/dist/cli/{chunk-DNJJ3ULJ.js → chunk-ANKD3AIR.js} +2 -2
  38. package/dist/cli/{chunk-4DFWDA2Q.js → chunk-ATATJNJ6.js} +9 -9
  39. package/dist/cli/{chunk-ZZ7U4YJS.mjs → chunk-BXIQD2IY.mjs} +1 -1
  40. package/dist/cli/{chunk-XT25FX6T.js → chunk-BXVYVIMB.js} +3 -3
  41. package/dist/cli/{chunk-XR6TN5DT.mjs → chunk-CH7JVSA7.mjs} +6 -6
  42. package/dist/cli/{chunk-RKE5YTHY.mjs → chunk-EO55Y4QW.mjs} +5 -5
  43. package/dist/cli/{chunk-RI672VNY.js → chunk-EQNAQENZ.js} +2 -2
  44. package/dist/cli/{chunk-LFSOBW7E.mjs → chunk-FXTV5B3D.mjs} +22 -10
  45. package/dist/cli/{chunk-C6WGMODR.mjs → chunk-GMO3JDZA.mjs} +2 -2
  46. package/dist/cli/{chunk-DRDZBRXV.js → chunk-GTGJBZVH.js} +7 -7
  47. package/dist/cli/{chunk-SFMCKB57.mjs → chunk-HLAFGQPV.mjs} +76 -34
  48. package/dist/cli/{chunk-534YYHIF.js → chunk-HTYT2OHB.js} +6 -6
  49. package/dist/cli/{chunk-ZZLZCO6Y.js → chunk-I75VRGQG.js} +22 -22
  50. package/dist/cli/{chunk-Y3LDRCMB.mjs → chunk-II3BJKCH.mjs} +2 -2
  51. package/dist/cli/{chunk-5BQPEHEP.js → chunk-JDIQBZ6O.js} +14 -14
  52. package/dist/cli/{chunk-ENWJFUWK.mjs → chunk-KKPBCB6D.mjs} +2 -2
  53. package/dist/cli/{chunk-BONXEWYF.mjs → chunk-KSQXBLRW.mjs} +3 -3
  54. package/dist/cli/{chunk-7JEN3FX4.js → chunk-LRWDZDBS.js} +5 -5
  55. package/dist/cli/{chunk-5477PEHL.mjs → chunk-MW3YMPD2.mjs} +1 -1
  56. package/dist/cli/{chunk-VFCVH2LV.mjs → chunk-NUC7ZVDG.mjs} +5 -5
  57. package/dist/cli/{chunk-DLDWAPA5.js → chunk-OCT4SUJA.js} +4 -4
  58. package/dist/cli/{chunk-FQQAAR3Q.mjs → chunk-OQ5G7RFQ.mjs} +1 -1
  59. package/dist/cli/{chunk-VIM6I7RC.js → chunk-PFKKZVFK.js} +41 -41
  60. package/dist/cli/{chunk-OAQIVJFY.mjs → chunk-PFKWKWUJ.mjs} +2 -2
  61. package/dist/cli/{chunk-52MHE7B4.mjs → chunk-R457IMHJ.mjs} +1 -1
  62. package/dist/cli/{chunk-UV6XCHOZ.mjs → chunk-RIX26ZJD.mjs} +1 -1
  63. package/dist/cli/{chunk-RDJTCW3I.mjs → chunk-RTDX5NNN.mjs} +3 -3
  64. package/dist/cli/{chunk-FNHUDCJE.js → chunk-RUULUCBP.js} +10 -10
  65. package/dist/cli/{chunk-GMYDVW7Z.js → chunk-SF4QJVBE.js} +3 -3
  66. package/dist/cli/{chunk-DARD7TJ7.js → chunk-SMWFOGUT.js} +53 -53
  67. package/dist/cli/{chunk-XXY4E57R.mjs → chunk-T43FF5PF.mjs} +2 -2
  68. package/dist/cli/{chunk-ZUAKRBZB.js → chunk-TZTWH53O.js} +1 -1
  69. package/dist/cli/{chunk-7J5PLHII.mjs → chunk-V2YIBBVT.mjs} +1 -1
  70. package/dist/cli/{chunk-6SJPZV5E.js → chunk-V4RJ57MA.js} +2 -2
  71. package/dist/cli/{chunk-4MF44THR.js → chunk-V7KUBDEB.js} +82 -40
  72. package/dist/cli/{chunk-ISUUSSS4.js → chunk-VHTVXS5A.js} +16 -16
  73. package/dist/cli/{chunk-NDNG3MAT.mjs → chunk-WCVIPZWX.mjs} +5 -5
  74. package/dist/cli/{chunk-F5D623KO.js → chunk-WOEPDSO3.js} +26 -26
  75. package/dist/cli/{chunk-VE6FHVXZ.mjs → chunk-XURWFEXM.mjs} +109 -24
  76. package/dist/cli/{chunk-G65FJ5JX.mjs → chunk-YCIXY66B.mjs} +2 -2
  77. package/dist/cli/{chunk-CFXERH7F.mjs → chunk-YGOI5ZE5.mjs} +1 -1
  78. package/dist/cli/{chunk-PDLRUZ42.mjs → chunk-YKFW3NNA.mjs} +5 -5
  79. package/dist/cli/{chunk-5H22VJPE.js → chunk-YXVYPYIP.js} +6 -6
  80. package/dist/cli/{chunk-KMBF3N2Z.js → chunk-Z4MOEQSY.js} +16 -16
  81. package/dist/cli/command-docs.js +2 -2
  82. package/dist/cli/command-docs.mjs +1 -1
  83. package/dist/cli/{csv-PE35WGRO.mjs → csv-HT2JBCW2.mjs} +4 -4
  84. package/dist/cli/{csv-3HIE4VCO.js → csv-Q2LWKXAV.js} +13 -13
  85. package/dist/cli/{db-L7ZMMQKW.mjs → db-CS3XQ2LX.mjs} +6 -6
  86. package/dist/cli/{db-O2YRTTDO.js → db-XEV4WEE4.js} +27 -27
  87. package/dist/cli/describe-5G5NXO5E.js +50 -0
  88. package/dist/cli/{describe-NI324Y2M.mjs → describe-OUTXLDGZ.mjs} +18 -18
  89. package/dist/cli/describe-core.d.mts +3 -3
  90. package/dist/cli/describe-core.d.ts +3 -3
  91. package/dist/cli/{executions-VH4DKLFI.js → executions-JCC34WAD.js} +8 -8
  92. package/dist/cli/{executions-T6KU2OKK.mjs → executions-L6XFG5MP.mjs} +6 -6
  93. package/dist/cli/{feedback-SCSJC3FX.mjs → feedback-AWBDO5I6.mjs} +5 -5
  94. package/dist/cli/{feedback-ZLC6G5OK.js → feedback-HV2M2G7N.js} +10 -10
  95. package/dist/cli/git-GDPTG52F.js +25 -0
  96. package/dist/cli/{git-I4LVQCID.mjs → git-S4LRXTRX.mjs} +5 -5
  97. package/dist/cli/index.js +146 -146
  98. package/dist/cli/index.mjs +45 -45
  99. package/dist/cli/{legacy-noops-44FQ2256.mjs → legacy-noops-7MOKBL4O.mjs} +6 -6
  100. package/dist/cli/{legacy-noops-UPFWEHPG.js → legacy-noops-RGSZUD6V.js} +9 -9
  101. package/dist/cli/{monitors-JN6IQGK6.js → monitors-JEFM2C5W.js} +100 -100
  102. package/dist/cli/{monitors-LMSASWXE.mjs → monitors-XQNXDZPQ.mjs} +7 -7
  103. package/dist/cli/{org-F7O3ZU5O.js → org-GYLA5V32.js} +235 -72
  104. package/dist/cli/{org-QYLVEE7A.mjs → org-KTMJZGTN.mjs} +169 -6
  105. package/dist/cli/{pages-KEL3Y4L4.js → pages-RY4U7OCL.js} +18 -18
  106. package/dist/cli/{pages-5XE4LBZN.mjs → pages-WOMU2T2O.mjs} +6 -6
  107. package/dist/cli/{play-OURHH6KV.js → play-2Q6MWJ3D.js} +363 -323
  108. package/dist/cli/{play-MWQG3G32.mjs → play-KOYGGNYS.mjs} +64 -24
  109. package/dist/cli/{providers-IQY7LUBB.mjs → providers-7YKDITJC.mjs} +6 -6
  110. package/dist/cli/{providers-ZCBWPE3C.js → providers-HOIRHMN2.js} +9 -9
  111. package/dist/cli/{quickstart-O53OXTN6.js → quickstart-OWCJOSQA.js} +6 -6
  112. package/dist/cli/{quickstart-L45NGRMI.mjs → quickstart-RDXHSMVX.mjs} +4 -4
  113. package/dist/cli/{run-W745Z3Z5.js → run-MT2ABKO5.js} +41 -41
  114. package/dist/cli/{run-VCSIWLEU.mjs → run-RT73NDP5.mjs} +23 -23
  115. package/dist/cli/search-7VBA6IGS.js +33 -0
  116. package/dist/cli/{search-THELKULN.mjs → search-CJPKIGSA.mjs} +8 -8
  117. package/dist/cli/{search-output-N7MJLYYD.mjs → search-output-AREMA544.mjs} +4 -4
  118. package/dist/cli/{search-output-SJW7LEOM.js → search-output-OSBZ7WK6.js} +6 -6
  119. package/dist/cli/{secrets-44ST3FJH.mjs → secrets-BTIY2FEJ.mjs} +6 -6
  120. package/dist/cli/{secrets-GDXPX3KB.js → secrets-OV6KH633.js} +15 -15
  121. package/dist/cli/{sessions-LYCBI77S.mjs → sessions-3CO3ZFOD.mjs} +6 -6
  122. package/dist/cli/sessions-B3WNEWRW.js +18 -0
  123. package/dist/cli/{settings-GXPDMJFG.mjs → settings-7BQIC7QN.mjs} +13 -13
  124. package/dist/cli/{settings-3WOFF642.js → settings-LBIECYDB.js} +86 -86
  125. package/dist/cli/{setup-YHLMBJP4.js → setup-QZE7QR3F.js} +50 -50
  126. package/dist/cli/{setup-YM6JEB64.mjs → setup-XPTSNNES.mjs} +10 -10
  127. package/dist/cli/{skills-WX4XWEAT.mjs → skills-TGGKIQLT.mjs} +8 -8
  128. package/dist/cli/skills-TXBRTWEV.js +37 -0
  129. package/dist/cli/{tools-K24VSQ7S.mjs → tools-MKIFX2TQ.mjs} +17 -17
  130. package/dist/cli/tools-RZJV4X3J.js +57 -0
  131. package/dist/cli/{update-PSSCF5AT.mjs → update-5R3D3WNH.mjs} +10 -10
  132. package/dist/cli/update-YWGGPWUA.js +35 -0
  133. package/dist/cli/{artifacts-RY2MK74N.mjs → views-VHKDHHUP.mjs} +76 -76
  134. package/dist/cli/views-VPWEINIA.js +270 -0
  135. package/dist/cli/{workflow-FPVI3NIA.js → workflow-7K2VEQ4V.js} +17 -17
  136. package/dist/cli/{workflow-DGOPYATO.mjs → workflow-D5DF65N6.mjs} +7 -7
  137. package/dist/{client-DA71-2_u.d.mts → client-C5_6W8yd.d.mts} +1 -1
  138. package/dist/{client-core-C0IzDKMJ.d.ts → client-core-B-GPfmaC.d.ts} +121 -44
  139. package/dist/{client-core-BXbds1cb.d.mts → client-core-Dob428Z4.d.mts} +121 -44
  140. package/dist/{client-B-2Am2y6.d.ts → client-iXW4TOat.d.ts} +1 -1
  141. package/dist/{compiler-manifest-B4mIIbw7.d.mts → compiler-manifest-DsxsQP-T.d.mts} +14 -7
  142. package/dist/{compiler-manifest-B4mIIbw7.d.ts → compiler-manifest-DsxsQP-T.d.ts} +14 -7
  143. package/dist/{errors-Gj9i5Rkd.d.ts → errors-Bk5h1D-C.d.ts} +1 -1
  144. package/dist/{errors-C2F4qzAq.d.mts → errors-qdJUVQ3g.d.mts} +1 -1
  145. package/dist/{index-5JZBufdF.d.mts → index-PaupwX1B.d.mts} +1 -1
  146. package/dist/{index-BXtSj8bv.d.ts → index-bL66eHYz.d.ts} +1 -1
  147. package/dist/index.d.mts +7 -7
  148. package/dist/index.d.ts +7 -7
  149. package/dist/index.js +9 -9
  150. package/dist/index.mjs +6 -6
  151. package/dist/install-integrity.json +117 -116
  152. package/dist/plays/bundle-play-file.d.mts +3 -3
  153. package/dist/plays/bundle-play-file.d.ts +3 -3
  154. package/dist/plays/bundle-play-file.mjs +7 -5
  155. package/dist/plays/play-description.d.mts +2 -2
  156. package/dist/plays/play-description.d.ts +2 -2
  157. package/dist/plays/run-request.d.mts +2 -2
  158. package/dist/plays/run-request.d.ts +2 -2
  159. package/dist/release.d.mts +1 -1
  160. package/dist/release.d.ts +1 -1
  161. package/dist/release.js +2 -2
  162. package/dist/release.mjs +1 -1
  163. package/dist/server.d.mts +4 -4
  164. package/dist/server.d.ts +4 -4
  165. package/dist/server.js +5 -5
  166. package/dist/server.mjs +3 -3
  167. package/package.json +1 -1
  168. package/dist/cli/artifacts-GIZZH5VA.js +0 -270
  169. package/dist/cli/auth-JSES2JOQ.js +0 -43
  170. package/dist/cli/describe-EB336DAO.js +0 -50
  171. package/dist/cli/git-23T7TXAH.js +0 -25
  172. package/dist/cli/search-R6K7ZAMU.js +0 -33
  173. package/dist/cli/sessions-2V5ZFOWL.js +0 -18
  174. package/dist/cli/skills-XNGADDO6.js +0 -37
  175. package/dist/cli/tools-ROUMCB7B.js +0 -57
  176. package/dist/cli/update-RXURGIRW.js +0 -35
@@ -9,6 +9,7 @@ import {
9
9
  type DurableRunFailureClass,
10
10
  } from '../../observability/dlq';
11
11
  import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
12
+ import { RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE } from '../play-admission-outcome';
12
13
 
13
14
  export type DurableRunSqlOptions = { readonly schema?: string };
14
15
  type Options = DurableRunSqlOptions;
@@ -66,6 +67,20 @@ export type DurableRunFailureCause = DurableRunFailureCauseFilter;
66
67
  export const isDurableRunFailureCause = isDurableRunFailureCauseFilter;
67
68
 
68
69
  const PLATFORM_RECOVERY_EXHAUSTED_PREFIX = 'PLATFORM_RECOVERY_EXHAUSTED:';
70
+ /**
71
+ * 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.
73
+ */
74
+ const PLATFORM_RUNTIME_FAILURE_CODES = [
75
+ 'RUNTIME_SANDBOX_START_FAILED',
76
+ 'RUNTIME_SCHEDULER_UNAVAILABLE',
77
+ ] as const;
78
+ /**
79
+ * Runtime error classes whose stored message is `<Class>: <CODE>: ...`. Only
80
+ * these names are stripped before reading the leading code: a Play's own
81
+ * `Error: <CODE>: ...` keeps its class prefix and stays the Play's.
82
+ */
83
+ const RUNTIME_ERROR_CLASS_PREFIXES = ['DaytonaRunnerInitializationError'] as const;
69
84
  /**
70
85
  * The exhausted-recovery message is a fixed Deepline template
71
86
  * (`platformRecoveryExhaustedMessage` and the pre-code variant), well under
@@ -85,7 +100,15 @@ export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
85
100
  * fixed exhausted-recovery template. Platform-vs-Play mirrors
86
101
  * `runtimeTerminalReasonFromError`: sandbox killed/lost and lost leases are
87
102
  * platform; runtime limit and sandbox OOM are the Play's; scheduler-written
88
- * codes (`SCHEDULER_*`, `CTX_RUN_PLAY_INLINE_ONLY`) are platform.
103
+ * codes (`SCHEDULER_*`, `CTX_RUN_PLAY_INLINE_ONLY`) are platform. A run whose
104
+ * data plane had no usable Runtime DB session
105
+ * (`RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE`, e.g. one that woke after its
106
+ * admission sessions expired) failed on Deepline's authority, not its code.
107
+ * So did a sandbox that never started a runner (`RUNTIME_SANDBOX_START_FAILED`,
108
+ * 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.
89
112
  */
90
113
  export function durableRunFailureLateralSql(): string {
91
114
  return `LEFT JOIN LATERAL (
@@ -98,7 +121,7 @@ export function durableRunFailureLateralSql(): string {
98
121
  THEN 'platform_recovery_exhausted'
99
122
  WHEN parsed.message IS NULL THEN 'unknown'
100
123
  WHEN parsed.terminal_reason IN ('sandbox_killed', 'sandbox_missing', 'lease_expired')
101
- OR parsed.code = 'CTX_RUN_PLAY_INLINE_ONLY'
124
+ OR parsed.code IN ('CTX_RUN_PLAY_INLINE_ONLY', '${RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE}', ${PLATFORM_RUNTIME_FAILURE_CODES.map((code) => `'${code}'`).join(', ')})
102
125
  OR starts_with(parsed.code, 'SCHEDULER_')
103
126
  THEN 'platform_failure'
104
127
  ELSE 'play_error'
@@ -130,7 +153,7 @@ export function durableRunFailureLateralSql(): string {
130
153
  raw.exhausted_at_ms,
131
154
  coalesce(
132
155
  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}):')
156
+ substring(raw.message FROM '^(?:(?:${RUNTIME_ERROR_CLASS_PREFIXES.join('|')}): )?([A-Z][A-Z0-9_]{2,63}):')
134
157
  ) AS code,
135
158
  CASE
136
159
  WHEN raw.message ~* 'RUNTIME_LIMIT_EXCEEDED' THEN 'runtime_limit'
@@ -69,6 +69,7 @@ import {
69
69
  } from './runtime-event-search';
70
70
  import type { PlayRunnerRuntimeResource } from '../runner-backends/types';
71
71
  import {
72
+ RUNTIME_SANDBOX_OPERATION_TERMINAL_STATES,
72
73
  RuntimeSandboxOperationState,
73
74
  type RuntimeSandboxProvider,
74
75
  runtimeSandboxOperationFromStates,
@@ -11012,10 +11013,23 @@ const POSTGRES_SCHEDULER_ATTEMPT_AUTHORITY_FIELDS = [
11012
11013
  export type PostgresSchedulerAttemptAuthority = Pick<
11013
11014
  PlaySchedulerSubmitInput,
11014
11015
  (typeof POSTGRES_SCHEDULER_ATTEMPT_AUTHORITY_FIELDS)[number]
11015
- > & { computeSessionIntentPersisted?: boolean };
11016
+ > & {
11017
+ computeSessionIntentPersisted?: boolean;
11018
+ /**
11019
+ * Present only when the caller asked for it: the stored preloaded Runtime
11020
+ * DB session array (null when the launch has none) and the key that sealed
11021
+ * it, falling back to the stored submit-time token as every reader does.
11022
+ */
11023
+ preloadedDbSessionRenewalSource?: {
11024
+ sessions: unknown[] | null;
11025
+ unwrapKey: string | null;
11026
+ };
11027
+ };
11016
11028
 
11017
11029
  type PostgresSchedulerAuthorityRow = PostgresSchedulerAttemptAuthority & {
11018
11030
  launch_required_fields_valid: boolean;
11031
+ preloaded_db_sessions?: unknown;
11032
+ preloaded_db_session_unwrap_key?: unknown;
11019
11033
  };
11020
11034
 
11021
11035
  // Keep JSON types intact: text columns would coerce malformed launch scalars.
@@ -11035,13 +11049,31 @@ function parsePostgresSchedulerAuthorityRow(
11035
11049
  row: PostgresSchedulerAuthorityRow | undefined,
11036
11050
  ): PostgresSchedulerAttemptAuthority | null {
11037
11051
  if (!row) return null;
11038
- const { launch_required_fields_valid, ...authority } = row;
11052
+ const {
11053
+ launch_required_fields_valid,
11054
+ preloaded_db_sessions,
11055
+ preloaded_db_session_unwrap_key,
11056
+ ...authority
11057
+ } = row;
11039
11058
  if (launch_required_fields_valid !== true) {
11040
11059
  throw new Error(
11041
11060
  'Postgres scheduler launch_json is missing required fields.',
11042
11061
  );
11043
11062
  }
11044
- return authority;
11063
+ if (preloaded_db_sessions === undefined) return authority;
11064
+ return {
11065
+ ...authority,
11066
+ preloadedDbSessionRenewalSource: {
11067
+ sessions: Array.isArray(preloaded_db_sessions)
11068
+ ? preloaded_db_sessions
11069
+ : null,
11070
+ unwrapKey:
11071
+ typeof preloaded_db_session_unwrap_key === 'string' &&
11072
+ preloaded_db_session_unwrap_key
11073
+ ? preloaded_db_session_unwrap_key
11074
+ : null,
11075
+ },
11076
+ };
11045
11077
  }
11046
11078
 
11047
11079
  /**
@@ -11053,12 +11085,31 @@ function parsePostgresSchedulerAuthorityRow(
11053
11085
  */
11054
11086
  export async function readPostgresSchedulerAttemptAuthorityForLease(
11055
11087
  client: PostgresSchedulerQueryClient,
11056
- input: { runId: string; attempt: number; leaseToken: string },
11088
+ input: {
11089
+ runId: string;
11090
+ attempt: number;
11091
+ leaseToken: string;
11092
+ /**
11093
+ * Also return the stored preloaded sessions and their sealing key, so the
11094
+ * token issuer can renew expired sessions without a second round trip.
11095
+ * Bounded: the array holds one entry per declared sheet plus receipts.
11096
+ */
11097
+ includePreloadedDbSessions?: boolean;
11098
+ },
11057
11099
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
11058
11100
  ): Promise<PostgresSchedulerAttemptAuthority | null> {
11059
11101
  const result = await client.query<PostgresSchedulerAuthorityRow>(
11060
11102
  `
11061
11103
  SELECT ${POSTGRES_SCHEDULER_AUTHORITY_SELECT},
11104
+ ${
11105
+ input.includePreloadedDbSessions === true
11106
+ ? `runs.launch_json -> 'preloadedDbSessions' AS preloaded_db_sessions,
11107
+ coalesce(
11108
+ nullif(runs.launch_json ->> 'preloadedDbSessionUnwrapKey', ''),
11109
+ runs.launch_json ->> 'executorToken'
11110
+ ) AS preloaded_db_session_unwrap_key,`
11111
+ : ''
11112
+ }
11062
11113
  EXISTS (
11063
11114
  SELECT 1 FROM jsonb_array_elements(
11064
11115
  CASE
@@ -11085,6 +11136,56 @@ export async function readPostgresSchedulerAttemptAuthorityForLease(
11085
11136
  return parsePostgresSchedulerAuthorityRow(result.rows[0]);
11086
11137
  }
11087
11138
 
11139
+ /**
11140
+ * Replace the stored preloaded sessions with renewed ones, only while the
11141
+ * attempt lease is active and only if the stored array is still the one the
11142
+ * caller renewed. `preloadedDbSessions` is outside the launch admission
11143
+ * identity and is never part of `admission_json`, so this changes no run
11144
+ * identity. Returns false when the lease ended or another issuer already
11145
+ * replaced the array; the caller retries and then sees the fresh sessions.
11146
+ */
11147
+ export async function replacePostgresSchedulerPreloadedDbSessionsForLease(
11148
+ client: PostgresSchedulerQueryClient,
11149
+ input: {
11150
+ runId: string;
11151
+ attempt: number;
11152
+ leaseToken: string;
11153
+ expected: unknown[];
11154
+ sessions: unknown[];
11155
+ },
11156
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
11157
+ ): Promise<boolean> {
11158
+ const result = await client.query<{ run_id: string }>(
11159
+ `
11160
+ UPDATE ${tableName('runs', options)} AS runs
11161
+ SET launch_json = jsonb_set(
11162
+ runs.launch_json,
11163
+ '{preloadedDbSessions}',
11164
+ $5::jsonb
11165
+ )
11166
+ WHERE runs.run_id = $1
11167
+ AND runs.launch_json -> 'preloadedDbSessions' = $4::jsonb
11168
+ AND runs.status IN ('queued', 'running', 'waiting')
11169
+ AND EXISTS (
11170
+ SELECT 1 FROM ${tableName('attempts', options)} AS attempts
11171
+ WHERE attempts.run_id = runs.run_id
11172
+ AND attempts.attempt = $2
11173
+ AND attempts.lease_token = $3
11174
+ AND attempts.status IN ('claimed', 'running', 'waiting')
11175
+ )
11176
+ RETURNING runs.run_id
11177
+ `,
11178
+ [
11179
+ input.runId,
11180
+ input.attempt,
11181
+ input.leaseToken,
11182
+ JSON.stringify(input.expected),
11183
+ JSON.stringify(input.sessions),
11184
+ ],
11185
+ );
11186
+ return result.rows.length === 1;
11187
+ }
11188
+
11088
11189
  /**
11089
11190
  * Absurd scheduler backend: persist the vendored engine's task id on the run
11090
11191
  * row after `spawn`. Idempotent (last write wins); a re-submit under the same
@@ -17079,6 +17180,14 @@ export async function cancelPostgresSchedulerRun(
17079
17180
  * exists to cancel through. Zero attempts proves execution never began.
17080
17181
  */
17081
17182
  onlyIfCreatedProjectionFailed?: { absurdTaskId: string };
17183
+ /**
17184
+ * Fence for a caller stop of a run no worker ever started. The caller has
17185
+ * already cancelled the engine task in this transaction and proved the
17186
+ * engine never claimed it. Zero scheduler attempts and no unfinished
17187
+ * sandbox operation, cleanup job or ambiguous create prove there is no
17188
+ * execution or provider resource left to wait for.
17189
+ */
17190
+ onlyIfUnclaimed?: { absurdTaskId: string };
17082
17191
  /**
17083
17192
  * Optional control-plane ownership for the oldest pending causal fact.
17084
17193
  * Cancellation makes the remaining prefix due without sharing this lease
@@ -17096,9 +17205,33 @@ export async function cancelPostgresSchedulerRun(
17096
17205
  );
17097
17206
  const strandedFence = input.onlyIfStrandedPreExecution;
17098
17207
  const createdFence = input.onlyIfCreatedProjectionFailed;
17099
- if (strandedFence && createdFence) {
17208
+ const unclaimedFence = input.onlyIfUnclaimed;
17209
+ if (
17210
+ [strandedFence, createdFence, unclaimedFence].filter(Boolean).length > 1
17211
+ ) {
17100
17212
  throw new Error('A scheduler cancellation accepts one operator fence.');
17101
17213
  }
17214
+ const unclaimedEligibility = unclaimedFence
17215
+ ? `AND target.status = 'queued'
17216
+ AND target.absurd_task_id = $8
17217
+ AND NOT EXISTS (
17218
+ SELECT 1 FROM ${tableName('attempts', options)} AS attempt
17219
+ WHERE attempt.run_id = target.run_id
17220
+ )
17221
+ AND NOT EXISTS (
17222
+ SELECT 1 FROM ${tableName('runtime_sandbox_operations', options)} AS operation
17223
+ WHERE operation.run_id = target.run_id
17224
+ AND operation.state::text <> ALL($9::text[])
17225
+ )
17226
+ AND NOT EXISTS (
17227
+ SELECT 1 FROM ${tableName('sandbox_cleanup_jobs_v2', options)} AS cleanup
17228
+ WHERE cleanup.run_id = target.run_id AND cleanup.status <> 'deleted'
17229
+ )
17230
+ AND NOT EXISTS (
17231
+ SELECT 1 FROM ${tableName('ambiguous_modal_creates', options)} AS intent
17232
+ WHERE intent.run_id = target.run_id AND intent.status = 'pending'
17233
+ )`
17234
+ : '';
17102
17235
  const createdEligibility = createdFence
17103
17236
  ? `AND target.status = 'queued'
17104
17237
  AND target.absurd_task_id = $8
@@ -17149,6 +17282,7 @@ export async function cancelPostgresSchedulerRun(
17149
17282
  AND target.status IN ('queued', 'running', 'waiting')
17150
17283
  ${strandedEligibility}
17151
17284
  ${createdEligibility}
17285
+ ${unclaimedEligibility}
17152
17286
  RETURNING target.run_id, target.launch_json
17153
17287
  ),
17154
17288
  cancelled_attempts AS (
@@ -17325,6 +17459,12 @@ export async function cancelPostgresSchedulerRun(
17325
17459
  ? [strandedFence.releaseId, strandedFence.absurdTaskId]
17326
17460
  : []),
17327
17461
  ...(createdFence ? [createdFence.absurdTaskId] : []),
17462
+ ...(unclaimedFence
17463
+ ? [
17464
+ unclaimedFence.absurdTaskId,
17465
+ [...RUNTIME_SANDBOX_OPERATION_TERMINAL_STATES],
17466
+ ]
17467
+ : []),
17328
17468
  ],
17329
17469
  );
17330
17470
  if (cancelled.rows.length === 0 && outboxLeaseOwner) {
@@ -1,3 +1,9 @@
1
+ import { isIntegrationEventWaitToolId } from './event-wait-tools';
2
+ import {
3
+ isCustomerDbDatasetTool,
4
+ isQueryResultDatasetReadRequest,
5
+ } from './query-result-dataset';
6
+
1
7
  const ALWAYS_FRESH_INTEGRATION_TOOL_IDS = new Set([
2
8
  'google_workspace_request',
3
9
  'google_workspace_export_dataset',
@@ -33,24 +39,198 @@ export function isAlwaysFreshIntegrationWriteTool(toolId: string): boolean {
33
39
  );
34
40
  }
35
41
 
36
- /**
37
- * Whether a completed result may serve a later call. The Play runner, `tools
38
- * get` and Play admission all ask this one function, so an author is never told
39
- * yes where the runner says no. Only the provider-owned `reusableResult` opt-in
40
- * admits reuse.
41
- */
42
- export function toolReusableResultSupport(input: {
42
+ // The legacy gate's Workspace reason. Older-edition metadata keeps this text.
43
+ const WORKSPACE_REUSE_UNAVAILABLE_REASON =
44
+ 'Workspace edits and conflict checks must be observed on every invocation.';
45
+
46
+ type ToolReuseCapabilityInput = {
43
47
  toolId?: string;
44
48
  reusableResult?: { supported?: boolean };
45
49
  retry?: { idempotencyScope?: 'invocation'; requiresExecutionFence?: boolean };
46
50
  authoredTags?: string[];
47
51
  tags?: string[];
48
- }): { supported: boolean; unavailableReason: string | null } {
52
+ };
53
+
54
+ /** A durable call whose edition-11 `staleAfterSeconds` is being judged. */
55
+ export type ReusableWindowCall =
56
+ | {
57
+ kind: 'tool';
58
+ toolId: string;
59
+ /**
60
+ * The request input when it is known. Omitted means unknown: only the
61
+ * verdicts that follow from the tool id alone apply (`tools get`, or a
62
+ * Play whose input `plays check` cannot read).
63
+ */
64
+ input?: Record<string, unknown>;
65
+ /** The runner found an event-wait handler for this tool. */
66
+ eventWait?: boolean;
67
+ }
68
+ | {
69
+ kind: 'fetch';
70
+ /** The HTTP method, or null when `plays check` cannot read it. */
71
+ method: string | null;
72
+ }
73
+ | { kind: 'customer_db_query' };
74
+
75
+ export type ReusableWindowRefusal =
76
+ | 'event_wait'
77
+ | 'workspace'
78
+ | 'customer_db_mutation'
79
+ | 'live_dataset'
80
+ | 'fetch_mutating_method'
81
+ | 'customer_db_query';
82
+
83
+ export type ReusableWindowEligibility =
84
+ | { allowed: true }
85
+ | {
86
+ allowed: false;
87
+ refusal: ReusableWindowRefusal;
88
+ /** Why this call cannot reuse an earlier result. */
89
+ reason: string;
90
+ /** What to write instead. */
91
+ fix: string;
92
+ /** The one message `plays check`, the runner and `tools get` show. */
93
+ message: string;
94
+ };
95
+
96
+ const ZERO_WINDOW_FIX = 'Remove staleAfterSeconds or set it to 0.';
97
+
98
+ function refuse(
99
+ refusal: ReusableWindowRefusal,
100
+ subject: string,
101
+ reason: string,
102
+ oldThing = 'an old result',
103
+ fix = ZERO_WINDOW_FIX,
104
+ ): ReusableWindowEligibility {
105
+ return {
106
+ allowed: false,
107
+ refusal,
108
+ reason,
109
+ fix,
110
+ message: `${subject} ${reason}, so it cannot reuse ${oldThing}. ${fix}`,
111
+ };
112
+ }
113
+
114
+ const REUSABLE_FETCH_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
115
+
116
+ /**
117
+ * The one edition-11 rule for a positive or null `staleAfterSeconds`: may this
118
+ * call reuse a completed answer from another call or run, and if not, why and
119
+ * what to write instead. `plays check`, the runner's refusal and `tools get`
120
+ * all ask this function, so they cannot disagree. A window of 0 (or an omitted
121
+ * one) is always allowed; same-run recovery is separate and always applies.
122
+ *
123
+ * Every tool may carry a window, writes included: the window is the author's
124
+ * explicit acceptance of reuse. Refused are only calls whose result is not a
125
+ * reusable answer: event waits, Google Workspace operations, Customer DB SQL
126
+ * that changes data, live datasets, fetches with a method that can change
127
+ * remote state, and `customerDb.query`.
128
+ */
129
+ export function reusableWindowEligibility(
130
+ call: ReusableWindowCall,
131
+ ): ReusableWindowEligibility {
132
+ if (call.kind === 'customer_db_query') {
133
+ return refuse(
134
+ 'customer_db_query',
135
+ 'customerDb.query',
136
+ 'can change data even when its SQL looks like a read',
137
+ );
138
+ }
139
+ if (call.kind === 'fetch') {
140
+ const method = call.method?.trim().toUpperCase() ?? null;
141
+ if (method !== null && REUSABLE_FETCH_METHODS.has(method)) {
142
+ return { allowed: true };
143
+ }
144
+ return refuse(
145
+ 'fetch_mutating_method',
146
+ method === null
147
+ ? 'fetch with a method that is not a literal GET, HEAD or OPTIONS'
148
+ : `fetch with method ${method}`,
149
+ 'can change remote state',
150
+ 'an old response',
151
+ 'Remove staleAfterSeconds or set it to 0, and send a stable Idempotency-Key header.',
152
+ );
153
+ }
154
+ const toolId = call.toolId.trim();
155
+ if (call.eventWait === true || isIntegrationEventWaitToolId(toolId)) {
156
+ return refuse(
157
+ 'event_wait',
158
+ toolId,
159
+ 'waits for a new event each run',
160
+ 'an old one',
161
+ );
162
+ }
163
+ if (isAlwaysFreshIntegrationTool(toolId)) {
164
+ return refuse(
165
+ 'workspace',
166
+ toolId,
167
+ 'works on a live Google Workspace file whose edits and conflict checks must be seen each run',
168
+ );
169
+ }
170
+ if (!call.input) return { allowed: true };
171
+ if (
172
+ isCustomerDbDatasetTool(toolId) &&
173
+ !isQueryResultDatasetReadRequest(toolId, {
174
+ ...call.input,
175
+ result_mode: undefined,
176
+ })
177
+ ) {
178
+ return refuse(
179
+ 'customer_db_mutation',
180
+ toolId,
181
+ 'runs SQL that changes Customer DB data',
182
+ );
183
+ }
184
+ const scalarCustomerDbQuery =
185
+ isCustomerDbDatasetTool(toolId) && call.input.result_mode === 'rows';
186
+ if (
187
+ !scalarCustomerDbQuery &&
188
+ isQueryResultDatasetReadRequest(toolId, call.input)
189
+ ) {
190
+ return refuse(
191
+ 'live_dataset',
192
+ toolId,
193
+ 'returns a live dataset that is paged fresh each run',
194
+ );
195
+ }
196
+ return { allowed: true };
197
+ }
198
+
199
+ /**
200
+ * Whether an author may give this tool a positive or null `staleAfterSeconds`
201
+ * (edition 11 and later), as `tools get` reports it. It is
202
+ * `reusableWindowEligibility` without a request input, so verdicts that depend
203
+ * on the input (Customer DB mutations, live datasets) are left to `plays
204
+ * check` and the runner.
205
+ */
206
+ export function toolReusableResultSupport(input: ToolReuseCapabilityInput): {
207
+ supported: boolean;
208
+ unavailableReason: string | null;
209
+ } {
210
+ if (!input.toolId) return { supported: true, unavailableReason: null };
211
+ const verdict = reusableWindowEligibility({
212
+ kind: 'tool',
213
+ toolId: input.toolId,
214
+ });
215
+ return 'message' in verdict
216
+ ? { supported: false, unavailableReason: verdict.message }
217
+ : { supported: true, unavailableReason: null };
218
+ }
219
+
220
+ /**
221
+ * The pre-edition-11 shared-cache gate. Runtime tool metadata sends this to
222
+ * the Play runner, whose legacy latest-cache path reads and publishes a shared
223
+ * result for an older edition only when it says yes. Only the provider-owned
224
+ * `reusableResult` opt-in on a non-write action admits it, so older editions
225
+ * keep their omitted-value behavior. Do not use it for author guidance.
226
+ */
227
+ export function legacySharedCacheReuseSupport(
228
+ input: ToolReuseCapabilityInput,
229
+ ): { supported: boolean; unavailableReason: string | null } {
49
230
  if (input.toolId && isAlwaysFreshIntegrationTool(input.toolId))
50
231
  return {
51
232
  supported: false,
52
- unavailableReason:
53
- 'Workspace edits and conflict checks must be observed on every invocation.',
233
+ unavailableReason: WORKSPACE_REUSE_UNAVAILABLE_REASON,
54
234
  };
55
235
  const write =
56
236
  input.retry?.idempotencyScope === 'invocation' ||