← Back to Pull requests

fix(trust): fall back to in-memory TUF metadata on a cache write race #3512

Closed
unknown closed this pull request without merging on Oct 29, 2026 20:43 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 19:40 UTC
Author

Summary

Fixes a race in the shared Sigstore TUF cache that failed binary-attestation verification when several aicr processes ran at once. This is what turned main's CLI E2E red on 563077763.

Motivation / Context

The On Push Qualification run for 563077763 (run 40932605071) failed CLI E2E on both attempts, each time in a different parallel signing test:

  • attempt 1: cli-bundle-headless-oidc-ci;

  • attempt 2: cli-bundle-attestation-ci.
  • Both failed with:

    failed to initialize TUF client: failed to load metadata: tuf refresh failed: failed to persist metadata
    

    That commit (#3505) only bumps a chart pin; the previous 11 main runs were green.

    Fixes: N/A
    Related: N/A (main On Push Qualification run 40932605071)

    Type of Change

  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Refactoring (no functional changes)

  • Build/CI/tooling
  • Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)

  • API server (cmd/aicrd, pkg/server)

  • Recipe engine / data (pkg/recipe)

  • Bundler and deployers (pkg/bundler, pkg/component)

  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)

  • Validator (pkg/validator)

  • Core libraries (pkg/errors, pkg/k8s)

  • Docs/examples (docs/, examples/)

  • Other: pkg/trust (Sigstore trusted root and signing config)
  • Implementation Notes

    Cause. Every aicr process uses the same TUF cache under ~/.sigstore. When go-tuf refreshes, it writes each metadata file to a temp file, renames it into place, reads it back and compares (persistMetadata in go-tuf v2.4.2). If another process renames in different bytes between that rename and the read-back, the comparison fails with failed to persist metadata, which has no underlying cause. Timestamp metadata is re-signed often, so two concurrent refreshes can download different bytes.

    On push, main's CLI E2E runs extra keyless signing tests in parallel. Each runs aicr bundle --attest, which refreshes the cache to verify the binary attestation, so main hits the race while PR runs do not. The same race can hit any user who runs aicr commands in parallel on one host.

    Fix. pkg/trust now builds and refreshes TUF clients through two helpers, newClient and refresh. When either loses that race, it starts over once with WithDisableLocalCache(), which reads the metadata into memory and cannot race again. Every other error is returned as before, and the callers keep their error classification. The match is on go-tuf's message text, because go-tuf exports no sentinel for it; the comment cites the source.

    Testing

    go test -race -count=1 ./pkg/trust/...
    golangci-lint run -c .golangci.yaml ./pkg/trust/...
    make qualify
    

  • TestNewClientFallsBackOnPersistRace and TestRefreshFallsBackOnPersistRace replace the TUF operations with fakes. They cover the fallback, the fallback failing in memory too, and other errors not being retried. Both fail with the fallback disabled.

  • The race itself depends on concurrent writers receiving different metadata, so it can't be reproduced on demand. Main's CLI E2E, which runs the signing tests in parallel, is the end-to-end check.
  • All pass; make qualify reports 85.8% coverage.

    Risk Assessment

  • Low — Isolated change, well-tested, easy to revert

  • Medium — Touches multiple components or has broader impact

  • High — Breaking change, affects critical paths, or complex rollout
  • The fallback runs only on this one error. It reads the same verified metadata from the same TUF repository, just without writing the cache.

    Rollout notes: N/A

    Checklist

  • Tests pass locally (make test with -race)

  • Linter passes (make lint)

  • I did not skip/disable tests to make CI green

  • I added/updated tests for new functionality

  • I updated docs if user-facing behavior changed

  • Changes follow existing patterns in the codebase

  • Commits are signed off and cryptographically signed (git commit -s -S) — GPG signing info
  • Diff: 546 lines (+409 / -137) across 6 files Reviewer: yuanchen8911 Review duration: 62m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 546 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.377
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3512"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48% (MEDIUM) · Higher = larger blast radius
    48%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.0% · Safe to merge
    19.0%
    Repository