Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

wait five minutes before re-dispatching a cancelled CI run, and re-check every guard after the wait (#7439)

[._.]/ Adam Eivyd88d585c5097
diff --git a/.github/workflows/ci-cancel-recovery.yml b/.github/workflows/ci-cancel-recovery.yml
index add2aadf58..4daea18abf 100644
--- a/.github/workflows/ci-cancel-recovery.yml
+++ b/.github/workflows/ci-cancel-recovery.yml
@@ -40,6 +40,13 @@ jobs:
&& github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.run_attempt == 1
runs-on: ubuntu-latest
+ # Must exceed RETRY_DELAY_MS in scripts/ci-retry-cancelled-run.js: the job
+ # deliberately idles for that long before re-dispatching (#7439), and a
+ # timeout shorter than the wait would kill it mid-wait — silently
+ # converting "retried late" into "never retried at all". Pinned rather
+ # than left at the 360-minute default so the relationship is visible to
+ # whoever tunes the delay; the guard test asserts the inequality.
+ timeout-minutes: 15
steps:
# No `setup-node` and no `npm ci`: the script imports Node builtins
# only (enforced by scripts/pre-install-entrypoints.test.js) and every
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
index 0f144b3cdb..0c09b142ce 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -634,6 +634,29 @@ retries only when every one of these holds:
Any API lookup that cannot be completed skips the retry rather than assuming a
guard passed — a missed retry costs one manual re-run, a wrong one loops.
+**The re-dispatch waits five minutes first** (`RETRY_DELAY_MS`, issue 7439).
+The cancel it recovers from is caused by a saturated queue, so firing the
+one-retry budget the instant the `workflow_run` event arrives spends it at the
+moment it is least likely to survive: on PR 7434 three re-runs of the identical
+SHA were each cancelled again while other runs were in flight, and that same SHA
+passed on the first attempt made against an idle queue. One job idling — not
+computing — for five minutes is the cheap side of that trade against re-running
+twelve jobs straight into another cancel. The recovery job pins
+`timeout-minutes` above the delay so it is never killed mid-wait, and a test
+asserts that inequality.
+
+Every API-backed guard in the table is evaluated **twice**: once before the wait,
+so a run that is already ineligible skips without occupying a runner, and once
+after it, because that is the reading the re-dispatch is actually made on. A push
+or a human re-run that lands during the delay therefore still wins. The step
+summary records `phase: before-wait | after-wait` and the `delay` it used, so
+the Actions history can be read back as evidence when the constant is tuned —
+under the delay that actually produced each outcome, not today's value.
+
+Deliberately **not** chosen: polling `GET /actions/runs?status=in_progress` and
+retrying only once the repository is quiet. On a busy repo that can mean never
+retrying, which is worse than retrying into a cancel.
+
**Why the failing-job guard reads the jobs' own conclusions** rather than a
marker written by the fail-fast step: a marker fails OPEN. It would be written
by a job that is already failing, on a run about to be cancelled out from under
@@ -651,11 +674,10 @@ prints its verdict. The recovery run is a separate run, so it survives; its
step summary records which guard applied. Publishing that back onto the pull
request as a neutral check run is issue #7438.
-Two known limits, both filed: the retry fires immediately, which is while the
-queue that caused the cancel is still full (#7439), and a retry re-runs the
-whole suite — Windows shards included — so if the cause is the spending limit
-then recovery spends more of it. Reducing the billable minutes of a full run is
-the complementary root-cause lever (#7440).
+One known limit, filed: a retry re-runs the whole suite — Windows shards
+included — so if the cause is the spending limit then recovery spends more of
+it. Reducing the billable minutes of a full run is the complementary root-cause
+lever (#7440).
Because the trigger is `workflow_run`, the recovery workflow runs the
**default branch's** copy of itself with a writable `actions` token and never
diff --git a/scripts/ci-retry-cancelled-run.js b/scripts/ci-retry-cancelled-run.js
index 18584ed91b..aab4f92a67 100644
--- a/scripts/ci-retry-cancelled-run.js
+++ b/scripts/ci-retry-cancelled-run.js
@@ -29,6 +29,10 @@
* lookup failure returns without re-dispatching, because the cost of missing a
* retry is one manual re-run and the cost of a wrong retry is a runaway loop.
*
+ * The re-dispatch is DELAYED — see RETRY_DELAY_MS — and every API-backed guard
+ * is evaluated again after the wait, so a supersession or a human re-run that
+ * lands during it still wins (issue 7439).
+ *
* The workflow that runs this is triggered by `workflow_run`, so it checks out
* the DEFAULT branch — never the pull request's head. Nothing here executes,
* imports, or interpolates repository content from the PR.
@@ -47,6 +51,30 @@ const SIBLING_RUNS_PER_PAGE = 5;
/** A conclusion that means something really broke, not that it was stopped. */
const FAILING_CONCLUSIONS = new Set(['failure', 'timed_out']);
+/**
+ * How long to idle before re-dispatching (issue 7439).
+ *
+ * The cancel this recovers from is caused by a saturated queue, so firing the
+ * one-retry budget the instant the event arrives spends it at the moment it is
+ * least likely to survive: on PR 7434 three re-runs of the IDENTICAL SHA were
+ * each cancelled again while other runs were in flight, and that same SHA
+ * passed on the first attempt made against an idle queue.
+ *
+ * Five minutes, because it is the smallest wait that plausibly outlives a
+ * burst and the trade is lopsided: one job idling — not computing — for five
+ * minutes against re-running twelve jobs straight into another cancel. It is
+ * deliberately NOT "poll until the repository is quiet": on a busy repo that
+ * can mean never retrying, which is worse than retrying into a cancel.
+ *
+ * Tune it from evidence, not intuition. Every recovery run's step summary
+ * records the delay it used and whether the skip happened before or after the
+ * wait, so the Actions history answers whether re-dispatched runs complete.
+ */
+export const RETRY_DELAY_MS = 5 * 60_000;
+
+/** Real elapsed time. Injected in tests so no suite ever sleeps. */
+const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
+
/**
* True when this job carries a real failure.
*
@@ -190,6 +218,75 @@ async function fetchNewestSiblingRunNumber(fetchImpl, target, logger) {
.reduce((newest, run) => Math.max(newest, Number(run?.run_number) || 0), 0);
}
+/**
+ * Every guard that needs the API, in one pass.
+ *
+ * Extracted because it runs TWICE — once before the wait, so an obviously
+ * ineligible run skips without occupying a runner for five minutes, and once
+ * after it, because that is the reading the re-dispatch is actually made on.
+ * Re-reading is not merely defensive: a supersession or a human re-run can
+ * land during the wait, and the post-wait job listing is also the more
+ * reliable one, since a failing job's step records can still be settling when
+ * the run's own cancel lands (see `jobFailed`).
+ *
+ * @returns {Promise<{level: string, message: string, result: object}|null>}
+ * null when every guard passes, otherwise the reason not to re-dispatch.
+ */
+async function evaluateApiGuards(fetchImpl, target, logger) {
+ const jobs = await fetchAttemptJobs(fetchImpl, target, logger);
+ if (!jobs) {
+ return {
+ level: 'error',
+ message: `⚠️ CI retry skipped: could not list the jobs of run ${target.runId}`,
+ result: { outcome: 'unavailable', reason: 'jobs-unavailable' },
+ };
+ }
+ const failedJobs = jobs.filter(jobFailed).map(safeJobName);
+ if (failedJobs.length) {
+ return {
+ level: 'log',
+ message: `ℹ️ CI retry skipped: run ${target.runId} cancelled after a real failure (${failedJobs.join(', ')})`,
+ result: { outcome: 'skipped', reason: 'job-failed' },
+ };
+ }
+
+ const live = await fetchLiveRunState(fetchImpl, target, logger);
+ if (!live) {
+ return {
+ level: 'error',
+ message: `⚠️ CI retry skipped: could not read the current state of run ${target.runId}`,
+ result: { outcome: 'unavailable', reason: 'run-state-unavailable' },
+ };
+ }
+ if (live.runAttempt !== 1 || live.status !== 'completed' || live.conclusion !== 'cancelled') {
+ return {
+ level: 'log',
+ message: `ℹ️ CI retry skipped: run ${target.runId} has moved on since the event (attempt ${live.runAttempt}, ${live.status}/${live.conclusion || 'no conclusion'})`,
+ result: { outcome: 'skipped', reason: 'run-state-moved-on' },
+ };
+ }
+
+ // Listed LAST, immediately before the POST, so the window in which a fresh
+ // push could create a successor we do not see is as small as it can be.
+ const newestSibling = await fetchNewestSiblingRunNumber(fetchImpl, target, logger);
+ if (newestSibling === null) {
+ return {
+ level: 'error',
+ message: `⚠️ CI retry skipped: could not list sibling runs for run ${target.runId}`,
+ result: { outcome: 'unavailable', reason: 'sibling-runs-unavailable' },
+ };
+ }
+ if (newestSibling > target.runNumber) {
+ return {
+ level: 'log',
+ message: `ℹ️ CI retry skipped: run ${target.runId} was superseded by run #${newestSibling} on the same pull request`,
+ result: { outcome: 'skipped', reason: 'superseded' },
+ };
+ }
+
+ return null;
+}
+
/**
* Decide whether the cancelled run deserves one re-dispatch, and do it.
*
@@ -198,13 +295,17 @@ async function fetchNewestSiblingRunNumber(fetchImpl, target, logger) {
* @param {typeof fetch} [options.fetchImpl]
* @param {{log?: Function, error?: Function}} [options.logger]
* @param {Function} [options.writeSummary] - injectable step-summary writer
- * @returns {Promise<{outcome: 'requested'|'skipped'|'unavailable', reason?: string, status?: number}>}
+ * @param {number} [options.delayMs] - wait before re-dispatching
+ * @param {(ms: number) => Promise<void>} [options.wait] - injectable clock; tests never sleep
+ * @returns {Promise<{outcome: 'requested'|'skipped'|'unavailable', reason?: string, status?: number, phase?: string}>}
*/
export async function retryCancelledCiRun({
env = process.env,
fetchImpl = globalThis.fetch,
logger = console,
writeSummary = writeStepSummary,
+ delayMs = RETRY_DELAY_MS,
+ wait = sleep,
} = {}) {
const runLabel = /^\d+$/.test(String(env.CI_RUN_ID ?? '')) ? env.CI_RUN_ID : 'unidentified';
// Every exit goes through here, so "why was my run not retried?" is
@@ -212,12 +313,19 @@ export async function retryCancelledCiRun({
// the numeric run id only — never the branch name or any other payload text.
// `level` is a parameter rather than derived from `outcome`: an invalid
// environment is a `skipped` outcome that still deserves stderr.
+ // `phase` and `delay` are what make the Actions history measurable (7439):
+ // they say whether an outcome was reached before or after the wait, and how
+ // long that wait was, so a later tuning pass can read its own baseline
+ // instead of guessing at summaries written under a since-changed constant.
+ let phase = 'before-wait';
const done = (level, message, result) => {
logger[level]?.(message);
writeSummary(`### CI cancel recovery: ${result.outcome}\n\n`
+ `- run: ${runLabel}\n`
- + `- reason: ${result.reason || 're-dispatched'}`, env);
- return result;
+ + `- reason: ${result.reason || 're-dispatched'}\n`
+ + `- phase: ${phase}\n`
+ + `- delay: ${Math.round(delayMs / 1000)}s`, env);
+ return { ...result, phase };
};
const target = retryTargetFromEnv(env);
@@ -243,38 +351,19 @@ export async function retryCancelledCiRun({
{ outcome: 'skipped', reason: 'retry-budget-exhausted' });
}
- const jobs = await fetchAttemptJobs(fetchImpl, target, logger);
- if (!jobs) {
- return done('error', `⚠️ CI retry skipped: could not list the jobs of run ${target.runId}`,
- { outcome: 'unavailable', reason: 'jobs-unavailable' });
- }
- const failedJobs = jobs.filter(jobFailed).map(safeJobName);
- if (failedJobs.length) {
- return done('log', `ℹ️ CI retry skipped: run ${target.runId} cancelled after a real failure (${failedJobs.join(', ')})`,
- { outcome: 'skipped', reason: 'job-failed' });
- }
+ // Before the wait: a run that is already ineligible skips now rather than
+ // holding a runner for the full delay.
+ const early = await evaluateApiGuards(fetchImpl, target, logger);
+ if (early) return done(early.level, early.message, early.result);
- const live = await fetchLiveRunState(fetchImpl, target, logger);
- if (!live) {
- return done('error', `⚠️ CI retry skipped: could not read the current state of run ${target.runId}`,
- { outcome: 'unavailable', reason: 'run-state-unavailable' });
- }
- if (live.runAttempt !== 1 || live.status !== 'completed' || live.conclusion !== 'cancelled') {
- return done('log', `ℹ️ CI retry skipped: run ${target.runId} has moved on since the event (attempt ${live.runAttempt}, ${live.status}/${live.conclusion || 'no conclusion'})`,
- { outcome: 'skipped', reason: 'run-state-moved-on' });
- }
+ logger.log?.(`⏳ Waiting ${Math.round(delayMs / 1000)}s before re-dispatching CI run ${target.runId}: the queue that cancelled it is likely still full`);
+ await wait(delayMs);
+ phase = 'after-wait';
- // Listed LAST, immediately before the POST, so the window in which a fresh
- // push could create a successor we do not see is as small as it can be.
- const newestSibling = await fetchNewestSiblingRunNumber(fetchImpl, target, logger);
- if (newestSibling === null) {
- return done('error', `⚠️ CI retry skipped: could not list sibling runs for run ${target.runId}`,
- { outcome: 'unavailable', reason: 'sibling-runs-unavailable' });
- }
- if (newestSibling > target.runNumber) {
- return done('log', `ℹ️ CI retry skipped: run ${target.runId} was superseded by run #${newestSibling} on the same pull request`,
- { outcome: 'skipped', reason: 'superseded' });
- }
+ // After the wait: the reading the re-dispatch is actually made on. A newer
+ // run for the branch, or a human re-run, may have landed during the delay.
+ const late = await evaluateApiGuards(fetchImpl, target, logger);
+ if (late) return done(late.level, late.message, late.result);
const response = await request(
fetchImpl,
diff --git a/scripts/ci-retry-cancelled-run.test.js b/scripts/ci-retry-cancelled-run.test.js
index 450f2da14f..0375e31110 100644
--- a/scripts/ci-retry-cancelled-run.test.js
+++ b/scripts/ci-retry-cancelled-run.test.js
@@ -12,7 +12,7 @@ import { fileURLToPath } from 'url';
import { describe, expect, it, vi } from 'vitest';
-import { retryCancelledCiRun, retryTargetFromEnv } from './ci-retry-cancelled-run.js';
+import { RETRY_DELAY_MS, retryCancelledCiRun, retryTargetFromEnv } from './ci-retry-cancelled-run.js';
import { workflowJobs } from './lib/workflowJobs.js';
const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
@@ -65,9 +65,17 @@ function stubFetch({ jobs = [], runs = [], rerunStatus = 201, live } = {}) {
const silent = { log: () => {}, error: () => {} };
const noSummary = () => {};
-const run = (env, fetchStub) => retryCancelledCiRun({
- env, fetchImpl: fetchStub.impl, logger: silent, writeSummary: noSummary,
+/** No suite ever sleeps — the production wait is always replaced. */
+const noWait = async () => {};
+/** ...and `waits` records what the delay WOULD have been. */
+const fakeClock = () => {
+ const waits = [];
+ return { waits, wait: async (ms) => { waits.push(ms); } };
+};
+const invoke = (options) => retryCancelledCiRun({
+ logger: silent, writeSummary: noSummary, wait: noWait, ...options,
});
+const run = (env, fetchStub) => invoke({ env, fetchImpl: fetchStub.impl });
describe('retryTargetFromEnv', () => {
it('accepts a well-formed workflow_run environment', () => {
@@ -167,9 +175,8 @@ describe('retryCancelledCiRun guards', () => {
if (url.includes('/jobs?')) return json(pages[new URL(url).searchParams.get('page')]);
return json({ workflow_runs: [] });
});
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'skipped', reason: 'job-failed' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'skipped', reason: 'job-failed' });
});
it('never lets a pull-request job name forge an Actions workflow command', async () => {
@@ -179,11 +186,10 @@ describe('retryCancelledCiRun guards', () => {
const fetchStub = stubFetch({
jobs: [{ name: 'Server\n::add-mask::secret', conclusion: 'failure' }],
});
- await retryCancelledCiRun({
+ await invoke({
env: BASE_ENV,
fetchImpl: fetchStub.impl,
logger: { log: (l) => logged.push(l), error: (l) => logged.push(l) },
- writeSummary: noSummary,
});
const text = logged.join('\n');
@@ -221,9 +227,8 @@ describe('retryCancelledCiRun guards', () => {
if (url.includes('/runs?')) return json({ workflow_runs: [] });
return { ok: false, status: 500 };
});
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'unavailable', reason: 'run-state-unavailable' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable', reason: 'run-state-unavailable' });
expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
});
@@ -242,9 +247,8 @@ describe('retryCancelledCiRun guards', () => {
const impl = vi.fn(async (url) => (url.includes('/jobs?')
? { ok: false, status: 502 }
: json({ workflow_runs: [] })));
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'unavailable', reason: 'jobs-unavailable' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable', reason: 'jobs-unavailable' });
expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
});
@@ -254,9 +258,8 @@ describe('retryCancelledCiRun guards', () => {
const impl = vi.fn(async (url) => (url.includes('/jobs?')
? json({ total_count: 40, jobs: [] })
: json({ workflow_runs: [] })));
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'unavailable', reason: 'jobs-unavailable' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable', reason: 'jobs-unavailable' });
});
it('does not retry when the sibling-run listing cannot be read', async () => {
@@ -265,16 +268,14 @@ describe('retryCancelledCiRun guards', () => {
if (url.includes('/jobs?')) return json({ total_count: 0, jobs: [] });
return json({ run_attempt: 1, status: 'completed', conclusion: 'cancelled' });
});
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'unavailable', reason: 'sibling-runs-unavailable' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable', reason: 'sibling-runs-unavailable' });
});
it('survives a network failure without throwing', async () => {
const impl = vi.fn(async () => { throw new Error('socket hang up'); });
- await expect(retryCancelledCiRun({
- env: BASE_ENV, fetchImpl: impl, logger: silent, writeSummary: noSummary,
- })).resolves.toMatchObject({ outcome: 'unavailable' });
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable' });
});
it('reports a rejected rerun rather than claiming success', async () => {
@@ -288,10 +289,9 @@ describe('retryCancelledCiRun guards', () => {
// and the summary must never echo the attacker-controlled branch name.
const written = [];
const fetchStub = stubFetch({ runs: [{ id: 5000, run_number: 901 }] });
- await retryCancelledCiRun({
+ await invoke({
env: { ...BASE_ENV, CI_RUN_HEAD_BRANCH: 'evil <img src=x>' },
fetchImpl: fetchStub.impl,
- logger: silent,
writeSummary: (markdown) => written.push(markdown),
});
@@ -302,9 +302,111 @@ describe('retryCancelledCiRun guards', () => {
});
});
+describe('the wait before re-dispatching', () => {
+ // The cancel this recovers from is caused by a saturated queue, so the
+ // one-retry budget is worth least at the instant the event arrives (7439).
+ // Every test injects the clock — a real five-minute sleep in CI is not a
+ // test, it is an outage.
+
+ it('waits the full delay, and re-dispatches only afterwards', async () => {
+ const fetchStub = stubFetch({ runs: [{ id: 4242, run_number: 900 }] });
+ const seenBeforeWait = [];
+ const clock = fakeClock();
+
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: fetchStub.impl,
+ wait: async (ms) => {
+ seenBeforeWait.push(...fetchStub.calls.map((call) => call.url));
+ await clock.wait(ms);
+ },
+ })).resolves.toMatchObject({ outcome: 'requested', phase: 'after-wait' });
+
+ expect(clock.waits).toEqual([RETRY_DELAY_MS]);
+ expect(seenBeforeWait.some((url) => url.endsWith('/rerun'))).toBe(false);
+ });
+
+ it('lets a supersession that lands DURING the wait win', async () => {
+ // This is the re-check the delay exists for: the pre-wait listing said
+ // there was no successor, and a push five minutes later must still
+ // cancel the retry rather than re-running code nobody is waiting on.
+ let pushedDuringWait = false;
+ const impl = vi.fn(async (url) => {
+ if (url.includes('/jobs?')) return json({ total_count: 0, jobs: [] });
+ if (url.includes('/runs?')) {
+ return json({
+ workflow_runs: pushedDuringWait
+ ? [{ id: 5000, run_number: 901, head_repository: { id: 555 } }]
+ : [],
+ });
+ }
+ return json({ run_attempt: 1, status: 'completed', conclusion: 'cancelled' });
+ });
+
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: impl,
+ wait: async () => { pushedDuringWait = true; },
+ })).resolves.toMatchObject({ outcome: 'skipped', reason: 'superseded', phase: 'after-wait' });
+ expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
+ });
+
+ it('lets a human re-run that lands DURING the wait keep the budget', async () => {
+ let rerunByHuman = false;
+ const impl = vi.fn(async (url) => {
+ if (url.includes('/jobs?')) return json({ total_count: 0, jobs: [] });
+ if (url.includes('/runs?')) return json({ workflow_runs: [] });
+ return json({
+ run_attempt: rerunByHuman ? 2 : 1, status: 'completed', conclusion: 'cancelled',
+ });
+ });
+
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: impl,
+ wait: async () => { rerunByHuman = true; },
+ })).resolves.toMatchObject({ outcome: 'skipped', reason: 'run-state-moved-on', phase: 'after-wait' });
+ expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
+ });
+
+ it('does not hold a runner idle for a run that is already ineligible', async () => {
+ // Skipping before the wait is what keeps the delay cheap: a genuinely red
+ // run costs one API call, not five minutes of occupancy.
+ const clock = fakeClock();
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: stubFetch({ jobs: [{ name: 'Server tests', conclusion: 'failure' }] }).impl,
+ wait: clock.wait,
+ })).resolves.toMatchObject({ outcome: 'skipped', reason: 'job-failed', phase: 'before-wait' });
+ expect(clock.waits).toEqual([]);
+ });
+
+ it('records the phase and the delay it used on the run summary', async () => {
+ // The tuning evidence this issue asks for: a summary written under a
+ // since-changed constant must still say which delay produced it.
+ const written = [];
+ await invoke({
+ env: BASE_ENV,
+ fetchImpl: stubFetch({ runs: [{ id: 4242, run_number: 900 }] }).impl,
+ writeSummary: (markdown) => written.push(markdown),
+ });
+ expect(written[0]).toContain('phase: after-wait');
+ expect(written[0]).toContain(`delay: ${RETRY_DELAY_MS / 1000}s`);
+ });
+});
+
describe('ci-cancel-recovery.yml wiring', () => {
const jobs = workflowJobs(RECOVERY_WORKFLOW);
+ it('gives the recovery job a timeout that outlives the wait', () => {
+ // The job now idles for RETRY_DELAY_MS before re-dispatching. A timeout
+ // shorter than that would kill it mid-wait and silently turn 'retried
+ // late' into 'never retried at all'.
+ const timeoutMinutes = Number(jobs.retry.match(/^\s+timeout-minutes:\s*(\d+)\s*$/m)?.[1]);
+ expect(Number.isFinite(timeoutMinutes)).toBe(true);
+ expect(timeoutMinutes * 60_000).toBeGreaterThan(RETRY_DELAY_MS);
+ });
+
it('triggers on a completed CI run and nothing else', () => {
expect(RECOVERY_WORKFLOW).toMatch(/on:\n {2}workflow_run:\n {4}workflows: \[CI\]\n {4}types: \[completed\]/);
// A `pull_request` trigger here would run with the PR's own code.