gencow 0.1.295 → 0.1.297

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.
@@ -1,8 +1,9 @@
1
1
  // Typed diagnosis for a deploy admission request that got no HTTP response.
2
2
  //
3
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.
4
+ // - ERR_INVALID_URL, CLI_REQUEST_HEADER_INVALID: the request was rejected before any network
5
+ // I/O (a malformed Platform URL, or a header value that cannot be sent). Nothing was sent,
6
+ // so the state is known: NOT CHANGED.
6
7
  // - Any other rejection: a network-layer failure. The request may have reached the
7
8
  // Platform, so the state is UNKNOWN and the next step is a status check before a rerun.
8
9
  //
@@ -38,7 +39,11 @@ const KNOWN_CAUSE_CODES = new Set([
38
39
  "ConnectionRefused",
39
40
  ]);
40
41
 
41
- const NOT_SENT_CAUSE_CODE = "ERR_INVALID_URL";
42
+ const INVALID_URL_CAUSE_CODE = "ERR_INVALID_URL";
43
+ // Thrown by platformFetch before fetch is called (see platform-client.mjs).
44
+ const INVALID_HEADER_CAUSE_CODE = "CLI_REQUEST_HEADER_INVALID";
45
+ const NOT_SENT_CAUSE_CODES = new Set([INVALID_URL_CAUSE_CODE, INVALID_HEADER_CAUSE_CODE]);
46
+ const SAFE_HEADER_NAME = /^[A-Za-z][A-Za-z0-9-]{0,63}$/u;
42
47
  // Release steps that run before any serving change. Only these may be rendered as
43
48
  // "Database: NOT CHANGED" with a stage label; the deploy admission submit keeps its own wording.
44
49
  const RELEASE_STAGES = new Set(["release capability check", "release-attempt registration"]);
@@ -60,6 +65,14 @@ function readAllowlistedCauseCode(cause) {
60
65
  return code !== null && KNOWN_CAUSE_CODES.has(code) ? code : null;
61
66
  }
62
67
 
68
+ // The header a local check refused to send: { name } (name is null when it is not a safe token),
69
+ // or null when the cause is something else. The header value is never read.
70
+ function readInvalidHeader(cause) {
71
+ if (readCauseCode(cause) !== INVALID_HEADER_CAUSE_CODE) return null;
72
+ const name = cause?.headerName ?? cause?.cause?.headerName;
73
+ return { name: typeof name === "string" && SAFE_HEADER_NAME.test(name) ? name : null };
74
+ }
75
+
63
76
  // The in-process message stays the original cause text, so callers that inspect the thrown
64
77
  // error keep their existing contract. The CLI prints only the typed rendering, never this message.
65
78
  export function createAdmissionTransportFailure({
@@ -77,7 +90,8 @@ export function createAdmissionTransportFailure({
77
90
  appName: typeof appName === "string" && SAFE_APP_ID.test(appName) ? appName : null,
78
91
  requestId: typeof requestId === "string" && SAFE_REQUEST_ID.test(requestId) ? requestId : null,
79
92
  envTarget: envTarget === "prod" ? "prod" : "dev",
80
- requestSent: readCauseCode(cause) !== NOT_SENT_CAUSE_CODE,
93
+ requestSent: !NOT_SENT_CAUSE_CODES.has(readCauseCode(cause)),
94
+ invalidHeader: readInvalidHeader(cause),
81
95
  causeMessage: readAllowlistedCauseMessage(cause),
82
96
  causeCode: readAllowlistedCauseCode(cause),
83
97
  attempts: null,
@@ -112,6 +126,32 @@ function causeLine(detail) {
112
126
  return detail.causeMessage ? `Cause: ${detail.causeMessage}` : `Cause: network error (${detail.causeCode})`;
113
127
  }
114
128
 
129
+ function invalidHeaderCauseLine(invalidHeader) {
130
+ return invalidHeader.name
131
+ ? `Cause: the ${invalidHeader.name} request header has a value that cannot be sent over HTTP`
132
+ : "Cause: a request header has a value that cannot be sent over HTTP";
133
+ }
134
+
135
+ // What to fix before a rerun when the request never left this machine.
136
+ function notSentNextLines(invalidHeader) {
137
+ const urlLines = [
138
+ "Retryable: yes, after the Platform URL setting is fixed",
139
+ "Next: check the Platform URL in your CLI login/configuration, then rerun the same deploy command.",
140
+ ];
141
+ if (!invalidHeader) return urlLines;
142
+ if (invalidHeader.name === "Origin") return urlLines;
143
+ if (invalidHeader.name === "Authorization") {
144
+ return [
145
+ "Retryable: yes, after the saved CLI credential is replaced",
146
+ "Next: run `gencow login` (or set a valid GENCOW_TOKEN), then rerun the same deploy command.",
147
+ ];
148
+ }
149
+ return [
150
+ "Retryable: yes, after the CLI is updated",
151
+ "Next: rerun the same deploy command with the latest CLI (for example `npx gencow@latest deploy`). If it fails again, report the header name above and the CLI version (`gencow --version`) in a GitHub issue.",
152
+ ];
153
+ }
154
+
115
155
  // Release steps before the serving change. The capability check is read-only; a registration
116
156
  // that got no response is not confirmed to have created anything, so the rerun is the plain
117
157
  // deploy command (no request ID or --resume).
@@ -144,7 +184,9 @@ function releaseStageLines(detail) {
144
184
  return lines;
145
185
  }
146
186
 
147
- export function renderAdmissionTransportFailureLines(caught) {
187
+ // `resumeCommand` lets a caller whose resume entry point differs from `gencow deploy --resume`
188
+ // (for example `gencow deploy --static ...`) name its own exact command.
189
+ export function renderAdmissionTransportFailureLines(caught, { resumeCommand = null } = {}) {
148
190
  const detail = caught.deployAdmissionTransport;
149
191
  if (detail.stage) return releaseStageLines(detail);
150
192
  const prodFlag = detail.envTarget === "prod" ? " --prod" : "";
@@ -160,7 +202,7 @@ export function renderAdmissionTransportFailureLines(caught) {
160
202
  );
161
203
  if (detail.appName) lines.push(`App ID: ${detail.appName}`);
162
204
  lines.push(detail.requestSent ? "Response: none received (network error)" : "Response: none (request not sent)");
163
- lines.push(causeLine(detail));
205
+ lines.push(detail.invalidHeader ? invalidHeaderCauseLine(detail.invalidHeader) : causeLine(detail));
164
206
  lines.push(`Request ID: ${detail.requestId ?? "none"}`);
165
207
  lines.push("Correlation ID: none (no response from the Platform)");
166
208
  const attempts = attemptsLine(detail);
@@ -169,8 +211,7 @@ export function renderAdmissionTransportFailureLines(caught) {
169
211
  if (!detail.requestSent) {
170
212
  lines.push("Database: NOT CHANGED (no request was sent)");
171
213
  lines.push("Incumbent serving: PRESERVED (no request was sent)");
172
- lines.push("Retryable: yes, after the Platform URL setting is fixed");
173
- lines.push("Next: check the Platform URL in your CLI login/configuration, then rerun the same deploy command.");
214
+ lines.push(...notSentNextLines(detail.invalidHeader));
174
215
  return lines;
175
216
  }
176
217
 
@@ -183,11 +224,21 @@ export function renderAdmissionTransportFailureLines(caught) {
183
224
  `Next: gencow deploy status${prodFlag} (shows the app status and last deployed time; a deployment from this attempt may or may not appear)`,
184
225
  );
185
226
  if (detail.requestId) {
186
- lines.push(
187
- `Then: if no deployment from this attempt appears, rerun with the same request ID: gencow deploy --resume ${detail.requestId}${prodFlag}`,
188
- );
227
+ const resume =
228
+ typeof resumeCommand === "string" && resumeCommand ? resumeCommand : `gencow deploy --resume ${detail.requestId}${prodFlag}`;
229
+ lines.push(`Then: if no deployment from this attempt appears, rerun with the same request ID: ${resume}`);
189
230
  } else {
190
231
  lines.push("Then: if no deployment from this attempt appears, rerun the same deploy command. Do not rerun first.");
191
232
  }
192
233
  return lines;
193
234
  }
235
+
236
+ // Prints the typed rendering through the caller's output functions. Returns false (and prints
237
+ // nothing) when `caught` is not a typed transport failure, so the caller can use its own fallback.
238
+ export function reportAdmissionTransportFailure(caught, { resumeCommand = null, errorImpl, infoImpl }) {
239
+ if (!isAdmissionTransportFailure(caught)) return false;
240
+ const [headline, ...details] = renderAdmissionTransportFailureLines(caught, { resumeCommand });
241
+ errorImpl(headline);
242
+ for (const line of details) infoImpl(line);
243
+ return true;
244
+ }
@@ -0,0 +1,23 @@
1
+ // Request headers that tell the Platform which local directory a deploy came from.
2
+ //
3
+ // An HTTP header value cannot carry characters outside Latin-1, so a directory such as
4
+ // /Users/홍길동/app makes fetch reject the request before anything is sent. A directory that
5
+ // is plain printable ASCII keeps the original header, which every Platform version reads.
6
+ // Any other directory is sent percent-encoded (UTF-8) in a separate header: a Platform that
7
+ // predates it ignores the header and records no directory, and the deploy still runs.
8
+
9
+ const PLAIN_HEADER = "X-Deploy-Local-Dir";
10
+ const ENCODED_HEADER = "X-Deploy-Local-Dir-Encoded";
11
+ // Printable ASCII with no leading or trailing space (a header value is trimmed in transit).
12
+ const PLAIN_SAFE_VALUE = /^[\x21-\x7e](?:[\x20-\x7e]*[\x21-\x7e])?$/u;
13
+
14
+ export function deployLocalDirHeaders(localDir) {
15
+ if (typeof localDir !== "string" || localDir.length === 0) return {};
16
+ if (PLAIN_SAFE_VALUE.test(localDir)) return { [PLAIN_HEADER]: localDir };
17
+ try {
18
+ return { [ENCODED_HEADER]: encodeURIComponent(localDir) };
19
+ } catch {
20
+ // A lone surrogate cannot be encoded. The directory is display metadata, so it is left out.
21
+ return {};
22
+ }
23
+ }
@@ -28,6 +28,7 @@ import { credentialEnvNameOf, renderDeployFailureDiagnosticLines } from "./deplo
28
28
  import { readJsonObjectResponse } from "./http-response-json.mjs";
29
29
  import { createDeploymentProgressObservers, pollAcceptedDeploymentOperation } from "./deployment-operation-poll.mjs";
30
30
  import { postDeploymentAdmissionWithTimeout } from "./deploy-admission-boundary.mjs";
31
+ import { deployLocalDirHeaders } from "./deploy-local-dir-header.mjs";
31
32
  import { submitDeploymentWithIdempotentRetry } from "./deployment-admission-retry.mjs";
32
33
  import * as deployReceiptStore from "./deploy-receipt-store.mjs";
33
34
  import { CYAN, DIM, RED, RESET, YELLOW, error, info, log, success, warn } from "./output.mjs";
@@ -562,7 +563,7 @@ export function createDeployPackageRuntime({
562
563
  method: "POST",
563
564
  headers: {
564
565
  "Content-Type": "application/octet-stream",
565
- "X-Deploy-Local-Dir": cwd,
566
+ ...deployLocalDirHeaders(cwd),
566
567
  ...(activeReleaseAttemptId
567
568
  ? {
568
569
  "X-Gencow-Release-Attempt-Id": activeReleaseAttemptId,
@@ -34,6 +34,7 @@ import {
34
34
  import { buildClientUserFixableDiagnostic } from "./migration-client-diagnostic.mjs";
35
35
  import { metadataErrorDetails } from "./metadata-diagnostic.mjs";
36
36
  import { formatCommandError } from "./cli-command-runner.mjs";
37
+ import { deployLocalDirHeaders } from "./deploy-local-dir-header.mjs";
37
38
 
38
39
  export function resolveDevCloudAppName({
39
40
  cloudArgs,
@@ -316,7 +317,7 @@ export function createDevCloudCommand(deps) {
316
317
  method: "POST",
317
318
  body: form,
318
319
  headers: {
319
- "X-Deploy-Local-Dir": projectDir,
320
+ ...deployLocalDirHeaders(projectDir),
320
321
  ...protocolHeaders,
321
322
  },
322
323
  });
@@ -102,17 +102,45 @@ export function requireCreds({ throwOnMissing = false } = {}) {
102
102
  return creds;
103
103
  }
104
104
 
105
+ export const REQUEST_HEADER_INVALID_CODE = "CLI_REQUEST_HEADER_INVALID";
106
+
107
+ // fetch rejects a header value it cannot encode before any network I/O, with a runtime-specific
108
+ // TypeError that looks like a network failure to callers. Checking here gives one stable code and
109
+ // the header name. The value is never included: it can be a credential.
110
+ function assertSendableRequestHeaders(headers) {
111
+ try {
112
+ new Headers(headers);
113
+ return;
114
+ } catch {
115
+ // Fall through to name the header.
116
+ }
117
+ const headerName =
118
+ Object.entries(headers).find(([name, value]) => {
119
+ try {
120
+ new Headers([[name, value]]);
121
+ return false;
122
+ } catch {
123
+ return true;
124
+ }
125
+ })?.[0] ?? null;
126
+ const error = new Error(
127
+ `${REQUEST_HEADER_INVALID_CODE}: the request was not sent because the ${headerName ?? "request"} header value cannot be sent over HTTP.`,
128
+ );
129
+ error.code = REQUEST_HEADER_INVALID_CODE;
130
+ error.headerName = headerName;
131
+ throw error;
132
+ }
133
+
105
134
  export async function platformFetch(creds, path, opts = {}) {
106
135
  const url = `${creds.platformUrl}${path}`;
107
- return fetch(url, {
108
- ...opts,
109
- headers: {
110
- Authorization: `Bearer ${creds.apiKey}`,
111
- Origin: creds.platformUrl,
112
- ...opts.headers,
113
- "X-Gencow-CLI-Capabilities": CLI_CAPABILITIES,
114
- },
115
- });
136
+ const headers = {
137
+ Authorization: `Bearer ${creds.apiKey}`,
138
+ Origin: creds.platformUrl,
139
+ ...opts.headers,
140
+ "X-Gencow-CLI-Capabilities": CLI_CAPABILITIES,
141
+ };
142
+ assertSendableRequestHeaders(headers);
143
+ return fetch(url, { ...opts, headers });
116
144
  }
117
145
 
118
146
  function safePlatformCorrelationId(value) {
@@ -25,6 +25,8 @@ import { renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.
25
25
  import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
26
26
  import { writeProjectMetadata } from "./deploy-project-metadata.mjs";
27
27
  import { postDeploymentAdmissionWithTimeout } from "./deploy-admission-boundary.mjs";
28
+ import { deployLocalDirHeaders } from "./deploy-local-dir-header.mjs";
29
+ import { recordAdmissionTransportAttempts, reportAdmissionTransportFailure } from "./deploy-admission-transport-failure.mjs";
28
30
  import { installLocalDeployInterruptGuard } from "./local-deploy-interrupt-guard.mjs";
29
31
  import {
30
32
  loadStaticDeployReceipt,
@@ -66,7 +68,10 @@ export async function postStaticDeployWithTransientProxyRetry({
66
68
  // release attempt). Replaying it is admission observation, not a new
67
69
  // static deployment. Keep this bounded; the final transport error is
68
70
  // still reported to the caller without inventing a terminal outcome.
69
- if (attempt >= retryDelaysMs.length) throw error;
71
+ if (attempt >= retryDelaysMs.length) {
72
+ recordAdmissionTransportAttempts(error, attempt + 1);
73
+ throw error;
74
+ }
70
75
  await delayImpl(retryDelaysMs[attempt]);
71
76
  continue;
72
77
  }
@@ -593,6 +598,7 @@ export function createStaticDeployRuntime({
593
598
  infoImpl("Deploying static files...");
594
599
  let deployRes;
595
600
  let acceptedServerOperation = false;
601
+ const staticResumeCommand = `gencow deploy --static${opts.envTarget === "prod" ? " --prod" : ""} --app ${appId}${opts.clientName ? ` --client ${opts.clientName}` : ""} --resume ${deployClaim.claim.requestId}`;
596
602
  try {
597
603
  deployRes = await postStaticDeployWithTransientProxyRetry({
598
604
  send: () =>
@@ -602,13 +608,13 @@ export function createStaticDeployRuntime({
602
608
  envTarget: opts.envTarget || "dev",
603
609
  // Resume static admission directly; fullstack flow skips the
604
610
  // already-completed backend component for this scoped receipt.
605
- resumeCommand: `gencow deploy --static${opts.envTarget === "prod" ? " --prod" : ""} --app ${appId}${opts.clientName ? ` --client ${opts.clientName}` : ""} --resume ${deployClaim.claim.requestId}`,
611
+ resumeCommand: staticResumeCommand,
606
612
  send: ({ signal }) =>
607
613
  platformFetchImpl(creds, `/platform/apps/${appId}/deploy-static`, {
608
614
  method: "POST",
609
615
  headers: {
610
616
  "Content-Type": "application/octet-stream",
611
- "X-Deploy-Local-Dir": cwd,
617
+ ...deployLocalDirHeaders(cwd),
612
618
  "X-Gencow-Deploy-Claim": deployClaim.header,
613
619
  "X-Gencow-Deploy-Protocol": "1",
614
620
  "X-Gencow-CLI-Version": deployClaim.claim.generatedBy.version,
@@ -636,7 +642,7 @@ export function createStaticDeployRuntime({
636
642
  setTimeoutImpl,
637
643
  });
638
644
  }
639
- } catch {
645
+ } catch (caught) {
640
646
  // Without a response, the accepted operation may already exist. Do not let
641
647
  // this observer infer a terminal result; retain the same claim/attempt so its
642
648
  // owner can converge without duplicate work.
@@ -645,8 +651,11 @@ export function createStaticDeployRuntime({
645
651
  } catch {
646
652
  /* ignore */
647
653
  }
648
- errorImpl("Static deployment admission is temporarily unavailable. Retry the same command.");
649
- infoImpl("Code: PLATFORM_DEPLOYMENT_ADMISSION_UNAVAILABLE");
654
+ // Show the typed transport diagnosis (cause, attempts, state impact, exact next command).
655
+ if (!reportAdmissionTransportFailure(caught, { resumeCommand: staticResumeCommand, errorImpl, infoImpl })) {
656
+ errorImpl("Static deployment admission is temporarily unavailable. Retry the same command.");
657
+ infoImpl("Code: PLATFORM_DEPLOYMENT_ADMISSION_UNAVAILABLE");
658
+ }
650
659
  exitImpl(1);
651
660
  return;
652
661
  }
@@ -666,6 +675,7 @@ export function createStaticDeployRuntime({
666
675
  ) {
667
676
  errorImpl("Static deploy status is unknown. The same server request may already be running.");
668
677
  infoImpl("Code: PLATFORM_DEPLOYMENT_ADMISSION_UNAVAILABLE");
678
+ infoImpl(`Response: HTTP ${deployRes.status} from the network edge, without a Platform diagnostic body`);
669
679
  infoImpl("Retry the same gencow static command from this app workspace.");
670
680
  exitImpl(1);
671
681
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gencow",
3
- "version": "0.1.295",
3
+ "version": "0.1.297",
4
4
  "description": "Gencow — AI Backend Engine",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,11 +40,11 @@
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",
44
43
  "@gencow/core": "0.1.48",
45
- "@gencow/server": "0.1.3",
46
44
  "@gencow/react": "0.2.9",
47
- "@gencow/shared": "0.0.0"
45
+ "@gencow/server": "0.1.3",
46
+ "@gencow/shared": "0.0.0",
47
+ "@gencow/client": "0.2.9"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",