deepline 0.3.537 → 0.3.538

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 (204) 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 +1 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +330 -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 +2 -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 -3
  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 +2390 -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-traffic-policy.ts +54 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-work-counters.ts +10 -1
  41. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +15 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +18 -1
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +18 -4
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +219 -7
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +340 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +1 -0
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +10 -1
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +623 -7
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +340 -5
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +61 -0
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -1
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +269 -2
  54. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +238 -5
  55. package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +47 -0
  56. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +5 -4
  57. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +6 -0
  58. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +11 -0
  59. package/dist/cli/auth-4WEVLYK4.js +43 -0
  60. package/dist/cli/{auth-4SUPGDIM.mjs → auth-KYH7N7RQ.mjs} +5 -5
  61. package/dist/cli/{billing-SQU726P7.js → billing-4KTUVZ4S.js} +114 -90
  62. package/dist/cli/{billing-5JUA3ZM3.mjs → billing-WK346KAI.mjs} +31 -7
  63. package/dist/cli/{chunk-KULT6O5K.js → chunk-25RGHJQL.js} +15 -15
  64. package/dist/cli/{chunk-PJ4ZGZAN.js → chunk-34PLG5OE.js} +13 -13
  65. package/dist/cli/{chunk-37AZHCTP.mjs → chunk-35OCRH5C.mjs} +5 -5
  66. package/dist/cli/{chunk-JMHYDDBQ.js → chunk-3I5TU5XE.js} +292 -279
  67. package/dist/cli/{chunk-Y6AMMXWS.mjs → chunk-4KZF6OYY.mjs} +3 -3
  68. package/dist/cli/{chunk-BRRCWUOW.mjs → chunk-4NEOGPKD.mjs} +1 -1
  69. package/dist/cli/{chunk-NU7B5X6J.mjs → chunk-4WQR4DG4.mjs} +1 -1
  70. package/dist/cli/{chunk-AVQET3NR.js → chunk-5VSPRRTI.js} +7 -7
  71. package/dist/cli/{chunk-EEFSUCYP.mjs → chunk-6JG3MRTM.mjs} +2 -2
  72. package/dist/cli/{chunk-D77W6Q67.js → chunk-6SLQLWWL.js} +26 -26
  73. package/dist/cli/{chunk-ZUAMXZXC.mjs → chunk-7XDJKIM2.mjs} +4 -4
  74. package/dist/cli/{chunk-C37VELBR.mjs → chunk-A6E7TCK2.mjs} +5 -5
  75. package/dist/cli/{chunk-JS2SBCWD.js → chunk-ADLDU2QG.js} +6 -6
  76. package/dist/cli/{chunk-VP2K5B3R.mjs → chunk-ALARRSMZ.mjs} +3 -3
  77. package/dist/cli/{chunk-CHIGEDAE.js → chunk-B2BTBHX2.js} +3 -3
  78. package/dist/cli/{chunk-CFND2ACL.js → chunk-BBS2BLPV.js} +16 -16
  79. package/dist/cli/{chunk-QDBGPRR2.mjs → chunk-CLO562KG.mjs} +3 -1
  80. package/dist/cli/{chunk-CXTW7SRW.mjs → chunk-E7D37PLM.mjs} +8 -0
  81. package/dist/cli/{chunk-UGA5KI4A.js → chunk-ESX3H7Q7.js} +22 -22
  82. package/dist/cli/{chunk-BFHR7IC2.mjs → chunk-FJ5KPGCS.mjs} +10 -10
  83. package/dist/cli/{chunk-R7JYG6XO.mjs → chunk-FWE37N2P.mjs} +1 -1
  84. package/dist/cli/{chunk-K4WJ4BYO.mjs → chunk-ICTA5ICE.mjs} +1 -1
  85. package/dist/cli/{chunk-PU42VOBI.js → chunk-IMLFB66A.js} +3 -3
  86. package/dist/cli/{chunk-GI3V4D7K.mjs → chunk-IP3XJTWA.mjs} +2 -2
  87. package/dist/cli/{chunk-WBFOV5HT.js → chunk-JCLRSMUP.js} +5 -5
  88. package/dist/cli/{chunk-L3JVGNAT.mjs → chunk-JPEBKN3K.mjs} +2 -2
  89. package/dist/cli/{chunk-Z2PPB3IO.mjs → chunk-JTOV5RUA.mjs} +1 -1
  90. package/dist/cli/{chunk-WBTYWJLN.js → chunk-KCUQNH4K.js} +2 -2
  91. package/dist/cli/{chunk-C3XD2WHM.mjs → chunk-KNIYEZVV.mjs} +2 -2
  92. package/dist/cli/{chunk-3PMCQ3LK.js → chunk-LPTBHNGB.js} +7 -5
  93. package/dist/cli/{chunk-KH27B2HJ.mjs → chunk-M3NCXGNN.mjs} +2 -2
  94. package/dist/cli/{chunk-XDS26J7Z.js → chunk-MNBIGX6O.js} +10 -10
  95. package/dist/cli/{chunk-L6QAIZNZ.js → chunk-MYSPQUAO.js} +44 -44
  96. package/dist/cli/{chunk-W3J3LT22.mjs → chunk-N2BCPZVR.mjs} +5 -5
  97. package/dist/cli/{chunk-ZFSB7GXF.js → chunk-N5HSG4OV.js} +5 -5
  98. package/dist/cli/{chunk-2Q7VXTMS.js → chunk-O765M4LT.js} +2 -2
  99. package/dist/cli/{chunk-QPDLG7DQ.js → chunk-OOLBE6FR.js} +53 -53
  100. package/dist/cli/{chunk-IQOIT6E3.js → chunk-P3DP56HB.js} +41 -41
  101. package/dist/cli/{chunk-BGXEMTIG.js → chunk-PQKD5DMT.js} +19 -19
  102. package/dist/cli/{chunk-V5IIBG2E.mjs → chunk-T6GPTJ5F.mjs} +1 -1
  103. package/dist/cli/{chunk-GPMS6OPX.mjs → chunk-TWWYCJJW.mjs} +5 -5
  104. package/dist/cli/{chunk-ZHPSJ3LJ.mjs → chunk-UE7JHAZ2.mjs} +29 -16
  105. package/dist/cli/{chunk-VRYX2BR4.js → chunk-UEZNIPFO.js} +107 -107
  106. package/dist/cli/{chunk-AX2OAXDL.mjs → chunk-VCHV4LS3.mjs} +1 -1
  107. package/dist/cli/{chunk-NXGLJGPB.js → chunk-VIFLWQXS.js} +2 -2
  108. package/dist/cli/{chunk-6BBGUQJJ.js → chunk-XTYHZEJ2.js} +8 -0
  109. package/dist/cli/{chunk-5EOEJKSV.js → chunk-YQURGSRB.js} +1 -1
  110. package/dist/cli/{chunk-ALHKB3AE.js → chunk-YZ2ZPHWR.js} +9 -9
  111. package/dist/cli/{chunk-CGDW2CRR.mjs → chunk-ZDLDCXY3.mjs} +2 -2
  112. package/dist/cli/{chunk-RMVZTBI5.mjs → chunk-ZU6JBRV5.mjs} +4 -4
  113. package/dist/cli/command-docs.js +2 -2
  114. package/dist/cli/command-docs.mjs +1 -1
  115. package/dist/cli/{csv-HZP6QMG7.mjs → csv-2YKLUKDR.mjs} +4 -4
  116. package/dist/cli/{csv-JITYN27L.js → csv-LM7FBECI.js} +13 -13
  117. package/dist/cli/{db-QRIRTOMM.mjs → db-234UBWJH.mjs} +6 -6
  118. package/dist/cli/{db-FYSRB7O4.js → db-5PMA4IVW.js} +27 -27
  119. package/dist/cli/describe-C7GOSGYB.js +49 -0
  120. package/dist/cli/{describe-REXJVJC3.mjs → describe-W26LW5O7.mjs} +17 -17
  121. package/dist/cli/describe-core.d.mts +3 -3
  122. package/dist/cli/describe-core.d.ts +3 -3
  123. package/dist/cli/{executions-BSTF4DDS.js → executions-3S736GXX.js} +8 -8
  124. package/dist/cli/{executions-53KJAFOW.mjs → executions-GD7GXTJM.mjs} +6 -6
  125. package/dist/cli/{feedback-6MW3QOXX.js → feedback-BUWTDY4R.js} +14 -14
  126. package/dist/cli/{feedback-CWUJJF3J.mjs → feedback-GBV5HJJZ.mjs} +6 -6
  127. package/dist/cli/git-YG36MROC.js +25 -0
  128. package/dist/cli/{git-CKVZTJFS.mjs → git-YXJGTDQL.mjs} +5 -5
  129. package/dist/cli/index.js +143 -143
  130. package/dist/cli/index.mjs +42 -42
  131. package/dist/cli/{legacy-noops-USTBRFRX.mjs → legacy-noops-UJM6GBNP.mjs} +6 -6
  132. package/dist/cli/{legacy-noops-QBL4PNGB.js → legacy-noops-ZSF64V2U.js} +9 -9
  133. package/dist/cli/{monitors-6UCG5D7W.mjs → monitors-UERUQ6CT.mjs} +7 -7
  134. package/dist/cli/{monitors-VCR6SUZD.js → monitors-XQ2GNH6D.js} +100 -100
  135. package/dist/cli/{org-GSRBOJVO.mjs → org-CP4VLH6M.mjs} +6 -6
  136. package/dist/cli/{org-HPILTEG4.js → org-IF6MPVNR.js} +86 -86
  137. package/dist/cli/{play-TK7WOP5H.js → play-2NHQO5MO.js} +317 -317
  138. package/dist/cli/{play-QRTYQNG4.mjs → play-ZWDYYVPI.mjs} +17 -17
  139. package/dist/cli/{providers-OAQJWVBS.mjs → providers-2CVIATU4.mjs} +6 -6
  140. package/dist/cli/{providers-HEXNJ5QC.js → providers-LOPXQN56.js} +9 -9
  141. package/dist/cli/{quickstart-FFVHTPSP.mjs → quickstart-KVCFXLID.mjs} +4 -4
  142. package/dist/cli/{quickstart-PYZTFXZX.js → quickstart-N4WDEQZY.js} +6 -6
  143. package/dist/cli/{run-4DWJXJRO.js → run-BDT5LK3I.js} +42 -42
  144. package/dist/cli/{run-HLN6YYZH.mjs → run-RUXHYWLF.mjs} +22 -22
  145. package/dist/cli/search-ATDDVADT.js +32 -0
  146. package/dist/cli/{search-ZHRCXGEL.mjs → search-BFUTNPA5.mjs} +7 -7
  147. package/dist/cli/{search-output-2KY6PFDH.js → search-output-CTXI2QZU.js} +6 -6
  148. package/dist/cli/{search-output-N7QXACVK.mjs → search-output-WUGH4PZA.mjs} +4 -4
  149. package/dist/cli/{secrets-WXQ7XO5C.js → secrets-BZJZYFOU.js} +15 -15
  150. package/dist/cli/{secrets-FKMWBLHU.mjs → secrets-Z4XQVTC6.mjs} +6 -6
  151. package/dist/cli/sessions-HNU35AFM.js +22 -0
  152. package/dist/cli/{sessions-3YDTEDA5.mjs → sessions-VZXR3MQZ.mjs} +6 -6
  153. package/dist/cli/{settings-JTPASUZN.mjs → settings-VYEZFR4L.mjs} +12 -12
  154. package/dist/cli/{settings-67TWLQ6E.js → settings-WBYA4JMM.js} +85 -85
  155. package/dist/cli/{setup-KUERQJUX.js → setup-FS2RMSS2.js} +49 -49
  156. package/dist/cli/{setup-VYNGXUJ6.mjs → setup-H7KCI4SO.mjs} +9 -9
  157. package/dist/cli/skills-VPIURCAZ.js +36 -0
  158. package/dist/cli/{skills-KI4KYHH6.mjs → skills-YQNSJUUG.mjs} +7 -7
  159. package/dist/cli/tools-273GS5HU.js +56 -0
  160. package/dist/cli/{tools-UQDJS2RS.mjs → tools-ZF6SVEGW.mjs} +16 -16
  161. package/dist/cli/{update-7FQQUBOD.mjs → update-RKQNNJM4.mjs} +9 -9
  162. package/dist/cli/update-TOD3XY55.js +34 -0
  163. package/dist/cli/{views-JAM4MNNV.mjs → views-JHHOTWDU.mjs} +6 -6
  164. package/dist/cli/{views-MJK7JGZG.js → views-KN7FEDGT.js} +21 -21
  165. package/dist/cli/{workflow-AQPRIWQX.js → workflow-2WHSKTTV.js} +17 -17
  166. package/dist/cli/{workflow-TQRV5FGO.mjs → workflow-AAYLCLWA.mjs} +7 -7
  167. package/dist/{client-BlLYQDNo.d.mts → client-D0uDBybG.d.mts} +1 -1
  168. package/dist/{client-DSQlkIDO.d.ts → client-DZTnAv4B.d.ts} +1 -1
  169. package/dist/{client-core-rX7n2H8U.d.mts → client-core-BhWf8Y1b.d.mts} +15 -2
  170. package/dist/{client-core-CDwapXy5.d.ts → client-core-og3AP1LL.d.ts} +15 -2
  171. package/dist/{compiler-manifest-BHNC4RL-.d.ts → compiler-manifest-Bes3OVA3.d.mts} +1 -1
  172. package/dist/{compiler-manifest-BHNC4RL-.d.mts → compiler-manifest-Bes3OVA3.d.ts} +1 -1
  173. package/dist/{errors-lhtIWG5Z.d.ts → errors-BJm4lLWc.d.ts} +1 -1
  174. package/dist/{errors-D7sPXrvB.d.mts → errors-Dc5r42ks.d.mts} +1 -1
  175. package/dist/{index-CQTBHXHr.d.ts → index-BfV7mRPF.d.ts} +1 -1
  176. package/dist/{index-NaDZq2xf.d.mts → index-DTkiz_Ur.d.mts} +1 -1
  177. package/dist/index.d.mts +7 -7
  178. package/dist/index.d.ts +7 -7
  179. package/dist/index.js +9 -9
  180. package/dist/index.mjs +6 -6
  181. package/dist/install-integrity.json +120 -112
  182. package/dist/plays/bundle-play-file.d.mts +3 -3
  183. package/dist/plays/bundle-play-file.d.ts +3 -3
  184. package/dist/plays/play-description.d.mts +2 -2
  185. package/dist/plays/play-description.d.ts +2 -2
  186. package/dist/plays/run-request.d.mts +2 -2
  187. package/dist/plays/run-request.d.ts +2 -2
  188. package/dist/release.d.mts +1 -1
  189. package/dist/release.d.ts +1 -1
  190. package/dist/release.js +2 -2
  191. package/dist/release.mjs +1 -1
  192. package/dist/server.d.mts +4 -4
  193. package/dist/server.d.ts +4 -4
  194. package/dist/server.js +5 -5
  195. package/dist/server.mjs +3 -3
  196. package/package.json +1 -1
  197. package/dist/cli/auth-Y2K2ZYYA.js +0 -43
  198. package/dist/cli/describe-LSOHOLFI.js +0 -49
  199. package/dist/cli/git-S7SWUZ3T.js +0 -25
  200. package/dist/cli/search-WERQBC6V.js +0 -32
  201. package/dist/cli/sessions-LXQ4Q6BS.js +0 -22
  202. package/dist/cli/skills-EFRLHY3F.js +0 -36
  203. package/dist/cli/tools-C3EIGFFP.js +0 -56
  204. package/dist/cli/update-KCY72RXH.js +0 -34
@@ -18,6 +18,7 @@ import {
18
18
  import {
19
19
  STANDARD_PLAY_SANDBOX_RUNTIME_LIMITS,
20
20
  validatePlaySandboxRuntimeLimits,
21
+ type PlaySandboxRuntimeLimits,
21
22
  } from '../../../plays/sandbox-runtime-limits';
22
23
  import {
23
24
  RUNNER_POST_TERMINAL_DIAGNOSTIC_MAX_BYTES,
@@ -31,10 +32,13 @@ import {
31
32
  } from '../../run-failure';
32
33
  import {
33
34
  buildDaytonaPayloadMaterializerSource,
35
+ buildPrebootDeliveryMaterializerSource,
34
36
  type DaytonaPayloadEnvelope,
35
37
  } from '../../daytona-payload-contract';
36
38
  export { buildDaytonaPayloadMaterializerSource } from '../../daytona-payload-contract';
37
39
  import { compactPlayArtifactForRuntimeTransport } from '../../../plays/artifact-transport';
40
+ import { buildBakedRunnerVerifySource } from '../../baked-runner-image';
41
+ import { DURABLE_RUNS_ROLLOUT } from '../../durable-runs-rollout';
38
42
  import type {
39
43
  DaytonaExecutionContext,
40
44
  DaytonaSandbox,
@@ -81,8 +85,52 @@ export type StagedDaytonaPayload = {
81
85
  terminationDiagnosticPath: string;
82
86
  progressEventPath: string;
83
87
  startupDiagnosticPath: string;
88
+ /**
89
+ * Present only when the caller asked for stdin delivery: the gzipped
90
+ * envelope (base64) that `inlineCommand` reads from its own stdin before
91
+ * running exactly `command`. The envelope was NOT uploaded. If stdin
92
+ * delivery fails, upload `envelope` to `envelopePath` and run `command`.
93
+ */
94
+ inlineEnvelope?: {
95
+ envelopePath: string;
96
+ envelope: Buffer;
97
+ base64: string;
98
+ inlineCommand: string;
99
+ /** The inline command prints the baked verdict line before reading stdin. */
100
+ verifiesBakedRunner?: boolean;
101
+ };
84
102
  };
85
103
 
104
+ /** Exit code of the inline prefix when stdin did not carry the whole envelope. */
105
+ export const INLINE_ENVELOPE_INCOMPLETE_EXIT_CODE = 97;
106
+
107
+ /**
108
+ * Shell prefix that reads exactly the base64 envelope from stdin, decodes it
109
+ * to `envelopePath`, and refuses (exit 97, before anything else runs) unless
110
+ * the decoded file has exactly the expected byte count. The secret-bearing
111
+ * envelope travels only on stdin, never in argv or the environment.
112
+ */
113
+ export function inlineEnvelopeCommandPrefix(input: {
114
+ envelopePath: string;
115
+ base64Length: number;
116
+ bytes: number;
117
+ /** Verify the baked runner first and print its verdict line on stdout. */
118
+ verifyBakedRunner?: { nodeCommand: string; path: string; hash: string };
119
+ }): string {
120
+ const path = shellQuote(input.envelopePath);
121
+ return `${bakedRunnerGuardPrefix(input.verifyBakedRunner)}head -c ${input.base64Length} | base64 -d > ${path} && [ "$(wc -c < ${path} | tr -d ' ')" = "${input.bytes}" ] || exit ${INLINE_ENVELOPE_INCOMPLETE_EXIT_CODE}; `;
122
+ }
123
+
124
+ function bakedRunnerGuardPrefix(verify?: {
125
+ nodeCommand: string;
126
+ path: string;
127
+ hash: string;
128
+ }): string {
129
+ return verify
130
+ ? `v=$(${verify.nodeCommand} -e ${shellQuote(buildBakedRunnerVerifySource())} ${shellQuote(verify.path)} ${shellQuote(verify.hash)}); printf '%s\\n' "$v"; [ "$v" = 'baked-runner:ok' ] || exit ${INLINE_BAKED_RUNNER_UNVERIFIED_EXIT_CODE}; `
131
+ : '';
132
+ }
133
+
86
134
  /** No payload or customer command has been sent when this is raised. */
87
135
  export class DaytonaNodeUnavailableError extends Error {
88
136
  constructor(
@@ -100,6 +148,28 @@ export class DaytonaNodeUnavailableError extends Error {
100
148
  }
101
149
  }
102
150
 
151
+ /**
152
+ * A prebaked runner the launcher expects in the sandbox image. `verified`
153
+ * settles with whether the sandbox itself proved the file exists and hashes to
154
+ * `hash`; a rejection or `false` keeps the full-upload path. The runner is
155
+ * never executed from `path` before that verdict is `true`.
156
+ */
157
+ export type BakedRunnerExpectation = {
158
+ hash: string;
159
+ path: string;
160
+ verified: Promise<boolean>;
161
+ /**
162
+ * Inline (stdin) delivery only: the launch command itself verifies the
163
+ * baked file before reading stdin, printing the verdict line first, so no
164
+ * separate verify call is made. `verified` must then resolve true; a
165
+ * non-`ok` verdict makes the command exit 98 before reading the envelope.
166
+ */
167
+ verifyInCommand?: boolean;
168
+ };
169
+
170
+ /** Exit code of the inline prefix when the baked runner did not verify. */
171
+ export const INLINE_BAKED_RUNNER_UNVERIFIED_EXIT_CODE = 98;
172
+
103
173
  export type RemoteRunnerPayloadSandbox = {
104
174
  id: string;
105
175
  /** Daytona target (region) the sandbox runs in, when the provider reports it. */
@@ -162,6 +232,20 @@ function nodeMaterializePayloadCommand(input: {
162
232
  ].join(' ');
163
233
  }
164
234
 
235
+ /**
236
+ * One Node process materializes the payload and then becomes the runtime
237
+ * watchdog (`DURABLE_RUNS_ROLLOUT.singleNodeMaterializeWatchdog`). The materializer runs in its own block scope (so its constants
238
+ * cannot collide with the watchdog's), consumes its six leading arguments, and
239
+ * removes them from `process.argv` so the watchdog reads exactly the argument
240
+ * positions it always had. A materializer failure throws before the watchdog
241
+ * is evaluated, which is what the former `materialize && watchdog` chain did.
242
+ */
243
+ export function buildCombinedMaterializeAndWatchdogSource(
244
+ watchdogSource: string,
245
+ ): string {
246
+ return `{${buildDaytonaPayloadMaterializerSource()}}process.argv.splice(1,6);${watchdogSource}`;
247
+ }
248
+
165
249
  /**
166
250
  * Crash-containment epilogue (push execution). The parked worker no longer
167
251
  * holds anything that returns when the runner process dies, so a runner that
@@ -598,6 +682,262 @@ export function withRunnerSandboxProvider(
598
682
  };
599
683
  }
600
684
 
685
+ type DetachedRunnerPaths = Pick<
686
+ StagedDaytonaPayload,
687
+ | 'outputPath'
688
+ | 'exitCodePath'
689
+ | 'oomKillBaselinePath'
690
+ | 'runnerPidPath'
691
+ | 'runtimeStartedPath'
692
+ | 'runtimeCompletedPath'
693
+ | 'terminationDiagnosticPath'
694
+ | 'progressEventPath'
695
+ | 'startupDiagnosticPath'
696
+ >;
697
+
698
+ /**
699
+ * The detached shell command: the watched runner (its output captured), then
700
+ * the crash-terminal epilogue. With `materialize`, the envelope is
701
+ * materialized in the same chain first (today's launch). Without it (PB), the
702
+ * runner is started with `--wait-config` and the files arrive later, config
703
+ * last; every watchdog limit and marker is otherwise the same.
704
+ */
705
+ function buildDetachedRunnerCommand(input: {
706
+ workDir: string;
707
+ nodeBinaryPath?: string;
708
+ sandboxTarget?: string;
709
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
710
+ memoryLimitMiB?: number;
711
+ /** The runner file the watchdog starts. */
712
+ runnerPath: string;
713
+ configPath: string;
714
+ crashPusherPath: string;
715
+ materialize: {
716
+ envelopePath: string;
717
+ /** Where the materializer writes runner bytes the envelope carries. */
718
+ uploadedRunnerPath: string;
719
+ artifactCodePath: string;
720
+ artifactSourceMapPath: string;
721
+ } | null;
722
+ }): DetachedRunnerPaths & { command: string } {
723
+ const { workDir, configPath, crashPusherPath, materialize } = input;
724
+ const runtimeLimitSeconds = input.sandboxRuntimeLimits.timeoutSeconds;
725
+ const outputPath = `${workDir}/deepline-play-output-${randomUUID()}.log`;
726
+ const crashPusherLogPath = `${workDir}/deepline-play-crash-terminal-${randomUUID()}.log`;
727
+ const exitCodePath = `${workDir}/deepline-play-exit-${randomUUID()}.txt`;
728
+ const oomKillBaselinePath = `${workDir}/deepline-play-oom-kill-${randomUUID()}.txt`;
729
+ const runnerPidPath = `${workDir}/deepline-play-runner-pid-${randomUUID()}.txt`;
730
+ const runtimeStartedPath = `${workDir}/deepline-play-runtime-started-${randomUUID()}.json`;
731
+ const runtimeCompletedPath = `${workDir}/deepline-play-runtime-completed-${randomUUID()}.json`;
732
+ const runtimeLimitMarkerPath = `${workDir}/deepline-play-runtime-limit-${randomUUID()}.txt`;
733
+ const terminationDiagnosticPath = `${workDir}/deepline-play-termination-${randomUUID()}.json`;
734
+ const memoryLedgerPath = `${workDir}/deepline-play-memory-ledger-${randomUUID()}.json`;
735
+ const memoryPressurePath = `${workDir}/deepline-play-memory-pressure-${randomUUID()}.json`;
736
+ const progressEventPath = `${workDir}/deepline-play-progress-${randomUUID()}.jsonl`;
737
+ const startupDiagnosticPath = `${workDir}/deepline-play-startup-${randomUUID()}.json`;
738
+ const runnerTraceEnv =
739
+ process.env.DEEPLINE_RUNTIME_RECEIPT_TRACE === '1'
740
+ ? 'DEEPLINE_RUNTIME_RECEIPT_TRACE=1 '
741
+ : '';
742
+ const runtimeReliabilityEnv = runtimeReliabilityEnvironmentPrefix();
743
+ // The runner's egress probe prints this next to its round-trip timings so
744
+ // a slow sandbox-to-estate path can be read against the region it crosses.
745
+ const sandboxTarget = input.sandboxTarget;
746
+ const sandboxTargetEnv =
747
+ typeof sandboxTarget === 'string' && sandboxTarget.trim()
748
+ ? `DEEPLINE_SANDBOX_TARGET=${shellQuote(sandboxTarget.trim())} `
749
+ : '';
750
+ const nodeCommand = input.nodeBinaryPath
751
+ ? shellQuote(input.nodeBinaryPath)
752
+ : 'node';
753
+ const singleNodeStart =
754
+ materialize !== null && DURABLE_RUNS_ROLLOUT.singleNodeMaterializeWatchdog;
755
+ const watchdogSource = buildDaytonaRuntimeWatchdogSource(
756
+ input.sandboxRuntimeLimits,
757
+ input.memoryLimitMiB,
758
+ materialize === null,
759
+ );
760
+ const watchedRunnerCommand = [
761
+ nodeCommand,
762
+ '-e',
763
+ shellQuote(
764
+ singleNodeStart
765
+ ? buildCombinedMaterializeAndWatchdogSource(watchdogSource)
766
+ : watchdogSource,
767
+ ),
768
+ // Materializer arguments, consumed (and removed from argv) before the
769
+ // watchdog reads its own.
770
+ ...(singleNodeStart && materialize
771
+ ? [
772
+ shellQuote(materialize.envelopePath),
773
+ shellQuote(materialize.uploadedRunnerPath),
774
+ shellQuote(configPath),
775
+ shellQuote(materialize.artifactCodePath),
776
+ shellQuote(materialize.artifactSourceMapPath),
777
+ shellQuote(crashPusherPath),
778
+ ]
779
+ : []),
780
+ // Watchdog arguments.
781
+ shellQuote(input.runnerPath),
782
+ shellQuote(configPath),
783
+ shellQuote(runtimeStartedPath),
784
+ shellQuote(runtimeCompletedPath),
785
+ String(runtimeLimitSeconds * 1_000),
786
+ String(PLAY_RUNNER_STARTUP_GRACE_SECONDS * 1_000),
787
+ String(PLAY_RUNNER_TERMINAL_GRACE_SECONDS * 1_000),
788
+ shellQuote(runtimeLimitMarkerPath),
789
+ shellQuote(terminationDiagnosticPath),
790
+ shellQuote(memoryLedgerPath),
791
+ shellQuote(memoryPressurePath),
792
+ shellQuote(RUNNER_MEMORY_CGROUP_ROOT),
793
+ shellQuote(runnerPidPath),
794
+ ].join(' ');
795
+ const materializeFirst =
796
+ singleNodeStart || !materialize
797
+ ? ''
798
+ : `${nodeMaterializePayloadCommand({
799
+ envelopePath: materialize.envelopePath,
800
+ runnerPath: materialize.uploadedRunnerPath,
801
+ configPath,
802
+ artifactCodePath: materialize.artifactCodePath,
803
+ artifactSourceMapPath: materialize.artifactSourceMapPath,
804
+ crashPusherPath,
805
+ nodeBinaryPath: input.nodeBinaryPath,
806
+ })} && `;
807
+ const runnerCommand = `${materializeFirst}DEEPLINE_PLAY_RUNNER_RUNTIME_STARTED_PATH=${shellQuote(runtimeStartedPath)} DEEPLINE_PLAY_RUNNER_RUNTIME_COMPLETED_PATH=${shellQuote(runtimeCompletedPath)} DEEPLINE_PLAY_RUNNER_PROGRESS_EVENT_PATH=${shellQuote(progressEventPath)} DEEPLINE_PLAY_RUNNER_STARTUP_DIAGNOSTIC_PATH=${shellQuote(startupDiagnosticPath)} DEEPLINE_PLAY_RUNNER_STDOUT_EVENT_MODE=compact UV_THREADPOOL_SIZE=${PLAY_RUNNER_UV_THREADPOOL_SIZE} ${runtimeReliabilityEnv}${runnerTraceEnv}${sandboxTargetEnv}${watchedRunnerCommand}`;
808
+ // Crash-containment epilogue: runs UNCONDITIONALLY after the runner exits and
809
+ // pushes an unacknowledged parsed (or synthesized) terminal so the parked
810
+ // worker wakes within seconds of ANY runner death — process.exit abuse, OOM
811
+ // SIGKILL, or a crash before the in-process push. Idempotent against a
812
+ // successful in-runner push when its local acknowledgement was lost.
813
+ // Its own retry diagnostics are kept in a separate log: appending them to
814
+ // `outputPath` after a near-gateway-sized result could hide that result from
815
+ // a later bounded-tail recovery read.
816
+ const command = `rm -f ${shellQuote(outputPath)} ${shellQuote(crashPusherLogPath)} ${shellQuote(exitCodePath)} ${shellQuote(oomKillBaselinePath)} ${shellQuote(runnerPidPath)} ${shellQuote(runtimeStartedPath)} ${shellQuote(runtimeCompletedPath)} ${shellQuote(runtimeLimitMarkerPath)} ${shellQuote(terminationDiagnosticPath)} ${shellQuote(memoryLedgerPath)} ${shellQuote(`${memoryLedgerPath}.tmp`)} ${shellQuote(memoryPressurePath)} ${shellQuote(progressEventPath)} ${shellQuote(`${progressEventPath}.*`)} ${shellQuote(startupDiagnosticPath)}; ( awk '$1 == "oom_kill" { print $2 }' /sys/fs/cgroup/memory.events 2>/dev/null || true ) > ${shellQuote(oomKillBaselinePath)}; ( ${runnerCommand} ) > ${shellQuote(outputPath)} 2>&1; code=$?; printf '%s' "$code" > ${shellQuote(exitCodePath)}; ${runtimeReliabilityEnv}${nodeCommand} ${shellQuote(crashPusherPath)} ${shellQuote(configPath)} "$code" ${shellQuote(outputPath)} ${shellQuote(runtimeLimitMarkerPath)} ${shellQuote(oomKillBaselinePath)} /sys/fs/cgroup/memory.events ${shellQuote(terminationDiagnosticPath)} ${shellQuote(runtimeCompletedPath)} > ${shellQuote(crashPusherLogPath)} 2>&1 || true; printf 'deepline runner output captured: %s\\n' ${shellQuote(outputPath)}; exit "$code"`;
817
+
818
+ return {
819
+ command,
820
+ outputPath,
821
+ exitCodePath,
822
+ oomKillBaselinePath,
823
+ runnerPidPath,
824
+ runtimeStartedPath,
825
+ runtimeCompletedPath,
826
+ terminationDiagnosticPath,
827
+ progressEventPath,
828
+ startupDiagnosticPath,
829
+ };
830
+ }
831
+
832
+ /**
833
+ * PB (pre-booted runner): what the early sandbox runs before its run is
834
+ * adopted, and the fixed paths the run's delivery and suspension must use.
835
+ */
836
+ export type PrebootedRunnerLaunch = DetachedRunnerPaths & {
837
+ /**
838
+ * The long-lived pre-boot command: the baked-runner verify guard (verdict
839
+ * line first; exit 98 before anything else on a non-ok verdict), then the
840
+ * watched runner started with `--wait-config`, then the crash-terminal
841
+ * epilogue. It names only public paths and the public baked runner: no
842
+ * envelope, config, token or customer data.
843
+ */
844
+ command: string;
845
+ /** The verified baked runner the watchdog starts. */
846
+ runnerPath: string;
847
+ configPath: string;
848
+ artifactCodePath: string;
849
+ artifactSourceMapPath: string;
850
+ crashPusherPath: string;
851
+ /** The limits the watchdog and V8 flags were fixed with at pre-boot. */
852
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
853
+ memoryLimitMiB?: number;
854
+ };
855
+
856
+ export function buildPrebootedRunnerLaunch(input: {
857
+ workDir: string;
858
+ bakedRunner: { hash: string; path: string };
859
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
860
+ memoryLimitMiB?: number;
861
+ nodeBinaryPath?: string;
862
+ }): PrebootedRunnerLaunch {
863
+ const workDir = input.workDir.replace(/\/$/, '');
864
+ const sandboxRuntimeLimits = validatePlaySandboxRuntimeLimits(
865
+ input.sandboxRuntimeLimits,
866
+ );
867
+ const configPath = `${workDir}/deepline-play-config-${randomUUID()}.json`;
868
+ const artifactCodePath = `${workDir}/deepline-play-artifact-${randomUUID()}.cjs`;
869
+ const crashPusherPath = `${workDir}/deepline-play-crash-terminal-${randomUUID()}.cjs`;
870
+ const nodeCommand = input.nodeBinaryPath
871
+ ? shellQuote(input.nodeBinaryPath)
872
+ : 'node';
873
+ const { command, ...paths } = buildDetachedRunnerCommand({
874
+ workDir,
875
+ nodeBinaryPath: input.nodeBinaryPath,
876
+ sandboxRuntimeLimits,
877
+ memoryLimitMiB: input.memoryLimitMiB,
878
+ runnerPath: input.bakedRunner.path,
879
+ configPath,
880
+ crashPusherPath,
881
+ materialize: null,
882
+ });
883
+ return {
884
+ ...paths,
885
+ command: `${bakedRunnerGuardPrefix({
886
+ nodeCommand,
887
+ path: input.bakedRunner.path,
888
+ hash: input.bakedRunner.hash,
889
+ })}${command}`,
890
+ runnerPath: input.bakedRunner.path,
891
+ configPath,
892
+ artifactCodePath,
893
+ artifactSourceMapPath: `${artifactCodePath}.map`,
894
+ crashPusherPath,
895
+ sandboxRuntimeLimits,
896
+ ...(input.memoryLimitMiB === undefined
897
+ ? {}
898
+ : { memoryLimitMiB: input.memoryLimitMiB }),
899
+ };
900
+ }
901
+
902
+ /** The run's limits differ from those the pre-booted runner was started with. */
903
+ export class PrebootedRunnerLimitsMismatchError extends Error {
904
+ constructor() {
905
+ super(
906
+ 'The pre-booted runner was started with different sandbox limits than this run; nothing was delivered to it.',
907
+ );
908
+ this.name = 'PrebootedRunnerLimitsMismatchError';
909
+ }
910
+ }
911
+
912
+ export function samePlaySandboxRuntimeLimits(
913
+ a: PlaySandboxRuntimeLimits,
914
+ b: PlaySandboxRuntimeLimits,
915
+ ): boolean {
916
+ return (
917
+ a.timeoutSeconds === b.timeoutSeconds &&
918
+ a.memoryGiB === b.memoryGiB &&
919
+ a.cpu === b.cpu &&
920
+ a.diskGiB === b.diskGiB
921
+ );
922
+ }
923
+
924
+ function prebootDeliveryMaterializeCommand(input: {
925
+ nodeCommand: string;
926
+ envelopePath: string;
927
+ preboot: PrebootedRunnerLaunch;
928
+ }): string {
929
+ return [
930
+ input.nodeCommand,
931
+ '-e',
932
+ shellQuote(buildPrebootDeliveryMaterializerSource()),
933
+ shellQuote(input.envelopePath),
934
+ shellQuote(input.preboot.configPath),
935
+ shellQuote(input.preboot.artifactCodePath),
936
+ shellQuote(input.preboot.artifactSourceMapPath),
937
+ shellQuote(input.preboot.crashPusherPath),
938
+ ].join(' ');
939
+ }
940
+
601
941
  export async function stageRunnerPayload(input: {
602
942
  sandbox: RemoteRunnerPayloadSandbox;
603
943
  bundlePromise: Promise<string>;
@@ -609,14 +949,42 @@ export async function stageRunnerPayload(input: {
609
949
  workDir: string;
610
950
  startedAt: number;
611
951
  emitStage: DaytonaStageEmitter;
952
+ /** Set only when the image is expected to carry this deploy's runner. */
953
+ bakedRunner?: BakedRunnerExpectation;
954
+ /**
955
+ * `stdin`: do not upload the envelope; return it for the caller to deliver
956
+ * on the launch command's stdin (one provider call fewer). Default upload.
957
+ */
958
+ envelopeDelivery?: 'upload' | 'stdin';
959
+ /**
960
+ * PB: a runner already started in this sandbox by
961
+ * `buildPrebootedRunnerLaunch` and polling for its config. The envelope is
962
+ * staged for that runner's fixed paths (stdin delivery only, no runner
963
+ * bytes), and the returned command only materializes it, config last.
964
+ * Mutually exclusive with `bakedRunner`.
965
+ */
966
+ preboot?: PrebootedRunnerLaunch;
612
967
  }): Promise<StagedDaytonaPayload> {
968
+ const preboot = input.preboot;
969
+ if (preboot && (input.bakedRunner || input.envelopeDelivery !== 'stdin')) {
970
+ throw new Error(
971
+ 'A pre-booted runner takes its envelope on stdin and has no separate baked-runner placement.',
972
+ );
973
+ }
613
974
  const workDir = input.workDir.replace(/\/$/, '');
614
975
  const runnerPath = `${workDir}/deepline-play-runner-${randomUUID()}.cjs`;
615
976
  const envelopePath = `${workDir}/deepline-play-payload-${randomUUID()}.json.gz`;
616
- const configPath = `${workDir}/deepline-play-config-${randomUUID()}.json`;
617
- const artifactCodePath = `${workDir}/deepline-play-artifact-${randomUUID()}.cjs`;
618
- const artifactSourceMapPath = `${artifactCodePath}.map`;
619
- const crashPusherPath = `${workDir}/deepline-play-crash-terminal-${randomUUID()}.cjs`;
977
+ const configPath =
978
+ preboot?.configPath ??
979
+ `${workDir}/deepline-play-config-${randomUUID()}.json`;
980
+ const artifactCodePath =
981
+ preboot?.artifactCodePath ??
982
+ `${workDir}/deepline-play-artifact-${randomUUID()}.cjs`;
983
+ const artifactSourceMapPath =
984
+ preboot?.artifactSourceMapPath ?? `${artifactCodePath}.map`;
985
+ const crashPusherPath =
986
+ preboot?.crashPusherPath ??
987
+ `${workDir}/deepline-play-crash-terminal-${randomUUID()}.cjs`;
620
988
 
621
989
  const remoteMaterializedFiles: Record<string, string> = {};
622
990
  const hasInlineCsv = Boolean(input.config.csvSourceContentBase64);
@@ -712,16 +1080,30 @@ export async function stageRunnerPayload(input: {
712
1080
  },
713
1081
  );
714
1082
  const runtimeLimitSeconds = sandboxRuntimeLimits.timeoutSeconds;
1083
+ if (
1084
+ preboot &&
1085
+ (!samePlaySandboxRuntimeLimits(
1086
+ preboot.sandboxRuntimeLimits,
1087
+ sandboxRuntimeLimits,
1088
+ ) ||
1089
+ preboot.memoryLimitMiB !== input.memoryLimitMiB)
1090
+ ) {
1091
+ // Nothing was delivered: the pre-booted runner still holds no config.
1092
+ throw new PrebootedRunnerLimitsMismatchError();
1093
+ }
715
1094
 
1095
+ const inlineDelivery = input.envelopeDelivery === 'stdin';
1096
+ let inlineEnvelopeBytes: Buffer | null = null;
716
1097
  const envelopeUpload = input.bundlePromise.then((bundle) =>
717
- timedRunnerPayloadUpload({
1098
+ deliverEnvelope({
718
1099
  sandbox: input.sandbox,
719
1100
  emitStage: input.emitStage,
720
1101
  label: 'payload',
721
1102
  path: envelopePath,
722
1103
  content: gzipJson({
723
1104
  schemaVersion: 1,
724
- runnerCode: bundle,
1105
+ // Empty means "already on disk"; see the runner placement below.
1106
+ runnerCode: input.bakedRunner || preboot ? '' : bundle,
725
1107
  artifactBundledCode: compactedArtifact.bundledCode,
726
1108
  artifactSourceMap: input.config.artifact.sourceMap,
727
1109
  config: preparePlayRunnerConfigForTransport(remoteConfig),
@@ -730,84 +1112,173 @@ export async function stageRunnerPayload(input: {
730
1112
  }),
731
1113
  }),
732
1114
  );
733
- await Promise.all([filesUpload, envelopeUpload]);
1115
+ function deliverEnvelope(
1116
+ upload: Parameters<typeof timedRunnerPayloadUpload>[0],
1117
+ ) {
1118
+ if (!inlineDelivery) return timedRunnerPayloadUpload(upload);
1119
+ inlineEnvelopeBytes = upload.content;
1120
+ return Promise.resolve();
1121
+ }
1122
+ // The baked runner is used only after the sandbox proved the file. Any other
1123
+ // verdict uploads the bundle exactly where the full-upload path always did,
1124
+ // so the command below never names a runner file that was not confirmed.
1125
+ const runnerPlacement = (async (): Promise<{
1126
+ path: string;
1127
+ source: 'envelope' | 'baked' | 'uploaded_fallback' | 'prebooted';
1128
+ }> => {
1129
+ const baked = input.bakedRunner;
1130
+ if (preboot) return { path: preboot.runnerPath, source: 'prebooted' };
1131
+ if (!baked) return { path: runnerPath, source: 'envelope' };
1132
+ const verified = await baked.verified.then(
1133
+ (value) => value === true,
1134
+ () => false,
1135
+ );
1136
+ if (verified) return { path: baked.path, source: 'baked' };
1137
+ await timedRunnerPayloadUpload({
1138
+ sandbox: input.sandbox,
1139
+ emitStage: input.emitStage,
1140
+ label: 'runner_fallback',
1141
+ path: runnerPath,
1142
+ content: Buffer.from(await input.bundlePromise, 'utf-8'),
1143
+ });
1144
+ return { path: runnerPath, source: 'uploaded_fallback' };
1145
+ })();
1146
+ // Awaited below; this only keeps an earlier upload failure from orphaning it.
1147
+ runnerPlacement.catch(() => undefined);
1148
+ const [, , placedRunner] = await Promise.all([
1149
+ filesUpload,
1150
+ envelopeUpload,
1151
+ runnerPlacement,
1152
+ ]);
1153
+ if (input.bakedRunner) {
1154
+ input.emitStage('runner:placement', {
1155
+ sandboxId: input.sandbox.id,
1156
+ source: placedRunner.source,
1157
+ bakedHashPrefix: input.bakedRunner.hash.slice(0, 12),
1158
+ });
1159
+ }
1160
+ if (preboot) {
1161
+ input.emitStage('runner:placement', {
1162
+ sandboxId: input.sandbox.id,
1163
+ source: placedRunner.source,
1164
+ });
1165
+ }
734
1166
  input.emitStage('upload:done', {
735
1167
  sandboxId: input.sandbox.id,
736
1168
  uploadedFileCount: uniqueLocalPaths.size + 1,
737
1169
  elapsedMs: Date.now() - input.startedAt,
738
1170
  });
739
1171
 
740
- const outputPath = `${workDir}/deepline-play-output-${randomUUID()}.log`;
741
- const crashPusherLogPath = `${workDir}/deepline-play-crash-terminal-${randomUUID()}.log`;
742
- const exitCodePath = `${workDir}/deepline-play-exit-${randomUUID()}.txt`;
743
- const oomKillBaselinePath = `${workDir}/deepline-play-oom-kill-${randomUUID()}.txt`;
744
- const runnerPidPath = `${workDir}/deepline-play-runner-pid-${randomUUID()}.txt`;
745
- const runtimeStartedPath = `${workDir}/deepline-play-runtime-started-${randomUUID()}.json`;
746
- const runtimeCompletedPath = `${workDir}/deepline-play-runtime-completed-${randomUUID()}.json`;
747
- const runtimeLimitMarkerPath = `${workDir}/deepline-play-runtime-limit-${randomUUID()}.txt`;
748
- const terminationDiagnosticPath = `${workDir}/deepline-play-termination-${randomUUID()}.json`;
749
- const memoryLedgerPath = `${workDir}/deepline-play-memory-ledger-${randomUUID()}.json`;
750
- const memoryPressurePath = `${workDir}/deepline-play-memory-pressure-${randomUUID()}.json`;
751
- const progressEventPath = `${workDir}/deepline-play-progress-${randomUUID()}.jsonl`;
752
- const startupDiagnosticPath = `${workDir}/deepline-play-startup-${randomUUID()}.json`;
753
- const runnerTraceEnv =
754
- process.env.DEEPLINE_RUNTIME_RECEIPT_TRACE === '1'
755
- ? 'DEEPLINE_RUNTIME_RECEIPT_TRACE=1 '
756
- : '';
757
- const runtimeReliabilityEnv = runtimeReliabilityEnvironmentPrefix();
758
- // The runner's egress probe prints this next to its round-trip timings so
759
- // a slow sandbox-to-estate path can be read against the region it crosses.
760
- const sandboxTarget = input.sandbox.target;
761
- const sandboxTargetEnv =
762
- typeof sandboxTarget === 'string' && sandboxTarget.trim()
763
- ? `DEEPLINE_SANDBOX_TARGET=${shellQuote(sandboxTarget.trim())} `
764
- : '';
1172
+ if (preboot) {
1173
+ const inlineEnvelope = inlineEnvelopeBytes as Buffer | null;
1174
+ if (!inlineEnvelope) {
1175
+ throw new Error('Inline envelope delivery produced no envelope.');
1176
+ }
1177
+ const base64 = inlineEnvelope.toString('base64');
1178
+ // Materialize only: the watched runner, its limits and the crash-pusher
1179
+ // epilogue are already running in the pre-boot exec.
1180
+ const command = prebootDeliveryMaterializeCommand({
1181
+ nodeCommand: input.nodeBinaryPath
1182
+ ? shellQuote(input.nodeBinaryPath)
1183
+ : 'node',
1184
+ envelopePath,
1185
+ preboot,
1186
+ });
1187
+ input.emitStage('upload:payload:inline', {
1188
+ bytes: inlineEnvelope.byteLength,
1189
+ base64Bytes: base64.length,
1190
+ });
1191
+ return {
1192
+ inlineEnvelope: {
1193
+ envelopePath,
1194
+ envelope: inlineEnvelope,
1195
+ base64,
1196
+ inlineCommand: `${inlineEnvelopeCommandPrefix({
1197
+ envelopePath,
1198
+ base64Length: base64.length,
1199
+ bytes: inlineEnvelope.byteLength,
1200
+ })}${command}`,
1201
+ },
1202
+ workDir: input.workDir,
1203
+ command,
1204
+ outputPath: preboot.outputPath,
1205
+ exitCodePath: preboot.exitCodePath,
1206
+ oomKillBaselinePath: preboot.oomKillBaselinePath,
1207
+ runnerPidPath: preboot.runnerPidPath,
1208
+ runtimeStartedPath: preboot.runtimeStartedPath,
1209
+ runtimeCompletedPath: preboot.runtimeCompletedPath,
1210
+ terminationDiagnosticPath: preboot.terminationDiagnosticPath,
1211
+ progressEventPath: preboot.progressEventPath,
1212
+ startupDiagnosticPath: preboot.startupDiagnosticPath,
1213
+ };
1214
+ }
1215
+
1216
+ const {
1217
+ command,
1218
+ outputPath,
1219
+ exitCodePath,
1220
+ oomKillBaselinePath,
1221
+ runnerPidPath,
1222
+ runtimeStartedPath,
1223
+ runtimeCompletedPath,
1224
+ terminationDiagnosticPath,
1225
+ progressEventPath,
1226
+ startupDiagnosticPath,
1227
+ } = buildDetachedRunnerCommand({
1228
+ workDir,
1229
+ nodeBinaryPath: input.nodeBinaryPath,
1230
+ sandboxTarget: input.sandbox.target,
1231
+ sandboxRuntimeLimits,
1232
+ memoryLimitMiB: input.memoryLimitMiB,
1233
+ runnerPath: placedRunner.path,
1234
+ configPath,
1235
+ crashPusherPath,
1236
+ materialize: {
1237
+ envelopePath,
1238
+ uploadedRunnerPath: runnerPath,
1239
+ artifactCodePath,
1240
+ artifactSourceMapPath,
1241
+ },
1242
+ });
765
1243
  const nodeCommand = input.nodeBinaryPath
766
1244
  ? shellQuote(input.nodeBinaryPath)
767
1245
  : 'node';
768
- const watchedRunnerCommand = [
769
- nodeCommand,
770
- '-e',
771
- shellQuote(
772
- buildDaytonaRuntimeWatchdogSource(
773
- sandboxRuntimeLimits,
774
- input.memoryLimitMiB,
775
- ),
776
- ),
777
- shellQuote(runnerPath),
778
- shellQuote(configPath),
779
- shellQuote(runtimeStartedPath),
780
- shellQuote(runtimeCompletedPath),
781
- String(runtimeLimitSeconds * 1_000),
782
- String(PLAY_RUNNER_STARTUP_GRACE_SECONDS * 1_000),
783
- String(PLAY_RUNNER_TERMINAL_GRACE_SECONDS * 1_000),
784
- shellQuote(runtimeLimitMarkerPath),
785
- shellQuote(terminationDiagnosticPath),
786
- shellQuote(memoryLedgerPath),
787
- shellQuote(memoryPressurePath),
788
- shellQuote(RUNNER_MEMORY_CGROUP_ROOT),
789
- shellQuote(runnerPidPath),
790
- ].join(' ');
791
- const runnerCommand = `${nodeMaterializePayloadCommand({
792
- envelopePath,
793
- runnerPath,
794
- configPath,
795
- artifactCodePath,
796
- artifactSourceMapPath,
797
- crashPusherPath,
798
- nodeBinaryPath: input.nodeBinaryPath,
799
- })} && DEEPLINE_PLAY_RUNNER_RUNTIME_STARTED_PATH=${shellQuote(runtimeStartedPath)} DEEPLINE_PLAY_RUNNER_RUNTIME_COMPLETED_PATH=${shellQuote(runtimeCompletedPath)} DEEPLINE_PLAY_RUNNER_PROGRESS_EVENT_PATH=${shellQuote(progressEventPath)} DEEPLINE_PLAY_RUNNER_STARTUP_DIAGNOSTIC_PATH=${shellQuote(startupDiagnosticPath)} DEEPLINE_PLAY_RUNNER_STDOUT_EVENT_MODE=compact UV_THREADPOOL_SIZE=${PLAY_RUNNER_UV_THREADPOOL_SIZE} ${runtimeReliabilityEnv}${runnerTraceEnv}${sandboxTargetEnv}${watchedRunnerCommand}`;
800
- // Crash-containment epilogue: runs UNCONDITIONALLY after the runner exits and
801
- // pushes an unacknowledged parsed (or synthesized) terminal so the parked
802
- // worker wakes within seconds of ANY runner death — process.exit abuse, OOM
803
- // SIGKILL, or a crash before the in-process push. Idempotent against a
804
- // successful in-runner push when its local acknowledgement was lost.
805
- // Its own retry diagnostics are kept in a separate log: appending them to
806
- // `outputPath` after a near-gateway-sized result could hide that result from
807
- // a later bounded-tail recovery read.
808
- const command = `rm -f ${shellQuote(outputPath)} ${shellQuote(crashPusherLogPath)} ${shellQuote(exitCodePath)} ${shellQuote(oomKillBaselinePath)} ${shellQuote(runnerPidPath)} ${shellQuote(runtimeStartedPath)} ${shellQuote(runtimeCompletedPath)} ${shellQuote(runtimeLimitMarkerPath)} ${shellQuote(terminationDiagnosticPath)} ${shellQuote(memoryLedgerPath)} ${shellQuote(`${memoryLedgerPath}.tmp`)} ${shellQuote(memoryPressurePath)} ${shellQuote(progressEventPath)} ${shellQuote(`${progressEventPath}.*`)} ${shellQuote(startupDiagnosticPath)}; ( awk '$1 == "oom_kill" { print $2 }' /sys/fs/cgroup/memory.events 2>/dev/null || true ) > ${shellQuote(oomKillBaselinePath)}; ( ${runnerCommand} ) > ${shellQuote(outputPath)} 2>&1; code=$?; printf '%s' "$code" > ${shellQuote(exitCodePath)}; ${runtimeReliabilityEnv}${nodeCommand} ${shellQuote(crashPusherPath)} ${shellQuote(configPath)} "$code" ${shellQuote(outputPath)} ${shellQuote(runtimeLimitMarkerPath)} ${shellQuote(oomKillBaselinePath)} /sys/fs/cgroup/memory.events ${shellQuote(terminationDiagnosticPath)} ${shellQuote(runtimeCompletedPath)} > ${shellQuote(crashPusherLogPath)} 2>&1 || true; printf 'deepline runner output captured: %s\\n' ${shellQuote(outputPath)}; exit "$code"`;
1246
+
1247
+ const inlineEnvelope = inlineEnvelopeBytes as Buffer | null;
1248
+ let inline: StagedDaytonaPayload['inlineEnvelope'];
1249
+ if (inlineDelivery) {
1250
+ if (!inlineEnvelope) {
1251
+ throw new Error('Inline envelope delivery produced no envelope.');
1252
+ }
1253
+ const base64 = inlineEnvelope.toString('base64');
1254
+ inline = {
1255
+ envelopePath,
1256
+ envelope: inlineEnvelope,
1257
+ base64,
1258
+ inlineCommand: `${inlineEnvelopeCommandPrefix({
1259
+ envelopePath,
1260
+ base64Length: base64.length,
1261
+ bytes: inlineEnvelope.byteLength,
1262
+ ...(input.bakedRunner?.verifyInCommand
1263
+ ? {
1264
+ verifyBakedRunner: {
1265
+ nodeCommand,
1266
+ path: input.bakedRunner.path,
1267
+ hash: input.bakedRunner.hash,
1268
+ },
1269
+ }
1270
+ : {}),
1271
+ })}${command}`,
1272
+ verifiesBakedRunner: input.bakedRunner?.verifyInCommand === true,
1273
+ };
1274
+ input.emitStage('upload:payload:inline', {
1275
+ bytes: inlineEnvelope.byteLength,
1276
+ base64Bytes: base64.length,
1277
+ });
1278
+ }
809
1279
 
810
1280
  return {
1281
+ ...(inline ? { inlineEnvelope: inline } : {}),
811
1282
  workDir: input.workDir,
812
1283
  command,
813
1284
  outputPath,