Skip to content

Commit 6969801

Browse files
fix(server): CI tools keep sign-in failures, refresh checks after a rerun, and count reruns
- A check log or rerun fails the call on sign-in and rate-limit errors instead of reporting them per check. - A byte-capped GitHub log reports itself truncated. - A rerun refreshes cached checks and notifies readers, like other PR mutations. - The rerun summary counts the checks the host restarted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 956fbf3 commit 6969801

9 files changed

Lines changed: 155 additions & 27 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,40 @@ it.effect(
13051305
}),
13061306
);
13071307

1308+
it.effect("re-reads checks after a rerun instead of serving the failed ones", () =>
1309+
Effect.gen(function* () {
1310+
let rerun = false;
1311+
const service = yield* makeService({
1312+
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
1313+
providers: [
1314+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
1315+
getChangeRequestChecks: () =>
1316+
Effect.succeed({
1317+
state: "open" as const,
1318+
checks: [
1319+
{
1320+
name: "Test",
1321+
status: rerun ? ("pending" as const) : ("failure" as const),
1322+
description: null,
1323+
url: null,
1324+
},
1325+
],
1326+
}),
1327+
rerunChecks: (input) =>
1328+
Effect.sync(() => {
1329+
rerun = true;
1330+
return input.checks.map((check) => ({ ...check, rerun: true, detail: null }));
1331+
}),
1332+
}),
1333+
],
1334+
});
1335+
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
1336+
assert.equal((yield* service.checks(reference))?.checks[0]?.status, "failure");
1337+
yield* service.rerunChecks(reference);
1338+
assert.equal((yield* service.checks(reference))?.checks[0]?.status, "pending");
1339+
}),
1340+
);
1341+
13081342
it.effect("refuses a merge whose head moved past expectedHeadSha and pins the host merge", () =>
13091343
Effect.gen(function* () {
13101344
const pinned: Array<string | undefined> = [];

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,13 +3763,19 @@ export const make = Effect.gen(function* () {
37633763
}
37643764
const checks = yield* selectChecks(project, input, "rerunChecks");
37653765
if (checks.length === 0) return [];
3766+
const ref = yield* canonicalRef(input);
37663767
const outcomes = yield* rerun({
37673768
cwd: project.project.workspaceRoot,
37683769
repository: project.repository,
37693770
host: project.host,
37703771
checks,
3771-
}).pipe(Effect.mapError(toPullRequestError("rerunChecks")));
3772-
yield* readCache.invalidate(refScope(yield* canonicalRef(input)));
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);
37733779
return outcomes;
37743780
});
37753781

‎packages/client-runtime/src/t3ToolSummary.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ describe("summarizeT3ToolCalls", () => {
7676
).toBe("Merged 1 pull request, queued 1");
7777
});
7878

79+
it("counts the checks a CI rerun restarted, and the ones the host refused", () => {
80+
const rerun = (...outcomes: boolean[]) =>
81+
completed(
82+
{},
83+
{ checks: outcomes.map((outcome, index) => ({ name: `c${index}`, rerun: outcome })) },
84+
);
85+
expect(summarizeT3ToolCalls("ci-rerun", [rerun(true, true)])).toEqual({
86+
label: "Re-ran 2 checks",
87+
failedCount: 0,
88+
});
89+
expect(summarizeT3ToolCalls("ci-rerun", [rerun(true, false)])).toEqual({
90+
label: "Re-ran 1 check, 1 refused",
91+
failedCount: 1,
92+
});
93+
expect(summarizeT3ToolCalls("ci-rerun", [rerun(false)])).toEqual({
94+
label: "Could not re-run 1 check",
95+
failedCount: 1,
96+
});
97+
});
98+
7999
it("excludes failed and unfinished sends even if the provider reports completed", () => {
80100
const calls: T3ToolSummaryCall[] = [
81101
completed({ threadId: "success" }, { messageId: "ok", threadId: "success" }),

‎packages/client-runtime/src/t3ToolSummary.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,29 @@ export function summarizeT3ToolCalls(
507507
case "ci-logs":
508508
label = phrase("Read", "read", `CI logs ${times}`);
509509
break;
510-
case "ci-rerun":
511-
label = phrase("Re-ran", "re-run", `CI ${times}`);
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}`);
522+
} else if (rerun === 0) {
523+
label = `Could not re-run ${quantity(refused, "check")}`;
524+
} else {
525+
label = phrase(
526+
"Re-ran",
527+
"re-run",
528+
`${quantity(rerun, "check")}${refused > 0 ? `, ${refused} refused` : ""}`,
529+
);
530+
}
512531
break;
532+
}
513533
case "browser":
514534
label = phrase("Used", "use", `browser ${times}`);
515535
break;

‎packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,25 @@ describe("GitCafePullRequestProvider", () => {
684684
truncated: true,
685685
},
686686
"POST /repos/owner/repo/actions/runs/actwfrun_abc/rerun": {},
687+
"GET /repos/owner/repo/ci/github/checks/401/log": new Response("{}", { status: 401 }),
687688
});
688689
const mirrored = { name: "Test", url: "https://github.com/owner/repo/runs/555" };
690+
const missing = { name: "Gone", url: "https://github.com/owner/repo/runs/404" };
691+
const signedOut = { name: "Lint", url: "https://github.com/owner/repo/runs/401" };
689692
const native = { name: "Build", url: "https://git.cafe/owner/repo/actions/runs/actwfrun_abc" };
690693
return Effect.gen(function* () {
691694
const provider = yield* GitCafePullRequestProvider.make;
692-
const logs = yield* provider.getCheckLogs!({ ...target, checks: [mirrored], tailLines: 1 });
695+
const logs = yield* provider.getCheckLogs!({
696+
...target,
697+
checks: [mirrored, missing],
698+
tailLines: 1,
699+
});
693700
assert.deepInclude(logs[0], { log: "FAIL a.test.ts", truncated: true, detail: null });
701+
assert.isNotNull(logs[1]?.detail);
702+
const refused = yield* Effect.flip(
703+
provider.getCheckLogs!({ ...target, checks: [signedOut], tailLines: 1 }),
704+
);
705+
assert.strictEqual(refused.reason, "unauthenticated");
694706
const reruns = yield* provider.rerunChecks!({ ...target, checks: [mirrored, native] });
695707
assert.deepStrictEqual(
696708
reruns.map(({ name, rerun }) => [name, rerun]),

‎packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ export const make = Effect.gen(function* () {
458458
),
459459
);
460460

461+
const isCheckFailure = (error: PullRequestProviderError) =>
462+
error.reason === "not-found" || error.reason === "forbidden" || error.reason === "failed";
463+
461464
const isForbidden = (error: PullRequestProviderError) =>
462465
isApiError(error.cause) && error.cause.status === 403;
463466

@@ -1140,7 +1143,7 @@ export const make = Effect.gen(function* () {
11401143
const base = yield* repositoryPath("getCheckLogs", input);
11411144
return yield* Effect.forEach(
11421145
input.checks,
1143-
(check): Effect.Effect<ProviderCheckLog> => {
1146+
(check): Effect.Effect<ProviderCheckLog, PullRequestProviderError> => {
11441147
// GitCafe reads the log of a check its GitHub mirror ran.
11451148
const checkId = gitHubActionsJobId(check.url);
11461149
if (checkId === null) {
@@ -1166,7 +1169,8 @@ export const make = Effect.gen(function* () {
11661169
detail: null,
11671170
};
11681171
}),
1169-
Effect.catch((error) =>
1172+
// Sign-in and rate-limit failures fail the call; the rest are this check's.
1173+
Effect.catchIf(isCheckFailure, (error) =>
11701174
Effect.succeed({ ...check, log: null, truncated: false, detail: error.detail }),
11711175
),
11721176
);
@@ -1190,8 +1194,8 @@ export const make = Effect.gen(function* () {
11901194
method: "POST",
11911195
path: `${base}/actions/runs/${runId}/rerun`,
11921196
}).pipe(
1193-
Effect.as(null),
1194-
Effect.catch((error) => Effect.succeed(error.detail)),
1197+
Effect.as<string | null>(null),
1198+
Effect.catchIf(isCheckFailure, (error) => Effect.succeed(error.detail)),
11951199
Effect.map((detail) => outcomes.set(runId, detail)),
11961200
),
11971201
{ concurrency: 2, discard: true },

‎packages/source-control-github/src/server/GitHubPullRequestApi.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,15 @@ layer("GitHubPullRequestApi.layer", (it) => {
796796
mockedExecute.mockImplementation((call) => {
797797
if (call.kind !== "rest") return Effect.succeed(output("{}"));
798798
const log = /actions\/jobs\/(\d+)\/logs$/.exec(call.path);
799+
if (log?.[1] === "13") return Effect.succeed(output("one long line", true));
800+
if (log?.[1] === "14") {
801+
return Effect.fail(
802+
new GitHubRequestPolicy.GitHubApiAuthenticationError({
803+
host: "github.com",
804+
operation: "readCheckLog",
805+
}),
806+
);
807+
}
799808
if (log) return Effect.succeed(output("setup\nbuild\nError: boom\n"));
800809
const job = /actions\/jobs\/(\d+)$/.exec(call.path);
801810
if (job) return Effect.succeed(output(encodeJson({ run_id: runOf[job[1]!] })));
@@ -817,6 +826,12 @@ layer("GitHubPullRequestApi.layer", (it) => {
817826
{ name: "job 11", log: "build\nError: boom", truncated: true, detail: null },
818827
{ name: "Vercel", log: null },
819828
]);
829+
const capped = { host: "github.com", repository: "octo/repo", tailLines: 5 };
830+
expect(yield* api.readCheckLogs({ ...capped, checks: [job(13, 30)] })).toMatchObject([
831+
{ log: "one long line", truncated: true },
832+
]);
833+
const refused = yield* Effect.flip(api.readCheckLogs({ ...capped, checks: [job(14, 30)] }));
834+
expect(refused._tag).toBe("GitHubApiAuthenticationError");
820835

821836
const reruns = yield* api.rerunChecks({
822837
host: "github.com",

‎packages/source-control-github/src/server/GitHubPullRequestApi.ts‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,12 @@ export class GitHubPullRequestApi extends Context.Service<
681681
readonly repository: string;
682682
readonly checks: ReadonlyArray<ProviderCheckReference>;
683683
readonly tailLines: number;
684-
}) => Effect.Effect<ReadonlyArray<ProviderCheckLog>>;
684+
}) => Effect.Effect<ReadonlyArray<ProviderCheckLog>, GitHubPullRequestApiError>;
685685
readonly rerunChecks: (input: {
686686
readonly host: string;
687687
readonly repository: string;
688688
readonly checks: ReadonlyArray<ProviderCheckReference>;
689-
}) => Effect.Effect<ReadonlyArray<ProviderCheckRerun>>;
689+
}) => Effect.Effect<ReadonlyArray<ProviderCheckRerun>, GitHubPullRequestApiError>;
690690
readonly runPullRequestAction: (input: {
691691
readonly cwd: string;
692692
readonly repository: string;
@@ -2770,14 +2770,24 @@ export const make = Effect.gen(function* () {
27702770
timeout: "60 seconds",
27712771
})
27722772
.pipe(
2773-
Effect.map((response) => ({
2774-
...check,
2775-
...tailLogLines(response.body, input.tailLines),
2776-
detail: response.truncated ? "The log is too large; this is from its start." : null,
2777-
})),
2778-
Effect.catch((error) =>
2779-
Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),
2780-
),
2773+
Effect.map((response) => {
2774+
const tail = tailLogLines(response.body, input.tailLines);
2775+
return {
2776+
...check,
2777+
log: tail.log,
2778+
truncated: tail.truncated || response.truncated,
2779+
detail: response.truncated
2780+
? "The log is too large; this is from its start."
2781+
: null,
2782+
};
2783+
}),
2784+
// Sign-in and rate-limit failures fail the call; the rest are this check's.
2785+
Effect.catchTags({
2786+
GitHubApiNotFoundError: (error) =>
2787+
Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),
2788+
GitHubApiResponseError: (error) =>
2789+
Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),
2790+
}),
27812791
);
27822792
},
27832793
{ concurrency: 4 },
@@ -2789,7 +2799,7 @@ export const make = Effect.gen(function* () {
27892799
const root = `repos/${owner}/${name}/actions`;
27902800
const located = yield* Effect.forEach(
27912801
input.checks,
2792-
(check): Effect.Effect<LocatedCheckJob> => {
2802+
(check): Effect.Effect<LocatedCheckJob, GitHubPullRequestApiError> => {
27932803
const jobId = gitHubActionsJobId(check.url);
27942804
if (jobId === null)
27952805
return Effect.succeed({ check, jobId, runId: null, detail: NOT_A_JOB });
@@ -2798,9 +2808,13 @@ export const make = Effect.gen(function* () {
27982808
.pipe(
27992809
Effect.flatMap((response) => decodeActionsJob(response.body)),
28002810
Effect.map((job) => ({ check, jobId, runId: job.run_id, detail: null })),
2801-
Effect.catch((error) =>
2802-
Effect.succeed({ check, jobId, runId: null, detail: error.message }),
2803-
),
2811+
Effect.catchTags({
2812+
GitHubApiNotFoundError: (error) =>
2813+
Effect.succeed({ check, jobId, runId: null, detail: error.message }),
2814+
GitHubApiResponseError: (error) =>
2815+
Effect.succeed({ check, jobId, runId: null, detail: error.message }),
2816+
SchemaError: () => Effect.succeed({ check, jobId, runId: null, detail: NOT_A_JOB }),
2817+
}),
28042818
);
28052819
},
28062820
{ concurrency: 4 },
@@ -2826,8 +2840,11 @@ export const make = Effect.gen(function* () {
28262840
: `${root}/runs/${runId}/rerun-failed-jobs`,
28272841
})
28282842
.pipe(
2829-
Effect.as(null),
2830-
Effect.catch((error) => Effect.succeed(error.message)),
2843+
Effect.as<string | null>(null),
2844+
Effect.catchTags({
2845+
GitHubApiNotFoundError: (error) => Effect.succeed(error.message),
2846+
GitHubApiResponseError: (error) => Effect.succeed(error.message),
2847+
}),
28312848
Effect.map((detail) => outcomes.set(runId, detail)),
28322849
),
28332850
{ concurrency: 2, discard: true },

‎packages/source-control-github/src/server/GitHubPullRequestProvider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,8 @@ export const make = Effect.gen(function* () {
699699
})
700700
.pipe(Effect.mapError(fail("runAction"))),
701701

702-
getCheckLogs: (input) => cli.readCheckLogs(input),
703-
rerunChecks: (input) => cli.rerunChecks(input),
702+
getCheckLogs: (input) => cli.readCheckLogs(input).pipe(Effect.mapError(fail("getCheckLogs"))),
703+
rerunChecks: (input) => cli.rerunChecks(input).pipe(Effect.mapError(fail("rerunChecks"))),
704704

705705
updateChangeRequest: (input) =>
706706
cli

0 commit comments

Comments
 (0)