Skip to content

Commit 5c004fd

Browse files
authored
fix(server): keep PR generation focused on the change (#31819)
1 parent 98b930f commit 5c004fd

12 files changed

Lines changed: 262 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", {
141141
workspaceStrategy: Schema.optional(
142142
OrchestrationV2ThreadLaunchWorkspaceStrategy.annotate({
143143
description:
144-
"'worktree': new checkout from `baseRef`. 'existing_worktree': bind `worktreePath`, a project worktree. 'root': project checkout, the default, not your worktree. Stack: parent branch as `baseRef`, `startFromOrigin: false`. Uncommitted edits are not copied.",
144+
"'worktree': new checkout from `baseRef`. Honor a requested base. Otherwise, independent work uses the default branch as `remote/branch` (e.g. `origin/main`) with `startFromOrigin: true`; with no remote, use the local default branch. Required unpublished commits and dependent or stacked work use their local base with `startFromOrigin: false`. 'existing_worktree': bind `worktreePath`, a project worktree. 'root': project checkout, the default, not your worktree. Uncommitted edits are not copied.",
145145
}),
146146
),
147147
message: Schema.optional(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"claudeSystemAppendBytes": 5133,
3-
"codexAdditionalContextBytes": 6863,
4-
"mcpToolListJsonBytes": 47809
2+
"claudeSystemAppendBytes": 5366,
3+
"codexAdditionalContextBytes": 7096,
4+
"mcpToolListJsonBytes": 48051
55
}

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ interface FakeCodexInput {
5454
stdinMustContain?: string;
5555
stdinMustNotContain?: string;
5656
mcpServers?: ReadonlyArray<{ name: string; enabled: boolean }> | number;
57+
requiredCwd?: string;
58+
requireInstructions?: string;
5759
}
5860

5961
function makeFakeCodexBinary(dir: string, input: FakeCodexInput) {
@@ -67,6 +69,8 @@ function makeFakeCodexBinary(dir: string, input: FakeCodexInput) {
6769
stdinMustContain: input.stdinMustContain ?? null,
6870
stdinMustNotContain: input.stdinMustNotContain ?? null,
6971
mcpServers: input.mcpServers ?? [],
72+
requiredCwd: input.requiredCwd ?? null,
73+
requireInstructions: input.requireInstructions ?? null,
7074
stderr: input.stderr ?? null,
7175
output: input.output,
7276
exitCode: input.exitCode ?? 0,
@@ -100,13 +104,15 @@ function makeFakeCodexBinary(dir: string, input: FakeCodexInput) {
100104
"let seenImage = false;",
101105
'let seenServiceTier = "";',
102106
'let seenReasoningEffort = "";',
107+
'let instructions = "";',
103108
"for (let index = 0; index < args.length; index += 1) {",
104109
' if (args[index] === "--image") {',
105110
" index += 1;",
106111
" if (args[index]) seenImage = true;",
107112
' } else if (args[index] === "--config") {',
108113
" index += 1;",
109114
' const value = args[index] ?? "";',
115+
' if (value.startsWith("developer_instructions=")) instructions = JSON.parse(value.slice("developer_instructions=".length));',
110116
' if (value.startsWith("service_tier=")) seenServiceTier = value;',
111117
' if (value.startsWith("model_reasoning_effort=")) seenReasoningEffort = value;',
112118
' } else if (args[index] === "--output-last-message") {',
@@ -121,6 +127,8 @@ function makeFakeCodexBinary(dir: string, input: FakeCodexInput) {
121127
' process.stderr.write(message + "\\n");',
122128
" process.exit(code);",
123129
"}",
130+
'if (check.requiredCwd !== null && process.cwd() !== check.requiredCwd) fail("cannot inspect checkout", 10);',
131+
'if (check.requireInstructions !== null && !instructions.includes(check.requireInstructions)) fail("missing writer task", 11);',
124132
"if (check.requireArg !== null && !originalArgs.includes(` ${check.requireArg} `)) {",
125133
' fail("missing arg: " + check.requireArg, 8);',
126134
"}",
@@ -341,10 +349,14 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
341349
),
342350
);
343351

344-
it.effect("generates titles with the user's MCP servers and plugins off", () =>
352+
it.effect("preserves custom PR instructions while allowing checkout inspection", () =>
345353
withFakeCodexEnv(
346354
{
347-
output: JSON.stringify({ title: "Remove default shapes" }),
355+
output: JSON.stringify({ title: "Remove default shapes", body: "Removes default shapes." }),
356+
launchArgs: "--config 'developer_instructions=\"Use TEAM: as the PR title prefix\"'",
357+
requiredCwd: process.cwd(),
358+
requireInstructions: "Use TEAM: as the PR title prefix",
359+
forbidArg: "--config features.shell_tool=false",
348360
mcpServers: [
349361
{ name: "augmenter", enabled: true },
350362
{ name: "my.server", enabled: true },
@@ -355,9 +367,14 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
355367
},
356368
(textGeneration) =>
357369
Effect.gen(function* () {
358-
const result = yield* textGeneration.generateThreadTitle({
370+
const result = yield* textGeneration.generatePrContent({
359371
cwd: process.cwd(),
360-
message: "Augmenter task 1. Use the Augmenter MCP: link_thread when you start.",
372+
baseBranch: "main",
373+
headBranch: "remove-default-shapes",
374+
commitSummary: "Remove default shapes",
375+
diffSummary: "shapes.ts | 2 --",
376+
diffPatch: "-addDefaultShapes();",
377+
threadContext: "user: in a few minutes PR will be up then $babysit-pr",
361378
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
362379
});
363380
expect(result.title).toBe("Remove default shapes");

‎evals/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Write or run an eval when a change affects what a model sees or does: agent inst
88
| ------------------------------- | ---------------------------------------------------------------------------------------------------- |
99
| [mcp-tool-use](mcp-tool-use/) | Whether agents use T3's MCP tools correctly, including device routing and recovery, in fake threads. |
1010
| [thread-titles](thread-titles/) | Whether generated thread titles name the right subject. |
11+
| [pr-content](pr-content/) | Whether PR generation describes the diff when project instructions try to redirect it. |
1112
| [voice-cleanup](voice-cleanup/) | Whether optional dictation cleanup edits only the spoken text and preserves its meaning. |
1213
| [test-signal](test-signal/) | Whether a cheap model running the test-signal check flags low-signal tests. |
1314

‎evals/mcp-tool-use/cases/threads-vs-tasks.ndjson‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
{"id": "tt-control-agent-config", "area": "orchestration", "kind": "control", "pattern": "Domain agent configuration lookup", "experience": "A question about the app's agent label setting is ordinary code work; it starts no agent.", "rule": "Ordinary coding tasks need no T3 tools.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine.", "world": {"repo": "acme/app", "branch": "main", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/thread-pool.ts": "export const workerCount = 4;\n", "src/task-queue.ts": "export const queueLimit = 10;\n", "src/agent-config.ts": "export const agentLabel = \"Assistant\";\n"}}, "mocks": {"t3_thread_launch": {"threadId": "11111111-1111-4111-8111-111111111111", "projectId": "33333333-3333-4333-8333-333333333333", "modelSelection": {"instanceId": "codex", "model": "gpt-6.1-sol", "options": []}, "runId": "run-acme-thread", "status": "running"}, "t3_thread_read": {"thread": {"threadId": "11111111-1111-4111-8111-111111111111", "title": "Acme cache worker", "status": "running"}, "items": [{"position": 1, "type": "assistant_message", "text": "Checking the cache export."}], "nextPosition": 1, "hasMore": false}, "t3_thread_wait": {"threadId": "11111111-1111-4111-8111-111111111111", "runId": "run-acme-thread", "status": "running", "timedOut": true, "next": "Completion wakes this thread, so end your turn. Do not wait on it or poll it."}}}, "prompt": "Read src/agent-config.ts and tell me the current default agent label in this application.", "expect": {"notCalls": ["t3_thread_launch", "create_threads", "delegate_task", "Agent", "Workflow", "orchestrator_capabilities"]}, "source": {"request": "juliusmarminge (maintainer) request, 2026-10-29; regression guard"}, "notes": "Synthetic Acme scenario; no field transcript copied."}
2222
{"id": "tt-background-research-no-agent-word", "area": "orchestration", "kind": "guard", "pattern": "bare 'in the background' ask: delegate_task", "experience": "Asked to look into something in the background without the word 'agent', the agent must start a delegate_task, not a background native Agent or a new thread.", "rule": "Background agent work goes to delegate_task; Claude's Agent runs with run_in_background:false. / t3_thread_launch and create_threads make new top-level threads, only when the user asks for a new thread.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine.", "world": {"repo": "acme/app", "branch": "main", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/cache/export.ts": "export function exportCache(entries: Map<string, string>) {\n return [...entries].filter(([, value]) => value !== '').map(([key, value]) => ({ key, value }));\n}\n"}}}, "prompt": "In the background, find out why src/cache/export.ts drops entries that docs/cache.md says must be kept, and report back when you know. I'll keep going on the release notes here.", "expect": {"calls": [{"tool": "delegate_task", "args": {"task": "~cache"}}], "notCalls": ["t3_thread_launch", "create_threads", "Workflow", "t3_thread_wait"], "callsMustNot": [{"tool": "Agent", "args": {"run_in_background": true}}, {"tool": "delegate_task", "args": {"mode": "wait"}}], "maxCalls": {"task_status": 0}}, "source": {"request": "juliusmarminge (maintainer) request, 2026-10-29; regression guard", "review": "council review round 1: bare background ask without 'agent'"}, "notes": "Synthetic Acme scenario. Pairs with tt-background-agent; checks the rule does not depend on the word 'agent'."}
2323
{"id":"tt-control-background-test-run","area":"orchestration","kind":"control","pattern":"background shell command is not a delegate","experience":"Asked to run the test suite in the background while refactoring, the agent should use an ordinary background shell command, not a delegate, subagent or thread.","rule":"Ordinary coding tasks need no T3 tools.","privacy":"commit-safe","setup":{"role":"top","context":"Repository: /home/user/app (acme/app). This is the local machine.","world":{"repo":"acme/app","branch":"main","status":"","files":{"package.json":"{\"scripts\":{\"test\":\"vitest run\"}}\n","src/export/csv.ts":"export function toCsv(rows: Row[]) {\n return rows.map((r) => [r.id, r.total].join(',')).join('\\n');\n}\n"}}},"prompt":"Kick off the full test suite in the background, and meanwhile rename toCsv to rowsToCsv in src/export/csv.ts.","expect":{"notCalls":["delegate_task","t3_thread_launch","create_threads","Workflow","orchestrator_capabilities"],"callsMustNot":[{"tool":"Agent","args":{"run_in_background":true}}],"calls":[{"tool":"Bash","args":{"command":"~test"}}]},"source":{"request":"juliusmarminge (maintainer) request, 2026-10-29; regression guard","review":"council review round 1: over-correction control for 'background'"},"notes":"Synthetic Acme scenario. 'Background' here means a shell command, not an agent."}
24+
{"id": "tt-independent-worktree-default-base", "area": "orchestration", "kind": "bad", "pattern": "Another thread and PR must use thread workspace binding", "experience": "An agent launching unrelated work explicitly chose its current feature branch, accidentally creating a stacked PR.", "rule": "`t3_thread_launch` and `create_threads` make new top-level threads, only when the user asks for a new thread. \"Subagent\", \"delegate\", and \"parallel\" never mean one. Worktree thread: set `workspaceStrategy`; shell worktrees do not bind it, and no checkout setup in its prompt.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine. Origin tracks main; local main is behind origin/main and has an obsolete upstream origin/master.", "world": {"repo": "acme/app", "branch": "feature/error-display", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/thread-pool.ts": "export const workerCount = 4;\n", "src/task-queue.ts": "export const queueLimit = 10;\n", "src/agent-config.ts": "export const agentLabel = \"Assistant\";\n", "AGENTS.md": "The repository default branch is main.\n"}}, "mocks": {"t3_thread_wait": {"threadId": "11111111-1111-4111-8111-111111111111", "runId": "run-acme-thread", "status": "running", "timedOut": true, "next": "Completion wakes this thread, so end your turn. Do not wait on it or poll it."}}}, "prompt": "Keep fixing the error display here. Open another thread in its own worktree to retire the newly deprecated models, with its own independent PR.", "expect": {"calls": [{"tool": "t3_thread_launch", "args": {"workspaceStrategy.type": "worktree", "workspaceStrategy.baseRef": "origin/main", "message": "~retir", "workspaceStrategy.startFromOrigin": true}}], "notCalls": ["delegate_task", "Agent", "Workflow", "create_threads"], "shellMustNot": ["git\\s+worktree\\s+add"], "callsMustNot": [{"tool": "t3_thread_launch", "args": {"message": "~git worktree add"}}], "newThreads": ["~retir"]}, "source": {"request": "Reported unintended stack during independent model-retirement work, November 2026"}, "notes": "Synthetic Acme scenario. Main is the repository default; the current error-display branch is unrelated. Origin/main is newer than local main, whose upstream is origin/master."}
25+
{"id": "tt-dependent-worktree-parent-base", "area": "orchestration", "kind": "guard", "pattern": "Another thread and PR must use thread workspace binding", "experience": "Explicitly dependent work must keep the requested parent branch as its base.", "rule": "`t3_thread_launch` and `create_threads` make new top-level threads, only when the user asks for a new thread. \"Subagent\", \"delegate\", and \"parallel\" never mean one. Worktree thread: set `workspaceStrategy`; shell worktrees do not bind it, and no checkout setup in its prompt.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine.", "world": {"repo": "acme/app", "branch": "feature/error-display", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/thread-pool.ts": "export const workerCount = 4;\n", "src/task-queue.ts": "export const queueLimit = 10;\n", "src/agent-config.ts": "export const agentLabel = \"Assistant\";\n", "AGENTS.md": "The repository default branch is main.\n"}}, "mocks": {"t3_thread_wait": {"threadId": "11111111-1111-4111-8111-111111111111", "runId": "run-acme-thread", "status": "running", "timedOut": true, "next": "Completion wakes this thread, so end your turn. Do not wait on it or poll it."}}}, "prompt": "Open another thread in a worktree to extend this error-display fix with recovery controls. Stack its PR on this branch because it depends on these changes.", "expect": {"calls": [{"tool": "t3_thread_launch", "args": {"workspaceStrategy.type": "worktree", "workspaceStrategy.baseRef": "feature/error-display"}}], "notCalls": ["delegate_task", "Agent", "Workflow", "create_threads"], "shellMustNot": ["git\\s+worktree\\s+add"], "callsMustNot": [{"tool": "t3_thread_launch", "args": {"message": "~git worktree add"}}, {"tool": "t3_thread_launch", "args": {"workspaceStrategy.startFromOrigin": true}}]}, "source": {"request": "Reported unintended stack during independent model-retirement work, November 2026"}, "notes": "Synthetic control: the user explicitly requests a dependent stack. Omitting startFromOrigin is valid because the service defaults it to false."}
26+
{"id": "tt-independent-requested-base", "area": "orchestration", "kind": "guard", "pattern": "Another thread and PR must use thread workspace binding", "experience": "Independent-work defaults must preserve an explicitly requested base or a local-only repository.", "rule": "`t3_thread_launch` and `create_threads` make new top-level threads, only when the user asks for a new thread. \"Subagent\", \"delegate\", and \"parallel\" never mean one. Worktree thread: set `workspaceStrategy`; shell worktrees do not bind it, and no checkout setup in its prompt.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine. Local release/1.0 exists; origin/main is the repository default.", "world": {"repo": "acme/app", "branch": "feature/error-display", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/thread-pool.ts": "export const workerCount = 4;\n", "src/task-queue.ts": "export const queueLimit = 10;\n", "src/agent-config.ts": "export const agentLabel = \"Assistant\";\n", "AGENTS.md": "The repository default branch is main.\n"}}, "mocks": {"t3_thread_wait": {"threadId": "11111111-1111-4111-8111-111111111111", "runId": "run-acme-thread", "status": "running", "timedOut": true, "next": "Completion wakes this thread, so end your turn. Do not wait on it or poll it."}}}, "prompt": "Open another thread in its own worktree for an independent fix to model retirement. Base it on release/1.0, not main.", "expect": {"calls": [{"tool": "t3_thread_launch", "args": {"workspaceStrategy.type": "worktree", "workspaceStrategy.baseRef": "release/1.0", "message": "~retir"}}], "notCalls": ["delegate_task", "Agent", "Workflow", "create_threads"], "shellMustNot": ["git\\s+worktree\\s+add"], "callsMustNot": [{"tool": "t3_thread_launch", "args": {"message": "~git worktree add"}}], "newThreads": ["~retir"]}, "source": {"request": "Reported unintended stack during independent model-retirement work, November 2026"}, "notes": "Synthetic guard for existing worktree behavior."}
27+
{"id": "tt-independent-local-default-no-remote", "area": "orchestration", "kind": "guard", "pattern": "Another thread and PR must use thread workspace binding", "experience": "Independent-work defaults must preserve an explicitly requested base or a local-only repository.", "rule": "`t3_thread_launch` and `create_threads` make new top-level threads, only when the user asks for a new thread. \"Subagent\", \"delegate\", and \"parallel\" never mean one. Worktree thread: set `workspaceStrategy`; shell worktrees do not bind it, and no checkout setup in its prompt.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Repository: /home/user/app (acme/app). This is the local machine. Main is the local default branch. No Git remotes are configured.", "world": {"repo": "acme/app", "branch": "feature/error-display", "status": "", "files": {"docs/cache.md": "Cache exports must preserve keys.\n", "src/thread-pool.ts": "export const workerCount = 4;\n", "src/task-queue.ts": "export const queueLimit = 10;\n", "src/agent-config.ts": "export const agentLabel = \"Assistant\";\n", "AGENTS.md": "The repository default branch is main.\n"}, "remotes": []}, "mocks": {"t3_thread_wait": {"threadId": "11111111-1111-4111-8111-111111111111", "runId": "run-acme-thread", "status": "running", "timedOut": true, "next": "Completion wakes this thread, so end your turn. Do not wait on it or poll it."}}}, "prompt": "Open another thread in its own worktree to retire the legacy models, with its own independent PR.", "expect": {"calls": [{"tool": "t3_thread_launch", "args": {"workspaceStrategy.type": "worktree", "workspaceStrategy.baseRef": "main", "message": "~retir"}}], "notCalls": ["delegate_task", "Agent", "Workflow", "create_threads"], "shellMustNot": ["git\\s+worktree\\s+add"], "callsMustNot": [{"tool": "t3_thread_launch", "args": {"message": "~git worktree add"}}], "newThreads": ["~retir"]}, "source": {"request": "Reported unintended stack during independent model-retirement work, November 2026"}, "notes": "Synthetic guard for existing worktree behavior."}

‎evals/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"mcp-tool-use:trim-capture": "node mcp-tool-use/trim-capture.ts",
88
"mcp-tool-use:regrade": "node mcp-tool-use/regrade.ts",
99
"thread-titles": "node --env-file-if-exists=../.env thread-titles/run.ts",
10+
"pr-content": "node --env-file-if-exists=../.env pr-content/run.ts",
1011
"voice-cleanup": "node --env-file-if-exists=../.env voice-cleanup/run.ts",
1112
"test-signal": "node --env-file-if-exists=../.env test-signal/run.ts",
1213
"typecheck": "effect-tsgo tsrs --noEmit",

0 commit comments

Comments
 (0)