deepline 0.3.577 → 0.3.579

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 (170) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +7 -0
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +3 -1
  4. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +18 -0
  5. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +124 -57
  6. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +4 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +43 -64
  8. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +25 -0
  9. package/dist/bundling-sources/shared_libs/plays/sandbox-runtime-limits.ts +83 -0
  10. package/dist/cli/{agents-ZIGK3FQ2.js → agents-D5RZEVXQ.js} +37 -54
  11. package/dist/cli/{agents-SUJRATC2.mjs → agents-FJTRTYCL.mjs} +10 -27
  12. package/dist/cli/{auth-TRKPRZK6.mjs → auth-OMYIDVXZ.mjs} +5 -5
  13. package/dist/cli/auth-Q4O7MJU4.js +44 -0
  14. package/dist/cli/{billing-6RAF4DQY.js → billing-EWFUDLQ7.js} +104 -102
  15. package/dist/cli/{billing-WPQT3QRS.mjs → billing-XK3LBNYS.mjs} +11 -9
  16. package/dist/cli/{chunk-MVCKEPWF.mjs → chunk-27ZYRIQC.mjs} +5 -5
  17. package/dist/cli/{chunk-CWHXE6HJ.mjs → chunk-3Z4TVZE7.mjs} +1 -1
  18. package/dist/cli/{chunk-KVDIN2YW.js → chunk-44NTNNKC.js} +11 -13
  19. package/dist/cli/{chunk-O35BHZLQ.mjs → chunk-6DMGKAWO.mjs} +2 -2
  20. package/dist/cli/{chunk-ATW77ZBL.mjs → chunk-6EVVUVU3.mjs} +2 -2
  21. package/dist/cli/{chunk-LXM36EXW.mjs → chunk-6GON36H3.mjs} +17 -14
  22. package/dist/cli/{chunk-RSZSKTRC.js → chunk-6MIEJJSO.js} +4 -4
  23. package/dist/cli/{chunk-ID5WQZ2H.mjs → chunk-6NYHMXC7.mjs} +1 -1
  24. package/dist/cli/{chunk-DJP7CJQC.js → chunk-72TWLORR.js} +3 -3
  25. package/dist/cli/{chunk-X5ZE7K4J.js → chunk-7HOYKXVY.js} +8 -8
  26. package/dist/cli/{chunk-NRBIYZUG.js → chunk-7JMCRYXU.js} +10 -10
  27. package/dist/cli/{chunk-MDP3CNDM.mjs → chunk-7SZCJC4R.mjs} +2 -2
  28. package/dist/cli/{chunk-APOWCBO7.js → chunk-ABH6PUDZ.js} +23 -23
  29. package/dist/cli/{chunk-EV47DV25.js → chunk-AP7PIGL5.js} +41 -41
  30. package/dist/cli/{chunk-CZF2LKIT.js → chunk-BLEYV4BJ.js} +21 -21
  31. package/dist/cli/{chunk-DWUESXDD.mjs → chunk-BZ4M7OFO.mjs} +11 -1
  32. package/dist/cli/{chunk-RVICQWXU.js → chunk-DH736ASH.js} +20 -20
  33. package/dist/cli/{chunk-FYKHAT2F.mjs → chunk-DTQBQSUU.mjs} +9 -0
  34. package/dist/cli/{chunk-X7Y4T7CV.mjs → chunk-F57NDSKT.mjs} +5 -5
  35. package/dist/cli/{chunk-ITK5TGQ7.js → chunk-FKXSIIR4.js} +15 -15
  36. package/dist/cli/{chunk-ZHJIDDYR.js → chunk-G5CZDRY3.js} +26 -26
  37. package/dist/cli/{chunk-MOWABWHT.js → chunk-HEZW2IDK.js} +277 -274
  38. package/dist/cli/{chunk-ORLJIJVX.mjs → chunk-HGUFTSB5.mjs} +11 -13
  39. package/dist/cli/{chunk-FHYNK7GL.mjs → chunk-I2TSRLOI.mjs} +1 -1
  40. package/dist/cli/{chunk-OQQDNJ2D.mjs → chunk-JFS4KHA3.mjs} +5 -5
  41. package/dist/cli/{chunk-NMSDMXYS.js → chunk-K2BU67UC.js} +2 -2
  42. package/dist/cli/{chunk-XQTJET2Y.mjs → chunk-KIIOKQFY.mjs} +1 -1
  43. package/dist/cli/{chunk-CCGFSELM.mjs → chunk-KQAEXBVQ.mjs} +3 -3
  44. package/dist/cli/{chunk-Y37JQZBP.js → chunk-KWQHQG53.js} +6 -6
  45. package/dist/cli/{chunk-V5SF5CJ7.js → chunk-LCPJR3IY.js} +2 -2
  46. package/dist/cli/{chunk-EKZ6JD6K.js → chunk-LQ45LCH7.js} +9 -9
  47. package/dist/cli/{chunk-APJ6YIYW.mjs → chunk-LV2LGW2Q.mjs} +1 -1
  48. package/dist/cli/{chunk-N6EU2FRF.mjs → chunk-LYBZLA6F.mjs} +2 -2
  49. package/dist/cli/{chunk-JWLV3XRF.js → chunk-LYJ2NSHD.js} +17 -12
  50. package/dist/cli/{chunk-MTM6WNPP.mjs → chunk-M4YWN5BT.mjs} +4 -4
  51. package/dist/cli/{chunk-H6NF5SNY.mjs → chunk-N6X2UKYQ.mjs} +2 -2
  52. package/dist/cli/{chunk-2NFDB6CL.js → chunk-NKUXW4WB.js} +2 -2
  53. package/dist/cli/{chunk-OBZB4J7B.js → chunk-NOMO5GPI.js} +1 -1
  54. package/dist/cli/{chunk-GFWVBXAK.mjs → chunk-NONMY5CY.mjs} +2 -2
  55. package/dist/cli/{chunk-QXAPAHIG.js → chunk-NWZU6HL4.js} +13 -13
  56. package/dist/cli/{chunk-FXN5WSTY.js → chunk-OOGP737I.js} +20 -20
  57. package/dist/cli/{chunk-LUQMTNFB.mjs → chunk-OSRATALX.mjs} +1 -1
  58. package/dist/cli/{chunk-ZO65VJRJ.js → chunk-PGRRMVQ5.js} +10 -1
  59. package/dist/cli/{chunk-MTHAVEQN.js → chunk-PLWZ3NB7.js} +5 -5
  60. package/dist/cli/{chunk-MXK4M7HP.js → chunk-Q4VKMF3B.js} +17 -17
  61. package/dist/cli/{chunk-SKHUWQZE.js → chunk-QA55PGJH.js} +17 -7
  62. package/dist/cli/{chunk-425SUSDJ.mjs → chunk-S2OXA7QS.mjs} +7 -7
  63. package/dist/cli/{chunk-NDMKFA6W.mjs → chunk-SUHCW7U5.mjs} +3 -3
  64. package/dist/cli/{chunk-U6Y4HX6J.mjs → chunk-SZIWFQI2.mjs} +3 -3
  65. package/dist/cli/{chunk-4ANO4DM5.mjs → chunk-TFNDOH4W.mjs} +1 -1
  66. package/dist/cli/{chunk-JHQ7FORY.js → chunk-TVAFWAOQ.js} +3 -3
  67. package/dist/cli/{chunk-NVJGVNEN.js → chunk-UYCBG75H.js} +5 -5
  68. package/dist/cli/{chunk-RW3URFZK.mjs → chunk-VFIIRK7S.mjs} +2 -2
  69. package/dist/cli/{chunk-WP4Q5PTK.mjs → chunk-WQQQP3FH.mjs} +4 -4
  70. package/dist/cli/{chunk-772IV64Y.js → chunk-WWSGXX6U.js} +5 -5
  71. package/dist/cli/{chunk-Q3WDT3YA.mjs → chunk-X6LPC3SU.mjs} +1 -1
  72. package/dist/cli/{chunk-DA5C5WOI.mjs → chunk-XQYBBCFI.mjs} +2 -2
  73. package/dist/cli/{chunk-FRYLXDNP.js → chunk-XTM6NOJ6.js} +53 -53
  74. package/dist/cli/{chunk-EJN43WGD.js → chunk-Y2ND6PPW.js} +48 -48
  75. package/dist/cli/{chunk-I44Y4MPK.mjs → chunk-YCWRKSLB.mjs} +8 -3
  76. package/dist/cli/command-docs.js +2 -2
  77. package/dist/cli/command-docs.mjs +1 -1
  78. package/dist/cli/concurrent-runs-help-D6XH3FY5.js +22 -0
  79. package/dist/cli/{concurrent-runs-help-6CGXMTFQ.mjs → concurrent-runs-help-IQBZBTD5.mjs} +6 -6
  80. package/dist/cli/{csv-L7P6PC6I.mjs → csv-6BEOWTGM.mjs} +4 -4
  81. package/dist/cli/{csv-7UZT2LGE.js → csv-T7TWLIGD.js} +13 -13
  82. package/dist/cli/{db-4OOEC5KV.mjs → db-FA5QGXZ7.mjs} +6 -6
  83. package/dist/cli/{db-7KETOIZY.js → db-MFTUN3DF.js} +27 -27
  84. package/dist/cli/{describe-M6HEFS46.mjs → describe-TITEQNVE.mjs} +21 -21
  85. package/dist/cli/describe-TYZ5YH3V.js +50 -0
  86. package/dist/cli/describe-core.d.mts +4 -2
  87. package/dist/cli/describe-core.d.ts +4 -2
  88. package/dist/cli/describe-core.js +4 -4
  89. package/dist/cli/describe-core.mjs +3 -3
  90. package/dist/cli/{executions-U27R2LY4.mjs → executions-DMYJJIRB.mjs} +6 -6
  91. package/dist/cli/{executions-UIR6RQFM.js → executions-QW3L7G7J.js} +8 -8
  92. package/dist/cli/{feedback-CQ5FUE4T.js → feedback-6JZGE7OQ.js} +14 -14
  93. package/dist/cli/{feedback-UUUISTGQ.mjs → feedback-WPSNSFRC.mjs} +6 -6
  94. package/dist/cli/{git-DTILSRIQ.mjs → git-GO65XRM3.mjs} +5 -5
  95. package/dist/cli/git-UGGRLGTQ.js +26 -0
  96. package/dist/cli/index.js +148 -148
  97. package/dist/cli/index.mjs +47 -47
  98. package/dist/cli/{integrations-NNACG3HD.mjs → integrations-EEBPETH2.mjs} +7 -7
  99. package/dist/cli/{integrations-ABBLLEJH.js → integrations-T5JPSZXN.js} +29 -29
  100. package/dist/cli/{legacy-noops-3JLS5OD7.js → legacy-noops-B55OMNH7.js} +9 -9
  101. package/dist/cli/{legacy-noops-KQW7AIYU.mjs → legacy-noops-XDNZ46IR.mjs} +6 -6
  102. package/dist/cli/{mcp-JPBFKR26.js → mcp-3YA333TQ.js} +24 -24
  103. package/dist/cli/{mcp-7NHGPYZH.mjs → mcp-4QIUAAWS.mjs} +4 -4
  104. package/dist/cli/{monitors-JOE2DALW.mjs → monitors-BVUPS4CE.mjs} +7 -7
  105. package/dist/cli/{monitors-J6HK5KCN.js → monitors-FOS7MWZO.js} +100 -100
  106. package/dist/cli/{org-WFZFQIXQ.js → org-CYM7HFLN.js} +121 -121
  107. package/dist/cli/{org-VZZ4LN4O.mjs → org-TCMRRVFC.mjs} +6 -6
  108. package/dist/cli/{outcomes-H2WEZYNT.mjs → outcomes-2JSWXWQ3.mjs} +6 -6
  109. package/dist/cli/{outcomes-RZWL47BJ.js → outcomes-VDJVP5YC.js} +14 -14
  110. package/dist/cli/{play-KMWA7GVN.mjs → play-CPP4EBYF.mjs} +20 -20
  111. package/dist/cli/{play-2ZEBUF5T.js → play-U3G73VIR.js} +349 -349
  112. package/dist/cli/{providers-57AZWFSW.js → providers-2ZB67TK7.js} +9 -9
  113. package/dist/cli/{providers-2BIA3OWA.mjs → providers-RVMIX5ED.mjs} +6 -6
  114. package/dist/cli/{quickstart-NSDM2RXV.mjs → quickstart-L3YO3OWZ.mjs} +4 -4
  115. package/dist/cli/{quickstart-EYJFERQO.js → quickstart-V3Y7XZ47.js} +6 -6
  116. package/dist/cli/{run-BW62DZGQ.js → run-M2CADJ6E.js} +49 -48
  117. package/dist/cli/{run-X6H5SCEE.mjs → run-PQ3Z2GOF.mjs} +27 -26
  118. package/dist/cli/{search-2VN74P5N.mjs → search-QVLGI7SZ.mjs} +7 -7
  119. package/dist/cli/search-RHPPZZFG.js +32 -0
  120. package/dist/cli/{search-output-SFWQVBYU.js → search-output-IUANVHWU.js} +8 -8
  121. package/dist/cli/{search-output-VN7XOZEQ.mjs → search-output-PN3V7MSO.mjs} +5 -5
  122. package/dist/cli/{secrets-OIPKG2H7.js → secrets-AOW6F67J.js} +15 -15
  123. package/dist/cli/{secrets-4M26N436.mjs → secrets-HK25G4K2.mjs} +6 -6
  124. package/dist/cli/sessions-AEGGTZ3K.js +23 -0
  125. package/dist/cli/{sessions-SYFH23L3.mjs → sessions-YN2OIAGR.mjs} +6 -6
  126. package/dist/cli/{settings-5NB4HZYL.js → settings-6EV2FPGF.js} +85 -85
  127. package/dist/cli/{settings-4HPF3T4P.mjs → settings-7UW5TWSM.mjs} +12 -12
  128. package/dist/cli/{setup-CI74F6CL.mjs → setup-BG56SHKH.mjs} +9 -9
  129. package/dist/cli/{setup-JV3F5C7P.js → setup-ZQPD2R5K.js} +49 -49
  130. package/dist/cli/skills-C6ZEZWBE.js +37 -0
  131. package/dist/cli/{skills-76CM4GHO.mjs → skills-MQV2TNUZ.mjs} +7 -7
  132. package/dist/cli/tools-PM3MC3RR.js +57 -0
  133. package/dist/cli/{tools-SVGLDWOC.mjs → tools-RGI4OE5T.mjs} +19 -19
  134. package/dist/cli/{update-KPMDOZRX.mjs → update-SQKGHQKF.mjs} +9 -9
  135. package/dist/cli/update-ZHUPF2HT.js +37 -0
  136. package/dist/cli/{views-KW54SAES.mjs → views-734T2CXF.mjs} +6 -6
  137. package/dist/cli/{views-R37NWN6J.js → views-BUKVHCRD.js} +21 -21
  138. package/dist/cli/{workflow-3MIRQV4Q.mjs → workflow-JNRRBMEK.mjs} +7 -7
  139. package/dist/cli/{workflow-BKRKUNYS.js → workflow-LPJC6RHP.js} +17 -17
  140. package/dist/{client-BrdMPFCM.d.ts → client-C1AubrWJ.d.ts} +1 -1
  141. package/dist/{client-CF-bsrtI.d.mts → client-CNYctEBh.d.mts} +1 -1
  142. package/dist/{client-core-DM1ZedOG.d.mts → client-core-Bb06TCx5.d.mts} +7 -0
  143. package/dist/{client-core-rMoUWSYM.d.ts → client-core-D6zAE46g.d.ts} +7 -0
  144. package/dist/index.d.mts +3 -3
  145. package/dist/index.d.ts +3 -3
  146. package/dist/index.js +9 -9
  147. package/dist/index.mjs +6 -6
  148. package/dist/install-integrity.json +126 -126
  149. package/dist/plays/play-description.d.mts +1 -1
  150. package/dist/plays/play-description.d.ts +1 -1
  151. package/dist/plays/run-request.d.mts +1 -1
  152. package/dist/plays/run-request.d.ts +1 -1
  153. package/dist/release.d.mts +1 -1
  154. package/dist/release.d.ts +1 -1
  155. package/dist/release.js +2 -2
  156. package/dist/release.mjs +1 -1
  157. package/dist/server.d.mts +2 -2
  158. package/dist/server.d.ts +2 -2
  159. package/dist/server.js +5 -5
  160. package/dist/server.mjs +3 -3
  161. package/package.json +1 -1
  162. package/dist/cli/auth-A5U6GVCF.js +0 -44
  163. package/dist/cli/concurrent-runs-help-VJDPVGXM.js +0 -22
  164. package/dist/cli/describe-RLWJYZIR.js +0 -50
  165. package/dist/cli/git-ZGDD3BVX.js +0 -26
  166. package/dist/cli/search-HYRDZVPQ.js +0 -32
  167. package/dist/cli/sessions-5P2KZOQE.js +0 -23
  168. package/dist/cli/skills-PJ5EL32L.js +0 -37
  169. package/dist/cli/tools-Y5ID2SPK.js +0 -57
  170. package/dist/cli/update-FSUMCMNZ.js +0 -37
@@ -2776,6 +2776,13 @@ export type BillingRecentUsageEntry = {
2776
2776
  | 'failed';
2777
2777
  /** Final billing truth may be unknown even after execution completes. */
2778
2778
  charge_finality?: 'final' | 'pending' | 'unknown';
2779
+ /**
2780
+ * The provider key the call ran on: `managed` (Deepline's key) or `user`
2781
+ * (the workspace's own connected key). `unknown` for calls recorded before
2782
+ * this was stored and for tools that need no provider key; absent from
2783
+ * older servers. Never the key itself.
2784
+ */
2785
+ credential_source?: 'managed' | 'user' | 'unknown';
2779
2786
  rough_usd_cost: number | null;
2780
2787
  created_at: string;
2781
2788
  };
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.577',
208
+ version: '0.3.579',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -1858,9 +1858,11 @@ async function createEarlyModalSandbox(
1858
1858
  },
1859
1859
  ): Promise<EarlyModalSandboxEntry> {
1860
1860
  const { key, orgId, hintAtMs } = input;
1861
+ // The run's own limits when the hint carried them, so the create, its
1862
+ // limitsKey, the pre-boot runner and the PX plan match the launch's.
1861
1863
  const modalConfig = await loadModalRequiredConfig({
1862
1864
  runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1863
- limits: null,
1865
+ limits: input.sandboxRuntimeLimits ?? null,
1864
1866
  });
1865
1867
  const supervisorSidecar = DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar;
1866
1868
  const memoryPolicy = resolveModalSandboxMemoryPolicy({
@@ -600,6 +600,11 @@ export type EarlySandboxStartRequest = {
600
600
  runtimeSchedulerSchema: string | null;
601
601
  /** EXPERIMENT: the hinted run's overrides (E2, PB, S1); absent: static. */
602
602
  experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
603
+ /**
604
+ * The hinted run's validated sandbox runtime limits (its launch's own).
605
+ * Absent: the standard profile, as before.
606
+ */
607
+ sandboxRuntimeLimits?: PlaySandboxRuntimeLimits | null;
603
608
  };
604
609
 
605
610
  /**
@@ -1220,6 +1225,19 @@ export async function adoptEarlySandbox<
1220
1225
  });
1221
1226
  return null;
1222
1227
  }
1228
+ // A sandbox created at other limits (size or timeout) than this launch's
1229
+ // can never be adopted. Decide that from the create tags first: it is an
1230
+ // ordinary miss, not a pre-boot plan failure (the plan's MAC binds the
1231
+ // limits too, and would otherwise report a mismatch as invalid).
1232
+ if (tags.limitsKey !== input.expectedLimitsKey) {
1233
+ input.emitStage('early:adopt_miss', {
1234
+ key,
1235
+ reason: 'limits_mismatch',
1236
+ sandboxId: sandbox.sandboxId,
1237
+ elapsedMs: nowMs() - startedAt,
1238
+ });
1239
+ return null;
1240
+ }
1223
1241
  // PB: another process started a runner here and holds its delivery
1224
1242
  // plan; nothing may be delivered to it from this process. Provider
1225
1243
  // claims (Modal's S1 sidecar) come first.
@@ -215,6 +215,7 @@ import {
215
215
  enqueuePostgresSchedulerSandboxCleanupForRun,
216
216
  hasPostgresSchedulerRecoverableDetachedRunner,
217
217
  executePostgresSchedulerClaim,
218
+ PostgresSchedulerAttemptFenceRefusedError,
218
219
  ensurePostgresSchedulerTerminalComputeBillingJob,
219
220
  failPostgresSchedulerAttempt,
220
221
  getPostgresSchedulerObservations,
@@ -8361,45 +8362,46 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
8361
8362
  ));
8362
8363
  let recovered = 0;
8363
8364
  let skipped = 0;
8365
+ const failures: unknown[] = [];
8364
8366
 
8365
8367
  for (const terminal of terminals) {
8366
- const runnerResult = parseDetachedRunnerResult(terminal.result);
8367
- if (
8368
- runnerResult?.status !== 'completed' &&
8369
- runnerResult?.status !== 'failed'
8370
- ) {
8371
- skipped += 1;
8372
- continue;
8373
- }
8374
- const absurdRun = await readOpenAbsurdEngineRunId({
8375
- client: input.client,
8376
- queue: input.queue,
8377
- schedulerRunId: terminal.runId,
8378
- });
8379
- // A platform failure retries the same run. While its engine task is open,
8380
- // the parked worker decides that when it wakes; committing the terminal
8381
- // here would end the run. A run with no open task has no one to wake it,
8382
- // so it still ends here.
8383
- if (
8384
- absurdRun &&
8385
- DURABLE_RUNS_ROLLOUT.automaticPostCodeRecovery &&
8386
- classifyPostCodeAttemptOutcome(runnerResult).kind === 'platform'
8387
- ) {
8388
- skipped += 1;
8389
- continue;
8390
- }
8391
- const launch = await readPostgresSchedulerLaunch(
8392
- input.client,
8393
- terminal.runId,
8394
- options,
8395
- { caller: 'runtime_worker_terminal_recovery' },
8396
- );
8397
- if (!launch) {
8398
- skipped += 1;
8399
- continue;
8400
- }
8401
-
8402
8368
  try {
8369
+ const runnerResult = parseDetachedRunnerResult(terminal.result);
8370
+ if (
8371
+ runnerResult?.status !== 'completed' &&
8372
+ runnerResult?.status !== 'failed'
8373
+ ) {
8374
+ skipped += 1;
8375
+ continue;
8376
+ }
8377
+ const absurdRun = await readOpenAbsurdEngineRunId({
8378
+ client: input.client,
8379
+ queue: input.queue,
8380
+ schedulerRunId: terminal.runId,
8381
+ });
8382
+ // A platform failure retries the same run. While its engine task is open,
8383
+ // the parked worker decides that when it wakes; committing the terminal
8384
+ // here would end the run. A run with no open task has no one to wake it,
8385
+ // so it still ends here.
8386
+ if (
8387
+ absurdRun &&
8388
+ DURABLE_RUNS_ROLLOUT.automaticPostCodeRecovery &&
8389
+ classifyPostCodeAttemptOutcome(runnerResult).kind === 'platform'
8390
+ ) {
8391
+ skipped += 1;
8392
+ continue;
8393
+ }
8394
+ const launch = await readPostgresSchedulerLaunch(
8395
+ input.client,
8396
+ terminal.runId,
8397
+ options,
8398
+ { caller: 'runtime_worker_terminal_recovery' },
8399
+ );
8400
+ if (!launch) {
8401
+ skipped += 1;
8402
+ continue;
8403
+ }
8404
+
8403
8405
  // Reuse the fenced normal completion implementation. This preserves the
8404
8406
  // terminal output envelope, resource settlement, billing, and ledger
8405
8407
  // outbox semantics instead of inventing a recovery-only terminal write.
@@ -8531,9 +8533,24 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
8531
8533
  );
8532
8534
  }
8533
8535
  } catch (error) {
8534
- // Do not start the claim loop after this function rejects: startup must
8535
- // fail loudly rather than reclaiming an acknowledged runner terminal and
8536
- // risking a duplicate play execution.
8536
+ if (error instanceof PostgresSchedulerAttemptFenceRefusedError) {
8537
+ // The scan raced the attempt's owner: it terminalized the attempt, or
8538
+ // a reclaim replaced this lease, after the scan read it. The owner
8539
+ // settles the run; this pass has nothing to recover and the next scan
8540
+ // re-reads the row. Retrying here would lose the same fence.
8541
+ skipped += 1;
8542
+ console.warn(
8543
+ '[absurd-runtime.worker] completed_runner_recovery_fenced',
8544
+ {
8545
+ runId: terminal.runId,
8546
+ attempt: terminal.attempt,
8547
+ queue: input.queue,
8548
+ reason: 'attempt_fence_refused',
8549
+ error: error.message,
8550
+ },
8551
+ );
8552
+ continue;
8553
+ }
8537
8554
  console.error(
8538
8555
  '[absurd-runtime.worker] completed_runner_recovery_failed',
8539
8556
  {
@@ -8543,12 +8560,49 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
8543
8560
  error: error instanceof Error ? error.message : String(error),
8544
8561
  },
8545
8562
  );
8546
- throw error;
8547
- }
8563
+ // One run's failure must not strand every other durable terminal in
8564
+ // this pass. Finish the pass, then reject below.
8565
+ failures.push(error);
8566
+ }
8567
+ }
8568
+ // Do not start the claim loop after this function rejects: startup must
8569
+ // fail loudly rather than reclaiming an acknowledged runner terminal and
8570
+ // risking a duplicate play execution. Every other terminal in this pass
8571
+ // has already been attempted.
8572
+ if (failures.length > 0) {
8573
+ throw completedRunnerRecoveryFailure(
8574
+ failures,
8575
+ `${failures.length} of ${terminals.length} terminals on ${input.queue}`,
8576
+ );
8548
8577
  }
8549
8578
  return { recovered, skipped };
8550
8579
  }
8551
8580
 
8581
+ /**
8582
+ * One failure rethrows as-is. Several become an AggregateError that keeps the
8583
+ * first retryable transaction SQLSTATE (deadlock, serialization, lock) as its
8584
+ * own `code`, so the scheduler pool still re-runs the idempotent recovery
8585
+ * operation instead of surfacing a transient lock conflict as a failed pass.
8586
+ */
8587
+ function completedRunnerRecoveryFailure(
8588
+ failures: unknown[],
8589
+ scope: string,
8590
+ ): unknown {
8591
+ if (failures.length === 1) return failures[0];
8592
+ const first = failures[0];
8593
+ const aggregate = new AggregateError(
8594
+ failures,
8595
+ `Completed runner terminal recovery failed for ${scope}; first: ${first instanceof Error ? first.message : String(first)}`,
8596
+ );
8597
+ const retryable = failures.find((failure): failure is { code: unknown } =>
8598
+ isRuntimeSchedulerRetryableTransactionError(failure),
8599
+ );
8600
+ if (retryable) {
8601
+ Object.assign(aggregate, { code: retryable.code });
8602
+ }
8603
+ return aggregate;
8604
+ }
8605
+
8552
8606
  /**
8553
8607
  * Fixed-controller recovery across all registered lanes.
8554
8608
  *
@@ -8591,17 +8645,30 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminalsAcrossLanes(in
8591
8645
 
8592
8646
  let recovered = 0;
8593
8647
  let skipped = 0;
8648
+ const failures: unknown[] = [];
8594
8649
  for (const releaseId of releaseIds) {
8595
- const outcome = await recoverAbsurdRuntimeCompletedRunnerTerminals({
8596
- client: input.client,
8597
- queue: absurdQueueNameForRelease(releaseId),
8598
- absurdReleaseId: releaseId,
8599
- schedulerOptions: input.schedulerOptions,
8600
- limit: input.limitPerLane,
8601
- terminals: terminalsByReleaseId.get(releaseId) ?? [],
8602
- });
8603
- recovered += outcome.recovered;
8604
- skipped += outcome.skipped;
8650
+ try {
8651
+ const outcome = await recoverAbsurdRuntimeCompletedRunnerTerminals({
8652
+ client: input.client,
8653
+ queue: absurdQueueNameForRelease(releaseId),
8654
+ absurdReleaseId: releaseId,
8655
+ schedulerOptions: input.schedulerOptions,
8656
+ limit: input.limitPerLane,
8657
+ terminals: terminalsByReleaseId.get(releaseId) ?? [],
8658
+ });
8659
+ recovered += outcome.recovered;
8660
+ skipped += outcome.skipped;
8661
+ } catch (error) {
8662
+ // Each failed terminal was already logged with its run identity. One
8663
+ // lane's failure must not strand every later lane's terminals.
8664
+ failures.push(error);
8665
+ }
8666
+ }
8667
+ if (failures.length > 0) {
8668
+ throw completedRunnerRecoveryFailure(
8669
+ failures,
8670
+ `${failures.length} of ${releaseIds.length} lanes`,
8671
+ );
8605
8672
  }
8606
8673
  return { recovered, skipped };
8607
8674
  }
@@ -12060,12 +12127,12 @@ export async function startRuntimeWorkerHost(
12060
12127
  let claimAffinityWake: (() => boolean) | null = null;
12061
12128
  const claimAffinityGate =
12062
12129
  EARLY_SANDBOX_CLAIM_AFFINITY_READER || previewClaimAffinityReader
12063
- ? createEarlySandboxClaimGate({
12064
- self: workerBase,
12065
- queue,
12066
- wake: () => claimAffinityWake?.() ?? false,
12067
- })
12068
- : undefined;
12130
+ ? createEarlySandboxClaimGate({
12131
+ self: workerBase,
12132
+ queue,
12133
+ wake: () => claimAffinityWake?.() ?? false,
12134
+ })
12135
+ : undefined;
12069
12136
  // LH: live slot use, from claimed task ids and running handlers; the
12070
12137
  // engine's saturation reading is bound below once the claim loop exists.
12071
12138
  let claimLoopHasIdleSlot: () => boolean = () => false;
@@ -402,6 +402,10 @@ export function startWorkerLaneEarlySandbox(
402
402
  orgId: input.orgId ?? null,
403
403
  runtimeSchedulerSchema: input.runtimeSchedulerSchema,
404
404
  experimentSwitchOverrides: input.experimentSwitchOverrides ?? null,
405
+ // Only when the hint carried them: a run without keeps today's request.
406
+ ...(input.sandboxRuntimeLimits
407
+ ? { sandboxRuntimeLimits: input.sandboxRuntimeLimits }
408
+ : {}),
405
409
  };
406
410
  if (
407
411
  !resolveExperimentSwitch(
@@ -119,11 +119,7 @@ import {
119
119
  type ToolResponseContract,
120
120
  } from '../../plays/tool-response-contract';
121
121
  import { normalizePlayRunFailure } from '../run-failure';
122
- import {
123
- resolvePlaySandboxRuntimeLimits,
124
- validatePlaySandboxRuntimeLimits,
125
- type PlaySandboxRuntimeLimits,
126
- } from '../sandbox-runtime-limits';
122
+ import { sandboxRuntimeLimitsFromContractSnapshot } from '../sandbox-runtime-limits';
127
123
  import type {
128
124
  ClaimRuntimeStepReceiptInput,
129
125
  ClaimRuntimeStepReceiptsInput,
@@ -12929,7 +12925,7 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
12929
12925
  // a fence loss, never success (PX: two launches adopted one early sandbox).
12930
12926
  const recorded = await client
12931
12927
  .query<{ operation_key: string }>(
12932
- `
12928
+ `
12933
12929
  WITH ${runtimeSandboxCustodyLocksSql('run.run_id = $1', options)}, eligible_attempt AS (
12934
12930
  SELECT run_id
12935
12931
  FROM custody_attempts
@@ -12996,20 +12992,20 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
12996
12992
  FROM live_operation
12997
12993
  JOIN bound_capacity ON bound_capacity.lease_id = live_operation.operation_key
12998
12994
  `,
12999
- [
13000
- input.runId,
13001
- input.attempt,
13002
- input.leaseToken,
13003
- stringifyPostgresJson(input.resource),
13004
- input.resource.sandboxCapacityLeaseId,
13005
- input.resource.sandboxId,
13006
- routingDomain,
13007
- environment,
13008
- runtimeSandboxOperationTargetState('bind_live'),
13009
- provider,
13010
- runtimeSandboxOperationFromStates('bind_live'),
13011
- ],
13012
- )
12995
+ [
12996
+ input.runId,
12997
+ input.attempt,
12998
+ input.leaseToken,
12999
+ stringifyPostgresJson(input.resource),
13000
+ input.resource.sandboxCapacityLeaseId,
13001
+ input.resource.sandboxId,
13002
+ routingDomain,
13003
+ environment,
13004
+ runtimeSandboxOperationTargetState('bind_live'),
13005
+ provider,
13006
+ runtimeSandboxOperationFromStates('bind_live'),
13007
+ ],
13008
+ )
13013
13009
  .catch((error: unknown) => {
13014
13010
  if ((error as { code?: unknown } | null)?.code === '23505')
13015
13011
  return { rows: [] as { operation_key: string }[] };
@@ -20079,6 +20075,28 @@ export function attachRunnerWorkProgressMetadata(
20079
20075
  };
20080
20076
  }
20081
20077
 
20078
+ /**
20079
+ * The fenced failure write refused this claim: the attempt is no longer
20080
+ * `running` under this lease token (its owner already terminalized it, or a
20081
+ * reclaim replaced the lease), or an authoritative runner terminal won. The
20082
+ * caller no longer owns the attempt, so this is a fence outcome, not a
20083
+ * service failure. The message is unchanged from the untyped error it
20084
+ * replaces so existing log searches and `lease_expired` classification hold.
20085
+ */
20086
+ export class PostgresSchedulerAttemptFenceRefusedError extends Error {
20087
+ readonly runId: string;
20088
+ readonly attempt: number;
20089
+
20090
+ constructor(input: { runId: string; attempt: number; message: string }) {
20091
+ super(
20092
+ `Postgres scheduler worker failed after losing lease for ${input.runId}/${input.attempt}: ${input.message}`,
20093
+ );
20094
+ this.name = 'PostgresSchedulerAttemptFenceRefusedError';
20095
+ this.runId = input.runId;
20096
+ this.attempt = input.attempt;
20097
+ }
20098
+ }
20099
+
20082
20100
  export async function executePostgresSchedulerClaim(
20083
20101
  client: PostgresSchedulerQueryClient,
20084
20102
  claim: PostgresSchedulerAttemptClaim,
@@ -20332,9 +20350,11 @@ export async function executePostgresSchedulerClaim(
20332
20350
  options,
20333
20351
  );
20334
20352
  if (!failed) {
20335
- throw new Error(
20336
- `Postgres scheduler worker failed after losing lease for ${claim.runId}/${claim.attempt}: ${message}`,
20337
- );
20353
+ throw new PostgresSchedulerAttemptFenceRefusedError({
20354
+ runId: claim.runId,
20355
+ attempt: claim.attempt,
20356
+ message,
20357
+ });
20338
20358
  }
20339
20359
  emitPlayRunFinished({
20340
20360
  orgId: claim.launch.orgId ?? null,
@@ -20432,47 +20452,6 @@ function toolResponseReceiptRevisionFromLaunch(
20432
20452
  );
20433
20453
  }
20434
20454
 
20435
- function sandboxRuntimeLimitsFromContractSnapshot(
20436
- contractSnapshot: unknown,
20437
- ): PlaySandboxRuntimeLimits {
20438
- if (
20439
- !contractSnapshot ||
20440
- typeof contractSnapshot !== 'object' ||
20441
- Array.isArray(contractSnapshot)
20442
- ) {
20443
- return resolvePlaySandboxRuntimeLimits(null);
20444
- }
20445
- const runtimeLimit = (contractSnapshot as Record<string, unknown>)
20446
- .runtimeLimit;
20447
- if (
20448
- !runtimeLimit ||
20449
- typeof runtimeLimit !== 'object' ||
20450
- Array.isArray(runtimeLimit)
20451
- ) {
20452
- return resolvePlaySandboxRuntimeLimits(null);
20453
- }
20454
- const value = runtimeLimit as Record<string, unknown>;
20455
- const timeoutSeconds = value.timeoutSeconds;
20456
- const memoryGiB = value.memoryGiB;
20457
- const cpu = value.cpu;
20458
- const diskGiB = value.diskGiB;
20459
- if (
20460
- ![timeoutSeconds, memoryGiB, cpu, diskGiB].every(
20461
- (entry) => typeof entry === 'number' && Number.isFinite(entry),
20462
- )
20463
- ) {
20464
- throw new Error(
20465
- 'Persisted Play runtime limit is invalid. Re-submit the run with the current runtime contract.',
20466
- );
20467
- }
20468
- return validatePlaySandboxRuntimeLimits({
20469
- timeoutSeconds: timeoutSeconds as number,
20470
- memoryGiB: memoryGiB as number,
20471
- cpu: cpu as number,
20472
- diskGiB: diskGiB as number,
20473
- });
20474
- }
20475
-
20476
20455
  export function buildPostgresSchedulerRunnerContext(
20477
20456
  launch: PlaySchedulerSubmitInput,
20478
20457
  runAttempt: number,
@@ -1,3 +1,7 @@
1
+ import {
2
+ readCarriedPlaySandboxRuntimeLimits,
3
+ type PlaySandboxRuntimeLimits,
4
+ } from '../sandbox-runtime-limits';
1
5
  import { createHash, timingSafeEqual } from 'node:crypto';
2
6
  import dns from 'node:dns';
3
7
  import type { IncomingMessage, ServerResponse } from 'node:http';
@@ -238,6 +242,13 @@ export type RuntimeWorkerEarlySandboxHint = {
238
242
  queue?: string;
239
243
  /** LH: set by the gateway only, the chosen listener's generation. */
240
244
  listenerGeneration?: string;
245
+ /**
246
+ * The run's validated sandbox runtime limits, the ones its launch will use,
247
+ * so the early create matches the launch's size and timeout. Absent (an
248
+ * older app or gateway): the standard profile, as before. Reader-first:
249
+ * an older worker drops it and takes the absent path.
250
+ */
251
+ sandboxRuntimeLimits?: PlaySandboxRuntimeLimits;
241
252
  };
242
253
 
243
254
  /** Longest placement policy id a hint may carry (catalog ids are ~25). */
@@ -290,6 +301,19 @@ export function parseEarlySandboxHint(
290
301
  if (!parsed) return null;
291
302
  listenerGeneration = parsed;
292
303
  }
304
+ // Present but not exactly a valid size and timeout is a malformed hint
305
+ // (refused, so the run launches without an early start).
306
+ let sandboxRuntimeLimits: PlaySandboxRuntimeLimits | undefined;
307
+ if (
308
+ value.sandboxRuntimeLimits !== undefined &&
309
+ value.sandboxRuntimeLimits !== null
310
+ ) {
311
+ const parsed = readCarriedPlaySandboxRuntimeLimits(
312
+ value.sandboxRuntimeLimits,
313
+ );
314
+ if (!parsed) return null;
315
+ sandboxRuntimeLimits = parsed;
316
+ }
293
317
  return {
294
318
  workflowId,
295
319
  orgId,
@@ -297,6 +321,7 @@ export function parseEarlySandboxHint(
297
321
  ...(sandboxPlacementPolicyId ? { sandboxPlacementPolicyId } : {}),
298
322
  ...(queue ? { queue } : {}),
299
323
  ...(listenerGeneration ? { listenerGeneration } : {}),
324
+ ...(sandboxRuntimeLimits ? { sandboxRuntimeLimits } : {}),
300
325
  };
301
326
  } catch {
302
327
  return null;
@@ -180,3 +180,86 @@ export function resolvePlaySandboxRuntimeLimits(
180
180
  ...PLAY_SANDBOX_SIZE_LIMITS[size],
181
181
  });
182
182
  }
183
+
184
+ /**
185
+ * The limits a launch runs with, read from its persisted contract snapshot
186
+ * (`contractSnapshot.runtimeLimit`). Absent: the standard profile. Present but
187
+ * malformed throws, exactly as the scheduler launch path does; start-run uses
188
+ * the same function so an early-start hint names the launch's own limits.
189
+ */
190
+ export function sandboxRuntimeLimitsFromContractSnapshot(
191
+ contractSnapshot: unknown,
192
+ ): PlaySandboxRuntimeLimits {
193
+ if (
194
+ !contractSnapshot ||
195
+ typeof contractSnapshot !== 'object' ||
196
+ Array.isArray(contractSnapshot)
197
+ ) {
198
+ return resolvePlaySandboxRuntimeLimits(null);
199
+ }
200
+ const runtimeLimit = (contractSnapshot as Record<string, unknown>)
201
+ .runtimeLimit;
202
+ if (
203
+ !runtimeLimit ||
204
+ typeof runtimeLimit !== 'object' ||
205
+ Array.isArray(runtimeLimit)
206
+ ) {
207
+ return resolvePlaySandboxRuntimeLimits(null);
208
+ }
209
+ const value = runtimeLimit as Record<string, unknown>;
210
+ const timeoutSeconds = value.timeoutSeconds;
211
+ const memoryGiB = value.memoryGiB;
212
+ const cpu = value.cpu;
213
+ const diskGiB = value.diskGiB;
214
+ if (
215
+ ![timeoutSeconds, memoryGiB, cpu, diskGiB].every(
216
+ (entry) => typeof entry === 'number' && Number.isFinite(entry),
217
+ )
218
+ ) {
219
+ throw new Error(
220
+ 'Persisted Play runtime limit is invalid. Re-submit the run with the current runtime contract.',
221
+ );
222
+ }
223
+ return validatePlaySandboxRuntimeLimits({
224
+ timeoutSeconds: timeoutSeconds as number,
225
+ memoryGiB: memoryGiB as number,
226
+ cpu: cpu as number,
227
+ diskGiB: diskGiB as number,
228
+ });
229
+ }
230
+
231
+ /**
232
+ * Carried runtime limits (an early-start hint's), validated against the
233
+ * product sizes and ceilings. Null when absent or not exactly a valid
234
+ * `PlaySandboxRuntimeLimits`, so a carrier can never ask for a size or
235
+ * timeout a Play could not declare.
236
+ */
237
+ export function readCarriedPlaySandboxRuntimeLimits(
238
+ value: unknown,
239
+ ): PlaySandboxRuntimeLimits | null {
240
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
241
+ const record = value as Record<string, unknown>;
242
+ if (
243
+ Object.keys(record).some(
244
+ (key) => !['timeoutSeconds', 'memoryGiB', 'cpu', 'diskGiB'].includes(key),
245
+ )
246
+ )
247
+ return null;
248
+ const { timeoutSeconds, memoryGiB, cpu, diskGiB } = record;
249
+ if (
250
+ ![timeoutSeconds, memoryGiB, cpu, diskGiB].every(
251
+ (entry) => typeof entry === 'number' && Number.isFinite(entry),
252
+ )
253
+ )
254
+ return null;
255
+ try {
256
+ return validatePlaySandboxRuntimeLimits({
257
+ timeoutSeconds: timeoutSeconds as number,
258
+ memoryGiB: memoryGiB as number,
259
+ cpu: cpu as number,
260
+ diskGiB: diskGiB as number,
261
+ });
262
+ } catch {
263
+ return null;
264
+ }
265
+ }