deepline 0.3.537 → 0.3.539

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 (205) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +22 -5
  2. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  3. package/dist/bundling-sources/sdk/src/plays/client-core.ts +18 -1
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +33 -4
  6. package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +1 -1
  7. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +18 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +9 -1
  9. package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +392 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +717 -133
  11. package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +7 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +22 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +123 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +480 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +24 -16
  16. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +293 -53
  17. package/dist/bundling-sources/shared_libs/play-runtime/governor/block-reserving-budget-state-backend.ts +57 -2
  18. package/dist/bundling-sources/shared_libs/play-runtime/governor/budget-state-backend.ts +43 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +141 -9
  20. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +4 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +6 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/modal-supervisor-sidecar.ts +556 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +27 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +19 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +54 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +5 -0
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +155 -7
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/relay-connection-counter.ts +103 -0
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +75 -6
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +59 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +544 -73
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +8 -1
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +19 -1
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2399 -110
  35. package/dist/bundling-sources/shared_libs/play-runtime/runtime-flow.ts +42 -8
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-read-through.ts +287 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-finish.ts +606 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +274 -119
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +136 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-traffic-policy.ts +54 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/runtime-work-counters.ts +10 -1
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +22 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +18 -1
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +18 -4
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +219 -7
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +340 -0
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +1 -0
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +10 -1
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +623 -7
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +340 -5
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +61 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -1
  54. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +269 -2
  55. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +238 -5
  56. package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +47 -0
  57. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +5 -4
  58. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +6 -0
  59. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +11 -0
  60. package/dist/cli/auth-O5Y2VYXK.js +43 -0
  61. package/dist/cli/{auth-4SUPGDIM.mjs → auth-QD7QGD3B.mjs} +5 -5
  62. package/dist/cli/{billing-5JUA3ZM3.mjs → billing-FIZXMHBW.mjs} +31 -7
  63. package/dist/cli/{billing-SQU726P7.js → billing-KOQAF6WS.js} +114 -90
  64. package/dist/cli/{chunk-R7JYG6XO.mjs → chunk-2XMFT44N.mjs} +1 -1
  65. package/dist/cli/{chunk-XDS26J7Z.js → chunk-3YDI2PTN.js} +10 -10
  66. package/dist/cli/{chunk-KH27B2HJ.mjs → chunk-55ITVU2V.mjs} +2 -2
  67. package/dist/cli/{chunk-2Q7VXTMS.js → chunk-5QL4GJB2.js} +2 -2
  68. package/dist/cli/{chunk-D77W6Q67.js → chunk-5RUB53KG.js} +26 -26
  69. package/dist/cli/{chunk-JS2SBCWD.js → chunk-5YF35HAV.js} +6 -6
  70. package/dist/cli/{chunk-C37VELBR.mjs → chunk-6KG4KVTH.mjs} +5 -5
  71. package/dist/cli/{chunk-AX2OAXDL.mjs → chunk-6NZBLFL4.mjs} +1 -1
  72. package/dist/cli/{chunk-C3XD2WHM.mjs → chunk-6V3LNYK5.mjs} +2 -2
  73. package/dist/cli/{chunk-GPMS6OPX.mjs → chunk-ADV2IB2C.mjs} +5 -5
  74. package/dist/cli/{chunk-ZUAMXZXC.mjs → chunk-APKZGUTU.mjs} +4 -4
  75. package/dist/cli/{chunk-IQOIT6E3.js → chunk-CQJCLHBE.js} +41 -41
  76. package/dist/cli/{chunk-W3J3LT22.mjs → chunk-DZFVVP3S.mjs} +5 -5
  77. package/dist/cli/{chunk-V5IIBG2E.mjs → chunk-E4QHTDPF.mjs} +1 -1
  78. package/dist/cli/{chunk-CXTW7SRW.mjs → chunk-E7D37PLM.mjs} +8 -0
  79. package/dist/cli/{chunk-KULT6O5K.js → chunk-EAZS52DL.js} +15 -15
  80. package/dist/cli/{chunk-L3JVGNAT.mjs → chunk-F43MXIN3.mjs} +2 -2
  81. package/dist/cli/{chunk-WBTYWJLN.js → chunk-FH3P3E4S.js} +2 -2
  82. package/dist/cli/{chunk-K4WJ4BYO.mjs → chunk-FIRV7BXJ.mjs} +1 -1
  83. package/dist/cli/{chunk-NXGLJGPB.js → chunk-FSQCB5SJ.js} +2 -2
  84. package/dist/cli/{chunk-AVQET3NR.js → chunk-FTBWFDF3.js} +7 -7
  85. package/dist/cli/{chunk-QDBGPRR2.mjs → chunk-G3UFDUYU.mjs} +3 -1
  86. package/dist/cli/{chunk-ZHPSJ3LJ.mjs → chunk-GEO2EMM7.mjs} +29 -16
  87. package/dist/cli/{chunk-CGDW2CRR.mjs → chunk-GLEGINSP.mjs} +2 -2
  88. package/dist/cli/{chunk-EEFSUCYP.mjs → chunk-GLKUC5PO.mjs} +2 -2
  89. package/dist/cli/{chunk-BFHR7IC2.mjs → chunk-GNCIMHO2.mjs} +10 -10
  90. package/dist/cli/{chunk-PU42VOBI.js → chunk-ISXX5DUD.js} +3 -3
  91. package/dist/cli/{chunk-Y6AMMXWS.mjs → chunk-JBCQFG7G.mjs} +3 -3
  92. package/dist/cli/{chunk-Z2PPB3IO.mjs → chunk-JHEZQMOM.mjs} +1 -1
  93. package/dist/cli/{chunk-WBFOV5HT.js → chunk-K22EKW6L.js} +5 -5
  94. package/dist/cli/{chunk-CHIGEDAE.js → chunk-K5MZHTK7.js} +3 -3
  95. package/dist/cli/{chunk-L6QAIZNZ.js → chunk-KAEVL62Q.js} +44 -44
  96. package/dist/cli/{chunk-PJ4ZGZAN.js → chunk-KQTX545E.js} +13 -13
  97. package/dist/cli/{chunk-VP2K5B3R.mjs → chunk-LE5KN7CZ.mjs} +3 -3
  98. package/dist/cli/{chunk-BGXEMTIG.js → chunk-LEREPTAE.js} +19 -19
  99. package/dist/cli/{chunk-QPDLG7DQ.js → chunk-MI53W4DN.js} +53 -53
  100. package/dist/cli/{chunk-RMVZTBI5.mjs → chunk-MKESK3SW.mjs} +4 -4
  101. package/dist/cli/{chunk-NU7B5X6J.mjs → chunk-N3LPGGWD.mjs} +1 -1
  102. package/dist/cli/{chunk-VRYX2BR4.js → chunk-NR5PLMNG.js} +107 -107
  103. package/dist/cli/{chunk-JMHYDDBQ.js → chunk-Q4HNK7JX.js} +292 -279
  104. package/dist/cli/{chunk-37AZHCTP.mjs → chunk-RULRGMMM.mjs} +5 -5
  105. package/dist/cli/{chunk-GI3V4D7K.mjs → chunk-SDAP5MCO.mjs} +2 -2
  106. package/dist/cli/{chunk-5EOEJKSV.js → chunk-TZBCJHV6.js} +1 -1
  107. package/dist/cli/{chunk-3PMCQ3LK.js → chunk-V7DEGIYO.js} +7 -5
  108. package/dist/cli/{chunk-ALHKB3AE.js → chunk-VK5UTS5B.js} +9 -9
  109. package/dist/cli/{chunk-ZFSB7GXF.js → chunk-W32KT6LM.js} +5 -5
  110. package/dist/cli/{chunk-6BBGUQJJ.js → chunk-XTYHZEJ2.js} +8 -0
  111. package/dist/cli/{chunk-UGA5KI4A.js → chunk-XZBXQCRJ.js} +22 -22
  112. package/dist/cli/{chunk-BRRCWUOW.mjs → chunk-Y66ZMOJI.mjs} +1 -1
  113. package/dist/cli/{chunk-CFND2ACL.js → chunk-YMQFQO3K.js} +16 -16
  114. package/dist/cli/command-docs.js +2 -2
  115. package/dist/cli/command-docs.mjs +1 -1
  116. package/dist/cli/{csv-JITYN27L.js → csv-BWWJYV2C.js} +13 -13
  117. package/dist/cli/{csv-HZP6QMG7.mjs → csv-G5RQQ74W.mjs} +4 -4
  118. package/dist/cli/{db-FYSRB7O4.js → db-5KNDLADE.js} +27 -27
  119. package/dist/cli/{db-QRIRTOMM.mjs → db-AJZHWB3V.mjs} +6 -6
  120. package/dist/cli/describe-B6CN6CFJ.js +49 -0
  121. package/dist/cli/{describe-REXJVJC3.mjs → describe-QY5TKWVD.mjs} +17 -17
  122. package/dist/cli/describe-core.d.mts +3 -3
  123. package/dist/cli/describe-core.d.ts +3 -3
  124. package/dist/cli/{executions-BSTF4DDS.js → executions-BCCW76BI.js} +8 -8
  125. package/dist/cli/{executions-53KJAFOW.mjs → executions-SJPH3MZT.mjs} +6 -6
  126. package/dist/cli/{feedback-6MW3QOXX.js → feedback-GF65JKK6.js} +14 -14
  127. package/dist/cli/{feedback-CWUJJF3J.mjs → feedback-S6SZOFGK.mjs} +6 -6
  128. package/dist/cli/git-DX6NB7VF.js +25 -0
  129. package/dist/cli/{git-CKVZTJFS.mjs → git-F5FT5YVB.mjs} +5 -5
  130. package/dist/cli/index.js +143 -143
  131. package/dist/cli/index.mjs +42 -42
  132. package/dist/cli/{legacy-noops-QBL4PNGB.js → legacy-noops-ECR6FS6U.js} +9 -9
  133. package/dist/cli/{legacy-noops-USTBRFRX.mjs → legacy-noops-NOA4P5NE.mjs} +6 -6
  134. package/dist/cli/{monitors-6UCG5D7W.mjs → monitors-CTYSAGP4.mjs} +7 -7
  135. package/dist/cli/{monitors-VCR6SUZD.js → monitors-DEWBSURN.js} +100 -100
  136. package/dist/cli/{org-GSRBOJVO.mjs → org-EKSKKT7H.mjs} +6 -6
  137. package/dist/cli/{org-HPILTEG4.js → org-ZM2UUMZZ.js} +86 -86
  138. package/dist/cli/{play-TK7WOP5H.js → play-6JQOM6DE.js} +317 -317
  139. package/dist/cli/{play-QRTYQNG4.mjs → play-R2BH374J.mjs} +17 -17
  140. package/dist/cli/{providers-HEXNJ5QC.js → providers-CMIYHEMN.js} +9 -9
  141. package/dist/cli/{providers-OAQJWVBS.mjs → providers-X7WMIWO4.mjs} +6 -6
  142. package/dist/cli/{quickstart-PYZTFXZX.js → quickstart-6HVPAMSW.js} +6 -6
  143. package/dist/cli/{quickstart-FFVHTPSP.mjs → quickstart-ZZ7L6VZJ.mjs} +4 -4
  144. package/dist/cli/{run-HLN6YYZH.mjs → run-FP32RKBU.mjs} +22 -22
  145. package/dist/cli/{run-4DWJXJRO.js → run-OOHYH3GI.js} +42 -42
  146. package/dist/cli/search-34C6LFOJ.js +32 -0
  147. package/dist/cli/{search-ZHRCXGEL.mjs → search-BDDNC23Z.mjs} +7 -7
  148. package/dist/cli/{search-output-2KY6PFDH.js → search-output-5VZIQQAM.js} +6 -6
  149. package/dist/cli/{search-output-N7QXACVK.mjs → search-output-QXJ6CV5G.mjs} +4 -4
  150. package/dist/cli/{secrets-WXQ7XO5C.js → secrets-EN2HQCO3.js} +15 -15
  151. package/dist/cli/{secrets-FKMWBLHU.mjs → secrets-Z7CQSQGC.mjs} +6 -6
  152. package/dist/cli/{sessions-3YDTEDA5.mjs → sessions-I2H37OTJ.mjs} +6 -6
  153. package/dist/cli/sessions-RYQX3NDD.js +22 -0
  154. package/dist/cli/{settings-67TWLQ6E.js → settings-CTRAPFNZ.js} +85 -85
  155. package/dist/cli/{settings-JTPASUZN.mjs → settings-IYSC5PPQ.mjs} +12 -12
  156. package/dist/cli/{setup-VYNGXUJ6.mjs → setup-PU3HOVI3.mjs} +9 -9
  157. package/dist/cli/{setup-KUERQJUX.js → setup-XIN53GEW.js} +49 -49
  158. package/dist/cli/skills-576CX7DK.js +36 -0
  159. package/dist/cli/{skills-KI4KYHH6.mjs → skills-TYBML2ZO.mjs} +7 -7
  160. package/dist/cli/tools-EXMUWA3Z.js +56 -0
  161. package/dist/cli/{tools-UQDJS2RS.mjs → tools-ZVNE6M6J.mjs} +16 -16
  162. package/dist/cli/{update-7FQQUBOD.mjs → update-54WENBNT.mjs} +9 -9
  163. package/dist/cli/update-RAHETNL2.js +34 -0
  164. package/dist/cli/{views-MJK7JGZG.js → views-7L75EZOJ.js} +21 -21
  165. package/dist/cli/{views-JAM4MNNV.mjs → views-EUBB4ONT.mjs} +6 -6
  166. package/dist/cli/{workflow-AQPRIWQX.js → workflow-EZVYCR6Y.js} +17 -17
  167. package/dist/cli/{workflow-TQRV5FGO.mjs → workflow-GUKGFJ72.mjs} +7 -7
  168. package/dist/{client-BlLYQDNo.d.mts → client-D0uDBybG.d.mts} +1 -1
  169. package/dist/{client-DSQlkIDO.d.ts → client-DZTnAv4B.d.ts} +1 -1
  170. package/dist/{client-core-rX7n2H8U.d.mts → client-core-BhWf8Y1b.d.mts} +15 -2
  171. package/dist/{client-core-CDwapXy5.d.ts → client-core-og3AP1LL.d.ts} +15 -2
  172. package/dist/{compiler-manifest-BHNC4RL-.d.ts → compiler-manifest-Bes3OVA3.d.mts} +1 -1
  173. package/dist/{compiler-manifest-BHNC4RL-.d.mts → compiler-manifest-Bes3OVA3.d.ts} +1 -1
  174. package/dist/{errors-lhtIWG5Z.d.ts → errors-BJm4lLWc.d.ts} +1 -1
  175. package/dist/{errors-D7sPXrvB.d.mts → errors-Dc5r42ks.d.mts} +1 -1
  176. package/dist/{index-CQTBHXHr.d.ts → index-BfV7mRPF.d.ts} +1 -1
  177. package/dist/{index-NaDZq2xf.d.mts → index-DTkiz_Ur.d.mts} +1 -1
  178. package/dist/index.d.mts +7 -7
  179. package/dist/index.d.ts +7 -7
  180. package/dist/index.js +9 -9
  181. package/dist/index.mjs +6 -6
  182. package/dist/install-integrity.json +121 -112
  183. package/dist/plays/bundle-play-file.d.mts +3 -3
  184. package/dist/plays/bundle-play-file.d.ts +3 -3
  185. package/dist/plays/play-description.d.mts +2 -2
  186. package/dist/plays/play-description.d.ts +2 -2
  187. package/dist/plays/run-request.d.mts +2 -2
  188. package/dist/plays/run-request.d.ts +2 -2
  189. package/dist/release.d.mts +1 -1
  190. package/dist/release.d.ts +1 -1
  191. package/dist/release.js +2 -2
  192. package/dist/release.mjs +1 -1
  193. package/dist/server.d.mts +4 -4
  194. package/dist/server.d.ts +4 -4
  195. package/dist/server.js +5 -5
  196. package/dist/server.mjs +3 -3
  197. package/package.json +1 -1
  198. package/dist/cli/auth-Y2K2ZYYA.js +0 -43
  199. package/dist/cli/describe-LSOHOLFI.js +0 -49
  200. package/dist/cli/git-S7SWUZ3T.js +0 -25
  201. package/dist/cli/search-WERQBC6V.js +0 -32
  202. package/dist/cli/sessions-LXQ4Q6BS.js +0 -22
  203. package/dist/cli/skills-EFRLHY3F.js +0 -36
  204. package/dist/cli/tools-C3EIGFFP.js +0 -56
  205. package/dist/cli/update-KCY72RXH.js +0 -34
@@ -3009,12 +3009,278 @@ export async function ensurePostgresSchedulerLaunchAdmissionFunctions(
3009
3009
  `);
3010
3010
  }
3011
3011
 
3012
+ /**
3013
+ * Preview-only maintenance rehearsal. Fixture lifecycle writes stay with their
3014
+ * scheduler owner. A fresh schema isolates synthetic historical Production
3015
+ * metadata from every worker queue and from real provider identities.
3016
+ */
3017
+ export async function verifyLegacySandboxCapacityPreview(
3018
+ client: PostgresSchedulerQueryClient,
3019
+ input: { previewSchema: string; orgId: string },
3020
+ ): Promise<{
3021
+ dryRunUnchanged: true;
3022
+ ownershipRefusals: number;
3023
+ releasedTerminalLeases: number;
3024
+ retainedOperations: number;
3025
+ measuredProviderReads: number;
3026
+ fixtureRemoved: true;
3027
+ }> {
3028
+ if (
3029
+ !/^runtime_scheduler_preview_[a-z0-9_]+$/.test(input.previewSchema) ||
3030
+ !input.orgId.trim()
3031
+ ) {
3032
+ throw new Error(
3033
+ 'Legacy capacity rehearsal requires an isolated Preview schema and authenticated organization.',
3034
+ );
3035
+ }
3036
+ const schema = `runtime_scheduler_preview_lease_${randomUUID().replaceAll('-', '').slice(0, 24)}`;
3037
+ const options = { schema };
3038
+ const table = (name: string) => tableName(name, options);
3039
+ const {
3040
+ advanceRuntimeSandboxOperationBackfill,
3041
+ reconcileRuntimeDaytonaSandboxLedger,
3042
+ } = await import('./runtime-sandbox-ledger-reconciliation');
3043
+ const check = (condition: unknown, message: string): void => {
3044
+ if (!condition)
3045
+ throw new Error(`Legacy capacity Preview assertion: ${message}`);
3046
+ };
3047
+ const snapshot = async () =>
3048
+ JSON.stringify(
3049
+ await Promise.all(
3050
+ [
3051
+ 'runtime_sandbox_capacity_leases',
3052
+ 'runtime_sandbox_operations',
3053
+ 'sandbox_cleanup_jobs_v2',
3054
+ 'sandbox_cleanup_events_v2',
3055
+ 'control',
3056
+ ].map(
3057
+ async (name) =>
3058
+ (
3059
+ await client.query(
3060
+ `SELECT to_jsonb(row) AS value FROM ${table(name)} AS row ORDER BY to_jsonb(row)::text`,
3061
+ )
3062
+ ).rows,
3063
+ ),
3064
+ ),
3065
+ );
3066
+ let measuredProviderReads = 0;
3067
+ let releasedTerminalLeases = 0;
3068
+ let ownershipRefusals = 0;
3069
+ try {
3070
+ await ensurePostgresSchedulerSchema(client, options, true);
3071
+ await client.query(
3072
+ `INSERT INTO ${table('runs')} (
3073
+ run_id, org_id, play_name, graph_hash, runtime_profile, artifact_storage_key, launch_json, status
3074
+ ) VALUES ('legacy-preview-run', $1, 'legacy-preview', 'synthetic', 'absurd', 'synthetic', '{}', 'completed')`,
3075
+ [input.orgId],
3076
+ );
3077
+ await client.query(
3078
+ `INSERT INTO ${table('attempts')} (run_id, attempt, status, resource_json, updated_at)
3079
+ VALUES ('legacy-preview-run', 1, 'completed', $1::jsonb, clock_timestamp() - interval '2 days')`,
3080
+ [
3081
+ JSON.stringify([
3082
+ {
3083
+ kind: 'daytona_sandbox',
3084
+ sandboxId: 'synthetic-legacy-preview-sandbox',
3085
+ daytonaOrganizationId: 'synthetic-preview-provider-domain',
3086
+ runtimeEnvironment: 'production',
3087
+ },
3088
+ ]),
3089
+ ],
3090
+ );
3091
+ // Build retained deleted-operation/cleanup evidence through the real owners.
3092
+ await advanceRuntimeSandboxOperationBackfill(
3093
+ client,
3094
+ { dryRun: false },
3095
+ options,
3096
+ );
3097
+ await reconcileRuntimeDaytonaSandboxLedger(
3098
+ client,
3099
+ {
3100
+ providerSandboxes: [],
3101
+ inventoryCapturedAtMs: Date.now(),
3102
+ minimumAgeMs: 0,
3103
+ dryRun: false,
3104
+ readExactSandbox: async ({ sandboxId, routingDomain }) => {
3105
+ check(
3106
+ sandboxId === 'synthetic-legacy-preview-sandbox' &&
3107
+ routingDomain === 'synthetic-preview-provider-domain',
3108
+ 'synthetic fixture identity',
3109
+ );
3110
+ return 'absent';
3111
+ },
3112
+ },
3113
+ options,
3114
+ );
3115
+ await client.query(
3116
+ `INSERT INTO ${table('runtime_sandbox_capacity_leases')} (
3117
+ lease_id, org_id, run_id, provider, sandbox_id, created_at, expires_at
3118
+ ) VALUES ('legacy-preview-lease', $1, 'legacy-preview-run', 'daytona', 'synthetic-legacy-preview-sandbox', clock_timestamp() - interval '2 days', clock_timestamp() - interval '1 day')`,
3119
+ [input.orgId],
3120
+ );
3121
+ // Wrong retained owner must refuse in both modes without changing any row.
3122
+ await client.query(
3123
+ `UPDATE ${table('runtime_sandbox_capacity_leases')} SET org_id = $1 WHERE lease_id = 'legacy-preview-lease'`,
3124
+ [`${input.orgId}-foreign`],
3125
+ );
3126
+ const refusedBefore = await snapshot();
3127
+ for (const dryRun of [true, false]) {
3128
+ try {
3129
+ await advanceRuntimeSandboxOperationBackfill(
3130
+ client,
3131
+ { dryRun },
3132
+ options,
3133
+ );
3134
+ } catch (error) {
3135
+ if (
3136
+ !(error instanceof Error) ||
3137
+ !error.message.includes('Cannot prove provider ownership')
3138
+ )
3139
+ throw error;
3140
+ ownershipRefusals++;
3141
+ }
3142
+ check(
3143
+ (await snapshot()) === refusedBefore,
3144
+ 'ownership refusal changed retained rows',
3145
+ );
3146
+ }
3147
+ check(ownershipRefusals === 2, 'both modes must refuse foreign ownership');
3148
+ await client.query(
3149
+ `UPDATE ${table('runtime_sandbox_capacity_leases')} SET org_id = $1 WHERE lease_id = 'legacy-preview-lease'`,
3150
+ [input.orgId],
3151
+ );
3152
+ await client.query(
3153
+ `UPDATE ${table('runtime_sandbox_operations')} SET org_id = $1`,
3154
+ [`${input.orgId}-foreign`],
3155
+ );
3156
+ const conflictingOperationBefore = await snapshot();
3157
+ for (const dryRun of [true, false]) {
3158
+ try {
3159
+ await advanceRuntimeSandboxOperationBackfill(
3160
+ client,
3161
+ { dryRun },
3162
+ options,
3163
+ );
3164
+ } catch (error) {
3165
+ if (
3166
+ !(error instanceof Error) ||
3167
+ !error.message.includes(
3168
+ 'Existing sandbox operation ownership conflicts',
3169
+ )
3170
+ )
3171
+ throw error;
3172
+ ownershipRefusals++;
3173
+ }
3174
+ check(
3175
+ (await snapshot()) === conflictingOperationBefore,
3176
+ 'existing-operation refusal changed retained rows',
3177
+ );
3178
+ }
3179
+ check(
3180
+ ownershipRefusals === 4,
3181
+ 'both modes must refuse conflicting existing operation ownership',
3182
+ );
3183
+ await client.query(
3184
+ `UPDATE ${table('runtime_sandbox_operations')} SET org_id = $1`,
3185
+ [input.orgId],
3186
+ );
3187
+ const before = await snapshot();
3188
+ const dry = await advanceRuntimeSandboxOperationBackfill(
3189
+ client,
3190
+ { dryRun: true },
3191
+ options,
3192
+ );
3193
+ check(
3194
+ dry.targets.length === 1 && dry.targets[0]?.wouldInsert === false,
3195
+ 'dry-run must select retained operation',
3196
+ );
3197
+ const noProviderRead = async (): Promise<'unknown'> => {
3198
+ measuredProviderReads++;
3199
+ throw new Error('Retained deletion proof must not call a provider.');
3200
+ };
3201
+ const reconciliation = {
3202
+ providerSandboxes: [],
3203
+ inventoryCapturedAtMs: Date.now(),
3204
+ readExactSandbox: noProviderRead,
3205
+ };
3206
+ await reconcileRuntimeDaytonaSandboxLedger(
3207
+ client,
3208
+ { ...reconciliation, dryRun: true },
3209
+ options,
3210
+ );
3211
+ check((await snapshot()) === before, 'dry-run wrote retained state');
3212
+ const applied = await advanceRuntimeSandboxOperationBackfill(
3213
+ client,
3214
+ { dryRun: false },
3215
+ options,
3216
+ );
3217
+ check(
3218
+ 'legacyCapacityLeasesRepaired' in applied &&
3219
+ applied.legacyCapacityLeasesRepaired === 1,
3220
+ 'historical lease was not rebound',
3221
+ );
3222
+ const result = await reconcileRuntimeDaytonaSandboxLedger(
3223
+ client,
3224
+ { ...reconciliation, dryRun: false },
3225
+ options,
3226
+ );
3227
+ releasedTerminalLeases = result.releasedTerminalLeases;
3228
+ check(releasedTerminalLeases === 1, 'terminal lease was not released');
3229
+ const lease = (
3230
+ await client.query(
3231
+ `SELECT routing_domain, released_at FROM ${table('runtime_sandbox_capacity_leases')} WHERE lease_id = 'legacy-preview-lease'`,
3232
+ )
3233
+ ).rows[0];
3234
+ check(
3235
+ lease?.routing_domain === 'synthetic-preview-provider-domain' &&
3236
+ lease?.released_at !== null,
3237
+ 'released lease lost its domain proof',
3238
+ );
3239
+ const operations = (
3240
+ await client.query(
3241
+ `SELECT state FROM ${table('runtime_sandbox_operations')}`,
3242
+ )
3243
+ ).rows;
3244
+ check(
3245
+ operations.length === 1 && operations[0]?.state === 'deleted',
3246
+ 'duplicated or revived retained operation',
3247
+ );
3248
+ const replay = await reconcileRuntimeDaytonaSandboxLedger(
3249
+ client,
3250
+ { ...reconciliation, dryRun: false },
3251
+ options,
3252
+ );
3253
+ check(
3254
+ replay.releasedTerminalLeases === 0 && measuredProviderReads === 0,
3255
+ 'reconciliation did not converge',
3256
+ );
3257
+ } finally {
3258
+ await client.query('ROLLBACK');
3259
+ }
3260
+ check(
3261
+ (await client.query('SELECT to_regnamespace($1) AS fixture', [schema]))
3262
+ .rows[0]?.fixture === null,
3263
+ 'fixture cleanup not proved',
3264
+ );
3265
+ return {
3266
+ dryRunUnchanged: true,
3267
+ ownershipRefusals,
3268
+ releasedTerminalLeases,
3269
+ retainedOperations: 1,
3270
+ measuredProviderReads,
3271
+ fixtureRemoved: true,
3272
+ };
3273
+ }
3274
+
3012
3275
  export async function ensurePostgresSchedulerSchema(
3013
3276
  client: PostgresSchedulerQueryClient,
3014
3277
  options?: Pick<PostgresSchedulerOptions, 'schema'> & {
3015
3278
  deferOpenRecoveryIndex?: boolean;
3016
3279
  deferRuntimeAdminIndexes?: boolean;
3017
3280
  },
3281
+ // Internal synthetic fixture bootstrap only; ordinary deployment callers
3282
+ // retain the existing self-owned migration transaction when absent.
3283
+ freshPreviewTransaction = false,
3018
3284
  ): Promise<void> {
3019
3285
  const schema = schemaName(options);
3020
3286
  const quotedSchema = quoteIdent(schema);
@@ -3023,15 +3289,28 @@ export async function ensurePostgresSchedulerSchema(
3023
3289
  // PostgreSQL does not permit a newly added enum label to be consumed by a
3024
3290
  // constraint in the same transaction. Upgrade the pre-v29 enum first; the
3025
3291
  // following transactional bootstrap can then safely install its check.
3292
+ if (freshPreviewTransaction) {
3293
+ if (
3294
+ !/^runtime_scheduler_preview_lease_[a-f0-9]{24}$/.test(schema) ||
3295
+ (await client.query('SELECT to_regnamespace($1) AS fixture', [schema]))
3296
+ .rows[0]?.fixture !== null
3297
+ )
3298
+ throw new Error(
3299
+ 'Atomic Preview bootstrap requires a fresh disposable fixture schema.',
3300
+ );
3301
+ await client.query('BEGIN');
3302
+ }
3026
3303
  try {
3027
- await client.query(`CREATE SCHEMA IF NOT EXISTS ${quotedSchema}`);
3028
- await client.query(`
3304
+ if (!freshPreviewTransaction) {
3305
+ await client.query(`CREATE SCHEMA IF NOT EXISTS ${quotedSchema}`);
3306
+ await client.query(`
3029
3307
  DO $$ BEGIN
3030
3308
  ALTER TYPE ${quotedSchema}."runtime_sandbox_operation_state"
3031
3309
  ADD VALUE IF NOT EXISTS 'abandoned';
3032
3310
  EXCEPTION WHEN undefined_object THEN NULL;
3033
3311
  END $$
3034
3312
  `);
3313
+ }
3035
3314
  } catch (error) {
3036
3315
  // These statements deliberately run before BEGIN: PostgreSQL cannot use a
3037
3316
  // newly-added enum value in this bootstrap transaction. Keep the public
@@ -3049,7 +3328,7 @@ export async function ensurePostgresSchedulerSchema(
3049
3328
  }
3050
3329
  throw error;
3051
3330
  }
3052
- await client.query('BEGIN');
3331
+ if (!freshPreviewTransaction) await client.query('BEGIN');
3053
3332
  let committed = false;
3054
3333
  try {
3055
3334
  await client.query(
@@ -3179,7 +3458,7 @@ export async function ensurePostgresSchedulerSchema(
3179
3458
  [POSTGRES_SCHEDULER_SCHEMA_VERSION],
3180
3459
  );
3181
3460
  }
3182
- await client.query('COMMIT');
3461
+ if (!freshPreviewTransaction) await client.query('COMMIT');
3183
3462
  committed = true;
3184
3463
  return;
3185
3464
  }
@@ -4594,7 +4873,7 @@ export async function ensurePostgresSchedulerSchema(
4594
4873
  [POSTGRES_SCHEDULER_TERMINAL_COMPUTE_BILLING_BACKFILL_CONTROL_KEY],
4595
4874
  );
4596
4875
  }
4597
- await client.query('COMMIT');
4876
+ if (!freshPreviewTransaction) await client.query('COMMIT');
4598
4877
  committed = true;
4599
4878
  } catch (error) {
4600
4879
  if (!committed) {
@@ -10586,6 +10865,7 @@ export async function deferPostgresSchedulerAttemptForRecovery(
10586
10865
  logicalCalls: 0,
10587
10866
  providerRequests: 0,
10588
10867
  provider429s: 0,
10868
+ reusableResultCalls: 0,
10589
10869
  final: true,
10590
10870
  };
10591
10871
  const noCodeWorkCounterEventId = `run-pre-code-work-counters:${input.runId}:${input.attempt}`;
@@ -12824,6 +13104,9 @@ function terminalWorkCounterProgressEventsFromRunnerResult(
12824
13104
  logicalCalls: counters.logicalCalls,
12825
13105
  providerRequests: counters.providerRequests,
12826
13106
  provider429s: counters.provider429s,
13107
+ ...(counters.reusableResultCalls !== undefined
13108
+ ? { reusableResultCalls: counters.reusableResultCalls }
13109
+ : {}),
12827
13110
  final: true,
12828
13111
  },
12829
13112
  ];
@@ -16493,6 +16776,55 @@ export async function registerPostgresSchedulerArrayInputIntent(
16493
16776
  * channel. Returns null when the run is missing or this attempt is no longer
16494
16777
  * current while the run remains active.
16495
16778
  */
16779
+ /**
16780
+ * Read-only twin of the heartbeat fence: the run status as seen by this exact,
16781
+ * still-current attempt (same predicates, one statement, no write), or the
16782
+ * run's terminal status, or null. It never reports a replacement attempt's
16783
+ * active state. Used only to re-check a heartbeat that already renewed the
16784
+ * attempt (park-ack long-poll); it never renews liveness itself.
16785
+ */
16786
+ export async function readPostgresSchedulerDetachedRunnerFencedStatus(
16787
+ client: PostgresSchedulerQueryClient,
16788
+ input: { runId: string; attempt: number },
16789
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
16790
+ ): Promise<
16791
+ 'queued' | 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | null
16792
+ > {
16793
+ const result = await client.query<{
16794
+ status:
16795
+ | 'queued'
16796
+ | 'running'
16797
+ | 'waiting'
16798
+ | 'completed'
16799
+ | 'failed'
16800
+ | 'cancelled';
16801
+ }>(
16802
+ `
16803
+ SELECT run.status
16804
+ FROM ${tableName('attempts', options)} AS target
16805
+ JOIN ${tableName('runs', options)} AS run ON run.run_id = target.run_id
16806
+ WHERE target.run_id = $1
16807
+ AND target.attempt = $2
16808
+ AND target.status IN ('claimed', 'running', 'waiting')
16809
+ AND run.status IN ('queued', 'running', 'waiting')
16810
+ AND NOT EXISTS (
16811
+ SELECT 1
16812
+ FROM ${tableName('attempts', options)} AS newer
16813
+ WHERE newer.run_id = target.run_id
16814
+ AND newer.attempt > target.attempt
16815
+ )
16816
+ UNION ALL
16817
+ SELECT status
16818
+ FROM ${tableName('runs', options)}
16819
+ WHERE run_id = $1
16820
+ AND status IN ('completed', 'failed', 'cancelled')
16821
+ LIMIT 1
16822
+ `,
16823
+ [input.runId, input.attempt],
16824
+ );
16825
+ return result.rows[0]?.status ?? null;
16826
+ }
16827
+
16496
16828
  export async function heartbeatPostgresSchedulerDetachedRunner(
16497
16829
  client: PostgresSchedulerQueryClient,
16498
16830
  input: { runId: string; attempt: number },
@@ -18943,6 +19275,9 @@ export function buildPostgresSchedulerRunnerContext(
18943
19275
  receiptGatewayBaseUrl,
18944
19276
  vercelProtectionBypassToken,
18945
19277
  runtimeTestFaultHeader: launch.runtimeTestFaultHeader ?? null,
19278
+ ...(launch.experimentSwitchOverrides
19279
+ ? { experimentSwitchOverrides: launch.experimentSwitchOverrides }
19280
+ : {}),
18946
19281
  preferredReceiptGatewayMachineId:
18947
19282
  launch.preferredReceiptGatewayMachineId ?? null,
18948
19283
  orgId: launch.orgId,
@@ -1,9 +1,70 @@
1
1
  import type { PostgresSchedulerQueryClient } from './postgres';
2
2
  import {
3
3
  heartbeatPostgresSchedulerDetachedRunner,
4
+ readPostgresSchedulerDetachedRunnerFencedStatus,
4
5
  readPostgresSchedulerRunnerLiveness,
5
6
  } from './postgres';
6
7
 
8
+ /** Upper bound for a park-ack long-poll the gateway will honor. */
9
+ export const RUNNER_PARK_ACK_LONG_POLL_MAX_MS = 1_000;
10
+ export const RUNNER_PARK_ACK_LONG_POLL_INTERVAL_MS = 15;
11
+
12
+ /** The requested long-poll bound, or 0 when the request did not ask (or asked invalidly). */
13
+ export function runnerParkAckLongPollMs(value: unknown): number {
14
+ return typeof value === 'number' && Number.isFinite(value) && value > 0
15
+ ? Math.min(Math.floor(value), RUNNER_PARK_ACK_LONG_POLL_MAX_MS)
16
+ : 0;
17
+ }
18
+
19
+ /**
20
+ * Park-ack long-poll. After a heartbeat that renewed the attempt answered a
21
+ * not-yet-parked status, re-check with the read-only attempt fence until the
22
+ * scheduler reports `waiting` or a terminal, or the bound passes; then answer
23
+ * with the latest fenced outcome. Never renews liveness and never reports a
24
+ * replacement attempt's state. A missing row keeps the renewed outcome.
25
+ */
26
+ export async function awaitRunnerSchedulerWaiting(input: {
27
+ initial: RunnerHeartbeatOutcome;
28
+ maxWaitMs: number;
29
+ readStatus: () => Promise<
30
+ 'queued' | 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | null
31
+ >;
32
+ sleep?: (ms: number) => Promise<void>;
33
+ now?: () => number;
34
+ signal?: AbortSignal;
35
+ }): Promise<RunnerHeartbeatOutcome> {
36
+ if (
37
+ input.maxWaitMs <= 0 ||
38
+ !input.initial.ok ||
39
+ input.initial.schedulerStatus === 'waiting'
40
+ )
41
+ return input.initial;
42
+ const now = input.now ?? Date.now;
43
+ const sleep =
44
+ input.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
45
+ const deadline = now() + input.maxWaitMs;
46
+ let latest: RunnerHeartbeatOutcome = input.initial;
47
+ while (now() < deadline && !input.signal?.aborted) {
48
+ await sleep(RUNNER_PARK_ACK_LONG_POLL_INTERVAL_MS);
49
+ const status = await input.readStatus();
50
+ if (status === null) return latest;
51
+ if (status === 'cancelled' || status === 'failed' || status === 'completed')
52
+ return { ok: false, terminal: status };
53
+ latest = { ok: true, schedulerStatus: status };
54
+ if (status === 'waiting') return latest;
55
+ }
56
+ return latest;
57
+ }
58
+
59
+ /** Read-only fenced status for one attempt (see awaitRunnerSchedulerWaiting). */
60
+ export async function readRunnerFencedStatus(
61
+ client: PostgresSchedulerQueryClient,
62
+ input: { runId: string; attempt: number },
63
+ options?: { schema?: string },
64
+ ) {
65
+ return readPostgresSchedulerDetachedRunnerFencedStatus(client, input, options);
66
+ }
67
+
7
68
  /**
8
69
  * Detached-runner heartbeat control for the receipt gateway.
9
70
  *
@@ -91,7 +91,7 @@ const RUNTIME_EVENT_LOG_POSITION_EXPRESSION = `jsonb_set(
91
91
  // Migration readiness tracks this projection body independently of scheduler
92
92
  // wire and schema versions. Bump when a changed trigger must be reinstalled.
93
93
  export const RUNTIME_EVENT_SEARCH_OUTBOX_PROJECTION_MARKER =
94
- 'runtime-event-search-epoch-resume-lifecycle';
94
+ 'runtime-event-search-epoch-resume-lifecycle-reuse';
95
95
  /** Trusted trigger-authored state; absent on already-projected legacy rows. */
96
96
  export const RUNTIME_EVENT_DEFERRED_PROJECTION_FIELD =
97
97
  '_runtimeSearchProjectionPending';
@@ -3570,6 +3570,7 @@ export async function attachRuntimeEventSearchTriggers(
3570
3570
  'attempt', value->'attempt', 'invocationSeq', value->'invocationSeq',
3571
3571
  'segmentId', value->'segmentId', 'logicalCalls', value->'logicalCalls',
3572
3572
  'providerRequests', value->'providerRequests', 'provider429s', value->'provider429s',
3573
+ 'reusableResultCalls', value->'reusableResultCalls',
3573
3574
  'final', value->'final')
3574
3575
  ELSE '{}'::jsonb
3575
3576
  END)