Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ci): retry transient 503 link failures with backoff

Steven Enamakel33365c104bf1
diff --git a/.github/workflows/pr-quality.yml b/.github/workflows/pr-quality.yml
index 7337a0059d..d1db604f54 100644
--- a/.github/workflows/pr-quality.yml
+++ b/.github/workflows/pr-quality.yml
@@ -59,8 +59,11 @@ jobs:
with:
fetch-depth: 1
- name: Lychee link check
+ id: link-check
+ continue-on-error: true
uses: lycheeverse/lychee-action@v2
with:
+ output: target/link-check/report.md
# Product Hunt denies GitHub-hosted runners (403) for the translated
# README badge destination, so it cannot be a stable external-link
# check.
@@ -95,6 +98,12 @@ jobs:
'CONTRIBUTING.md'
'.github/PULL_REQUEST_TEMPLATE.md'
fail: true
+ - name: Recheck transient service failures
+ if: steps.link-check.outcome == 'failure'
+ run: >-
+ node scripts/ci/retry-markdown-links.mjs
+ target/link-check/report.md
+ "$RUNNER_TEMP/lychee/bin/lychee"
appimage-rpath-guard:
name: AppImage RPATH + libxdo guard
runs-on: ubuntu-latest
diff --git a/scripts/__tests__/retry-markdown-links.test.mjs b/scripts/__tests__/retry-markdown-links.test.mjs
index 13a4afa6c4..ce384a4f5f 100644
--- a/scripts/__tests__/retry-markdown-links.test.mjs
+++ b/scripts/__tests__/retry-markdown-links.test.mjs
@@ -1,43 +1,96 @@
-import assert from 'node:assert/strict';
-import test from 'node:test';
-import { retryServiceUnavailable, serviceUnavailableUrls } from '../ci/retry-markdown-links.mjs';
+import assert from "node:assert/strict";
+import test from "node:test";
+import {
+ retryServiceUnavailable,
+ serviceUnavailableUrls,
+} from "../ci/retry-markdown-links.mjs";
-const unavailable = '* [503] <https://example.test/docs#anchor> | Service Unavailable\n';
-const missing = '* [404] <https://example.test/missing> | Not Found\n';
+const unavailable =
+ "* [503] <https://example.test/docs#anchor> | Service Unavailable\n";
+const missing = "* [404] <https://example.test/missing> | Not Found\n";
function checker(results) {
const calls = [];
- return { calls, check: async (urls) => { calls.push(urls); return results[calls.length - 1]; } };
+ return {
+ calls,
+ check: async (urls) => {
+ calls.push(urls);
+ return results[calls.length - 1];
+ },
+ };
}
-test('transient 503 recovers after more than one retry and preserves fragments', async () => {
- const { calls, check } = checker([{ status: 2, report: unavailable }, { status: 0, report: '' }]);
+test("transient 503 recovers after more than one retry and preserves fragments", async () => {
+ const { calls, check } = checker([
+ { status: 2, report: unavailable },
+ { status: 0, report: "" },
+ ]);
const waits = [];
- assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async (ms) => waits.push(ms) }), 0);
- assert.deepEqual(calls, [['https://example.test/docs#anchor'], ['https://example.test/docs#anchor']]);
+ assert.equal(
+ await retryServiceUnavailable({
+ initialReport: unavailable,
+ check,
+ wait: async (ms) => waits.push(ms),
+ }),
+ 0,
+ );
+ assert.deepEqual(calls, [
+ ["https://example.test/docs#anchor"],
+ ["https://example.test/docs#anchor"],
+ ]);
assert.deepEqual(waits, [5000, 10000]);
});
-test('persistent 503 remains a failure after bounded retries', async () => {
- const { calls, check } = checker(Array.from({ length: 3 }, () => ({ status: 2, report: unavailable })));
- assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async () => {} }), 2);
+test("persistent 503 remains a failure after bounded retries", async () => {
+ const { calls, check } = checker(
+ Array.from({ length: 3 }, () => ({ status: 2, report: unavailable })),
+ );
+ assert.equal(
+ await retryServiceUnavailable({
+ initialReport: unavailable,
+ check,
+ wait: async () => {},
+ }),
+ 2,
+ );
assert.equal(calls.length, 3);
});
-test('404 or mixed failures are not retried', async () => {
- for (const initialReport of [missing, unavailable + missing, '', '* [TIMEOUT] <https://example.test/> | Timeout\n']) {
+test("404 or mixed failures are not retried", async () => {
+ for (const initialReport of [
+ missing,
+ unavailable + missing,
+ "",
+ "* [TIMEOUT] <https://example.test/> | Timeout\n",
+ ]) {
const { calls, check } = checker([]);
- assert.equal(await retryServiceUnavailable({ initialReport, check, wait: async () => {} }), 1);
+ assert.equal(
+ await retryServiceUnavailable({
+ initialReport,
+ check,
+ wait: async () => {},
+ }),
+ 1,
+ );
assert.equal(calls.length, 0);
}
});
-test('a permanent error discovered on retry remains a failure', async () => {
+test("a permanent error discovered on retry remains a failure", async () => {
const { calls, check } = checker([{ status: 2, report: missing }]);
- assert.equal(await retryServiceUnavailable({ initialReport: unavailable, check, wait: async () => {} }), 2);
+ assert.equal(
+ await retryServiceUnavailable({
+ initialReport: unavailable,
+ check,
+ wait: async () => {},
+ }),
+ 2,
+ );
assert.equal(calls.length, 1);
});
-test('retry inputs deduplicate repeated failures without dropping URL fragments', () => {
- assert.deepEqual(serviceUnavailableUrls(unavailable.repeat(3)), ['https://example.test/docs#anchor']);
+test("retry inputs deduplicate repeated failures without dropping URL fragments", () => {
+ assert.deepEqual(serviceUnavailableUrls(unavailable.repeat(3)), [
+ "https://example.test/docs#anchor",
+ ]);
});
diff --git a/scripts/ci/retry-markdown-links.mjs b/scripts/ci/retry-markdown-links.mjs
index fe0ae89521..adf551a852 100644
--- a/scripts/ci/retry-markdown-links.mjs
+++ b/scripts/ci/retry-markdown-links.mjs
@@ -1,44 +1,74 @@
-import { readFileSync, writeFileSync } from 'node:fs';
-import { dirname, join, resolve } from 'node:path';
-import { spawnSync } from 'node:child_process';
-import { setTimeout as delay } from 'node:timers/promises';
-import { fileURLToPath } from 'node:url';
+import { readFileSync, writeFileSync } from "node:fs";
+import { dirname, join, resolve } from "node:path";
+import { spawnSync } from "node:child_process";
+import { setTimeout as delay } from "node:timers/promises";
+import { fileURLToPath } from "node:url";
/** Extract URLs only when every reported link failure is an HTTP 503. */
export function serviceUnavailableUrls(report) {
const failures = [...report.matchAll(/^\*\s+\[([^\]]+)\]\s+<([^>]+)>/gm)];
- if (!failures.length || failures.some(([, status]) => status !== '503')) return null;
+ if (!failures.length || failures.some(([, status]) => status !== "503"))
+ return null;
return [...new Set(failures.map(([, , url]) => url))];
}
/** Recheck a failed sweep without accepting unsuccessful HTTP responses. */
-export async function retryServiceUnavailable({ initialReport, check, wait = delay }) {
- const urls = serviceUnavailableUrls(initialReport);
+export async function retryServiceUnavailable({
+ initialReport,
+ check,
+ wait = delay,
+}) {
+ let urls = serviceUnavailableUrls(initialReport);
if (!urls) return 1;
- await wait(5000);
- return (await check(urls)).status;
+ let status = 1;
+ for (let attempt = 0; attempt < 3; attempt++) {
+ await wait(5000 * 2 ** attempt);
+ const result = await check(urls);
+ status = result.status;
+ if (status === 0) return 0;
+ urls = serviceUnavailableUrls(result.report);
+ if (!urls) return status;
+ }
+ return status;
}
async function main(reportPath, binary) {
- const initialReport = readFileSync(reportPath, 'utf8');
+ const initialReport = readFileSync(reportPath, "utf8");
let attempt = 0;
const status = await retryServiceUnavailable({
initialReport,
check(urls) {
const input = join(dirname(reportPath), `retry-${++attempt}.md`);
- writeFileSync(input, urls.map((url) => `- <${url}>`).join('\n') + '\n');
+ writeFileSync(input, urls.map((url) => `- <${url}>`).join("\n") + "\n");
// These URLs passed the full sweep's inclusion/exclusion rules already.
// Keep fragment checking on the retry, and require actual successful HTTP.
- const run = spawnSync(binary, [
- '--no-progress', '--max-concurrency', '4', '--include-fragments',
- '--format', 'markdown', '--output', reportPath, input,
- ], { stdio: 'inherit', timeout: 90000 });
- return { status: run.status ?? 1, report: readFileSync(reportPath, 'utf8') };
+ const run = spawnSync(
+ binary,
+ [
+ "--no-progress",
+ "--max-concurrency",
+ "4",
+ "--include-fragments",
+ "--format",
+ "markdown",
+ "--output",
+ reportPath,
+ input,
+ ],
+ { stdio: "inherit", timeout: 90000 },
+ );
+ return {
+ status: run.status ?? 1,
+ report: readFileSync(reportPath, "utf8"),
+ };
},
});
process.exitCode = status;
}
-if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+if (
+ process.argv[1] &&
+ resolve(process.argv[1]) === fileURLToPath(import.meta.url)
+) {
await main(process.argv[2], process.argv[3]);
}