deepline 0.3.570 → 0.3.571

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 (140) 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/resource-governor.ts +17 -0
  5. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +2 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-connection-probe.ts +199 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +43 -0
  8. package/dist/cli/{auth-KHJKNEYN.mjs → auth-ARGNQK7A.mjs} +5 -5
  9. package/dist/cli/auth-FKYYYCME.js +44 -0
  10. package/dist/cli/{billing-Q4BRUODF.js → billing-KAKODYTN.js} +99 -99
  11. package/dist/cli/{billing-R5AO4M3S.mjs → billing-QRZTHCBX.mjs} +8 -8
  12. package/dist/cli/{chunk-2GTLZNSK.js → chunk-2IZOCGOA.js} +53 -53
  13. package/dist/cli/{chunk-3YHMHV6U.mjs → chunk-336AHC7H.mjs} +4 -4
  14. package/dist/cli/{chunk-2MXS53XJ.js → chunk-6N3NTEJ6.js} +20 -20
  15. package/dist/cli/{chunk-OWEUQCBZ.js → chunk-6OP5UW7C.js} +48 -48
  16. package/dist/cli/{chunk-DPZAEVPO.js → chunk-73P76DCN.js} +20 -20
  17. package/dist/cli/{chunk-ZZ4D74UL.mjs → chunk-7HAYEKC4.mjs} +1 -1
  18. package/dist/cli/{chunk-UDN6EYBJ.js → chunk-7JGHNZTD.js} +4 -4
  19. package/dist/cli/{chunk-73RTZMDV.mjs → chunk-A3B54QEW.mjs} +3 -3
  20. package/dist/cli/{chunk-HPWP2B3D.mjs → chunk-A3IVPA6Q.mjs} +1 -1
  21. package/dist/cli/{chunk-FABLUH75.js → chunk-A5HDA22N.js} +3 -3
  22. package/dist/cli/{chunk-YXJVYY5V.mjs → chunk-AD7BGMTL.mjs} +2 -2
  23. package/dist/cli/{chunk-OPZHUL6T.js → chunk-AOMVAXGX.js} +10 -10
  24. package/dist/cli/{chunk-FDSQSUZF.js → chunk-C27FK36H.js} +5 -5
  25. package/dist/cli/{chunk-NIO2T6OC.js → chunk-C3FHMJ4A.js} +2 -2
  26. package/dist/cli/{chunk-I5EZZFQL.mjs → chunk-C6XV2DPY.mjs} +3 -3
  27. package/dist/cli/{chunk-O3ET4XR3.mjs → chunk-CF6CSAMJ.mjs} +4 -4
  28. package/dist/cli/{chunk-MH3WE5O6.mjs → chunk-CFMIWRGD.mjs} +2 -2
  29. package/dist/cli/{chunk-OV6EKORX.js → chunk-CITDBSXI.js} +26 -26
  30. package/dist/cli/{chunk-77HEH4RY.mjs → chunk-CR6IPQBB.mjs} +1 -1
  31. package/dist/cli/{chunk-UWQLRBXY.mjs → chunk-ETGM6PIR.mjs} +5 -5
  32. package/dist/cli/{chunk-WINZRS3A.mjs → chunk-FQP5VSVF.mjs} +1 -1
  33. package/dist/cli/{chunk-WNUFRUNS.js → chunk-GACQOGRS.js} +15 -15
  34. package/dist/cli/{chunk-BEE5VGCL.mjs → chunk-GCE5KOJJ.mjs} +11 -11
  35. package/dist/cli/{chunk-GPXLMRCB.js → chunk-GOUKX6XD.js} +3 -3
  36. package/dist/cli/{chunk-TWHTVGGW.mjs → chunk-GRD3DLH7.mjs} +2 -2
  37. package/dist/cli/{chunk-GFGXDDJH.mjs → chunk-H6QMUX7Y.mjs} +2 -2
  38. package/dist/cli/{chunk-ZZ7ZH27W.js → chunk-HGER4CJA.js} +5 -5
  39. package/dist/cli/{chunk-PERYT4ZA.js → chunk-IFKZQCPX.js} +1 -1
  40. package/dist/cli/{chunk-W26YT37U.js → chunk-ILKUKEWX.js} +41 -41
  41. package/dist/cli/{chunk-NR7QW2E7.js → chunk-IXFFOZZQ.js} +2 -2
  42. package/dist/cli/{chunk-2GBOHROU.mjs → chunk-J5KW2ZDB.mjs} +1 -1
  43. package/dist/cli/{chunk-J6PTH725.js → chunk-MFBFQUQK.js} +6 -6
  44. package/dist/cli/{chunk-JSHE4W6W.js → chunk-NAGGCF6Y.js} +5 -5
  45. package/dist/cli/{chunk-EEUBKKJE.mjs → chunk-PO3NOBHU.mjs} +1 -1
  46. package/dist/cli/{chunk-YQP4ZUOJ.js → chunk-PTM5V5FV.js} +7 -7
  47. package/dist/cli/{chunk-I4N62RWB.mjs → chunk-QRMTITKL.mjs} +2 -2
  48. package/dist/cli/{chunk-CHHXUEVC.js → chunk-RBPR5ZNN.js} +100 -100
  49. package/dist/cli/{chunk-PSMYOQFI.js → chunk-SJYLLHHZ.js} +13 -13
  50. package/dist/cli/{chunk-XHFSNMEU.mjs → chunk-TJU2BECV.mjs} +3 -3
  51. package/dist/cli/{chunk-NVYQ6WCW.mjs → chunk-UBNRPJKO.mjs} +5 -5
  52. package/dist/cli/{chunk-MVHKTZCX.mjs → chunk-UTGHPC5D.mjs} +1 -1
  53. package/dist/cli/{chunk-SOZ2SB43.js → chunk-VLQB65HI.js} +9 -9
  54. package/dist/cli/{chunk-RS6KPFQX.mjs → chunk-VULSFPD4.mjs} +5 -5
  55. package/dist/cli/{chunk-Q4P6STRD.js → chunk-WOU2WS6S.js} +23 -23
  56. package/dist/cli/{chunk-OOTXBEHG.mjs → chunk-WZOUXILM.mjs} +1 -1
  57. package/dist/cli/{chunk-J6M2AX3P.js → chunk-XD4MT4BH.js} +8 -8
  58. package/dist/cli/{chunk-EJB4V77N.mjs → chunk-YDM5WSXO.mjs} +5 -5
  59. package/dist/cli/{chunk-TMT3S2JR.mjs → chunk-YDULFKDL.mjs} +2 -2
  60. package/dist/cli/{chunk-NWAFCOUF.js → chunk-YGGHPEWP.js} +15 -15
  61. package/dist/cli/{chunk-ZGOCDLJQ.js → chunk-YQ36Z23U.js} +2 -2
  62. package/dist/cli/{chunk-5OOGWYSR.mjs → chunk-Z3DSCE5F.mjs} +1 -1
  63. package/dist/cli/{chunk-EYEPXZNS.mjs → chunk-Z6OUUAIV.mjs} +2 -2
  64. package/dist/cli/{concurrent-runs-help-Q26CEJ7I.mjs → concurrent-runs-help-VPYB4ODC.mjs} +6 -6
  65. package/dist/cli/concurrent-runs-help-VUMIMYO7.js +22 -0
  66. package/dist/cli/{csv-Z34I5QIU.js → csv-GHGDSFNV.js} +13 -13
  67. package/dist/cli/{csv-6LI6HLKG.mjs → csv-RALLG3MG.mjs} +4 -4
  68. package/dist/cli/{db-NUDEYQCF.js → db-722SKSIB.js} +27 -27
  69. package/dist/cli/{db-K5GKIKQU.mjs → db-HB65VYRR.mjs} +6 -6
  70. package/dist/cli/{describe-EB4KTEPT.mjs → describe-Q6M7PUBU.mjs} +18 -18
  71. package/dist/cli/describe-SG2N62VE.js +50 -0
  72. package/dist/cli/{executions-DAGHJZEI.mjs → executions-G3M75HW2.mjs} +6 -6
  73. package/dist/cli/{executions-KHOUABZ3.js → executions-GQNV3LNU.js} +8 -8
  74. package/dist/cli/{feedback-XLAWTPK2.js → feedback-B43F2FBL.js} +14 -14
  75. package/dist/cli/{feedback-A57YETEA.mjs → feedback-CSDBYSRS.mjs} +6 -6
  76. package/dist/cli/git-IJHKRWTR.js +26 -0
  77. package/dist/cli/{git-U3FNR34D.mjs → git-IZ4Y3RAW.mjs} +5 -5
  78. package/dist/cli/index.js +143 -143
  79. package/dist/cli/index.mjs +45 -45
  80. package/dist/cli/{integrations-LXUMB4RY.mjs → integrations-DT7EGM2Y.mjs} +7 -7
  81. package/dist/cli/{integrations-YVOJ5D6W.js → integrations-OLCUWZ6Z.js} +29 -29
  82. package/dist/cli/{legacy-noops-4Z2RBTHW.mjs → legacy-noops-4TPT534L.mjs} +6 -6
  83. package/dist/cli/{legacy-noops-IZVLGQZJ.js → legacy-noops-FTGNTO3U.js} +9 -9
  84. package/dist/cli/{mcp-GRGI3KYH.js → mcp-3IDWLBKK.js} +24 -24
  85. package/dist/cli/{mcp-ZHXRVV7D.mjs → mcp-5KDJJT7M.mjs} +4 -4
  86. package/dist/cli/{monitors-XFN5D6EW.js → monitors-7GOZBKJR.js} +100 -100
  87. package/dist/cli/{monitors-7ZVYJ3CX.mjs → monitors-EOAA5RQO.mjs} +7 -7
  88. package/dist/cli/{org-YY5JTKNV.mjs → org-H5I56A4F.mjs} +6 -6
  89. package/dist/cli/{org-RWWXN5TK.js → org-UJ5SWQJ5.js} +121 -121
  90. package/dist/cli/{outcomes-AOZVYNJT.js → outcomes-24KFY2X5.js} +14 -14
  91. package/dist/cli/{outcomes-MGWUZNQ6.mjs → outcomes-MG57YXJX.mjs} +6 -6
  92. package/dist/cli/{play-AJR7BT3R.mjs → play-MXPXRAUM.mjs} +19 -19
  93. package/dist/cli/{play-S34KIOWS.js → play-PPPACSQE.js} +324 -324
  94. package/dist/cli/{providers-QRWQGVIC.mjs → providers-5ZN3MO6E.mjs} +6 -6
  95. package/dist/cli/{providers-S4WMWHBW.js → providers-LTYNEXLB.js} +9 -9
  96. package/dist/cli/{quickstart-NLAIOXVY.mjs → quickstart-ENDTTNLE.mjs} +4 -4
  97. package/dist/cli/{quickstart-GET2M3BQ.js → quickstart-UBDHX7PT.js} +6 -6
  98. package/dist/cli/{run-BOHHBZSI.js → run-6O6LQVWD.js} +44 -44
  99. package/dist/cli/{run-R2RYHNVS.mjs → run-QJJSP35C.mjs} +23 -23
  100. package/dist/cli/{search-VBIVRRRO.mjs → search-PXZPVXDK.mjs} +7 -7
  101. package/dist/cli/search-TYPJWK4I.js +32 -0
  102. package/dist/cli/{search-output-EVNRKEGZ.js → search-output-H3ZQLJUF.js} +6 -6
  103. package/dist/cli/{search-output-OCYIQFV6.mjs → search-output-KRR4YOJX.mjs} +4 -4
  104. package/dist/cli/{secrets-TNCO45WJ.mjs → secrets-HIGERL4N.mjs} +6 -6
  105. package/dist/cli/{secrets-52T2SCZ5.js → secrets-QZMXBI64.js} +15 -15
  106. package/dist/cli/{sessions-4XE7AR3A.mjs → sessions-4SGQAX3F.mjs} +6 -6
  107. package/dist/cli/sessions-OS4ZBU4K.js +23 -0
  108. package/dist/cli/{settings-TKRF2B3K.js → settings-FFTTVDRV.js} +85 -85
  109. package/dist/cli/{settings-ZFCHR7MW.mjs → settings-UQLHVBOP.mjs} +12 -12
  110. package/dist/cli/{setup-QY3ZML4C.mjs → setup-R5MBUG5M.mjs} +9 -9
  111. package/dist/cli/{setup-AWNE4VNL.js → setup-SS3MABJP.js} +49 -49
  112. package/dist/cli/skills-FVDSEEUL.js +37 -0
  113. package/dist/cli/{skills-GUGJDCFY.mjs → skills-X6PNEVWX.mjs} +7 -7
  114. package/dist/cli/tools-ORTGWD63.js +57 -0
  115. package/dist/cli/{tools-NBKPWOWD.mjs → tools-YFW3FXAB.mjs} +17 -17
  116. package/dist/cli/{update-KLGVIBRY.mjs → update-HX5BNFLQ.mjs} +9 -9
  117. package/dist/cli/update-RWVNNNHN.js +37 -0
  118. package/dist/cli/{views-MDXEIVQ7.js → views-BGCRC22G.js} +21 -21
  119. package/dist/cli/{views-OEOW2EZO.mjs → views-FH5XL2PU.mjs} +6 -6
  120. package/dist/cli/{workflow-PUSTWPW4.js → workflow-UY5PZBIK.js} +17 -17
  121. package/dist/cli/{workflow-LK4SIUOM.mjs → workflow-VLNDGNJI.mjs} +7 -7
  122. package/dist/index.js +9 -9
  123. package/dist/index.mjs +6 -6
  124. package/dist/install-integrity.json +113 -112
  125. package/dist/release.d.mts +1 -1
  126. package/dist/release.d.ts +1 -1
  127. package/dist/release.js +2 -2
  128. package/dist/release.mjs +1 -1
  129. package/dist/server.js +5 -5
  130. package/dist/server.mjs +3 -3
  131. package/package.json +1 -1
  132. package/dist/cli/auth-X2LWGPF4.js +0 -44
  133. package/dist/cli/concurrent-runs-help-QDURIV4N.js +0 -22
  134. package/dist/cli/describe-BY7LKP53.js +0 -50
  135. package/dist/cli/git-CR6PBWBH.js +0 -26
  136. package/dist/cli/search-CZVM2OX5.js +0 -32
  137. package/dist/cli/sessions-GOHYDYMH.js +0 -23
  138. package/dist/cli/skills-54CGCMPF.js +0 -37
  139. package/dist/cli/tools-A7FEGDPX.js +0 -57
  140. package/dist/cli/update-3J52CJHB.js +0 -37
@@ -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.570',
208
+ version: '0.3.571',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -5,6 +5,11 @@ import {
5
5
  import { prepareRetainedPlayPipelinesForTransport } from '../plays/execution-pipeline';
6
6
  import { createWriteStream } from 'node:fs';
7
7
  import { createHash, randomUUID } from 'node:crypto';
8
+ import {
9
+ runtimeApiConnectionProbe,
10
+ settledRuntimeApiConnectionProbe,
11
+ type RuntimeApiConnectionProbe,
12
+ } from './runtime-api-connection-probe';
8
13
  import { stat } from 'node:fs/promises';
9
14
  import { Readable } from 'node:stream';
10
15
  import { pipeline } from 'node:stream/promises';
@@ -423,6 +428,12 @@ export type WorkerRuntimeApiContext = {
423
428
  * gateway record that produced it.
424
429
  */
425
430
  onResponseMeta?: (meta: RuntimeApiResponseMeta) => void;
431
+ /**
432
+ * Measure one fresh connection to this origin once per process (DNS, TCP
433
+ * connect, TLS) off the request path and report it on `onResponseMeta` as
434
+ * `connectionProbe`. Only the runner's receipt gateway context sets it.
435
+ */
436
+ probeConnection?: boolean;
426
437
  /**
427
438
  * Observe each request attempt as it is sent. `onResponseMeta` only fires
428
439
  * for a successful response, so an attempt that is aborted or times out
@@ -517,6 +528,13 @@ export type RuntimeApiResponseMeta = {
517
528
  * network time.
518
529
  */
519
530
  requestBodyPackMs?: number | null;
531
+ /**
532
+ * One fresh connection's setup cost to this origin, measured once per
533
+ * process off the request path (`runtime-api-connection-probe.ts`). Null
534
+ * until it has settled. Compare its `connectMs` with `roundTripMs` to tell
535
+ * path latency from per-request connection setup.
536
+ */
537
+ connectionProbe?: RuntimeApiConnectionProbe | null;
520
538
  };
521
539
 
522
540
  const RUNTIME_API_DIAGNOSTIC_HEADER_MAX_CHARS = 256;
@@ -1737,6 +1755,10 @@ async function postAppRuntimeApiAttempts<TResponse>(
1737
1755
  }
1738
1756
  const runtimeFetch = context.fetch ?? fetch;
1739
1757
  const boundaryLabel = runtimeApiBoundaryLabel(context);
1758
+ // Diagnostic only: one fresh-connection measurement per process and origin,
1759
+ // started on the first observed request and never awaited.
1760
+ if (context.probeConnection && context.onResponseMeta)
1761
+ void runtimeApiConnectionProbe(baseUrl);
1740
1762
  const fastRunLedgerBypass =
1741
1763
  body.action === 'append_run_events' || body.action === 'project_run_events';
1742
1764
  const vercelHeaders = fastRunLedgerBypass
@@ -2015,6 +2037,9 @@ async function postAppRuntimeApiAttempts<TResponse>(
2015
2037
  requestBodyWireBytes: wireBody.wireBytes,
2016
2038
  requestBodySerializeMs,
2017
2039
  requestBodyPackMs,
2040
+ connectionProbe: context.probeConnection
2041
+ ? settledRuntimeApiConnectionProbe(baseUrl)
2042
+ : null,
2018
2043
  });
2019
2044
  } catch {
2020
2045
  // Observation must never affect durable delivery.
@@ -20164,6 +20164,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20164
20164
  // it serialized and what it actually sent.
20165
20165
  gatewayRequestRawBytes: meta.requestBodyRawBytes ?? null,
20166
20166
  gatewayRequestWireBytes: meta.requestBodyWireBytes ?? null,
20167
+ gatewayConnectionProbe: meta.connectionProbe ?? null,
20167
20168
  });
20168
20169
  }
20169
20170
 
@@ -1,3 +1,4 @@
1
+ import type { RuntimeApiConnectionProbe } from './runtime-api-connection-probe';
1
2
  import type { RuntimeMapHeapAdmissionSnapshot } from './map-memory-limits';
2
3
  import type {
3
4
  RuntimeMemoryLedger,
@@ -193,6 +194,8 @@ export type RuntimeResourceObservation = {
193
194
  */
194
195
  gatewayRequestRawBytes?: number | null;
195
196
  gatewayRequestWireBytes?: number | null;
197
+ /** One fresh connection's setup cost to the gateway origin (once per process). */
198
+ gatewayConnectionProbe?: RuntimeApiConnectionProbe | null;
196
199
  /** Completion enqueue to the launch of the batch that carries it. */
197
200
  receiptCompletionQueueMs?: number | null;
198
201
  /**
@@ -455,6 +458,13 @@ export type RuntimeResourceSnapshot = {
455
458
  rawBytes: number;
456
459
  wireBytes: number;
457
460
  };
461
+ /**
462
+ * One fresh connection to the gateway origin, measured once per runner
463
+ * process off the request path: DNS, TCP connect (about one round trip)
464
+ * and TLS. Set against `phases.gatewayRoundTrip` it says whether requests
465
+ * reuse connections. Absent until measured, and on older runners.
466
+ */
467
+ connectionProbe?: RuntimeApiConnectionProbe;
458
468
  };
459
469
  providers: Record<
460
470
  string,
@@ -1348,6 +1358,7 @@ export function createRuntimeResourceGovernor(input: {
1348
1358
  upstreamHeadersMs: 0,
1349
1359
  upstreamBodyMs: 0,
1350
1360
  };
1361
+ let gatewayConnectionProbe: RuntimeApiConnectionProbe | null = null;
1351
1362
  const gatewayAuthSessionCounters = {
1352
1363
  hit: 0,
1353
1364
  miss: 0,
@@ -1754,6 +1765,9 @@ export function createRuntimeResourceGovernor(input: {
1754
1765
  if (observation.gatewayAuthSession != null) {
1755
1766
  gatewayAuthSessionCounters[observation.gatewayAuthSession] += 1;
1756
1767
  }
1768
+ if (observation.gatewayConnectionProbe != null) {
1769
+ gatewayConnectionProbe = observation.gatewayConnectionProbe;
1770
+ }
1757
1771
  // Raw is the authority for the count: every request has serialized bytes,
1758
1772
  // so a missing wire size (an older transport) adds nothing rather than
1759
1773
  // silently reporting a request that moved zero bytes.
@@ -2225,6 +2239,9 @@ export function createRuntimeResourceGovernor(input: {
2225
2239
  },
2226
2240
  authSession: { ...gatewayAuthSessionCounters },
2227
2241
  requestBody: { ...gatewayRequestBodyCounters },
2242
+ ...(gatewayConnectionProbe
2243
+ ? { connectionProbe: { ...gatewayConnectionProbe } }
2244
+ : {}),
2228
2245
  },
2229
2246
  rows: {
2230
2247
  acquired: rowCounters.acquired,
@@ -2692,6 +2692,8 @@ async function run(
2692
2692
  boundary: 'receipt_gateway' as const,
2693
2693
  requestTimeoutMs: RUNTIME_RECEIPT_GATEWAY_REQUEST_TIMEOUT_MS,
2694
2694
  onResponseMeta: receiptGatewayResponseObserver.onResponseMeta,
2695
+ // One fresh-connection measurement per runner process (diagnostic).
2696
+ probeConnection: true,
2695
2697
  }
2696
2698
  : null;
2697
2699
  const canUseRuntimeStepReceipts = playRunnerRuntimeReceiptsEnabled(
@@ -0,0 +1,199 @@
1
+ import { lookup } from 'node:dns/promises';
2
+ import { connect as tlsConnect, type TLSSocket } from 'node:tls';
3
+
4
+ /**
5
+ * One fresh connection's setup cost to the runtime API origin, measured once
6
+ * per runner process and origin, off the request path.
7
+ *
8
+ * Why: a receipt gateway round trip from a Modal sandbox is ~83 ms at p50
9
+ * while the gateway's own work is ~9 ms (Production, 2026-11-30). This probe
10
+ * separates path latency from per-request connection setup: compare
11
+ * `connectMs` (one TCP round trip) with the run's `gatewayRoundTrip`. A round
12
+ * trip near `connectMs` means requests reuse a connection; near
13
+ * `connectMs + tlsMs + connectMs` means each request pays a new connection.
14
+ *
15
+ * Bounded and allowlisted: numbers, the negotiated TLS protocol and ALPN, and a
16
+ * short error code. Never the URL, host, address, or any header.
17
+ */
18
+ export type RuntimeApiConnectionProbe = {
19
+ outcome: 'ok' | 'error' | 'timeout';
20
+ /** DNS resolution of the origin host. */
21
+ dnsMs: number | null;
22
+ /** TCP connect: about one network round trip. */
23
+ connectMs: number | null;
24
+ /** TLS handshake after TCP connect. */
25
+ tlsMs: number | null;
26
+ totalMs: number;
27
+ tlsProtocol: string | null;
28
+ alpn: string | null;
29
+ errorCode: string | null;
30
+ };
31
+
32
+ export const RUNTIME_API_CONNECTION_PROBE_TIMEOUT_MS = 2_000;
33
+ const ERROR_CODE_PATTERN = /^[A-Z0-9_]{1,40}$/;
34
+ const TLS_PROTOCOL_PATTERN = /^TLSv1(\.[0-3])?$/;
35
+ const ALPN_PATTERN = /^(h2|http\/1\.1)$/;
36
+
37
+ const probes = new Map<string, Promise<RuntimeApiConnectionProbe | null>>();
38
+ const settled = new Map<string, RuntimeApiConnectionProbe | null>();
39
+
40
+ type ProbeDeps = {
41
+ lookup: (host: string) => Promise<{ address: string; family: number }>;
42
+ connect: typeof tlsConnect;
43
+ now: () => number;
44
+ timeoutMs: number;
45
+ };
46
+
47
+ const DEFAULT_DEPS: ProbeDeps = {
48
+ lookup: (host) => lookup(host),
49
+ connect: tlsConnect,
50
+ now: () => performance.now(),
51
+ timeoutMs: RUNTIME_API_CONNECTION_PROBE_TIMEOUT_MS,
52
+ };
53
+
54
+ function round(ms: number): number {
55
+ return Math.max(0, Math.round(ms));
56
+ }
57
+
58
+ function errorCodeOf(error: unknown): string | null {
59
+ const code = (error as { code?: unknown } | null)?.code;
60
+ return typeof code === 'string' && ERROR_CODE_PATTERN.test(code)
61
+ ? code
62
+ : null;
63
+ }
64
+
65
+ /** Measure one fresh connection to `baseUrl`'s origin. Never throws. */
66
+ export async function measureRuntimeApiConnection(
67
+ baseUrl: string,
68
+ deps: ProbeDeps = DEFAULT_DEPS,
69
+ ): Promise<RuntimeApiConnectionProbe | null> {
70
+ let url: URL;
71
+ try {
72
+ url = new URL(baseUrl);
73
+ } catch {
74
+ return null;
75
+ }
76
+ if (url.protocol !== 'https:') return null;
77
+ const port = url.port ? Number(url.port) : 443;
78
+ const startedAt = deps.now();
79
+ let dnsMs: number | null = null;
80
+ let connectMs: number | null = null;
81
+ let tlsMs: number | null = null;
82
+ let socket: TLSSocket | null = null;
83
+ const result = (
84
+ outcome: RuntimeApiConnectionProbe['outcome'],
85
+ extra: Partial<RuntimeApiConnectionProbe> = {},
86
+ ): RuntimeApiConnectionProbe => ({
87
+ outcome,
88
+ dnsMs,
89
+ connectMs,
90
+ tlsMs,
91
+ totalMs: round(deps.now() - startedAt),
92
+ tlsProtocol: null,
93
+ alpn: null,
94
+ errorCode: null,
95
+ ...extra,
96
+ });
97
+ let timer: ReturnType<typeof setTimeout> | undefined;
98
+ const timeout = new Promise<RuntimeApiConnectionProbe>((resolve) => {
99
+ timer = setTimeout(() => resolve(result('timeout')), deps.timeoutMs);
100
+ (timer as { unref?: () => void }).unref?.();
101
+ });
102
+ const measured = (async (): Promise<RuntimeApiConnectionProbe> => {
103
+ try {
104
+ const dnsStartedAt = deps.now();
105
+ const { address } = await deps.lookup(url.hostname);
106
+ dnsMs = round(deps.now() - dnsStartedAt);
107
+ const connectStartedAt = deps.now();
108
+ return await new Promise<RuntimeApiConnectionProbe>((resolve) => {
109
+ let tcpAt: number | null = null;
110
+ socket = deps.connect({
111
+ host: address,
112
+ port,
113
+ servername: url.hostname,
114
+ ALPNProtocols: ['h2', 'http/1.1'],
115
+ });
116
+ socket.once('connect', () => {
117
+ tcpAt = deps.now();
118
+ connectMs = round(tcpAt - connectStartedAt);
119
+ });
120
+ socket.once('secureConnect', () => {
121
+ const secureAt = deps.now();
122
+ tlsMs = round(secureAt - (tcpAt ?? connectStartedAt));
123
+ const protocol = socket?.getProtocol?.() ?? null;
124
+ const alpn = socket?.alpnProtocol;
125
+ resolve(
126
+ result('ok', {
127
+ tlsProtocol:
128
+ typeof protocol === 'string' &&
129
+ TLS_PROTOCOL_PATTERN.test(protocol)
130
+ ? protocol
131
+ : null,
132
+ alpn:
133
+ typeof alpn === 'string' && ALPN_PATTERN.test(alpn)
134
+ ? alpn
135
+ : null,
136
+ }),
137
+ );
138
+ });
139
+ // Persistent: a socket that errors again after the first error (or
140
+ // after destroy) must never surface an unhandled 'error' event in
141
+ // the runner process. Resolving twice is a no-op.
142
+ socket.on('error', (error) =>
143
+ resolve(result('error', { errorCode: errorCodeOf(error) })),
144
+ );
145
+ });
146
+ } catch (error) {
147
+ return result('error', { errorCode: errorCodeOf(error) });
148
+ }
149
+ })();
150
+ try {
151
+ return await Promise.race([measured, timeout]);
152
+ } finally {
153
+ clearTimeout(timer);
154
+ (socket as TLSSocket | null)?.destroy();
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Start the probe for `baseUrl`'s origin once per process; later calls share
160
+ * the first. The returned promise never rejects.
161
+ */
162
+ export function runtimeApiConnectionProbe(
163
+ baseUrl: string,
164
+ ): Promise<RuntimeApiConnectionProbe | null> {
165
+ let origin: string;
166
+ try {
167
+ origin = new URL(baseUrl).origin;
168
+ } catch {
169
+ return Promise.resolve(null);
170
+ }
171
+ let probe = probes.get(origin);
172
+ if (!probe) {
173
+ probe = measureRuntimeApiConnection(origin)
174
+ .catch(() => null)
175
+ .then((value) => {
176
+ settled.set(origin, value);
177
+ return value;
178
+ });
179
+ probes.set(origin, probe);
180
+ }
181
+ return probe;
182
+ }
183
+
184
+ /** The probe for `baseUrl`'s origin once it has settled; null until then. */
185
+ export function settledRuntimeApiConnectionProbe(
186
+ baseUrl: string,
187
+ ): RuntimeApiConnectionProbe | null {
188
+ try {
189
+ return settled.get(new URL(baseUrl).origin) ?? null;
190
+ } catch {
191
+ return null;
192
+ }
193
+ }
194
+
195
+ /** Test seam: forget probes so each test starts fresh. */
196
+ export function resetRuntimeApiConnectionProbesForTests(): void {
197
+ probes.clear();
198
+ settled.clear();
199
+ }
@@ -20314,6 +20314,49 @@ export async function executePostgresSchedulerClaim(
20314
20314
  terminalFailureResult,
20315
20315
  options.terminalLogOutbox,
20316
20316
  );
20317
+ // A stop committed before this failure is the run's real outcome: the
20318
+ // cancellation's own sandbox termination is what usually fails a launch
20319
+ // ("Modal Sandbox is shutting down"). Settle it through the owner's
20320
+ // cancellation transition instead of recording a failure; the queued
20321
+ // request's reconciler then finds the run terminal and retires it. The
20322
+ // typed-wait failure path keeps its own guard for this case, and a
20323
+ // preserved runner terminal (detached recovery) is never overridden: a
20324
+ // runner that already pushed its own terminal keeps it.
20325
+ if (
20326
+ !options.protectWaitingSuspensionFailure &&
20327
+ !options.preserveRunnerTerminal
20328
+ ) {
20329
+ const requestedCancellation = await client.query<{
20330
+ reason: string | null;
20331
+ }>(
20332
+ `SELECT value->>'reason' AS reason
20333
+ FROM ${tableName('control', options)}
20334
+ WHERE key = 'runtime_cancel:' || $1`,
20335
+ [claim.runId],
20336
+ );
20337
+ const cancellation = requestedCancellation.rows[0];
20338
+ if (
20339
+ cancellation &&
20340
+ (await cancelPostgresSchedulerRun(
20341
+ client,
20342
+ {
20343
+ runId: claim.runId,
20344
+ reason: cancellation.reason?.trim() || 'Cancelled play run.',
20345
+ },
20346
+ options,
20347
+ ))
20348
+ ) {
20349
+ console.info(
20350
+ '[postgres-scheduler] failure_superseded_by_cancellation',
20351
+ {
20352
+ runId: claim.runId,
20353
+ attempt: claim.attempt,
20354
+ error: message.slice(0, 500),
20355
+ },
20356
+ );
20357
+ return { status: 'idle' };
20358
+ }
20359
+ }
20317
20360
  const failed = await failPostgresSchedulerAttempt(
20318
20361
  client,
20319
20362
  {
@@ -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-C6XV2DPY.mjs";
18
+ import "./chunk-QRMTITKL.mjs";
19
+ import "./chunk-CR6IPQBB.mjs";
20
+ import "./chunk-A3IVPA6Q.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-Z3DSCE5F.mjs";
26
26
  import "./chunk-WZYKRD7T.mjs";
27
27
  import "./chunk-KRD6H754.mjs";
28
28
  export {
@@ -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 _chunk2IZOCGOAjs = require('./chunk-2IZOCGOA.js');
18
+ require('./chunk-6N3NTEJ6.js');
19
+ require('./chunk-A5HDA22N.js');
20
+ require('./chunk-7JGHNZTD.js');
21
+ require('./chunk-6VLFQZK6.js');
22
+ require('./chunk-XNYIZMNQ.js');
23
+ require('./chunk-LFQJW4S2.js');
24
+ require('./chunk-CFJFUVX2.js');
25
+ require('./chunk-IFKZQCPX.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 = _chunk2IZOCGOAjs.EXIT_WORKSPACE_MISMATCH; exports.authStatusLine = _chunk2IZOCGOAjs.authStatusLine; exports.clearPendingClaim = _chunk2IZOCGOAjs.clearPendingClaim; exports.clearSatisfiedPendingClaim = _chunk2IZOCGOAjs.clearSatisfiedPendingClaim; exports.handleRegister = _chunk2IZOCGOAjs.handleRegister; exports.handleStatus = _chunk2IZOCGOAjs.handleStatus; exports.handleWait = _chunk2IZOCGOAjs.handleWait; exports.httpJson = _chunk2IZOCGOAjs.httpJson; exports.readPendingAuthClaim = _chunk2IZOCGOAjs.readPendingAuthClaim; exports.readStatusBanner = _chunk2IZOCGOAjs.readStatusBanner; exports.registerAuthCommands = _chunk2IZOCGOAjs.registerAuthCommands; exports.reportApprovalLinkShown = _chunk2IZOCGOAjs.reportApprovalLinkShown; exports.reportSetupCompleted = _chunk2IZOCGOAjs.reportSetupCompleted; exports.resolvePendingAuthClaimForResume = _chunk2IZOCGOAjs.resolvePendingAuthClaimForResume; exports.statusBannerLine = _chunk2IZOCGOAjs.statusBannerLine;