Skip to content

Commit e415f71

Browse files
t3dotggclaude
andcommitted
fix(server): agents link only the pull requests they create
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a8dba9c commit e415f71

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ it.effect(
438438
const linkTool = server.tools.find(({ tool }) => tool.name === "link_pull_request");
439439
expect(linkTool?.tool.annotations?.idempotentHint).toBe(true);
440440
expect(linkTool?.tool.annotations?.openWorldHint).toBe(false);
441-
expect(linkTool?.tool.description).toContain("Register every pull request you open");
441+
expect(linkTool?.tool.description).toContain("Register every pull request you create");
442+
expect(linkTool?.tool.description).toContain(
443+
"Do not link pull requests you only read or review.",
444+
);
442445

443446
const denied = yield* server
444447
.callTool({ name: "list_thread_pull_requests", arguments: {} })

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const guideDependencies = [
3232
];
3333

3434
const REGISTER_EVERY_PR =
35-
"Register every pull request you open for this thread, including each layer of a stack, right after creating it.";
35+
"Register every pull request you create for this thread, including each layer of a stack, right after creating it. Do not link pull requests you only read or review.";
3636

3737
export const PullRequestTargetInput = Schema.Struct({
3838
threadId: Schema.optional(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
3+
import { buildRuntimeInstructions } from "./runtimeInstructions.ts";
4+
5+
describe("buildRuntimeInstructions", () => {
6+
it("asks agents to link only the pull requests they create", () => {
7+
const instructions = buildRuntimeInstructions({ harness: "Codex" });
8+
9+
assert.include(instructions, "every pull request you create");
10+
assert.include(instructions, "Do not link PRs you only read, review, or score.");
11+
assert.notInclude(instructions, "work on");
12+
// Listing linked PRs as an end-of-work check found nothing to add in audited threads.
13+
assert.notInclude(instructions, "list_thread_pull_requests");
14+
});
15+
});

‎packages/provider-core/src/server/runtimeInstructions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const PULL_REQUEST_LINKING_INSTRUCTIONS = `<pull_request_linking>
2-
When the t3-code MCP server exposes link_pull_request, you must use it to register every pull request you create or work on for this thread. Call link_pull_request with the full PR URL immediately after creating a PR or starting work on an existing PR. For a stack, call it for every layer, not just the current branch or the top PR. This applies when creating or updating PRs through gh, gh stack, another CLI, or the host API: those operations do not register the PRs with this thread. Linking an already-linked PR is safe. Before finishing PR work, call list_thread_pull_requests and link any PR from your work that is missing. Do not link unrelated PRs mentioned only as background. If a linking call fails, report that failure instead of claiming the PR is linked. As a delegated child task, do not watch or poll PRs; return PR URLs, head SHA, and pending review/check state to your parent. Otherwise, when asked to monitor, watch, or babysit a PR and watch_pull_request is available, call it and end your turn: T3 Code wakes you when checks finish, someone else comments, or the branch conflicts, so do not poll or run your own watcher. When monitoring is done and you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox.
2+
When the t3-code MCP server exposes link_pull_request, call it with the full URL of every pull request you create, right after creating it. For a stack, link every layer. Do this for PRs created through gh, gh stack, another CLI, or the host API; those do not link the PR to this thread. Linking twice is safe. Do not link PRs you only read, review, or score. If linking fails, say so instead of claiming the PR is linked. As a delegated child task, do not watch or poll PRs; return PR URLs, head SHA, and pending review/check state to your parent. Otherwise, when asked to monitor, watch, or babysit a PR and watch_pull_request is available, call it and end your turn: T3 Code wakes you when checks finish, someone else comments, or the branch conflicts, so do not poll or run your own watcher. When monitoring is done and you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox.
33
</pull_request_linking>`;
44

55
/**

0 commit comments

Comments
 (0)