Repository navigation
fix(server): find a branch's Forgejo PR by head instead of paging every PR - #44
Merged
Merged
Conversation
…ry PR The Forgejo provider found a branch's pull request by listing /pulls 50 at a time and comparing head.ref, so a branch with no PR read every page. On one Forgejo 16.0.5 server that was 153,134 list requests in one day from one desktop client, about 2 s each on the server. Forgejo 16 filters /pulls by a `head` query parameter. Branch lookups now send it, so a lookup takes 1 or 2 short requests. Older Forgejo and Gitea ignore the parameter, so the scan now stops after 5 pages instead of reading the whole history. Fixes #41 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fixes #41.
The Forgejo source-control provider found a branch's PR by listing
/pulls50 at a time and comparinghead.ref. A branch with no PR read every page. On git.pseudoseed.com (Forgejo 16.0.5) that was 153,134 list requests in one day from one desktop client, about 2 s each on the server.What changed
apps/server/src/sourceControl/ForgejoSourceControlProvider.ts,listChangeRequests:head=<branch>. Forgejo 16 narrows/pullsto that head branch, so a lookup takes 1 request, or 2 when the caller asks for more than the PRs that exist.headand return every PR, so this bounds the scan there.head.ref, owner and repository checks are unchanged, soowner:branchselectors still filter forks the same way.Tests in
ForgejoSourceControlProvider.test.tsuse a fake server that either honoursheador ignores it. They cover: PR found in 1 filtered request (branch name with/and#, to check encoding), no PR in 1 request, owner selector sends the bare branch and keeps the owner check, the 5-page cap whenheadis ignored, and a recent PR still found whenheadis ignored.Why not
GET /pulls/{base}/{head}The issue suggested it. I did not use it, for 2 reasons:
GitManager.findOpenPr,findLatestPrForHeadContext) pass a head selector and a state, never a base branch.GetPullRequestByBaseHeadInfo) has no state filter and noORDER BY. Live,pulls/main/renovate/ghcr.io-shelf-nu-shelf.nu-latestreturned refactor(contracts): remove unused OrchestrationPersistedEvent schema pingdotgg/t3code#601, a merged PR last updated 2026-08-31, while 17 PRs share that head and the newest is feat: Add provider health and per-provider controls pingdotgg/t3code#1289. On a reused branch name it would hide a newer open PR.Suggestion 1 (fetch by known PR number) already holds:
getChangeRequestcallspulls/{index}.listChangeRequestscallers have no number.How it was verified
Live API, git.pseudoseed.com, repo
pseudoseed/infra(1,093 PRs), read-only GETs with curl:/api/v1/versionreturns16.0.5+gitea-1.22.0. The served swagger listsheadandbasequery parameters onGET /repos/{owner}/{repo}/pulls.pulls?state=all&head=no-such-branch-zzzreturns an empty array,x-total-count: 0, 86 ms. The unfiltered first page took 1.36 s.pulls?state=open&head=fix%2Fgideon-vm-discardreturns an array with 1 object: fix(web): apply sticky model when reusing existing draft thread pingdotgg/t3code#1291,state=open,head.ref=fix/gideon-vm-discard.pulls?state=all&head=renovate%2Fghcr.io-shelf-nu-shelf.nu-latestreturns 17 objects, all merged. Theirhead.refisrefs/pull/N/head, because Forgejo reports that once the branch is deleted, so the provider'shead.refcheck drops them. The old code dropped them too.head=pseudoseed%3Afix%2Fgideon-vm-discard(owner form) returns an empty array, so the provider sends the bare branch.pulls/main/no-such-branch-zzzreturns 404 with{"message":"The target couldn't be found.",...}. A missing repository also returns 404.Patched provider run against the live server through the real
ForgejoClilayer (fj credentials), via a throwaway script that is not committed:no-such-branch-zzz, state all, limit 20no-such-branch-zzz, state open, limit 1fix/gideon-vm-discard, state open, limit 1fix/gideon-vm-discard, state all, limit 20Times are client round trips from this machine, not server-side.
Commands, run in
apps/serverwith Node 24.20.0 and pnpm 11.10.0:vp test run src/sourceControl/ForgejoSourceControlProvider.test.ts: 11 passed. Against the unpatched provider, 4 of the 5 new tests fail. For example, the no-PR case made 21 requests instead of 1.vp test run src/sourceControl/ src/git/GitManager.test.ts: 20 files, 327 tests passed.vp run typecheck(tsc --noEmit): exit 0, 0 errors.vp lint --report-unused-disable-directivesandvp fmt --checkon the 2 changed files: exit 0, no findings.Not verified
tea apitransport was not run live. Only the fj HTTP path was. Both receive the same path string.headon the list endpoint comes from reading their source. On those servers, a PR older than the 250 most recently updated is no longer found.GitManageralready caches lookups for 60 s with an open PR and 5 min without one.🤖 Generated with Claude Code