Skip to content

Commit a0b096b

Browse files
authored
fix(agent): avoid redundant PR checkout
Make existing-PR follow-up context check out the branch only when needed, preventing cloud agents from repeating the checkout on every prompt. Generated-By: PostHog Code Task-Id: 9e493924-1eab-496a-ba66-aba8366de96e
1 parent f418475 commit a0b096b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

packages/agent/src/server/agent-server.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,13 +3827,18 @@ describe("AgentServer HTTP Mode", () => {
38273827
expect(context).not.toContain("gh pr checkout");
38283828
});
38293829

3830-
it("returns auto-update PR context for Slack-origin runs", () => {
3830+
it("avoids redundant PR checkout for auto-update runs", () => {
38313831
process.env.POSTHOG_CODE_INTERACTION_ORIGIN = "slack";
38323832
const s = createServer();
38333833
const context = (s as unknown as TestableServer).buildDetectedPrContext(
38343834
prUrl,
38353835
);
3836-
expect(context).toContain(`gh pr checkout ${prUrl}`);
3836+
expect(context).toContain(
3837+
`If it is not already checked out, check it out with \`gh pr checkout ${prUrl}\``,
3838+
);
3839+
expect(context).toContain(
3840+
"Do not check it out again when it is already active",
3841+
);
38373842
expect(context).toContain(
38383843
"Make changes, commit, and push to that branch",
38393844
);

packages/agent/src/server/agent-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ export class AgentServer {
31523152
`IMPORTANT — OVERRIDE PREVIOUS INSTRUCTIONS ABOUT CREATING BRANCHES/PRs.\n` +
31533153
`You already have an open pull request: ${prUrl}\n` +
31543154
`You MUST:\n` +
3155-
`1. Check out the existing PR branch with \`gh pr checkout ${prUrl}\`\n` +
3155+
`1. Continue working on the existing PR branch. If it is not already checked out, check it out with \`gh pr checkout ${prUrl}\`. Do not check it out again when it is already active.\n` +
31563156
`2. Make changes, commit, and push to that branch\n` +
31573157
`You MUST NOT create a new branch, close the existing PR, or create a new PR.`
31583158
);

0 commit comments

Comments
 (0)