Skip to content

Preserve proxy rewrite status when serving cached pages - #101628

Closed
wwewtech wants to merge 1 commit into
vercel:canaryfrom
wwewtech:fix/proxy-rewrite-status-cache-components
Closed

wwewtech wants to merge 1 commit into
vercel:canaryfrom
wwewtech:fix/proxy-rewrite-status-cache-components

Conversation

@wwewtech

@wwewtech wwewtech commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #101590

What?

  • packages/next/src/build/templates/app-page-runtime.ts: the cached entry's status is now applied only when res.statusCode === 200, so a status set by a proxy rewrite is no longer overwritten.
  • test/e2e/app-dir/proxy-rewrite-status: new e2e coverage for proxy rewrites that return 410 and 503 with retry-after.

Why?

With Cache Components enabled, a rewrite to a prerendered page with status 410/503 returned 200 because the cached entry's 200 status replaced the proxy status.

How?

  • The guard in app-page-runtime.ts keeps a non-200 status that was set before the cached entry is served.
  • The test covers both 410 and 503 + retry-after. In the Cache Components variant (__NEXT_CACHE_COMPONENTS=true) it fails without the fix and passes with it; it also passes with Cache Components disabled.
  • The suite is separate from not-found-non-document-dynamic because that suite covers 404 not-found semantics, while this one covers arbitrary proxy rewrite statuses.

Verification

  • New suite, Turbopack and webpack production start, with and without __NEXT_CACHE_COMPONENTS=true
  • New suite, Turbopack dev, with and without __NEXT_CACHE_COMPONENTS=true
  • not-found-non-document-dynamic, Turbopack start with and without __NEXT_CACHE_COMPONENTS=true, and webpack start with __NEXT_CACHE_COMPONENTS=true
  • pnpm test-types, pnpm lint-typescript, pnpm lint-ast-grep, pnpm lint-language
  • Focused Prettier and ESLint on the changed files
  • Full pnpm lint is currently blocked only by pre-existing check-unused-turbo-tasks findings in Rust/Turbopack (no Rust/Turbopack changes in this PR); full-repo Prettier/ESLint are blocked only by pre-existing symlink fixtures on Windows.

@wwewtech
wwewtech marked this pull request as ready for review November 12, 2026 14:14
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Failing CI jobs

Commit: 88dbb3c | About building and testing Next.js

@wwewtech
wwewtech force-pushed the fix/proxy-rewrite-status-cache-components branch from 869ab9c to 88dbb3c Compare November 13, 2026 00:21
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes.
88dbb3c • Fri, 13 Nov 2026 00:22:32 GMT

Vercel Agent's latest review does not approve this pull request under the repository's review policy.

Review steps (45.8s)

Preparing the workspace 12.8s
Analyzing the changes 30.0s
Finalizing the review 2.9s

jamiboym added a commit that referenced this pull request Nov 18, 2026
#101714)

## Summary

`node scripts/pr-status.js` decided a run was clean by counting failed
jobs and never looked at the run's conclusion. A finished run can have
no failed jobs without passing: it can be waiting for a maintainer to
approve a fork PR's workflows (`action_required`), cancelled before any
job failed, unable to start because of a broken workflow file
(`startup_failure`), skipped, or stale. Each of those printed "No failed
jobs found" and produced the same `index.md` as a passing run, apart
from the `Status:` line.

Only `success` now reads as clean. For any other conclusion with no
failed jobs, `index.md` opens with a "CI did not pass" note that names
the reason, the title becomes "CI Status Report", and the console says
the run did not pass. Conclusions without a specific note, including any
GitHub adds later, get a generic one. Runs that list failed jobs are
unchanged.

Every status other than `completed` now counts as unfinished. Before,
only `queued` and `in_progress` did, so `waiting`, `pending` and
`requested` runs fell into the "No failed jobs found" path and `--wait`
didn't wait for them.

The script now runs `main()` only when invoked directly and exports
`describeUnpassedRun`, `generateIndexMd` and `isRunUnfinished`, so
`test/unit/pr-status-run-status.test.ts` can check how each status and
conclusion is reported.

This is independent of
[#101707](#101707),
which makes the script pick the PR's own run and load job logs again.
Both edit `scripts/pr-status.js` in different places.

## Verification

- `test/unit/pr-status-run-status.test.ts` covers every status and
conclusion. Making the `action_required` case read clean again fails it.
- `node scripts/pr-status.js <pr> --skip-flaky-check` on live runs:
-
[#101643](#101643):
an `action_required` run shows the note in `index.md` and on the
console. Without #101707, the branch lookup picked
[#101628](#101628
newer run on the shared branch name, which is also waiting for approval.
-
[#101304](#101304):
a cancelled run with 1 failed job lists the failure, without the note.
-
[#101701](#101701):
a passing run still prints "No failed jobs found", without the note.
- prettier, eslint and ast-grep on `scripts/pr-status.js`.

<!-- NEXT_JS_LLM -->

🤖 Generated with [Claude Code](https://claude.com/claude-code)
jamiboym added a commit that referenced this pull request Nov 18, 2026
…101707)

## Summary

`node scripts/pr-status.js <pr>` could report a clean result for a PR
whose CI had failed. Both bugs below came up while triaging
[#101628](#101628).

### Wrong run for fork PRs that share a branch name

The script listed runs with `actions/runs?branch=<name>` and took the
newest `build-and-test` run. Fork PRs
[#101628](#101628)
and
[#101643](#101643)
both come from a branch named
`fix/proxy-rewrite-status-cache-components`, and runs for fork PRs have
an empty `pull_requests` list. So `node scripts/pr-status.js 101628`
reported the other PR's unapproved run (`action_required`, "No failed
jobs found") rather than its own failed run.

When the PR is known (passed as an argument or found for the current
branch), the script now lists runs by the PR's head commit
(`headRefOid`, `actions/runs?head_sha=`). Without a PR it still queries
by branch.

### No job logs with gh 2.97 or later

Since gh 2.97
([GHSA-3m3g-3wcr-px46](GHSA-3m3g-3wcr-px46)),
`gh api` refuses to print a raw response that contains an ESC byte
unless `--allow-escape-sequences` is passed, and every Actions job log
contains them. The script caught the error, so every job file said "Logs
not available" and the flaky-test check found 0 flaky tests without
saying why.

- One `getJobLogs` now serves both the PR's failed jobs and the flaky
check. It passes `--allow-escape-sequences` when `gh api --help` lists
it; older gh rejects the flag as unknown, so it is left out there.
- With the flag, gh no longer filters escape sequences, so `stripAnsi`
now removes all of them (CSI, OSC, other escapes, and any stray ESC
byte) before the logs are parsed or written to the output files.
Previously it removed only CSI sequences that end in a letter.
- A failed download now shows up in the report. The failed-jobs table
says "Logs unavailable", `index.md` lists each failure with gh's error
under "Log Fetch Failures", the job file explains why it has no
sections, and the Known Flaky Tests section warns when it couldn't read
some logs or couldn't list runs.

To make this testable, the script now runs `main()` only when invoked
directly and exports its helpers. The runs URL (`workflowRunsPath`) and
the `--help` check (`rawOutputFlagsFromHelp`) are their own functions,
and `getJobLogs` accepts the gh runner and flags, so
`test/unit/pr-status-ci-logs.test.ts` runs without gh, on Windows too.

A finished run that didn't pass but has no failed jobs, such as one
waiting for approval, still reads as clean. A separate PR handles that.

The `pr-status-triage` skill docs don't describe how runs are picked or
logs are fetched, so they're unchanged.

## Verification

- `test/unit/pr-status-ci-logs.test.ts`: undoing any one fix (head-SHA
lookup, the flag, escape stripping, reported download errors) fails a
test.
- `node scripts/pr-status.js 101628` with gh 2.103.3 reports run
43221853884 (attempt 2) with 4 failed jobs. The three deploy jobs' test
files contain the `vercel link` failure ("No existing credentials
found"), no output file contains an ESC byte, and the flaky check read
all 21 logs from other branches.
- The same run with a stand-in pre-2.97 `gh` on `PATH` (no flag in `gh
api --help`, rejects it as unknown, prints raw logs) never passes the
flag and produces output identical to the gh 2.103.3 run.
- With a stand-in `gh` whose log downloads fail with HTTP 404,
`index.md` lists the 4 failures, each job file names the error, and
Known Flaky Tests warns that 21 of 21 logs couldn't be fetched.
- `node scripts/pr-status.js --skip-flaky-check` on a branch without a
PR still queries by branch, and `--comments-only` still works.
- `stripAnsi` checked against colors, private-mode CSI, OSC 8 hyperlinks
(ST and BEL terminators), charset escapes, malformed and unterminated
sequences, and JSON text containing an escaped `\u001b`.
- prettier, eslint and ast-grep on `scripts/pr-status.js`.

<!-- NEXT_JS_LLM -->

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@wwewtech

Copy link
Copy Markdown
Author

Superseded by #101703. The adopted internal branch preserves the original commit, adds coverage for stored 404 and redirect statuses, and enables deploy-test verification. Instead of rebasing this conflicting fork PR, continuing review in #101703.

@wwewtech wwewtech closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status from NextResponse.rewrite() in proxy is replaced by 200 when cacheComponents is enabled

1 participant