feat(server): pull requests talk to GitHub's API instead of the gh CLI #16320
Mergedjuliusmarmingemerged 11 commits into
t3code/github-api-transport fromrefs/pull/16320/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge changed the title
- @@ -2221,3 +2405,18 @@2221- return Result.isSuccess(decoded)2222- ? Result.succeed(toActivity(decoded.success))2223- : Result.fail(decoded.failure);2405+ if (!Result.isSuccess(decoded)) return Result.fail(decoded.failure);2406+ const pr = decoded.success.data.repository.pullRequest;2407+ return Result.succeed({2408+ ...(pr.author === undefined ? {} : { author: toActor(pr.author) }),2409+ ...(pr.commits === undefined2410+ ? {}2411+ : {2412+ commits: toCommits(2413+ (pr.commits?.nodes ?? []).map(({ commit }) => ({2414+ ...commit,2415+ authors: (commit.authors?.nodes ?? []).map((author) => ({2416+ ...author,2417+ login: author.user?.login ?? null,2418+ })),2419+ })),2420+ ),2421+ }),2422+ remarks: toComments({apps/server/src/pullRequest/GitHubPullRequestProvider.ts line 233Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -224,4 +229,4 @@224229 .pipe(225230 Effect.matchEffect({226231 onFailure: (error) =>227- error._tag === "GitHubCliRateLimitError" ||232+ error._tag === "GitHubApiRateLimitError" ||
- @@ -37,9 +41,15 @@41+ graphql: (input) =>42+ api.graphql(input).pipe(43+ Effect.tap((body) =>44+ Effect.sync(() =>3745 reads.push({38- graphqlRequests,39- restRequests: requests - graphqlRequests,40- cost: Number(cost ?? 0),41- debug: output.stderr,42- });43- }),46+ graphqlRequests: 1,47+ restRequests: 0,48+ cost: Option.match(decodeCost(body), {49+ onNone: () => 0,50+ onSome: (decoded) => decoded.data.rateLimit.cost,51+ }),52+ }),53+ ),4454 ),4555 ),@@ -382,7 +389,14 @@382389383390 /** A large pull request can produce a multi-megabyte patch; past this it is truncated. */384391 const DIFF_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;385-const DIFF_TIMEOUT_MS = 60_000;392+const DIFF_TIMEOUT = Duration.seconds(60);386393 /** Pierre expansion is for source files, not blobs large enough to stall a review surface. */387394 const DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;388395396+/** What `gh pr list --state` asked a repository's own list for, without search. */397+const LIST_STATES: Record<PullRequestListState, ReadonlyArray<"OPEN" | "CLOSED" | "MERGED">> = {398+ all: ["OPEN", "CLOSED", "MERGED"],399+ open: ["OPEN"],400+ // Closed includes merged here, the way GitHub's own list reads it; merged rows are filtered out401+ // locally by `matchesUnsortedListing`.402+ closed: ["CLOSED", "MERGED"],@@ -303,4 +308,4 @@303308 ),304309 )305310 .pipe(306- Effect.timeout(DEFAULT_TIMEOUT),311+ Effect.timeout(input.timeout ?? DEFAULT_TIMEOUT),
- apps/server/src/pullRequest/GitHubPullRequestCli.ts line 1695OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1691,0 +1675,21 @@1675+ } while (after !== null && heads.length <= workflowApprovalLimit);1676+ return heads;1677+ });1678+1679+ /**1680+ * The runs waiting on a maintainer for this exact head, up to one past the limit. `head_sha` is1681+ * what scopes them; `head_branch` is checked as well, the way `gh run list --branch` did.1682+ */1683+ const listActionRequiredRuns = (input: {1684+ readonly cwd: string;1685+ readonly repository: string;1686+ readonly host: string;1687+ readonly headSha: string;1688+ readonly headBranch: string;1689+ }) =>1690+ Effect.gen(function* () {1691+ // The checks revalidator may have just confirmed every run of this head as current.1692+ const known = yield* KnownWorkflowRuns;1693+ if (known !== null && known.headSha === input.headSha) {1694+ return known.runs.flatMap((run) =>1695+ run.status === "action_required" && run.head_branch === input.headBranch
- @@ -138,9 +145,5 @@138145 cause: Schema.Defect(),139146 },140147 ) {141- get detail(): string {142- return `GitHub CLI returned an unreadable ${this.operation} response.`;143- }144-145148 override get message(): string {146- return `GitHub CLI failed in ${this.operation}: ${this.detail}`;149+ return `GitHub CLI returned an unreadable ${this.operation} response.`;@@ -196,4 +202,4 @@196202 provider: "github",197203 operation,198204 ...gitHubProviderFailure(error),199- detail: error.detail,205+ detail: error.message,
- @@ -86,14 +107,14 @@107+ }),108+ GitHubApiResponseError: (error) =>109+ Effect.sync(() => {110+ entry.supported = !UNSUPPORTED_STATUSES.has(error.status);86111 return null;87112 }),88113 }),89114 );90- if (result === null) {115+ if (response === null) {91116 entry.value = null;92117 return null;93118 }94- if (result.stdoutTruncated || result.stdoutInvalidUtf8) return yield* fail();95- const split = result.stdout.search(/\r?\n\r?\n/);96- const headers = split < 0 ? result.stdout : result.stdout.slice(0, split);97- const status = /^HTTP\/\S+ (\d+)/.exec(headers)?.[1];98- if (status === "304" && previous) return previous.next;99- if (status !== "200") return yield* fail();119+ if (response.status === 304 && previous) return previous.next;120+ if (response.status !== 200 || response.truncated) {
- @@ -41,5 +46,18 @@41- debug: output.stderr,42- });43- }),46+ graphqlRequests: 1,47+ restRequests: 0,48+ cost: Option.match(decodeCost(body), {49+ onNone: () => 0,50+ onSome: (decoded) => decoded.data.rateLimit.cost,51+ }),52+ }),53+ ),4454 ),4555 ),56+ rest: (input) =>57+ api58+ .rest(input)59+ .pipe(60+ Effect.tap(() =>61+ Effect.sync(() => reads.push({ graphqlRequests: 0, restRequests: 1, cost: 0 })),62+ ),63+ ),@@ -1696,0 +1650,21 @@1650+ run.head_branch === input.headBranch1651+ ? [1652+ {1653+ id: run.id,1654+ name: run.name?.trim() || `Workflow run ${run.id}`,1655+ url: run.html_url?.trim() || null,1656+ },1657+ ]1658+ : [],1659+ );1660+ }1661+ const { owner, name } = parseRepositorySelector(input.repository);1662+ const runs: GitHubWorkflowRunApproval[] = [];1663+ for (let page = 1; runs.length <= workflowApprovalLimit; page++) {1664+ const read: GitHubWorkflowRunPage = yield* restRead({1665+ cwd: input.cwd,1666+ host: input.host,1667+ operation: "listWorkflowRunsRequiringApproval",1668+ path: `repos/${owner}/${name}/actions/runs?head_sha=${encodeURIComponent(input.headSha)}&branch=${encodeURIComponent(input.headBranch)}&event=pull_request&status=action_required&per_page=100&page=${page}`,1669+ decode: decodeWorkflowRunsJson,1670+ }).pipe(Effect.mapError((error) => workflowApprovalReadError(input.cwd, error)));
juliusmarminge merged thisadc3c93
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
1f78a41· Source CI: successScenario and decoded snapshot size
10 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.