Skip to content

Commit cc9b074

Browse files
fix(server): ci_logs reads at most five logs unless a check is named
The rest come back unread with a note to ask by name, so many failing checks cannot flood the agent's context. The eval runner also refuses CI tools when the branch has no PR yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2b6b28d commit cc9b074

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ it.effect(
12651265
() =>
12661266
Effect.gen(function* () {
12671267
const asked: Array<ReadonlyArray<string>> = [];
1268+
let failing = 0;
12681269
const check = (name: string, status: "success" | "failure" | "cancelled") => ({
12691270
name,
12701271
status,
@@ -1284,6 +1285,9 @@ it.effect(
12841285
check("Lint", "success"),
12851286
check("Test", "failure"),
12861287
check("E2E", "cancelled"),
1288+
...Array.from({ length: failing }, (_, index) =>
1289+
check(`Shard ${index}`, "failure"),
1290+
),
12871291
],
12881292
}),
12891293
getCheckLogs: (input) =>
@@ -1302,6 +1306,17 @@ it.effect(
13021306
);
13031307
assert.deepStrictEqual(asked, [["Test", "E2E"], ["Lint"]]);
13041308
assert.include(missing.message, "Lint, Test, E2E");
1309+
1310+
failing = 6;
1311+
asked.length = 0;
1312+
const many = yield* service.checkLogs({ ...reference, tailLines: 50 });
1313+
// The host is asked for five; the other three come back unread, by name.
1314+
assert.lengthOf(asked[0] ?? [], 5);
1315+
assert.deepStrictEqual(
1316+
many.map((log) => log.name),
1317+
["Shard 3", "Shard 4", "Shard 5"],
1318+
);
1319+
assert.include(many[0]?.detail ?? "", "Ask for this check by name");
13051320
}),
13061321
);
13071322

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,6 +3728,7 @@ export const make = Effect.gen(function* () {
37283728
return matches.map(({ name, url }) => ({ name, url }));
37293729
});
37303730

3731+
const DEFAULT_CHECK_LOGS = 5;
37313732
const checkLogs: PullRequestService["Service"]["checkLogs"] = Effect.fn(
37323733
"PullRequestService.checkLogs",
37333734
)(function* (input) {
@@ -3741,13 +3742,27 @@ export const make = Effect.gen(function* () {
37413742
}
37423743
const checks = yield* selectChecks(project, input, "checkLogs");
37433744
if (checks.length === 0) return [];
3744-
return yield* read({
3745+
// Many failing checks would flood the agent's context; the rest stay a name away.
3746+
const [shown, rest] =
3747+
input.check === undefined
3748+
? [checks.slice(0, DEFAULT_CHECK_LOGS), checks.slice(DEFAULT_CHECK_LOGS)]
3749+
: [checks, []];
3750+
const logs = yield* read({
37453751
cwd: project.project.workspaceRoot,
37463752
repository: project.repository,
37473753
host: project.host,
3748-
checks,
3754+
checks: shown,
37493755
tailLines: input.tailLines,
37503756
}).pipe(Effect.mapError(toPullRequestError("checkLogs")));
3757+
return [
3758+
...logs,
3759+
...rest.map((check) => ({
3760+
...check,
3761+
log: null,
3762+
truncated: false,
3763+
detail: "Not read, to keep the reply short. Ask for this check by name.",
3764+
})),
3765+
];
37513766
});
37523767

37533768
const rerunChecks: PullRequestService["Service"]["rerunChecks"] = Effect.fn(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,8 @@ it.effect("reads the branch's PR only once the agent has opened it", () =>
981981
input,
982982
});
983983
assert.isTrue((yield* call("a", "pull_request_read", {})).is_error);
984+
sample.tools.push({ name: "mcp__t3-code__ci_logs" });
985+
assert.isTrue((yield* call("a2", "ci_logs", {})).is_error);
984986
yield* call("b", "pull_request_create", { title: "Feature", body: "Body" });
985987
assert.isNotTrue((yield* call("c", "pull_request_read", {})).is_error);
986988

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,8 @@ const BRANCH_PULL_REQUEST_TOOLS = new Set([
15801580
"pull_request_update",
15811581
"pull_request_respond",
15821582
"pull_request_merge",
1583+
"ci_logs",
1584+
"ci_rerun",
15831585
]);
15841586
const BRANCH_HAS_NO_PR_ERROR =
15851587
"This thread's branch has no known PR. Pass number, or open one with pull_request_create.";
@@ -1836,17 +1838,17 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun
18361838
if (name === "watch_pull_request" && testCase.setup.role === "delegated-child") {
18371839
return failed(SUBAGENT_WATCH_ERROR);
18381840
}
1841+
if (BRANCH_PULL_REQUEST_TOOLS.has(name) && input.number === undefined) {
1842+
// Until the agent opens it, the PR a create would open does not exist.
1843+
if (branchPullRequest(sample).created) return failed(BRANCH_HAS_NO_PR_ERROR);
1844+
}
18391845
if (name === "ci_logs" || name === "ci_rerun") {
18401846
const { all, checks, named } = selectedWorldChecks(sample, input);
18411847
if (named !== null && checks.length === 0) {
18421848
const names = all.map((check) => valueText(check.name)).join(", ") || "none";
18431849
return failed(`No check is named ${valueText(input.check)}. Checks: ${names}.`);
18441850
}
18451851
}
1846-
if (BRANCH_PULL_REQUEST_TOOLS.has(name) && input.number === undefined) {
1847-
// Until the agent opens it, the PR a create would open does not exist.
1848-
if (branchPullRequest(sample).created) return failed(BRANCH_HAS_NO_PR_ERROR);
1849-
}
18501852
const value = t3Default(sample, name, input);
18511853
if (name === "request_secret") savedSecretFile(sample, value);
18521854
return toolResult(

0 commit comments

Comments
 (0)