Skip to content

Commit de892bf

Browse files
mchwangclaude
andcommitted
Keep a GitHub failure that precedes the required-check wait limit
Only the limit's own abort reason classifies an inspection as the wait timing out; a stage failure that settles after the limit ends the job failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c1a329d commit de892bf

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎docs/implementation/merge-handoff.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Without a runner, **Merge PR** works as before.
3535
| Wait for checks | The job inspects the pull request (fresh) at once, then again after 10 s, with the wait doubling up to 60 s. | every required check succeeds, or the required set was read and is empty, and nothing else blocks | a required check fails, or 30 minutes pass (job: `blocked`, if the preparation still applies: the block re-checks readiness in its transaction, and a review edit or other task change meanwhile ends the job `failed` instead); the pull request moved, another blocker appears, or GitHub or the local review cannot be read (job: `failed`; one failed read fails closed rather than retrying; each inspection also loads the review, which awaits a history worker since #170, within the same 30-minute limit) |
3636
| Merge | The job calls the guarded merge with the current review token. Its inspections rerun the already-fixed check. | GitHub merged or queued the head, as the job's own merge attempt records it (job: `merged` or `queued`; `submitted` when GitHub accepted the merge but saving its outcome failed, so the attempt is still submitting and reconciles from GitHub) | GitHub refused (job: `blocked`; `failed` when GitHub refused because the head changed, which needs a fresh review, or when the review, snapshot or plan revision changed while GitHub was asked: the block is for the review the merge attempt was admitted for), validation refused (job: `failed`), or the outcome is unknown (job: `submitted`; the merge attempt reconciles as before) |
3737

38-
A required check run passes when it completed with success, neutral or skipped, as GitHub counts required checks; a commit status passes only with success. When a check has several runs or statuses with its name (a re-run), the one that started last counts, and a run not yet started counts as the latest. While waiting, an unknown mergeability (GitHub is still computing it) and a pending or missing required check keep the job waiting. No inspection starts after the 30 minutes, and one still running when they end is stopped, so only checks seen passing within the limit count. The guarded merge that follows inspects again and may ask GitHub to merge shortly after the limit; it refuses anything no longer clear. Unreadable branch rules never pass. Another blocker outranks a failing check: checks that fail on a head a collaborator pushed say nothing about this review, so the job ends `failed` and the task's status is unchanged.
38+
A required check run passes when it completed with success, neutral or skipped, as GitHub counts required checks; a commit status passes only with success. When a check has several runs or statuses with its name (a re-run), the one that started last counts, and a run not yet started counts as the latest. While waiting, an unknown mergeability (GitHub is still computing it) and a pending or missing required check keep the job waiting. No inspection starts after the 30 minutes, and one still running when they end is stopped, so only checks seen passing within the limit count. Only that stop counts as the wait timing out: an inspection that GitHub failed before the limit, but that settles after it (its stopped reads finishing), ends the job `failed` with GitHub's error. The guarded merge that follows inspects again and may ask GitHub to merge shortly after the limit; it refuses anything no longer clear. Unreadable branch rules never pass. Another blocker outranks a failing check: checks that fail on a head a collaborator pushed say nothing about this review, so the job ends `failed` and the task's status is unchanged.
3939

4040
## Outcomes
4141

@@ -80,7 +80,7 @@ Schema v19 adds `task_pull_requests.check_id` (the pre-PR check each opening fol
8080

8181
## Tests
8282

83-
`test/merge-job.test.ts` runs the job against the real Store and guarded merge with a faked GitHub and preparation. It covers the three wait cases the design names (zero required checks, one check pending then passing, a timeout), a failing check, GitHub still computing mergeability, preparation ending for review or failing, another blocker while waiting, a failed GitHub read while waiting, GitHub's refusal, an unknown merge outcome, a merge queue (`queued`), cancel while waiting (told or not) and during the guarded merge's validation, shutdown while waiting and during the guarded merge, startup settlement, resends, a second click, a stale token, a busy runner, and which blockers keep Merge PR available (including Retry merge after `blocked`). `test/pre-merge.test.ts` runs the #22 acceptance cases through the job with real preparation: a base move that leaves approvals valid merges; a rebase that makes an approval stale stops for review; a breaking command after a rebase fails the job; a collaborator push stops for review; a cancel during a command check ends the job `cancelled`. Server tests cover the merge route, its trust admission (an untrusted click refused and replayed, a failed read saving nothing), `GET /api/merge`, the `prepare-merge` and `publish` refusals, the `start` refusal after a plan import and approval during the preparation, the `start` and `resume` refusals after the same during the check wait (the import then ends the job `failed`, with nothing run, pushed, published or merged), cancel closing the pull requests, and shutdown; a production test covers startup settlement; a browser test follows a job to merged.
83+
`test/merge-job.test.ts` runs the job against the real Store and guarded merge with a faked GitHub and preparation. It covers the three wait cases the design names (zero required checks, one check pending then passing, a timeout), a failing check, GitHub still computing mergeability, preparation ending for review or failing, another blocker while waiting, a failed GitHub read while waiting (also one that settles after the wait limit), GitHub's refusal, an unknown merge outcome, a merge queue (`queued`), cancel while waiting (told or not) and during the guarded merge's validation, shutdown while waiting and during the guarded merge, startup settlement, resends, a second click, a stale token, a busy runner, and which blockers keep Merge PR available (including Retry merge after `blocked`). `test/pre-merge.test.ts` runs the #22 acceptance cases through the job with real preparation: a base move that leaves approvals valid merges; a rebase that makes an approval stale stops for review; a breaking command after a rebase fails the job; a collaborator push stops for review; a cancel during a command check ends the job `cancelled`. Server tests cover the merge route, its trust admission (an untrusted click refused and replayed, a failed read saving nothing), `GET /api/merge`, the `prepare-merge` and `publish` refusals, the `start` refusal after a plan import and approval during the preparation, the `start` and `resume` refusals after the same during the check wait (the import then ends the job `failed`, with nothing run, pushed, published or merged), cancel closing the pull requests, and shutdown; a production test covers startup settlement; a browser test follows a job to merged.
8484

8585
## Check this document with a reader
8686

‎runner/merge-job.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ export class MergeJobCoordinator {
248248
try { status = await this.merges.status(undefined, true, AbortSignal.any([signal, limit])); }
249249
catch (error) {
250250
if (signal.aborted) return { kind: 'cancelled' };
251-
if (limit.aborted) return timedOut();
251+
// Only the limit's own abort is the wait's timeout: every layer below rejects with that reason, unchanged. A
252+
// failure that came first (a GitHub stage failing while its stopped peers settle past the limit) keeps its error.
253+
if (limit.aborted && error === limit.reason) return timedOut();
252254
return { kind: 'failed', reason: error instanceof Error ? error.message : String(error) };
253255
}
254256
const verdict = classify(status);

‎test/merge-job.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,29 @@ it('starts no inspection after the wait limit and stops one that runs into it',
658658
expect(f.gh.merged).toEqual([]);
659659
});
660660

661+
it('keeps a GitHub failure that came before the wait limit, even when the inspection settles after it', async () => {
662+
let inspections = 0, abortedFirst: unknown = null;
663+
const f = setup({ checks: () => [pending()] });
664+
const inspect = f.gh.client.inspect;
665+
f.gh.client.inspect = (async (request: Parameters<typeof inspect>[0]) => {
666+
if (++inspections < 2) return inspect(request);
667+
// A stage fails at once; its stopped peers settle only after the wait's limit, and the gateway then reports the
668+
// stage's own error (github/merge.ts inspect), not the abort.
669+
const failure = new Error('gh: HTTP 502 from the rules read');
670+
await new Promise(resolve => request!.signal!.addEventListener('abort', resolve, { once: true }));
671+
abortedFirst = request!.signal!.reason;
672+
throw failure;
673+
}) as typeof inspect;
674+
const coordinator = new MergeJobCoordinator(f.review, f.prep.fake, f.merges, undefined, { checkWaitMs: 300, firstDelayMs: 5, maxDelayMs: 5 }); jobs.push(coordinator);
675+
await coordinator.start('review-token', randomUUID());
676+
const done = await settled(coordinator);
677+
// The interleaving happened: the wait's limit (a timeout, not a cancel) fired before the failed inspection settled.
678+
expect((abortedFirst as Error | null)?.name).toBe('TimeoutError');
679+
expect(done).toMatchObject({ state: 'failed', reason: 'gh: HTTP 502 from the rules read' });
680+
expect(f.store.getTask(identity).status).toBe('in review');
681+
expect(f.gh.merged).toEqual([]);
682+
});
683+
661684
// Since #170 a click's admission awaits the review load; these pin what may happen while it does.
662685
it('gives a resend of the same click, during the first send\'s review load, the same job', async () => {
663686
const f = setup(), id = randomUUID(), held = holdNextLoad(f.review as never);

0 commit comments

Comments
 (0)