Skip to main content

CI registry corruption recovery

Owner: devops-engineer. Tracking: core#3432, core#3643, core#4447; affected PR core#3431, run 35015944268. This is an operator procedure, not a record of completed repair. Recurring short read … expected 32 bytes on hetzner slots: start at §6. The durable fix is §5.

Evidence and scope​

On 2026-09-16 at approximately 09:26 UTC the mirror returned HTTP 200 and Content-Length 32 for library/golang blob sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1, but the body was empty (SHA-256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855). The new probe reproduced this. Direct Docker Hub retrieval returned the correct 32 bytes and expected digest. This is ongoing mirror corruption, not merely a historical cache problem.

Affected run attempt 2 failed Compose Smoke Test on slot 4. The fleet still had 12 active units at inspection. Discover the fleet at execution time; do not assume eight slots from the older runbook. Resizing remains separate (#3312).

Root authority is required. AGENTS.md prohibits agents using sudo; an explicit founder exception or a human operator is required before executing host changes. Do not use a privileged CI job to bypass that boundary.

1. Inventory and drain (operator with root authority)​

Record UTC time, unit enablement, Restart settings, CPU/memory properties, images, runner registrations/busy state, DinD names/mounts, builder drivers and volumes. Do not print runner environment files or minting credentials.

Read /usr/local/sbin/upsquad-runner-slot.sh first: confirm ephemeral one-job exit and what cleanup removes. Current documentation says /data/dind/N is wiped after each job; privileged inspection must confirm it. Check for shared buildx volumes.

For every discovered upsquad-runner@N.service, create a uniquely named runtime drop-in /run/systemd/system/upsquad-runner@N.service.d/90-registry-recovery.conf:

[Service]
Restart=no

Run systemctl daemon-reload, then verify Restart=no on EVERY inventoried unit. This prevents respawning after the current ephemeral runner exits; it does not stop any container or cancel a job. A listener that has not yet accepted its one job may accept one final job. Wait for every unit to exit naturally, including ExecStopPost cleanup. Do not stop/restart active runner units or Docker itself.

If an idle listener never receives a job, leave it alone and arrange a normal harmless job through the existing workflow mechanism. Do not replace the wait with a timeout that kills the listener. Record the terminal jobs and confirm no Runner.Worker/build processes remain. Units must be inactive/failed with no start/stop jobs pending before storage maintenance.

If cleanup destroys each sidecar and wipes its private Docker store, record that as a full cache reset for that slot (pruning a vanished daemon is meaningless). For any retained, verified idle sidecar, run and record:

docker exec upsquad-dind-N docker builder prune -af
docker exec upsquad-dind-N docker buildx ls

If a non-default docker-container builder is used, prune that builder explicitly with docker buildx prune --builder NAME -af in its owning daemon, or remove only its positively identified cache volume once all users are stopped. Do not run global docker system/volume prune. Keep a per-slot coverage table: slot, daemon, cache backing store, prune result or verified cleanup removal. No uncovered slot.

2. Reset mirror storage​

With the fleet fully drained, verify the live mirror container mounts exactly /data/registry-cache at /var/lib/registry. Stop only upsquad-registry-cache.service. Verify its container is gone and no process/container still mounts that directory. Quarantine the storage on the same filesystem instead of deleting evidence:

set -eu
stamp=$(date -u +%Y%m%dT%H%M%SZ)
quarantine="/data/registry-cache.corrupt-${stamp}"
test ! -e "$quarantine"
test -d /data/registry-cache
test ! -L /data/registry-cache
mv -- /data/registry-cache "$quarantine"
install -d -m 0755 /data/registry-cache
chown --reference="$quarantine" /data/registry-cache
chmod --reference="$quarantine" /data/registry-cache
systemctl start upsquad-registry-cache.service
python3 /path/to/reviewed/scripts/check-ci-registry-blob.py

The new directory preserves the old ownership/mode. Starting the mirror refills from upstream. Require exit 0 from the digest probe. On failure leave runners drained and inspect mirror logs and upstream reachability. Never silently restore known-corrupt storage. After successful recovery, deletion of the recorded quarantine is a separate explicit cleanup decision; it costs no extra copy space while diagnosing.

3. Clean build and resume​

Use one drained slot's verified preparation path to create its DinD sidecar without starting its GitHub listener. Inspect the live helper before invoking it; do not invent helper options. Alternatively use a disposable verification sidecar with the same pinned image, network/mirror configuration and resource limits. Build inside that slot's normal client environment with the source at 8a99a3eb879e557b02feab6a9d29ba614b11d601 (the failed run's head):

docker compose -f docker-compose.dev.yml build --no-cache agent-orchestrator

Record slot, source SHA, daemon ID, image digest, build duration and exit status. Do not put bot credentials or the host Docker socket in the build container. The normal workflow sets COMPOSE_FILE=docker-compose.dev.yml and builds agent-orchestrator plus agent-worker; use its environment if additional variables are needed. Remove the temporary verification resources after recording evidence.

Only once the mirror probe and clean build pass, remove ONLY the recovery drop-ins created above, daemon-reload, verify original Restart settings, and start the originally active slots. Preserve their images, CPU pins, memory limits and enablement. Verify online registrations and completed real jobs.

With the devops bot, request the user-authorized rerun:

gh api -X POST repos/upsquad-ai/upsquad-core/actions/runs/35015944268/rerun-failed-jobs
gh api 'repos/upsquad-ai/upsquad-core/actions/runs/35015944268/jobs?per_page=100' \
--paginate --jq '.jobs[] | [.name,.status,.conclusion,.runner_name,.html_url] | @tsv'

Require a new attempt with Compose Smoke Test completed/success and verify its build step actually ran. Do not claim success from a skipped job or old attempt.

4. Install the probe​

From the reviewed checkout on the CI host, as the authorized operator:

install -d -m 0755 /usr/local/lib/upsquad-ci
install -m 0644 scripts/check-ci-registry-blob.py /usr/local/lib/upsquad-ci/
install -m 0644 scripts/systemd/upsquad-registry-probe.service /etc/systemd/system/
install -m 0644 scripts/systemd/upsquad-registry-probe.timer /etc/systemd/system/
systemctl daemon-reload
systemctl start upsquad-registry-probe.service
# Refuse to overwrite any pre-existing collector entry; inspect it instead.
test ! -e /var/lib/node_exporter/textfile/upsquad_registry.prom
test ! -L /var/lib/node_exporter/textfile/upsquad_registry.prom
ln -s /var/lib/upsquad-registry-probe/registry.prom \
/var/lib/node_exporter/textfile/upsquad_registry.prom
systemctl enable --now upsquad-registry-probe.timer
curl -fsS http://127.0.0.1:9100/metrics | grep upsquad_registry_blob

The service runs as the existing prometheus user, has no Docker/root credential, and writes atomically to its own StateDirectory. The collector symlink follows atomic replacements. The systemd 20-second deadline bounds slow responses.

Deploy dev/prometheus/rules/ci-registry.yml through the existing dev Prometheus configuration/reload procedure. Its configured rules/.yml glob loads the file. Verify the live /api/v1/rules contains both CIBoxRegistryBlobInvalid and CIBoxRegistryProbeStale and /api/v1/query sees fresh upsquad_registry_blob_ series with job="ci-box". A checked-in file alone is not deployed monitoring. If the ci-box scrape is missing, record that blocker; absence of alerts is not proof.

Check twice at least 60 seconds apart: digest result 1 and advancing timestamp. The invalid rule fires after 2 minutes of failure; the stale rule catches a probe older than 180 seconds or missing on a reachable ci-box target after 2 minutes. This probes a known canary, not every blob; other corruption can still require storage reset. Redirects fail deliberately: this local filesystem mirror must serve the bytes itself, not send the probe straight to a healthy upstream.

5. Durable fix: registry:3 with proxy expiry disabled (#4447)​

The mirror ran the unpinned registry:2 tag (Distribution 2.8.3). That version hard-codes a 7-day proxy TTL and has no setting to turn it off. Its expiry deletes a blob that other repositories still link to (§6). The fix is one config file and one systemd drop-in, both in deploy/ci-runner/:

FileInstalled at
upsquad-registry-cache.yml/etc/upsquad-ci/registry-cache.yml
upsquad-registry-cache.service.d/50-registry-v3.conf/etc/systemd/system/upsquad-registry-cache.service.d/
scripts/check-ci-registry-blob.py (widened probe)/usr/local/lib/upsquad-ci/
scripts/systemd/upsquad-registry-probe.service (adds --registry-root)/etc/systemd/system/

What the config changes, and the source for each setting:

  • proxy.ttl: 0. Distribution v3.1.2 docs/content/about/configuration.md, proxy table: "Expire proxy cache configured in "storage" after this time. Cache 168h(7 days) by default, set to 0 to disable cache expiration". In registry/proxy/proxyregistry.go (v3.1.2) a TTL of 0 means the expiration scheduler is never constructed. scheduler-state.json is then never read, and no expiry ever deletes anything. The key first shipped in v3.0.0-alpha.1. It is absent from 2.8.3, where REGISTRY_PROXY_TTL=0 is silently ignored (#3643, 2026-09-30).
  • No storage.cache.blobdescriptor. With the in-memory descriptor cache, a blob file that disappears for any reason keeps being reported present, so the mirror serves HTTP 200 with zero bytes until restarted. Without the cache, the next request refills the blob from upstream.
  • storage.delete.enabled: false. Defense in depth. If a finite TTL is ever reintroduced, expiry fails instead of deleting shared blobs.
  • Image registry:3.1.2@sha256:82f6ff4a…bc3c, pinned by digest.

Measured on the pinned image on 2026-11-13, against the real Docker Hub upstream, with the 4f4fb700… layer linked from library/golang and library/redis, and a carried-over scheduler-state.json whose redis entry had already expired:

ConfigurationExpired entry at startBlob file deleted under a running process
v3, default TTL, in-memory cacheblob deleted; library/golang then served 200 with 0 bytesstays at 0 bytes
v3, ttl: 0, in-memory cacheinert; blob intact, 32 correct bytesstays at 0 bytes
v3, ttl: 0, no cache (shipped)inert; blob intactnext GET refills it; 32 correct bytes

Apply (founder or vaisakh/ciops with sudo, on the box)​

  1. Drain or confirm idle: every hetzner-ci-1-slot-* must read busy=false in GET /repos/upsquad-ai/upsquad-core/actions/runners (or drain as in §1). The restart takes seconds. A pull in flight at that moment fails the same way it fails today.

  2. From a checkout of the reviewed commit on the box:

    bash deploy/ci-runner/apply-registry-cache-v3.sh --check
    sudo bash deploy/ci-runner/apply-registry-cache-v3.sh --apply --confirm-idle

There is no git checkout on upsquad-ci-1 (verified 2026-11-14: find /opt /srv /home /root /data -maxdepth 4 -name .git returns nothing), so step 2 has nothing to git pull. Ship the reviewed paths instead, and do not put repo credentials on the CI box:

# on the devbox, from a checkout at the reviewed commit
git archive --format=tar -o /tmp/registry-v3.tar "$SHA" -- \
deploy/ci-runner scripts/check-ci-registry-blob.py \
scripts/systemd/upsquad-registry-probe.service
scp -i ~/.ssh/id_ed25519_ci_runner /tmp/registry-v3.tar ciops@62.238.87.30:
# on the box: extract into a fresh dir named for the commit, then sha256sum
# each file and compare with the devbox before running anything.

--check is read-only. It prints the live unit's ExecStart and the drop-in's, then compares the container name, the published ports and the store volume. It refuses (exit 3) if they differ. In that case, update the drop-in in the repo to match the live publish/volume, get it reviewed, and re-run. Never edit the drop-in on the box.

It also compares the live REGISTRY_PROXY_REMOTEURL with the reviewed config's proxy.remoteurl and refuses if they differ, because the drop-in carries no -e options and --apply would otherwise silently repoint the mirror. That used to be a manual item on this checklist; it is now enforced (#4480). Env vars the config owns outright are accepted and superseded — REGISTRY_STORAGE_DELETE_ENABLED=true is live on the box and the config sets storage.delete.enabled: false on purpose.

--apply takes these steps:

  1. Pre-pulls the pinned image while the old mirror is still serving.
  2. Installs the four files at mode 0644, runs daemon-reload, and refuses unless the unit now runs the pinned image.
  3. Restarts the mirror, waits for /v2/, and checks the running container's image.
  4. Requests every dangling reference the probe reports through the normal pull-through API, which refills it.
  5. Re-runs the probe, then starts upsquad-registry-probe.service as the prometheus user.

Exit 4 means the mirror is up but verification failed. The cause is printed.

Verify​

python3 /usr/local/lib/upsquad-ci/check-ci-registry-blob.py --registry-root /data/registry-cache
# OK: library/golang sha256:4f4fb700…, 32 bytes
# OK: store scan {... "dangling_links": 0, "dangling_scheduler_entries": 0, "scan_ok": 1 ...}
# `residue_dirs` counts empty `_layers`/`_manifests` digest directories whose
# `link` a 2.8 expiry removed. They reference nothing, so they are counted and
# not an error; 258 of them predate the move to v3. A non-empty directory with
# no `link` is still a failed scan.
docker exec upsquad-registry-cache registry --version # .../v3 3.1.2
stat -c '%y' /data/registry-cache/scheduler-state.json 2>/dev/null || echo absent
# the mtime must NOT advance from here on: v3 with ttl 0 never writes it
for n in $(seq 1 8); do # one per slot bridge gateway; re-derive the slot count (§1)
curl -s http://10.202.$n.1:5001/v2/library/golang/blobs/sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 | sha256sum
done # each 4f4fb700…acc1

Then confirm with real jobs. The next Container Image Scan / Compose Smoke Test on a hetzner slot, and the nightly db.yml, must show the image pulls executed and green. On the devbox, upsquad_registry_store_scan_ok must read 1 and CIBoxRegistryStoreScanFailed must resolve.

Rollback​

sudo bash deploy/ci-runner/apply-registry-cache-v3.sh --rollback --confirm-idle

This removes the drop-in, stops the mirror, and moves scheduler-state.json aside before registry:2 starts. That move is the step that must not be skipped. 2.8.3 reads the file at startup and fires every entry whose expiry passed while v3 was running all at once, and each fired entry deletes a shared blob. The rollback brings back the 7-day defect in §6. The config file and the widened probe stay in place; both are harmless under v2.

6. Fault class: shared-blob expiry (#3643, #4447; upstream distribution#2367)​

Symptom. Jobs on every hetzner slot fail pulling or building images with short read: expected 32 bytes but got 0: unexpected EOF, under both docker pull and BuildKit failed to compute cache key. Hosted runners are unaffected because they pull straight from Docker Hub. Seen 2026-09-16/23/26/30, 10-22, 11-02, 11-07 and 11-12 (4f4fb700… 32 B, 4abcf206… 3,408,729 B, 6b37362b…, ecc510c1…).

Mechanism. Distribution 2.8's proxy scheduler keeps one 7-day entry per repository@digest, but a blob file is stored once, globally. When any one repository's entry expires, the blob file is deleted. Other repositories still hold links and live entries for it. The in-memory descriptor cache keeps reporting the blob as present, so the mirror answers 200 with the right Content-Length and sends no bytes. Docker Hub refuses the digest under repositories that never contained it, so only a repository that genuinely has the layer, and has no stale link, can refill it.

Measure (read-only, ciops):

python3 /usr/local/lib/upsquad-ci/check-ci-registry-blob.py --registry-root /data/registry-cache
# FINDING: dangling link <repo>@sha256:<d> (...) <- every reference to a missing blob
curl -sS -o /dev/null -D - http://127.0.0.1:5001/v2/library/golang/blobs/sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1
# "curl: (18) transfer closed with 32 bytes remaining" + "HTTP/1.1 200 OK" = this fault
stat /data/registry-cache/docker/registry/v2/blobs/sha256/4f/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1/data
ls -l --time-style=+%FT%T /data/registry-cache/docker/registry/v2/repositories/*/*/_layers/sha256/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1/link
python3 - <<'PY'
import json
s = json.load(open("/data/registry-cache/scheduler-state.json"))
for k, v in sorted(s.items(), key=lambda kv: kv[1]["ExpiryData"]):
if "4f4fb700" in k:
print(k, v["ExpiryData"])
PY

On the devbox, upsquad_registry_blob_ok{job="ci-box"} (dev Prometheus, 127.0.0.1:9092) dates the break to the minute. Needing sudo: sudo docker logs --since 36h upsquad-registry-cache 2>&1 | grep -E '4f4fb700|Deleting|expir' names the repository whose expiry did the deleting.

Immediate repair on registry:2 (sudo, slots idle). sudo systemctl restart upsquad-registry-cache.service. This clears the stale descriptor, and the next GET refills the blob from upstream under a repository that has it. Verify with the probe and the per-gateway loop in §5. If the probe still fails, request the digest under a repository that genuinely contains the layer and has no link to it yet (the 2026-10-22 refill method in #3643), or fall back to the quarantine reset in §2.

The expiry-date trap. A restart on registry:2 repairs only until the next live entry expires, and that date is predictable. Read every entry, not just the canary's. The snippet above filters on 4f4fb700, which answers "when does the canary break again" and not "when does the box break again" — and the difference is days. Filtering to the canary on 2026-11-13 gave 2026-11-17 19:09Z (library/redis) and 2026-11-18 20:06Z (library/golang), and that pair was recorded on #4447 as the deadline. The real next expiry was 2026-11-14T17:32:26Z (pgvector/pgvector), three days earlier, with 22 entries firing that day. Read the whole file:

sudo python3 - <<'PY'
import collections, json
s = json.load(open("/data/registry-cache/scheduler-state.json"))
c = collections.Counter(v["ExpiryData"][:10] for v in s.values())
for day in sorted(c):
print(f"{day} {c[day]:>4}")
print("earliest:", min(v["ExpiryData"] for v in s.values()))
PY

Measured 2026-11-14 (253 live entries): 22 on 11-14, 10 on 11-15, 1 on 11-16, 32 on 11-17, 124 on 11-19, 62 on 11-20. A green probe after a restart is not a fix. Only §5 removes the mechanism.

7. Store growth and cleanup​

With proxy.ttl: 0 nothing is ever deleted automatically. The store was 6.6 GB (339 blobs) on 2026-11-13 against 755 GB free on /data. CIBoxRegistryStoreLarge warns above 30 GiB (upsquad_registry_store_blob_bytes), and CIBoxDiskLow is the emergency signal for /data itself. Reclaiming space is a drained maintenance step: the §2 quarantine reset. Move the store aside and start empty; it refills on demand. Do not run registry garbage-collect against a pull-through store without testing it on a copy first. Its interaction with proxy-cached manifests has not been measured here. Do not set a finite proxy.ttl again until a released Distribution contains the shared-blob fix (distribution#4872, unmerged as of 2026-11-13).

8. Alert routing​

Rules: dev/prometheus/rules/ci-registry.yml, routed by dev/alertmanager/alertmanager.yml to Discord (DISCORD_WEBHOOK_URL, the same webhook Grafana uses). Before #4447 dev Prometheus had no Alertmanager, and CIBoxRegistryBlobInvalid fired unseen for 11 hours.

AlertFires whenSeverity
CIBoxRegistryBlobInvalidcanary blob wrong or empty, 2mcritical
CIBoxRegistryProbeStaleprobe result older than 180 s or missing, 2mwarning
CIBoxRegistryDanglingReferenceany link or live scheduler entry points at a missing blob, 2mcritical
CIBoxRegistryStoreScanFailedstore scan failed, or the box runs a probe without --registry-root, 5mwarning
CIBoxRegistryStoreLargestore > 30 GiB, 30mwarning

Only component="ci-box" alerts notify, which covers every rule in ci-box.yml and ci-registry.yml. Other rule families route to unrouted until someone decides to page on them. CIBoxRegistryStoreScanFailed fires from the moment the rules are loaded until §5 is applied on the box. That is intended: it says the reference check is not yet running.

Known firing alert on first deploy. CIBoxRunnerRegistrationMetricsUnavailable (ci-box.yml) has been firing since 2026-10-15 and is component="ci-box", so Discord receives it every 4 h from the moment routing goes live. It needs an owner or an Alertmanager silence; the coordinator files the issue. Do not fix it by narrowing the route.

Rendering the dev compose file locally needs the knowledge image tag exported (UPSQUAD_KNOWLEDGE_IMAGE_TAG=<tag> docker compose -f docker-compose.dev.yml config); without it the pre-existing :? guard refuses.

Devbox deployment: on merge, the reconciler creates upsquad-alertmanager. Prometheus reads its new alerting: block only on reload:

curl -sSf -X POST http://127.0.0.1:9092/-/reload
curl -s http://127.0.0.1:9092/api/v1/alertmanagers # activeAlertmanagers must list alertmanager:9093
docker exec upsquad-alertmanager amtool --alertmanager.url=http://127.0.0.1:9093 alert query

Verification and audit​

python3 -m unittest tests.scripts.test_check_ci_registry_blob tests.scripts.test_apply_registry_cache_v3 -v
bash tests/scripts/test_ci_registry_alerts.sh
systemd-analyze verify scripts/systemd/upsquad-registry-probe.service scripts/systemd/upsquad-registry-probe.timer

Record on #3431: UTC start/end, operator, per-slot cache coverage, mirror storage quarantine path, before/after blob hashes, clean build evidence, rerun URL/attempt/ job conclusion, installed probe commit and live alert/metric checks. Keep #3432 open until deployment, actual clean build, and rerun evidence are complete.