The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 23:00 UTC
fix(server): GitHub PR lookups stop probing owner-qualified heads (#13200)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Sep 22, 2026 at 20:50 UTC
eafb4a9340bd2c2271b7c8fac7eddd55beea3972
2 files changed
+51
-104
apps/server/src/git/GitManager.test.ts
+21
-98
@@ -1309,7 +1309,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
1309
prListByHeadSelector: {
1310
// Fake gh returns raw JSON stdout, matching the CLI boundary under test.
1311
// @effect-diagnostics-next-line preferSchemaOverJson:off
1312
- "contributor:feature/deleted-fork-branch": JSON.stringify([
1312
+ "feature/deleted-fork-branch": JSON.stringify([
1313
{
1314
number: 218,
1315
title: "Deleted fork branch PR",
@@ -1339,8 +1339,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
1339
updatedAt: "2026-04-05T15:00:00.000Z",
1340
});
1341
expect(
1342
- ghCalls.some((call) => call.includes("--head contributor:feature/deleted-fork-branch")),
1342
+ ghCalls.some((call) => call.includes("--head feature/deleted-fork-branch --state all")),
1343
).toBe(true);
1344
+ expect(ghCalls.some((call) => call.includes("--head contributor:"))).toBe(false);
1345
}),
1346
);
1347
@@ -1776,8 +1777,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
1777
const { manager } = yield* makeManager({
1778
ghScenario: {
1779
prListByHeadSelector: {
1779
- "alice:feature": output,
1780
- "fork:feature": output,
1780
feature: output,
1781
},
1782
},
@@ -1944,10 +1943,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
1943
const { manager, ghCalls } = yield* makeManager({
1944
ghScenario: {
1945
prListSequence: [
1947
- // @effect-diagnostics-next-line preferSchemaOverJson:off
1948
- JSON.stringify([]),
1949
- // @effect-diagnostics-next-line preferSchemaOverJson:off
1950
- JSON.stringify([]),
1946
// @effect-diagnostics-next-line preferSchemaOverJson:off
1947
JSON.stringify([
1948
{
@@ -1983,7 +1978,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
1978
updatedAt: "2026-03-10T07:00:00.000Z",
1979
});
1980
expect(ghCalls).toContain(
1986
- "pr list --head jasonLaster:statemachine --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,closedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
1981
+ "pr list --head statemachine --state all --limit 100 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,closedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
1982
);
1983
}),
1984
20_000,
@@ -2015,7 +2010,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2010
ghScenario: {
2011
prListByHeadSelector: {
2012
// @effect-diagnostics-next-line preferSchemaOverJson:off
2018
- "contributor:main": JSON.stringify([
2013
+ main: JSON.stringify([
2014
{
2015
number: 777,
2016
title: "Fork PR from main",
@@ -2049,7 +2044,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2044
updatedAt: "2026-03-10T07:00:00.000Z",
2045
});
2046
expect(ghCalls).toContain(
2052
- "pr list --head contributor:main --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,closedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
2047
+ "pr list --head main --state all --limit 100 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,closedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
2048
);
2049
}),
2050
20_000,
@@ -2114,34 +2109,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2109
updatedAt: "2026-04-01T10:00:00Z",
2110
},
2111
]),
2117
- // @effect-diagnostics-next-line preferSchemaOverJson:off
2118
- "pingdotgg:effect-atom": JSON.stringify([]),
2119
- // @effect-diagnostics-next-line preferSchemaOverJson:off
2120
- "my-org/upstream:effect-atom": JSON.stringify([]),
2121
- // @effect-diagnostics-next-line preferSchemaOverJson:off
2122
- "pingdotgg:upstream/effect-atom": JSON.stringify([
2123
- {
2124
- number: 1518,
2125
- title: "Wrong PR",
2126
- url: "https://github.com/pingdotgg/t3code/pull/1518",
2127
- baseRefName: "main",
2128
- headRefName: "upstream/effect-atom",
2129
- state: "OPEN",
2130
- updatedAt: "2026-04-01T10:00:00Z",
2131
- },
2132
- ]),
2133
- // @effect-diagnostics-next-line preferSchemaOverJson:off
2134
- "my-org/upstream:upstream/effect-atom": JSON.stringify([
2135
- {
2136
- number: 1518,
2137
- title: "Wrong PR",
2138
- url: "https://github.com/pingdotgg/t3code/pull/1518",
2139
- baseRefName: "main",
2140
- headRefName: "upstream/effect-atom",
2141
- state: "OPEN",
2142
- updatedAt: "2026-04-01T10:00:00Z",
2143
- },
2144
- ]),
2112
},
2113
},
2114
});
@@ -2352,7 +2319,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2319
prListByHeadSelector: {
2320
// Fake gh returns raw JSON stdout, matching the CLI boundary under test.
2321
// @effect-diagnostics-next-line preferSchemaOverJson:off
2355
- "contributor:feature/fork-plain": JSON.stringify([
2322
+ "feature/fork-plain": JSON.stringify([
2323
{
2324
number: 89,
2325
title: "Fork PR pushed without -u",
@@ -2372,9 +2339,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2339
2340
const status = yield* manager.status({ cwd: repoDir });
2341
expect(status.pr?.number).toBe(89);
2375
- expect(ghCalls.some((call) => call.includes("--head contributor:feature/fork-plain"))).toBe(
2376
- true,
2377
- );
2342
+ expect(ghCalls.some((call) => call.includes("--head feature/fork-plain"))).toBe(true);
2343
+ expect(ghCalls.some((call) => call.includes("--head contributor:"))).toBe(false);
2344
expect(ghCalls.some((call) => call.includes("--head main"))).toBe(false);
2345
}),
2346
);
@@ -2409,7 +2375,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
2375
prListByHeadSelector: {
2376
// Fake gh returns raw JSON stdout, matching the CLI boundary under test.
2377
// @effect-diagnostics-next-line preferSchemaOverJson:off
2412
- "contributor:feature/fork-settle": JSON.stringify([
2378
+ "feature/fork-settle": JSON.stringify([
2379
{
2380
number: 91,
2381
title: "Fork PR to settle",
@@ -3570,7 +3536,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3536
);
3537
3538
it.effect(
3573
- "returns existing cross-repo PR metadata using the fork owner selector",
3539
+ "returns existing cross-repo PR metadata found under the bare branch name",
3540
() =>
3541
Effect.gen(function* () {
3542
const repoDir = yield* makeTempDir("t3code-git-manager-");
@@ -3589,8 +3555,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3555
const { manager, ghCalls } = yield* makeManager({
3556
ghScenario: {
3557
prListSequence: [
3592
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3593
- JSON.stringify([]),
3558
// @effect-diagnostics-next-line preferSchemaOverJson:off
3559
JSON.stringify([
3560
{
@@ -3622,7 +3586,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3586
expect(result.pr.number).toBe(142);
3587
expect(
3588
ghCalls.some((call) =>
3625
- call.includes("pr list --head octocat:statemachine --state open --limit 1"),
3589
+ call.includes("pr list --head statemachine --state open --limit 100"),
3590
),
3591
).toBe(true);
3592
expect(ghCalls.some((call) => call.startsWith("pr create "))).toBe(false);
@@ -3688,30 +3652,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3652
headRefName: "upstream/effect-atom",
3653
},
3654
]),
3691
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3692
- "pingdotgg:effect-atom": JSON.stringify([]),
3693
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3694
- "my-org/upstream:effect-atom": JSON.stringify([]),
3695
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3696
- "pingdotgg:upstream/effect-atom": JSON.stringify([
3697
- {
3698
- number: 1518,
3699
- title: "Wrong PR",
3700
- url: "https://github.com/pingdotgg/t3code/pull/1518",
3701
- baseRefName: "main",
3702
- headRefName: "upstream/effect-atom",
3703
- },
3704
- ]),
3705
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3706
- "my-org/upstream:upstream/effect-atom": JSON.stringify([
3707
- {
3708
- number: 1518,
3709
- title: "Wrong PR",
3710
- url: "https://github.com/pingdotgg/t3code/pull/1518",
3711
- baseRefName: "main",
3712
- headRefName: "upstream/effect-atom",
3713
- },
3714
- ]),
3655
},
3656
},
3657
});
@@ -3731,7 +3671,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3671
);
3672
3673
it.effect(
3734
- "prefers owner-qualified selectors before bare branch names for cross-repo PRs",
3674
+ "picks the fork PR among same-named branches from other repositories",
3675
() =>
3676
Effect.gen(function* () {
3677
const repoDir = yield* makeTempDir("t3code-git-manager-");
@@ -3763,9 +3703,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3703
baseRefName: "main",
3704
headRefName: "statemachine",
3705
},
3766
- ]),
3767
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3768
- "octocat:statemachine": JSON.stringify([
3706
{
3707
number: 142,
3708
title: "Existing fork PR",
@@ -3782,8 +3719,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3719
},
3720
},
3721
]),
3785
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3786
- "fork-seed:statemachine": JSON.stringify([]),
3722
},
3723
},
3724
});
@@ -3795,11 +3730,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3730
3731
expect(result.pr.status).toBe("opened_existing");
3732
expect(result.pr.number).toBe(142);
3798
-
3799
- const ownerSelectorCallIndex = ghCalls.findIndex((call) =>
3800
- call.includes("pr list --head octocat:statemachine --state open --limit 1"),
3801
- );
3802
- expect(ownerSelectorCallIndex).toBeGreaterThanOrEqual(0);
3733
+ expect(
3734
+ ghCalls.some((call) => /--head [^ ]*:/u.test(call) && call.startsWith("pr list")),
3735
+ ).toBe(false);
3736
expect(ghCalls.some((call) => call.startsWith("pr create "))).toBe(false);
3737
}),
3738
12_000,
@@ -3828,7 +3761,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3761
ghScenario: {
3762
prListByHeadSelector: {
3763
// @effect-diagnostics-next-line preferSchemaOverJson:off
3831
- "octocat:statemachine": JSON.stringify([
3764
+ statemachine: JSON.stringify([
3765
{
3766
number: 142,
3767
title: "Existing fork PR",
@@ -3846,11 +3779,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3779
},
3780
]),
3781
// @effect-diagnostics-next-line preferSchemaOverJson:off
3849
- "fork-seed:statemachine": JSON.stringify([]),
3850
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3782
"t3code/pr-142/statemachine": JSON.stringify([]),
3852
- // @effect-diagnostics-next-line preferSchemaOverJson:off
3853
- statemachine: JSON.stringify([]),
3783
},
3784
},
3785
});
@@ -3863,10 +3792,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3792
expect(result.pr.status).toBe("opened_existing");
3793
expect(result.pr.number).toBe(142);
3794
3866
- const openLookupCalls = ghCalls.filter((call) => call.includes("--state open --limit 1"));
3795
+ const openLookupCalls = ghCalls.filter((call) => call.includes("--state open --limit 100"));
3796
expect(openLookupCalls).toHaveLength(1);
3797
expect(openLookupCalls[0]).toContain(
3869
- "pr list --head octocat:statemachine --state open --limit 1",
3798
+ "pr list --head statemachine --state open --limit 100",
3799
);
3800
}),
3801
12_000,
@@ -3891,12 +3820,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
3820
const { manager, ghCalls } = yield* makeManager({
3821
ghScenario: {
3822
prListSequenceByHeadSelector: {
3894
- "octocat:statemachine": [
3823
+ statemachine: [
3824
`[{"number":41,"title":"Ambiguous fork PR","url":"https://github.com/pingdotgg/codething-mvp/pull/41","baseRefName":"main","headRefName":"statemachine","state":"OPEN"}]`,
3825
`[{"number":142,"title":"Add stacked git actions","url":"https://github.com/pingdotgg/codething-mvp/pull/142","baseRefName":"main","headRefName":"statemachine","state":"OPEN","isCrossRepository":true,"headRepository":{"nameWithOwner":"octocat/codething-mvp"},"headRepositoryOwner":{"login":"octocat"}}]`,
3826
],
3898
- "fork-seed:statemachine": ["[]"],
3899
- statemachine: ["[]"],
3827
},
3828
},
3829
});
@@ -4295,7 +4222,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4222
const { manager, ghCalls } = yield* makeManager({
4223
ghScenario: {
4224
prListSequenceByHeadSelector: {
4298
- "octocat:statemachine": [
4225
+ statemachine: [
4226
// @effect-diagnostics-next-line preferSchemaOverJson:off
4227
JSON.stringify([]),
4228
// @effect-diagnostics-next-line preferSchemaOverJson:off
@@ -4317,10 +4244,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4244
},
4245
]),
4246
],
4320
- // @effect-diagnostics-next-line preferSchemaOverJson:off
4321
- "fork-seed:statemachine": [JSON.stringify([])],
4322
- // @effect-diagnostics-next-line preferSchemaOverJson:off
4323
- statemachine: [JSON.stringify([])],
4247
},
4248
},
4249
});
apps/server/src/git/GitManager.ts
+30
-6
@@ -32,6 +32,7 @@ import {
32
ModelSelection,
33
type ProjectId,
34
SourceControlProviderError,
35
+ type SourceControlProviderKind,
36
type SourceControlWritingStyleSettings,
37
type ThreadId,
38
} from "@t3tools/contracts";
@@ -594,6 +595,26 @@ function parseCustomCommitMessage(raw: string): { subject: string; body: string
595
};
596
}
597
598
+// Without the owner selector, a bare branch name also lists same-named
599
+// branches on other forks (`main`, `patch-1`), so GitHub probes ask for a full
600
+// page and let matchesBranchHeadContext pick the right head. gh fetches up to
601
+// 100 in one request, and GitHub prices a first:100 connection like first:1.
602
+const GITHUB_HEAD_BRANCH_PROBE_LIMIT = 100;
603
+
604
+// `gh pr list --head` filters on the head ref name alone and accepts anything, so an
605
+// `owner:branch` or `remote:branch` selector silently lists zero pull requests
606
+// while spending a GraphQL call. Git branch names cannot contain ":", and the
607
+// bare head branch is always among the selectors, so GitHub probes skip them and
608
+// leave the owner check to matchesBranchHeadContext.
609
+function probeableHeadSelectors(
610
+ providerKind: SourceControlProviderKind,
611
+ headSelectors: ReadonlyArray<string>,
612
+): ReadonlyArray<string> {
613
+ return providerKind === "github"
614
+ ? headSelectors.filter((selector) => !selector.includes(":"))
615
+ : headSelectors;
616
+}
617
+
618
function appendUnique(values: string[], next: string | null | undefined): void {
619
const trimmed = next?.trim() ?? "";
620
if (trimmed.length === 0 || values.includes(trimmed)) {
@@ -1604,12 +1625,14 @@ export const make = Effect.gen(function* () {
1625
| "isCrossRepository"
1626
>,
1627
) {
1607
- for (const headSelector of headContext.headSelectors) {
1608
- const pullRequests = yield* (yield* sourceControlProvider(cwd)).listChangeRequests({
1628
+ const provider = yield* sourceControlProvider(cwd);
1629
+ const headSelectors = probeableHeadSelectors(provider.kind, headContext.headSelectors);
1630
+ for (const headSelector of headSelectors) {
1631
+ const pullRequests = yield* provider.listChangeRequests({
1632
cwd,
1633
headSelector,
1634
state: "open",
1612
- limit: 1,
1635
+ limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 1,
1636
});
1637
const normalizedPullRequests = pullRequests.map(toPullRequestInfo);
1638
@@ -1634,12 +1657,13 @@ export const make = Effect.gen(function* () {
1657
) {
1658
const parsedByNumber = new Map<number, PullRequestInfo>();
1659
1637
- for (const headSelector of headContext.headSelectors) {
1638
- const pullRequests = yield* (yield* sourceControlProvider(cwd)).listChangeRequests({
1660
+ const provider = yield* sourceControlProvider(cwd);
1661
+ for (const headSelector of probeableHeadSelectors(provider.kind, headContext.headSelectors)) {
1662
+ const pullRequests = yield* provider.listChangeRequests({
1663
cwd,
1664
headSelector,
1665
state: "all",
1642
- limit: 20,
1666
+ limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 20,
1667
});
1668
1669
for (const pr of pullRequests.map(toPullRequestInfo)) {