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

Bound slow-mirror recovery in the DB CI package install

Claude56d65145aa8b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 15759104a0..8ed90ad57a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -651,26 +651,17 @@ jobs:
# PostgreSQL 16 client cannot dump the PostgreSQL 17 service above.
#
# The pull is ~95 ffmpeg dependency packages from the runner's mirror, and
- # a slow mirror once ate this job's whole 20-minute budget before any test
- # ran (issue #10369): single `Get:` lines stalled for 2-4 minutes. Two
- # guards, so a bad mirror costs minutes and names itself:
- # - apt's own timeout + retries drop a stalled connection and ask again,
- # which recovers the common case (one slow package) without a rerun;
- # - the step's own `timeout-minutes` fails a genuinely dead mirror here,
- # under this step's name, instead of cancelling the whole job later.
+ # a slow mirror has eaten this job's budget before any test ran (#10369,
+ # #10562): apt's retries and timeouts cannot bound a connection that
+ # trickles bytes. The script bounds the download, falls back from the
+ # runner mirror to the official Ubuntu archive with signing intact, and
+ # fails with an installation-failure annotation once its budget is spent.
+ # The step timeout stays as a backstop above the script's own budget.
- name: Install PostgreSQL client and audio verification tools
- timeout-minutes: 8
- run: |
- # Ubuntu's default repository only supplies its bundled major.
- # Use PostgreSQL's signed repository for the service's major.
- sudo install -d /usr/share/postgresql-common/pgdg
- sudo curl --fail --silent --show-error -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
- . /etc/os-release
- echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
- APT_RESILIENCE=(-o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30)
- sudo apt-get "${APT_RESILIENCE[@]}" update
- sudo apt-get "${APT_RESILIENCE[@]}" install -y postgresql-client-17 ffmpeg
- echo "/usr/lib/postgresql/17/bin" >> "$GITHUB_PATH"
+ timeout-minutes: 9
+ env:
+ PG_MAJOR: '17'
+ run: bash scripts/ci-install-db-tools.sh
- name: Run DB-backed tests (portos_test)
if: needs.impact.outputs.db == 'true'
diff --git a/scripts/ci-install-db-tools.sh b/scripts/ci-install-db-tools.sh
new file mode 100644
index 0000000000..a5374738ee
--- /dev/null
+++ b/scripts/ci-install-db-tools.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+# Installs the DB job's PostgreSQL client (matching the service's major) and
+# ffmpeg on a GitHub-hosted Ubuntu runner, within a bounded network budget.
+#
+# apt's own retries and timeouts cannot bound a connection that trickles bytes,
+# and a slow runner mirror has eaten the whole step before (#10369, #10562).
+# So the download phase runs under a wall-clock budget: the runner's mirror gets
+# APT_PRIMARY_BUDGET_SECONDS, then the Ubuntu sources are pointed at the
+# official archive and the download resumes (finished .debs stay cached) until
+# APT_TOTAL_BUDGET_SECONDS. Repository signing is untouched — only the mirror
+# URI changes, so apt still verifies every Release file against its keyring.
+# Installation then runs from the local cache with --no-download.
+#
+# APT_ROOT exists only so the contract test can run this against a fake tree.
+set -euo pipefail
+
+: "${PG_MAJOR:?PG_MAJOR must name the PostgreSQL service major}"
+ROOT="${APT_ROOT:-}"
+PRIMARY_BUDGET="${APT_PRIMARY_BUDGET_SECONDS:-180}"
+TOTAL_BUDGET="${APT_TOTAL_BUDGET_SECONDS:-390}"
+OFFICIAL_ARCHIVE='http://archive.ubuntu.com/ubuntu/'
+# The runner's Azure mirror, by URL or through its mirror list.
+RUNNER_MIRROR='(mirror\+file:/etc/apt/apt-mirrors\.txt|https?://[a-z0-9.-]+\.archive\.ubuntu\.com/ubuntu/?)'
+PACKAGES=("postgresql-client-${PG_MAJOR}" ffmpeg)
+APT_OPTS=(-o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30)
+
+fail() {
+ echo "::error title=DB tool installation failed::$1 No test ran; this is an installation failure, not a test failure." >&2
+ exit 1
+}
+
+# Runs a command with whatever remains of the budget ending at second $1.
+bounded() {
+ local remaining=$(( $1 - SECONDS ))
+ shift
+ (( remaining > 0 )) || return 124
+ timeout --kill-after=10 "$remaining" "$@"
+}
+
+download_by() {
+ bounded "$1" sudo apt-get "${APT_OPTS[@]}" update &&
+ bounded "$1" sudo apt-get "${APT_OPTS[@]}" install -y --download-only "${PACKAGES[@]}"
+}
+
+# Ubuntu's default repository only supplies its bundled PostgreSQL major.
+# Use PostgreSQL's signed repository for the service's major.
+keyring="${ROOT}/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc"
+sudo install -d "$(dirname "$keyring")"
+sudo curl --fail --silent --show-error --max-time 60 -o "$keyring" https://www.postgresql.org/media/keys/ACCC4CF8.asc
+# shellcheck source=/dev/null
+. "${ROOT}/etc/os-release"
+echo "deb [signed-by=${keyring#"$ROOT"}] https://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" |
+ sudo tee "${ROOT}/etc/apt/sources.list.d/pgdg.list" >/dev/null
+
+if ! download_by "$PRIMARY_BUDGET"; then
+ echo "⚠️ Runner mirror did not deliver packages within ${PRIMARY_BUDGET}s; switching to ${OFFICIAL_ARCHIVE}"
+ mapfile -t sources < <(grep -lE "$RUNNER_MIRROR" "${ROOT}/etc/apt/sources.list" "${ROOT}/etc/apt/sources.list.d/"*.sources 2>/dev/null || true)
+ (( ${#sources[@]} > 0 )) || fail "The runner mirror was slow and no Ubuntu source names it, so there is no mirror to replace."
+ sudo sed -i -E "s#${RUNNER_MIRROR}#${OFFICIAL_ARCHIVE}#g" "${sources[@]}"
+ download_by "$TOTAL_BUDGET" ||
+ fail "Packages did not download from the runner mirror or ${OFFICIAL_ARCHIVE} within ${TOTAL_BUDGET}s."
+fi
+
+sudo apt-get install -y --no-download "${PACKAGES[@]}" || fail "Downloaded packages did not install."
+echo "/usr/lib/postgresql/${PG_MAJOR}/bin" >> "$GITHUB_PATH"
+echo "✅ Installed ${PACKAGES[*]} in ${SECONDS}s"
diff --git a/scripts/ci-install-db-tools.test.js b/scripts/ci-install-db-tools.test.js
new file mode 100644
index 0000000000..07577e6873
--- /dev/null
+++ b/scripts/ci-install-db-tools.test.js
@@ -0,0 +1,114 @@
+import { describe, it, expect } from 'vitest';
+import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+
+const script = fileURLToPath(new URL('./ci-install-db-tools.sh', import.meta.url));
+
+const RUNNER_SOURCES = `Types: deb
+URIs: http://azure.archive.ubuntu.com/ubuntu/
+Suites: noble noble-updates
+Components: main universe
+Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
+
+Types: deb
+URIs: http://security.ubuntu.com/ubuntu/
+Suites: noble-security
+Components: main universe
+Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
+`;
+
+// Runs the real script against a fake filesystem root and a fake sudo/curl/
+// apt-get on PATH; nothing touches the host's package manager or network.
+// `mirror` decides how the fake apt-get behaves:
+// ok — every source answers promptly
+// slowRunner — anything while the runner's Azure mirror is configured stalls
+// dead — every download stalls
+function run(mirror) {
+ const dir = mkdtempSync(join(tmpdir(), 'ci-db-tools-'));
+ const bin = join(dir, 'bin');
+ const root = join(dir, 'root');
+ const sourcesFile = join(root, 'etc/apt/sources.list.d/ubuntu.sources');
+ const log = join(dir, 'calls');
+ const githubPath = join(dir, 'github_path');
+ mkdirSync(bin);
+ mkdirSync(join(root, 'etc/apt/sources.list.d'), { recursive: true });
+ writeFileSync(join(root, 'etc/os-release'), 'VERSION_CODENAME=noble\n');
+ writeFileSync(sourcesFile, RUNNER_SOURCES);
+ const fake = (name, body) => writeFileSync(join(bin, name), `#!/bin/bash\n${body}\n`, { mode: 0o755 });
+ fake('sudo', 'exec "$@"');
+ fake('curl', 'while [ $# -gt 0 ]; do [ "$1" = -o ] && echo key > "$2"; shift; done');
+ const stall = { ok: 'false', slowRunner: `grep -q azure '${sourcesFile}'`, dead: 'true' }[mirror];
+ fake('apt-get', `echo "apt-get $*" >> '${log}'\nif ${stall}; then exec sleep 30; fi`);
+
+ const result = spawnSync('/bin/bash', [script], {
+ encoding: 'utf8',
+ env: {
+ PATH: `${bin}:${process.env.PATH}`,
+ APT_ROOT: root,
+ APT_PRIMARY_BUDGET_SECONDS: '1',
+ APT_TOTAL_BUDGET_SECONDS: '3',
+ PG_MAJOR: '17',
+ GITHUB_PATH: githubPath,
+ },
+ });
+ const read = (file) => readFileSync(file, { encoding: 'utf8', flag: 'a+' });
+ const out = {
+ ...result,
+ calls: read(log).split('\n').filter(Boolean).map((line) => line.replace(/ -o \S+/g, '')),
+ sources: read(sourcesFile),
+ pgdg: read(join(root, 'etc/apt/sources.list.d/pgdg.list')),
+ githubPath: read(githubPath),
+ };
+ rmSync(dir, { recursive: true, force: true });
+ return out;
+}
+
+const INSTALL_FROM_CACHE = 'apt-get install -y --no-download postgresql-client-17 ffmpeg';
+
+describe.skipIf(process.platform === 'win32')('CI DB tool installation', () => {
+ it('installs the service-major client from the signed PostgreSQL repository', () => {
+ const result = run('ok');
+ expect(result.status).toBe(0);
+ expect(result.pgdg).toBe('deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt noble-pgdg main\n');
+ expect(result.calls).toEqual([
+ 'apt-get update',
+ 'apt-get install -y --download-only postgresql-client-17 ffmpeg',
+ INSTALL_FROM_CACHE,
+ ]);
+ expect(result.sources).toBe(RUNNER_SOURCES);
+ expect(result.githubPath).toBe('/usr/lib/postgresql/17/bin\n');
+ });
+
+ it('recovers from a stalled runner mirror through the official archive, keeping signing', () => {
+ const result = run('slowRunner');
+ expect(result.status).toBe(0);
+ expect(result.stdout).toContain('switching to http://archive.ubuntu.com/ubuntu/');
+ expect(result.sources).toBe(RUNNER_SOURCES.replace('azure.archive.ubuntu.com', 'archive.ubuntu.com'));
+ expect(result.calls).toEqual([
+ 'apt-get update',
+ 'apt-get update',
+ 'apt-get install -y --download-only postgresql-client-17 ffmpeg',
+ INSTALL_FROM_CACHE,
+ ]);
+ expect(result.githubPath).toBe('/usr/lib/postgresql/17/bin\n');
+ });
+
+ it('fails as an installation failure once the whole budget is spent', () => {
+ const result = run('dead');
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain('::error title=DB tool installation failed::');
+ expect(result.stderr).toContain('within 3s');
+ expect(result.calls).not.toContain(INSTALL_FROM_CACHE);
+ expect(result.githubPath).toBe('');
+ });
+
+ it('installs the client major of the DB job\'s PostgreSQL service', () => {
+ const workflow = readFileSync(fileURLToPath(new URL('../.github/workflows/ci.yml', import.meta.url)), 'utf8');
+ const serviceMajor = workflow.match(/image: pgvector\/pgvector:pg(\d+)@/)?.[1];
+ expect(serviceMajor).toBeTruthy();
+ expect(workflow).toMatch(new RegExp(`PG_MAJOR: '${serviceMajor}'\\n\\s+run: bash scripts/ci-install-db-tools\\.sh`));
+ });
+});