gencow 0.1.291 → 0.1.293

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.
@@ -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 { renderDeploymentOperationNotFoundLines } from "./deploy-status-operation-not-found.mjs";
13
14
  import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
14
15
  import { formatAppLogDiagnosis } from "./deploy-logs-diagnostic.mjs";
15
16
  import { formatDeploymentOperationPhase } from "./deployment-operation-poll.mjs";
@@ -222,6 +223,8 @@ export async function handleDeployReadonlySubcommand(params) {
222
223
  for (const line of renderDeployFailureDiagnosticLines(body, res.statusText, {
223
224
  expectedAppName: appId,
224
225
  credentialEnvName: credentialEnvNameOf(creds),
226
+ httpStatus: res.status,
227
+ retryAfter: res.headers?.get?.("retry-after") ?? null,
225
228
  }))
226
229
  errorImpl(line);
227
230
  exitImpl(1);
@@ -277,8 +280,20 @@ export async function handleDeployReadonlySubcommand(params) {
277
280
  return true;
278
281
  }
279
282
  if (!res.ok) {
283
+ const notFoundLines = renderDeploymentOperationNotFoundLines({
284
+ status: res.status,
285
+ body,
286
+ deploymentId,
287
+ });
288
+ if (notFoundLines) {
289
+ for (const line of notFoundLines) errorImpl(line);
290
+ exitImpl(1);
291
+ return true;
292
+ }
280
293
  for (const line of renderDeployFailureDiagnosticLines(body, res.statusText, {
281
294
  credentialEnvName: credentialEnvNameOf(creds),
295
+ httpStatus: res.status,
296
+ retryAfter: res.headers?.get?.("retry-after") ?? null,
282
297
  })) {
283
298
  errorImpl(line);
284
299
  }
@@ -4,6 +4,7 @@ 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 { isPlatformUnavailableStatus, renderPlatformUnavailableLines } from "./deploy-platform-unavailable-diagnostic.mjs";
7
8
  import { credentialEnvNameOf, formatCliAuthFailureLines, readTypedCliAuthDiagnostic } from "./prod-create-auth-diagnostic.mjs";
8
9
 
9
10
  export { credentialEnvNameOf };
@@ -55,7 +56,7 @@ const SELF_SERVICE_RETRY_POLICIES = new Set([
55
56
  "AFTER_STATUS",
56
57
  ]);
57
58
  const SAFE_SELF_SERVICE_COMMAND =
58
- /^gencow (?:(?:deploy status(?: --prod)?(?: --deployment [1-9][0-9]*| --release-attempt [a-f0-9-]{36})?|deploy status --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)? --release-attempt [a-f0-9-]{36}|deploy status --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)?)|(?:deploy --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)? --resume [A-Za-z0-9_-]{16,128})|(?:db:check(?: --prod)? --inspect-state)|(?:deploy logs(?: --prod)?)|whoami)$/u;
59
+ /^gencow (?:(?:deploy status(?: --prod)?(?: --deployment [1-9][0-9]*| --release-attempt [a-f0-9-]{36})?|deploy status --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)? --release-attempt [a-f0-9-]{36}|deploy status --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)?)|(?:deploy --app [a-z][a-z0-9]*(?:-[a-z0-9]+)*(?: --prod)? --resume [A-Za-z0-9_-]{16,128})|(?:db:check(?: --prod)? --inspect-state)|(?:deploy logs(?: --prod)?)|(?:deploy(?: --prod)?)|(?:static(?: --prod)?)|whoami)$/u;
59
60
 
60
61
  // These known Platform-side failures are already terminal. The diagnostic
61
62
  // asks for no source edits and authorizes no retry; `gencow deploy status` is
@@ -604,6 +605,9 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
604
605
  "Next command: gencow deploy status",
605
606
  ];
606
607
  }
608
+ // A gateway/Platform outage (502/503/504) without a typed contract gets its own retry-aware diagnosis.
609
+ if (isPlatformUnavailableStatus(options.httpStatus))
610
+ return renderPlatformUnavailableLines({ responseBody, statusText, httpStatus: options.httpStatus, retryAfter: options.retryAfter, correlationLine, expectedAppName: options.expectedAppName });
607
611
  // No typed contract: the outcome is unclassified. Say so explicitly, with the CLI's own unknown-state
608
612
  // markers, instead of a bare status line. Only a known deploy stage is echoed; anything else is unknown.
609
613
  // The support-first wording is never printed.
@@ -740,7 +740,7 @@ export function createDeployPackageRuntime({
740
740
  lines.slice(1).forEach((line) => logImpl(line));
741
741
  } else {
742
742
  const lines = renderDeployFailureDiagnosticLines(errData, deployRes.statusText, {
743
- expectedAppName: targetAppId, credentialEnvName: credentialEnvNameOf(creds),
743
+ expectedAppName: targetAppId, credentialEnvName: credentialEnvNameOf(creds), httpStatus: deployRes.status, retryAfter: deployRes.headers?.get?.("retry-after") ?? null,
744
744
  });
745
745
  errorImpl(lines[0]);
746
746
  lines
@@ -0,0 +1,66 @@
1
+ // Renders deploy failures from a Platform/edge gateway outage (HTTP 502/503/504) that arrives without a typed
2
+ // deploy-failure contract. The outcome is unknown: the request may have failed after an upload, so database
3
+ // mutation and incumbent serving stay UNKNOWN. The renderer never dumps the raw response body; it only echoes a
4
+ // body `code` that matches the stable public code format.
5
+
6
+ export const PLATFORM_UNAVAILABLE_DEPLOY_FAILURE_CODE = "CLI_DEPLOY_PLATFORM_UNAVAILABLE";
7
+
8
+ const PLATFORM_UNAVAILABLE_HTTP_STATUSES = new Set([502, 503, 504]);
9
+ const PLATFORM_CODE_PATTERN = /^[A-Z][A-Z0-9_]{2,63}$/u;
10
+ const RETRY_AFTER_PATTERN = /^[1-9][0-9]*$/u;
11
+ const DEFAULT_RETRY_SECONDS = 30;
12
+ const MAX_RETRY_SECONDS = 300;
13
+ const DEFAULT_STATUS_MESSAGE = "Platform temporarily unavailable";
14
+
15
+ export function isPlatformUnavailableStatus(status) {
16
+ return PLATFORM_UNAVAILABLE_HTTP_STATUSES.has(status);
17
+ }
18
+
19
+ function readStatusMessage(value) {
20
+ if (typeof value !== "string") return DEFAULT_STATUS_MESSAGE;
21
+ const normalized = value.trim();
22
+ if (!normalized || normalized.length > 120 || /[\u0000-\u001f\u007f]/u.test(normalized)) {
23
+ return DEFAULT_STATUS_MESSAGE;
24
+ }
25
+ return normalized;
26
+ }
27
+
28
+ function readRetryAfterSeconds(value) {
29
+ if (typeof value !== "string" || !RETRY_AFTER_PATTERN.test(value.trim())) return DEFAULT_RETRY_SECONDS;
30
+ const seconds = Number(value.trim());
31
+ // A longer server-requested wait is capped, not discarded: the Platform asked for at least this long.
32
+ return Math.min(seconds, MAX_RETRY_SECONDS);
33
+ }
34
+
35
+ function readPlatformCode(responseBody) {
36
+ if (!responseBody || typeof responseBody !== "object" || Array.isArray(responseBody)) return null;
37
+ const code = responseBody.code;
38
+ return typeof code === "string" && PLATFORM_CODE_PATTERN.test(code) ? code : null;
39
+ }
40
+
41
+ export function renderPlatformUnavailableLines({
42
+ responseBody = null,
43
+ statusText,
44
+ httpStatus,
45
+ retryAfter = null,
46
+ correlationLine = null,
47
+ expectedAppName,
48
+ } = {}) {
49
+ // A body that names another app (or no expected app) is not this deploy's evidence: echo nothing from it.
50
+ const foreignApp = typeof responseBody?.appName === "string" && responseBody.appName !== expectedAppName;
51
+ const platformCode = foreignApp ? null : readPlatformCode(responseBody);
52
+ const waitSeconds = readRetryAfterSeconds(retryAfter);
53
+ const lines = [
54
+ `Deploy failed: ${readStatusMessage(statusText)}`,
55
+ `Code: ${PLATFORM_UNAVAILABLE_DEPLOY_FAILURE_CODE}`,
56
+ "Stage: unknown",
57
+ `HTTP status: ${httpStatus}`,
58
+ "Database mutation: UNKNOWN",
59
+ "Incumbent serving: UNKNOWN",
60
+ `Retryable: yes (wait ${waitSeconds}s, then run the next command before retrying)`,
61
+ ];
62
+ if (platformCode) lines.push(`Platform code: ${platformCode}`);
63
+ if (correlationLine && !foreignApp) lines.push(correlationLine);
64
+ lines.push("Next command: gencow deploy status");
65
+ return lines;
66
+ }
@@ -0,0 +1,29 @@
1
+ // Typed diagnosis for `gencow deploy status --deployment <id>` when the Platform reports the operation
2
+ // as unknown (HTTP 404 with only the legacy error text). Other 404 shapes keep the generic renderer.
3
+ const OPERATION_NOT_FOUND_TEXT = "Deployment operation not found";
4
+
5
+ function isPlainObject(value) {
6
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
7
+ const proto = Object.getPrototypeOf(value);
8
+ return proto === Object.prototype || proto === null;
9
+ }
10
+
11
+ function isExactOperationNotFoundBody(body) {
12
+ if (!isPlainObject(body)) return false;
13
+ const keys = Object.keys(body);
14
+ return keys.length === 1 && keys[0] === "error" && body.error === OPERATION_NOT_FOUND_TEXT;
15
+ }
16
+
17
+ export function renderDeploymentOperationNotFoundLines({ status, body, deploymentId }) {
18
+ if (status !== 404) return null;
19
+ if (!isExactOperationNotFoundBody(body)) return null;
20
+ if (!Number.isSafeInteger(deploymentId) || deploymentId <= 0) return null;
21
+ return [
22
+ `DEPLOYMENT_OPERATION_NOT_FOUND: Deployment ${deploymentId} was not found for this account.`,
23
+ "Stage: status_lookup",
24
+ "Changed: nothing; status is read-only.",
25
+ "Why: the id may be wrong, belong to another account, or belong to an app that was deleted.",
26
+ "Retry: no, until the id or app is corrected.",
27
+ "Next command: gencow app list",
28
+ ];
29
+ }
@@ -698,6 +698,8 @@ export function createStaticDeployRuntime({
698
698
  const [headline, ...details] = renderDeployFailureDiagnosticLines(errData, deployRes.statusText, {
699
699
  expectedAppName: appId,
700
700
  credentialEnvName: credentialEnvNameOf(creds),
701
+ httpStatus: deployRes.status,
702
+ retryAfter: deployRes.headers?.get?.("retry-after") ?? null,
701
703
  });
702
704
  errorImpl(headline.replace(/^Deploy failed:/u, "Static deploy failed:"));
703
705
  for (const line of details) infoImpl(line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gencow",
3
- "version": "0.1.291",
3
+ "version": "0.1.293",
4
4
  "description": "Gencow — AI Backend Engine",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,9 +40,9 @@
40
40
  "ai": "^6.0.326",
41
41
  "better-auth": "1.7.11",
42
42
  "postgres": "^3.4.9",
43
+ "@gencow/client": "0.2.9",
43
44
  "@gencow/core": "0.1.48",
44
- "@gencow/client": "0.2.8",
45
- "@gencow/react": "0.2.8",
45
+ "@gencow/react": "0.2.9",
46
46
  "@gencow/server": "0.1.3",
47
47
  "@gencow/shared": "0.0.0"
48
48
  },