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

address review: let a pre-wait API blip fall through to the retry, and bound the job timeout by the real worst case

[._.]/ Adam Eivy5ed922eea9e6
diff --git a/.github/workflows/ci-cancel-recovery.yml b/.github/workflows/ci-cancel-recovery.yml
index 4daea18abf..0e9caddc1d 100644
--- a/.github/workflows/ci-cancel-recovery.yml
+++ b/.github/workflows/ci-cancel-recovery.yml
@@ -40,13 +40,15 @@ 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
+ # Must exceed MAX_RUNTIME_MS in scripts/ci-retry-cancelled-run.js — the
+ # deliberate pre-dispatch idle (#7439) PLUS two worst-case guard passes,
+ # ~13.5 minutes in total. A shorter timeout kills the job mid-wait and
+ # silently converts "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 against
+ # that derived bound, so raising the delay fails the build rather than
+ # quietly eating the margin.
+ timeout-minutes: 20
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 0c09b142ce..52b53e12fb 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -642,16 +642,30 @@ 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.
+`timeout-minutes` above `MAX_RUNTIME_MS` — the delay *plus* two worst-case
+guard passes — so a slow GitHub can never get it killed mid-wait; that bound is
+derived from the constants, and the workflow test asserts the inequality, so
+raising the delay fails the build rather than quietly eating the margin.
+
+Every API-backed guard in the table is evaluated **twice**: once before the wait
+and once after it. A push or a human re-run that lands during the delay
+therefore still wins, and the post-wait job listing is the more reliable one —
+a failing job's step records can still be settling when the run's own fail-fast
+cancel lands.
+
+The two passes are **not** equal in authority. The post-wait pass is the reading
+the re-dispatch is made on, and it fails CLOSED as before. The pre-wait pass is
+only an optimization — it exists so an obviously ineligible run skips without
+holding a runner idle — so **only a definitive `skipped` verdict short-circuits
+there.** An `unavailable` reading before the wait is not evidence of
+ineligibility, and a saturated GitHub is exactly when a transient 5xx is
+likeliest, so it falls through to the wait and lets the post-wait pass decide.
+Forfeiting the retry on a blip would lose the very case the delay was added to
+win.
+
+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
diff --git a/scripts/ci-retry-cancelled-run.js b/scripts/ci-retry-cancelled-run.js
index aab4f92a67..cdbcfdc625 100644
--- a/scripts/ci-retry-cancelled-run.js
+++ b/scripts/ci-retry-cancelled-run.js
@@ -72,6 +72,20 @@ const FAILING_CONCLUSIONS = new Set(['failure', 'timed_out']);
*/
export const RETRY_DELAY_MS = 5 * 60_000;
+/**
+ * The longest one invocation can take: the wait, plus TWO full guard passes at
+ * their worst case — every job page and both run lookups each spending the
+ * whole request timeout.
+ *
+ * The recovery job's `timeout-minutes` must exceed this, or a slow GitHub gets
+ * the job killed mid-wait and silently turns "retried late" into "never
+ * retried at all". Derived from the constants above rather than written down,
+ * so raising MAX_JOB_PAGES or RETRY_DELAY_MS fails the workflow test instead of
+ * quietly eating the margin.
+ */
+export const MAX_RUNTIME_MS = RETRY_DELAY_MS
+ + 2 * (MAX_JOB_PAGES + 2) * REQUEST_TIMEOUT_MS;
+
/** Real elapsed time. Injected in tests so no suite ever sleeps. */
const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
@@ -351,10 +365,18 @@ export async function retryCancelledCiRun({
{ outcome: 'skipped', reason: 'retry-budget-exhausted' });
}
- // Before the wait: a run that is already ineligible skips now rather than
- // holding a runner for the full delay.
+ // Before the wait: a run that is DEFINITIVELY ineligible skips now rather
+ // than holding a runner idle for the full delay.
+ //
+ // Only a `skipped` verdict short-circuits. An `unavailable` one is not
+ // evidence of ineligibility, and a saturated GitHub — precisely the condition
+ // this workflow exists for — is when a transient 5xx here is likeliest, so
+ // forfeiting the retry on it would lose the very case the delay was added to
+ // win. A failed lookup falls through to the wait and lets the post-wait pass
+ // decide; that pass still fails CLOSED. This one is only an optimization, so
+ // it may save time but must never spend the budget.
const early = await evaluateApiGuards(fetchImpl, target, logger);
- if (early) return done(early.level, early.message, early.result);
+ if (early?.result.outcome === 'skipped') return done(early.level, early.message, early.result);
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);
diff --git a/scripts/ci-retry-cancelled-run.test.js b/scripts/ci-retry-cancelled-run.test.js
index 0375e31110..390732427d 100644
--- a/scripts/ci-retry-cancelled-run.test.js
+++ b/scripts/ci-retry-cancelled-run.test.js
@@ -12,7 +12,12 @@ import { fileURLToPath } from 'url';
import { describe, expect, it, vi } from 'vitest';
-import { RETRY_DELAY_MS, retryCancelledCiRun, retryTargetFromEnv } from './ci-retry-cancelled-run.js';
+import {
+ MAX_RUNTIME_MS,
+ 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)), '..');
@@ -381,6 +386,66 @@ describe('the wait before re-dispatching', () => {
expect(clock.waits).toEqual([]);
});
+ it('does not forfeit the retry when a PRE-wait lookup merely fails', async () => {
+ // The pre-wait pass is an optimization, not a verdict: a 5xx there is not
+ // evidence of ineligibility, and a saturated GitHub — the exact condition
+ // this workflow exists for — is when one is likeliest. Skipping on it
+ // would lose the very case the delay was added to win.
+ let apiRecovered = false;
+ const impl = vi.fn(async (url) => {
+ if (!apiRecovered) return { ok: false, status: 502 };
+ if (url.includes('/jobs?')) return json({ total_count: 0, jobs: [] });
+ if (url.includes('/runs?')) return json({ workflow_runs: [] });
+ if (url.endsWith('/rerun')) return { ok: true, status: 201 };
+ return json({ run_attempt: 1, status: 'completed', conclusion: 'cancelled' });
+ });
+
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: impl,
+ wait: async () => { apiRecovered = true; },
+ })).resolves.toMatchObject({ outcome: 'requested', phase: 'after-wait' });
+ expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(true);
+ });
+
+ it('still fails CLOSED when the POST-wait lookup cannot be read', async () => {
+ // The other half of the rule above: falling through a pre-wait failure may
+ // only ever cost time. The pass the dispatch is actually made on must
+ // still refuse to treat an unreadable listing as "no job failed".
+ const impl = vi.fn(async () => ({ ok: false, status: 502 }));
+ await expect(invoke({ env: BASE_ENV, fetchImpl: impl }))
+ .resolves.toMatchObject({ outcome: 'unavailable', reason: 'jobs-unavailable', phase: 'after-wait' });
+ expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
+ });
+
+ it('catches a job whose failure only settles DURING the wait', async () => {
+ // The fail-fast self-cancel can land while the failing job is still in its
+ // post-steps, so the pre-wait listing can legitimately read clean. The
+ // post-wait re-read is the more reliable one, and must block the retry.
+ let stepsSettled = false;
+ const impl = vi.fn(async (url) => {
+ if (url.includes('/jobs?')) {
+ return json({
+ total_count: 1,
+ jobs: [{
+ name: 'Server tests',
+ conclusion: 'cancelled',
+ steps: stepsSettled ? [{ conclusion: 'failure' }] : [{ conclusion: 'success' }],
+ }],
+ });
+ }
+ if (url.includes('/runs?')) return json({ workflow_runs: [] });
+ return json({ run_attempt: 1, status: 'completed', conclusion: 'cancelled' });
+ });
+
+ await expect(invoke({
+ env: BASE_ENV,
+ fetchImpl: impl,
+ wait: async () => { stepsSettled = true; },
+ })).resolves.toMatchObject({ outcome: 'skipped', reason: 'job-failed', phase: 'after-wait' });
+ expect(impl.mock.calls.some(([url]) => url.endsWith('/rerun'))).toBe(false);
+ });
+
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.
@@ -398,13 +463,15 @@ describe('the wait before re-dispatching', () => {
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'.
+ it('gives the recovery job a timeout that outlives the wait AND both guard passes', () => {
+ // The job idles for RETRY_DELAY_MS and then re-reads every guard, so the
+ // bound that matters is MAX_RUNTIME_MS, not the delay alone — a timeout
+ // between the two would kill a slow run mid-wait and silently turn
+ // 'retried late' into 'never retried at all'. Asserting the derived bound
+ // is what makes raising the delay fail here instead of eating the margin.
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);
+ expect(timeoutMinutes * 60_000).toBeGreaterThan(MAX_RUNTIME_MS);
});
it('triggers on a completed CI run and nothing else', () => {