Skip to content

fix(daemon): skip a scheduled update run when every source is unreachable - #472

Merged
bketelsen merged 3 commits into
mainfrom
fix/471-skip-unreachable-runs
Oct 26, 2026
Merged

bketelsen merged 3 commits into
mainfrom
fix/471-skip-unreachable-runs

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

Fixes #471 (Brian's decision T256b, 2026-10-26: option 2).

A scheduled updex features update run whose sources are all unreachable is now a skip: it logs one line and exits 0, so updex-update.service does not stay failed (and the system degraded) for up to 6 h on an offline laptop. Any other failure still fails the unit.

Definition (updex/unreachable.go, UpdateFeatures): the error wraps the new updex.ErrSourcesUnreachable only when

  1. at least 1 transfer failed;
  2. no HTTP request of the run got a response of any status (per-run sourceTracker in the context; NewClient installs sourceTrackerTransport on a shallow copy of its HTTP client — Timeout, CheckRedirect, Jar kept, caller's client untouched, CloseIdleConnections forwarded);
  3. every transfer error except the collateral not linked: another transfer … failed is unreachable: *net.DNSError, a *net.OpError with Op == "dial", ECONNREFUSED/EHOSTUNREACH/ENETUNREACH/ENETDOWN, or a net.Error timeout (no response, per rule 2);
  4. the run context is live; 5. no refresh failed. It also requires that a request was attempted (a replaced transport fails closed).

CLI: only under systemd (INVOCATION_ID, as the existing ErrBusy skip): the normal output (table or --json array) is printed, then updex: no update source is reachable; skipping this run on stderr, exit 0. An interactive run still exits non-zero. The units do not change (DaemonUnits(), units_hook_contract_test.go untouched).

ADR: new ADR-0018 amends ADR-0016's exit rule ("exits non-zero when any enabled feature failed"); ADR-0016 is Accepted and immutable, so its text is not edited.

Checks

  • make fmt
  • make ci — tidy, vet, gofmt, golangci-lint 0 issues, unit/E2E/race tests, coverage 90.0% (baseline 90.0, floor 89.5), linux amd64/arm64 builds
  • go test ./cmd/updex ./tests/e2e/...
  • New tests: isUnreachable table; SDK: all unreachable (DNS fake transport, refused loopback port) → wrapped; 1 reachable + 1 unreachable, a 404/500 source, a hash/signature failure, a cancelled run, a refresh failure, a replaced transport → not wrapped; no errors → nil. CLI: all unreachable under systemd → exit 0 + 1 line; partial → error; verification failure → error; interactive → error; --json under systemd → 1 array, exit 0.

Risk classification

  • Tier 1: Low
  • Tier 2: Moderate
  • Tier 3: High
  • Tier 4: Critical

Rationale:

  • It changes the HTTP client that carries manifest and image downloads (a wrapper that only observes; requests, verification and hashes are unchanged) and the failure contract of a root-run daemon that operators monitor.
  • Trust boundary / abuse: an attacker who can only block traffic can already stop updates; now that is silent in the unit state, but the per-transfer warnings still reach the journal. An attacker who can answer (captive portal, interception, TLS/x509 error, proxy 502) gets a response or a non-dial error, so the run still fails. Negative consequence recorded in ADR-0018: a source host name that is wrong for ever (DNS not found) also looks offline to the timer; features update in a shell and features check still fail.
  • Rollback: revert this PR; no on-disk state or unit changes.

Docs housekeeping

  • README.md, docs/design/overview.md, docs/specs/sdk-api.md, AGENTS.md
  • ADR-0018 from TEMPLATE.md, indexed in docs/README.md
  • Conformance aliases untouched

Verification

  • node scripts/check-docs.mjs green
  • Checked against the PR review rubric

…able

UpdateFeatures wraps the new updex.ErrSourcesUnreachable when at least one
transfer failed, every own transfer error is a DNS, dial or pre-response
timeout failure, no HTTP request of the run got a response, the run context
is live and no refresh failed. A per-run tracker in the context, read by a
transport wrapper NewClient installs on a copy of its HTTP client, records
whether a source answered.

Under systemd, features update prints its normal output, logs one line and
exits 0, so updex-update.service does not stay failed while a host is
offline. Partial failures, error statuses, verification failures and an
interactive run still fail. ADR-0018 amends the exit rule of ADR-0016.

Fixes #471
@github-actions github-actions Bot added documentation Improvements or additions to documentation go Pull requests that update go code labels Oct 26, 2026
…d CancelRequest

Cross-review findings on #472:
- a dial that fails for a local reason (EMFILE, EACCES, ENOBUFS) no longer
  counts as unreachable; ETIMEDOUT does
- the transport wrapper forwards CancelRequest to a base that is not an
  *http.Transport, so a client timeout still cancels a legacy transport
- ADR-0018 and the docs say the skip adds one line after the run's usual
  warnings, which stay live in the journal; the CLI test reads both stderr
  routes with the reporter on

Coverage rose to 90.1%: bump the baseline.
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.24390% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/updex/features_run.go 64.70% 3 Missing and 3 partials ⚠️
updex/unreachable.go 95.91% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 26, 2026
@bketelsen
bketelsen added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit c8d70c8 Oct 26, 2026
19 checks passed
@bketelsen
bketelsen deleted the fix/471-skip-unreachable-runs branch October 26, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation go Pull requests that update go code ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

daemon: a failed update run stays failed until the next successful run

2 participants