Skip to content

feat(ship-pr): look the PR up before retrying a failed gh pr create - #72

Merged
chapati23 merged 2 commits into
mainfrom
ship-pr-failed-create-lookup
Nov 26, 2026
Merged

chapati23 merged 2 commits into
mainfrom
ship-pr-failed-create-lookup

Conversation

@chapati23

Copy link
Copy Markdown
Contributor

tl;dr

  • The shared ship-pr skill now says what to do when creating a pull request fails, because GitHub sometimes creates the PR anyway. The rule was written in the personal library after the core loop moved here, so without this port its deletion there would drop it.

The Problem

  • gh pr create can return HTTP 502 or a GraphQL error after GitHub created the PR; a blind retry then fails with "already exists".
  • The company ship-pr copy predates that rule, and the personal copy is about to be deleted.

The Solution

  • Port the rule: after a failed create, look the branch up through REST, bind a PR it finds, and retry or fall back to a REST create only when the lookup lists none.
  • A second commit closes three gaps that Codex found in the rule: a body-guard rejection is fixed and rerun instead of bypassed, a failed final POST is followed by a lookup, and the lookup keeps only PRs from the bound head repository.

Validation

  • Head under test: the two commits on ship-pr-failed-create-lookup.
  • Passed: node scripts/validate-skills.mjs (27 skills); the lookup command, run against a known branch, returned exactly its PR; skills/ship-pr/SKILL.md is 496 lines.
  • Review: direct reading of the diff plus a Codex review (gpt-6.2-sol); its 3 P2 findings are fixed in the second commit. The fix commit was not re-reviewed by Codex before push.
  • Not run: a live failed gh pr create; this is instruction prose with no executable test.

Deferrals

  • None

Ship Checklist

  • PR title is a Conventional Commits header, type: summary or type(scope): summary, as commitlint.config.mjs enforces for commits
  • Performed a self-review of my own changes
  • node scripts/validate-skills.mjs and the affected test suites pass
  • Nothing in the diff breaks the public-readership rules in AGENTS.md
  • Body is about 250 words, 400 at most, excluding this checklist

🤖 Generated with Claude Code

chapati23 and others added 2 commits November 26, 2026 10:42
gh pr create can return HTTP 502 or a GraphQL error after GitHub created the PR, so a blind retry fails with 'already exists', and a REST fallback can skip a local body guard. This ports the rule that the personal library added after the core loop was promoted, so its deletion there does not drop it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A guard rejection no longer falls through to a REST create, a failed final POST is followed by a lookup, and the lookup keeps only PRs from the bound head repository. Codex review findings on the port.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Claude finished @chapati23's task in 3m 44s —— View job


Review complete

  • Gather context (diff, AGENTS.md rules, related skill content)
  • Understand the request (review the PR)
  • Review skills/ship-pr/SKILL.md changes for correctness, safety, and AGENTS.md compliance
  • Post inline comments for concrete findings
  • Post summary with verdict and numbered roll-up

Verdict: needs-changes (one P1 correctness bug; otherwise solid)

Summary

This is a docs-only port (confirmed: SKILL.md is the only changed file, 496 lines, prose only). The new "A failed create may have created the PR" paragraph (SKILL.md:392–411) teaches the recovery procedure: look the branch up via REST on a failed gh pr create, bind what's found, and only fall back to a REST POST create when the lookup is clean. The second commit's three stated fixes all check out against the diff:

  1. A local body-guard rejection is now excluded from "every failed create" and just gets fixed-and-rerun, not routed into the lookup/retry machinery.
  2. A failed final POST is now followed by a lookup before giving up, closing the same "GitHub created it anyway" gap for the REST path that the GraphQL path already had.
  3. The lookup's select(.head.repo.full_name == "<HEAD_REPO>") now drops a same-owner PR that isn't from the bound head repository.

Findings

  1. [P1] correctness (inline on SKILL.md:396) — the lookup command's --jq filter extracts .html_url, but the very next sentence says to bind the result with published --state <file> --pr <N>. repo-trust/publish.sh:89 requires --pr to be a bare integer ([[ $pr =~ ^[0-9]+$ ]]), so passing a URL fails with a usage error — breaking the happy path this paragraph exists to handle (GitHub created the PR despite the error). The fix needs .number available, not just .html_url (the URL is still needed for the later "report the PR URL" step). The same lookup command is reused for the "bind what the lookup finds" step after a second failed POST, so the fix covers both call sites.

  2. [P3] naming nit — <HEAD_REPO> is a real emitted state key (resolve.sh:262: emit HEAD_REPO "$HEAD_REPO"), so it's accurate, but SKILL.md's own description of what resolve binds (line 86: "CURRENT_REPO, BASE_REPO, BASE_REMOTE, HEAD_REMOTE, and an existing PR's real head repository and branch") never names it HEAD_REPO there. Not a bug, just a small cross-reference gap for a reader trying to match the new paragraph's placeholder back to where it's bound. Not blocking.

Everything else — the guard/GraphQL/REST distinctions, the retry-once semantics, the never-draft and never-placeholder-body carry-overs, and the terminology (guard, published, BASE_REPO) — is consistent with the rest of SKILL.md and with references/publish.md. No public-readership issues (no hostnames, private repo names, personal paths). N/A: skills layout/frontmatter, bash 3.2 compatibility, shell size limits, SHA-pinned actions — this PR touches no shell script or workflow file.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:51:29.676685Z dfaa8ba PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread skills/ship-pr/SKILL.md
GraphQL error after GitHub created the PR, and it can also fail without creating one. A
local guard that rejects the body is no GitHub failure: fix the body and rerun the guarded
command. After every other failed create, look the branch up through REST, which does not
use GraphQL: `gh api -X GET repos/<BASE_REPO>/pulls -f head=<head owner>:<head branch> -f base=<base> -f state=open --jq '.[] | select(.head.repo.full_name == "<HEAD_REPO>") | .html_url'`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] correctness: the lookup's --jq filter extracts .html_url, but the text immediately after says to bind it with published --state <file> --pr <N>. repo-trust-preflight.sh's published subcommand enforces [[ $pr =~ ^[0-9]+$ ]] (skills/babysit-pr/scripts/repo-trust/publish.sh:89) — it rejects anything that isn't a bare integer, so a URL like https://github.com/owner/repo/pull/123 fails with a usage error. Following this instruction literally breaks the one case it exists to handle (a create that actually succeeded).

Fix: extract .number (or emit both .number and .html_url, e.g. "\(.number) \(.html_url)") so there's a PR number to pass to --pr <N>, while still keeping the URL available for the "report the PR URL" step a few sentences later. The same gap applies to the "bind what the lookup finds" step after a second failed POST, since it reuses this same lookup command.

Fix this →

@chapati23
chapati23 merged commit 0b01f6c into main Nov 26, 2026
4 of 5 checks passed
@chapati23
chapati23 deleted the ship-pr-failed-create-lookup branch November 26, 2026 09:58
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.

1 participant