deepline 0.3.497 → 0.3.499

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 (135) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +2 -0
  3. package/dist/bundling-sources/shared_libs/monitors/billing/state.ts +8 -1
  4. package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +23 -5
  5. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +4 -3
  6. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
  7. package/dist/bundling-sources/shared_libs/observability/scheduled-work-control.ts +2 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/play-admission-outcome.ts +8 -3
  9. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +470 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +318 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +7 -4
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +4 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +19 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +138 -0
  15. package/dist/cli/auth-32FRISRT.js +43 -0
  16. package/dist/cli/{auth-OAKBFUQD.mjs → auth-TECJ27G3.mjs} +5 -5
  17. package/dist/cli/{billing-AM6D2KN5.mjs → billing-PMKO73VG.mjs} +6 -6
  18. package/dist/cli/{billing-FUB6HQZ5.js → billing-ULZGAED6.js} +79 -79
  19. package/dist/cli/{chunk-V2EVSEUD.js → chunk-2PKZ3RUU.js} +16 -16
  20. package/dist/cli/{chunk-SLS3HUVC.js → chunk-2RZHMCDL.js} +4 -4
  21. package/dist/cli/{chunk-3IVAGF4P.mjs → chunk-3GP52OHV.mjs} +10 -10
  22. package/dist/cli/{chunk-KFJV3BZX.mjs → chunk-43ZERPGR.mjs} +1 -1
  23. package/dist/cli/{chunk-FISH2MI2.mjs → chunk-56JE475N.mjs} +9 -5
  24. package/dist/cli/{chunk-6TA2H7CY.js → chunk-57LW4TGY.js} +26 -26
  25. package/dist/cli/{chunk-MBOAXLWC.mjs → chunk-5IDORX4E.mjs} +4 -4
  26. package/dist/cli/{chunk-XLYJ7MJX.js → chunk-7OQZZHZ4.js} +15 -11
  27. package/dist/cli/{chunk-EWQ3KY5U.mjs → chunk-7UC2UZYW.mjs} +6 -6
  28. package/dist/cli/{chunk-JDFYCHNV.js → chunk-7WUMIRBV.js} +5 -5
  29. package/dist/cli/{chunk-5GXYXU45.mjs → chunk-A2VCFBZN.mjs} +1 -1
  30. package/dist/cli/{chunk-7RBIOOCQ.js → chunk-AGZRRHSB.js} +3 -3
  31. package/dist/cli/{chunk-SJM7MKOE.js → chunk-AKLI4XSG.js} +2 -2
  32. package/dist/cli/{chunk-4MR7LZXF.mjs → chunk-BBFWIYAF.mjs} +2 -2
  33. package/dist/cli/{chunk-XNLXHU6L.mjs → chunk-C2V5U6HO.mjs} +5 -5
  34. package/dist/cli/{chunk-OWDK2PVH.js → chunk-FG5OZ5FB.js} +8 -8
  35. package/dist/cli/{chunk-BRUDMG56.js → chunk-G7BB2VOC.js} +41 -41
  36. package/dist/cli/{chunk-IURXJPGH.mjs → chunk-IGCSKXGK.mjs} +3 -3
  37. package/dist/cli/{chunk-WKCMARFR.js → chunk-JIZHGOZ5.js} +94 -94
  38. package/dist/cli/{chunk-WZ3A35ZD.mjs → chunk-JM52ATUS.mjs} +1 -1
  39. package/dist/cli/{chunk-KUX3HYJI.mjs → chunk-JQHJKARU.mjs} +28 -22
  40. package/dist/cli/{chunk-5IBHSACU.mjs → chunk-JUQESEJX.mjs} +2 -2
  41. package/dist/cli/{chunk-ZLYKN4AJ.js → chunk-K54BUQSK.js} +7 -7
  42. package/dist/cli/{chunk-FVS5MJQ5.js → chunk-KLQ5CR77.js} +30 -24
  43. package/dist/cli/{chunk-VMOVB2FN.mjs → chunk-KOD45UP5.mjs} +5 -5
  44. package/dist/cli/{chunk-SJID5WMV.mjs → chunk-KZJKRU24.mjs} +4 -4
  45. package/dist/cli/{chunk-BBHGJE73.js → chunk-L6C7C7IJ.js} +1 -1
  46. package/dist/cli/{chunk-DKSTMQ3F.js → chunk-L7O7AFSF.js} +21 -21
  47. package/dist/cli/{chunk-YUEFDOME.js → chunk-LUNXREUI.js} +6 -6
  48. package/dist/cli/{chunk-3DHPKENA.mjs → chunk-MQ5YPD7K.mjs} +1 -1
  49. package/dist/cli/{chunk-LPCK5KK5.mjs → chunk-OWHQ4OG5.mjs} +2 -2
  50. package/dist/cli/{chunk-YQ66NC4J.mjs → chunk-P3MGNLZF.mjs} +2 -2
  51. package/dist/cli/{chunk-B4Q3EBQX.js → chunk-PE3UHMMZ.js} +5 -5
  52. package/dist/cli/{chunk-M2WIEW2E.mjs → chunk-PSYGSXDS.mjs} +1 -1
  53. package/dist/cli/{chunk-THD6KA67.mjs → chunk-QXI2W7YY.mjs} +4 -4
  54. package/dist/cli/{chunk-OEI6HXMK.js → chunk-SLWCXGKP.js} +16 -16
  55. package/dist/cli/{chunk-2HCZHIMT.mjs → chunk-TFFJ2PRN.mjs} +5 -3
  56. package/dist/cli/{chunk-7FFNSYMJ.js → chunk-TUDYBF4Y.js} +9 -9
  57. package/dist/cli/{chunk-UETGYJYH.mjs → chunk-UMPCQ4EE.mjs} +2 -2
  58. package/dist/cli/{chunk-A66Y2LCW.js → chunk-UOQUCFAK.js} +53 -53
  59. package/dist/cli/{chunk-TGAYN34A.mjs → chunk-WEVIUQGZ.mjs} +2 -2
  60. package/dist/cli/{chunk-77IAUCTB.js → chunk-WSOM3TY6.js} +3 -3
  61. package/dist/cli/{chunk-3KG2FUU4.js → chunk-XSUQAUG4.js} +7 -7
  62. package/dist/cli/{chunk-HRODQDTB.mjs → chunk-YAW7ET4P.mjs} +1 -1
  63. package/dist/cli/{chunk-N3T3L3WW.js → chunk-YPTZJ7LO.js} +5 -3
  64. package/dist/cli/{chunk-UV7AT2D4.js → chunk-YRQWGWRJ.js} +2 -2
  65. package/dist/cli/{chunk-WXW7YJDO.js → chunk-Z2MO7FZG.js} +53 -53
  66. package/dist/cli/{chunk-XX7WLKOQ.mjs → chunk-ZVAD65CF.mjs} +1 -1
  67. package/dist/cli/command-docs.js +2 -2
  68. package/dist/cli/command-docs.mjs +1 -1
  69. package/dist/cli/{csv-U2GOFP3M.mjs → csv-ACO5YC46.mjs} +4 -4
  70. package/dist/cli/{csv-PMBYKVUU.js → csv-VGSQ3JYE.js} +13 -13
  71. package/dist/cli/{db-DKFOTZGZ.mjs → db-CXNZOXGM.mjs} +6 -6
  72. package/dist/cli/{db-GREVTMIR.js → db-QOUPHFFN.js} +27 -27
  73. package/dist/cli/describe-DEXYQMBO.js +50 -0
  74. package/dist/cli/{describe-SWXA6L62.mjs → describe-J4O5GCJS.mjs} +17 -17
  75. package/dist/cli/{executions-EBRFC5JR.mjs → executions-SJETRLXW.mjs} +6 -6
  76. package/dist/cli/{executions-2RRAESQK.js → executions-YIECH2CL.js} +8 -8
  77. package/dist/cli/{feedback-N6ML7IRH.js → feedback-5BRCNERV.js} +8 -8
  78. package/dist/cli/{feedback-4A57QLX2.mjs → feedback-GSAFFMF6.mjs} +4 -4
  79. package/dist/cli/git-RDKLITUC.js +25 -0
  80. package/dist/cli/{git-6D2WQPOS.mjs → git-SF5XIGLU.mjs} +5 -5
  81. package/dist/cli/index.js +141 -141
  82. package/dist/cli/index.mjs +41 -41
  83. package/dist/cli/{legacy-noops-DXRJARNC.js → legacy-noops-5TBT4XC6.js} +8 -8
  84. package/dist/cli/{legacy-noops-CL5QWXGH.mjs → legacy-noops-TZA3CALE.mjs} +5 -5
  85. package/dist/cli/{monitors-SGMEGGJO.mjs → monitors-XAYWJNSV.mjs} +7 -7
  86. package/dist/cli/{monitors-XWKDVHYL.js → monitors-XNB5YNC3.js} +95 -95
  87. package/dist/cli/{org-QKQ57PDN.js → org-2UYWJXG7.js} +72 -72
  88. package/dist/cli/{org-55BI5RQF.mjs → org-S5VZL5KZ.mjs} +6 -6
  89. package/dist/cli/{pages-LM4QACOM.mjs → pages-NGVJO7PA.mjs} +6 -6
  90. package/dist/cli/{pages-FOIR5UH4.js → pages-ZQRRTZIT.js} +18 -18
  91. package/dist/cli/{play-7VA26O6E.mjs → play-3JNERHSC.mjs} +37 -27
  92. package/dist/cli/{play-S44FXGD7.js → play-P3OYQ7JV.js} +406 -396
  93. package/dist/cli/{providers-QAVIR5E2.mjs → providers-27O6BOAP.mjs} +6 -6
  94. package/dist/cli/{providers-RDSHID7C.js → providers-2FFGAPUR.js} +9 -9
  95. package/dist/cli/{quickstart-EREQPM3G.js → quickstart-5G2UPKJV.js} +6 -6
  96. package/dist/cli/{quickstart-IL4HQYE4.mjs → quickstart-B2EXIAU6.mjs} +4 -4
  97. package/dist/cli/{run-TBUUV5EG.js → run-2TGD7FAL.js} +82 -43
  98. package/dist/cli/{run-4XZNJR7N.mjs → run-3QFXYV3Z.mjs} +69 -30
  99. package/dist/cli/{search-SYT5UT5G.mjs → search-GXEEOMVD.mjs} +7 -7
  100. package/dist/cli/search-YKTYDBCN.js +32 -0
  101. package/dist/cli/{search-output-Y3IKZ3TX.mjs → search-output-DMIJQTAA.mjs} +4 -4
  102. package/dist/cli/{search-output-5F3EEQ34.js → search-output-I4RZPHU6.js} +6 -6
  103. package/dist/cli/{secrets-AKAU2N3K.mjs → secrets-DQI5YCS6.mjs} +6 -6
  104. package/dist/cli/{secrets-PZWJ2ES5.js → secrets-MJMNRXZX.js} +15 -15
  105. package/dist/cli/{sessions-Z5C26IS7.mjs → sessions-HAUN3VYE.mjs} +5 -5
  106. package/dist/cli/{sessions-UMHA7K23.js → sessions-QS74ZTRH.js} +6 -6
  107. package/dist/cli/{settings-S5BM3SVI.mjs → settings-E64HIUXW.mjs} +11 -11
  108. package/dist/cli/{settings-WGJYWTJZ.js → settings-VQBOS6VU.js} +78 -78
  109. package/dist/cli/{setup-6K6ERKOH.js → setup-KRW3JCJE.js} +49 -49
  110. package/dist/cli/{setup-E4HRXP2X.mjs → setup-NRUG42F2.mjs} +9 -9
  111. package/dist/cli/{skills-HIZA7YAN.mjs → skills-AHLZRTKZ.mjs} +7 -7
  112. package/dist/cli/skills-PGVIJK6Q.js +36 -0
  113. package/dist/cli/{tools-FS5S6BT7.mjs → tools-INRRIWOU.mjs} +16 -16
  114. package/dist/cli/tools-IXXN2RE4.js +57 -0
  115. package/dist/cli/{update-4CJPTG3L.mjs → update-ETOWEJ7D.mjs} +9 -9
  116. package/dist/cli/update-QW4RV2UX.js +34 -0
  117. package/dist/cli/{workflow-UMSXOIOS.mjs → workflow-JT2DOSCJ.mjs} +7 -7
  118. package/dist/cli/{workflow-TYSZ5JWS.js → workflow-RUAYQK4D.js} +17 -17
  119. package/dist/index.js +9 -9
  120. package/dist/index.mjs +6 -6
  121. package/dist/install-integrity.json +102 -100
  122. package/dist/release.d.mts +1 -1
  123. package/dist/release.d.ts +1 -1
  124. package/dist/release.js +2 -2
  125. package/dist/release.mjs +1 -1
  126. package/dist/server.js +5 -5
  127. package/dist/server.mjs +3 -3
  128. package/package.json +1 -1
  129. package/dist/cli/auth-553ZBCPJ.js +0 -43
  130. package/dist/cli/describe-BL5NNHV5.js +0 -50
  131. package/dist/cli/git-7TSX5V57.js +0 -25
  132. package/dist/cli/search-GCANFVVZ.js +0 -32
  133. package/dist/cli/skills-J3GQHHHL.js +0 -36
  134. package/dist/cli/tools-RZYKMOUX.js +0 -57
  135. package/dist/cli/update-CATZW7GA.js +0 -34
@@ -0,0 +1,318 @@
1
+ import { RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES } from './output-size-limits';
2
+
3
+ /**
4
+ * Named, versioned Runtime gateway profiles. A profile decides where a run's
5
+ * receipt and execution gateways are served. Absence keeps today's Fly
6
+ * gateways. Changing what a profile means creates a new version: a queued
7
+ * launch keeps the meaning it was admitted with.
8
+ */
9
+ export const RUNTIME_GATEWAY_PROFILE_IDS = {
10
+ vercelApp: 'vercel_app@1',
11
+ } as const;
12
+
13
+ export type RuntimeGatewayProfileId =
14
+ (typeof RUNTIME_GATEWAY_PROFILE_IDS)[keyof typeof RUNTIME_GATEWAY_PROFILE_IDS];
15
+
16
+ export type RuntimeGatewayProfile = Readonly<{
17
+ id: RuntimeGatewayProfileId;
18
+ /** Gateways run inside the immutable app deployment that admitted the run. */
19
+ hosting: 'admitting_app_deployment';
20
+ receiptPath: '/api/receipt';
21
+ executionPath: '/api/execution';
22
+ /** Oldest pin a new attempt or resumed sandbox may still use. */
23
+ maxPinAgeMs: number;
24
+ /** Scheduler Postgres clients one gateway function instance may hold. */
25
+ poolMaxClients: number;
26
+ /** Same request ceiling as the Fly gateway contract. */
27
+ requestBodyMaxBytes: number;
28
+ }>;
29
+
30
+ export const RUNTIME_GATEWAY_PROFILES: Readonly<
31
+ Record<RuntimeGatewayProfileId, RuntimeGatewayProfile>
32
+ > = Object.freeze({
33
+ [RUNTIME_GATEWAY_PROFILE_IDS.vercelApp]: Object.freeze({
34
+ id: RUNTIME_GATEWAY_PROFILE_IDS.vercelApp,
35
+ hosting: 'admitting_app_deployment',
36
+ receiptPath: '/api/receipt',
37
+ executionPath: '/api/execution',
38
+ maxPinAgeMs: 6 * 60 * 60 * 1_000,
39
+ poolMaxClients: 2,
40
+ requestBodyMaxBytes: RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES,
41
+ }),
42
+ });
43
+
44
+ const RUNTIME_GATEWAY_PROFILE_ID_SET: ReadonlySet<string> = new Set(
45
+ Object.values(RUNTIME_GATEWAY_PROFILE_IDS),
46
+ );
47
+
48
+ export function normalizeRuntimeGatewayProfileId(
49
+ value: unknown,
50
+ ): RuntimeGatewayProfileId | undefined {
51
+ if (typeof value !== 'string') return undefined;
52
+ const normalized = value.trim();
53
+ return RUNTIME_GATEWAY_PROFILE_ID_SET.has(normalized)
54
+ ? (normalized as RuntimeGatewayProfileId)
55
+ : undefined;
56
+ }
57
+
58
+ export function resolveRuntimeGatewayProfile(
59
+ id: string,
60
+ ): RuntimeGatewayProfile {
61
+ const normalized = normalizeRuntimeGatewayProfileId(id);
62
+ if (!normalized) {
63
+ throw new RuntimeGatewayLaunchError(
64
+ 'runtime_gateway_profile_unknown',
65
+ `Unknown Runtime gateway profile ${JSON.stringify(id)}.`,
66
+ );
67
+ }
68
+ return RUNTIME_GATEWAY_PROFILES[normalized];
69
+ }
70
+
71
+ /** Optional executor-token request field advertising pinned-launch support. */
72
+ export const RUNTIME_GATEWAY_PROFILE_READER_FIELD =
73
+ 'runtimeGatewayProfileReader';
74
+ /** Presence flag value (the contract's `1`); never compared as a version. */
75
+ export const RUNTIME_GATEWAY_PROFILE_READER_FLAG = 1;
76
+ /** 409 body `error` when a pinned launch's worker does not advertise the reader. */
77
+ export const RUNTIME_GATEWAY_PROFILE_READER_REQUIRED_ERROR =
78
+ 'runtime_gateway_profile_reader_required';
79
+
80
+ export type RuntimeGatewayLaunchErrorCode =
81
+ | 'runtime_gateway_pin_expired'
82
+ | 'runtime_gateway_pin_invalid'
83
+ | 'runtime_gateway_profile_unknown'
84
+ | typeof RUNTIME_GATEWAY_PROFILE_READER_REQUIRED_ERROR
85
+ | 'runtime_gateway_executor_token_unpinned'
86
+ | 'runtime_gateway_oidc_unavailable';
87
+
88
+ /**
89
+ * A pinned launch that cannot run on its pinned gateway. Deterministic: a
90
+ * retry cannot fix it, and falling back to Fly gateways would silently drop
91
+ * the pin, so callers terminalize the attempt with this code.
92
+ */
93
+ export class RuntimeGatewayLaunchError extends Error {
94
+ constructor(
95
+ readonly code: RuntimeGatewayLaunchErrorCode,
96
+ message: string,
97
+ ) {
98
+ super(`${code}: ${message}`);
99
+ this.name = 'RuntimeGatewayLaunchError';
100
+ }
101
+ }
102
+
103
+ export function isRuntimeGatewayLaunchError(
104
+ error: unknown,
105
+ ): error is RuntimeGatewayLaunchError {
106
+ return error instanceof RuntimeGatewayLaunchError;
107
+ }
108
+
109
+ /** Optional launch fields. Every one is absent on unpinned launches. */
110
+ export type RuntimeGatewayLaunchFields = {
111
+ runtimeGatewayProfileId?: string | null;
112
+ runtimeReceiptGatewayBaseUrl?: string | null;
113
+ runtimeExecutionGatewayBaseUrl?: string | null;
114
+ runtimeGatewayDeploymentId?: string | null;
115
+ runtimeGatewayPinnedAtMs?: number | null;
116
+ };
117
+
118
+ export const RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES = [
119
+ 'runtimeGatewayProfileId',
120
+ 'runtimeReceiptGatewayBaseUrl',
121
+ 'runtimeExecutionGatewayBaseUrl',
122
+ 'runtimeGatewayDeploymentId',
123
+ 'runtimeGatewayPinnedAtMs',
124
+ ] as const satisfies readonly (keyof RuntimeGatewayLaunchFields)[];
125
+
126
+ export type RuntimeGatewayLaunchPin = Readonly<{
127
+ profile: RuntimeGatewayProfile;
128
+ deploymentId: string;
129
+ /** `https://<immutable deployment host>` with no path. */
130
+ origin: string;
131
+ receiptGatewayBaseUrl: string;
132
+ executionGatewayBaseUrl: string;
133
+ pinnedAtMs: number;
134
+ }>;
135
+
136
+ const VERCEL_DEPLOYMENT_ID_PATTERN = /^dpl_[A-Za-z0-9]+$/;
137
+
138
+ export function isRuntimeGatewayDeploymentId(value: unknown): value is string {
139
+ return typeof value === 'string' && VERCEL_DEPLOYMENT_ID_PATTERN.test(value);
140
+ }
141
+
142
+ function deploymentOrigin(host: string): string {
143
+ const trimmed = host.trim();
144
+ let url: URL;
145
+ try {
146
+ url = new URL(`https://${trimmed}`);
147
+ } catch {
148
+ throw new RuntimeGatewayLaunchError(
149
+ 'runtime_gateway_pin_invalid',
150
+ 'Runtime gateway deployment host is not a hostname.',
151
+ );
152
+ }
153
+ if (
154
+ url.host !== trimmed.toLowerCase() ||
155
+ url.port ||
156
+ url.username ||
157
+ url.password ||
158
+ url.pathname !== '/' ||
159
+ url.search ||
160
+ url.hash
161
+ ) {
162
+ throw new RuntimeGatewayLaunchError(
163
+ 'runtime_gateway_pin_invalid',
164
+ 'Runtime gateway deployment host must be a bare hostname.',
165
+ );
166
+ }
167
+ return url.origin;
168
+ }
169
+
170
+ /**
171
+ * Build the launch fields that pin a run to the admitting deployment. The app
172
+ * passes its own immutable deployment host and id (VERCEL_URL and
173
+ * VERCEL_DEPLOYMENT_ID of the admitting deployment), never request data.
174
+ */
175
+ export function buildRuntimeGatewayLaunchPin(input: {
176
+ profileId: RuntimeGatewayProfileId;
177
+ deploymentHost: string;
178
+ deploymentId: string;
179
+ nowMs: number;
180
+ }): Required<{
181
+ [K in keyof RuntimeGatewayLaunchFields]: NonNullable<
182
+ RuntimeGatewayLaunchFields[K]
183
+ >;
184
+ }> {
185
+ const profile = resolveRuntimeGatewayProfile(input.profileId);
186
+ if (!isRuntimeGatewayDeploymentId(input.deploymentId)) {
187
+ throw new RuntimeGatewayLaunchError(
188
+ 'runtime_gateway_pin_invalid',
189
+ 'Runtime gateway deployment id is invalid.',
190
+ );
191
+ }
192
+ if (!Number.isSafeInteger(input.nowMs) || input.nowMs <= 0) {
193
+ throw new RuntimeGatewayLaunchError(
194
+ 'runtime_gateway_pin_invalid',
195
+ 'Runtime gateway pin time is invalid.',
196
+ );
197
+ }
198
+ const origin = deploymentOrigin(input.deploymentHost);
199
+ return {
200
+ runtimeGatewayProfileId: profile.id,
201
+ runtimeReceiptGatewayBaseUrl: `${origin}${profile.receiptPath}`,
202
+ runtimeExecutionGatewayBaseUrl: `${origin}${profile.executionPath}`,
203
+ runtimeGatewayDeploymentId: input.deploymentId,
204
+ runtimeGatewayPinnedAtMs: input.nowMs,
205
+ };
206
+ }
207
+
208
+ /**
209
+ * Read a launch's gateway pin. Returns null only when no pin field is
210
+ * present (older or unpinned launches). Any partial, malformed, or unknown
211
+ * pin fails loudly: a reader that cannot honor a pin must never fall back to
212
+ * the worker's configured gateways.
213
+ */
214
+ export function readRuntimeGatewayLaunchPin(
215
+ launch: RuntimeGatewayLaunchFields,
216
+ ): RuntimeGatewayLaunchPin | null {
217
+ const present = RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES.filter(
218
+ (field) => launch[field] !== undefined && launch[field] !== null,
219
+ );
220
+ if (present.length === 0) return null;
221
+ if (present.length !== RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES.length) {
222
+ throw new RuntimeGatewayLaunchError(
223
+ 'runtime_gateway_pin_invalid',
224
+ `Runtime gateway pin is incomplete (present: ${present.join(', ')}).`,
225
+ );
226
+ }
227
+ const profile = resolveRuntimeGatewayProfile(
228
+ String(launch.runtimeGatewayProfileId),
229
+ );
230
+ const deploymentId = launch.runtimeGatewayDeploymentId;
231
+ const pinnedAtMs = launch.runtimeGatewayPinnedAtMs;
232
+ if (!isRuntimeGatewayDeploymentId(deploymentId)) {
233
+ throw new RuntimeGatewayLaunchError(
234
+ 'runtime_gateway_pin_invalid',
235
+ 'Runtime gateway deployment id is invalid.',
236
+ );
237
+ }
238
+ if (
239
+ typeof pinnedAtMs !== 'number' ||
240
+ !Number.isSafeInteger(pinnedAtMs) ||
241
+ pinnedAtMs <= 0
242
+ ) {
243
+ throw new RuntimeGatewayLaunchError(
244
+ 'runtime_gateway_pin_invalid',
245
+ 'Runtime gateway pin time is invalid.',
246
+ );
247
+ }
248
+ let receipt: URL;
249
+ let execution: URL;
250
+ try {
251
+ receipt = new URL(String(launch.runtimeReceiptGatewayBaseUrl));
252
+ execution = new URL(String(launch.runtimeExecutionGatewayBaseUrl));
253
+ } catch {
254
+ throw new RuntimeGatewayLaunchError(
255
+ 'runtime_gateway_pin_invalid',
256
+ 'Runtime gateway URLs are not absolute URLs.',
257
+ );
258
+ }
259
+ const origin = receipt.origin;
260
+ if (
261
+ receipt.protocol !== 'https:' ||
262
+ receipt.port ||
263
+ receipt.username ||
264
+ receipt.password ||
265
+ execution.origin !== origin ||
266
+ launch.runtimeReceiptGatewayBaseUrl !== `${origin}${profile.receiptPath}` ||
267
+ launch.runtimeExecutionGatewayBaseUrl !==
268
+ `${origin}${profile.executionPath}`
269
+ ) {
270
+ throw new RuntimeGatewayLaunchError(
271
+ 'runtime_gateway_pin_invalid',
272
+ `Runtime gateway URLs do not match profile ${profile.id}.`,
273
+ );
274
+ }
275
+ return Object.freeze({
276
+ profile,
277
+ deploymentId,
278
+ origin,
279
+ receiptGatewayBaseUrl: `${origin}${profile.receiptPath}`,
280
+ executionGatewayBaseUrl: `${origin}${profile.executionPath}`,
281
+ pinnedAtMs,
282
+ });
283
+ }
284
+
285
+ /** A new attempt or resumed sandbox may not start on an expired pin. */
286
+ export function assertRuntimeGatewayPinFresh(
287
+ pin: RuntimeGatewayLaunchPin,
288
+ nowMs: number,
289
+ ): void {
290
+ const ageMs = nowMs - pin.pinnedAtMs;
291
+ if (ageMs > pin.profile.maxPinAgeMs) {
292
+ throw new RuntimeGatewayLaunchError(
293
+ 'runtime_gateway_pin_expired',
294
+ `Runtime gateway pin to ${pin.deploymentId} is ${ageMs} ms old; profile ${pin.profile.id} allows ${pin.profile.maxPinAgeMs} ms. Re-run the Play to pin a current deployment.`,
295
+ );
296
+ }
297
+ }
298
+
299
+ /**
300
+ * True only for a code-owned gateway request to the pinned origin under the
301
+ * profile's receipt or execution prefix. Signed object URLs, other origins,
302
+ * and other app paths never receive the gateway credential.
303
+ */
304
+ export function isRuntimeGatewayCredentialTarget(
305
+ pin: Pick<RuntimeGatewayLaunchPin, 'origin' | 'profile'>,
306
+ target: string | URL,
307
+ ): boolean {
308
+ let url: URL;
309
+ try {
310
+ url = new URL(target);
311
+ } catch {
312
+ return false;
313
+ }
314
+ if (url.origin !== pin.origin || url.username || url.password) return false;
315
+ return [pin.profile.receiptPath, pin.profile.executionPath].some(
316
+ (path) => url.pathname === path || url.pathname.startsWith(`${path}/`),
317
+ );
318
+ }
@@ -363,10 +363,13 @@ export const RUNTIME_INCIDENT_DRILL_CATALOG: readonly RuntimeIncidentDrill[] = [
363
363
  control: {
364
364
  kind: 'runtime_test_fault',
365
365
  // The 120-second lease plus 80 seconds of confirmation puts the first
366
- // provider read at about 200 seconds. A further 250 seconds absorbs
367
- // delayed scheduler wakes in the shared Preview lane, so the read still
368
- // lands inside the silence and not after it.
369
- defaultValue: 450_000,
366
+ // provider read at about 200 seconds. Four hosted runs (PR Checks
367
+ // 42718627528, 42726813235, 42726817966, 42727242047) read the provider
368
+ // 3 to 6 seconds after that. The floor of 60 more seconds, ten times the
369
+ // worst lag, absorbs delayed scheduler wakes so the read still lands
370
+ // inside the silence and not after it; a late read fails the drill
371
+ // loudly ("silence ended before it reached its liveness verdict").
372
+ defaultValue: 260_000,
370
373
  valueMeaning: 'milliseconds',
371
374
  },
372
375
  expected: {
@@ -316,7 +316,10 @@ export interface PlaySchedulerBackend {
316
316
  readonly id: PlaySchedulerBackendId;
317
317
 
318
318
  /** Submit a play run; returns a handle to observe / cancel / signal it. */
319
- submit(input: PlaySchedulerSubmitInput): Promise<PlaySchedulerRunHandle>;
319
+ submit(
320
+ input: PlaySchedulerSubmitInput,
321
+ options?: { checkWorkspaceAdmission: () => Promise<void> },
322
+ ): Promise<PlaySchedulerRunHandle>;
320
323
 
321
324
  /** Open a handle to an already-submitted run (e.g. for tail-reconnect). */
322
325
  attach(
@@ -46,6 +46,7 @@ import {
46
46
  RUNTIME_SCHEDULER_CANCEL_STATEMENT_TIMEOUT_MS,
47
47
  withRuntimeSchedulerClient,
48
48
  withRuntimeSchedulerTransaction,
49
+ withWorkspaceAdmissionLock,
49
50
  } from './postgres-pool';
50
51
  import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
51
52
  import { withRuntimeSchedulerSubmitAdmission } from './submit-admission';
@@ -405,7 +406,7 @@ export function createAbsurdSchedulerBackend(
405
406
  const queueSuffix = schedulerOptions.queueSuffix?.trim() || null;
406
407
  return {
407
408
  id: PLAY_SCHEDULER_BACKENDS.absurd,
408
- async submit(input) {
409
+ async submit(input, guards) {
409
410
  const legacyParentRunId = (
410
411
  input as PlaySchedulerSubmitInput & {
411
412
  playCallGovernance?: { parentRunId?: unknown } | null;
@@ -421,6 +422,21 @@ export function createAbsurdSchedulerBackend(
421
422
  const poolOptions = resolveAbsurdPoolOptions(
422
423
  normalizedSchedulerOptions.url,
423
424
  );
425
+ const withAdmissionClient = <T>(
426
+ operation: (client: PostgresSchedulerQueryClient) => Promise<T>,
427
+ trace: { runId: string; phase: string },
428
+ ) =>
429
+ guards
430
+ ? withWorkspaceAdmissionLock(
431
+ poolOptions,
432
+ input.orgId,
433
+ 'shared',
434
+ async (client) => {
435
+ await guards.checkWorkspaceAdmission();
436
+ return operation(client);
437
+ },
438
+ )
439
+ : withRuntimeSchedulerClient(poolOptions, operation, trace);
424
440
  // The run pins its release lane at launch: prefer the release id stamped
425
441
  // in the envelope; fall back to the suffix-derived release for pre-release
426
442
  // launch rows and unit tests (enforce-when-exists / allow-when-absent).
@@ -484,8 +500,7 @@ export function createAbsurdSchedulerBackend(
484
500
  schedulerSchema: normalizedSchedulerOptions.schema ?? null,
485
501
  queueSuffix: queueSuffix ?? null,
486
502
  });
487
- return withRuntimeSchedulerClient(
488
- poolOptions,
503
+ return withAdmissionClient(
489
504
  async (client) =>
490
505
  (
491
506
  await createPlayRunAdmissionJob(
@@ -537,8 +552,7 @@ export function createAbsurdSchedulerBackend(
537
552
  queueSuffix,
538
553
  recoveryReleaseId,
539
554
  );
540
- return withRuntimeSchedulerClient(
541
- poolOptions,
555
+ return withAdmissionClient(
542
556
  async (client) =>
543
557
  (
544
558
  await createPlayRunAdmissionJob(
@@ -24,6 +24,7 @@
24
24
  */
25
25
  import { attachDatabasePool } from '@vercel/functions/db-connections';
26
26
  import { Client, Pool } from 'pg';
27
+ import { randomBytes } from 'node:crypto';
27
28
  import {
28
29
  RuntimeSchedulerPgBouncerCapacityError,
29
30
  RuntimeSchedulerSubmissionAdmissionError,
@@ -1298,6 +1299,30 @@ export async function withRuntimeSchedulerTransaction<T>(
1298
1299
  );
1299
1300
  }
1300
1301
 
1302
+ /** Shared by durable Play admission and the admin transition that closes it. */
1303
+ export async function withWorkspaceAdmissionLock<T>(
1304
+ options: RuntimeSchedulerPoolOptions,
1305
+ orgId: string,
1306
+ mode: 'shared' | 'exclusive',
1307
+ operation: (client: RuntimeSchedulerQueryClient) => Promise<T>,
1308
+ ): Promise<T> {
1309
+ return withRuntimeSchedulerTransaction(
1310
+ options,
1311
+ { lockTimeoutMs: 5_000, statementTimeoutMs: 15_000 },
1312
+ async (client) => {
1313
+ const lock =
1314
+ mode === 'shared'
1315
+ ? 'pg_advisory_xact_lock_shared'
1316
+ : 'pg_advisory_xact_lock';
1317
+ await client.query(
1318
+ `SELECT ${lock}(hashtext('deepline:workspace-admission'), hashtext($1))`,
1319
+ [orgId],
1320
+ );
1321
+ return operation(client);
1322
+ },
1323
+ );
1324
+ }
1325
+
1301
1326
  export type RuntimeSchedulerPoolStats = {
1302
1327
  url: string;
1303
1328
  maxClients: number;
@@ -1457,6 +1482,119 @@ export async function probeRuntimeSchedulerDirectSession(input: {
1457
1482
  }
1458
1483
  }
1459
1484
 
1485
+ /** Explicit backend selection must prove that transaction and session work
1486
+ * reach one database. A successful connection alone cannot prove that: an
1487
+ * ambient direct URL can authenticate against a different server. This uses
1488
+ * only transient locks/notifications, never a table or persisted probe row. */
1489
+ export async function probeRuntimeSchedulerDatabasePair(input: {
1490
+ url: string;
1491
+ eventsReadUrl?: string;
1492
+ applicationName?: string;
1493
+ createDirectClient?: (
1494
+ config: ConstructorParameters<typeof Client>[0],
1495
+ ) => Pick<Client, 'connect' | 'query' | 'end' | 'on'>;
1496
+ }): Promise<void> {
1497
+ const applicationName =
1498
+ input.applicationName ?? 'scheduler-database-pair-preflight';
1499
+ const direct = (input.createDirectClient ?? ((config) => new Client(config)))(
1500
+ {
1501
+ connectionString: deriveDirectDatabaseUrl(input.url),
1502
+ application_name: applicationName,
1503
+ connectionTimeoutMillis: RUNTIME_SCHEDULER_POOL_DEFAULTS.connectTimeoutMs,
1504
+ query_timeout: RUNTIME_SCHEDULER_POOL_DEFAULTS.queryTimeoutMs,
1505
+ },
1506
+ );
1507
+ const nonce = randomBytes(16).toString('hex');
1508
+ const channel = `scheduler_probe_${nonce}`;
1509
+ let notified = false;
1510
+ let disconnected = false;
1511
+ let wake: (() => void) | undefined;
1512
+ let timer: ReturnType<typeof setTimeout> | undefined;
1513
+ try {
1514
+ direct.on('error', () => {
1515
+ disconnected = true;
1516
+ wake?.();
1517
+ });
1518
+ await direct.connect();
1519
+ direct.on('notification', (message) => {
1520
+ if (message.channel === channel && message.payload === nonce) {
1521
+ notified = true;
1522
+ wake?.();
1523
+ }
1524
+ });
1525
+ await direct.query(`LISTEN "${channel}"`);
1526
+ await withRuntimeSchedulerTransaction(
1527
+ {
1528
+ url: input.url,
1529
+ applicationName,
1530
+ maxClients: RUNTIME_SCHEDULER_CONTROL_PLANE_MAX_CLIENTS,
1531
+ },
1532
+ { lockTimeoutMs: 2_000, statementTimeoutMs: 15_000 },
1533
+ async (pooled) => {
1534
+ await pooled.query(
1535
+ 'SELECT pg_advisory_xact_lock(hashtext($1), hashtext($2))',
1536
+ [channel, nonce],
1537
+ );
1538
+ const result = await direct.query(
1539
+ 'SELECT pg_try_advisory_xact_lock(hashtext($1), hashtext($2)) AS acquired',
1540
+ [channel, nonce],
1541
+ );
1542
+ if (result.rows[0]?.acquired !== false)
1543
+ throw Error('Scheduler pooled/direct database authority differs.');
1544
+ if (input.eventsReadUrl) {
1545
+ await withRuntimeSchedulerClient(
1546
+ {
1547
+ url: input.eventsReadUrl,
1548
+ applicationName: `${applicationName}-reader`,
1549
+ maxClients: 1,
1550
+ },
1551
+ async (reader) => {
1552
+ const role = await reader.query(`SELECT
1553
+ (r.rolsuper OR r.rolbypassrls OR r.rolcreaterole OR r.rolcreatedb OR r.rolreplication
1554
+ OR NOT r.rolcanlogin OR EXISTS (SELECT 1 FROM pg_auth_members m
1555
+ WHERE m.member=r.oid OR m.roleid=r.oid)) AS unsafe
1556
+ FROM pg_roles r WHERE r.rolname=current_user`);
1557
+ if (role.rows[0]?.unsafe !== false)
1558
+ throw Error('Scheduler event reader role is not isolated.');
1559
+ const lock = await reader.query(
1560
+ 'SELECT pg_try_advisory_xact_lock(hashtext($1), hashtext($2)) AS acquired',
1561
+ [channel, nonce],
1562
+ );
1563
+ if (lock.rows[0]?.acquired !== false)
1564
+ throw Error(
1565
+ 'Scheduler event reader database authority differs.',
1566
+ );
1567
+ },
1568
+ );
1569
+ }
1570
+ await pooled.query('SELECT pg_notify($1, $2)', [channel, nonce]);
1571
+ },
1572
+ );
1573
+ if (disconnected) throw Error('Scheduler direct session disconnected.');
1574
+ if (!notified)
1575
+ await new Promise<void>((resolve, reject) => {
1576
+ wake = resolve;
1577
+ timer = setTimeout(
1578
+ () =>
1579
+ reject(
1580
+ Error('Scheduler direct-session notification was not proved.'),
1581
+ ),
1582
+ 15_000,
1583
+ );
1584
+ });
1585
+ if (!notified || disconnected)
1586
+ throw Error('Scheduler direct notification was not proved.');
1587
+ } catch {
1588
+ // Provider messages may contain connection identities or credential text.
1589
+ throw Error(
1590
+ 'Scheduler database transaction/session preflight failed. Verify credentials, direct endpoint and PostgreSQL pooling/session support; runtime preparation did not advance past this preflight.',
1591
+ );
1592
+ } finally {
1593
+ if (timer) clearTimeout(timer);
1594
+ await direct.end().catch(() => undefined);
1595
+ }
1596
+ }
1597
+
1460
1598
  /**
1461
1599
  * `standby` means this process lost an optional session advisory-lock election
1462
1600
  * and deliberately closed its direct connection. It will retry the election
@@ -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 _chunkZ2MO7FZGjs = require('./chunk-Z2MO7FZG.js');
18
+ require('./chunk-7OQZZHZ4.js');
19
+ require('./chunk-WSOM3TY6.js');
20
+ require('./chunk-2RZHMCDL.js');
21
+ require('./chunk-ALJJRZNJ.js');
22
+ require('./chunk-XNYIZMNQ.js');
23
+ require('./chunk-DIAWYWT5.js');
24
+ require('./chunk-L6C7C7IJ.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 = _chunkZ2MO7FZGjs.EXIT_WORKSPACE_MISMATCH; exports.authStatusLine = _chunkZ2MO7FZGjs.authStatusLine; exports.clearPendingClaim = _chunkZ2MO7FZGjs.clearPendingClaim; exports.clearSatisfiedPendingClaim = _chunkZ2MO7FZGjs.clearSatisfiedPendingClaim; exports.handleRegister = _chunkZ2MO7FZGjs.handleRegister; exports.handleStatus = _chunkZ2MO7FZGjs.handleStatus; exports.handleWait = _chunkZ2MO7FZGjs.handleWait; exports.httpJson = _chunkZ2MO7FZGjs.httpJson; exports.readPendingAuthClaim = _chunkZ2MO7FZGjs.readPendingAuthClaim; exports.readStatusBanner = _chunkZ2MO7FZGjs.readStatusBanner; exports.registerAuthCommands = _chunkZ2MO7FZGjs.registerAuthCommands; exports.reportApprovalLinkShown = _chunkZ2MO7FZGjs.reportApprovalLinkShown; exports.reportSetupCompleted = _chunkZ2MO7FZGjs.reportSetupCompleted; exports.resolvePendingAuthClaimForResume = _chunkZ2MO7FZGjs.resolvePendingAuthClaimForResume; exports.statusBannerLine = _chunkZ2MO7FZGjs.statusBannerLine;
@@ -14,14 +14,14 @@ import {
14
14
  reportSetupCompleted,
15
15
  resolvePendingAuthClaimForResume,
16
16
  statusBannerLine
17
- } from "./chunk-IURXJPGH.mjs";
18
- import "./chunk-FISH2MI2.mjs";
19
- import "./chunk-XX7WLKOQ.mjs";
20
- import "./chunk-WZ3A35ZD.mjs";
17
+ } from "./chunk-IGCSKXGK.mjs";
18
+ import "./chunk-56JE475N.mjs";
19
+ import "./chunk-ZVAD65CF.mjs";
20
+ import "./chunk-JM52ATUS.mjs";
21
21
  import "./chunk-4QF2K7TM.mjs";
22
22
  import "./chunk-DLIRSHV6.mjs";
23
23
  import "./chunk-HBL4PM5Q.mjs";
24
- import "./chunk-5GXYXU45.mjs";
24
+ import "./chunk-A2VCFBZN.mjs";
25
25
  import "./chunk-WZYKRD7T.mjs";
26
26
  import "./chunk-KRD6H754.mjs";
27
27
  export {
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-7I4B6V2S.mjs";
4
4
  import {
5
5
  DeeplineClient
6
- } from "./chunk-4MR7LZXF.mjs";
6
+ } from "./chunk-BBFWIYAF.mjs";
7
7
  import {
8
8
  iterateCursorPages,
9
9
  requireBillingIdempotencyKey
10
- } from "./chunk-HRODQDTB.mjs";
10
+ } from "./chunk-YAW7ET4P.mjs";
11
11
  import "./chunk-L2VKAASU.mjs";
12
12
  import "./chunk-CS2AEAD6.mjs";
13
13
  import "./chunk-S3A4IXBQ.mjs";
@@ -18,9 +18,9 @@ import {
18
18
  openInBrowser,
19
19
  printCommandEnvelope,
20
20
  shouldEmitJson
21
- } from "./chunk-FISH2MI2.mjs";
22
- import "./chunk-XX7WLKOQ.mjs";
23
- import "./chunk-WZ3A35ZD.mjs";
21
+ } from "./chunk-56JE475N.mjs";
22
+ import "./chunk-ZVAD65CF.mjs";
23
+ import "./chunk-JM52ATUS.mjs";
24
24
  import {
25
25
  AuthError,
26
26
  ConfigError
@@ -29,7 +29,7 @@ import "./chunk-DLIRSHV6.mjs";
29
29
  import {
30
30
  DeeplineError
31
31
  } from "./chunk-HBL4PM5Q.mjs";
32
- import "./chunk-5GXYXU45.mjs";
32
+ import "./chunk-A2VCFBZN.mjs";
33
33
  import "./chunk-WZYKRD7T.mjs";
34
34
  import "./chunk-KRD6H754.mjs";
35
35