gencow 0.1.285 → 0.1.286

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.
@@ -23,7 +23,7 @@
23
23
  <link rel="icon" type="image/png" sizes="32x32" href="/_dashboard/favicon-32.png" />
24
24
  <link rel="icon" type="image/png" sizes="16x16" href="/_dashboard/favicon-16.png" />
25
25
  <link rel="apple-touch-icon" sizes="180x180" href="/_dashboard/apple-touch-icon.png" />
26
- <script type="module" crossorigin src="/_dashboard/assets/index-CpQz6uv1.js"></script>
26
+ <script type="module" crossorigin src="/_dashboard/assets/index-BnBn8uo4.js"></script>
27
27
  <link rel="stylesheet" crossorigin href="/_dashboard/assets/index-C6-BpKKR.css">
28
28
  </head>
29
29
  <body class="antialiased">
@@ -1,4 +1,5 @@
1
1
  import { formatLatestCliInvocation } from "./cli-update-guidance.mjs";
2
+ import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
2
3
 
3
4
  import {
4
5
  APP_DELETE_OPERATION_PATTERN,
@@ -39,6 +40,31 @@ const USER_ACTIONS = new Set([
39
40
  "WAIT",
40
41
  ]);
41
42
 
43
+ // Only a credential the Platform refused (CLI_AUTH_REQUIRED, stage "auth", not retryable) gets the login-check
44
+ // rendering. Other stage "auth" responses (for example a suspended account) keep the generic path, because a
45
+ // login retry would misattribute the cause. The safe cause is shown only when it is a known enum.
46
+ function isTypedAuthRejection(body) {
47
+ return (
48
+ body.code === "CLI_AUTH_REQUIRED" &&
49
+ body.stage === "auth" &&
50
+ body.retryable !== true
51
+ );
52
+ }
53
+
54
+ function formatTypedAuthRejectionLines(body) {
55
+ const message = typeof body.error === "string" && body.error.trim() ? body.error.trim() : "CLI authentication is required";
56
+ const lines = [message, `Code: ${body.code}`];
57
+ const cause = safeAuthCauseCode(body.causeCode);
58
+ if (cause) lines.push(`Cause: ${cause}`);
59
+ if (body.stateChanged === false) lines.push("Changed: nothing");
60
+ lines.push("Retryable: no");
61
+ if (/^[A-Za-z0-9_-]{8,128}$/u.test(body.correlationId ?? "")) {
62
+ lines.push(`Correlation ID: ${body.correlationId}`);
63
+ }
64
+ lines.push(`Next: ${authCauseNextAction()}`);
65
+ return lines;
66
+ }
67
+
42
68
  export function appResponseError(body, fallback, response = null, options = {}) {
43
69
  if (!body || typeof body !== "object" || Array.isArray(body)) {
44
70
  if (response?.status === 503) {
@@ -46,6 +72,7 @@ export function appResponseError(body, fallback, response = null, options = {})
46
72
  }
47
73
  return fallback;
48
74
  }
75
+ if (isTypedAuthRejection(body)) return formatTypedAuthRejectionLines(body).join("\n");
49
76
  const blockedDeleteDiagnostic = readBlockedAppDeleteDiagnostic(body, options.expectedAppId);
50
77
  if (blockedDeleteDiagnostic) {
51
78
  return formatBlockedAppDeleteDiagnosticLines(blockedDeleteDiagnostic).join("\n");
@@ -4,12 +4,17 @@
4
4
  const DEFAULT_DB_CHECK_TIMEOUT_MS = 60_000;
5
5
  export const DEADLINE_EXCEEDED = Symbol("db-check-deadline-exceeded");
6
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) {
7
+ /**
8
+ * Out-of-range or non-numeric values fall back to the given default, matching the app query deadline policy.
9
+ * Shared by every read-only request deadline (db:check, deploy target lookup) so the range rule has one owner.
10
+ */
11
+ export function resolveReadOnlyDeadlineMs(value, defaultMs) {
9
12
  const parsed = Number(value);
10
- return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000
11
- ? parsed
12
- : DEFAULT_DB_CHECK_TIMEOUT_MS;
13
+ return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000 ? parsed : defaultMs;
14
+ }
15
+
16
+ export function resolveDbCheckTimeoutMs(value) {
17
+ return resolveReadOnlyDeadlineMs(value, DEFAULT_DB_CHECK_TIMEOUT_MS);
13
18
  }
14
19
 
15
20
  /**
@@ -1,5 +1,11 @@
1
1
  import { appNotFoundDiagnostic } from "./app-response-contract.mjs";
2
2
  import { describeProdTargetFailure, resolveProdAppTarget } from "./cloud-targets.mjs";
3
+ import {
4
+ createReadOnlyCheckDeadline,
5
+ DEADLINE_EXCEEDED,
6
+ resolveReadOnlyDeadlineMs,
7
+ withCheckDeadline,
8
+ } from "./db-check-deadline.mjs";
3
9
  import { responseHeaderCorrelationId, SAFE_CORRELATION_ID } from "./http-correlation-id.mjs";
4
10
  import { readJsonObjectResponse } from "./http-response-json.mjs";
5
11
  import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
@@ -14,6 +20,17 @@ const PUBLIC_LOOKUP_ERROR_CODES = new Set([
14
20
  "APP_RELEASE_POLICY_READ_UNAVAILABLE",
15
21
  ]);
16
22
  const UNTYPED_STAGE = "deploy target lookup";
23
+ const DEPLOY_TARGET_LOOKUP_TIMEOUT_ENV = "GENCOW_DEPLOY_TARGET_LOOKUP_TIMEOUT_MS";
24
+ const DEFAULT_DEPLOY_TARGET_LOOKUP_TIMEOUT_MS = 30_000;
25
+
26
+ /** Bounds the read-only release-capability lookup; the value is read at call time so an override takes effect. */
27
+ export function resolveDeployTargetLookupTimeoutMs(value) {
28
+ return resolveReadOnlyDeadlineMs(value, DEFAULT_DEPLOY_TARGET_LOOKUP_TIMEOUT_MS);
29
+ }
30
+
31
+ function formatDeadlineDuration(ms) {
32
+ return ms % 1000 === 0 ? `${ms / 1000}s` : `${ms}ms`;
33
+ }
17
34
 
18
35
  function publicLookupFailure(response, body, creds) {
19
36
  const typed = PUBLIC_LOOKUP_ERROR_CODES.has(body?.code);
@@ -54,9 +71,27 @@ function publicLookupFailure(response, body, creds) {
54
71
  };
55
72
  }
56
73
 
74
+ // Silent Platform past the read-only deadline. Nothing was sent or changed: the lookup runs before the source upload.
75
+ function formatDeadlineLookupFailure(failure, target, retryCommand) {
76
+ const lines = [
77
+ `${failure.code}: Could not verify the configured ${target} app. No replacement app was created and gencow.json was unchanged.`,
78
+ `Stage: ${UNTYPED_STAGE} (existing ${failure.environment} app, release-capability)`,
79
+ `Response: none within ${formatDeadlineDuration(failure.timeoutMs)} (request deadline exceeded)`,
80
+ `Changed: nothing. The lookup stopped before any source upload; no app was created or deployed, gencow.json was not modified, and app data and the serving state were not changed.`,
81
+ "Incumbent serving: PRESERVED (this lookup did not change it)",
82
+ "Retryable: yes (the lookup is read-only; retry once the Platform responds)",
83
+ `Timeout setting: ${DEPLOY_TARGET_LOOKUP_TIMEOUT_ENV} (100 to 600000 ms, default ${DEFAULT_DEPLOY_TARGET_LOOKUP_TIMEOUT_MS})`,
84
+ "Correlation ID: none returned",
85
+ `Rerun: ${retryCommand ?? "the same deploy command"}`,
86
+ `Action: wait 5-10 seconds for Platform release capability to respond, then rerun the same command once. If it stays silent, add the failure time (UTC) to the GitHub issue.`,
87
+ ];
88
+ return lines.join("\n");
89
+ }
90
+
57
91
  // Lookup failure without a typed Platform error: an untyped 5xx, or no HTTP response at all (network error).
58
92
  // Serving is stated only for this lookup: a GET changes nothing, so the incumbent serving state is unchanged by it.
59
93
  function formatUntypedLookupFailure(failure, target, retryCommand) {
94
+ if (failure.deadlineExceeded) return formatDeadlineLookupFailure(failure, target, retryCommand);
60
95
  const lines = [
61
96
  `${failure.code}: Could not verify the configured ${target} app. No replacement app was created and gencow.json was unchanged.`,
62
97
  `Stage: ${UNTYPED_STAGE}`,
@@ -227,22 +262,54 @@ export function checkExplicitProdAppTarget({ explicitAppId, prodApp, projectAppI
227
262
  return false;
228
263
  }
229
264
 
230
- export async function lookupOwnedApp({ creds, appId, environment, platformFetchImpl }) {
265
+ async function fetchOwnedAppState({ creds, appId, environment, platformFetchImpl, signal }) {
266
+ const response = await platformFetchImpl(
267
+ creds,
268
+ `/platform/apps/${appId}/release-capability?environment=${environment}`,
269
+ { method: "GET", signal },
270
+ );
271
+ const body = await readJsonObjectResponse(response);
272
+ if (response.status === 404) {
273
+ if (body?.code === "APP_RELEASE_APP_NOT_FOUND") return "missing";
274
+ return body?.code ? publicLookupFailure(response, body, creds) : "unsupported";
275
+ }
276
+ if (response.status === 409 && body?.code === "APP_RELEASE_VERSIONS_DISABLED") return "found";
277
+ if (!response.ok) return publicLookupFailure(response, body, creds);
278
+ return body?.protocol === "app-release-v1" && typeof body.enabled === "boolean" ? "found" : "error";
279
+ }
280
+
281
+ function deadlineExceededLookup({ environment, timeoutMs }) {
282
+ return {
283
+ kind: "error",
284
+ code: "APP_RELEASE_CAPABILITY_UNAVAILABLE",
285
+ retryable: true,
286
+ untyped: true,
287
+ deadlineExceeded: true,
288
+ environment,
289
+ timeoutMs,
290
+ };
291
+ }
292
+
293
+ // The whole lookup (request and body read) is bounded: a silent Platform must not hang the deploy before any
294
+ // output. The deadline is read-only, so an expiry is reported as a retryable lookup failure, not a write outcome.
295
+ export async function lookupOwnedApp({
296
+ creds,
297
+ appId,
298
+ environment,
299
+ platformFetchImpl,
300
+ timeoutMs = resolveDeployTargetLookupTimeoutMs(process.env[DEPLOY_TARGET_LOOKUP_TIMEOUT_ENV]),
301
+ }) {
302
+ const deadline = createReadOnlyCheckDeadline(timeoutMs);
231
303
  try {
232
- const response = await platformFetchImpl(
233
- creds,
234
- `/platform/apps/${appId}/release-capability?environment=${environment}`,
235
- { method: "GET" },
304
+ const outcome = await withCheckDeadline(
305
+ fetchOwnedAppState({ creds, appId, environment, platformFetchImpl, signal: deadline.signal }),
306
+ deadline,
236
307
  );
237
- const body = await readJsonObjectResponse(response);
238
- if (response.status === 404) {
239
- if (body?.code === "APP_RELEASE_APP_NOT_FOUND") return "missing";
240
- return body?.code ? publicLookupFailure(response, body, creds) : "unsupported";
241
- }
242
- if (response.status === 409 && body?.code === "APP_RELEASE_VERSIONS_DISABLED") return "found";
243
- if (!response.ok) return publicLookupFailure(response, body, creds);
244
- return body?.protocol === "app-release-v1" && typeof body.enabled === "boolean" ? "found" : "error";
308
+ if (outcome === DEADLINE_EXCEEDED) return deadlineExceededLookup({ environment, timeoutMs });
309
+ return outcome;
245
310
  } catch {
311
+ // A signal-aware fetch rejects on abort; that rejection is the deadline, not a network error.
312
+ if (deadline.timedOut) return deadlineExceededLookup({ environment, timeoutMs });
246
313
  return {
247
314
  kind: "error",
248
315
  code: "APP_RELEASE_CAPABILITY_UNAVAILABLE",
@@ -250,6 +317,8 @@ export async function lookupOwnedApp({ creds, appId, environment, platformFetchI
250
317
  untyped: true,
251
318
  transportError: true,
252
319
  };
320
+ } finally {
321
+ deadline.clear();
253
322
  }
254
323
  }
255
324
 
@@ -12,8 +12,12 @@ const MAX_SAFE_PATH_LENGTH = 240;
12
12
  // The location pattern backtracks quadratically on long unbroken text, so only the head of a message is classified.
13
13
  const MAX_CLASSIFIED_MESSAGE_LENGTH = 8192;
14
14
  // Matches `<path>.<ts|js|...>:<line>[:<column>]` as emitted by esbuild and the
15
- // loader wrapper in tooling-codegen-runtime.ts. Only the matched location is kept.
15
+ // Bun build message for transpile diagnostics. Only the matched location is kept.
16
16
  const SOURCE_LOCATION_PATTERN = /([^\s'"`<>()[\]]+?\.[cm]?[jt]sx?):([1-9]\d{0,5})(?::([1-9]\d{0,5}))?/gu;
17
+ // The dedicated line the producer adds for a loader failure. Only this line can name a loader location:
18
+ // text the user wrote in an error message is never a location. The value is `<path>:<line>[:<column>]`.
19
+ const LOADER_LOCATION_LINE_PATTERN = /^Loader location: (.+)$/gmu;
20
+ const LOADER_LOCATION_VALUE_PATTERN = /^(.+?):([1-9]\d{0,5})(?::([1-9]\d{0,5}))?$/u;
17
21
 
18
22
  // esbuild prints paths relative to the process working directory, while the Bun
19
23
  // loader prints absolute paths; both are converted to a project-relative path.
@@ -44,6 +48,8 @@ const MISSING_EXPORT_PATTERN = /No matching export in "[^"\n]*" for import "([A-
44
48
  // The specifier of an unresolved import, as esbuild and the named-import check print it. It is
45
49
  // only carried here; the renderer decides whether it is safe to show.
46
50
  const UNRESOLVED_SPECIFIER_PATTERN = /Could not resolve "([^"\n]{1,240})"/u;
51
+ // The Bun loader's form for the same failure: `Cannot find module '<specifier>' from '<importer>'`.
52
+ const LOADER_UNRESOLVED_SPECIFIER_PATTERN = /Cannot find module '([^'\n]{1,240})'/u;
47
53
 
48
54
  // The first diagnostic decides the class, matching how the first location is reported.
49
55
  function firstDiagnosticLine(message) {
@@ -77,6 +83,21 @@ function findProjectSourceLocation(message, { cwd, processCwd }) {
77
83
  return null;
78
84
  }
79
85
 
86
+ // Returns the project-relative location of a loader failure, read only from the `Loader location:` line.
87
+ // The producer appends that line after the raw loader text, so the last such line is the producer's own.
88
+ // A path with spaces or a drive letter is kept whole because the line is parsed as one value.
89
+ function findLoaderLocation(message, { cwd, processCwd }) {
90
+ let value = null;
91
+ for (const match of message.matchAll(LOADER_LOCATION_LINE_PATTERN)) value = match[1];
92
+ const parsed = value === null ? null : LOADER_LOCATION_VALUE_PATTERN.exec(value.trimEnd());
93
+ if (!parsed) return null;
94
+ const sourceFile = toProjectRelativePath(parsed[1], cwd, processCwd);
95
+ if (!sourceFile) return null;
96
+ const location = { sourceFile, line: Number(parsed[2]) };
97
+ if (parsed[3] !== undefined) location.column = Number(parsed[3]);
98
+ return location;
99
+ }
100
+
80
101
  // Classifies a codegen failure from its raw error. The result is safe to show publicly.
81
102
  // `sourceFile` is only returned for backend source (under backendRoot), so the
82
103
  // public location never points at a dependency or a file outside the backend.
@@ -103,7 +124,16 @@ export function classifyDeployCodegenFailure(error, { cwd, backendRoot = "gencow
103
124
  }
104
125
  }
105
126
  if (message.includes("Loader error:")) {
106
- return { code: CODEGEN_FAILURE_CODES.SOURCE_LOAD_FAILED };
127
+ // A loader failure has no syntax position; its location is the `Loader location:` line that the
128
+ // producer adds when the loader names one. The raw loader text is never returned.
129
+ const location = findLoaderLocation(message, { cwd, processCwd });
130
+ const backendLocation = location && location.sourceFile.startsWith(`${backendRoot}/`) ? location : null;
131
+ const unresolvedSpecifier = LOADER_UNRESOLVED_SPECIFIER_PATTERN.exec(message)?.[1];
132
+ return {
133
+ code: CODEGEN_FAILURE_CODES.SOURCE_LOAD_FAILED,
134
+ ...(backendLocation ?? {}),
135
+ ...(unresolvedSpecifier ? { unresolvedSpecifier } : {}),
136
+ };
107
137
  }
108
138
  return { code: CODEGEN_FAILURE_CODES.GENERATION_FAILED };
109
139
  }
@@ -161,10 +191,12 @@ export function createDeployCodegenFailure(classification, { correlationId } = {
161
191
  const error = new Error(classification.code);
162
192
  error.code = classification.code;
163
193
  error.stage = "codegen";
194
+ // Bun Error objects carry the line and column of their construction as own properties. Overwrite
195
+ // them so a failure without a location never reports the position of this helper.
196
+ error.line = classification.sourceFile !== undefined ? classification.line : undefined;
197
+ error.column = classification.sourceFile !== undefined ? classification.column : undefined;
164
198
  if (classification.sourceFile !== undefined) {
165
199
  error.sourceFile = classification.sourceFile;
166
- error.line = classification.line;
167
- if (classification.column !== undefined) error.column = classification.column;
168
200
  }
169
201
  if (classification.missingExport !== undefined) error.missingExport = classification.missingExport;
170
202
  if (classification.unresolvedSpecifier !== undefined) error.unresolvedSpecifier = classification.unresolvedSpecifier;
@@ -54,7 +54,7 @@ const SELF_SERVICE_RETRY_POLICIES = new Set([
54
54
  "AFTER_STATUS",
55
55
  ]);
56
56
  const SAFE_SELF_SERVICE_COMMAND =
57
- /^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)|whoami)$/u;
57
+ /^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;
58
58
 
59
59
  // These known Platform-side failures are already terminal. The diagnostic
60
60
  // asks for no source edits and authorizes no retry; `gencow deploy status` is
@@ -494,6 +494,18 @@ function appendPendingState(lines, responseBody, retryClass, retryCondition) {
494
494
  );
495
495
  }
496
496
 
497
+ // Customer-fixable candidate startup failure: the app's schema/relations source did not load.
498
+ // When the response carries no typed self-service diagnosis, the CLI states the same contract itself
499
+ // and marks the database state UNKNOWN rather than guessing it.
500
+ const SOURCE_SCHEMA_INVALID_CODE = "RUNTIME_RELATIONS_SCHEMA_INVALID";
501
+ function isSourceSchemaInvalidContract(contract) {
502
+ return (
503
+ contract.code === SOURCE_SCHEMA_INVALID_CODE &&
504
+ contract.stage === "candidate" &&
505
+ contract.userAction === "EDIT_AND_CHECK"
506
+ );
507
+ }
508
+
497
509
  function isCliUpgradeContract(contract) {
498
510
  return (
499
511
  contract.code === "DEPLOY_CLI_UPGRADE_REQUIRED" &&
@@ -679,6 +691,14 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
679
691
  "Retry policy: AFTER_FIX — Update the CLI before retrying.",
680
692
  );
681
693
  }
694
+ const sourceSchemaWithoutDiagnosis = isSourceSchemaInvalidContract(contract) && !selfService;
695
+ if (sourceSchemaWithoutDiagnosis) {
696
+ lines.push(
697
+ "Database mutation: UNKNOWN",
698
+ "Incumbent serving: UNKNOWN",
699
+ "Retry policy: AFTER_FIX — Fix the schema/relations source, then deploy again; do not repeat this same deployment unchanged.",
700
+ );
701
+ }
682
702
  const correlationLine = formatDeployCorrelationId(contract.correlationId);
683
703
  if (correlationLine) lines.push(correlationLine);
684
704
  appendRootCauseLines(
@@ -693,7 +713,9 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
693
713
  ? `Next command: ${formatLatestCliInvocation("deploy")}`
694
714
  : selfService?.action.command
695
715
  ? `Next command: ${selfService.action.command}`
696
- : `Next action: ${contract.userAction}`,
716
+ : sourceSchemaWithoutDiagnosis
717
+ ? "Next command: gencow deploy logs (add --prod for production)"
718
+ : `Next action: ${contract.userAction}`,
697
719
  );
698
720
  return lines;
699
721
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gencow",
3
- "version": "0.1.285",
3
+ "version": "0.1.286",
4
4
  "description": "Gencow — AI Backend Engine",
5
5
  "type": "module",
6
6
  "bin": {
@@ -42,9 +42,9 @@
42
42
  "postgres": "^3.4.9",
43
43
  "@gencow/client": "0.2.8",
44
44
  "@gencow/core": "0.1.47",
45
- "@gencow/shared": "0.0.0",
45
+ "@gencow/react": "0.2.8",
46
46
  "@gencow/server": "0.1.3",
47
- "@gencow/react": "0.2.8"
47
+ "@gencow/shared": "0.0.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",