fix(server): background GitHub polling uses ~74% fewer calls with batched GraphQL (#14673)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-10-01 16:48:29 -07:00
1 parent a3abb52660
commit 10ac2f2ba4
15 files changed
+1039 -213

No files matched your search

@@ -7,6 +7,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import * as GitHubCli from "./GitHubCli.ts";
import * as GitHubGraphQlBudget from "./githubGraphQlBudget.ts";
import { parseGitHubAuthStatus } from "./gitHubAuthStatus.ts";
import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
@@ -32,19 +33,13 @@ function makeProvider(github: Partial<GitHubCli.GitHubCli["Service"]>) {
it.effect("uses the enterprise quota for a current-repository default branch read", () =>
Effect.gen(function* () {
const provider = yield* GitHubSourceControlProvider.make.pipe(
Effect.provide(GitHubCli.layer),
Effect.provideService(VcsProcess.VcsProcess, {
run: (input) =>
Effect.sync(() => {
if (input.args[1] !== "rate_limit") return processResult("main");
assert.strictEqual(input.args[3], "enterprise.test");
return processResult(
'{"data":{"rateLimit":{"cost":1,"limit":5000,"remaining":5000,"resetAt":"2099-01-01T00:00:00Z"}}}',
);
}),
}),
// github.com is out of quota; the enterprise read must not be priced against it.
const budget = yield* GitHubGraphQlBudget.GitHubGraphQlBudget;
yield* budget.observe(
"github.com",
'{"data":{"rateLimit":{"cost":1,"limit":5000,"remaining":0,"resetAt":"2099-01-01T00:00:00Z"}}}',
);
const provider = yield* GitHubSourceControlProvider.make;
const branch = yield* provider.getDefaultBranch({
cwd: "/enterprise-repo",
context: {
@@ -54,7 +49,12 @@ it.effect("uses the enterprise quota for a current-repository default branch rea
},
});
assert.strictEqual(branch, "main");
}),
}).pipe(
Effect.provide(GitHubCli.layer),
Effect.provideService(VcsProcess.VcsProcess, {
run: () => Effect.succeed(processResult("main")),
}),
),
);
it.effect("maps GitHub PR summaries into provider-neutral change requests", () =>
@@ -138,50 +138,47 @@ it.effect("adds safe request context while retaining GitHub CLI causes", () =>
}),
);
it.effect("uses gh json listing for non-open change request state queries", () =>
it.effect("lists change request history through the batched head lookup", () =>
Effect.gen(function* () {
let executeArgs: ReadonlyArray<string> = [];
let lookup: Parameters<GitHubCli.GitHubCli["Service"]["listPullRequestsByHead"]>[0] | null =
null;
const provider = yield* makeProvider({
execute: (input) => {
executeArgs = input.args;
return Effect.succeed(
processResult(
JSON.stringify([
{
number: 7,
title: "Merged work",
url: "https://github.com/pingdotgg/t3code/pull/7",
baseRefName: "main",
headRefName: "feature/merged",
state: "merged",
mergedAt: "2026-01-01T00:00:00Z",
updatedAt: "2026-01-02T00:00:00.000Z",
},
]),
),
);
listPullRequestsByHead: (input) => {
lookup = input;
return Effect.succeed([
{
number: 7,
title: "Merged work",
url: "https://enterprise.test/acme/web/pull/7",
baseRefName: "main",
headRefName: "feature/merged",
state: "merged",
mergedAt: "2026-01-01T00:00:00Z",
updatedAt: Option.some(DateTime.makeUnsafe("2026-01-02T00:00:00.000Z")),
},
]);
},
});
const changeRequests = yield* provider.listChangeRequests({
cwd: "/repo",
context: {
provider: { kind: "github", name: "GitHub Enterprise", baseUrl: "https://enterprise.test" },
remoteName: "origin",
remoteUrl: "https://enterprise.test/acme/web.git",
},
headSelector: "feature/merged",
state: "all",
limit: 10,
});
assert.deepStrictEqual(executeArgs, [
"pr",
"list",
"--head",
"feature/merged",
"--state",
"all",
"--limit",
"10",
"--json",
"number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,closedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
]);
assert.deepStrictEqual(lookup, {
cwd: "/repo",
headSelector: "feature/merged",
state: "all",
limit: 10,
rateLimitHost: "enterprise.test",
});
assert.strictEqual(changeRequests[0]?.provider, "github");
assert.strictEqual(changeRequests[0]?.state, "merged");
assert.strictEqual(changeRequests[0]?.mergedAt, "2026-01-01T00:00:00Z");
@@ -192,23 +189,6 @@ it.effect("uses gh json listing for non-open change request state queries", () =
}),
);
it.effect("treats empty non-open change request listing output as no results", () =>
Effect.gen(function* () {
const provider = yield* makeProvider({
execute: () => Effect.succeed(processResult("")),
});
const changeRequests = yield* provider.listChangeRequests({
cwd: "/repo",
headSelector: "feature/empty",
state: "all",
limit: 10,
});
assert.deepStrictEqual(changeRequests, []);
}),
);
it.effect("creates GitHub PRs through provider-neutral input names", () =>
Effect.gen(function* () {
let createInput: Parameters<GitHubCli.GitHubCli["Service"]["createPullRequest"]>[0] | null =