Skip to content

fix(sysext): guard SHA256SUMS writes with ETags and add opt-in retention - #104

Merged
bketelsen merged 6 commits into
mainfrom
fix/102-sysext-sums-race
Nov 13, 2026
Merged

bketelsen merged 6 commits into
mainfrom
fix/102-sysext-sums-race

Conversation

@frostyard-machines

Copy link
Copy Markdown

Summary

Closes #102.

snosi will publish the sysexts of 2 Debian suites (_13_ trixie, _14_ forky) into the same ext/<name>/ with 1 SHA256SUMS (core Plan 0009 Phase 6). This PR closes the 2 gaps of #102. The decision is recorded in ADR-0019.

  1. Lost-update guard (sysext only). scripts/sync-sysext-metadata.sh restores ext/<name>/SHA256SUMS and SHA256SUMS.gpg with aws s3api get-object and records the ETag of exactly the bytes it wrote (never an ETag read after the download). scripts/upload-to-r2.sh phase 3b writes each changed manifest, then its signature, with --if-match <etag>, or --if-none-match '*' for a new file. R2 evaluates these headers atomically on PutObject (R2 S3 API, conditional operations). A 412 stops the run with ::error::; no metadata of the run replaces the other publisher's. An unchanged manifest is not written. An aws CLI without the flags fails loud; it never writes without the condition. ADR-0017's order stays: payloads, metadata, guarded manifests, indexes.
  2. Publishers must still serialize. The guard turns an unserialized race into a failed run, not lost entries. The ADR names the remaining window: a manifest written whose signature write then gets a 412 leaves a mismatched pair until a rerun; repogen and updex both refuse a mismatched pair (fail closed). ext/index is not guarded.
  3. Retention, opt-in, default off. New action input sysext-keep-versions (CLI --sysext-keep-versions, --pruned-report). 0 (the default) keeps every version: nothing is pruned, as today. With N > 0, SHA256SUMS keeps the newest N versions per (name, OS version, arch), in systemd-sysupdate's version order (a port of strverscmp_improved()), so trixie files never push forky files out. A new last step deletes a pruned payload only after the upload and the cache purge succeeded, and only when the live SHA256SUMS no longer lists it.

Other package types upload exactly as before (METADATA_ETAGS unset).

Checks

  • make check — green
  • make ci — CI run below (the Docker package build is not run locally)
  • Generator changes: make test-unit green; integration unchanged by this PR

Risk tier

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

Rationale: the PR touches publication paths in .github/risk-paths.json:

  • .github/actions/publish-to-r2/** (L1): the sync step calls the new restore script, the upload step sets METADATA_ETAGS for sysext only, and 1 new step deletes pruned payloads. Safe: other package types are unchanged (TestUploadWithoutGuardKeepsOtherPackageTypesUnchanged); the delete step runs only when sysext-keep-versions is not 0 and every earlier step passed.
  • scripts/upload-to-r2.sh, scripts/sync-sysext-metadata.sh, scripts/delete-pruned-payloads.sh (L1): the write guard and the delete. Safe: a malformed state file, a missing signature beside a published one, a deeper path, or an old aws CLI all fail before or instead of an unconditional write; the delete re-reads the live manifest and refuses a listed file.
  • internal/generator/sysext/**, internal/cli/generate.go (L1): retention. Safe: default 0 prunes nothing (TestRetentionOffKeepsEveryVersion, TestGenerateSysextKeepVersionsDefaultPrunesNothing); signing is unchanged.
  • .github/risk-paths.json (L2): adds the 2 new scripts at L1.
  • internal/releaseasset/** (L2): new contract tests only.

Docs housekeeping

  • New ADR-0019 started from TEMPLATE.md, indexed in docs/README.md
  • docs/design/ci-cd.md, docs/guides/publish-to-r2.md, docs/guides/usage.md, docs/specs/generators.md, AGENTS.md, README.md updated

Verification

  • node scripts/check-docs.mjs green (31 docs, 305 links)
  • make lint: 0 issues; go test ./... green; shellcheck scripts/*.sh clean
  • Tests that fail without the fix (scripts reverted in a scratch worktree): TestSyncSysextMetadata* (2), TestUploadGuard* (8), TestDeletePrunedPayloads* (4), TestPublishActionGuardsSysextMetadataAndPrunesLast; with retention removed: TestRetentionKeepsNewestVersionPerOSVersion, TestRetentionDropsIncomingVersionOlderThanKept, TestRetentionKeepsTwoNewest, TestGenerateSysextKeepVersionsWritesPrunedReport.
  • Not tested: real R2. The fake aws follows R2's documented 412 behavior; the first real sysext publish after merge is the live check.

Two publishers of one bucket (the trixie and forky sysext builds) restore,
merge and write back the same ext/<name>/SHA256SUMS. The write had no
condition, so the later run dropped the entries of the earlier one.

- sync-sysext-metadata.sh restores ext/ and records the ETag of each
  SHA256SUMS and SHA256SUMS.gpg it downloaded with get-object.
- upload-to-r2.sh, with METADATA_ETAGS set (sysext only), writes each
  changed manifest and then its signature with --if-match on that ETag, or
  --if-none-match '*' for a new one; a 412 fails the run before any other
  manifest or index. Other package types upload as before.
- --sysext-keep-versions N (default 0, nothing pruned) keeps the newest N
  versions per name, OS version and arch, in systemd-sysupdate version order,
  and --pruned-report lists the dropped payloads.
- delete-pruned-payloads.sh deletes a pruned payload only after the upload and
  only when the live SHA256SUMS no longer lists it.

Refs #102
Publishers of one bucket must still serialize; the conditional write turns an
unserialized race into a failed run. Nothing is pruned by default.

Refs #102
@github-actions github-actions Bot added level:L1 Read every line risk:high Touches a high-risk path (ADR-0068) labels Nov 13, 2026
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.96104% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/generator/sysext/generator.go 82.69% 6 Missing and 3 partials ⚠️
internal/cli/generate.go 66.66% 3 Missing and 4 partials ⚠️
internal/generator/sysext/version.go 98.76% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…2 as a conflict

- sync-sysext-metadata.sh no longer creates an empty ext/: the generator reads
  an existing ext/ strictly and failed a first publish with "no existing
  sysext packages found". An ext/ with any restored file stays, so a
  malformed published repository still fails closed.
- upload-to-r2.sh compares the object with the local bytes only after an
  ambiguous attempt (no response or another error). A 412 on the first
  attempt is a conflict even over identical bytes, so no signature follows it.
- compareVersions has no shortcut for an empty string, like upstream systemd;
  tests pin systemd's documented order and its edge cases.

Refs #102
@frostyard-machines

Copy link
Copy Markdown
Author

Cross-review record

  • Coder: anthropic/claude-opus-5-5. Reviewer: openai/gpt-6.1-sol (read-only).
  • Initial review at f64976f522a8fbc99f3856fb7617e8d424044cbb (base 4349d7d4c6bb782909831646fa51aa8ea93dd222), all 21 files in 3 batches: Not ready, 3 blocking findings.
    1. version.go tilde order vs systemd: withdrawn by the reviewer after upstream evidence: systemd src/fundamental/string-util.c at 74d392ed1bab578e901699ee272faa0c8b922128 returns CMP(*a, *b) after both ~ are consumed, so 1~~ > 1~ there too. Expected-order tests added anyway (TestCompareVersionsMatchesSystemdDocumentedOrder, TestCompareVersionsUpstreamEdgeCases), and the empty-string shortcut now follows upstream.
    2. First publish to an empty bucket created ext/ and the strict reader failed: fixed in 08e8e94; guard TestFirstPublishRestoreGenerateUpload, record .memory/corrections/2026-11-13-pr-104-first-publish-ext.json.
    3. A first-attempt 412 over identical bytes continued to the signature write: fixed in 08e8e94; guard TestUploadGuardFirstAttemptConflictWithIdenticalBytesFails, record .memory/corrections/2026-11-13-pr-104-first-412-conflict.json.
  • Re-review 1 of 3 at d2c89b6675c9c266f4483f4dac898fd9e2192475 (diff since f64976f): Ready, Blocking: none.

Revert test

In a scratch worktree from the head, the 2 scripts and version.go were reverted to f64976f (tests kept): TestFirstPublishRestoreGenerateUpload/default and /skip_published_identities fail with restore existing sysext metadata: no existing sysext packages found; TestUploadGuardFirstAttemptConflictWithIdenticalBytesFails fails; TestCompareVersionsUpstreamEdgeCases fails at compareVersions("", "~1") = -1, want sign 1. Against origin/main, the scripts reverted: TestSyncSysextMetadata* (2), TestUploadGuard* (8), TestDeletePrunedPayloads* (4) and TestPublishActionGuardsSysextMetadataAndPrunesLast fail; with retention removed, TestRetentionKeepsNewestVersionPerOSVersion, TestRetentionDropsIncomingVersionOlderThanKept, TestRetentionKeepsTwoNewest and TestGenerateSysextKeepVersionsWritesPrunedReport fail. The scratch worktrees were removed.

Limits

No test against real R2. The fake aws follows R2's documented 412 behavior. The first real sysext publish after the merge is the live check.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 13, 2026
@bketelsen
bketelsen added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 1303788 Nov 13, 2026
4 checks passed
@bketelsen
bketelsen deleted the fix/102-sysext-sums-race branch November 13, 2026 23:15
bketelsen pushed a commit to frostyard/snosi that referenced this pull request Nov 17, 2026
* ci(build): move the sysext publish to repogen v0.7.4

repogen v0.7.4 writes each ext/<name>/SHA256SUMS and SHA256SUMS.gpg only
when its ETag is unchanged since the metadata restore (repogen ADR-0019,
frostyard/repogen#104), so a concurrent writer fails the run with a 412
instead of losing manifest entries. Both publish steps (build and
build-forky) move the action pin, repogen-version and repogen-commit
together to the peeled v0.7.4 commit. sysext-keep-versions stays unset:
its default 0 keeps every published version.

The forky job comment and the sysexts and CI/CD design docs now describe
the guard and why the two publish jobs must stay serialized.

* docs(sysexts): state what a Phase 3b conflict leaves written

Phase 3b writes 1 extension at a time, so a 412 keeps the manifests
written before it and can leave a SHA256SUMS and its signature out of
step (repogen ADR-0019).

---------

Co-authored-by: frostyard-machines <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L1 Read every line ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a high-risk path (ADR-0068)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sysexts of 2 suites: SHA256SUMS has no write lock, and ext/ has no retention

2 participants