deepline 0.3.570 → 0.3.572

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 (152) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +25 -0
  3. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +1 -0
  4. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +11 -0
  5. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +17 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +2 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +28 -17
  8. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +360 -3
  9. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +274 -3
  10. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-connection-probe.ts +199 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +35 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +28 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +2 -2
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +11 -1
  15. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +67 -43
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +23 -6
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-listener-hint.ts +62 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +54 -2
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +54 -5
  20. package/dist/cli/auth-PXIVGUVZ.js +44 -0
  21. package/dist/cli/{auth-KHJKNEYN.mjs → auth-YUDM3YOC.mjs} +5 -5
  22. package/dist/cli/{billing-Q4BRUODF.js → billing-F3ZGOWKL.js} +99 -99
  23. package/dist/cli/{billing-R5AO4M3S.mjs → billing-O7WUC4TU.mjs} +8 -8
  24. package/dist/cli/{chunk-FDSQSUZF.js → chunk-3SFLY3T3.js} +5 -5
  25. package/dist/cli/{chunk-GPXLMRCB.js → chunk-43GCEVHO.js} +3 -3
  26. package/dist/cli/{chunk-YQP4ZUOJ.js → chunk-4W5EFHHY.js} +7 -7
  27. package/dist/cli/{chunk-2GTLZNSK.js → chunk-5EMYPLTW.js} +53 -53
  28. package/dist/cli/{chunk-NR7QW2E7.js → chunk-5VUD7HGD.js} +2 -2
  29. package/dist/cli/{chunk-ZZ4D74UL.mjs → chunk-6R57HEPF.mjs} +1 -1
  30. package/dist/cli/{chunk-GFGXDDJH.mjs → chunk-72WI67H4.mjs} +2 -2
  31. package/dist/cli/{chunk-J6PTH725.js → chunk-AHNJGA6Z.js} +6 -6
  32. package/dist/cli/{chunk-77HEH4RY.mjs → chunk-AJO3I3LL.mjs} +1 -1
  33. package/dist/cli/{chunk-NVYQ6WCW.mjs → chunk-BWWDU6FN.mjs} +5 -5
  34. package/dist/cli/{chunk-UWQLRBXY.mjs → chunk-CYW6PE3G.mjs} +5 -5
  35. package/dist/cli/{chunk-5OOGWYSR.mjs → chunk-EDAG7ZU4.mjs} +1 -1
  36. package/dist/cli/{chunk-WINZRS3A.mjs → chunk-EKIWY5DD.mjs} +1 -1
  37. package/dist/cli/{chunk-3YHMHV6U.mjs → chunk-EKWDSE6H.mjs} +4 -4
  38. package/dist/cli/{chunk-OWEUQCBZ.js → chunk-EL4LME5Y.js} +48 -48
  39. package/dist/cli/{chunk-UDN6EYBJ.js → chunk-FGBX2WVJ.js} +4 -4
  40. package/dist/cli/{chunk-XHFSNMEU.mjs → chunk-GX4VZL4Z.mjs} +3 -3
  41. package/dist/cli/{chunk-NWAFCOUF.js → chunk-HYCJNHZ4.js} +15 -15
  42. package/dist/cli/{chunk-I4N62RWB.mjs → chunk-I4WKB3HO.mjs} +2 -2
  43. package/dist/cli/{chunk-FABLUH75.js → chunk-ITQPBWDS.js} +3 -3
  44. package/dist/cli/{chunk-HPWP2B3D.mjs → chunk-JEI7PHET.mjs} +1 -1
  45. package/dist/cli/{chunk-2GBOHROU.mjs → chunk-JJEN7TRR.mjs} +1 -1
  46. package/dist/cli/{chunk-W26YT37U.js → chunk-K4LAEKHS.js} +41 -41
  47. package/dist/cli/{chunk-ZZ7ZH27W.js → chunk-LBNP52C4.js} +5 -5
  48. package/dist/cli/{chunk-73RTZMDV.mjs → chunk-MVQ5XGRO.mjs} +3 -3
  49. package/dist/cli/{chunk-PERYT4ZA.js → chunk-NOKSEYMS.js} +1 -1
  50. package/dist/cli/{chunk-EEUBKKJE.mjs → chunk-OUVQKSVC.mjs} +1 -1
  51. package/dist/cli/{chunk-OV6EKORX.js → chunk-PI4TKE2B.js} +26 -26
  52. package/dist/cli/{chunk-OOTXBEHG.mjs → chunk-PQ6PM4V6.mjs} +1 -1
  53. package/dist/cli/{chunk-2MXS53XJ.js → chunk-PRDCU7BY.js} +20 -20
  54. package/dist/cli/{chunk-CHHXUEVC.js → chunk-PZGK6EEB.js} +100 -100
  55. package/dist/cli/{chunk-O3ET4XR3.mjs → chunk-Q6H5RRTG.mjs} +4 -4
  56. package/dist/cli/{chunk-MVHKTZCX.mjs → chunk-QA733N7N.mjs} +1 -1
  57. package/dist/cli/{chunk-SOZ2SB43.js → chunk-QMIMGKR2.js} +9 -9
  58. package/dist/cli/{chunk-TMT3S2JR.mjs → chunk-RIA73OAZ.mjs} +2 -2
  59. package/dist/cli/{chunk-BEE5VGCL.mjs → chunk-SJI56XPM.mjs} +11 -11
  60. package/dist/cli/{chunk-TWHTVGGW.mjs → chunk-UFUXGMHL.mjs} +2 -2
  61. package/dist/cli/{chunk-JSHE4W6W.js → chunk-UKD5ZBQD.js} +5 -5
  62. package/dist/cli/{chunk-I5EZZFQL.mjs → chunk-UMP76GYQ.mjs} +3 -3
  63. package/dist/cli/{chunk-RS6KPFQX.mjs → chunk-UQWYDNGB.mjs} +5 -5
  64. package/dist/cli/{chunk-PSMYOQFI.js → chunk-UUYB6IXC.js} +13 -13
  65. package/dist/cli/{chunk-EYEPXZNS.mjs → chunk-UY6Z3XWW.mjs} +2 -2
  66. package/dist/cli/{chunk-MH3WE5O6.mjs → chunk-V2W7GX2I.mjs} +2 -2
  67. package/dist/cli/{chunk-WNUFRUNS.js → chunk-VGPHXXPI.js} +15 -15
  68. package/dist/cli/{chunk-Q4P6STRD.js → chunk-VZ4S5JRC.js} +23 -23
  69. package/dist/cli/{chunk-OPZHUL6T.js → chunk-W3HLZ24Q.js} +10 -10
  70. package/dist/cli/{chunk-J6M2AX3P.js → chunk-W3RHISD6.js} +8 -8
  71. package/dist/cli/{chunk-EJB4V77N.mjs → chunk-W742U53L.mjs} +5 -5
  72. package/dist/cli/{chunk-YXJVYY5V.mjs → chunk-X6F4XOT2.mjs} +2 -2
  73. package/dist/cli/{chunk-ZGOCDLJQ.js → chunk-XNJXRS3B.js} +2 -2
  74. package/dist/cli/{chunk-NIO2T6OC.js → chunk-XVQE6IBS.js} +2 -2
  75. package/dist/cli/{chunk-DPZAEVPO.js → chunk-YOST7EJF.js} +20 -20
  76. package/dist/cli/{concurrent-runs-help-Q26CEJ7I.mjs → concurrent-runs-help-5BKCGFGL.mjs} +6 -6
  77. package/dist/cli/concurrent-runs-help-KGELXJIQ.js +22 -0
  78. package/dist/cli/{csv-Z34I5QIU.js → csv-7ZAWND7L.js} +13 -13
  79. package/dist/cli/{csv-6LI6HLKG.mjs → csv-MO5WZZDN.mjs} +4 -4
  80. package/dist/cli/{db-NUDEYQCF.js → db-36LX7JBQ.js} +27 -27
  81. package/dist/cli/{db-K5GKIKQU.mjs → db-OYMULINA.mjs} +6 -6
  82. package/dist/cli/describe-AVGE4MH6.js +50 -0
  83. package/dist/cli/{describe-EB4KTEPT.mjs → describe-JLAERB6X.mjs} +18 -18
  84. package/dist/cli/{executions-KHOUABZ3.js → executions-AQ32J4BZ.js} +8 -8
  85. package/dist/cli/{executions-DAGHJZEI.mjs → executions-IZAB2XNC.mjs} +6 -6
  86. package/dist/cli/{feedback-XLAWTPK2.js → feedback-3IV54HOH.js} +14 -14
  87. package/dist/cli/{feedback-A57YETEA.mjs → feedback-WA6EBE5H.mjs} +6 -6
  88. package/dist/cli/{git-U3FNR34D.mjs → git-OSLU6HIK.mjs} +5 -5
  89. package/dist/cli/git-VOFO6V5W.js +26 -0
  90. package/dist/cli/index.js +143 -143
  91. package/dist/cli/index.mjs +45 -45
  92. package/dist/cli/{integrations-YVOJ5D6W.js → integrations-65SYNL53.js} +29 -29
  93. package/dist/cli/{integrations-LXUMB4RY.mjs → integrations-WOXFOC4M.mjs} +7 -7
  94. package/dist/cli/{legacy-noops-IZVLGQZJ.js → legacy-noops-3SGXDAV6.js} +9 -9
  95. package/dist/cli/{legacy-noops-4Z2RBTHW.mjs → legacy-noops-4FNG2JY3.mjs} +6 -6
  96. package/dist/cli/{mcp-GRGI3KYH.js → mcp-PX27RHCY.js} +24 -24
  97. package/dist/cli/{mcp-ZHXRVV7D.mjs → mcp-RZLWMZHH.mjs} +4 -4
  98. package/dist/cli/{monitors-XFN5D6EW.js → monitors-F5BLGS4R.js} +100 -100
  99. package/dist/cli/{monitors-7ZVYJ3CX.mjs → monitors-VK2LW7VU.mjs} +7 -7
  100. package/dist/cli/{org-YY5JTKNV.mjs → org-7AEBTN6Y.mjs} +6 -6
  101. package/dist/cli/{org-RWWXN5TK.js → org-UU3V7U4K.js} +121 -121
  102. package/dist/cli/{outcomes-MGWUZNQ6.mjs → outcomes-BWERSUJL.mjs} +6 -6
  103. package/dist/cli/{outcomes-AOZVYNJT.js → outcomes-GCTBGPMK.js} +14 -14
  104. package/dist/cli/{play-S34KIOWS.js → play-7NBCCL26.js} +324 -324
  105. package/dist/cli/{play-AJR7BT3R.mjs → play-TX3RAAYS.mjs} +19 -19
  106. package/dist/cli/{providers-S4WMWHBW.js → providers-IL2IVKHB.js} +9 -9
  107. package/dist/cli/{providers-QRWQGVIC.mjs → providers-KFWZXDCV.mjs} +6 -6
  108. package/dist/cli/{quickstart-GET2M3BQ.js → quickstart-MPA6TUK5.js} +6 -6
  109. package/dist/cli/{quickstart-NLAIOXVY.mjs → quickstart-RAMDGRRI.mjs} +4 -4
  110. package/dist/cli/{run-R2RYHNVS.mjs → run-QNJSKPBN.mjs} +23 -23
  111. package/dist/cli/{run-BOHHBZSI.js → run-WBUSXBUS.js} +44 -44
  112. package/dist/cli/{search-VBIVRRRO.mjs → search-2X4P2FXR.mjs} +7 -7
  113. package/dist/cli/search-CJHG3VA4.js +32 -0
  114. package/dist/cli/{search-output-OCYIQFV6.mjs → search-output-MNJ4AQLV.mjs} +4 -4
  115. package/dist/cli/{search-output-EVNRKEGZ.js → search-output-P2WNCHA3.js} +6 -6
  116. package/dist/cli/{secrets-52T2SCZ5.js → secrets-K5CNDUVR.js} +15 -15
  117. package/dist/cli/{secrets-TNCO45WJ.mjs → secrets-XX54OU22.mjs} +6 -6
  118. package/dist/cli/sessions-3RMRBBJZ.js +23 -0
  119. package/dist/cli/{sessions-4XE7AR3A.mjs → sessions-C4GQ6ZVO.mjs} +6 -6
  120. package/dist/cli/{settings-ZFCHR7MW.mjs → settings-7HBTADGW.mjs} +12 -12
  121. package/dist/cli/{settings-TKRF2B3K.js → settings-QP3DVFPS.js} +85 -85
  122. package/dist/cli/{setup-QY3ZML4C.mjs → setup-VPDAKY2G.mjs} +9 -9
  123. package/dist/cli/{setup-AWNE4VNL.js → setup-X6J7U6B4.js} +49 -49
  124. package/dist/cli/skills-JUGXGSX2.js +37 -0
  125. package/dist/cli/{skills-GUGJDCFY.mjs → skills-UGY6W4AC.mjs} +7 -7
  126. package/dist/cli/{tools-NBKPWOWD.mjs → tools-SVBUAHDD.mjs} +17 -17
  127. package/dist/cli/tools-ZEI42NSP.js +57 -0
  128. package/dist/cli/{update-KLGVIBRY.mjs → update-SDNKNDNW.mjs} +9 -9
  129. package/dist/cli/update-VC4UEGMR.js +37 -0
  130. package/dist/cli/{views-MDXEIVQ7.js → views-JBFSHQBU.js} +21 -21
  131. package/dist/cli/{views-OEOW2EZO.mjs → views-M6RBPC65.mjs} +6 -6
  132. package/dist/cli/{workflow-LK4SIUOM.mjs → workflow-RYVRAIHV.mjs} +7 -7
  133. package/dist/cli/{workflow-PUSTWPW4.js → workflow-UAMTGHQC.js} +17 -17
  134. package/dist/index.js +9 -9
  135. package/dist/index.mjs +6 -6
  136. package/dist/install-integrity.json +113 -112
  137. package/dist/release.d.mts +1 -1
  138. package/dist/release.d.ts +1 -1
  139. package/dist/release.js +2 -2
  140. package/dist/release.mjs +1 -1
  141. package/dist/server.js +5 -5
  142. package/dist/server.mjs +3 -3
  143. package/package.json +1 -1
  144. package/dist/cli/auth-X2LWGPF4.js +0 -44
  145. package/dist/cli/concurrent-runs-help-QDURIV4N.js +0 -22
  146. package/dist/cli/describe-BY7LKP53.js +0 -50
  147. package/dist/cli/git-CR6PBWBH.js +0 -26
  148. package/dist/cli/search-CZVM2OX5.js +0 -32
  149. package/dist/cli/sessions-GOHYDYMH.js +0 -23
  150. package/dist/cli/skills-54CGCMPF.js +0 -37
  151. package/dist/cli/tools-A7FEGDPX.js +0 -57
  152. package/dist/cli/update-3J52CJHB.js +0 -37
@@ -68,31 +68,36 @@ export type ClaimAffinityDueRun = {
68
68
  };
69
69
 
70
70
  /**
71
- * Whether this worker should skip its next claim, and for how long. Yields
72
- * only when every due run is a first attempt recorded for ANOTHER owner whose
73
- * window is still open, and nothing else is due (expired claims, due sleeps
74
- * and due cancellations are claim_task work too). Anything else claims now.
71
+ * How much of its next claim this worker may take. `claim_task` takes due
72
+ * runs in order, so a worker may only take the leading due runs that are not
73
+ * another owner's first attempt inside its open window: it claims that
74
+ * prefix (`limit`), and when the head itself is such a run it yields until
75
+ * that window closes (`yieldMs`). A run's window is at most
76
+ * `EARLY_SANDBOX_CLAIM_AFFINITY_WINDOW_MS` from its enqueue, so a lost owner
77
+ * delays it, and any run queued behind it, by at most the window; then anyone
78
+ * claims it. Other due claim_task work (expired claims, due sleeps, due
79
+ * cancellations) always claims as requested.
75
80
  */
76
- export function decideEarlySandboxClaimYield(input: {
81
+ export function decideEarlySandboxClaimLimit(input: {
77
82
  self: string;
83
+ /** The first due pending runs, in claim order. */
78
84
  dueRuns: readonly ClaimAffinityDueRun[];
79
85
  otherDueWork: boolean;
80
- }): number | null {
86
+ }): { limit: number } | { yieldMs: number } | null {
81
87
  if (input.otherDueWork || input.dueRuns.length === 0) return null;
82
- let yieldMs = Number.POSITIVE_INFINITY;
83
- for (const run of input.dueRuns) {
88
+ const heldForAnother = (run: ClaimAffinityDueRun) => {
84
89
  const owner = parseEarlySandboxClaimOwner(run.owner);
85
- if (
86
- !owner ||
87
- owner === input.self ||
88
- run.attempt !== 1 ||
89
- !(run.remainingMs > 0)
90
- ) {
91
- return null;
92
- }
93
- yieldMs = Math.min(yieldMs, run.remainingMs);
94
- }
95
- return Number.isFinite(yieldMs) ? Math.ceil(yieldMs) : null;
90
+ return (
91
+ owner !== null &&
92
+ owner !== input.self &&
93
+ run.attempt === 1 &&
94
+ run.remainingMs > 0
95
+ );
96
+ };
97
+ const prefix = input.dueRuns.findIndex(heldForAnother);
98
+ if (prefix === -1) return null;
99
+ if (prefix > 0) return { limit: prefix };
100
+ return { yieldMs: Math.ceil(input.dueRuns[0]!.remainingMs) };
96
101
  }
97
102
 
98
103
  /**
@@ -168,17 +173,22 @@ export async function readEarlySandboxClaimAffinity(input: {
168
173
  /** The vendored engine's claim statement (`Absurd.claimTasks`). */
169
174
  const ABSURD_CLAIM_TASK_SQL = 'absurd.claim_task(';
170
175
 
176
+ /**
177
+ * The most runs this claim may take: null takes the requested batch as
178
+ * today, 0 skips this claim, and a smaller count claims only that many.
179
+ */
171
180
  export type EarlySandboxClaimGate = (
172
181
  client: RuntimeSchedulerQueryClient,
173
182
  claimParams: readonly unknown[],
174
- ) => Promise<boolean>;
183
+ ) => Promise<number | null>;
175
184
 
176
185
  /**
177
186
  * The claim gate the worker's scheduler queryable runs on the claim's own
178
- * pooled client, before `claim_task`. It returns false (skip this claim) only
179
- * while another owner's window is open, and then wakes the engine when that
180
- * window closes, so the run is claimed by someone within the window plus one
181
- * wake. A failed read claims as today.
187
+ * pooled client, before `claim_task`. It narrows the claim to the leading due
188
+ * runs no other owner holds, or skips it while another owner's window holds
189
+ * the head run, and then wakes the engine when that window closes, so the run
190
+ * is claimed by someone within the window plus one wake. A failed read claims
191
+ * as today.
182
192
  */
183
193
  export function createEarlySandboxClaimGate(input: {
184
194
  self: string;
@@ -201,7 +211,7 @@ export function createEarlySandboxClaimGate(input: {
201
211
  return async (client, claimParams) => {
202
212
  const startedAt = performance.now();
203
213
  const limit = Number(claimParams[3] ?? 1);
204
- let decision: number | null;
214
+ let decision: ReturnType<typeof decideEarlySandboxClaimLimit>;
205
215
  try {
206
216
  const read = await readEarlySandboxClaimAffinity({
207
217
  client,
@@ -209,7 +219,7 @@ export function createEarlySandboxClaimGate(input: {
209
219
  limit: Number.isFinite(limit) && limit > 0 ? limit : 1,
210
220
  windowMs,
211
221
  });
212
- decision = decideEarlySandboxClaimYield({
222
+ decision = decideEarlySandboxClaimLimit({
213
223
  self: input.self,
214
224
  dueRuns: read.dueRuns,
215
225
  otherDueWork: read.otherDueWork,
@@ -219,50 +229,64 @@ export function createEarlySandboxClaimGate(input: {
219
229
  event: 'gate_failed',
220
230
  error: error instanceof Error ? error.message : String(error),
221
231
  });
222
- return true;
232
+ return null;
223
233
  }
224
234
  const gateMs = Math.round(performance.now() - startedAt);
225
235
  if (decision === null) {
226
236
  log('[runtime.claim_affinity]', { event: 'gate_claim', gateMs });
227
- return true;
237
+ return null;
238
+ }
239
+ if ('limit' in decision) {
240
+ log('[runtime.claim_affinity]', {
241
+ event: 'gate_claim_prefix',
242
+ limit: decision.limit,
243
+ gateMs,
244
+ });
245
+ return decision.limit;
228
246
  }
229
247
  // One timer per open window: a later yield inside it reuses the wake.
230
- const due = Date.now() + decision + 1;
248
+ const due = Date.now() + decision.yieldMs + 1;
231
249
  if (wakeAt === null || wakeAt <= Date.now() || due < wakeAt) {
232
250
  wakeAt = due;
233
251
  setTimer(() => {
234
252
  wakeAt = null;
235
253
  input.wake();
236
- }, decision + 1);
254
+ }, decision.yieldMs + 1);
237
255
  }
238
256
  log('[runtime.claim_affinity]', {
239
257
  event: 'gate_yield',
240
- yieldMs: decision,
258
+ yieldMs: decision.yieldMs,
241
259
  gateMs,
242
260
  });
243
- return false;
261
+ return 0;
244
262
  };
245
263
  }
246
264
 
247
265
  /**
248
- * Run `claim` unless `gate` says to yield; a yielded claim returns no rows,
249
- * exactly like a claim that found nothing. Non-claim statements pass through.
266
+ * Run the claim as `gate` allows: as requested, narrowed to a smaller batch
267
+ * (the claim's fourth parameter is its count), or skipped, which returns no
268
+ * rows exactly like a claim that found nothing. Non-claim statements pass
269
+ * through.
250
270
  */
251
271
  export async function runGatedAbsurdClaimQuery<Row>(input: {
252
272
  sql: string;
253
273
  params: readonly unknown[] | undefined;
254
274
  client: RuntimeSchedulerQueryClient;
255
275
  gate: EarlySandboxClaimGate | undefined;
256
- run: () => Promise<{ rows: Row[] }>;
276
+ run: (params: readonly unknown[] | undefined) => Promise<{ rows: Row[] }>;
257
277
  }): Promise<{ rows: Row[] }> {
258
- if (
259
- input.gate &&
260
- input.sql.includes(ABSURD_CLAIM_TASK_SQL) &&
261
- !(await input.gate(input.client, input.params ?? []))
262
- ) {
263
- return { rows: [] };
264
- }
265
- return input.run();
278
+ if (!input.gate || !input.sql.includes(ABSURD_CLAIM_TASK_SQL))
279
+ return input.run(input.params);
280
+ const params = input.params ?? [];
281
+ const limit = await input.gate(input.client, params);
282
+ if (limit === null) return input.run(input.params);
283
+ if (limit < 1) return { rows: [] };
284
+ const requested = Number(params[3]);
285
+ if (!Number.isFinite(requested) || limit >= requested)
286
+ return input.run(input.params);
287
+ const narrowed = [...params];
288
+ narrowed[3] = limit;
289
+ return input.run(narrowed);
266
290
  }
267
291
 
268
292
  /**
@@ -424,12 +424,29 @@ export function startWorkerLaneEarlySandbox(
424
424
  workflowId: input.workflowId,
425
425
  ...adapter.scope(request),
426
426
  });
427
- const refusal = desk.admit({
428
- key,
429
- workflowId: input.workflowId,
430
- queue: input.listenerHint?.queue ?? '',
431
- listenerGeneration: input.listenerHint?.listenerGeneration ?? '',
432
- });
427
+ // CA spread: the gateway chose this worker for its free capacity and named
428
+ // no generation; the run's claim follows its recorded owner (this worker),
429
+ // so the desk binds the hint to the queue and one free slot only. Without
430
+ // CA a hint must still name this worker's current listener generation.
431
+ const claimOwnerHint =
432
+ !input.listenerHint?.listenerGeneration &&
433
+ resolveExperimentSwitch(
434
+ 'CA',
435
+ input.experimentSwitchOverrides,
436
+ CLAIM_AFFINITY_FOR_EARLY_SANDBOX,
437
+ );
438
+ const refusal = claimOwnerHint
439
+ ? desk.admitClaimOwner({
440
+ key,
441
+ workflowId: input.workflowId,
442
+ queue: input.listenerHint?.queue ?? '',
443
+ })
444
+ : desk.admit({
445
+ key,
446
+ workflowId: input.workflowId,
447
+ queue: input.listenerHint?.queue ?? '',
448
+ listenerGeneration: input.listenerHint?.listenerGeneration ?? '',
449
+ });
433
450
  if (refusal) {
434
451
  return refuseEarlySandboxHint({ ...hint, reason: `listener_${refusal}` });
435
452
  }
@@ -48,6 +48,9 @@ export const EARLY_SANDBOX_LISTENER_HINT = false;
48
48
  */
49
49
  export const EARLY_SANDBOX_LISTENER_RESERVATION_MS = 10_000;
50
50
 
51
+ /** The generation recorded on a CA spread reservation (never a real one). */
52
+ const CLAIM_OWNER_RESERVATION = 'claim-owner';
53
+
51
54
  /** A worker's hold on its queue's listener election. */
52
55
  export type EarlySandboxListenerLeadership = {
53
56
  /** The release queue this worker claims from. */
@@ -131,6 +134,17 @@ export type EarlySandboxListenerHintDesk = {
131
134
  queue: string;
132
135
  listenerGeneration: string;
133
136
  }): EarlySandboxListenerHintRefusal | null;
137
+ /**
138
+ * CA spread: a hint the gateway sent to this worker for its free capacity,
139
+ * not its leadership. Bound to the queue and one free slot only; the run's
140
+ * claim reaches this worker through its recorded claim owner (CA), so a
141
+ * reservation is not tied to a listener generation and survives handover.
142
+ */
143
+ admitClaimOwner(hint: {
144
+ key: string;
145
+ workflowId: string;
146
+ queue: string;
147
+ }): EarlySandboxListenerHintRefusal | null;
134
148
  /** The launch took the run's sandbox here: release, keep the sandbox. */
135
149
  adopted(key: string): void;
136
150
  /**
@@ -231,6 +245,26 @@ export function createEarlySandboxListenerHintDesk(input: {
231
245
  held.set(hint.key, { reservation, timer });
232
246
  return null;
233
247
  },
248
+ admitClaimOwner: (hint) => {
249
+ if (hint.queue !== input.leadership.queue) return 'foreign_queue';
250
+ if (input.capacity.draining) return 'worker_draining';
251
+ if (held.has(hint.key)) return 'duplicate_hint';
252
+ if (unreservedSlots() < 1) return 'no_idle_slot';
253
+ // No generation: a leadership loss never drops this reservation.
254
+ const reservation = {
255
+ key: hint.key,
256
+ workflowId: hint.workflowId,
257
+ generation: CLAIM_OWNER_RESERVATION,
258
+ acceptedAtMs: now(),
259
+ };
260
+ const timer = setTimer(() => {
261
+ if (held.get(hint.key)?.reservation !== reservation) return;
262
+ drop(hint.key);
263
+ input.onUnadopted?.(reservation, 'expired');
264
+ }, reservationMs);
265
+ held.set(hint.key, { reservation, timer });
266
+ return null;
267
+ },
234
268
  adopted: (key) => {
235
269
  drop(key);
236
270
  },
@@ -253,6 +287,34 @@ export function createEarlySandboxListenerHintDesk(input: {
253
287
  };
254
288
  }
255
289
 
290
+ /**
291
+ * CA spread: the gateway's choice by free capacity. Among the workers for the
292
+ * run's queue that are not draining and have an unreserved slot, the one with
293
+ * the most unreserved slots (ties broken by `pick`). None: null, and the
294
+ * caller falls back to the listener choice.
295
+ */
296
+ export function selectEarlySandboxClaimOwnerTarget(input: {
297
+ queue: string;
298
+ statuses: readonly (EarlySandboxListenerStatus | null)[];
299
+ /** Chooses among equally free candidates; random by default. */
300
+ pick?: (count: number) => number;
301
+ }): number | null {
302
+ const candidates = input.statuses.flatMap((status, index) =>
303
+ status &&
304
+ status.queue === input.queue &&
305
+ !status.draining &&
306
+ status.unreservedSlots >= 1
307
+ ? [{ index, slots: status.unreservedSlots }]
308
+ : [],
309
+ );
310
+ if (candidates.length === 0) return null;
311
+ const most = Math.max(...candidates.map((candidate) => candidate.slots));
312
+ const top = candidates.filter((candidate) => candidate.slots === most);
313
+ const pick = input.pick ?? ((count) => Math.floor(Math.random() * count));
314
+ const chosen = top[Math.min(top.length - 1, Math.max(0, pick(top.length)))];
315
+ return chosen!.index;
316
+ }
317
+
256
318
  export type EarlySandboxListenerSelection =
257
319
  | { target: number; generation: string }
258
320
  | { refused: 'no_listener' | 'ambiguous_listeners' | 'listener_busy' };
@@ -12924,7 +12924,11 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
12924
12924
  input.resource.daytonaEnvironment ??
12925
12925
  'production';
12926
12926
  const operationStates = runtimeSandboxOperationFromStatesCast(options);
12927
- const recorded = await client.query<{ operation_key: string }>(
12927
+ // Another operation already bound this sandbox (UNIQUE provider,
12928
+ // sandbox_id, routing domain): this attempt lost the sandbox to it. That is
12929
+ // a fence loss, never success (PX: two launches adopted one early sandbox).
12930
+ const recorded = await client
12931
+ .query<{ operation_key: string }>(
12928
12932
  `
12929
12933
  WITH ${runtimeSandboxCustodyLocksSql('run.run_id = $1', options)}, eligible_attempt AS (
12930
12934
  SELECT run_id
@@ -13005,7 +13009,12 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
13005
13009
  provider,
13006
13010
  runtimeSandboxOperationFromStates('bind_live'),
13007
13011
  ],
13008
- );
13012
+ )
13013
+ .catch((error: unknown) => {
13014
+ if ((error as { code?: unknown } | null)?.code === '23505')
13015
+ return { rows: [] as { operation_key: string }[] };
13016
+ throw error;
13017
+ });
13009
13018
  if (recorded.rows.length === 1) return true;
13010
13019
  // Daytona reports the end of a retired sandbox's billing interval before
13011
13020
  // retrying acquisition. That is an update to the same live resource, not a
@@ -20314,6 +20323,49 @@ export async function executePostgresSchedulerClaim(
20314
20323
  terminalFailureResult,
20315
20324
  options.terminalLogOutbox,
20316
20325
  );
20326
+ // A stop committed before this failure is the run's real outcome: the
20327
+ // cancellation's own sandbox termination is what usually fails a launch
20328
+ // ("Modal Sandbox is shutting down"). Settle it through the owner's
20329
+ // cancellation transition instead of recording a failure; the queued
20330
+ // request's reconciler then finds the run terminal and retires it. The
20331
+ // typed-wait failure path keeps its own guard for this case, and a
20332
+ // preserved runner terminal (detached recovery) is never overridden: a
20333
+ // runner that already pushed its own terminal keeps it.
20334
+ if (
20335
+ !options.protectWaitingSuspensionFailure &&
20336
+ !options.preserveRunnerTerminal
20337
+ ) {
20338
+ const requestedCancellation = await client.query<{
20339
+ reason: string | null;
20340
+ }>(
20341
+ `SELECT value->>'reason' AS reason
20342
+ FROM ${tableName('control', options)}
20343
+ WHERE key = 'runtime_cancel:' || $1`,
20344
+ [claim.runId],
20345
+ );
20346
+ const cancellation = requestedCancellation.rows[0];
20347
+ if (
20348
+ cancellation &&
20349
+ (await cancelPostgresSchedulerRun(
20350
+ client,
20351
+ {
20352
+ runId: claim.runId,
20353
+ reason: cancellation.reason?.trim() || 'Cancelled play run.',
20354
+ },
20355
+ options,
20356
+ ))
20357
+ ) {
20358
+ console.info(
20359
+ '[postgres-scheduler] failure_superseded_by_cancellation',
20360
+ {
20361
+ runId: claim.runId,
20362
+ attempt: claim.attempt,
20363
+ error: message.slice(0, 500),
20364
+ },
20365
+ );
20366
+ return { status: 'idle' };
20367
+ }
20368
+ }
20317
20369
  const failed = await failPostgresSchedulerAttempt(
20318
20370
  client,
20319
20371
  {
@@ -6,12 +6,16 @@ import {
6
6
  resolveExperimentSwitch,
7
7
  type ExperimentSwitchOverrides,
8
8
  } from '../experiment-switches';
9
- import { parseEarlySandboxClaimOwner } from './early-sandbox-claim-affinity';
9
+ import {
10
+ CLAIM_AFFINITY_FOR_EARLY_SANDBOX,
11
+ parseEarlySandboxClaimOwner,
12
+ } from './early-sandbox-claim-affinity';
10
13
  import {
11
14
  EARLY_SANDBOX_LISTENER_HINT,
12
15
  parseEarlySandboxListenerGeneration,
13
16
  parseEarlySandboxListenerQueue,
14
17
  parseEarlySandboxListenerStatus,
18
+ selectEarlySandboxClaimOwnerTarget,
15
19
  selectEarlySandboxListener,
16
20
  type EarlySandboxListenerStatus,
17
21
  } from './early-sandbox-listener-hint';
@@ -550,10 +554,20 @@ export async function findEarlySandboxListener(input: {
550
554
  signal?: AbortSignal;
551
555
  /** Close each connection after its read (the path warmer: no pooled socket). */
552
556
  closeConnections?: boolean;
557
+ /**
558
+ * CA spread: choose the worker with the most free capacity for the queue
559
+ * (its claim follows through the recorded claim owner); with none, fall
560
+ * back to the listener choice.
561
+ */
562
+ claimOwner?: boolean;
563
+ /** Test seam for the spread tie-break. */
564
+ pick?: (count: number) => number;
553
565
  }): Promise<
554
566
  | {
555
567
  target: URL;
556
- generation: string;
568
+ /** The listener's generation, or null for a CA spread target. */
569
+ generation: string | null;
570
+ mode: 'listener' | 'claim_owner';
557
571
  asked: number;
558
572
  outcomes: EarlySandboxListenerStatusOutcomes;
559
573
  }
@@ -666,6 +680,24 @@ export async function findEarlySandboxListener(input: {
666
680
  }
667
681
  }),
668
682
  );
683
+ if (input.claimOwner) {
684
+ const spread = selectEarlySandboxClaimOwnerTarget({
685
+ queue: input.queue,
686
+ statuses,
687
+ ...(input.pick ? { pick: input.pick } : {}),
688
+ });
689
+ if (spread !== null) {
690
+ const target = new URL(targets[spread]!);
691
+ target.pathname = RUNTIME_WORKER_EARLY_SANDBOX_PATH;
692
+ return {
693
+ target,
694
+ generation: null,
695
+ mode: 'claim_owner',
696
+ asked: targets.length,
697
+ outcomes,
698
+ };
699
+ }
700
+ }
669
701
  const selection = selectEarlySandboxListener({
670
702
  queue: input.queue,
671
703
  statuses,
@@ -677,6 +709,7 @@ export async function findEarlySandboxListener(input: {
677
709
  return {
678
710
  target,
679
711
  generation: selection.generation,
712
+ mode: 'listener',
680
713
  asked: targets.length,
681
714
  outcomes,
682
715
  };
@@ -778,10 +811,19 @@ export async function handleRuntimeGatewayEarlySandbox(
778
811
  return respond(503, '{"ok":false,"refused":"no_queue"}');
779
812
  }
780
813
  const lhStartedAt = performance.now();
814
+ // CA spread: with CA the run's claim follows its recorded owner, so the
815
+ // hint goes to the worker with the most free capacity, not only the
816
+ // listener; Production keeps CA off until a profile turns it on.
817
+ const claimOwner = resolveExperimentSwitch(
818
+ 'CA',
819
+ hint.experimentSwitchOverrides,
820
+ CLAIM_AFFINITY_FOR_EARLY_SANDBOX,
821
+ );
781
822
  const found = await (input.findListener ?? findEarlySandboxListener)({
782
823
  url: workerUrl.toString(),
783
824
  token: input.target.token,
784
825
  queue: hint.queue,
826
+ ...(claimOwner ? { claimOwner: true } : {}),
785
827
  });
786
828
  if ('refused' in found) {
787
829
  decided({
@@ -807,10 +849,12 @@ export async function handleRuntimeGatewayEarlySandbox(
807
849
  (performance.now() - lhStartedAt),
808
850
  ),
809
851
  );
810
- const { status } = await requestRuntimeWorkerEarlySandboxWithOwner(
852
+ const { status, owner } = await requestRuntimeWorkerEarlySandboxWithOwner(
811
853
  found.target.toString(),
812
854
  input.target.token,
813
- { ...hint, listenerGeneration: found.generation },
855
+ found.generation === null
856
+ ? hint
857
+ : { ...hint, listenerGeneration: found.generation },
814
858
  relayBudgetMs,
815
859
  );
816
860
  // A refusing worker (handover since the status read, slot taken) means
@@ -819,7 +863,9 @@ export async function handleRuntimeGatewayEarlySandbox(
819
863
  status === 202
820
864
  ? {
821
865
  event: 'accepted',
866
+ mode: found.mode,
822
867
  generation: found.generation,
868
+ ...(owner ? { owner } : {}),
823
869
  asked: found.asked,
824
870
  lookupMs: found.outcomes.lookupMs,
825
871
  slowestReadMs: found.outcomes.slowestReadMs,
@@ -831,10 +877,13 @@ export async function handleRuntimeGatewayEarlySandbox(
831
877
  asked: found.asked,
832
878
  },
833
879
  );
880
+ // CA needs the owner in the reply to record it on the run's task.
834
881
  return respond(
835
882
  status ?? 503,
836
883
  status === 202
837
- ? '{"ok":true}'
884
+ ? owner
885
+ ? JSON.stringify({ ok: true, owner })
886
+ : '{"ok":true}'
838
887
  : JSON.stringify({ ok: false, refused: 'listener_refused' }),
839
888
  );
840
889
  }
@@ -0,0 +1,44 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ var _chunk5EMYPLTWjs = require('./chunk-5EMYPLTW.js');
18
+ require('./chunk-PRDCU7BY.js');
19
+ require('./chunk-ITQPBWDS.js');
20
+ require('./chunk-FGBX2WVJ.js');
21
+ require('./chunk-6VLFQZK6.js');
22
+ require('./chunk-XNYIZMNQ.js');
23
+ require('./chunk-LFQJW4S2.js');
24
+ require('./chunk-CFJFUVX2.js');
25
+ require('./chunk-NOKSEYMS.js');
26
+ require('./chunk-OG64RBAC.js');
27
+ require('./chunk-COGTRVWW.js');
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ exports.EXIT_WORKSPACE_MISMATCH = _chunk5EMYPLTWjs.EXIT_WORKSPACE_MISMATCH; exports.authStatusLine = _chunk5EMYPLTWjs.authStatusLine; exports.clearPendingClaim = _chunk5EMYPLTWjs.clearPendingClaim; exports.clearSatisfiedPendingClaim = _chunk5EMYPLTWjs.clearSatisfiedPendingClaim; exports.handleRegister = _chunk5EMYPLTWjs.handleRegister; exports.handleStatus = _chunk5EMYPLTWjs.handleStatus; exports.handleWait = _chunk5EMYPLTWjs.handleWait; exports.httpJson = _chunk5EMYPLTWjs.httpJson; exports.readPendingAuthClaim = _chunk5EMYPLTWjs.readPendingAuthClaim; exports.readStatusBanner = _chunk5EMYPLTWjs.readStatusBanner; exports.registerAuthCommands = _chunk5EMYPLTWjs.registerAuthCommands; exports.reportApprovalLinkShown = _chunk5EMYPLTWjs.reportApprovalLinkShown; exports.reportSetupCompleted = _chunk5EMYPLTWjs.reportSetupCompleted; exports.resolvePendingAuthClaimForResume = _chunk5EMYPLTWjs.resolvePendingAuthClaimForResume; exports.statusBannerLine = _chunk5EMYPLTWjs.statusBannerLine;
@@ -14,15 +14,15 @@ import {
14
14
  reportSetupCompleted,
15
15
  resolvePendingAuthClaimForResume,
16
16
  statusBannerLine
17
- } from "./chunk-I5EZZFQL.mjs";
18
- import "./chunk-I4N62RWB.mjs";
19
- import "./chunk-77HEH4RY.mjs";
20
- import "./chunk-HPWP2B3D.mjs";
17
+ } from "./chunk-UMP76GYQ.mjs";
18
+ import "./chunk-I4WKB3HO.mjs";
19
+ import "./chunk-AJO3I3LL.mjs";
20
+ import "./chunk-JEI7PHET.mjs";
21
21
  import "./chunk-ASB47RXJ.mjs";
22
22
  import "./chunk-DLIRSHV6.mjs";
23
23
  import "./chunk-Z3A2S3QM.mjs";
24
24
  import "./chunk-2MGZAI54.mjs";
25
- import "./chunk-5OOGWYSR.mjs";
25
+ import "./chunk-EDAG7ZU4.mjs";
26
26
  import "./chunk-WZYKRD7T.mjs";
27
27
  import "./chunk-KRD6H754.mjs";
28
28
  export {