gencow 0.1.283 → 0.1.285

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.
package/core/index.js CHANGED
@@ -4126,6 +4126,9 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = [
4126
4126
  "GENCOW_MEMORY_MB",
4127
4127
  "BUN_JSC_forceRAMSize",
4128
4128
  "MIMALLOC_PURGE_DELAY",
4129
+ "BUN_JSC_numberOfGCMarkers",
4130
+ "BUN_JSC_numberOfDFGCompilerThreads",
4131
+ "BUN_JSC_numberOfFTLCompilerThreads",
4129
4132
  "NODE_PATH"
4130
4133
  ];
4131
4134
  var RESERVED_TENANT_RUNTIME_ENV_KEY_SET = new Set(RESERVED_TENANT_RUNTIME_ENV_KEYS);
@@ -22,6 +22,9 @@ import { resolveProjectMetadataPath, resolveProjectSelection } from "./project-c
22
22
  import { updateEnvLocalUrl } from "./cli-project-runtime.mjs";
23
23
 
24
24
  const DEFAULT_APP_CREATE_TIMEOUT_MS = 60_000;
25
+ const DEFAULT_APP_QUERY_TIMEOUT_MS = 30_000;
26
+ const APP_QUERY_TIMED_OUT = Symbol("app-query-timed-out");
27
+ const SAFE_APP_NAME_FOR_COMMAND = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
25
28
  const SAFE_CLI_OPTION_PATTERN = /^--?[A-Za-z][A-Za-z0-9-]{0,40}$/u;
26
29
 
27
30
  function resolveAppCreateTimeoutMs(value) {
@@ -31,6 +34,25 @@ function resolveAppCreateTimeoutMs(value) {
31
34
  : DEFAULT_APP_CREATE_TIMEOUT_MS;
32
35
  }
33
36
 
37
+ function resolveAppQueryTimeoutMs(value) {
38
+ const parsed = Number(value);
39
+ return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000
40
+ ? parsed
41
+ : DEFAULT_APP_QUERY_TIMEOUT_MS;
42
+ }
43
+
44
+ /** Read-only query timeout: nothing is changed, so the user can simply retry the same lookup. */
45
+ function formatAppQueryTimeoutDiagnostic({ operation, timeoutMs, retryCommand }) {
46
+ return [
47
+ `The Gencow Platform did not respond to "${operation}" within ${timeoutMs}ms.`,
48
+ "Code: CLI_PLATFORM_TIMEOUT",
49
+ `Stage: ${operation}`,
50
+ "State: nothing was changed; this is a read-only lookup.",
51
+ "Retryable: yes",
52
+ `Retry: ${retryCommand}`,
53
+ ].join("\n");
54
+ }
55
+
34
56
  function appResponseStatus(response) {
35
57
  return Number.isSafeInteger(response?.status) ? `HTTP ${response.status}` : "unknown HTTP status";
36
58
  }
@@ -231,6 +253,7 @@ async function confirmDelete(name) {
231
253
 
232
254
  export function createAppCommand({
233
255
  appCreateTimeoutMs = resolveAppCreateTimeoutMs(process.env.GENCOW_APP_CREATE_TIMEOUT_MS),
256
+ appQueryTimeoutMs = resolveAppQueryTimeoutMs(process.env.GENCOW_APP_QUERY_TIMEOUT_MS),
234
257
  clearTimeoutImpl = clearTimeout,
235
258
  confirmDeleteImpl = confirmDelete,
236
259
  createAbortControllerImpl = () => new AbortController(),
@@ -251,6 +274,29 @@ export function createAppCommand({
251
274
  warnImpl = warn,
252
275
  }) {
253
276
  const boundedAppCreateTimeoutMs = resolveAppCreateTimeoutMs(appCreateTimeoutMs);
277
+ const boundedAppQueryTimeoutMs = resolveAppQueryTimeoutMs(appQueryTimeoutMs);
278
+
279
+ // Resolves to APP_QUERY_TIMED_OUT when the Platform stays silent past the deadline.
280
+ // The query is aborted so no lingering request outlives the command.
281
+ async function requestAppQuery(creds, queryName, args) {
282
+ const controller = createAbortControllerImpl();
283
+ let timeoutHandle;
284
+ const timeoutPromise = new Promise((resolve) => {
285
+ timeoutHandle = setTimeoutImpl(() => {
286
+ controller.abort();
287
+ resolve(APP_QUERY_TIMED_OUT);
288
+ }, boundedAppQueryTimeoutMs);
289
+ });
290
+ try {
291
+ const request = (async () => {
292
+ const response = await rpcQueryImpl(creds, queryName, args, { signal: controller.signal });
293
+ return { response, decoded: await readJsonValueResponse(response) };
294
+ })();
295
+ return await Promise.race([request, timeoutPromise]);
296
+ } finally {
297
+ clearTimeoutImpl(timeoutHandle);
298
+ }
299
+ }
254
300
 
255
301
  async function requestAppCreate(creds, name) {
256
302
  const controller = createAbortControllerImpl();
@@ -291,8 +337,19 @@ export function createAppCommand({
291
337
 
292
338
  if (!subcmd || subcmd === "list") {
293
339
  logImpl(`\n${BOLD}${CYAN}Your Apps${RESET}\n`);
294
- const res = await rpcQueryImpl(creds, "apps.list");
295
- const body = await res.json().catch(() => null);
340
+ const queried = await requestAppQuery(creds, "apps.list");
341
+ if (queried === APP_QUERY_TIMED_OUT) {
342
+ errorImpl(
343
+ formatAppQueryTimeoutDiagnostic({
344
+ operation: "app list",
345
+ timeoutMs: boundedAppQueryTimeoutMs,
346
+ retryCommand: "gencow app list",
347
+ }),
348
+ );
349
+ return 1;
350
+ }
351
+ const { response: res, decoded } = queried;
352
+ const body = decoded.parsed ? decoded.value : null;
296
353
  if (!res.ok) {
297
354
  errorImpl(appResponseError(body, invalidAppResponse("app list", res, "error"), res));
298
355
  return 1;
@@ -499,8 +556,20 @@ ${dashboardLine}
499
556
  errorImpl("Usage: gencow app status <name>");
500
557
  return 1;
501
558
  }
502
- const res = await rpcQueryImpl(creds, "apps.get", { name });
503
- const decoded = await readJsonValueResponse(res);
559
+ const queried = await requestAppQuery(creds, "apps.get", { name });
560
+ if (queried === APP_QUERY_TIMED_OUT) {
561
+ errorImpl(
562
+ formatAppQueryTimeoutDiagnostic({
563
+ operation: "app status",
564
+ timeoutMs: boundedAppQueryTimeoutMs,
565
+ retryCommand: SAFE_APP_NAME_FOR_COMMAND.test(name)
566
+ ? `gencow app status ${name}`
567
+ : "gencow app status <name>",
568
+ }),
569
+ );
570
+ return 1;
571
+ }
572
+ const { response: res, decoded } = queried;
504
573
  const body = decoded.parsed ? decoded.value : null;
505
574
  if (!res.ok) {
506
575
  errorImpl(
@@ -10,6 +10,10 @@ import {
10
10
  HINTS_DATA_LOSS_NOTICE,
11
11
  SAFE_COLUMN_REFERENCE,
12
12
  } from "./migration-hints.mjs";
13
+ import {
14
+ isAdmissionTransportFailure,
15
+ renderAdmissionTransportFailureLines,
16
+ } from "./deploy-admission-transport-failure.mjs";
13
17
 
14
18
  const SAFE_CORRELATION_ID = /^[A-Za-z0-9_-]{8,128}$/u;
15
19
  const SAFE_APP_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
@@ -330,6 +334,7 @@ export function formatCommandError(caught) {
330
334
  }
331
335
 
332
336
  function commandErrorMessage(caught) {
337
+ if (isAdmissionTransportFailure(caught)) return renderAdmissionTransportFailureLines(caught).join("\n");
333
338
  const procedureDiagnostic = formatProcedureRpcDiagnostic(caught);
334
339
  if (procedureDiagnostic) return procedureDiagnostic;
335
340
  const localDiagnostic = SAFE_LOCAL_ERROR_CODES.get(caught?.code);
@@ -0,0 +1,45 @@
1
+ // Bounded request deadline for read-only db:check and db:check --inspect-state requests.
2
+ // db:push never uses this: a write whose outcome is unknown must keep the receipt recovery flow.
3
+
4
+ const DEFAULT_DB_CHECK_TIMEOUT_MS = 60_000;
5
+ export const DEADLINE_EXCEEDED = Symbol("db-check-deadline-exceeded");
6
+
7
+ /** Out-of-range or non-numeric values fall back to the default, matching the app query deadline policy. */
8
+ export function resolveDbCheckTimeoutMs(value) {
9
+ const parsed = Number(value);
10
+ return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000
11
+ ? parsed
12
+ : DEFAULT_DB_CHECK_TIMEOUT_MS;
13
+ }
14
+
15
+ /**
16
+ * Upper bound for a read-only db:check / db:check --inspect-state request. Only the check path uses this:
17
+ * a db:push outcome can be ambiguous after a silent wait, so pushes keep the receipt recovery flow unbounded.
18
+ */
19
+ export function createReadOnlyCheckDeadline(timeoutMs) {
20
+ const controller = new AbortController();
21
+ let timer;
22
+ let timedOut = false;
23
+ const expired = new Promise((resolve) => {
24
+ timer = setTimeout(() => {
25
+ timedOut = true;
26
+ controller.abort(new Error("db:check request deadline exceeded"));
27
+ resolve(DEADLINE_EXCEEDED);
28
+ }, timeoutMs);
29
+ });
30
+ return {
31
+ signal: controller.signal,
32
+ timeoutMs,
33
+ expired,
34
+ get timedOut() {
35
+ return timedOut;
36
+ },
37
+ clear() {
38
+ clearTimeout(timer);
39
+ },
40
+ };
41
+ }
42
+
43
+ export function withCheckDeadline(promise, deadline) {
44
+ return deadline ? Promise.race([promise, deadline.expired]) : promise;
45
+ }
@@ -56,6 +56,12 @@ import {
56
56
  resolveConfirmationMode,
57
57
  } from "./confirm-gate.mjs";
58
58
  import { formatCommandError } from "./cli-command-runner.mjs";
59
+ import {
60
+ DEADLINE_EXCEEDED,
61
+ createReadOnlyCheckDeadline,
62
+ resolveDbCheckTimeoutMs,
63
+ withCheckDeadline,
64
+ } from "./db-check-deadline.mjs";
59
65
  import { emitMigrationResponsibilityNotice } from "./migration-advisory.mjs";
60
66
  import { describeProdTargetFailure } from "./cloud-targets.mjs";
61
67
  import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
@@ -535,6 +541,7 @@ function createDbMigrationCommand(deps, command) {
535
541
  return;
536
542
  }
537
543
 
544
+ let checkDeadline = null;
538
545
  try {
539
546
  let bundleData;
540
547
  try {
@@ -554,32 +561,48 @@ function createDbMigrationCommand(deps, command) {
554
561
  });
555
562
  let res;
556
563
  let recoveredSuccess = null;
564
+ if (isCheck) {
565
+ checkDeadline = createReadOnlyCheckDeadline(
566
+ resolveDbCheckTimeoutMs(deps.processEnv.GENCOW_DB_CHECK_TIMEOUT_MS),
567
+ );
568
+ }
557
569
  try {
558
570
  remoteRequestStarted = true;
559
- res = await deps.platformFetchImpl(
560
- creds,
561
- `/platform/apps/${appId}/${isInspection ? "schema-inspection" : isCheck ? "schema-check" : "schema-push"}`,
562
- {
563
- method: "POST",
564
- headers: {
565
- "Content-Type": "application/octet-stream",
566
- "X-Gencow-CLI-Version": deps.cliVersion,
567
- "X-Gencow-Environment": envLabel,
568
- "X-Gencow-Migration-Operation-ID": receiptId,
569
- "X-Gencow-Migration-Bundle-Sha256": stagedBundle.manifest.bundleSha256,
570
- ...(stagedBundle.manifest.artifactIdentitySha256
571
- ? {
572
- "X-Gencow-Migration-Artifact-Identity-Sha256":
573
- stagedBundle.manifest.artifactIdentitySha256,
574
- }
575
- : {}),
571
+ res = await withCheckDeadline(
572
+ deps.platformFetchImpl(
573
+ creds,
574
+ `/platform/apps/${appId}/${isInspection ? "schema-inspection" : isCheck ? "schema-check" : "schema-push"}`,
575
+ {
576
+ method: "POST",
577
+ headers: {
578
+ "Content-Type": "application/octet-stream",
579
+ "X-Gencow-CLI-Version": deps.cliVersion,
580
+ "X-Gencow-Environment": envLabel,
581
+ "X-Gencow-Migration-Operation-ID": receiptId,
582
+ "X-Gencow-Migration-Bundle-Sha256": stagedBundle.manifest.bundleSha256,
583
+ ...(stagedBundle.manifest.artifactIdentitySha256
584
+ ? {
585
+ "X-Gencow-Migration-Artifact-Identity-Sha256":
586
+ stagedBundle.manifest.artifactIdentitySha256,
587
+ }
588
+ : {}),
589
+ },
590
+ body: bundleData,
591
+ ...(checkDeadline ? { signal: checkDeadline.signal } : {}),
576
592
  },
577
- body: bundleData,
578
- },
593
+ ),
594
+ checkDeadline,
579
595
  );
596
+ if (res === DEADLINE_EXCEEDED) throw new Error("db:check request deadline exceeded");
580
597
  } catch {
581
598
  if (isCheck) {
582
- emitFailure(buildMigrationCheckNoResponseDiagnostic(clientCorrelationId(), retryCommand));
599
+ emitFailure(
600
+ buildMigrationCheckNoResponseDiagnostic(
601
+ clientCorrelationId(),
602
+ retryCommand,
603
+ checkDeadline?.timedOut ? { timeoutMs: checkDeadline.timeoutMs } : undefined,
604
+ ),
605
+ );
583
606
  return;
584
607
  }
585
608
  const status = await fetchMigrationOperationStatus({
@@ -613,7 +636,20 @@ function createDbMigrationCommand(deps, command) {
613
636
  }
614
637
  }
615
638
 
616
- const data = recoveredSuccess ? null : await res.json().catch(() => ({}));
639
+ const data = recoveredSuccess
640
+ ? null
641
+ : await withCheckDeadline(
642
+ res.json().catch(() => ({})),
643
+ checkDeadline,
644
+ );
645
+ if (data === DEADLINE_EXCEEDED) {
646
+ emitFailure(
647
+ buildMigrationCheckNoResponseDiagnostic(clientCorrelationId(), retryCommand, {
648
+ timeoutMs: checkDeadline.timeoutMs,
649
+ }),
650
+ );
651
+ return;
652
+ }
617
653
  const hasJsonObjectBody = data !== null && typeof data === "object" && !Array.isArray(data);
618
654
  if (isCheck && !recoveredSuccess && !hasJsonObjectBody) {
619
655
  emitFailure(buildMigrationCheckInvalidResponseDiagnostic(clientCorrelationId(), retryCommand));
@@ -724,6 +760,7 @@ function createDbMigrationCommand(deps, command) {
724
760
  emitJson,
725
761
  });
726
762
  } finally {
763
+ checkDeadline?.clear();
727
764
  stagedBundle.cleanup();
728
765
  }
729
766
  };
@@ -1,3 +1,5 @@
1
+ import { createAdmissionTransportFailure } from "./deploy-admission-transport-failure.mjs";
2
+
1
3
  const DEFAULT_ADMISSION_TIMEOUT_MS = 5 * 60 * 1000;
2
4
 
3
5
  function pendingResponse({ requestId, appName, resumeCommand = null }) {
@@ -26,10 +28,25 @@ function pendingResponse({ requestId, appName, resumeCommand = null }) {
26
28
  return response;
27
29
  }
28
30
 
31
+ // A rejected send means no HTTP response was received. It is converted to a typed
32
+ // transport failure here, so the CLI renders the state instead of the raw fetch message.
33
+ function sendAdmission(send, signal, { requestId, appName, envTarget }) {
34
+ const toTransportFailure = (cause) =>
35
+ createAdmissionTransportFailure({ cause, appName, requestId, envTarget });
36
+ try {
37
+ return Promise.resolve(send({ signal })).catch((cause) => {
38
+ throw toTransportFailure(cause);
39
+ });
40
+ } catch (cause) {
41
+ return Promise.reject(toTransportFailure(cause));
42
+ }
43
+ }
44
+
29
45
  export async function postDeploymentAdmissionWithTimeout({
30
46
  send,
31
47
  requestId = null,
32
48
  appName,
49
+ envTarget = "dev",
33
50
  resumeCommand = requestId ? `gencow deploy --resume ${requestId}` : null,
34
51
  timeoutMs = DEFAULT_ADMISSION_TIMEOUT_MS,
35
52
  setTimeoutImpl = setTimeout,
@@ -45,7 +62,7 @@ export async function postDeploymentAdmissionWithTimeout({
45
62
  timer?.unref?.();
46
63
  });
47
64
  try {
48
- return await Promise.race([send({ signal: controller.signal }), deadline]);
65
+ return await Promise.race([sendAdmission(send, controller.signal, { requestId, appName, envTarget }), deadline]);
49
66
  } finally {
50
67
  if (timer !== undefined) clearTimeoutImpl(timer);
51
68
  }
@@ -0,0 +1,148 @@
1
+ // Typed diagnosis for a deploy admission request that got no HTTP response.
2
+ //
3
+ // Two cases are told apart by a stable error code:
4
+ // - ERR_INVALID_URL: the request was rejected before any network I/O (for example a
5
+ // malformed Platform URL). Nothing was sent, so the state is known: NOT CHANGED.
6
+ // - Any other rejection: a network-layer failure. The request may have reached the
7
+ // Platform, so the state is UNKNOWN and the next step is a status check before a rerun.
8
+ //
9
+ // Printed cause text is an allowlist, never the raw message. Only the messages and codes
10
+ // below are printed; anything else (hosts, IPs, tokens, paths, long or multi-line text)
11
+ // is dropped and at most a generic "network error" line is shown.
12
+
13
+ export const ADMISSION_TRANSPORT_FAILURE_CODE = "CLI_PLATFORM_UNAVAILABLE";
14
+
15
+ // Messages the runtimes actually produce for network-layer failures seen in this CLI.
16
+ const KNOWN_CAUSE_MESSAGES = new Set([
17
+ "The socket connection was closed unexpectedly",
18
+ "The socket connection was closed unexpectedly.",
19
+ "socket closed before response",
20
+ "fetch failed",
21
+ "terminated",
22
+ "Unable to connect. Is the computer able to access the url?",
23
+ ]);
24
+
25
+ // Error codes that describe a connection-level failure.
26
+ const KNOWN_CAUSE_CODES = new Set([
27
+ "ECONNRESET",
28
+ "ECONNREFUSED",
29
+ "ECONNABORTED",
30
+ "ENOTFOUND",
31
+ "EAI_AGAIN",
32
+ "ETIMEDOUT",
33
+ "EPIPE",
34
+ "EHOSTUNREACH",
35
+ "ENETUNREACH",
36
+ "UND_ERR_SOCKET",
37
+ "UND_ERR_CONNECT_TIMEOUT",
38
+ "ConnectionRefused",
39
+ ]);
40
+
41
+ const NOT_SENT_CAUSE_CODE = "ERR_INVALID_URL";
42
+ const SAFE_APP_ID = /^[A-Za-z0-9_-]{1,128}$/u;
43
+ const SAFE_REQUEST_ID = /^[A-Za-z0-9_-]{8,128}$/u;
44
+
45
+ function readCauseCode(cause) {
46
+ const code = cause?.code ?? cause?.cause?.code;
47
+ return typeof code === "string" ? code : null;
48
+ }
49
+
50
+ function readAllowlistedCauseMessage(cause) {
51
+ const message = typeof cause?.message === "string" ? cause.message : "";
52
+ return KNOWN_CAUSE_MESSAGES.has(message) ? message : null;
53
+ }
54
+
55
+ function readAllowlistedCauseCode(cause) {
56
+ const code = readCauseCode(cause);
57
+ return code !== null && KNOWN_CAUSE_CODES.has(code) ? code : null;
58
+ }
59
+
60
+ // The in-process message stays the original cause text, so callers that inspect the thrown
61
+ // error keep their existing contract. The CLI prints only the typed rendering, never this message.
62
+ export function createAdmissionTransportFailure({ cause, appName = null, requestId = null, envTarget = "dev" }) {
63
+ const originalMessage = typeof cause?.message === "string" && cause.message ? cause.message : null;
64
+ const error = new Error(originalMessage ?? ADMISSION_TRANSPORT_FAILURE_CODE);
65
+ error.code = ADMISSION_TRANSPORT_FAILURE_CODE;
66
+ error.deployAdmissionTransport = {
67
+ appName: typeof appName === "string" && SAFE_APP_ID.test(appName) ? appName : null,
68
+ requestId: typeof requestId === "string" && SAFE_REQUEST_ID.test(requestId) ? requestId : null,
69
+ envTarget: envTarget === "prod" ? "prod" : "dev",
70
+ requestSent: readCauseCode(cause) !== NOT_SENT_CAUSE_CODE,
71
+ causeMessage: readAllowlistedCauseMessage(cause),
72
+ causeCode: readAllowlistedCauseCode(cause),
73
+ attempts: null,
74
+ };
75
+ return error;
76
+ }
77
+
78
+ export function isAdmissionTransportFailure(caught) {
79
+ return caught instanceof Error && caught.deployAdmissionTransport !== undefined;
80
+ }
81
+
82
+ // Called by the retry loop with the number of tries made for this request before it gave up.
83
+ export function recordAdmissionTransportAttempts(caught, attempts) {
84
+ if (isAdmissionTransportFailure(caught) && Number.isSafeInteger(attempts) && attempts >= 1) {
85
+ caught.deployAdmissionTransport.attempts = attempts;
86
+ }
87
+ }
88
+
89
+ function attemptsLine(detail) {
90
+ if (detail.attempts === null) return null;
91
+ const times = detail.attempts === 1 ? "1 time" : `${detail.attempts} times`;
92
+ return detail.requestId
93
+ ? `The CLI already tried this request ${times} with the same request ID before giving up.`
94
+ : `The CLI already tried this request ${times} before giving up.`;
95
+ }
96
+
97
+ function causeLine(detail) {
98
+ if (!detail.causeMessage && !detail.causeCode) return "Cause: network error (no safe detail)";
99
+ if (detail.causeMessage && detail.causeCode) return `Cause: ${detail.causeMessage} (${detail.causeCode})`;
100
+ return detail.causeMessage ? `Cause: ${detail.causeMessage}` : `Cause: network error (${detail.causeCode})`;
101
+ }
102
+
103
+ export function renderAdmissionTransportFailureLines(caught) {
104
+ const detail = caught.deployAdmissionTransport;
105
+ const prodFlag = detail.envTarget === "prod" ? " --prod" : "";
106
+ const lines = detail.requestSent
107
+ ? [
108
+ `${ADMISSION_TRANSPORT_FAILURE_CODE}: The deploy request got no response from the Platform. The server may have accepted it.`,
109
+ ]
110
+ : [`${ADMISSION_TRANSPORT_FAILURE_CODE}: The deploy request was not sent to the Platform.`];
111
+ lines.push(
112
+ detail.requestSent
113
+ ? "Stage: deploy admission (bundle upload request)"
114
+ : "Stage: deploy admission (before the request was sent)",
115
+ );
116
+ if (detail.appName) lines.push(`App ID: ${detail.appName}`);
117
+ lines.push(detail.requestSent ? "Response: none received (network error)" : "Response: none (request not sent)");
118
+ lines.push(causeLine(detail));
119
+ lines.push(`Request ID: ${detail.requestId ?? "none"}`);
120
+ lines.push("Correlation ID: none (no response from the Platform)");
121
+ const attempts = attemptsLine(detail);
122
+ if (attempts) lines.push(attempts);
123
+
124
+ if (!detail.requestSent) {
125
+ lines.push("Database: NOT CHANGED (no request was sent)");
126
+ lines.push("Incumbent serving: PRESERVED (no request was sent)");
127
+ lines.push("Retryable: yes, after the Platform URL setting is fixed");
128
+ lines.push("Next: check the Platform URL in your CLI login/configuration, then rerun the same deploy command.");
129
+ return lines;
130
+ }
131
+
132
+ lines.push("Database: UNKNOWN (the upload may have reached the server; nothing is confirmed)");
133
+ lines.push(
134
+ "Incumbent serving: UNKNOWN (not confirmed; a changed serving version is possible if the deploy was accepted)",
135
+ );
136
+ lines.push("Retryable: yes, but only after the status check below");
137
+ lines.push(
138
+ `Next: gencow deploy status${prodFlag} (shows the app status and last deployed time; a deployment from this attempt may or may not appear)`,
139
+ );
140
+ if (detail.requestId) {
141
+ lines.push(
142
+ `Then: if no deployment from this attempt appears, rerun with the same request ID: gencow deploy --resume ${detail.requestId}${prodFlag}`,
143
+ );
144
+ } else {
145
+ lines.push("Then: if no deployment from this attempt appears, rerun the same deploy command. Do not rerun first.");
146
+ }
147
+ return lines;
148
+ }
@@ -10,6 +10,7 @@ import { resolveCloudAppTargetWithServerEnvironment } from "./cloud-target-envir
10
10
  import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
11
11
  import { readJsonValueResponse } from "./http-response-json.mjs";
12
12
  import { renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.mjs";
13
+ import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
13
14
  import { formatAppLogDiagnosis } from "./deploy-logs-diagnostic.mjs";
14
15
  import { formatDeploymentOperationPhase } from "./deployment-operation-poll.mjs";
15
16
  import { handleDeployReleaseSubcommand } from "./release-history-command.mjs";
@@ -218,7 +219,10 @@ export async function handleDeployReadonlySubcommand(params) {
218
219
  const decoded = await readJsonValueResponse(res);
219
220
  const body = decoded.parsed && decoded.value && typeof decoded.value === "object" ? decoded.value : null;
220
221
  if (!res.ok || !body || body.attemptId !== releaseAttemptId) {
221
- for (const line of renderDeployFailureDiagnosticLines(body, res.statusText, { expectedAppName: appId }))
222
+ for (const line of renderDeployFailureDiagnosticLines(body, res.statusText, {
223
+ expectedAppName: appId,
224
+ credentialEnvName: credentialEnvNameOf(creds),
225
+ }))
222
226
  errorImpl(line);
223
227
  exitImpl(1);
224
228
  return true;
@@ -273,7 +277,9 @@ export async function handleDeployReadonlySubcommand(params) {
273
277
  return true;
274
278
  }
275
279
  if (!res.ok) {
276
- for (const line of renderDeployFailureDiagnosticLines(body, res.statusText)) {
280
+ for (const line of renderDeployFailureDiagnosticLines(body, res.statusText, {
281
+ credentialEnvName: credentialEnvNameOf(creds),
282
+ })) {
277
283
  errorImpl(line);
278
284
  }
279
285
  exitImpl(1);
@@ -4,6 +4,9 @@ import { APP_DELETE_OPERATION_PATTERN } from "./app-response-error.mjs";
4
4
  import { formatLatestCliInvocation } from "./cli-update-guidance.mjs";
5
5
  import { formatDeployCorrelationId } from "./deploy-correlation-diagnostic.mjs";
6
6
  import { formatDeploymentOperationPhase } from "./deployment-operation-poll.mjs";
7
+ import { credentialEnvNameOf, formatCliAuthFailureLines, readTypedCliAuthDiagnostic } from "./prod-create-auth-diagnostic.mjs";
8
+
9
+ export { credentialEnvNameOf };
7
10
 
8
11
  const DEPLOY_FAILURE_STAGES = new Set([
9
12
  "admission",
@@ -499,6 +502,12 @@ function isCliUpgradeContract(contract) {
499
502
  }
500
503
 
501
504
  export function renderDeployFailureDiagnosticLines(responseBody, statusText, options = {}) {
505
+ // A typed CLI auth rejection (deploy status, deploy, static, rollback routes) renders its code, stage,
506
+ // unchanged state, retry rule and correlation ID; the bare status text is never the only message.
507
+ const typedAuth = readTypedCliAuthDiagnostic(responseBody);
508
+ if (typedAuth) {
509
+ return formatCliAuthFailureLines(typedAuth, { credentialEnvName: options.credentialEnvName ?? null });
510
+ }
502
511
  const contract = readDeployFailureContract(responseBody, options.expectedAppName);
503
512
  const fallbackMessage = safeText(statusText, 120) ?? "Request failed";
504
513
  if (!contract) {
@@ -21,7 +21,7 @@ import {
21
21
  runDrizzleGenerateWithFallback,
22
22
  } from "./drizzle-generate.mjs";
23
23
  import { buildDeployClaimFromArchive } from "./deploy-package-claim.mjs";
24
- import { renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.mjs";
24
+ import { credentialEnvNameOf, renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.mjs";
25
25
  import { readJsonObjectResponse } from "./http-response-json.mjs";
26
26
  import { formatDeploymentAcceptedLine, pollAcceptedDeploymentOperation } from "./deployment-operation-poll.mjs";
27
27
  import { postDeploymentAdmissionWithTimeout } from "./deploy-admission-boundary.mjs";
@@ -644,7 +644,7 @@ export function createDeployPackageRuntime({
644
644
  submit: () =>
645
645
  postDeploymentAdmissionWithTimeout({
646
646
  requestId: activeDeployClaim?.claim?.requestId ?? explicitRequestId,
647
- appName: targetAppId,
647
+ appName: targetAppId, envTarget,
648
648
  send: ({ signal }) => deployOnce(targetAppId, signal),
649
649
  }),
650
650
  retryOnResponse: Boolean(activeDeployClaim),
@@ -760,7 +760,7 @@ export function createDeployPackageRuntime({
760
760
  lines.slice(1).forEach((line) => logImpl(line));
761
761
  } else {
762
762
  const lines = renderDeployFailureDiagnosticLines(errData, deployRes.statusText, {
763
- expectedAppName: targetAppId,
763
+ expectedAppName: targetAppId, credentialEnvName: credentialEnvNameOf(creds),
764
764
  });
765
765
  errorImpl(lines[0]);
766
766
  lines
@@ -25,6 +25,11 @@ import {
25
25
  } from "./deploy-prepared-source.mjs";
26
26
  import { resolveImplicitProdEnvironment } from "./cloud-targets.mjs";
27
27
  import { checkExplicitProdAppTarget } from "./deploy-app-target.mjs";
28
+ import {
29
+ credentialEnvNameOf,
30
+ formatCliAuthFailureLines,
31
+ readTypedCliAuthDiagnostic,
32
+ } from "./prod-create-auth-diagnostic.mjs";
28
33
 
29
34
  export function parseDeployArgs(deployArgs) {
30
35
  const parsed = {
@@ -234,7 +239,17 @@ async function runRollbackDeploy({
234
239
 
235
240
  if (!rollbackRes.ok) {
236
241
  const errData = await readJsonObjectResponse(rollbackRes);
237
- errorImpl(`Rollback failed: ${errData?.error || rollbackRes.statusText}`);
242
+ const typedAuth = readTypedCliAuthDiagnostic(errData);
243
+ if (typedAuth) {
244
+ for (const line of formatCliAuthFailureLines(typedAuth, {
245
+ operation: "Rollback",
246
+ credentialEnvName: credentialEnvNameOf(creds),
247
+ })) {
248
+ errorImpl(line);
249
+ }
250
+ } else {
251
+ errorImpl(`Rollback failed: ${errData?.error || rollbackRes.statusText}`);
252
+ }
238
253
  exitImpl(1);
239
254
  return;
240
255
  }
@@ -1,3 +1,5 @@
1
+ import { recordAdmissionTransportAttempts } from "./deploy-admission-transport-failure.mjs";
2
+
1
3
  const INITIAL_DEPLOYMENT_ADMISSION_ATTEMPTS = 3;
2
4
 
3
5
  function isRetryableInitialDeploymentAdmission(response) {
@@ -37,7 +39,10 @@ export async function submitDeploymentWithIdempotentRetry({
37
39
  try {
38
40
  response = await submit();
39
41
  } catch (error) {
40
- if (!retryOnTransport || attempt === INITIAL_DEPLOYMENT_ADMISSION_ATTEMPTS) throw error;
42
+ if (!retryOnTransport || attempt === INITIAL_DEPLOYMENT_ADMISSION_ATTEMPTS) {
43
+ recordAdmissionTransportAttempts(error, attempt);
44
+ throw error;
45
+ }
41
46
  await sleepImpl(250 * attempt);
42
47
  continue;
43
48
  }