Skip to content

Commit 709d6cd

Browse files
fix(server): pull_request_create returns an open PR despite local commits
- The unpushed-commit refusal applies only before opening a new PR. - A created PR refreshes the branch's PR lookup, so the thread finds it. - The eval runner records the PR the agent opened instead of inferring it from links. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7ec0192 commit 709d6cd

4 files changed

Lines changed: 58 additions & 20 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,22 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
40894089

40904090
expect(error.message).toContain("1 unpushed commit");
40914091
expect(created(providerCalls)).toEqual([]);
4092+
4093+
// An open PR is returned as it is; returning it publishes nothing.
4094+
const open = {
4095+
number: 7,
4096+
title: "Feature",
4097+
url: "https://github.com/pingdotgg/codething-mvp/pull/7",
4098+
baseRefName: "main",
4099+
headRefName: "feature/unpushed",
4100+
};
4101+
const existing = yield* makeManager({ providerScenario: { prListSequence: [[open]] } });
4102+
const found = yield* existing.manager.createPullRequest({
4103+
cwd: repoDir,
4104+
title: "Feature",
4105+
body: "Body",
4106+
});
4107+
expect(found).toMatchObject({ status: "opened_existing", number: 7 });
40924108
}),
40934109
);
40944110

‎apps/server/src/git/GitManager.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,14 @@ export const make = Effect.gen(function* () {
23772377
};
23782378
}
23792379

2380+
// A PR opened from the remote branch would leave out commits not pushed yet.
2381+
if (details.aheadCount > 0) {
2382+
return yield* new GitManagerError({
2383+
operation: "runPrStep",
2384+
cwd,
2385+
detail: `The branch has ${details.aheadCount} unpushed commit${details.aheadCount === 1 ? "" : "s"}. Push before opening the PR.`,
2386+
});
2387+
}
23802388
const resolved = yield* resolvePrBase(cwd, branch, details.upstreamRef, headContext);
23812389
const baseBranch = requestedBase ?? resolved.baseBranch;
23822390
const generated = yield* content({
@@ -2493,22 +2501,16 @@ export const make = Effect.gen(function* () {
24932501
const createPullRequest: GitManager["Service"]["createPullRequest"] = Effect.fn(
24942502
"GitManager.createPullRequest",
24952503
)(function* (input) {
2496-
// A PR opened from the remote branch would leave out commits not pushed yet.
2497-
const { aheadCount } = yield* gitCore.statusDetails(input.cwd);
2498-
if (aheadCount > 0) {
2499-
return yield* new GitManagerError({
2500-
operation: "createPullRequest",
2501-
cwd: input.cwd,
2502-
detail: `The branch has ${aheadCount} unpushed commit${aheadCount === 1 ? "" : "s"}. Push before opening the PR.`,
2503-
});
2504-
}
2505-
return yield* openPrFromBranch(
2504+
const result = yield* openPrFromBranch(
25062505
input.cwd,
25072506
null,
25082507
() => Effect.void,
25092508
input.baseBranch,
25102509
() => Effect.succeed({ title: input.title, body: input.body }),
25112510
);
2511+
// The thread's branch PR comes from status, which may hold the lookup from before.
2512+
if (result.status === "created") yield* invalidateStatus(input.cwd);
2513+
return result;
25122514
});
25132515

25142516
const localStatus: GitManager["Service"]["localStatus"] = Effect.fn("localStatus")(

‎evals/mcp-tool-use/run.test.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ it.effect("reads the branch's PR only once the agent has opened it", () =>
880880
assert.isNotTrue((yield* call("c", "pull_request_read", {})).is_error);
881881

882882
// A case that mocks the create still opens the PR it names.
883-
const url = "https://github.com/acme/app/pull/124";
884-
const mocks = { pull_request_create: { number: 124, url, created: true } };
883+
const url = "https://github.com/acme/app/pull/125";
884+
const mocks = { pull_request_create: { number: 125, url, created: true } };
885885
const mockedSample = makeSample(
886886
{ ...childCase, setup: { ...childCase.setup, world, mocks } },
887887
base,
@@ -895,7 +895,21 @@ it.effect("reads the branch's PR only once the agent has opened it", () =>
895895
input: name === "pull_request_create" ? { title: "Feature", body: "Body" } : {},
896896
});
897897
yield* mockedCall("d", "pull_request_create");
898-
assert.isNotTrue((yield* mockedCall("e", "pull_request_read")).is_error);
898+
const mockedRead = yield* mockedCall("e", "pull_request_read");
899+
assert.isNotTrue(mockedRead.is_error);
900+
assert.include(String(mockedRead.content), "/pull/125");
901+
902+
// Linking the URL a create would open is not opening it.
903+
const linkedOnly = makeSample({ ...childCase, setup: { ...childCase.setup, world } }, base);
904+
linkedOnly.tools.push(...sample.tools);
905+
linkedOnly.linked.add("https://github.com/acme/app/pull/124");
906+
const linkedRead = yield* answerToolCall(linkedOnly, config, {
907+
type: "tool_use",
908+
id: "f",
909+
name: "mcp__t3-code__pull_request_read",
910+
input: {},
911+
});
912+
assert.isTrue(linkedRead.is_error);
899913
}).pipe(Effect.provide(FetchHttpClient.layer)),
900914
);
901915

‎evals/mcp-tool-use/run.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ type Sample = {
826826
readonly shell: Array<ShellEntry>;
827827
readonly shellUsage: Usage;
828828
readonly linked: Set<string>;
829+
/** The branch PR the agent opened in this sample, which links alone do not prove. */
830+
openedPullRequest: number | undefined;
829831
readonly codeStore: Record<string, unknown>;
830832
nextTask: number;
831833
/** Threads the agent launched in this sample, by id, so reading one shows its own brief. */
@@ -875,6 +877,10 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {
875877
shell,
876878
shellUsage: emptyUsage(),
877879
linked: new Set([...urls, ...shell.flatMap(createdPullRequests)]),
880+
openedPullRequest: shell
881+
.flatMap(createdPullRequests)
882+
.map((url) => Number(/\/pull\/(\d+)/.exec(url)?.[1]))
883+
.find((number) => number > 0),
878884
codeStore: {},
879885
nextTask: Math.max(0, ...taskNumbers) + 1,
880886
threads: new Map(),
@@ -1117,6 +1123,9 @@ const branchPullRequest = (sample: Sample) => {
11171123
const prs = worldPullRequests(sample);
11181124
const own = prs.find((pr) => pr.headRefName === branch);
11191125
if (own !== undefined) return { number: Number(own.number), created: false, pr: own };
1126+
if (sample.openedPullRequest !== undefined) {
1127+
return { number: sample.openedPullRequest, created: false, pr: undefined };
1128+
}
11201129
const mocked = (sample.testCase.setup.shellMocks ?? []).find((mock) =>
11211130
/\b(pr|mr) create\b/.test(mock.match),
11221131
);
@@ -1226,6 +1235,7 @@ export const t3Default = (
12261235
const { number, created } = branchPullRequest(sample);
12271236
const target = pullRequest(sample.repo, { number });
12281237
sample.linked.add(target.url);
1238+
if (created) sample.openedPullRequest = number;
12291239
return { ...target, created };
12301240
}
12311241
case "pull_request_read": {
@@ -1753,6 +1763,8 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun
17531763
if (name === "request_secret") savedSecretFile(sample, mock);
17541764
if (name === "pull_request_create" && isRecord(mock) && typeof mock.url === "string") {
17551765
sample.linked.add(mock.url);
1766+
const number = Number(mock.number);
1767+
if (number > 0) sample.openedPullRequest = number;
17561768
}
17571769
return toolResult(
17581770
call.id,
@@ -1768,13 +1780,7 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun
17681780
}
17691781
if (BRANCH_PULL_REQUEST_TOOLS.has(name) && input.number === undefined) {
17701782
// Until the agent opens it, the PR a create would open does not exist.
1771-
const own = branchPullRequest(sample);
1772-
const mocked = testCase.setup.mocks?.pull_request_create;
1773-
const opened = [
1774-
pullRequest(sample.repo, { number: own.number }).url,
1775-
isRecord(mocked) ? mocked.url : undefined,
1776-
].some((url) => typeof url === "string" && sample.linked.has(url));
1777-
if (own.created && !opened) return failed(BRANCH_HAS_NO_PR_ERROR);
1783+
if (branchPullRequest(sample).created) return failed(BRANCH_HAS_NO_PR_ERROR);
17781784
}
17791785
const value = t3Default(sample, name, input);
17801786
if (name === "request_secret") savedSecretFile(sample, value);

0 commit comments

Comments
 (0)