feat(server): agents read failing CI logs and re-run checks through MCP tools #26752
Mergedjuliusmarmingemerged 17 commits into
t3/source-control-mcp-tools fromrefs/pull/26752/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/client-runtime/src/t3ToolSummary.ts line 466OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -459,3 +459,8 @@459459 case "merge-pr":460460 label = phrase("Merged", "merge", quantity(selected.length, "pull request"));461461 break;462+ case "ci-logs":463+ label = phrase("Read", "read", `CI logs ${times}`);464+ break;465+ case "ci-rerun":466+ label = phrase("Re-ran", "re-run", `CI ${times}`);packages/source-control-github/src/server/GitHubPullRequestApi.ts lines 2646 to 2650OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2592,0 +2630,21 @@2630+ ...check,2631+ log: null,2632+ truncated: false,2633+ detail: "This check is not a GitHub Actions job, so GitHub holds no log for it.",2634+ });2635+ }2636+ // The log is a redirect to storage; fetch drops the credential when it leaves GitHub.2637+ return api2638+ .rest({2639+ host: input.host,2640+ operation: "readCheckLog",2641+ path: `repos/${owner}/${name}/actions/jobs/${jobId}/logs`,2642+ maxResponseBytes: CHECK_LOG_MAX_BYTES,2643+ timeout: "60 seconds",2644+ })2645+ .pipe(2646+ Effect.map((response) => ({2647+ ...check,2648+ ...tailLogLines(response.body, input.tailLines),2649+ detail: response.truncated ? "The log is too large; this is from its start." : null,2650+ })),
- apps/server/src/provider/agentContextBudget.json line 4OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1,4 +1,4 @@11 {22 "claudeSystemAppendBytes": 5135,33 "codexAdditionalContextBytes": 6865,4- "mcpToolListJsonBytes": 487224+ "mcpToolListJsonBytes": 49478apps/server/src/pullRequest/PullRequestService.ts lines 3611 to 3612OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3521,0 +3592,21 @@3592+ const rerunChecks: PullRequestService["Service"]["rerunChecks"] = Effect.fn(3593+ "PullRequestService.rerunChecks",3594+ )(function* (input) {3595+ const project = yield* requireProject(input);3596+ const rerun = project.api.rerunChecks;3597+ if (rerun === undefined) {3598+ return yield* new PullRequestOperationError({3599+ operation: "rerunChecks",3600+ detail: "This host cannot re-run checks.",3601+ });3602+ }3603+ const checks = yield* selectChecks(project, input, "rerunChecks");3604+ if (checks.length === 0) return [];3605+ const outcomes = yield* rerun({3606+ cwd: project.project.workspaceRoot,3607+ repository: project.repository,3608+ host: project.host,3609+ checks,3610+ }).pipe(Effect.mapError(toPullRequestError("rerunChecks")));3611+ yield* readCache.invalidate(refScope(yield* canonicalRef(input)));3612+ return outcomes;packages/source-control-github/src/server/GitHubPullRequestApi.ts lines 2651 to 2653OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2592,0 +2633,21 @@2633+ detail: "This check is not a GitHub Actions job, so GitHub holds no log for it.",2634+ });2635+ }2636+ // The log is a redirect to storage; fetch drops the credential when it leaves GitHub.2637+ return api2638+ .rest({2639+ host: input.host,2640+ operation: "readCheckLog",2641+ path: `repos/${owner}/${name}/actions/jobs/${jobId}/logs`,2642+ maxResponseBytes: CHECK_LOG_MAX_BYTES,2643+ timeout: "60 seconds",2644+ })2645+ .pipe(2646+ Effect.map((response) => ({2647+ ...check,2648+ ...tailLogLines(response.body, input.tailLines),2649+ detail: response.truncated ? "The log is too large; this is from its start." : null,2650+ })),2651+ Effect.catch((error) =>2652+ Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),2653+ ),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge added labelsagent-context-increase
- apps/server/src/pullRequest/PullRequestService.ts lines 3776 to 3778OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3682,0 +3758,21 @@3758+ if (rerun === undefined) {3759+ return yield* new PullRequestOperationError({3760+ operation: "rerunChecks",3761+ detail: "This host cannot re-run checks.",3762+ });3763+ }3764+ const checks = yield* selectChecks(project, input, "rerunChecks");3765+ if (checks.length === 0) return [];3766+ const ref = yield* canonicalRef(input);3767+ const outcomes = yield* rerun({3768+ cwd: project.project.workspaceRoot,3769+ repository: project.repository,3770+ host: project.host,3771+ checks,3772+ }).pipe(3773+ Effect.mapError(toPullRequestError("rerunChecks")),3774+ Effect.ensuring(readCache.invalidate(refScope(ref))),3775+ );3776+ bumpRefEpoch(ref);3777+ listingsEpoch = ++epochCounter;3778+ yield* SubscriptionRef.set(pullRequestRefreshes, listingsEpoch);evals/mcp-tool-use/run.ts line 1344OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1334,3 +1334,11 @@13341334 ...pullRequest(sample.repo, { number: input.number ?? branchPullRequest(sample).number }),13351335 state: input.auto === true ? "open" : "merged",13361336 };1337+ case "ci_logs":1338+ case "ci_rerun": {1339+ const number =1340+ typeof input.number === "number" ? input.number : branchPullRequest(sample).number;1341+ const world = worldPullRequests(sample).find((pr) => Number(pr.number) === number);1342+ const checks = (Array.isArray(world?.checks) ? world.checks.filter(isRecord) : []).filter(1343+ (check) =>1344+ typeof input.check === "string" ? check.name === input.check : check.state === "fail",packages/client-runtime/src/t3ToolSummary.ts lines 520 to 521OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -504,3 +504,18 @@504504 );505505 break;506506 }507+ case "ci-logs":508+ label = phrase("Read", "read", `CI logs ${times}`);509+ break;510+ case "ci-rerun": {511+ // A host can refuse a check it cannot re-run, such as one outside its CI.512+ const outcomes = selected.flatMap((call) =>513+ Array.isArray(call.output?.checks)514+ ? call.output.checks.map((check) => asRecord(check)?.rerun === true)515+ : [],516+ );517+ const rerun = outcomes.filter(Boolean).length;518+ const refused = outcomes.length - rerun;519+ failedCount += refused;520+ if (outcomes.length === 0) {521+ label = phrase("Re-ran", "re-run", `CI ${times}`);packages/source-control-core/src/server/PullRequestProvider.ts line 217OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -190,0 +197,21 @@197+export interface ProviderCheckLog {198+ readonly name: string;199+ readonly url: string | null;200+ /** Null when the host holds no log for this check; `detail` says why. */201+ readonly log: string | null;202+ readonly truncated: boolean;203+ readonly detail: string | null;204+}205+206+export interface ProviderCheckRerun {207+ readonly name: string;208+ readonly rerun: boolean;209+ readonly detail: string | null;210+}211+212+/** The job id of a GitHub Actions check run, from its run link or its job link. */213+export function gitHubActionsJobId(url: string | null): string | null {214+ if (url === null) return null;215+ return (216+ /\/actions\/runs\/\d+\/job\/(\d+)(?:[/?#]|$)/.exec(url)?.[1] ??217+ /^https:\/\/[^/]+\/[^/]+\/[^/]+\/runs\/(\d+)(?:[/?#]|$)/.exec(url)?.[1] ??packages/source-control-core/src/server/PullRequestProvider.ts lines 227 to 230OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -190,0 +210,21 @@210+}211+212+/** The job id of a GitHub Actions check run, from its run link or its job link. */213+export function gitHubActionsJobId(url: string | null): string | null {214+ if (url === null) return null;215+ return (216+ /\/actions\/runs\/\d+\/job\/(\d+)(?:[/?#]|$)/.exec(url)?.[1] ??217+ /^https:\/\/[^/]+\/[^/]+\/[^/]+\/runs\/(\d+)(?:[/?#]|$)/.exec(url)?.[1] ??218+ null219+ );220+}221+222+/** The last `lines` lines of a log, where a failure usually is. */223+export function tailLogLines(224+ text: string,225+ lines: number,226+): { readonly log: string; readonly truncated: boolean } {227+ const all = text.replace(/\n$/, "").split("\n");228+ return all.length <= lines229+ ? { log: all.join("\n"), truncated: false }230+ : { log: all.slice(-lines).join("\n"), truncated: true };packages/source-control-github/src/server/GitHubPullRequestApi.ts lines 2838 to 2840OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2719,0 +2820,21 @@2820+ { concurrency: 4 },2821+ );2822+ // GitHub refuses a second job re-run while the run re-runs, so a run's failed jobs go together.2823+ const byRun = new Map<number, Array<LocatedCheckJob>>();2824+ for (const entry of located) {2825+ if (entry.runId === null) continue;2826+ byRun.set(entry.runId, [...(byRun.get(entry.runId) ?? []), entry]);2827+ }2828+ const outcomes = new Map<number, string | null>();2829+ yield* Effect.forEach(2830+ byRun,2831+ ([runId, jobs]) =>2832+ api2833+ .rest({2834+ host: input.host,2835+ operation: "rerunChecks",2836+ method: "POST",2837+ path:2838+ jobs.length === 12839+ ? `${root}/jobs/${jobs[0]!.jobId}/rerun`2840+ : `${root}/runs/${runId}/rerun-failed-jobs`,
- packages/source-control-github/src/server/GitHubPullRequestApi.ts line 2854OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2719,0 +2833,21 @@2833+ );2834+ // GitHub refuses a second job re-run while the run re-runs, so a run's jobs go together.2835+ const byRun = new Map<number, Array<LocatedCheckJob>>();2836+ for (const entry of located) {2837+ if (entry.runId === null) continue;2838+ byRun.set(entry.runId, [...(byRun.get(entry.runId) ?? []), entry]);2839+ }2840+ const post = (path: string) =>2841+ api.rest({ host: input.host, operation: "rerunChecks", method: "POST", path }).pipe(2842+ Effect.as<string | null>(null),2843+ Effect.catchTags({2844+ GitHubApiNotFoundError: (error) => Effect.succeed(error.message),2845+ GitHubApiResponseError: (error) => Effect.succeed(error.message),2846+ }),2847+ );2848+ const failedJobsOf = (runId: number) =>2849+ api2850+ .rest({2851+ host: input.host,2852+ operation: "readRunJobs",2853+ path: `${root}/runs/${runId}/jobs?filter=latest&per_page=100`,evals/mcp-tool-use/run.ts line 1354OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1344,3 +1344,11 @@13441344 ...pullRequest(sample.repo, { number: input.number ?? branchPullRequest(sample).number }),13451345 state: input.auto === true ? "open" : "merged",13461346 };1347+ case "ci_logs":1348+ case "ci_rerun": {1349+ const number =1350+ typeof input.number === "number" ? input.number : branchPullRequest(sample).number;1351+ const world = worldPullRequests(sample).find((pr) => Number(pr.number) === number);1352+ // Selects as PullRequestService does: a name ignoring case, else every failed check.1353+ const named = typeof input.check === "string" ? input.check.trim().toLowerCase() : null;1354+ const checks = (Array.isArray(world?.checks) ? world.checks.filter(isRecord) : []).filter(
- apps/server/src/pullRequest/PullRequestService.ts lines 3717 to 3719OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3682,0 +3699,21 @@3699+ const selectChecks = Effect.fn("PullRequestService.selectChecks")(function* (3700+ project: SupportedProject,3701+ input: PullRequestRef & { readonly check?: string },3702+ operation: string,3703+ ) {3704+ const ref = {3705+ cwd: project.project.workspaceRoot,3706+ repository: project.repository,3707+ host: project.host,3708+ number: input.number,3709+ };3710+ const { checks } = yield* (3711+ project.api.getChangeRequestChecks === undefined3712+ ? project.api.getChangeRequest(ref)3713+ : project.api.getChangeRequestChecks(ref)3714+ ).pipe(Effect.mapError(toPullRequestError(operation)));3715+ const named = input.check?.trim().toLowerCase();3716+ if (named === undefined) {3717+ return checks3718+ .filter((check) => check.status === "failure" || check.status === "cancelled")3719+ .map(({ name, url }) => ({ name, url }));evals/mcp-tool-use/run.ts lines 1856 to 1857OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1804,3 +1836,5 @@18041836 if (name === "watch_pull_request" && testCase.setup.role === "delegated-child") {18051837 return failed(SUBAGENT_WATCH_ERROR);18061838 }1839+ if (name === "ci_logs" || name === "ci_rerun") {1840+ const { all, checks, named } = selectedWorldChecks(sample, input);
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
tanstack-source added labelsfeature
- evals/mcp-tool-use/run.ts line 1303OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1248,3 +1288,16 @@12481288 };12491289 }12501290 case "pull_request_create": {1291+ const checkedOut = checkedOutBranch(sample);1292+ if (checkedOut !== sample.testCase.setup.world?.branch) {1293+ // Another layer of a stack: its own PR, opened once per branch like the real tool.1294+ const known = worldPullRequests(sample).find((pr) => pr.headRefName === checkedOut);1295+ const opened = sample.openedByBranch.get(checkedOut);1296+ const number =1297+ known !== undefined1298+ ? Number(known.number)1299+ : (opened ??1300+ Math.max(1301+ branchPullRequest(sample).number,1302+ ...sample.openedByBranch.values(),1303+ ...[...sample.linked].map((url) => Number(/\/pull\/(\d+)/.exec(url)?.[1]) || 0),
- evals/mcp-tool-use/run.ts line 1306OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1248,3 +1288,19 @@12481288 };12491289 }12501290 case "pull_request_create": {1291+ const checkedOut = checkedOutBranch(sample);1292+ if (checkedOut !== sample.testCase.setup.world?.branch) {1293+ // Another layer of a stack: its own PR, opened once per branch like the real tool.1294+ const known = worldPullRequests(sample).find((pr) => pr.headRefName === checkedOut);1295+ const opened = sample.openedByBranch.get(checkedOut);1296+ const number =1297+ known !== undefined1298+ ? Number(known.number)1299+ : (opened ??1300+ Math.max(1301+ branchPullRequest(sample).number,1302+ ...sample.openedByBranch.values(),1303+ ...worldPullRequests(sample).map((pr) => Number(pr.number) || 0),1304+ ...[...sample.linked].map((url) => Number(/\/pull\/(\d+)/.exec(url)?.[1]) || 0),1305+ ) + 1);1306+ sample.openedByBranch.set(checkedOut, number);
- @@ -857,3 +857,15 @@857857 .map((url) => Number(/\/pull\/(\d+)/.exec(url)?.[1]))858858 .find((number) => number > 0);859859 };860+/** The branch the agent last checked out or switched to in the shell, else the world's. */861+const checkedOutBranch = (sample: Sample) => {862+ let branch = sample.testCase.setup.world?.branch ?? "";863+ for (const entry of sample.shell) {864+ const command = isRecord(entry.input) ? valueText(entry.input.command) : "";865+ for (const part of command.replace(/\s\d?>&\d/g, "").split(/[;&|\n]+/)) {866+ // `git checkout <ref> -- <paths>` restores files and stays on the branch.867+ if (/\s--(\s|$)/.test(part)) continue;868+ const match = /\bgit (?:checkout|switch)\s+(?:-[bcBC]\s+)?([A-Za-z0-9][\w./-]*)\s*$/.exec(869+ part.trim(),870+ );871+ if (match !== null) branch = match[1]!;
- @@ -1107,0 +1109,21 @@1109+ Effect.gen(function* () {1110+ const { target, ref } = yield* locate(input);1111+ const checks = yield* pullRequests1112+ .checkLogs({1113+ ...ref,1114+ tailLines: input.tailLines ?? 200,1115+ ...(input.check === undefined ? {} : { check: input.check }),1116+ })1117+ .pipe(Effect.mapError(forgeFailure));1118+ return { ...identityOf(target), checks };1119+ }),1120+ ),1121+ ci_rerun: McpToolAccess.writesWithCapability((input) =>1122+ Effect.gen(function* () {1123+ const { thread, target, ref } = yield* locate(input);1124+ const checks = yield* pullRequests1125+ .rerunChecks({ ...ref, ...(input.check === undefined ? {} : { check: input.check }) })1126+ .pipe(Effect.mapError(forgeFailure));1127+ // Like a push, a rerun makes a watch's finished checks stale, so the thread keeps working1128+ // until a read sees them run. The rerun already happened, so a failed reopen only logs.1129+ if (
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed