deepline 0.3.528 → 0.3.530

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 (132) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +60 -0
  3. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +22 -1
  4. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +3 -2
  5. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +123 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +302 -48
  7. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +29 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +43 -16
  9. package/dist/cli/{auth-PPOTNK4T.mjs → auth-LRWNDQFT.mjs} +5 -5
  10. package/dist/cli/auth-QFIXECQV.js +43 -0
  11. package/dist/cli/{billing-3C7T7CUQ.js → billing-5FDPWGCG.js} +79 -79
  12. package/dist/cli/{billing-OEZUQ2K6.mjs → billing-7T73MRYF.mjs} +6 -6
  13. package/dist/cli/{chunk-4SBUXDKZ.js → chunk-2FLODRM2.js} +13 -13
  14. package/dist/cli/{chunk-AFIAVG5T.mjs → chunk-2FLRKNME.mjs} +2 -2
  15. package/dist/cli/{chunk-B6YWCGVC.mjs → chunk-2LKVNWRA.mjs} +10 -10
  16. package/dist/cli/{chunk-7WZXUAQW.js → chunk-32NTC5UD.js} +7 -7
  17. package/dist/cli/{chunk-KLGYBOGZ.mjs → chunk-3MAHDV5C.mjs} +1 -1
  18. package/dist/cli/{chunk-IYCRX34W.mjs → chunk-4VQ63Y6S.mjs} +5 -5
  19. package/dist/cli/{chunk-WXHBD6H7.js → chunk-4WPIORJX.js} +1 -1
  20. package/dist/cli/{chunk-IJAEYEJM.js → chunk-5B37ER3C.js} +3 -3
  21. package/dist/cli/{chunk-IM5XQ4DG.mjs → chunk-5DJUNUHN.mjs} +5 -5
  22. package/dist/cli/{chunk-GFGFAAY2.mjs → chunk-5KX3TWBK.mjs} +1 -1
  23. package/dist/cli/{chunk-FPHAUP55.mjs → chunk-6NG3FRJB.mjs} +5 -5
  24. package/dist/cli/{chunk-FXYWEKUK.js → chunk-7E7CP5KA.js} +4 -4
  25. package/dist/cli/{chunk-RFTBMEWL.js → chunk-7WGMCOM6.js} +2 -2
  26. package/dist/cli/{chunk-GP7E4TE4.mjs → chunk-A5MYJM4K.mjs} +2 -2
  27. package/dist/cli/{chunk-T4QPRL3P.mjs → chunk-BVY4QRVT.mjs} +3 -3
  28. package/dist/cli/{chunk-R5ZQVQ3K.js → chunk-C44RZGM5.js} +26 -26
  29. package/dist/cli/{chunk-G7RTPKRJ.js → chunk-D7Y7I4EE.js} +2 -2
  30. package/dist/cli/{chunk-36UD7H7Y.js → chunk-E6L3NEFV.js} +41 -41
  31. package/dist/cli/{chunk-XD2DRBPH.js → chunk-EADHDZW2.js} +6 -6
  32. package/dist/cli/{chunk-Z25KC5V2.mjs → chunk-ERMDXXP5.mjs} +1 -1
  33. package/dist/cli/{chunk-MLNH4DK2.js → chunk-GW76IDID.js} +22 -22
  34. package/dist/cli/{chunk-Z44S7VWO.mjs → chunk-HCWPX2UP.mjs} +2 -2
  35. package/dist/cli/{chunk-6OLQWQU5.mjs → chunk-I2YXEHDO.mjs} +3 -3
  36. package/dist/cli/{chunk-HJVNCRXY.mjs → chunk-J6XSBTEX.mjs} +1 -1
  37. package/dist/cli/{chunk-DCVNL5XN.mjs → chunk-K4Y6CNFV.mjs} +1 -1
  38. package/dist/cli/{chunk-GCBFSFLA.js → chunk-KEXGBXUG.js} +5 -5
  39. package/dist/cli/{chunk-CMTY6SVY.mjs → chunk-KI63L5H3.mjs} +2 -2
  40. package/dist/cli/{chunk-5MJ4CDAQ.js → chunk-KUHH7RW4.js} +44 -44
  41. package/dist/cli/{chunk-237PKFIQ.js → chunk-L4QR7CYL.js} +14 -14
  42. package/dist/cli/{chunk-RC5CG5SE.mjs → chunk-LNZILMVK.mjs} +4 -4
  43. package/dist/cli/{chunk-LU4EA3ET.js → chunk-M4Q4LEMM.js} +2 -2
  44. package/dist/cli/{chunk-ZFD5FJCZ.js → chunk-MHR3XVJD.js} +5 -5
  45. package/dist/cli/{chunk-RML3VSTN.mjs → chunk-MVF7ZBJX.mjs} +1 -1
  46. package/dist/cli/{chunk-OEI7YUEF.js → chunk-MVFKZQ7E.js} +3 -3
  47. package/dist/cli/{chunk-PS2UYVAE.mjs → chunk-OUM2V7R6.mjs} +6 -6
  48. package/dist/cli/{chunk-NCOTOGTK.mjs → chunk-QI2LKPW5.mjs} +2 -2
  49. package/dist/cli/{chunk-ULUI2FEM.mjs → chunk-QQ4LNSY5.mjs} +1 -1
  50. package/dist/cli/{chunk-GSBKODMU.mjs → chunk-QWEPCX6L.mjs} +2 -2
  51. package/dist/cli/{chunk-OVZSNBDJ.js → chunk-SJQ7Z3NI.js} +53 -53
  52. package/dist/cli/{chunk-ADZGTMLU.js → chunk-V4EK7ZZX.js} +98 -98
  53. package/dist/cli/{chunk-IXEEXYE2.js → chunk-VKVLJTW5.js} +9 -9
  54. package/dist/cli/{chunk-NZM4KWWV.mjs → chunk-VQMGCNX2.mjs} +5 -5
  55. package/dist/cli/{chunk-OGVUT2KM.js → chunk-VYSQ76RP.js} +7 -7
  56. package/dist/cli/{chunk-42ZSDTOC.mjs → chunk-WAWOMHWO.mjs} +2 -2
  57. package/dist/cli/{chunk-B3HQF2CA.js → chunk-WWLIDAVT.js} +11 -11
  58. package/dist/cli/{chunk-7X3NLHI7.js → chunk-WYI3VMTO.js} +6 -6
  59. package/dist/cli/{chunk-LT4IEJ6V.js → chunk-X547OW3I.js} +16 -16
  60. package/dist/cli/{chunk-KWIKFR7Y.mjs → chunk-XNWS2WJG.mjs} +1 -1
  61. package/dist/cli/{chunk-KHVCHFE3.js → chunk-YI7QOP6L.js} +16 -16
  62. package/dist/cli/{chunk-SP2KZ7SH.mjs → chunk-YVLPGYRS.mjs} +1 -1
  63. package/dist/cli/{csv-OTRVTHD2.js → csv-EFIEDJA2.js} +13 -13
  64. package/dist/cli/{csv-K7TRWOFJ.mjs → csv-VY2S7KKV.mjs} +4 -4
  65. package/dist/cli/{db-UO2ZFLFN.js → db-3DLI5TYW.js} +27 -27
  66. package/dist/cli/{db-C7GQU3TZ.mjs → db-D32CBDTN.mjs} +6 -6
  67. package/dist/cli/{describe-LG4CPTIV.mjs → describe-6MYKK2P3.mjs} +18 -18
  68. package/dist/cli/describe-U6HM52X6.js +50 -0
  69. package/dist/cli/{executions-LHFVPO7E.js → executions-QG3DEEY3.js} +8 -8
  70. package/dist/cli/{executions-P3INNVZE.mjs → executions-U6TPX4RX.mjs} +6 -6
  71. package/dist/cli/{feedback-H22FWG63.mjs → feedback-YZ6H4VMQ.mjs} +6 -6
  72. package/dist/cli/{feedback-M3HZQAWX.js → feedback-ZSPW6NXL.js} +14 -14
  73. package/dist/cli/{git-G2N7PVFI.mjs → git-ENN72IK4.mjs} +5 -5
  74. package/dist/cli/git-OBV73OVY.js +25 -0
  75. package/dist/cli/index.js +141 -141
  76. package/dist/cli/index.mjs +43 -43
  77. package/dist/cli/{legacy-noops-LDYSWTL2.mjs → legacy-noops-MNA6LWJU.mjs} +6 -6
  78. package/dist/cli/{legacy-noops-2RVROWBY.js → legacy-noops-Q6EVYIGN.js} +9 -9
  79. package/dist/cli/{monitors-U4RE6KN5.js → monitors-BUH54HXJ.js} +100 -100
  80. package/dist/cli/{monitors-IYT3VON7.mjs → monitors-KENWEEWC.mjs} +7 -7
  81. package/dist/cli/{org-SO52ZGRP.js → org-AHWQJMV7.js} +86 -86
  82. package/dist/cli/{org-R3JE22GS.mjs → org-HWOHKYP3.mjs} +6 -6
  83. package/dist/cli/{pages-5RLT5YTF.mjs → pages-I7DYTCW6.mjs} +6 -6
  84. package/dist/cli/{pages-SWXJQJXH.js → pages-Z5R7NYEF.js} +18 -18
  85. package/dist/cli/{play-J4UXOQOJ.js → play-3LXZB4ED.js} +317 -317
  86. package/dist/cli/{play-2ELYCSXZ.mjs → play-ET7CRVWJ.mjs} +18 -18
  87. package/dist/cli/{providers-IXITXHTS.mjs → providers-GZSAZVHZ.mjs} +6 -6
  88. package/dist/cli/{providers-VVUDGV2D.js → providers-ZV2E7NGX.js} +9 -9
  89. package/dist/cli/{quickstart-HQCGDPPL.mjs → quickstart-5746NBS2.mjs} +4 -4
  90. package/dist/cli/{quickstart-XPH6MT47.js → quickstart-VJZAT4RY.js} +6 -6
  91. package/dist/cli/{run-OR646AC6.js → run-WGUAVYZC.js} +41 -41
  92. package/dist/cli/{run-H2HQPWC4.mjs → run-WOQ6XMTT.mjs} +23 -23
  93. package/dist/cli/search-IGHNMXI4.js +33 -0
  94. package/dist/cli/{search-MBPI5SBW.mjs → search-NNPFJYEW.mjs} +8 -8
  95. package/dist/cli/{search-output-CYOMJNRV.mjs → search-output-65HDEEFS.mjs} +4 -4
  96. package/dist/cli/{search-output-YGNSHBXX.js → search-output-K4ISMPKD.js} +6 -6
  97. package/dist/cli/{secrets-HVZKNNLZ.js → secrets-NBKGWMF4.js} +15 -15
  98. package/dist/cli/{secrets-NK2CN7WI.mjs → secrets-RK44OV3X.mjs} +6 -6
  99. package/dist/cli/{sessions-NY4G427U.mjs → sessions-ULQJJN3J.mjs} +6 -6
  100. package/dist/cli/sessions-ZJNV4SEL.js +22 -0
  101. package/dist/cli/{settings-PVJRDEN2.js → settings-IHNA7X3Y.js} +86 -86
  102. package/dist/cli/{settings-RC4FGYY2.mjs → settings-V5ZRL2EF.mjs} +13 -13
  103. package/dist/cli/{setup-YT3XSY6X.mjs → setup-54VZPJGM.mjs} +10 -10
  104. package/dist/cli/{setup-B7QB4YV2.js → setup-HTEBFMOQ.js} +50 -50
  105. package/dist/cli/{skills-5ILFNAHR.mjs → skills-3FCPWMHX.mjs} +8 -8
  106. package/dist/cli/skills-ZCJ6FOOK.js +37 -0
  107. package/dist/cli/{tools-7PAY32OZ.mjs → tools-2NTDNUQT.mjs} +17 -17
  108. package/dist/cli/tools-Q75XC2BS.js +57 -0
  109. package/dist/cli/{update-Z27QYB6O.mjs → update-25MTBTGU.mjs} +10 -10
  110. package/dist/cli/update-3G3GO7IE.js +35 -0
  111. package/dist/cli/{views-NP2SCMOV.js → views-37K4JNNS.js} +18 -18
  112. package/dist/cli/{views-2IANF6KR.mjs → views-OBE5LUSW.mjs} +6 -6
  113. package/dist/cli/{workflow-2GNQL646.js → workflow-6YTIHHJH.js} +17 -17
  114. package/dist/cli/{workflow-CAMEZLLY.mjs → workflow-HAPCL4K6.mjs} +7 -7
  115. package/dist/index.js +9 -9
  116. package/dist/index.mjs +6 -6
  117. package/dist/install-integrity.json +104 -104
  118. package/dist/release.d.mts +1 -1
  119. package/dist/release.d.ts +1 -1
  120. package/dist/release.js +2 -2
  121. package/dist/release.mjs +1 -1
  122. package/dist/server.js +5 -5
  123. package/dist/server.mjs +3 -3
  124. package/package.json +1 -1
  125. package/dist/cli/auth-CWJZYLTB.js +0 -43
  126. package/dist/cli/describe-IK4UYJ5M.js +0 -50
  127. package/dist/cli/git-72ADWRUQ.js +0 -25
  128. package/dist/cli/search-D27DZH2D.js +0 -33
  129. package/dist/cli/sessions-MTISSOZ4.js +0 -22
  130. package/dist/cli/skills-BHF35NLX.js +0 -37
  131. package/dist/cli/tools-W5BZ37L6.js +0 -57
  132. package/dist/cli/update-M65CGK42.js +0 -35
@@ -286,6 +286,7 @@ import {
286
286
  isRuntimeSchedulerRetryableTransactionError,
287
287
  isRuntimeSchedulerServerUnavailableError,
288
288
  parseRuntimeSchedulerCapacityError,
289
+ probeRuntimeSchedulerDatabaseReachable,
289
290
  RuntimeSchedulerCapacityError,
290
291
  runtimeSchedulerCapacityRetryAfterMs,
291
292
  type PgNotifyHubLease,
@@ -457,12 +458,98 @@ export const ABSURD_RUNTIME_WORKER_SLOTS =
457
458
  * inside their slots, and the finished runs waited for those creates to end
458
459
  * before they could stage (round 43357298524-2: 16 such creates, up to 3.1 s
459
460
  * of waiting with a ready sandbox, and no claims for 4 s on each warm worker).
460
- * The worker holds at most slots + 2 x permits runs; creates stay bounded by
461
- * the permits, and pre-create work and staging by `slots`.
461
+ * On top of those, `ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS` runs may lend their
462
+ * slot while the pre-park lifecycle flush waits on the app, so flush loans can
463
+ * never use up the create loans. The worker holds at most
464
+ * slots + 2 x permits + flush loans runs; creates stay bounded by the permits,
465
+ * and pre-create work and staging by `slots`.
462
466
  */
467
+ export const ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS = 10;
463
468
  export const ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS =
464
469
  2 *
465
- RUNTIME_CAPACITY_POLICY.sandboxAcquisition.daytonaConcurrentStartsPerProcess;
470
+ RUNTIME_CAPACITY_POLICY.sandboxAcquisition
471
+ .daytonaConcurrentStartsPerProcess +
472
+ ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS;
473
+
474
+ /**
475
+ * Process-wide count of flush loans, against `max`. A flush takes a loan only
476
+ * while one is free here and the engine still has lending budget; otherwise
477
+ * it flushes in its slot, as before.
478
+ */
479
+ export function createAbsurdFlushLoanBudget(max: number): {
480
+ tryTake(): boolean;
481
+ give(): void;
482
+ outstanding(): number;
483
+ } {
484
+ let out = 0;
485
+ return {
486
+ tryTake: () => {
487
+ if (out >= max) return false;
488
+ out += 1;
489
+ return true;
490
+ },
491
+ give: () => {
492
+ out = Math.max(0, out - 1);
493
+ },
494
+ outstanding: () => out,
495
+ };
496
+ }
497
+
498
+ const absurdFlushLoanBudget = createAbsurdFlushLoanBudget(
499
+ ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS,
500
+ );
501
+
502
+ /**
503
+ * Runs the pre-park lifecycle flush with the attempt's worker slot lent, and
504
+ * gets the slot back before returning, whether or not the flush throws. The
505
+ * flush only waits on the run-ledger outbox and the app (round 43377040223-1:
506
+ * detach -> park p50 1.2 s, p95 2.5 s, with the slot held), so the worker can
507
+ * claim another run meanwhile; the park that follows runs in a slot, as every
508
+ * step of the task does. Getting the slot back is in-memory in the engine and
509
+ * makes no scheduler-pool call, but it waits for a free slot, so the caller
510
+ * keeps the lease heartbeat running around this whole call. One
511
+ * `lifecycle_flush` phase line per flush reports the flush time, whether it
512
+ * was lent, and the wait for the slot.
513
+ */
514
+ export async function runLifecycleFlushWithSlotLent<T>(input: {
515
+ workerSlot: PlayRunnerWorkerSlot | undefined;
516
+ budget?: ReturnType<typeof createAbsurdFlushLoanBudget>;
517
+ flush: () => Promise<T>;
518
+ log: (fields: {
519
+ totalMs: number;
520
+ lent: boolean;
521
+ slotWaitMs: number;
522
+ ok: boolean;
523
+ }) => void;
524
+ }): Promise<T> {
525
+ const budget = input.budget ?? absurdFlushLoanBudget;
526
+ let loan: { reclaim(): Promise<void> } | null = null;
527
+ if (input.workerSlot && budget.tryTake()) {
528
+ loan = input.workerSlot.lend();
529
+ if (!loan) budget.give();
530
+ }
531
+ const startedAt = performance.now();
532
+ let totalMs = 0;
533
+ let slotWaitMs = 0;
534
+ let ok = false;
535
+ try {
536
+ const result = await input.flush();
537
+ ok = true;
538
+ return result;
539
+ } finally {
540
+ totalMs = performance.now() - startedAt;
541
+ if (loan) {
542
+ const reclaimStartedAt = performance.now();
543
+ try {
544
+ await loan.reclaim();
545
+ } finally {
546
+ slotWaitMs = performance.now() - reclaimStartedAt;
547
+ budget.give();
548
+ }
549
+ }
550
+ input.log({ totalMs, lent: loan !== null, slotWaitMs, ok });
551
+ }
552
+ }
466
553
 
467
554
  /**
468
555
  * The engine's lendable slot for a play-run attempt. Undefined when the task
@@ -1086,51 +1173,93 @@ function buildDefaultDeps(absurd: Absurd): AbsurdRuntimeWorkerDeps {
1086
1173
  * outage keeps the outbox row durable for recovery, but is always loud instead
1087
1174
  * of silently leaving the CLI stale.
1088
1175
  */
1089
- async function projectLifecycleOutbox(input: {
1176
+ export async function projectLifecycleOutbox(input: {
1090
1177
  ctx: TaskContext;
1091
- deps: AbsurdRuntimeWorkerDeps;
1178
+ deps: Pick<AbsurdRuntimeWorkerDeps, 'projectOutbox'>;
1092
1179
  launch: PlaySchedulerSubmitInput;
1093
1180
  lifecycle: PostgresSchedulerLifecycleOutboxEvent;
1094
1181
  options?: Pick<PostgresSchedulerOptions, 'schema'>;
1095
1182
  transition: 'waiting' | 'resumed';
1096
1183
  }): Promise<void> {
1184
+ // Before a park the flush only waits on the outbox and the app, so the slot
1185
+ // is lent for it (`runLifecycleFlushWithSlotLent`). Execution follows a
1186
+ // 'resumed' flush, which keeps its slot. The lease heartbeat runs until the
1187
+ // slot is back, as it does around a create loan: on a full worker, getting
1188
+ // the slot back can outlast the claim lease.
1097
1189
  await runWithAbsurdExecutionLeaseHeartbeat({
1098
1190
  ctx: input.ctx,
1099
1191
  runId: input.lifecycle.runId,
1100
1192
  operation: async (signal) => {
1101
- try {
1102
- const result = await input.deps.projectOutbox(
1103
- input.launch,
1104
- input.lifecycle.runId,
1105
- input.options,
1106
- input.lifecycle.eventId,
1107
- signal,
1108
- );
1109
- if (result && !result.targetDelivered) {
1110
- console.error('[run-ledger-outbox.lifecycle_projection_pending]', {
1111
- runId: input.lifecycle.runId,
1112
- eventId: input.lifecycle.eventId,
1113
- transition: input.transition,
1114
- projected: result.projected,
1115
- failed: result.failed,
1116
- failedEventIds: result.failedEventIds,
1117
- });
1118
- }
1119
- } catch (error) {
1120
- // Scheduler truth and the outbox row were committed atomically before this
1121
- // handoff. Keep the durable continuation live so recovery can heal a
1122
- // transient app-runtime failure, but do not hide the visibility gap.
1123
- console.error('[run-ledger-outbox.lifecycle_projection_failed]', {
1124
- runId: input.lifecycle.runId,
1125
- eventId: input.lifecycle.eventId,
1126
- transition: input.transition,
1127
- error: error instanceof Error ? error.message : String(error),
1128
- });
1129
- }
1193
+ let delivered = false;
1194
+ await runLifecycleFlushWithSlotLent({
1195
+ workerSlot:
1196
+ input.transition === 'waiting'
1197
+ ? absurdTaskWorkerSlot(input.ctx)
1198
+ : undefined,
1199
+ flush: async () => {
1200
+ delivered = await runLifecycleFlush(input, signal);
1201
+ },
1202
+ log: (fields) =>
1203
+ console.info(
1204
+ '[absurd-runtime.worker.phase] ' +
1205
+ JSON.stringify({
1206
+ runId: input.lifecycle.runId,
1207
+ phase: 'lifecycle_flush',
1208
+ transition: input.transition,
1209
+ ...fields,
1210
+ delivered,
1211
+ }),
1212
+ ),
1213
+ });
1130
1214
  },
1131
1215
  });
1132
1216
  }
1133
1217
 
1218
+ /** True when the outbox delivered the lifecycle event to the app. */
1219
+ async function runLifecycleFlush(
1220
+ input: {
1221
+ deps: Pick<AbsurdRuntimeWorkerDeps, 'projectOutbox'>;
1222
+ launch: PlaySchedulerSubmitInput;
1223
+ lifecycle: PostgresSchedulerLifecycleOutboxEvent;
1224
+ options?: Pick<PostgresSchedulerOptions, 'schema'>;
1225
+ transition: 'waiting' | 'resumed';
1226
+ },
1227
+ signal: AbortSignal,
1228
+ ): Promise<boolean> {
1229
+ try {
1230
+ const result = await input.deps.projectOutbox(
1231
+ input.launch,
1232
+ input.lifecycle.runId,
1233
+ input.options,
1234
+ input.lifecycle.eventId,
1235
+ signal,
1236
+ );
1237
+ if (result && !result.targetDelivered) {
1238
+ console.error('[run-ledger-outbox.lifecycle_projection_pending]', {
1239
+ runId: input.lifecycle.runId,
1240
+ eventId: input.lifecycle.eventId,
1241
+ transition: input.transition,
1242
+ projected: result.projected,
1243
+ failed: result.failed,
1244
+ failedEventIds: result.failedEventIds,
1245
+ });
1246
+ return false;
1247
+ }
1248
+ return true;
1249
+ } catch (error) {
1250
+ // Scheduler truth and the outbox row were committed atomically before this
1251
+ // handoff. Keep the durable continuation live so recovery can heal a
1252
+ // transient app-runtime failure, but do not hide the visibility gap.
1253
+ console.error('[run-ledger-outbox.lifecycle_projection_failed]', {
1254
+ runId: input.lifecycle.runId,
1255
+ eventId: input.lifecycle.eventId,
1256
+ transition: input.transition,
1257
+ error: error instanceof Error ? error.message : String(error),
1258
+ });
1259
+ return false;
1260
+ }
1261
+ }
1262
+
1134
1263
  function nonJsonResponseTitle(
1135
1264
  value: string,
1136
1265
  secrets: readonly string[],
@@ -5173,17 +5302,48 @@ async function executeAssignedAbsurdAttempt(input: {
5173
5302
  .daytonaMaximumStartsPerMinute
5174
5303
  : effectiveDaytonaStartRatePerMinute,
5175
5304
  };
5176
- await enforceRuntimeTrafficPolicyBeforeSandboxStart({
5177
- policy: trafficPolicy,
5178
- defaultSandboxStartsPerMinute: defaultDaytonaStartRatePerMinute,
5179
- nowMs: Date.now(),
5180
- ...sandboxStartPermitStore({
5181
- runWithClient: deps.runWithClient,
5182
- schedulerSchema: options.schema ?? null,
5183
- maximumRatePerMinute:
5184
- daytonaStartRateConfig?.maximumRatePerMinute ?? null,
5185
- }),
5305
+ // Measurement only: one line per attempt with its acquires
5306
+ // (each a scheduler-pool call) and local waits at the limiter.
5307
+ const permitStore = sandboxStartPermitStore({
5308
+ runWithClient: deps.runWithClient,
5309
+ schedulerSchema: options.schema ?? null,
5310
+ maximumRatePerMinute:
5311
+ daytonaStartRateConfig?.maximumRatePerMinute ?? null,
5186
5312
  });
5313
+ const limiterStartedAt = performance.now();
5314
+ const limiterCounts = { acquires: 0, waits: 0, waitMs: 0 };
5315
+ let limiterOk = false;
5316
+ try {
5317
+ await enforceRuntimeTrafficPolicyBeforeSandboxStart({
5318
+ policy: trafficPolicy,
5319
+ defaultSandboxStartsPerMinute:
5320
+ defaultDaytonaStartRatePerMinute,
5321
+ nowMs: Date.now(),
5322
+ acquireStartPermit: (startsPerMinute) => {
5323
+ limiterCounts.acquires += 1;
5324
+ return permitStore.acquireStartPermit(startsPerMinute);
5325
+ },
5326
+ refundStartPermit: permitStore.refundStartPermit,
5327
+ sleep: async (ms) => {
5328
+ limiterCounts.waits += 1;
5329
+ limiterCounts.waitMs += ms;
5330
+ await sleep(ms);
5331
+ },
5332
+ });
5333
+ limiterOk = true;
5334
+ } finally {
5335
+ console.info(
5336
+ '[absurd-runtime.worker.phase] ' +
5337
+ JSON.stringify({
5338
+ runId,
5339
+ attempt: generation,
5340
+ phase: 'sandbox_start_limiter',
5341
+ totalMs: performance.now() - limiterStartedAt,
5342
+ ok: limiterOk,
5343
+ ...limiterCounts,
5344
+ }),
5345
+ );
5346
+ }
5187
5347
  }
5188
5348
  const sandboxRuns = createSandboxExecutionJob({
5189
5349
  execution: createPlayRunnerBackendSandboxExecutionAdapter({
@@ -11074,6 +11234,78 @@ export function createAbsurdWorkerWakeHook(input: {
11074
11234
  return hook;
11075
11235
  }
11076
11236
 
11237
+ /**
11238
+ * How long a booting worker waits for its scheduler database before failing
11239
+ * loudly. A new Production Machine cannot reach PlanetScale for about 5-15 s
11240
+ * after creation: the worker app egresses through an app-scoped Fly static
11241
+ * egress IP, which a new Machine cannot use at first. Before this wait, the
11242
+ * pool's first connections timed out (5 s, three attempts) and 66 of ~415
11243
+ * fresh boots crashed on "Connection terminated due to connection timeout"
11244
+ * (2026-11-10/11). Past the deadline a real outage still fails the boot.
11245
+ */
11246
+ export const ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS = 60_000;
11247
+ /** Each reachability attempt's connect and query timeout. */
11248
+ export const ABSURD_WORKER_BOOT_DATABASE_ATTEMPT_TIMEOUT_MS = 2_000;
11249
+ const ABSURD_WORKER_BOOT_DATABASE_RETRY_DELAY_MS = 250;
11250
+
11251
+ export class RuntimeSchedulerDatabaseUnreachableAtBootError extends Error {
11252
+ constructor(attempts: number, waitedMs: number, lastError: unknown) {
11253
+ super(
11254
+ `Runtime scheduler database unreachable at worker boot after ${attempts} attempts over ${waitedMs} ms: ` +
11255
+ (lastError instanceof Error ? lastError.message : String(lastError)),
11256
+ { cause: lastError },
11257
+ );
11258
+ this.name = 'RuntimeSchedulerDatabaseUnreachableAtBootError';
11259
+ }
11260
+ }
11261
+
11262
+ /**
11263
+ * Retry a short reachability probe until it succeeds or the deadline passes,
11264
+ * then fail loudly. Every failed attempt is reported; the deadline bounds how
11265
+ * many there can be. The caller keeps the worker unready meanwhile.
11266
+ */
11267
+ export async function waitForRuntimeSchedulerDatabaseAtBoot(input: {
11268
+ probe: (timeoutMs: number) => Promise<void>;
11269
+ deadlineMs?: number;
11270
+ attemptTimeoutMs?: number;
11271
+ retryDelayMs?: number;
11272
+ now?: () => number;
11273
+ sleep?: (ms: number) => Promise<void>;
11274
+ onAttemptFailed?: (failure: {
11275
+ attempt: number;
11276
+ elapsedMs: number;
11277
+ error: unknown;
11278
+ }) => void;
11279
+ }): Promise<{ attempts: number; waitedMs: number }> {
11280
+ const now = input.now ?? Date.now;
11281
+ const pause = input.sleep ?? ((ms: number) => sleep(ms));
11282
+ const deadlineMs =
11283
+ input.deadlineMs ?? ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS;
11284
+ const attemptTimeoutMs =
11285
+ input.attemptTimeoutMs ?? ABSURD_WORKER_BOOT_DATABASE_ATTEMPT_TIMEOUT_MS;
11286
+ const retryDelayMs =
11287
+ input.retryDelayMs ?? ABSURD_WORKER_BOOT_DATABASE_RETRY_DELAY_MS;
11288
+ const startedAt = now();
11289
+ for (let attempt = 1; ; attempt += 1) {
11290
+ const remainingMs = deadlineMs - (now() - startedAt);
11291
+ try {
11292
+ await input.probe(Math.max(1, Math.min(attemptTimeoutMs, remainingMs)));
11293
+ return { attempts: attempt, waitedMs: now() - startedAt };
11294
+ } catch (error) {
11295
+ const elapsedMs = now() - startedAt;
11296
+ input.onAttemptFailed?.({ attempt, elapsedMs, error });
11297
+ if (elapsedMs + retryDelayMs >= deadlineMs) {
11298
+ throw new RuntimeSchedulerDatabaseUnreachableAtBootError(
11299
+ attempt,
11300
+ elapsedMs,
11301
+ error,
11302
+ );
11303
+ }
11304
+ await pause(retryDelayMs);
11305
+ }
11306
+ }
11307
+ }
11308
+
11077
11309
  export type RuntimeWorkerHostConfig = {
11078
11310
  schedulerSchema?: string | null;
11079
11311
  slots?: number | null;
@@ -11189,19 +11421,41 @@ export async function startRuntimeWorkerHost(
11189
11421
  'gateway (apps/runtime-receipt-gateway/index.ts), never the Vercel app.',
11190
11422
  );
11191
11423
  }
11424
+ const poolOptions = resolveAbsurdPoolOptions();
11425
+ // Wait for the scheduler database beside the gateway check, before the pool
11426
+ // makes its first connections: their 5 s timeouts and breaker are for a
11427
+ // running worker, not for a new Machine's first seconds of egress.
11428
+ const databaseReachable = waitForRuntimeSchedulerDatabaseAtBoot({
11429
+ probe: (timeoutMs) =>
11430
+ probeRuntimeSchedulerDatabaseReachable({
11431
+ url: poolOptions.url,
11432
+ timeoutMs,
11433
+ applicationName: 'deepline-absurd-worker-boot',
11434
+ }),
11435
+ onAttemptFailed: ({ attempt, elapsedMs, error }) =>
11436
+ console.warn('[absurd-runtime.worker] boot_database_unreachable', {
11437
+ attempt,
11438
+ elapsedMs,
11439
+ deadlineMs: ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS,
11440
+ error: error instanceof Error ? error.message : String(error),
11441
+ }),
11442
+ });
11192
11443
  // This is a liveness/identity check only. Named operation capability is
11193
11444
  // checked by its caller, so a compatible receiver can serve draining older
11194
11445
  // lanes without a global-version boot gate.
11195
- await verifyRuntimeReceiptGatewayHealth({
11196
- gatewayBaseUrl: process.env.DEEPLINE_RUNTIME_RECEIPT_GATEWAY_URL,
11197
- });
11446
+ const [, reachable] = await Promise.all([
11447
+ verifyRuntimeReceiptGatewayHealth({
11448
+ gatewayBaseUrl: process.env.DEEPLINE_RUNTIME_RECEIPT_GATEWAY_URL,
11449
+ }),
11450
+ databaseReachable,
11451
+ ]);
11452
+ console.info('[absurd-runtime.worker] boot_database_reachable', reachable);
11198
11453
  // This is deliberately structured and non-secret. `runtime status` exposes
11199
11454
  // the app/gateway copy; the worker boot record lets on-call verify that a
11200
11455
  // coordinated SEV configuration reached the Fly execution lane as well.
11201
11456
  console.info('[absurd-runtime.worker] reliability_policy', {
11202
11457
  policy: RUNTIME_RELIABILITY_POLICY,
11203
11458
  });
11204
- const poolOptions = resolveAbsurdPoolOptions();
11205
11459
  const schedulerOptions: AbsurdSchedulerOptions =
11206
11460
  normalizeAbsurdSchedulerOptions({
11207
11461
  schema: options.schedulerSchema ?? null,
@@ -1501,6 +1501,35 @@ export function deriveDirectDatabaseUrl(url: string): string {
1501
1501
  }
1502
1502
  }
1503
1503
 
1504
+ /**
1505
+ * One connect and `select 1` against the scheduler's pooled endpoint, with its
1506
+ * own short connect and query timeout. It never touches a pool, its admission
1507
+ * queue or its failure breaker, so a worker can ask "is the database reachable
1508
+ * yet?" at boot without tripping the circuit its real work depends on.
1509
+ */
1510
+ export async function probeRuntimeSchedulerDatabaseReachable(input: {
1511
+ url: string;
1512
+ timeoutMs: number;
1513
+ applicationName?: string;
1514
+ createClient?: (
1515
+ config: ConstructorParameters<typeof Client>[0],
1516
+ ) => Pick<Client, 'connect' | 'query' | 'end'>;
1517
+ }): Promise<void> {
1518
+ const client = (input.createClient ?? ((config) => new Client(config)))({
1519
+ connectionString: normalizePostgresConnectionStringForPg(input.url),
1520
+ application_name:
1521
+ input.applicationName ?? 'deepline-runtime-scheduler-reachability',
1522
+ connectionTimeoutMillis: input.timeoutMs,
1523
+ query_timeout: input.timeoutMs,
1524
+ });
1525
+ try {
1526
+ await client.connect();
1527
+ await client.query('select 1');
1528
+ } finally {
1529
+ await client.end().catch(() => undefined);
1530
+ }
1531
+ }
1532
+
1504
1533
  /**
1505
1534
  * The runtime worker needs one direct Postgres session for its optional
1506
1535
  * LISTEN wake hint. Preview gates must prove that this separate session budget
@@ -37,6 +37,10 @@ import type {
37
37
  import type { PlaySchedulerSubmitInput } from '../scheduler-backend';
38
38
  import type { DocflowObservationRecord } from '../docflow-observation';
39
39
  import { runtimeWorkCountersFromStats } from '../runtime-work-counters';
40
+ import {
41
+ durableReplayRefusalFromRunLogLine,
42
+ emitPlayRunReplayRefusal,
43
+ } from '../runtime-telemetry';
40
44
  import {
41
45
  buildPlayRunLedgerEventsFromStatusPatch,
42
46
  createEmptyPlayRunLedgerSnapshot,
@@ -764,6 +768,22 @@ export function createPostgresSchedulerProgressReporter(input: {
764
768
  void flush({ force }).catch(() => undefined);
765
769
  };
766
770
 
771
+ /** Re-emit runner replay refusals to this process's shipped log stream. */
772
+ const forwardReplayRefusal = (
773
+ line: string,
774
+ attempt: number | null | undefined = producerAttempt,
775
+ ) => {
776
+ const refusal = durableReplayRefusalFromRunLogLine(line);
777
+ if (!refusal) return;
778
+ emitPlayRunReplayRefusal({
779
+ orgId: launch.orgId ?? null,
780
+ runId: launch.runId,
781
+ playName: launch.playName ?? null,
782
+ attempt: attempt ?? null,
783
+ refusal,
784
+ });
785
+ };
786
+
767
787
  const appendLiveLog = (
768
788
  line: string,
769
789
  context?: unknown,
@@ -1469,6 +1489,7 @@ export function createPostgresSchedulerProgressReporter(input: {
1469
1489
  logEvent.entryId,
1470
1490
  logEvent.metadata,
1471
1491
  );
1492
+ forwardReplayRefusal(rawLine);
1472
1493
  }
1473
1494
  markMapStartedFromLog(rawLine);
1474
1495
  markMapStartedFromPerfLog(rawLine);
@@ -1758,6 +1779,27 @@ export function createPostgresSchedulerProgressReporter(input: {
1758
1779
  reconcileTerminalMapProgressFromSheetOutcomes();
1759
1780
  }
1760
1781
  const status = options.status ?? 'running';
1782
+ const terminalReplayAttempt =
1783
+ options.terminalLogProducerAttempt ?? producerAttempt;
1784
+ const terminalLogReplay =
1785
+ options.skipTerminalLogReplay || !Array.isArray(result?.logs)
1786
+ ? null
1787
+ : terminalReplayPayloadForMode({
1788
+ resultLogs: result.logs,
1789
+ resultLogContexts: result.logContexts,
1790
+ resultLogMetadata: result.logMetadata,
1791
+ resultLogIds: result.logIds,
1792
+ durableLogMode,
1793
+ liveLogs,
1794
+ liveLogContexts,
1795
+ liveLogsTotalCount,
1796
+ replayAllTerminalLogs: options.replayAllTerminalLogs === true,
1797
+ producerAttempt: terminalReplayAttempt,
1798
+ });
1799
+ // A detached runner that streamed no events delivers its refusals here.
1800
+ for (const line of terminalLogReplay?.lines ?? []) {
1801
+ forwardReplayRefusal(line, terminalReplayAttempt);
1802
+ }
1761
1803
  await flush({
1762
1804
  force: true,
1763
1805
  status,
@@ -1767,22 +1809,7 @@ export function createPostgresSchedulerProgressReporter(input: {
1767
1809
  options.required === true ||
1768
1810
  status === 'completed' ||
1769
1811
  status === 'failed',
1770
- terminalLogReplay:
1771
- options.skipTerminalLogReplay || !Array.isArray(result?.logs)
1772
- ? null
1773
- : terminalReplayPayloadForMode({
1774
- resultLogs: result.logs,
1775
- resultLogContexts: result.logContexts,
1776
- resultLogMetadata: result.logMetadata,
1777
- resultLogIds: result.logIds,
1778
- durableLogMode,
1779
- liveLogs,
1780
- liveLogContexts,
1781
- liveLogsTotalCount,
1782
- replayAllTerminalLogs: options.replayAllTerminalLogs === true,
1783
- producerAttempt:
1784
- options.terminalLogProducerAttempt ?? producerAttempt,
1785
- }),
1812
+ terminalLogReplay,
1786
1813
  });
1787
1814
  };
1788
1815
 
@@ -14,14 +14,14 @@ import {
14
14
  reportSetupCompleted,
15
15
  resolvePendingAuthClaimForResume,
16
16
  statusBannerLine
17
- } from "./chunk-T4QPRL3P.mjs";
18
- import "./chunk-GP7E4TE4.mjs";
19
- import "./chunk-Z25KC5V2.mjs";
20
- import "./chunk-RML3VSTN.mjs";
17
+ } from "./chunk-BVY4QRVT.mjs";
18
+ import "./chunk-A5MYJM4K.mjs";
19
+ import "./chunk-ERMDXXP5.mjs";
20
+ import "./chunk-MVF7ZBJX.mjs";
21
21
  import "./chunk-QNHHZ63P.mjs";
22
22
  import "./chunk-DLIRSHV6.mjs";
23
23
  import "./chunk-ZPGGW27Q.mjs";
24
- import "./chunk-HJVNCRXY.mjs";
24
+ import "./chunk-J6XSBTEX.mjs";
25
25
  import "./chunk-WZYKRD7T.mjs";
26
26
  import "./chunk-KRD6H754.mjs";
27
27
  export {
@@ -0,0 +1,43 @@
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 _chunkSJQ7Z3NIjs = require('./chunk-SJQ7Z3NI.js');
18
+ require('./chunk-32NTC5UD.js');
19
+ require('./chunk-5B37ER3C.js');
20
+ require('./chunk-7E7CP5KA.js');
21
+ require('./chunk-T2N3B7IQ.js');
22
+ require('./chunk-XNYIZMNQ.js');
23
+ require('./chunk-SQWET4SL.js');
24
+ require('./chunk-4WPIORJX.js');
25
+ require('./chunk-OG64RBAC.js');
26
+ require('./chunk-COGTRVWW.js');
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ exports.EXIT_WORKSPACE_MISMATCH = _chunkSJQ7Z3NIjs.EXIT_WORKSPACE_MISMATCH; exports.authStatusLine = _chunkSJQ7Z3NIjs.authStatusLine; exports.clearPendingClaim = _chunkSJQ7Z3NIjs.clearPendingClaim; exports.clearSatisfiedPendingClaim = _chunkSJQ7Z3NIjs.clearSatisfiedPendingClaim; exports.handleRegister = _chunkSJQ7Z3NIjs.handleRegister; exports.handleStatus = _chunkSJQ7Z3NIjs.handleStatus; exports.handleWait = _chunkSJQ7Z3NIjs.handleWait; exports.httpJson = _chunkSJQ7Z3NIjs.httpJson; exports.readPendingAuthClaim = _chunkSJQ7Z3NIjs.readPendingAuthClaim; exports.readStatusBanner = _chunkSJQ7Z3NIjs.readStatusBanner; exports.registerAuthCommands = _chunkSJQ7Z3NIjs.registerAuthCommands; exports.reportApprovalLinkShown = _chunkSJQ7Z3NIjs.reportApprovalLinkShown; exports.reportSetupCompleted = _chunkSJQ7Z3NIjs.reportSetupCompleted; exports.resolvePendingAuthClaimForResume = _chunkSJQ7Z3NIjs.resolvePendingAuthClaimForResume; exports.statusBannerLine = _chunkSJQ7Z3NIjs.statusBannerLine;