fix(github): reuse an existing repo-docs branch ref instead of failing (#8310)#8481
Conversation
JSONbored#8310) openRepoDocPullRequest always targets the fixed loopover/repo-docs branch, but only looks for an OPEN pull request on it before deciding to create the ref. A maintainer who closes the repo-doc PR without deleting its branch (GitHub never forces that, and an API/bot close deletes nothing) leaves the ref behind: the open-only lookup finds nothing, POST /git/refs then 422s "Reference already exists", and the outer catch turns every later refresh into { opened: false }, permanently. When the create reports that specific failure, fall back to PATCH /git/refs/{ref} with { sha, force: true } and continue into the existing PR-open path unchanged. The branch is owned solely by this feature (per the file's own header comment), never shared with contributor work, so force- updating it to the freshly built commit is safe. Deliberately narrow: - Only a 422 whose message says "Reference already exists" recovers; any other create-ref failure still propagates to the outer catch's fail-safe, so a bad sha is never force-pushed over. - The "reuse only an OPEN PR" behaviour is untouched -- a closed PR still results in a NEW pull request, only the underlying ref is reused. - Reuses the existing githubErrorStatus and errorMessage helpers rather than hand-rolling status/message extraction. Adds two tests: the 422 path force-updates the ref and still opens a fresh PR (reused: false), and an unrelated create-ref 422 issues no PATCH and degrades to opened: false.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-24 15:27:35 UTC
Review summary Nits — 3 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Summary
Closes #8310.
openRepoDocPullRequestalways targets the fixedloopover/repo-docsbranch (deliberately stable, per the file's header comment, so repeat runs update one PR instead of piling up duplicates). But it only checks for an open PR on that branch before deciding to create the ref:When a maintainer closes the repo-doc PR without deleting its branch -- GitHub offers a "Delete branch" button but never forces it, and a PR closed via the API or a bot deletes nothing -- the ref survives. The open-only lookup then finds nothing, the function proceeds, and
POST /git/refs422s "Reference already exists". The outertry/catchturns that into{ opened: false, reason }, so every subsequent refresh for that repo fails permanently -- both the scheduled sweep and the on-demandloopover_refresh_repo_docstool.Change
When the create reports that specific failure, fall back to
PATCH /repos/{owner}/{repo}/git/refs/{ref}with{ sha: commitSha, force: true }, then continue into the existing PR-open path unchanged. This branch is exclusively owned by this feature and never shared with contributor work, so force-updating it to the freshly built commit is safe.Deliberately narrow, matching the issue's constraints:
Reference already existsrecovers. Any other create-ref failure (e.g. an invalid sha) still propagates to the outer catch's fail-safe, so nothing is silently force-pushed over.reused: false); only the underlying ref is reused.githubErrorStatushelper and the sharederrorMessagehelper rather than hand-rolling status/message extraction.Tests
PATCHbody carries{ sha, force: true }) and still opens a fresh PR withreused: falsePATCHand degrades toopened: false, pinning the fail-safeScope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #8310).Validation
git diff --checknpm run actionlint- no workflow files touched.npm run typechecknpx vitest run test/unit/repo-doc-pr.test.ts- 33 pass (was 31).isRefAlreadyExistsErrorguard are exercised by the two tests above).npm run test:coverage(full) /test:workers/build:mcp/ui:*- not run: this is a scoped change to one backend module plus its unit test, touching no worker, MCP, or UI surface.npm audit --audit-level=moderate- no dependency changes.Safety
makeInstallationOctokit/withInstallationTokenRetrychokepoint, and the unrelated-failure test is the negative path.loopover_refresh_repo_docssimply stops failing on this case.UI Evidencesection - n/a: no visible UI/frontend/docs/extension change.Notes
loopover/repo-docs. Because the recovery is gated on both the 422 status and the "Reference already exists" message, an unrelated 422 can never reach theforce: truecall.Reopened from #8474, which was auto-closed because its branch received an additional commit (a rebase onto latest
main) after opening - this repo reviews one-shot and treats that as a restart. No code changed: same diff, rebased and re-verified (33/33 tests; 0 uncovered statements and 0 partial branches on the diff).