Repository navigation
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
4 issues found across 9 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="package.json">
<violation number="1" location="package.json:18">
P2: `--experimental-strip-types` was introduced in Node 22.6, but `engines.node` and the README still allow Node 22.0–22.5, where `npm test` and `npm run check` fail. Raise the declared and documented minimum to 22.6+ or use a test runner compatible with Node 22.0.</violation>
</file>
<file name="src/components/Contact.tsx">
<violation number="1" location="src/components/Contact.tsx:82">
P2: The 12-second client deadline is shorter than the endpoint's 5-second body-read and 8-second delivery budgets combined. A slow upload followed by a slow-but-successful delivery can therefore show an error while the email is sent, making a retry duplicate it; allow time beyond both budgets.</violation>
</file>
<file name="docs/operations.md">
<violation number="1" location="docs/operations.md:12">
P2: The standard `.dev.vars` setup leaves a nonempty placeholder key, so this check calls Resend instead of exercising the mailto fallback. Remove `RESEND_API_KEY` from `.dev.vars` before starting Wrangler.</violation>
</file>
<file name="functions/api/contact.ts">
<violation number="1" location="functions/api/contact.ts:186">
P2: A 2xx provider response can still have an errored body, causing `cancel()` to reject and this handler to return 502 after the email was accepted. Make body cancellation best-effort so it cannot change the delivery result.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| "format:check": "prettier --check .", | ||
| "security:audit": "npm audit --omit=dev --audit-level=moderate" | ||
| "security:audit": "npm audit --audit-level=moderate", | ||
| "test": "node --experimental-strip-types --test tests/*.test.mjs" |
There was a problem hiding this comment.
P2: --experimental-strip-types was introduced in Node 22.6, but engines.node and the README still allow Node 22.0–22.5, where npm test and npm run check fail. Raise the declared and documented minimum to 22.6+ or use a test runner compatible with Node 22.0.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At package.json, line 18:
<comment>`--experimental-strip-types` was introduced in Node 22.6, but `engines.node` and the README still allow Node 22.0–22.5, where `npm test` and `npm run check` fail. Raise the declared and documented minimum to 22.6+ or use a test runner compatible with Node 22.0.</comment>
<file context>
@@ -8,13 +8,14 @@
"format:check": "prettier --check .",
- "security:audit": "npm audit --omit=dev --audit-level=moderate"
+ "security:audit": "npm audit --audit-level=moderate",
+ "test": "node --experimental-strip-types --test tests/*.test.mjs"
},
"engines": {
</file context>
| try { | ||
| const res = await fetch("/api/contact", { | ||
| method: "POST", | ||
| signal: AbortSignal.timeout(12_000), |
There was a problem hiding this comment.
P2: The 12-second client deadline is shorter than the endpoint's 5-second body-read and 8-second delivery budgets combined. A slow upload followed by a slow-but-successful delivery can therefore show an error while the email is sent, making a retry duplicate it; allow time beyond both budgets.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/components/Contact.tsx, line 82:
<comment>The 12-second client deadline is shorter than the endpoint's 5-second body-read and 8-second delivery budgets combined. A slow upload followed by a slow-but-successful delivery can therefore show an error while the email is sent, making a retry duplicate it; allow time beyond both budgets.</comment>
<file context>
@@ -79,6 +79,7 @@ export function Contact() {
try {
const res = await fetch("/api/contact", {
method: "POST",
+ signal: AbortSignal.timeout(12_000),
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, email, subject, message, website }),
</file context>
| signal: AbortSignal.timeout(12_000), | |
| signal: AbortSignal.timeout(15_000), |
| 1. Use Node 22.13+ and `npm ci`. | ||
| 2. Run `npm run check`. This includes API regression tests and dependency audits | ||
| for production and build dependencies. | ||
| 3. Run `npm run build`, then `npx wrangler pages dev dist`. Verify the contact |
There was a problem hiding this comment.
P2: The standard .dev.vars setup leaves a nonempty placeholder key, so this check calls Resend instead of exercising the mailto fallback. Remove RESEND_API_KEY from .dev.vars before starting Wrangler.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/operations.md, line 12:
<comment>The standard `.dev.vars` setup leaves a nonempty placeholder key, so this check calls Resend instead of exercising the mailto fallback. Remove `RESEND_API_KEY` from `.dev.vars` before starting Wrangler.</comment>
<file context>
@@ -0,0 +1,57 @@
+1. Use Node 22.13+ and `npm ci`.
+2. Run `npm run check`. This includes API regression tests and dependency audits
+ for production and build dependencies.
+3. Run `npm run build`, then `npx wrangler pages dev dist`. Verify the contact
+ form in both languages, required-field validation, error recovery, and the
+ unconfigured-service mailto fallback. Do not use real recipient data in tests.
</file context>
| 3. Run `npm run build`, then `npx wrangler pages dev dist`. Verify the contact | |
| 3. Run `npm run build`, then `npx wrangler pages dev dist` with `RESEND_API_KEY` removed from `.dev.vars`. Verify the contact |
| // Do not log message bodies, email addresses, or provider response content. | ||
| if (!response.ok) { | ||
| console.error("contact.delivery_failed", { requestId, status: response.status }); | ||
| await response.body?.cancel(); |
There was a problem hiding this comment.
P2: A 2xx provider response can still have an errored body, causing cancel() to reject and this handler to return 502 after the email was accepted. Make body cancellation best-effort so it cannot change the delivery result.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At functions/api/contact.ts, line 186:
<comment>A 2xx provider response can still have an errored body, causing `cancel()` to reject and this handler to return 502 after the email was accepted. Make body cancellation best-effort so it cannot change the delivery result.</comment>
<file context>
@@ -1,208 +1,218 @@
+ // Do not log message bodies, email addresses, or provider response content.
+ if (!response.ok) {
+ console.error("contact.delivery_failed", { requestId, status: response.status });
+ await response.body?.cancel();
+ return reply(502, { error: "Failed to send" });
}
</file context>
| await response.body?.cancel(); | |
| void response.body?.cancel().catch(() => {}); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddf83601ac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "format:check": "prettier --check .", | ||
| "security:audit": "npm audit --omit=dev --audit-level=moderate" | ||
| "security:audit": "npm audit --audit-level=moderate", | ||
| "test": "node --experimental-strip-types --test tests/*.test.mjs" |
There was a problem hiding this comment.
Require a Node version that supports type stripping
The new test command fails on Node 22.0–22.5 even though engines.node and the README still advertise all Node 22 releases: --experimental-strip-types was only added in Node 22.6.0, as documented in the Node.js TypeScript documentation. Raise the engine/prerequisite floor to at least 22.6 so supported local installations can run npm test and npm run check.
Useful? React with 👍 / 👎.
| try { | ||
| const res = await fetch("/api/contact", { | ||
| method: "POST", | ||
| signal: AbortSignal.timeout(12_000), |
There was a problem hiding this comment.
Allow the client deadline to cover the server deadlines
When uploading the request takes more than four seconds—but remains within the API's five-second body-read deadline—the server can subsequently spend another eight seconds waiting for Resend, while this 12-second client deadline expires first. The UI then reports a network failure even though the provider request is still pending and may succeed; make the browser timeout exceed the complete server-side budget, including response latency.
Useful? React with 👍 / 👎.
| formRef.current?.reset(); | ||
| // Delivery may have succeeded before the connection failed. Preserve the | ||
| // message and avoid opening another send automatically. | ||
| setErrorState(t.contact.errGeneric); |
There was a problem hiding this comment.
Avoid prompting a retry when delivery is uncertain
On a timeout or connection loss after Resend has accepted the message, this catch path intentionally preserves the form because delivery is uncertain, but errGeneric tells the user to “try again in a moment.” Following that instruction submits the preserved message again and can produce duplicate email; use an uncertainty-specific message that does not encourage an immediate resend.
Useful? React with 👍 / 👎.
| const MAX_MESSAGE_LENGTH = 5000; | ||
| const PUBLIC_ORIGINS = new Set(["https://johnkrentschler.me", "https://www.johnkrentschler.me"]); | ||
| const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]); | ||
| const MAX_BODY_BYTES = 16_384; |
There was a problem hiding this comment.
Size the body cap for every valid field combination
The 16 KiB cap is smaller than payloads permitted by the shared field limits. For example, a 5,000-code-unit CJK message, 150-code-unit subject, 100-code-unit name, and a syntactically accepted 253-code-unit Unicode email produce a 16,560-byte JSON body, so the frontend accepts every field but the API returns 413 before validation. Set the cap above the worst-case encoded valid payload or enforce the same encoded-byte limit in the client.
Useful? React with 👍 / 👎.
The contact API had no throttle despite the README describing one, buffered the entire request before checking its size, and classified upstream outages as client errors. The browser could clear a message and launch another send after an uncertain network failure.
This change adds byte-bounded streamed reads, read/provider deadlines, strict origin/media-type/body validation, a bounded per-isolate IP throttle, request IDs, and explicit 429/502/504 handling without logging message content. The form preserves entered text on uncertain failures. Ten endpoint regression tests cover success, invalid origins/input, chunked and multibyte limits, throttling, honeypot, missing configuration, upstream failures, and method handling.
The complete dependency audit now includes build tools; the lockfile resolves the 11 reported package advisories, with compatible Cloudflare worker types. CI has read-only check permissions, timeouts, concurrency control, and pinned actions. Dependabot and an operations guide cover updates, edge rate limiting, deployment verification, and rollback.
Validation:
npm ci --ignore-scriptsandnpm run checkpassed: format, lint, TypeScript, 10 API tests, build, and full dependency audit with zero reported advisories.git diff --checkpassed.Production limits: the local throttle is not a distributed quota. Cloudflare edge rate limits, production secrets, sender-domain verification, monitoring, and real email delivery still require environment verification. The operations guide states these boundaries explicitly.
Summary by cubic
The contact API previously buffered the entire request before rejecting oversized bodies, had no documented IP throttle, and treated upstream outages as client errors; the form could clear a message and open a mailto fallback after an uncertain network failure.
Written for commit ddf8360. Summary will update on new commits.