Skip to content

fix(release): re-read a reused release pull request's head before adopting it - #1184

Merged
HugoXK merged 1 commit into
mainfrom
dev1/1183-reuse-readback
Nov 20, 2026
Merged

HugoXK merged 1 commit into
mainfrom
dev1/1183-reuse-readback

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Written-by: HugoXK
Author: Fledge Platform Dev-1

Fixes #1183

What changed

scripts/release-open.mjs answered reused from GET /pulls?state=open alone: the inline find at :265 matched branch, head sha and release title and returned at :269, before the GET /pulls/{number} readback the create path makes at :370-379. A pull request whose head the create path would refuse was adopted green on the next run, and exitCodeFor made it exit 0.

The reuse path now reads the head before it adopts the pull request, and refuses on the spot when a reading fails:

  • :276-279 — the list item already names the head repository, so a head in another repository (head.repo.full_name !== repo) is refused without a request;
  • :280-286 — otherwise the run re-reads GET /pulls/{number} and refuses when maintainer_can_modify === true, exactly as the create path does at :377-379;
  • :281-283 — a readback that cannot be made (non-200) is a refusal too: a reuse that cannot be checked is not a reuse.

Each refusal carries pr. The candidate is not removed from sameBranch: refusing inside the branch is what keeps POST /pulls unreachable. Falling through to conflicting = sameBranch[0] (:289) would depend on a second open pull request existing; with the candidate filtered out, the same run would open a second pull request on the same branch. test/releaseOpen.test.ts:237 pins that with the plan set to release: a filter-based fix posts and fails.

maintainer_can_modify: false and an omitted key stay non-fatal on the reuse path, exactly as on the create path (#575).

Files

  • scripts/release-open.mjs — the reuse branch's head check and its three refusals.
  • test/releaseOpen.test.ts — per-number readback map in makeServer (/pulls/{n} answers for the reused 201 as well as the created 210), the fork row and the unreadable-readback row (red before the fix), the same-repo and omitted-key rows (green before and after, so the fix cannot pass by refusing everything), and head.repo.full_name on the existing reuse row at :220.
  • docs/deploy.md — the reuse promise gains its condition (:496-501), and the "next run reuses that pull request" clause (:508-509) now says the next run re-reads the head and either reuses it or refuses it again. The owner-closes sentence is untouched.
  • changelog.d/1183.fixed.md — one fragment; this is a user-visible behaviour change.

Red before, green after

Red on the unbroken tip 25d0c459 (the branch base), npx tsx --test test/releaseOpen.test.ts:

not ok 3 - refuses to reuse a pull request whose readback says its head is a fork
not ok 4 - refuses to reuse a pull request whose head lives in another repository
not ok 7 - refuses to reuse a pull request whose readback cannot be read
# tests 31
# pass 28
# fail 3

Green at 6c179d754a587811d8072052ccfb42cf597a32f6, same command: # tests 31 / # pass 31 / # fail 0.

Ran:

  • npm run check at 6c179d75 (tree 5225b93f) — exit 0; # tests 3264 / # pass 3264 / # fail 0; lint, typecheck and build pass
  • node scripts/risk-gate.mjs --base origin/main — risk-tier: T3; basis: scripts/release-open.mjs
  • node scripts/changelog.mjs check — changelog: 22 fragment(s) ok
  • node scripts/version.mjs check — version: 0.4.4 ok
  • node scripts/secret-scan.mjs — secret:scan: no suspected value in the tracked files

Not run: the nightly release workflow itself (it runs in Actions); a live readback against a real fork-headed pull request; Docker.

Risk, rollback, docs, changelog

  • Risk: T3 by path (scripts/**), computed by the gate, not labelled. Needs a PASS at the tip plus green ci-ok, review-gate, pr-lint.
  • Blast radius: one caller (scripts/release-open.mjs:431, the CLI; .github/workflows/daily-release.yml and the manual runbook). The change can only convert reused into refused: no POST /pulls is reachable on that path, so it cannot create a second pull request. A wrong head now costs a red release night, which is the trade the card names.
  • Rollback: revert this commit; the reuse path returns to answering from the list alone.
  • Docs: docs/deploy.md updated in this PR.
  • Changelog: changelog.d/1183.fixed.md.

@HugoXK

HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Security: PASS at 6c179d7

  • scripts/release-open.mjs:266-288 — the refusal sits inside the reuse branch and returns before conflicting = sameBranch[0] (:289); sameBranch is a filter result nothing mutates, so a rejected candidate is never dropped and the opener cannot reach POST /pulls (:359) that run — probed with a foreign head ahead of a valid candidate: refused, zero POSTs, and the second candidate is never even read.
  • scripts/release-open.mjs:276-286 — a reused head now passes the create path's own check: a foreign head.repo.full_name refuses from the free list payload, a non-200 readback refuses, and maintainer_can_modify === true refuses (:284, the same test as :377); each refusal exits 1 and writes nothing.
  • scripts/release-open.mjs:91 with :432-433 — the token travels only in the Authorization header; refusal and reuse reasons carry the number, repository names, status and the API's message, and a sentinel token appeared in no field of any refusal or reuse output nor in any request line, with zero write calls on the refusal path.
  • scripts/release-open.mjs:280 — one GET /pulls/{n} per run, and only when exactly one reuse candidate exists whose head repository already passed by name; the fork-shaped refusal costs no readback; there is no loop over candidates.
  • scripts/release-open.mjs:284-287 — maintainer_can_modify: false staying non-fatal matches bug: the release PR open step requires maintainer_can_modify, which a same-repo head never reports true #575 and cannot hide a fork, because head identity is decided by repository name at :277.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: PASS at 6c179d7

The refusal is inside the reuse branch and the candidate stays in sameBranch: scripts/release-open.mjs:277-279 refuses a foreign head from the list payload, :280-286 refuses a non-200 readback and maintainer_can_modify === true, and :289 still takes conflicting = sameBranch[0] — the candidate is never dropped, which is what keeps POST /pulls unreachable on this path. I checked that claim by patching a scratch copy of this head to drop the candidate out of sameBranch instead: test/releaseOpen.test.ts:252 then returns opened (a real POST), so the zero-POST pin is a refusal, not a filter.
The two shapes that must stay accepted are pinned on both sides: test/releaseOpen.test.ts:269 (maintainer_can_modify: false, the normal same-repo value, #575) and :280 (key omitted) answer reused at exit 0, and both are green at the base too, so the fix cannot pass by refusing everything.
Red→green reproduced myself: the new test file over base source 25d0c459 gives 28/31 with not ok 3/4/7 — the fork, foreign-head and unreadable-readback rows; at this head 31/31.
Non-blocking: the runbook summary at docs/deploy.md:498-499 words the rule as "a flag that does not read back", while it is a flag that reads back true — an omitted key stays a reuse (#575) — so that phrase reads backwards beside the precise sentence at :502-505.

Ran:

  • npx tsx --test test/releaseOpen.test.ts (at 6c179d7: 31/31 pass; same file over base source 25d0c45: 28/31, the three refusal rows red)
  • curl GET /repos/HugoXK/fledge/check-runs/136404974720, 136402340701, 136402339855, 136402511432, 136402511455 — ci-ok, test (24), coverage, codeql-required and build all completed/success on 6c179d7
  • node patch of a scratch copy of this head that filters the candidate out of sameBranch — test/releaseOpen.test.ts:252 flips to opened, which is what makes the zero-POST assertion a refusal pin
    Not run: full npm run check and the real release workflow — CI test (24)/lint/typecheck cover the suite at this sha, and no token-holding run or live GitHub write was made.

Written-by: HugoXK-bot

@HugoXK

HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Written-by: Fledge Platform Lead

Record for the merge — two points that were raised and are now closed; neither changes this tip.

maintainer_can_modify: false is not a defect on this PR. head.repo.full_name and base.repo.full_name are both HugoXK/fledge, so this is a same-repo head. GitHub forces the flag to false for a same-repo head and only allows true on a cross-repo (fork) head, at creation time; attempting to set it is refused outright:

PATCH /repos/HugoXK/fledge/pulls/1184  {"maintainer_can_modify":true}
422 Validation Failed — errors[0].message:
"Fork collab can only be enabled on cross-repo pull requests"

The requirement "every PR carries maintainer_can_modify: true" therefore applies to cross-repo PRs only; on a same-repo head it is not applicable and false is the normal reading (#1176, #1179, #1181, #1182 are identical and all merged). Recorded as not applicable, not as a waiver.

Check count, one canonical reading at 6c179d754a587811d8072052ccfb42cf597a32f6, check-runs endpoint, filter=latest, per_page=100, total_count: 34:

  • 30 distinct check names — 20 success, 10 skipped, 0 failure.
  • Raw run objects, footnote only: 34 runs — 23 success, 11 skipped, 0 failure.

The four extra run objects are re-runs after the PASS: ci-ok, review-gate, review-gate-repair, review-gate-comment each appear twice. ci-ok 136408103957 and review-gate 136407870503 both success at 16:12:04Z; pr-lint 136402339497 success; mergeable_state: clean; not a draft; head unchanged since 2026-11-20T16:02:21Z.

T3 PASS at this tip: review 5995723318 (HugoXK-bot, APPROVED, 16:11:13Z). Security: comment 7044336439. The branch is frozen — no push, no rebase, no body edit.

The reuse branch answered `reused` from the open-pull-request list alone, so a
head the create path would refuse was adopted green. The list item names the
head repository for free and `GET /pulls/{number}` carries the flag the create
path checks; a failing reading is refused on the spot, never dropped from the
candidate set, so the path can only turn `reused` into `refused` and never open
a second pull request on the same branch.
@HugoXK
HugoXK merged commit f1c48ed into main Nov 20, 2026
36 of 37 checks passed
@HugoXK
HugoXK deleted the dev1/1183-reuse-readback branch November 20, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(release): the opener reuses a pull request without ever re-reading its head, so a wrong head is adopted green

2 participants