← Back to Pull requests

[docs] Add RFC0017: Fingerprint-Based CI Artifact Cache #9500

Open
ammallya opened this pull request with 509 lines diff across 3 files
View on GitHub
ammallya ammallya commented on Oct 26, 2026 19:41 UTC
Author

Motivation

Adds RFC0017, proposing a fingerprint-based CI artifact cache to replace the current "baseline run" stage-reuse mechanism.

Reuse today selects a baseline workflow run by commit ancestry + S3 archive-filename presence + job health. It is O(N) over workflow runs, costs many API calls, cannot express rocm-libraries → rocm-libraries dependencies or arbitrary build-graph subsets, and is fragile on release branches. This RFC instead keys reuse on the THEROCK_FPRINT the build already computes.

GitHub issue: https://github.com/ROCm/TheRock/issues/8651 (parent #3399)

Technical Details

  • docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md

  • docs/rfcs/assets/RFC0017-cache-flow.svg (plan/restore/publish flow diagram)
  • The RFC specifies: the cache key (e{EPOCH}:{variant}:{fingerprint}) and its composition, incl. proposed additions (output identity / target_family, container digest, compiler id); the manifest cache value and the trust / validation / publication states with a read policy; the plan → restore → publish flows; and storage (S3 pointers + the team's ClickHouse index; SQLite for local builds). It composes with but stays independent of RFC0013 (test selection) and RFC0008 (Kpack split packaging).

    Test Plan

  • Render the RFC on GitHub; confirm tables, code blocks, and the embedded assets/RFC0017-cache-flow.svg display and all relative links resolve.
  • Test Result

  • RFC render correctly; diagram and links resolve.
  • Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/CONTRIBUTING.md.
  • Diff: 509 lines (+509 / -0) across 3 files Reviewer: ScottTodd Review duration: 51002m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.50) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 509 lines diff across 3 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.88 · 5 substantive comment(s)
    0.88
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    88%
    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.373
    Real PR Conversation Timeline
    44 items
    therock-pr-bot[bot] therock-pr-bot[bot] commented on Oct 26, 2026 19:42 UTC
    Bot

    <!-- therock-pr-bot-policy-check -->

    ✅ All Checks Passed — Ready for Review

    | Check | Status | Details |
    |---|:---:|---|
    | 📝 PR Description | ✅ Pass | — |
    | ⛔ Forbidden Files | ✅ Pass | — |
    | 🧪 Unit Test | ✅ Pass | PR does not contain code files — Unit Test auto-passed |
    | 🔎 pre-commit | ✅ Pass | — |
    | 🚫 Draft PR | 🔜 To Be Enabled | — |
    | 🚩 Feature Flag | 🔜 To Be Enabled | — |
    | 📊 Code Coverage | 🔜 To Be Enabled | — |
    | 🤖 therock-pr-bot | ✅ Pass | — |

    🎉 All checks passed! This PR is ready for review.

    📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

    🙋 Wish to Override Policy?

    therock-pr-bot[bot] therock-pr-bot[bot] commented on Oct 26, 2026 19:42 UTC
    Bot

    <!-- therock-pr-bot-precommit-failed -->

    Pre-commit check failed

    ⛔ pre-commit failed

    Please run locally:

  • python -m pip install pre-commit

  • pre-commit install

  • pre-commit run --all-files --show-diff-on-failure
  • This repo uses .pre-commit-config.yaml.

    ScottTodd ScottTodd commented on code on Nov 06, 2026 21:43 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |

    Explicit build variant seems okay to add, but I'm not sure it's strictly necessary if we already have the underlying CMake flags used in the fprint.

    ScottTodd ScottTodd commented on code on Nov 06, 2026 21:57 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |
    +| Output identity (`name`, `component`, `target_family`) | no | **add** — per-arch split artifacts share one source fingerprint and must not collide |

    Let's be careful here with the details of targets vs target families of how multi-arch CI works.

    A build of the math-libs stage with the target family gfx110X-all like https://github.com/ROCm/rockrel/actions/runs/42133689495/job/127624314660 builds for targets gfx1100,gfx1101,gfx1102,gfx1103.
    logs: https://therock-nightly-artifacts.s3.amazonaws.com/42133689495-linux/logs/math-libs/gfx110X-all/index.html
    Note rocFFT_build.log, hipFFT_build.log, etc.
    artifacts: https://therock-nightly-artifacts.s3.amazonaws.com/42133689495-linux/index.html
    Note fft_lib_gfx1100.tar.zst, fft_lib_gfx1101.tar.zst, fft_lib_gfx1102.tar.zst, etc.

    It could be reasonable to say that "fft_lib_gfx1100.tar.zst and fft_lib_gfx1101.tar.zst built from the same source have the same fprint". Then if someone builds gfx110X-all as a family _or_ gfx1100 on its own they would get the same cache hits:

    Scenario 1:
    First CI build of gfx110X-all writes gfx1100,gfx1101,gfx1102,gfx1103 artifacts into cache with some fprint
    Second CI build of gfx110X-all requests gfx1100,gfx1101,gfx1102,gfx1103 artifacts, cache hits for all
    Third CI/local build of gfx1100 requests gfx1100 artifacts and gets cache hits for it

    Scenario 2:
    First CI build of gfx1100 writes gfx1100 artifacts into cache with some fprint
    Second CI build of gfx110X-all requests gfx1100,gfx1101,gfx1102,gfx1103 artifacts, cache hits for only gfx1100, decides to build from source
    Third CI/local build of gfx1100 requests gfx1100 artifacts and gets cache hits for it

    Note that the cache lookup there is not just "this is the fprint", it's "this is the artifact name I want at this fprint". If we handle artifact caching at the very start of the build, we would need to build that complete list of expected artifacts during CI configure. We could also push caching down into the build itself, so each build action would compute its fprint on demand and check the database for a cache hit prior to building (as ccache/sccache/bazel/etc. function).

    Also note that the artifact naming schema refers to target family but that predates multi-arch. All current artifacts produced by CI use a single target (not family) after splitting: https://github.com/ROCm/TheRock/blob/4a0d18306bb5085d7a7482c93dd1bae6ca08339d/build_tools/_therock_utils/artifacts.py#L38-L42

    ScottTodd ScottTodd commented on code on Nov 06, 2026 22:04 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |
    +| Output identity (`name`, `component`, `target_family`) | no | **add** — per-arch split artifacts share one source fingerprint and must not collide |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target_family)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked
    +}
    +```
    +
    +A **read policy** filters at lookup time (default: `trusted` + `build_passed` +
    +`published`). `trust` = push/schedule on a protected branch vs. pull_request (PR
    +entries are stored but tagged, so PRs cannot poison shared reuse). `publication`
    +enforces write ordering (readers trust only `published`).
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](./assets/RFC0016-cache-flow.svg)

    this file is stored in docs/assets/ but this tries to load from docs/rfcs/assets/

    ScottTodd ScottTodd commented on code on Nov 06, 2026 22:04 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |
    +| Output identity (`name`, `component`, `target_family`) | no | **add** — per-arch split artifacts share one source fingerprint and must not collide |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target_family)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked
    +}
    +```
    +
    +A **read policy** filters at lookup time (default: `trusted` + `build_passed` +
    +`published`). `trust` = push/schedule on a protected branch vs. pull_request (PR
    +entries are stored but tagged, so PRs cannot poison shared reuse). `publication`
    +enforces write ordering (readers trust only `published`).
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](./assets/RFC0016-cache-flow.svg)
    +
    +1. **Plan** (per run): changed paths → required artifact units per build stage →
    +   compute keys → one batched `WHERE cache_key IN (...)` lookup → a stage is
    +   skippable iff every required unit is a hit; otherwise only missing units build.
    +   Source-changed units are forced misses.
    +2. **Restore** (per unit): lookup under read policy → check completeness → download
    +   objects → re-verify digests → reusable / needs-build. A hit with missing or
    +   corrupt objects is downgraded to a build (defends against DB/storage drift).
    +3. **Publish** (per built unit): gate on outputs-complete + producer policy →
    +   upload objects first → publish manifest + fingerprint entry last.
    +
    +### Storage
    +
    +Objects stay in the existing S3 buckets (manifest holds pointers; entries evictable
    +when objects are retention-deleted). Index is a `fingerprint -> manifest` store
    +behind one interface: SQLite for local builds, the team's **ClickHouse** instance
    +behind a batched lookup/publish API in production.
    +
    +Reference implementation: `build_tools/github_actions/fingerprint_cache/` (plan →
    +`planner.py`/`local_cache.py`, key → `cache_key.py`, value → `manifest.py`, index →
    +`cache_db.py`, objects → `local_store.py`, restore → `restore.py`, publish →
    +`publish.py`); 63 unit tests.
    +
    +## Proof of concept
    +
    +Local `gfx110X-all` build, no workflow edits:
    +
    +- Cold build populated the cache; second build reused **50 artifacts** with per-object
    +  SHA-256 verification; entries tagged `trusted`/`build_passed`/`published`.
    +- Coverage: **62 `target-neutral` artifacts cacheable, 15 `target-specific` (split)
    +  uncacheable** — split artifacts emit no `.fprint` (`if(NOT _should_split)` in
    +  `cmake/therock_artifacts.cmake`). The uncacheable set is the expensive math/ML libs.
    +- Committed single-subproject edit → reuse all but that artifact. Uncommitted (dirty)
    +  edit → fingerprint invalid → reported uncacheable, never reused.
    +
    +## Required changes
    +
    +1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
    +   artifacts — core fingerprinting change; largest reuse unlock.
    +2. Fold `target_family` (output identity) into the key (prevents per-arch collision).

    See above. I'm not sure if we need this.

    ScottTodd ScottTodd commented on code on Nov 06, 2026 22:07 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |
    +| Output identity (`name`, `component`, `target_family`) | no | **add** — per-arch split artifacts share one source fingerprint and must not collide |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target_family)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked
    +}
    +```
    +
    +A **read policy** filters at lookup time (default: `trusted` + `build_passed` +
    +`published`). `trust` = push/schedule on a protected branch vs. pull_request (PR
    +entries are stored but tagged, so PRs cannot poison shared reuse). `publication`
    +enforces write ordering (readers trust only `published`).
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](./assets/RFC0016-cache-flow.svg)
    +
    +1. **Plan** (per run): changed paths → required artifact units per build stage →
    +   compute keys → one batched `WHERE cache_key IN (...)` lookup → a stage is
    +   skippable iff every required unit is a hit; otherwise only missing units build.
    +   Source-changed units are forced misses.
    +2. **Restore** (per unit): lookup under read policy → check completeness → download
    +   objects → re-verify digests → reusable / needs-build. A hit with missing or
    +   corrupt objects is downgraded to a build (defends against DB/storage drift).
    +3. **Publish** (per built unit): gate on outputs-complete + producer policy →
    +   upload objects first → publish manifest + fingerprint entry last.
    +
    +### Storage
    +
    +Objects stay in the existing S3 buckets (manifest holds pointers; entries evictable
    +when objects are retention-deleted). Index is a `fingerprint -> manifest` store
    +behind one interface: SQLite for local builds, the team's **ClickHouse** instance
    +behind a batched lookup/publish API in production.
    +
    +Reference implementation: `build_tools/github_actions/fingerprint_cache/` (plan →
    +`planner.py`/`local_cache.py`, key → `cache_key.py`, value → `manifest.py`, index →
    +`cache_db.py`, objects → `local_store.py`, restore → `restore.py`, publish →
    +`publish.py`); 63 unit tests.
    +
    +## Proof of concept
    +
    +Local `gfx110X-all` build, no workflow edits:
    +
    +- Cold build populated the cache; second build reused **50 artifacts** with per-object
    +  SHA-256 verification; entries tagged `trusted`/`build_passed`/`published`.
    +- Coverage: **62 `target-neutral` artifacts cacheable, 15 `target-specific` (split)
    +  uncacheable** — split artifacts emit no `.fprint` (`if(NOT _should_split)` in
    +  `cmake/therock_artifacts.cmake`). The uncacheable set is the expensive math/ML libs.
    +- Committed single-subproject edit → reuse all but that artifact. Uncommitted (dirty)
    +  edit → fingerprint invalid → reported uncacheable, never reused.
    +
    +## Required changes
    +
    +1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
    +   artifacts — core fingerprinting change; largest reuse unlock.
    +2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    +4. Upload fingerprints + manifests as part of CI runs.
    +
    +## Disabling the cache
    +
    +| Mechanism | Scope | Effect |
    +| --- | --- | --- |
    +| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    +| Dev-build default | local | proposed off-by-default locally |
    +| Dry-run | any/CI | report hits, always build |
    +| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    +| `CACHE_EPOCH` bump | global | invalidate entire cache |
    +| Revoke manifest | targeted | never serve a known-bad entry |
    +| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |

    There are some fragments of good ideas in here, but I'm not following each individual item fully. Could you expand this out?

    ScottTodd ScottTodd commented on code on Nov 06, 2026 22:08 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,185 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-10-26
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    +                                             recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags / variant | partial | keep + explicit `build_variant` in key |
    +| Output identity (`name`, `component`, `target_family`) | no | **add** — per-arch split artifacts share one source fingerprint and must not collide |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target_family)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked
    +}
    +```
    +
    +A **read policy** filters at lookup time (default: `trusted` + `build_passed` +
    +`published`). `trust` = push/schedule on a protected branch vs. pull_request (PR
    +entries are stored but tagged, so PRs cannot poison shared reuse). `publication`
    +enforces write ordering (readers trust only `published`).
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](./assets/RFC0016-cache-flow.svg)
    +
    +1. **Plan** (per run): changed paths → required artifact units per build stage →
    +   compute keys → one batched `WHERE cache_key IN (...)` lookup → a stage is
    +   skippable iff every required unit is a hit; otherwise only missing units build.
    +   Source-changed units are forced misses.
    +2. **Restore** (per unit): lookup under read policy → check completeness → download
    +   objects → re-verify digests → reusable / needs-build. A hit with missing or
    +   corrupt objects is downgraded to a build (defends against DB/storage drift).
    +3. **Publish** (per built unit): gate on outputs-complete + producer policy →
    +   upload objects first → publish manifest + fingerprint entry last.
    +
    +### Storage
    +
    +Objects stay in the existing S3 buckets (manifest holds pointers; entries evictable
    +when objects are retention-deleted). Index is a `fingerprint -> manifest` store
    +behind one interface: SQLite for local builds, the team's **ClickHouse** instance
    +behind a batched lookup/publish API in production.
    +
    +Reference implementation: `build_tools/github_actions/fingerprint_cache/` (plan →
    +`planner.py`/`local_cache.py`, key → `cache_key.py`, value → `manifest.py`, index →
    +`cache_db.py`, objects → `local_store.py`, restore → `restore.py`, publish →
    +`publish.py`); 63 unit tests.
    +
    +## Proof of concept
    +
    +Local `gfx110X-all` build, no workflow edits:
    +
    +- Cold build populated the cache; second build reused **50 artifacts** with per-object
    +  SHA-256 verification; entries tagged `trusted`/`build_passed`/`published`.
    +- Coverage: **62 `target-neutral` artifacts cacheable, 15 `target-specific` (split)
    +  uncacheable** — split artifacts emit no `.fprint` (`if(NOT _should_split)` in
    +  `cmake/therock_artifacts.cmake`). The uncacheable set is the expensive math/ML libs.
    +- Committed single-subproject edit → reuse all but that artifact. Uncommitted (dirty)
    +  edit → fingerprint invalid → reported uncacheable, never reused.
    +
    +## Required changes
    +
    +1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
    +   artifacts — core fingerprinting change; largest reuse unlock.
    +2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    +4. Upload fingerprints + manifests as part of CI runs.
    +
    +## Disabling the cache
    +
    +| Mechanism | Scope | Effect |
    +| --- | --- | --- |
    +| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    +| Dev-build default | local | proposed off-by-default locally |
    +| Dry-run | any/CI | report hits, always build |
    +| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    +| `CACHE_EPOCH` bump | global | invalidate entire cache |
    +| Revoke manifest | targeted | never serve a known-bad entry |
    +| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |
    +
    +## Test scenarios
    +
    +| Scenario | Expected |
    +| --- | --- |
    +| Rebuild, no changes | 100% reuse |
    +| Committed edit of one subproject | only that artifact + consumers rebuild |
    +| Uncommitted (dirty) edit | uncacheable, reported, never reused |
    +| Compiler/toolchain change | broad invalidation |
    +| release → ASan | no cross-variant reuse |
    +| Container/image change | invalidation (once image digest in key) |
    +| Split/per-arch artifact | uncacheable today — closed by this RFC |
    +| Same source, different dir | same key (path-independent) |
    +| Cache unavailable / object missing / digest mismatch | build, no failure |
    +| Untrusted (PR) entry, default policy | ignored |
    +
    +Benchmarks (repeatable harness, same commit/flags/runner): cold vs. warm wall-time
    +per arch, hit rate (no-op and single-subproject edit), batched lookup latency,
    +runner-hours saved/week, storage growth.
    +
    +## Implementation plan
    +
    +1. Fingerprint audit + split-artifact `.fprint` emission + output identity in key.
    +2. Upload fingerprints/manifests in CI; ingest run history into a dev cache.
    +3. ClickHouse `fingerprint -> manifest` schema + lookup/publish API; eviction;
    +   monitoring.
    +4. Wire planner into `configure_multi_arch_ci.py` in dry-run; validate predicted
    +   vs. actual.
    +5. Replace `baseline_runs.py` checks + the "Copy Prebuilt Stages" path in
    +   `multi_arch_ci_linux.yml` behind a flag; enable trusted reuse for `main` +
    +   rocm-libraries; retire the legacy search after parity.

    This plan could use more sequencing and risk analysis. Start small - see https://github.com/ROCm/TheRock/pull/2432 where fprints were first added for example:

    This will be used in CI in combination with a special bootstrap script for certain stages to cache entire artifacts in the remote cache for presubmits. This will be enabled first for base artifacts like the compiler and certain base libraries that change infrequently but are expensive to build and should effectively reduce them to no-ops. We'll evaluate which stages this is suitable for carefully: the further we go in the system the more variable the build system and therefore the higher the risk of accidental cache poisoning, so the first target here is the compiler, which is quite self contained and well managed.

    ScottTodd ScottTodd commented on Nov 06, 2026 22:11 UTC
    Reviewer

    The outline here, together with the task outline on https://github.com/ROCm/TheRock/issues/8651 seems reasonable to me to proceed. Let's proceed milestone by milestone and not try to boil the ocean too much here. First priority is cache hits for the compiler and other nodes near the start of the build graph, then we can expand out from there.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:46 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1

    Please update the RFC number to 17 now that https://github.com/ROCm/TheRock/tree/main/docs/rfcs already includes a different 16.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:46 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:47 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:48 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -48,29 +48,39 @@ dependency fingerprints, toolchain, and build flags. We use it as the cache key.
     ### Cache key
     
     ```
    -cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    -                                             recipe_inputs, output_identity)}
    +cache_key = e{EPOCH}:{SHA256(source_fingerprint, recipe_inputs, output_identity)}
     ```
     
     | Input | In `THEROCK_FPRINT` | Action |
     | --- | --- | --- |
    -| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Subproject source identity (project-scoped git tree + extra inputs; invalid if dirty) | yes | keep — computation refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)) |

    I'd like for the fprint computation discussion to be either part of this RFC or the tracking issues, not a separate RFC.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:52 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -99,17 +109,28 @@ enforces write ordering (readers trust only `published`).
     3. **Publish** (per built unit): gate on outputs-complete + producer policy →
        upload objects first → publish manifest + fingerprint entry last.
     
    -### Storage
    -
    -Objects stay in the existing S3 buckets (manifest holds pointers; entries evictable
    -when objects are retention-deleted). Index is a `fingerprint -> manifest` store
    -behind one interface: SQLite for local builds, the team's **ClickHouse** instance
    -behind a batched lookup/publish API in production.
    -
    -Reference implementation: `build_tools/github_actions/fingerprint_cache/` (plan →
    -`planner.py`/`local_cache.py`, key → `cache_key.py`, value → `manifest.py`, index →
    -`cache_db.py`, objects → `local_store.py`, restore → `restore.py`, publish →
    -`publish.py`); 63 unit tests.
    +### Index and storage
    +
    +Objects stay in the existing S3 buckets (the index holds pointers; entries are
    +evictable when objects are retention-deleted). The `fingerprint -> artifact
    +location` index sits behind one interface and starts as simply as possible,
    +growing only as it must:
    +
    +- **Static, checked-in JSON** (`build_tools/artifact_cache_index.json`) is the
    +  first index — human-reviewable, no service, no secrets. Its initial scope is
    +  the single `amd-llvm` artifact ([#10026](https://github.com/ROCm/TheRock/pull/10026)):
    +  expensive to build and infrequently changed, so the highest-value, lowest-risk
    +  place to prove reuse.
    +- A **dynamic backend** (SQLite locally; the team's ClickHouse instance behind a
    +  batched lookup/publish API) is a later step behind the same interface, adopted
    +  once the static index outgrows manual maintenance — not a prerequisite.

    I wouldn't frame this as "outgrows manual maintenance". The checked in file is not going to be viable for anything but early proofs of concept and prototypes.

    We _could_ use https://github.com/ROCm/Quartz (or a similar repository) as our "database" but we'd be writing a large volume of commits there (Quartz has 60k commits already).

    This really calls for a server-side database that is written to as artifacts are uploaded and can also be regenerated from a cold start by either backfilling from github run history or listing files across the artifact S3 buckets directly. The static checked in JSON lets us experiment and test while we're still setting up the server-side component.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:56 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).

    ditto here - fprint stability/robustness should go in this RFC or issues, not its own separate RFC

    @erman-gurses

    ScottTodd ScottTodd commented on code on Nov 18, 2026 17:58 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).
    +5. Record producers in the index. Fingerprint upload next to artifacts is landed
    +   ([#9921](https://github.com/ROCm/TheRock/pull/9921)); the static index records
    +   those sidecars ([#10026](https://github.com/ROCm/TheRock/pull/10026)).
     
     ## Disabling the cache
     
    -| Mechanism | Scope | Effect |
    -| --- | --- | --- |
    -| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    -| Dev-build default | local | proposed off-by-default locally |
    -| Dry-run | any/CI | report hits, always build |
    -| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    -| `CACHE_EPOCH` bump | global | invalidate entire cache |
    -| Revoke manifest | targeted | never serve a known-bad entry |
    -| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |
    +Reuse is an optimization, so every layer has an off switch. They differ in blast
    +radius, which matters when something goes wrong and you need to stop the bleeding
    +without blocking the build.
    +
    +- **Build from source (`THEROCK_CACHE=off`).** Per-invocation kill switch: the
    +  planner is skipped entirely and everything builds. The simplest escape hatch
    +  for a developer or a single run.

    Release builds will not use artifact caches. That's not a per-invocation "kill switch", it's a standard mode that is expected to run regularly.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 18:03 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).
    +5. Record producers in the index. Fingerprint upload next to artifacts is landed
    +   ([#9921](https://github.com/ROCm/TheRock/pull/9921)); the static index records
    +   those sidecars ([#10026](https://github.com/ROCm/TheRock/pull/10026)).
     
     ## Disabling the cache
     
    -| Mechanism | Scope | Effect |
    -| --- | --- | --- |
    -| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    -| Dev-build default | local | proposed off-by-default locally |
    -| Dry-run | any/CI | report hits, always build |
    -| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    -| `CACHE_EPOCH` bump | global | invalidate entire cache |
    -| Revoke manifest | targeted | never serve a known-bad entry |
    -| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |
    +Reuse is an optimization, so every layer has an off switch. They differ in blast
    +radius, which matters when something goes wrong and you need to stop the bleeding
    +without blocking the build.
    +
    +- **Build from source (`THEROCK_CACHE=off`).** Per-invocation kill switch: the
    +  planner is skipped entirely and everything builds. The simplest escape hatch
    +  for a developer or a single run.
    +- **Off-by-default locally (proposed).** Local developer builds default to no
    +  cache so a contributor never consumes a shared entry they cannot reason about;
    +  CI opts in explicitly. Keeps the trust boundary clear.

    This does not make sense. What this RFC initially proposes affects only the CI system directly, then there is no on _or_ off mode for local developers just using the build system to use.

    What we should provide is
    1. Scripts like https://github.com/ROCm/TheRock/blob/main/build_tools/find_latest_artifacts.py that can find artifacts that are compatible with the current source using the shared database, as well as scripts to bootstrap the build using those artifacts, such as https://github.com/ROCm/TheRock/blob/main/build_tools/buildctl.py
    2. Documentation for those scripts

    If we were using a build system like Bazel with remote caching built in (or even ccache/sccache with our existing cmake builds) then that would be different - there would be the option to naturally opt-in/out to remote cache use with a build configuration or toolchain file.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 18:04 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).
    +5. Record producers in the index. Fingerprint upload next to artifacts is landed
    +   ([#9921](https://github.com/ROCm/TheRock/pull/9921)); the static index records
    +   those sidecars ([#10026](https://github.com/ROCm/TheRock/pull/10026)).
     
     ## Disabling the cache
     
    -| Mechanism | Scope | Effect |
    -| --- | --- | --- |
    -| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    -| Dev-build default | local | proposed off-by-default locally |
    -| Dry-run | any/CI | report hits, always build |
    -| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    -| `CACHE_EPOCH` bump | global | invalidate entire cache |
    -| Revoke manifest | targeted | never serve a known-bad entry |
    -| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |
    +Reuse is an optimization, so every layer has an off switch. They differ in blast
    +radius, which matters when something goes wrong and you need to stop the bleeding
    +without blocking the build.
    +
    +- **Build from source (`THEROCK_CACHE=off`).** Per-invocation kill switch: the
    +  planner is skipped entirely and everything builds. The simplest escape hatch
    +  for a developer or a single run.
    +- **Off-by-default locally (proposed).** Local developer builds default to no
    +  cache so a contributor never consumes a shared entry they cannot reason about;
    +  CI opts in explicitly. Keeps the trust boundary clear.
    +- **Dry-run.** The planner computes and reports what it *would* reuse but always
    +  builds. Used to validate predictions before trusting them (see the plan).
    +- **Read-bypass.** Ignore existing hits and rebuild + republish, so a single run
    +  can overwrite a bad entry without a global flush. The targeted recovery path
    +  for a suspected poisoned entry.
    +- **`CACHE_EPOCH` bump.** Global invalidation: changing the epoch changes every
    +  key at once. The big hammer for "the recipe/environment changed in a way the
    +  fingerprint does not capture" or a schema change.
    +- **Revoke a manifest.** Mark one entry as never-serve (`publication = revoked`)
    +  when a specific known-bad artifact is identified, leaving the rest of the cache
    +  intact.

    I don't think we need to design "read-bypass" or "revoke a manifest" at this point. Let's start simple. Could leave those as future ideas.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 18:05 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).
    +5. Record producers in the index. Fingerprint upload next to artifacts is landed
    +   ([#9921](https://github.com/ROCm/TheRock/pull/9921)); the static index records
    +   those sidecars ([#10026](https://github.com/ROCm/TheRock/pull/10026)).
     
     ## Disabling the cache
     
    -| Mechanism | Scope | Effect |
    -| --- | --- | --- |
    -| Env flag (e.g. `THEROCK_CACHE=off`) | any | skip cache, build from source |
    -| Dev-build default | local | proposed off-by-default locally |
    -| Dry-run | any/CI | report hits, always build |
    -| Read-bypass | any | ignore hits, repopulate (recover from poisoned entry) |
    -| `CACHE_EPOCH` bump | global | invalidate entire cache |
    -| Revoke manifest | targeted | never serve a known-bad entry |
    -| `stage_reuse_mode = off` | workflow | disable per-workflow / release branches |
    +Reuse is an optimization, so every layer has an off switch. They differ in blast
    +radius, which matters when something goes wrong and you need to stop the bleeding
    +without blocking the build.
    +
    +- **Build from source (`THEROCK_CACHE=off`).** Per-invocation kill switch: the
    +  planner is skipped entirely and everything builds. The simplest escape hatch
    +  for a developer or a single run.
    +- **Off-by-default locally (proposed).** Local developer builds default to no
    +  cache so a contributor never consumes a shared entry they cannot reason about;
    +  CI opts in explicitly. Keeps the trust boundary clear.
    +- **Dry-run.** The planner computes and reports what it *would* reuse but always
    +  builds. Used to validate predictions before trusting them (see the plan).
    +- **Read-bypass.** Ignore existing hits and rebuild + republish, so a single run
    +  can overwrite a bad entry without a global flush. The targeted recovery path
    +  for a suspected poisoned entry.
    +- **`CACHE_EPOCH` bump.** Global invalidation: changing the epoch changes every
    +  key at once. The big hammer for "the recipe/environment changed in a way the
    +  fingerprint does not capture" or a schema change.
    +- **Revoke a manifest.** Mark one entry as never-serve (`publication = revoked`)
    +  when a specific known-bad artifact is identified, leaving the rest of the cache
    +  intact.
    +- **`stage_reuse_mode = off` (workflow).** Disables automatic reuse for a whole
    +  workflow or branch — e.g. release branches, where we may want every artifact
    +  rebuilt from source regardless of cache state.

    This overlaps with the "Build from source (THEROCK_CACHE=off)" point above.

    ScottTodd ScottTodd commented on code on Nov 18, 2026 18:09 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,271 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-17
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{SHA256(source_fingerprint, recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (project-scoped git tree + extra inputs; invalid if dirty) | yes | keep — computation refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)) |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags (incl. build variant, e.g. release/ASan) | yes | keep — already in the fingerprint; no separate key term |
    +| Output identity (`name`, `component`, `target`) | partial | **add** — see *Targets vs. target families* below |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +**Targets vs. target families.** Multi-arch CI builds a target *family* (e.g.
    +`gfx110X-all`), which expands to individual *targets* (`gfx1100`, `gfx1101`,
    +`gfx1102`, `gfx1103`). Split artifacts are emitted and named **per target** —
    +`fft_lib_gfx1100.tar.zst`, not per family — so the key's output identity must
    +distinguish targets, not families. This term is only load-bearing while split
    +artifacts share one source fingerprint; once each per-target artifact emits its
    +own `.fprint` (Required change 1), the fingerprint already differs per target and
    +folding the target into the key becomes a redundant safeguard rather than a
    +requirement. Build variant (release/ASan/...) is already captured by the CMake
    +flags in `THEROCK_FPRINT`, so it is not a separate key term.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked

    I don't think we need/want these fields:
    trust: only write trusted entries to the cache
    validation: irrelevant. The build cache does not care whether tests ran or passed. It's just "for this source, here is what the build produced"

  • publication: irrelevant? A cache key existing means that it is "published", no separate state.
  • ScottTodd ScottTodd commented on code on Nov 18, 2026 18:11 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,271 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-17
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +Replace the "baseline run" stage-reuse mechanism with a content-addressed artifact
    +cache keyed on `THEROCK_FPRINT`. Each run computes a cache key per artifact,
    +resolves hits in one batched database lookup, verifies object integrity, and
    +reuses prebuilt artifacts instead of rebuilding. No GitHub-API history traversal,
    +no git-history heuristics. Tracks [#8651](https://github.com/ROCm/TheRock/issues/8651)
    +(parent [#3399](https://github.com/ROCm/TheRock/issues/3399)).
    +
    +## Problem
    +
    +Reuse today selects a baseline workflow run by **commit ancestry + S3
    +archive-filename presence + job health** (`build_tools/github_actions/baseline_runs.py`,
    +`stage_reuse_decision.py`); fingerprints are never used. This is O(N) over workflow
    +runs, costs many API calls, cannot express rocm-libraries → rocm-libraries
    +dependencies or arbitrary build-graph subsets, and is fragile on release branches
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` (configure-time, per artifact) already hashes source identity,
    +dependency fingerprints, toolchain, and build flags. We use it as the cache key.
    +
    +## Goals
    +
    +- O(1)-style, batched key lookup, independent of workflow-history length.
    +- Reuse unchanged artifacts across pin updates and component commits; invalidate on
    +  recipe/environment changes.
    +- Integrity-verified reuse; unavailable/ineligible cache always falls back to build.
    +- Works on non-default/release branches; composes with RFC0013 test selection.
    +
    +## Non-goals
    +
    +- Test selection — stays [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md);
    +  a cache hit never suppresses a test.
    +- Replacing `ccache` (compiler-call cache; complementary, stacks with this).
    +- New storage — reuse existing `ci-artifacts` S3 buckets as object storage; store
    +  pointers, not copies.
    +
    +## Design
    +
    +### Cache key
    +
    +```
    +cache_key = e{EPOCH}:{SHA256(source_fingerprint, recipe_inputs, output_identity)}
    +```
    +
    +| Input | In `THEROCK_FPRINT` | Action |
    +| --- | --- | --- |
    +| Subproject source identity (project-scoped git tree + extra inputs; invalid if dirty) | yes | keep — computation refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)) |
    +| Dependency fingerprints | yes | keep |
    +| Toolchain file | yes | keep |
    +| Build flags (incl. build variant, e.g. release/ASan) | yes | keep — already in the fingerprint; no separate key term |
    +| Output identity (`name`, `component`, `target`) | partial | **add** — see *Targets vs. target families* below |
    +| Container/image digest | no | **add** |
    +| Compiler id + version | indirect | add |
    +| `CACHE_EPOCH` (global) | n/a | keep — bump to invalidate the whole cache |
    +
    +Key composition is isolated in one function so `source_fingerprint` is the only term
    +that changes when real uploaded fingerprints replace the PoC stand-in.
    +
    +**Targets vs. target families.** Multi-arch CI builds a target *family* (e.g.
    +`gfx110X-all`), which expands to individual *targets* (`gfx1100`, `gfx1101`,
    +`gfx1102`, `gfx1103`). Split artifacts are emitted and named **per target** —
    +`fft_lib_gfx1100.tar.zst`, not per family — so the key's output identity must
    +distinguish targets, not families. This term is only load-bearing while split
    +artifacts share one source fingerprint; once each per-target artifact emits its
    +own `.fprint` (Required change 1), the fingerprint already differs per target and
    +folding the target into the key becomes a redundant safeguard rather than a
    +requirement. Build variant (release/ASan/...) is already captured by the CMake
    +flags in `THEROCK_FPRINT`, so it is not a separate key term.
    +
    +### Cache value (manifest)
    +
    +```
    +cache_key -> Manifest {
    +  artifact: (name, component, target)
    +  outputs:  [ {key, uri->S3 pointer, digest sha256, size} ]
    +  provenance: {repository, run_id, branch, commit, workflow, created_at}
    +  build_variant, dep_identities
    +  trust:       trusted | untrusted
    +  validation:  unvalidated | build_passed | tests_passed
    +  publication: pending | published | revoked
    +}
    +```
    +
    +A **read policy** filters at lookup time (default: `trusted` + `build_passed` +
    +`published`). `trust` = push/schedule on a protected branch vs. pull_request (PR
    +entries are stored but tagged, so PRs cannot poison shared reuse). `publication`
    +enforces write ordering (readers trust only `published`).

    Same here, unnecessary complexity.

    Only trusted runs write to the cache.
    "build passed" is irrelevant.

  • All cache entries are "published", no intermediate "pending" or stale "revoked"
  • ScottTodd ScottTodd commented on Nov 18, 2026 18:24 UTC
    Reviewer

    Thanks, this is improving.

    I think we should restructure this to make it easier to digest though. In particular I see three main components that are worth calling out directly as section headings

    1. The build system produces fprints for artifacts. If the fprint is the same, artifacts are expected to be equivalent (ideally bit identical).
    * Here we can list open areas for improvement - support both generic artifacts (already works) and device-specific artifacts (not yet implemented), make more artifacts reproducible (link the llvm changes so far)
    2. The CI system, under certain conditions, reads and writes from/to a remote cache for fprint cache. Trusted runs can write to the cache, non-release runs can read from the cache.
    3. The remote cache database provides efficient lookup of cache entries.

    Right now the document leads with "cache key design" and "cache value (manifest)" when those are implementation details between 2 and 3. Then other sections like "Required changes" are lacking qualification/detail.

    Can you guys rewrite sections of this RFC to better represent the overall architecture, putting implementation decisions under appropriate sections within that?

    therock-pr-bot[bot] therock-pr-bot[bot] commented on Nov 20, 2026 22:10 UTC
    Bot

    <!-- therock-pr-bot-fix-policies -->
    🎉 All checks passed! This PR is ready for review.

    erman-gurses erman-gurses commented on code on Nov 23, 2026 08:06 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -127,21 +148,45 @@ Local `gfx110X-all` build, no workflow edits:
     
     1. Emit `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
        artifacts — core fingerprinting change; largest reuse unlock.
    -2. Fold `target_family` (output identity) into the key (prevents per-arch collision).
    +2. Distinguish **targets** (not just families) in the key so per-arch artifacts do
    +   not collide. Needed only while split artifacts share one fingerprint; subsumed
    +   once change 1 emits a per-target `.fprint`.
     3. Finalize + freeze key composition (container digest, env allowlist) under `CACHE_EPOCH`.
    -4. Upload fingerprints + manifests as part of CI runs.
    +4. Reproducible fingerprints. Reuse is only safe when a fresh build reproduces a
    +   prior run's fingerprint; non-reproducibility is a false *miss* (safe, wasteful).
    +   MLIR reconfiguration stability is fixed ([#9936](https://github.com/ROCm/TheRock/pull/9936));
    +   HIPCC fresh-build reproducibility is the current open item, and source-identity
    +   scoping is refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)).

    Keeping them as issues is better - I consolidated anything regarding fingerprint stability under this issue: https://github.com/ROCm/TheRock/issues/9525.

    I opened this one just for communication for the POC regarding fingerprint stability : https://github.com/ROCm/TheRock/pull/9732 - closed it

    erman-gurses erman-gurses commented on code on Nov 23, 2026 08:11 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1

    Also updated some of the 16s -> 17s in the PR description

    erman-gurses erman-gurses commented on code on Nov 23, 2026 08:44 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,246 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-20
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +This RFC proposes caching CI build artifacts by content, keyed on the
    +`THEROCK_FPRINT` that CMake already computes for each artifact. A run computes
    +the fingerprint of every artifact it would build, looks those fingerprints up in
    +a shared database in one query, and downloads the matching prebuilt artifacts
    +instead of rebuilding them. This replaces the "baseline run" stage-reuse
    +mechanism, which picks a prior run by commit ancestry and S3-filename presence
    +rather than by what the sources actually produce. Tracks
    +[#8651](https://github.com/ROCm/TheRock/issues/8651).
    +
    +## Problem
    +
    +Reuse today walks workflow history to find a baseline run, then trusts it based on
    +commit ancestry, S3 archive filenames, and job health
    +(`baseline_runs.py`, `stage_reuse_decision.py`). Fingerprints are never
    +consulted. This is O(N) over runs, spends a lot of GitHub API calls, can't express
    +rocm-libraries → rocm-libraries dependencies or arbitrary build-graph subsets, and
    +is brittle on release branches ([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` already hashes the inputs that determine an artifact's output —
    +its sources, its dependencies' fingerprints, the toolchain, and the build flags.
    +If two builds compute the same fingerprint, they would produce the same artifact,
    +so we can reuse it. That makes the fingerprint the natural cache key and removes
    +the history walk entirely.
    +
    +## Goals
    +
    +- Look reuse up by content in one batched query, independent of run history.
    +- Reuse unchanged artifacts across pin bumps and component commits; rebuild only
    +  what actually changed.
    +- Verify every reused object; anything missing or unverifiable falls back to a
    +  build.
    +- Compose with [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md) — a cache
    +  hit never suppresses a test.
    +
    +## Non-goals
    +
    +- Test selection — that stays in RFC0013.
    +- Replacing `ccache`, which caches compiler calls; this caches whole artifacts
    +  and stacks on top of it.
    +- New object storage — artifacts already live in the `ci-artifacts` S3 buckets;
    +  the cache stores pointers, not copies.
    +
    +## Design
    +
    +### The key
    +
    +The key is the artifact's source fingerprint plus the recipe inputs and output
    +identity, under a global epoch we can bump to invalidate everything at once:
    +
    +```text
    +cache_key = e{CACHE_EPOCH}:SHA256(source_fingerprint, recipe_inputs, output_identity)
    +```
    +
    +Most of what the key needs is already inside `THEROCK_FPRINT`:
    +
    +| Input                                                                               | In `THEROCK_FPRINT`? | Notes                                                            |
    +| ----------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------- |
    +| Source identity (project-scoped Git tree + declared extra inputs; invalid if dirty) | yes                  | see below                                                        |
    +| Dependency fingerprints                                                             | yes                  | a dependency change propagates to its consumers                  |
    +| Toolchain file                                                                      | yes                  |                                                                  |
    +| Build flags (including the variant, e.g. release vs. ASan)                          | yes                  | already folded in, so the variant is not a separate key term     |
    +| Output identity (`name`, `component`, `target`)                                     | partial              | needed only until split artifacts fingerprint per target (below) |
    +| Container image digest                                                              | no                   | add, so a different build image invalidates                      |
    +| Compiler id + version                                                               | indirect             | add explicitly                                                   |
    +
    +A note on **targets vs. target families**: multi-arch CI builds a *family* like
    +`gfx110X-all`, which expands to the *targets* `gfx1100`–`gfx1103`, and split
    +artifacts are named per target (`fft_lib_gfx1100.tar.zst`). So the key has to
    +distinguish targets, not families. This is only load-bearing while every target
    +of a split artifact shares one fingerprint; once split artifacts emit a `.fprint`
    +per target, the fingerprint already differs per target and this term goes away.
    +
    +### Fingerprint computation and stability
    +
    +The fingerprint is only useful if a fresh build reproduces it. Source identity is
    +scoped to a subproject's Git tree plus declared extra inputs
    +([#9907](https://github.com/ROCm/TheRock/pull/9907)), so a repo-wide commit
    +doesn't invalidate a subproject whose own sources didn't change, and a dirty tree
    +produces an invalid fingerprint that is never cached.
    +
    +The failure to avoid is a *false hit* — reusing an artifact that should have been
    +rebuilt — which can only happen if the fingerprint misses a real input. A
    +*false miss* (a fingerprint that doesn't reproduce) is merely wasteful. So
    +fingerprint stability gates the whole feature, and we track it under #8651: MLIR
    +reconfiguration stability ([#9936](https://github.com/ROCm/TheRock/pull/9936))
    +and the hipcc changelog timestamp
    +([llvm-project#5411](https://github.com/ROCm/llvm-project/pull/5411)) are fixed;
    +hipcc fresh-build reproducibility is the open item.
    +
    +### The value
    +
    +The database maps a key to the objects that make up the artifact, plus enough
    +provenance to debug a reuse:
    +
    +```text
    +cache_key -> {
    +  artifact:   (name, component, target)
    +  outputs:    [ {object_key, s3_uri, sha256, size_bytes} ]
    +  provenance: {repository, run_id, commit, created_at}
    +}
    +```
    +
    +That's deliberately all of it. We don't store trust, validation, or publication
    +state: only trusted runs (push/scheduled on a protected branch) write to the
    +cache, so a PR can't poison it without us recording a "trust" flag; whether tests
    +passed is irrelevant to a build cache; and a key existing in the database is what
    +"published" means.
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](../assets/RFC0017-cache-flow.svg)
    +
    +- **Plan** (per run): from the changed paths, compute the fingerprint of each
    +  artifact the run would build and look them all up in one query. Changed
    +  artifacts are forced misses. Hits are reuse candidates; misses get built.
    +- **Restore** (per hit): download the objects and re-verify their SHA-256
    +  digests. A missing object or a digest mismatch demotes the hit to a build, so
    +  storage drift can never hand back a wrong artifact.
    +- **Publish** (per built artifact, trusted runs only): upload the objects, then
    +  write the entry.
    +
    +### The database
    +
    +Objects stay in the S3 buckets; the index stores pointers and tolerates objects
    +being retention-deleted (a dangling entry just falls back to a build).
    +
    +The index needs to be a **server-side database** that is written as artifacts are
    +uploaded and can be rebuilt from a cold start by backfilling from S3 or replaying
    +run history. A file checked into Git is fine for an early proof of concept but
    +won't scale: a real cache writes an entry per artifact per trusted run, which is
    +far too many commits for a Git repo (Quartz is already ~60k commits). We put a
    +small `lookup(fingerprints)` / `publish(entries)` interface in front of it so the
    +first LLVM-only prototype can use a checked-in JSON
    +([#10026](https://github.com/ROCm/TheRock/pull/10026)) and switch to the
    +server-side store without touching callers. Fingerprints are already uploaded
    +next to their artifacts ([#9921](https://github.com/ROCm/TheRock/pull/9921)), so
    +populating the database just records existing sidecars.
    +
    +### Using it
    +
    +Reuse is driven by small scripts over the database, in the spirit of the existing
    +[`find_latest_artifacts.py`](https://github.com/ROCm/TheRock/blob/main/build_tools/find_latest_artifacts.py):
    +one that asks the database which artifacts match the current sources, and a
    +bootstrap script that fetches them and marks their stages prebuilt. CI runs these
    +in its build-planning step; a developer can run the same scripts to start a local
    +build from cached artifacts. There is no cache on/off switch in the build system
    +itself — this is a CI feature plus opt-in scripts.
    +
    +## Controlling reuse
    +
    +- CI picks a **reuse mode**: `off` (build everything), `dry-run` (compute and
    +  report the plan but still build — how we validate predictions before trusting
    +  them), or `on`.
    +- **Release builds** build everything from source and don't read the cache. This
    +  is a normal mode we run regularly, not a kill switch.
    +- **`CACHE_EPOCH`** is the one global lever: bump it to invalidate every key, for
    +  a schema change or an environment change the fingerprint doesn't capture.
    +
    +Per-entry controls — ignoring a specific hit, revoking a bad entry — are left as
    +future ideas; we don't need them to start.
    +
    +## What we measured
    +
    +A benchmark harness drove a real `gfx110X-all` build against a real database:
    +
    +- **Reuse works and tracks the dependency graph.** An unchanged rebuild is a 100%
    +  hit. Changing a leaf tool (`compiler/hipify`) invalidates 2 artifacts; changing
    +  the compiler (`compiler/amd-llvm`) invalidates its whole downstream cone, 132 of
    +  206 — which is correct, since everything builds with it.
    +- **The big gap is split artifacts.** Of 349 artifacts, 206 are cacheable and
    +  143 (~41%) are not: the per-target split artifacts emit no `.fprint`
    +  (`if(NOT _should_split)` in `cmake/therock_artifacts.cmake`), and that set
    +  includes the expensive libraries (`blas`, `fft`, `composable-kernel`,
    +  `hipkernelprovider`). Fingerprinting them is the largest win on the table.
    +- **The payoff is real.** On a full run the cold build took ~100 min and an
    +  unchanged warm rerun ~3 s.
    +
    +Two caveats on these numbers: the per-component rows perturb a non-compiled file,
    +so they measure invalidation scope rather than rebuild time; and lookups ran from
    +the build host to an external ClickHouse Cloud instance (~100 ms per query), an
    +upper bound that an in-region database would beat.
    +
    +## What this needs
    +
    +1. Emit a `.fprint` for split (Kpack, [RFC0008](./RFC0008-Multi-Arch-Packaging.md))
    +   artifacts. Biggest reuse unlock, and it also retires the per-target key term.
    +1. Add the container image digest and explicit compiler id+version to the key,
    +   then freeze the composition under `CACHE_EPOCH`.
    +1. Stand up the server-side database with populate-on-upload and cold-start
    +   backfill.
    +
    +## Plan
    +
    +Start where a wrong reuse is cheapest to catch and the savings are largest — the
    +compiler — and widen only as each stage proves out, following the staged rollout
    +from when fingerprints were first added
    +([#2432](https://github.com/ROCm/TheRock/pull/2432)). Each step is gated on
    +evidence that a false hit can't happen before the next begins.
    +
    +1. **Reproducible fingerprints** (gating, in progress): MLIR stability fixed
    +   (#9936), source scoping landed (#9907), hipcc reproducibility open.
    +1. **Fingerprints available** (landed): emit and upload `.fprint` next to each
    +   archive (#9921). Additive; nothing consumes them yet.

    Anything related to fingerprint stability - we can refer this issue: https://github.com/ROCm/TheRock/issues/9525

    erman-gurses erman-gurses commented on code on Nov 23, 2026 08:56 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,246 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-20
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +This RFC proposes caching CI build artifacts by content, keyed on the
    +`THEROCK_FPRINT` that CMake already computes for each artifact. A run computes
    +the fingerprint of every artifact it would build, looks those fingerprints up in
    +a shared database in one query, and downloads the matching prebuilt artifacts
    +instead of rebuilding them. This replaces the "baseline run" stage-reuse
    +mechanism, which picks a prior run by commit ancestry and S3-filename presence
    +rather than by what the sources actually produce. Tracks
    +[#8651](https://github.com/ROCm/TheRock/issues/8651).
    +
    +## Problem
    +
    +Reuse today walks workflow history to find a baseline run, then trusts it based on
    +commit ancestry, S3 archive filenames, and job health
    +(`baseline_runs.py`, `stage_reuse_decision.py`). Fingerprints are never
    +consulted. This is O(N) over runs, spends a lot of GitHub API calls, can't express
    +rocm-libraries → rocm-libraries dependencies or arbitrary build-graph subsets, and
    +is brittle on release branches ([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` already hashes the inputs that determine an artifact's output —
    +its sources, its dependencies' fingerprints, the toolchain, and the build flags.
    +If two builds compute the same fingerprint, they would produce the same artifact,
    +so we can reuse it. That makes the fingerprint the natural cache key and removes
    +the history walk entirely.
    +
    +## Goals
    +
    +- Look reuse up by content in one batched query, independent of run history.
    +- Reuse unchanged artifacts across pin bumps and component commits; rebuild only
    +  what actually changed.
    +- Verify every reused object; anything missing or unverifiable falls back to a
    +  build.
    +- Compose with [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md) — a cache
    +  hit never suppresses a test.
    +
    +## Non-goals
    +
    +- Test selection — that stays in RFC0013.
    +- Replacing `ccache`, which caches compiler calls; this caches whole artifacts
    +  and stacks on top of it.
    +- New object storage — artifacts already live in the `ci-artifacts` S3 buckets;
    +  the cache stores pointers, not copies.
    +
    +## Design
    +
    +### The key
    +
    +The key is the artifact's source fingerprint plus the recipe inputs and output
    +identity, under a global epoch we can bump to invalidate everything at once:
    +
    +```text
    +cache_key = e{CACHE_EPOCH}:SHA256(source_fingerprint, recipe_inputs, output_identity)
    +```
    +
    +Most of what the key needs is already inside `THEROCK_FPRINT`:
    +
    +| Input                                                                               | In `THEROCK_FPRINT`? | Notes                                                            |
    +| ----------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------- |
    +| Source identity (project-scoped Git tree + declared extra inputs; invalid if dirty) | yes                  | see below                                                        |
    +| Dependency fingerprints                                                             | yes                  | a dependency change propagates to its consumers                  |
    +| Toolchain file                                                                      | yes                  |                                                                  |
    +| Build flags (including the variant, e.g. release vs. ASan)                          | yes                  | already folded in, so the variant is not a separate key term     |
    +| Output identity (`name`, `component`, `target`)                                     | partial              | needed only until split artifacts fingerprint per target (below) |
    +| Container image digest                                                              | no                   | add, so a different build image invalidates                      |
    +| Compiler id + version                                                               | indirect             | add explicitly                                                   |
    +
    +A note on **targets vs. target families**: multi-arch CI builds a *family* like
    +`gfx110X-all`, which expands to the *targets* `gfx1100`–`gfx1103`, and split
    +artifacts are named per target (`fft_lib_gfx1100.tar.zst`). So the key has to
    +distinguish targets, not families. This is only load-bearing while every target
    +of a split artifact shares one fingerprint; once split artifacts emit a `.fprint`
    +per target, the fingerprint already differs per target and this term goes away.
    +
    +### Fingerprint computation and stability
    +
    +The fingerprint is only useful if a fresh build reproduces it. Source identity is
    +scoped to a subproject's Git tree plus declared extra inputs
    +([#9907](https://github.com/ROCm/TheRock/pull/9907)), so a repo-wide commit
    +doesn't invalidate a subproject whose own sources didn't change, and a dirty tree
    +produces an invalid fingerprint that is never cached.
    +
    +The failure to avoid is a *false hit* — reusing an artifact that should have been
    +rebuilt — which can only happen if the fingerprint misses a real input. A
    +*false miss* (a fingerprint that doesn't reproduce) is merely wasteful. So
    +fingerprint stability gates the whole feature, and we track it under #8651: MLIR
    +reconfiguration stability ([#9936](https://github.com/ROCm/TheRock/pull/9936))
    +and the hipcc changelog timestamp
    +([llvm-project#5411](https://github.com/ROCm/llvm-project/pull/5411)) are fixed;
    +hipcc fresh-build reproducibility is the open item.
    +
    +### The value
    +
    +The database maps a key to the objects that make up the artifact, plus enough
    +provenance to debug a reuse:
    +
    +```text
    +cache_key -> {
    +  artifact:   (name, component, target)
    +  outputs:    [ {object_key, s3_uri, sha256, size_bytes} ]
    +  provenance: {repository, run_id, commit, created_at}
    +}
    +```
    +
    +That's deliberately all of it. We don't store trust, validation, or publication
    +state: only trusted runs (push/scheduled on a protected branch) write to the
    +cache, so a PR can't poison it without us recording a "trust" flag; whether tests
    +passed is irrelevant to a build cache; and a key existing in the database is what
    +"published" means.
    +
    +### Flows
    +
    +![Cache flow and the file behind each step](../assets/RFC0017-cache-flow.svg)
    +
    +- **Plan** (per run): from the changed paths, compute the fingerprint of each
    +  artifact the run would build and look them all up in one query. Changed
    +  artifacts are forced misses. Hits are reuse candidates; misses get built.
    +- **Restore** (per hit): download the objects and re-verify their SHA-256
    +  digests. A missing object or a digest mismatch demotes the hit to a build, so
    +  storage drift can never hand back a wrong artifact.
    +- **Publish** (per built artifact, trusted runs only): upload the objects, then
    +  write the entry.
    +
    +### The database
    +
    +Objects stay in the S3 buckets; the index stores pointers and tolerates objects
    +being retention-deleted (a dangling entry just falls back to a build).
    +
    +The index needs to be a **server-side database** that is written as artifacts are
    +uploaded and can be rebuilt from a cold start by backfilling from S3 or replaying
    +run history. A file checked into Git is fine for an early proof of concept but
    +won't scale: a real cache writes an entry per artifact per trusted run, which is
    +far too many commits for a Git repo (Quartz is already ~60k commits). We put a
    +small `lookup(fingerprints)` / `publish(entries)` interface in front of it so the
    +first LLVM-only prototype can use a checked-in JSON
    +([#10026](https://github.com/ROCm/TheRock/pull/10026)) and switch to the
    +server-side store without touching callers. Fingerprints are already uploaded
    +next to their artifacts ([#9921](https://github.com/ROCm/TheRock/pull/9921)), so
    +populating the database just records existing sidecars.
    +
    +### Using it
    +
    +Reuse is driven by small scripts over the database, in the spirit of the existing
    +[`find_latest_artifacts.py`](https://github.com/ROCm/TheRock/blob/main/build_tools/find_latest_artifacts.py):
    +one that asks the database which artifacts match the current sources, and a
    +bootstrap script that fetches them and marks their stages prebuilt. CI runs these
    +in its build-planning step; a developer can run the same scripts to start a local
    +build from cached artifacts. There is no cache on/off switch in the build system
    +itself — this is a CI feature plus opt-in scripts.
    +
    +## Controlling reuse
    +
    +- CI picks a **reuse mode**: `off` (build everything), `dry-run` (compute and
    +  report the plan but still build — how we validate predictions before trusting
    +  them), or `on`.
    +- **Release builds** build everything from source and don't read the cache. This
    +  is a normal mode we run regularly, not a kill switch.
    +- **`CACHE_EPOCH`** is the one global lever: bump it to invalidate every key, for
    +  a schema change or an environment change the fingerprint doesn't capture.
    +
    +Per-entry controls — ignoring a specific hit, revoking a bad entry — are left as
    +future ideas; we don't need them to start.
    +
    +## What we measured
    +
    +A benchmark harness drove a real `gfx110X-all` build against a real database:
    +
    +- **Reuse works and tracks the dependency graph.** An unchanged rebuild is a 100%
    +  hit. Changing a leaf tool (`compiler/hipify`) invalidates 2 artifacts; changing
    +  the compiler (`compiler/amd-llvm`) invalidates its whole downstream cone, 132 of
    +  206 — which is correct, since everything builds with it.
    +- **The big gap is split artifacts.** Of 349 artifacts, 206 are cacheable and
    +  143 (~41%) are not: the per-target split artifacts emit no `.fprint`
    +  (`if(NOT _should_split)` in `cmake/therock_artifacts.cmake`), and that set
    +  includes the expensive libraries (`blas`, `fft`, `composable-kernel`,
    +  `hipkernelprovider`). Fingerprinting them is the largest win on the table.
    +- **The payoff is real.** On a full run the cold build took ~100 min and an
    +  unchanged warm rerun ~3 s.

    Maybe overstated (~3 s )- we still have download and extraction time.

    erman-gurses erman-gurses commented on code on Nov 23, 2026 08:59 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,246 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-20
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +This RFC proposes caching CI build artifacts by content, keyed on the
    +`THEROCK_FPRINT` that CMake already computes for each artifact. A run computes
    +the fingerprint of every artifact it would build, looks those fingerprints up in
    +a shared database in one query, and downloads the matching prebuilt artifacts
    +instead of rebuilding them. This replaces the "baseline run" stage-reuse
    +mechanism, which picks a prior run by commit ancestry and S3-filename presence
    +rather than by what the sources actually produce. Tracks
    +[#8651](https://github.com/ROCm/TheRock/issues/8651).
    +
    +## Problem
    +
    +Reuse today walks workflow history to find a baseline run, then trusts it based on
    +commit ancestry, S3 archive filenames, and job health
    +(`baseline_runs.py`, `stage_reuse_decision.py`). Fingerprints are never
    +consulted. This is O(N) over runs, spends a lot of GitHub API calls, can't express
    +rocm-libraries → rocm-libraries dependencies or arbitrary build-graph subsets, and
    +is brittle on release branches ([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` already hashes the inputs that determine an artifact's output —
    +its sources, its dependencies' fingerprints, the toolchain, and the build flags.
    +If two builds compute the same fingerprint, they would produce the same artifact,
    +so we can reuse it. That makes the fingerprint the natural cache key and removes
    +the history walk entirely.
    +
    +## Goals
    +
    +- Look reuse up by content in one batched query, independent of run history.
    +- Reuse unchanged artifacts across pin bumps and component commits; rebuild only
    +  what actually changed.
    +- Verify every reused object; anything missing or unverifiable falls back to a
    +  build.
    +- Compose with [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md) — a cache
    +  hit never suppresses a test.
    +
    +## Non-goals
    +
    +- Test selection — that stays in RFC0013.
    +- Replacing `ccache`, which caches compiler calls; this caches whole artifacts
    +  and stacks on top of it.
    +- New object storage — artifacts already live in the `ci-artifacts` S3 buckets;
    +  the cache stores pointers, not copies.
    +
    +## Design
    +
    +### The key
    +
    +The key is the artifact's source fingerprint plus the recipe inputs and output
    +identity, under a global epoch we can bump to invalidate everything at once:
    +
    +```text
    +cache_key = e{CACHE_EPOCH}:SHA256(source_fingerprint, recipe_inputs, output_identity)
    +```

    By source_fingerprint, do you mean THEROCK_FPRINT?

    erman-gurses erman-gurses commented on code on Nov 23, 2026 09:01 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,246 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-20
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +This RFC proposes caching CI build artifacts by content, keyed on the
    +`THEROCK_FPRINT` that CMake already computes for each artifact. A run computes
    +the fingerprint of every artifact it would build, looks those fingerprints up in
    +a shared database in one query, and downloads the matching prebuilt artifacts
    +instead of rebuilding them. This replaces the "baseline run" stage-reuse
    +mechanism, which picks a prior run by commit ancestry and S3-filename presence
    +rather than by what the sources actually produce. Tracks
    +[#8651](https://github.com/ROCm/TheRock/issues/8651).
    +
    +## Problem
    +
    +Reuse today walks workflow history to find a baseline run, then trusts it based on
    +commit ancestry, S3 archive filenames, and job health
    +(`baseline_runs.py`, `stage_reuse_decision.py`). Fingerprints are never
    +consulted. This is O(N) over runs, spends a lot of GitHub API calls, can't express
    +rocm-libraries → rocm-libraries dependencies or arbitrary build-graph subsets, and
    +is brittle on release branches ([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +`THEROCK_FPRINT` already hashes the inputs that determine an artifact's output —
    +its sources, its dependencies' fingerprints, the toolchain, and the build flags.
    +If two builds compute the same fingerprint, they would produce the same artifact,
    +so we can reuse it. That makes the fingerprint the natural cache key and removes
    +the history walk entirely.
    +
    +## Goals
    +
    +- Look reuse up by content in one batched query, independent of run history.
    +- Reuse unchanged artifacts across pin bumps and component commits; rebuild only
    +  what actually changed.
    +- Verify every reused object; anything missing or unverifiable falls back to a
    +  build.
    +- Compose with [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md) — a cache
    +  hit never suppresses a test.
    +
    +## Non-goals
    +
    +- Test selection — that stays in RFC0013.
    +- Replacing `ccache`, which caches compiler calls; this caches whole artifacts
    +  and stacks on top of it.
    +- New object storage — artifacts already live in the `ci-artifacts` S3 buckets;
    +  the cache stores pointers, not copies.
    +
    +## Design
    +
    +### The key
    +
    +The key is the artifact's source fingerprint plus the recipe inputs and output
    +identity, under a global epoch we can bump to invalidate everything at once:
    +
    +```text
    +cache_key = e{CACHE_EPOCH}:SHA256(source_fingerprint, recipe_inputs, output_identity)
    +```
    +
    +Most of what the key needs is already inside `THEROCK_FPRINT`:
    +
    +| Input                                                                               | In `THEROCK_FPRINT`? | Notes                                                            |
    +| ----------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------- |
    +| Source identity (project-scoped Git tree + declared extra inputs; invalid if dirty) | yes                  | see below                                                        |
    +| Dependency fingerprints                                                             | yes                  | a dependency change propagates to its consumers                  |
    +| Toolchain file                                                                      | yes                  |                                                                  |
    +| Build flags (including the variant, e.g. release vs. ASan)                          | yes                  | already folded in, so the variant is not a separate key term     |
    +| Output identity (`name`, `component`, `target`)                                     | partial              | needed only until split artifacts fingerprint per target (below) |
    +| Container image digest                                                              | no                   | add, so a different build image invalidates                      |
    +| Compiler id + version                                                               | indirect             | add explicitly                                                   |
    +
    +A note on **targets vs. target families**: multi-arch CI builds a *family* like
    +`gfx110X-all`, which expands to the *targets* `gfx1100`–`gfx1103`, and split
    +artifacts are named per target (`fft_lib_gfx1100.tar.zst`). So the key has to
    +distinguish targets, not families. This is only load-bearing while every target
    +of a split artifact shares one fingerprint; once split artifacts emit a `.fprint`
    +per target, the fingerprint already differs per target and this term goes away.
    +
    +### Fingerprint computation and stability
    +
    +The fingerprint is only useful if a fresh build reproduces it. Source identity is
    +scoped to a subproject's Git tree plus declared extra inputs
    +([#9907](https://github.com/ROCm/TheRock/pull/9907)), so a repo-wide commit
    +doesn't invalidate a subproject whose own sources didn't change, and a dirty tree
    +produces an invalid fingerprint that is never cached.
    +
    +The failure to avoid is a *false hit* — reusing an artifact that should have been
    +rebuilt — which can only happen if the fingerprint misses a real input. A
    +*false miss* (a fingerprint that doesn't reproduce) is merely wasteful. So
    +fingerprint stability gates the whole feature, and we track it under #8651: MLIR
    +reconfiguration stability ([#9936](https://github.com/ROCm/TheRock/pull/9936))
    +and the hipcc changelog timestamp
    +([llvm-project#5411](https://github.com/ROCm/llvm-project/pull/5411)) are fixed;
    +hipcc fresh-build reproducibility is the open item.
    +
    +### The value
    +
    +The database maps a key to the objects that make up the artifact, plus enough
    +provenance to debug a reuse:
    +
    +```text
    +cache_key -> {
    +  artifact:   (name, component, target)
    +  outputs:    [ {object_key, s3_uri, sha256, size_bytes} ]
    +  provenance: {repository, run_id, commit, created_at}
    +}
    +```
    +
    +That's deliberately all of it. We don't store trust, validation, or publication
    +state: only trusted runs (push/scheduled on a protected branch) write to the
    +cache, so a PR can't poison it without us recording a "trust" flag; whether tests

    _only trusted runs (push/scheduled on a protected branch) write to the cache_ - Maybe we can mention how is this enforced?

    erman-gurses erman-gurses commented on Nov 23, 2026 09:02 UTC
    Reviewer

    Please see my comments, I will do one more pass.

    erman-gurses erman-gurses commented on code on Nov 23, 2026 19:14 UTC
    Code Review
    docs/rfcs/RFC0016-Fingerprint-Based-Artifact-Cache.md:1
    @@ -48,29 +48,39 @@ dependency fingerprints, toolchain, and build flags. We use it as the cache key.
     ### Cache key
     
     ```
    -cache_key = e{EPOCH}:{build_variant}:{SHA256(source_fingerprint, build_variant,
    -                                             recipe_inputs, output_identity)}
    +cache_key = e{EPOCH}:{SHA256(source_fingerprint, recipe_inputs, output_identity)}
     ```
     
     | Input | In `THEROCK_FPRINT` | Action |
     | --- | --- | --- |
    -| Subproject source identity (committed rev/HEAD; invalid if dirty) | yes | keep |
    +| Subproject source identity (project-scoped git tree + extra inputs; invalid if dirty) | yes | keep — computation refined in RFC0017 ([#9732](https://github.com/ROCm/TheRock/pull/9732)) |

    I consolidated anything regarding fingerprint stability under this issue: https://github.com/ROCm/TheRock/issues/9525

    erman-gurses erman-gurses commented on Nov 24, 2026 19:53 UTC
    Contributor

    Worked on these updates below:

    1. Restructured around three components: the build system (fingerprints), CI (read/write policy, consumer and producer flows) and the remote cache database.
    2. Rewrote the Problem to describe how reuse works today (baseline runs, stage granularity, API cost, release branches disabled), and moved the AMD LLVM slice out of the design sections into the Implementation Plan.
    3. The first slice (AMD LLVM) moved out of the design sections and into an incremental Implementation Plan. The plan expands outward to ROCm Systems and Libraries, with one enablement checklist and retiring baseline reuse as the last step.
    4. Reorganized the plan into one enablement checklist plus an 8-milestone table, from AMD LLVM outward to ROCm Systems and Libraries, ending with retiring baseline reuse.
    5. Made the test scenarios concrete (rocFFT, runtime, HSA headers, TheRock PR) and cut evidence and open-decision text to a short list.

    CC: @ammallya

    ammallya ammallya commented on code on Nov 24, 2026 22:05 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,313 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-23
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +## Problem
    +
    +Today reuse walks recent workflow runs to select a single baseline run, then decides
    +per build stage using change-impact analysis plus commit-compatibility, job-health,
    +and artifact-availability checks (`baseline_runs.py`, `stage_reuse_decision.py`).
    +Fingerprints are never consulted. Reuse is therefore limited to whole stages from one
    +run, cannot combine compatible artifacts from different runs, and costs GitHub API
    +queries for runs and jobs plus artifact listings on every selection. Release
    +branches disable reuse
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +## Proposed solution
    +
    +Select reusable artifacts by the fingerprints computed during build configuration.
    +CI queries the artifact cache index, verifies and restores usable matches, and
    +builds artifacts without usable matches. Compatible artifacts may come from
    +different producer runs.
    +
    +Trusted producer runs upload archives, checksums, and fingerprints, then publish
    +entries to the remote cache database. The database records artifact locations;
    +archives remain in the existing S3 buckets.
    +
    +## Goals
    +
    +- Preserve reuse when unrelated sources or repository commits change.
    +- Rebuild artifacts when relevant sources, configuration, selected files, or
    +  dependency fingerprints change.
    +- Support partial reuse within stages and across the build graph.
    +- Once all projects in a source set are enabled, a PR that changes only ROCm
    +  Libraries hits the cache for every ROCm Systems project.
    +- Fall back to building when cached artifacts cannot be restored safely.
    +- Keep test selection independent of reuse: a hit does not suppress tests selected
    +  by [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md).
    +
    +## Non-goals
    +
    +- Replacing `ccache` or `sccache`, which cache individual compilation operations.
    +- Introducing new artifact object storage.
    +- Adding automatic remote-cache access to ordinary CMake invocations.
    +- Requiring byte-identical outputs for the explicitly accepted metadata
    +  differences described below.
    +
    +## Overall architecture
    +
    +The build system defines compatibility, the remote cache database finds candidate
    +artifacts, and CI verifies and restores them.
    +
    +![Fingerprint-based artifact cache flow](../assets/RFC0017-cache-flow.svg)
    +
    +### 1. Build system: artifact fingerprints
    +
    +TheRock computes fingerprints during CMake configuration. Input changes require
    +reconfiguration before building or querying the cache.
    +
    +| Term                   | Meaning                                                                                                                                      |
    +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    +| Source identity        | Identity of a selected source directory, using its applicable `.smrev` marker or Git tree. Additional source inputs are declared explicitly. |
    +| Subproject fingerprint | Combines source identity, selected configuration values and file hashes, and dependency fingerprints.                                        |
    +| Artifact fingerprint   | Accounts for the artifact's contributing subprojects and is used for artifact lookup.                                                        |
    +| Archive checksum       | Verifies the bytes of a particular archive; it does not establish build compatibility.                                                       |
    +
    +Equal artifact fingerprints should identify interchangeable artifacts, ideally
    +with identical bytes. Validation must detect both false hits (changed relevant
    +inputs retain a fingerprint) and false misses (equivalent inputs produce different
    +fingerprints). Invalid fingerprints must not authorize reuse, although local
    +source builds may continue.
    +
    +A **restore group** contains the components required to restore one artifact name
    +and target. For example, restoring the complete generic `amd-llvm` bundle requires
    +its `dbg`, `dev`, `doc`, `lib`, and `run` components, containing outputs from
    +`amd-llvm`, `amd-comgr`, and `hipcc`. For generic reuse, those components must share
    +one fingerprint and be restored together. This differs from `artifact_group` in
    +`BUILD_TOPOLOGY.toml`, which organizes artifacts for stage planning.
    +
    +Dependencies follow declared inputs, including inputs across repository
    +boundaries. LLVM's additional inputs include the SPIR-V translator and, on
    +applicable platforms, HSA headers. See
    +[#9907](https://github.com/ROCm/TheRock/pull/9907) for source scoping and additional
    +inputs.
    +
    +#### Coverage and stability
    +
    +Fingerprint correctness, stability, and robustness are tracked in
    +[#9525](https://github.com/ROCm/TheRock/issues/9525).
    +
    +Generic artifacts provide the initial implementation path. Device-specific and
    +split artifacts need fingerprint generation, target identification, and validated
    +restoration rules before reuse is enabled. This includes outputs described in
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md).
    +
    +#### Accepted metadata differences
    +
    +Non-release CI may reuse unchanged HIPCC inputs with the producer's original
    +changelog timestamp. Relevant HIPCC source changes must invalidate the applicable
    +fingerprints. Making changelog bytes reproducible across fresh builds is optional
    +and non-blocking under this policy; see
    +[#10011](https://github.com/ROCm/TheRock/issues/10011). Other metadata differences
    +require explicit justification. Release builds do not consume cached artifacts.
    +
    +### 2. CI system: cache consumption and publication
    +
    +#### Read and write policy
    +
    +Non-release CI may read artifacts enabled for reuse. Only trusted producer runs
    +may publish to the shared cache. CI identity and permissions must prevent
    +untrusted jobs from modifying either the database or trusted artifact objects.
    +An unrelated test failure does not by itself make a successfully produced artifact
    +unusable; complete matching outputs and trusted provenance are required.
    +
    +Release builds build from source. Artifact reuse does not change which tests run.
    +The cache does not need per-entry trust or test-validation states: only complete
    +entries from authorized producers become visible to readers.
    +
    +#### Consumer flow
    +
    +The stage job that uses restored outputs also computes fingerprints and builds
    +misses. It must use the same stage configuration procedure as producer builds,

    the consumer should assert the restored artifact's fprint matches the producer's before trusting it, so config drift becomes a clean miss rather than a silent bad hit.

    ammallya ammallya commented on code on Nov 24, 2026 22:06 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,313 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-23
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +## Problem
    +
    +Today reuse walks recent workflow runs to select a single baseline run, then decides
    +per build stage using change-impact analysis plus commit-compatibility, job-health,
    +and artifact-availability checks (`baseline_runs.py`, `stage_reuse_decision.py`).
    +Fingerprints are never consulted. Reuse is therefore limited to whole stages from one
    +run, cannot combine compatible artifacts from different runs, and costs GitHub API
    +queries for runs and jobs plus artifact listings on every selection. Release
    +branches disable reuse
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +## Proposed solution
    +
    +Select reusable artifacts by the fingerprints computed during build configuration.
    +CI queries the artifact cache index, verifies and restores usable matches, and
    +builds artifacts without usable matches. Compatible artifacts may come from
    +different producer runs.
    +
    +Trusted producer runs upload archives, checksums, and fingerprints, then publish
    +entries to the remote cache database. The database records artifact locations;
    +archives remain in the existing S3 buckets.
    +
    +## Goals
    +
    +- Preserve reuse when unrelated sources or repository commits change.
    +- Rebuild artifacts when relevant sources, configuration, selected files, or
    +  dependency fingerprints change.
    +- Support partial reuse within stages and across the build graph.
    +- Once all projects in a source set are enabled, a PR that changes only ROCm
    +  Libraries hits the cache for every ROCm Systems project.
    +- Fall back to building when cached artifacts cannot be restored safely.
    +- Keep test selection independent of reuse: a hit does not suppress tests selected
    +  by [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md).
    +
    +## Non-goals
    +
    +- Replacing `ccache` or `sccache`, which cache individual compilation operations.
    +- Introducing new artifact object storage.
    +- Adding automatic remote-cache access to ordinary CMake invocations.
    +- Requiring byte-identical outputs for the explicitly accepted metadata
    +  differences described below.
    +
    +## Overall architecture
    +
    +The build system defines compatibility, the remote cache database finds candidate
    +artifacts, and CI verifies and restores them.
    +
    +![Fingerprint-based artifact cache flow](../assets/RFC0017-cache-flow.svg)
    +
    +### 1. Build system: artifact fingerprints
    +
    +TheRock computes fingerprints during CMake configuration. Input changes require
    +reconfiguration before building or querying the cache.
    +
    +| Term                   | Meaning                                                                                                                                      |
    +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    +| Source identity        | Identity of a selected source directory, using its applicable `.smrev` marker or Git tree. Additional source inputs are declared explicitly. |
    +| Subproject fingerprint | Combines source identity, selected configuration values and file hashes, and dependency fingerprints.                                        |
    +| Artifact fingerprint   | Accounts for the artifact's contributing subprojects and is used for artifact lookup.                                                        |
    +| Archive checksum       | Verifies the bytes of a particular archive; it does not establish build compatibility.                                                       |
    +
    +Equal artifact fingerprints should identify interchangeable artifacts, ideally
    +with identical bytes. Validation must detect both false hits (changed relevant
    +inputs retain a fingerprint) and false misses (equivalent inputs produce different
    +fingerprints). Invalid fingerprints must not authorize reuse, although local
    +source builds may continue.
    +
    +A **restore group** contains the components required to restore one artifact name
    +and target. For example, restoring the complete generic `amd-llvm` bundle requires
    +its `dbg`, `dev`, `doc`, `lib`, and `run` components, containing outputs from
    +`amd-llvm`, `amd-comgr`, and `hipcc`. For generic reuse, those components must share
    +one fingerprint and be restored together. This differs from `artifact_group` in
    +`BUILD_TOPOLOGY.toml`, which organizes artifacts for stage planning.
    +
    +Dependencies follow declared inputs, including inputs across repository
    +boundaries. LLVM's additional inputs include the SPIR-V translator and, on
    +applicable platforms, HSA headers. See
    +[#9907](https://github.com/ROCm/TheRock/pull/9907) for source scoping and additional
    +inputs.
    +
    +#### Coverage and stability
    +
    +Fingerprint correctness, stability, and robustness are tracked in
    +[#9525](https://github.com/ROCm/TheRock/issues/9525).
    +
    +Generic artifacts provide the initial implementation path. Device-specific and
    +split artifacts need fingerprint generation, target identification, and validated
    +restoration rules before reuse is enabled. This includes outputs described in
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md).
    +
    +#### Accepted metadata differences
    +
    +Non-release CI may reuse unchanged HIPCC inputs with the producer's original
    +changelog timestamp. Relevant HIPCC source changes must invalidate the applicable
    +fingerprints. Making changelog bytes reproducible across fresh builds is optional
    +and non-blocking under this policy; see
    +[#10011](https://github.com/ROCm/TheRock/issues/10011). Other metadata differences
    +require explicit justification. Release builds do not consume cached artifacts.
    +
    +### 2. CI system: cache consumption and publication
    +
    +#### Read and write policy
    +
    +Non-release CI may read artifacts enabled for reuse. Only trusted producer runs
    +may publish to the shared cache. CI identity and permissions must prevent
    +untrusted jobs from modifying either the database or trusted artifact objects.
    +An unrelated test failure does not by itself make a successfully produced artifact
    +unusable; complete matching outputs and trusted provenance are required.
    +
    +Release builds build from source. Artifact reuse does not change which tests run.
    +The cache does not need per-entry trust or test-validation states: only complete
    +entries from authorized producers become visible to readers.
    +
    +#### Consumer flow
    +
    +The stage job that uses restored outputs also computes fingerprints and builds
    +misses. It must use the same stage configuration procedure as producer builds,
    +such as `configure_stage.py`, with equivalent fingerprint-relevant settings.
    +Different configuration modes can produce different fingerprints from the same
    +sources.
    +
    +1. Configure the prepared sources and save the expected artifact fingerprints.
    +1. Query the artifact cache index in a batch and produce a hit/miss plan.
    +1. Populate the current run's artifact location, checking required components,
    +   fingerprints, and archive checksums.
    +1. Restore verified artifacts through the prebuilt-stage mechanism.
    +1. Configure again so CMake recognizes the prebuilt stages. Require selected
    +   fingerprints to match their values before restoration.
    +1. Build uncached projects and run the selected downstream work and tests.
    +
    +A lookup hit is only a candidate. Missing objects, transfer errors, invalid
    +checksums, restoration failures, or changed post-restoration fingerprints must fall back to a source build for the affected restore group: remove its restored state and prebuilt markers, then reconfigure. Failed reuse must not leave prebuilt state that suppresses that build.
    +
    +Population copies objects into the current run's artifact location so downstream
    +jobs can continue fetching from that run. The database retains pointers to the
    +original objects. The transfer and storage costs are part of reuse measurements.
    +
    +#### Producer flow
    +
    +1. Build and package the artifact.
    +1. Upload its archives, checksums, and matching fingerprints.
    +1. Publish an entry only after all required uploads succeed.
    +
    +Publish newly built outputs. Restored artifacts retain their original producer
    +information; copying them does not make the current run their producer.
    +
    +#### Rollout and local use
    +
    +Use one `stage_reuse_mode` control during migration, with exactly one reuse
    +implementation owning each restore group. Migrated restore groups use fingerprint
    +reuse; others may continue baseline-run reuse. The two paths must not restore the
    +same outputs or let baseline reuse override a fingerprint rejection.
    +
    +For automatic reuse, `off` disables restoration, `dry-run` reports decisions, and
    +`reuse-stage` permits restoration. Preserve explicit manual reuse through
    +`prebuilt_stages` and `baseline_run_id` in `dry-run`, as described in the
    +[stage reuse documentation](../development/stage_reuse.md). Release policy excludes
    +cache consumption, including manual reuse. Migrated restore groups do not require
    +a baseline run ID. Detailed mode precedence and workflow wiring belong in the CI
    +implementation plan.
    +
    +Local use remains an explicit script-driven lookup and bootstrap operation.
    +Ordinary CMake invocations do not automatically access the remote cache.
    +
    +### 3. Remote cache database: storage and lookup
    +
    +The **artifact cache index** is the lookup interface, implemented first by a
    +static JSON file and later by the remote cache database. The static prototype
    +([#10026](https://github.com/ROCm/TheRock/pull/10026)) is easy to inspect and edit
    +for experiments; it is not the production design.
    +
    +The remote cache database must support batched lookup, automated trusted
    +publication, and historical queries relating artifacts and fingerprints to
    +producer runs. Replacing the static backend should not require rewriting
    +restoration logic.
    +
    +#### Lookup identity and records
    +
    +Conceptually, lookup uses:
    +
    +```text
    +(epoch, compatibility scope, artifact name, component, target,
    + artifact fingerprint)
    +```
    +
    +The artifact fingerprint comes from the build system; the client must not
    +independently rehash its inputs. Compatibility scope retains required distinctions

    I think it might be helpful to define the compatibility scope and rules of reuse in this doc

    ammallya ammallya commented on code on Nov 24, 2026 22:07 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,313 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-23
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +## Problem
    +
    +Today reuse walks recent workflow runs to select a single baseline run, then decides
    +per build stage using change-impact analysis plus commit-compatibility, job-health,
    +and artifact-availability checks (`baseline_runs.py`, `stage_reuse_decision.py`).
    +Fingerprints are never consulted. Reuse is therefore limited to whole stages from one
    +run, cannot combine compatible artifacts from different runs, and costs GitHub API
    +queries for runs and jobs plus artifact listings on every selection. Release
    +branches disable reuse
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +## Proposed solution
    +
    +Select reusable artifacts by the fingerprints computed during build configuration.
    +CI queries the artifact cache index, verifies and restores usable matches, and
    +builds artifacts without usable matches. Compatible artifacts may come from
    +different producer runs.
    +
    +Trusted producer runs upload archives, checksums, and fingerprints, then publish
    +entries to the remote cache database. The database records artifact locations;
    +archives remain in the existing S3 buckets.
    +
    +## Goals
    +
    +- Preserve reuse when unrelated sources or repository commits change.
    +- Rebuild artifacts when relevant sources, configuration, selected files, or
    +  dependency fingerprints change.
    +- Support partial reuse within stages and across the build graph.
    +- Once all projects in a source set are enabled, a PR that changes only ROCm
    +  Libraries hits the cache for every ROCm Systems project.
    +- Fall back to building when cached artifacts cannot be restored safely.
    +- Keep test selection independent of reuse: a hit does not suppress tests selected
    +  by [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md).
    +
    +## Non-goals
    +
    +- Replacing `ccache` or `sccache`, which cache individual compilation operations.
    +- Introducing new artifact object storage.
    +- Adding automatic remote-cache access to ordinary CMake invocations.
    +- Requiring byte-identical outputs for the explicitly accepted metadata
    +  differences described below.
    +
    +## Overall architecture
    +
    +The build system defines compatibility, the remote cache database finds candidate
    +artifacts, and CI verifies and restores them.
    +
    +![Fingerprint-based artifact cache flow](../assets/RFC0017-cache-flow.svg)
    +
    +### 1. Build system: artifact fingerprints
    +
    +TheRock computes fingerprints during CMake configuration. Input changes require
    +reconfiguration before building or querying the cache.
    +
    +| Term                   | Meaning                                                                                                                                      |
    +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    +| Source identity        | Identity of a selected source directory, using its applicable `.smrev` marker or Git tree. Additional source inputs are declared explicitly. |
    +| Subproject fingerprint | Combines source identity, selected configuration values and file hashes, and dependency fingerprints.                                        |
    +| Artifact fingerprint   | Accounts for the artifact's contributing subprojects and is used for artifact lookup.                                                        |
    +| Archive checksum       | Verifies the bytes of a particular archive; it does not establish build compatibility.                                                       |
    +
    +Equal artifact fingerprints should identify interchangeable artifacts, ideally
    +with identical bytes. Validation must detect both false hits (changed relevant
    +inputs retain a fingerprint) and false misses (equivalent inputs produce different
    +fingerprints). Invalid fingerprints must not authorize reuse, although local
    +source builds may continue.
    +
    +A **restore group** contains the components required to restore one artifact name
    +and target. For example, restoring the complete generic `amd-llvm` bundle requires
    +its `dbg`, `dev`, `doc`, `lib`, and `run` components, containing outputs from
    +`amd-llvm`, `amd-comgr`, and `hipcc`. For generic reuse, those components must share
    +one fingerprint and be restored together. This differs from `artifact_group` in
    +`BUILD_TOPOLOGY.toml`, which organizes artifacts for stage planning.
    +
    +Dependencies follow declared inputs, including inputs across repository
    +boundaries. LLVM's additional inputs include the SPIR-V translator and, on
    +applicable platforms, HSA headers. See
    +[#9907](https://github.com/ROCm/TheRock/pull/9907) for source scoping and additional
    +inputs.
    +
    +#### Coverage and stability
    +
    +Fingerprint correctness, stability, and robustness are tracked in
    +[#9525](https://github.com/ROCm/TheRock/issues/9525).
    +
    +Generic artifacts provide the initial implementation path. Device-specific and
    +split artifacts need fingerprint generation, target identification, and validated

    We should pin down whether target goes into the fingerprint or stays a separate lookup-key field

    erman-gurses erman-gurses commented on Nov 25, 2026 00:02 UTC
    Contributor

    can we also update the demonstration RFC0017-cache-flow.svg based on the remote database?

    ammallya ammallya commented on Nov 25, 2026 00:02 UTC
    Author

    can we also update the demonstration RFC0017-cache-flow.svg based on the remote database.

    Will do

    ScottTodd ScottTodd approved these changes on Nov 25, 2026 20:01 UTC
    Approved Reviewer

    Great, this is looking good now. Thanks for the edits.

    ScottTodd ScottTodd commented on Nov 25, 2026 21:58 UTC
    Contributor

    Please fix pre-commit (https://github.com/ROCm/TheRock/actions/runs/45514042521/job/138868758847?pr=9500) and let me know when you are both happy with the state of this RFC @erman-gurses and @ammallya so I can merge it.

    Or maybe @amd-shiraz could review too?

    We don't necessarily need the remaining product manager team review for this eng RFC (implementation detail of the CI system, not user-facing).

    erman-gurses erman-gurses commented on Nov 30, 2026 07:46 UTC
    Contributor

    Please fix pre-commit (https://github.com/ROCm/TheRock/actions/runs/45514042521/job/138868758847?pr=9500) and let me know when you are both happy with the state of this RFC @erman-gurses and @ammallya so I can merge it.

    > Or maybe @amd-shiraz could review too?

    > We don't necessarily need the remaining product manager team review for this eng RFC (implementation detail of the CI system, not user-facing).

    Updated items below:

    1. Fix pre-commit
    2. Add CI reuse decision step

    @ammallya , I think only remaining work is to update RFC0017-cache-flow.svg flow chart that shows the remote database.

    ScottTodd ScottTodd commented on code on Nov 30, 2026 18:59 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,365 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-29
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +## Problem
    +
    +Today reuse walks recent workflow runs to select a single baseline run, then decides
    +per build stage using change-impact analysis plus commit-compatibility, job-health,
    +and artifact-availability checks (`baseline_runs.py`, `stage_reuse_decision.py`).
    +Fingerprints are never consulted. Reuse is therefore limited to whole stages from one
    +run, cannot combine compatible artifacts from different runs, and costs GitHub API
    +queries for runs and jobs plus artifact listings on every selection. Release
    +branches disable reuse
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +## Proposed solution
    +
    +Select reusable artifacts by the fingerprints computed during build configuration.
    +CI queries the artifact cache index, verifies and restores usable matches, and
    +builds artifacts without usable matches. Compatible artifacts may come from
    +different producer runs.
    +
    +Trusted producer runs upload archives, checksums, and fingerprints, then publish
    +entries to the remote cache database. The database records artifact locations;
    +archives remain in the existing S3 buckets.
    +
    +## Goals
    +
    +- Preserve reuse when unrelated sources or repository commits change.
    +- Rebuild artifacts when relevant sources, configuration, selected files, or
    +  dependency fingerprints change.
    +- Support partial reuse within stages and across the build graph.
    +- Once all projects in a source set are enabled, a PR that changes only ROCm
    +  Libraries hits the cache for every ROCm Systems project.
    +- Fall back to building when cached artifacts cannot be restored safely.
    +- Keep test selection independent of reuse: a hit does not suppress tests selected
    +  by [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md).
    +
    +## Non-goals
    +
    +- Replacing `ccache` or `sccache`, which cache individual compilation operations.
    +- Introducing new artifact object storage.
    +- Adding automatic remote-cache access to ordinary CMake invocations.
    +- Requiring byte-identical outputs for the explicitly accepted metadata
    +  differences described below.
    +
    +## Overall architecture
    +
    +The build system defines compatibility, the remote cache database finds candidate
    +artifacts, and CI verifies and restores them.
    +
    +![Fingerprint-based artifact cache flow](../assets/RFC0017-cache-flow.svg)
    +
    +### 1. Build system: artifact fingerprints
    +
    +TheRock computes fingerprints during CMake configuration. Input changes require
    +reconfiguration before building or querying the cache.
    +
    +| Term                   | Meaning                                                                                                                                      |
    +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    +| Source identity        | Identity of a selected source directory, using its applicable `.smrev` marker or Git tree. Additional source inputs are declared explicitly. |
    +| Subproject fingerprint | Combines source identity, selected configuration values and file hashes, and dependency fingerprints.                                        |
    +| Artifact fingerprint   | Accounts for the artifact's contributing subprojects and is used for artifact lookup.                                                        |
    +| Archive checksum       | Verifies the bytes of a particular archive; it does not establish build compatibility.                                                       |
    +
    +Equal artifact fingerprints should identify interchangeable artifacts, ideally
    +with identical bytes. Validation must detect both false hits (changed relevant
    +inputs retain a fingerprint) and false misses (equivalent inputs produce different
    +fingerprints). Invalid fingerprints must not authorize reuse, although local
    +source builds may continue.
    +
    +A **restore group** contains the components required to restore one artifact name
    +and target. For example, restoring the complete generic `amd-llvm` bundle requires
    +its `dbg`, `dev`, `doc`, `lib`, and `run` components, containing outputs from
    +`amd-llvm`, `amd-comgr`, and `hipcc`. For generic reuse, those components must share
    +one fingerprint and be restored together. A device-specific or split artifact
    +forms one restore group per `target`; a target-family request expands to one
    +restore group per target, each restored or rebuilt independently (see
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md)). This differs from `artifact_group`
    +in `BUILD_TOPOLOGY.toml`, which organizes artifacts for stage planning.
    +
    +Dependencies follow declared inputs, including inputs across repository
    +boundaries. LLVM's additional inputs include the SPIR-V translator and, on
    +applicable platforms, HSA headers. See
    +[#9907](https://github.com/ROCm/TheRock/pull/9907) for source scoping and additional
    +inputs.
    +
    +#### Coverage and stability
    +
    +Fingerprint correctness, stability, and robustness are tracked in
    +[#9525](https://github.com/ROCm/TheRock/issues/9525).
    +
    +Generic artifacts provide the initial implementation path. Device-specific and
    +split artifacts need fingerprint generation, target identification, and validated
    +restoration rules before reuse is enabled. This includes outputs described in
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md).
    +
    +`target` is a lookup-key coordinate, not a fingerprint input: archives built from
    +the same inputs for different targets share one fingerprint and are distinguished
    +by `target` in the key. `target_family` is a dispatch and planning concept only
    +and never enters the fingerprint or the key. This keeps reuse independent of build
    +granularity, so a `gfx110X-all` producer can serve a later single-`gfx1100` build,
    +provided a target's output does not depend on which sibling targets were built
    +alongside it; that independence is validated per target class under
    +[#9525](https://github.com/ROCm/TheRock/issues/9525) before enablement.
    +
    +#### Accepted metadata differences
    +
    +Non-release CI may reuse unchanged HIPCC inputs with the producer's original
    +changelog timestamp. Relevant HIPCC source changes must invalidate the applicable
    +fingerprints. Making changelog bytes reproducible across fresh builds is optional
    +and non-blocking under this policy; see
    +[#10011](https://github.com/ROCm/TheRock/issues/10011). Other metadata differences
    +require explicit justification. Release builds do not consume cached artifacts.
    +
    +### 2. CI system: cache consumption and publication
    +
    +#### Read and write policy
    +
    +Non-release CI may read artifacts enabled for reuse. Only trusted producer runs
    +may publish to the shared cache. A trusted run is a push or scheduled run on a
    +protected branch; its publish credentials are issued through CI identity (for
    +example OIDC to a scoped writer role) and are not available to `pull_request`
    +jobs, which therefore can read but never write. Readers accept any existing entry
    +because only trusted jobs can create one. CI identity and permissions must prevent
    +untrusted jobs from modifying either the database or trusted artifact objects.
    +An unrelated test failure does not by itself make a successfully produced artifact
    +unusable; complete matching outputs and trusted provenance are required.

    @amd-shiraz can you review this section of the design? See also https://github.com/ROCm/TheRock/blob/main/docs/development/s3_buckets.md#authentication

    ScottTodd ScottTodd commented on code on Nov 30, 2026 19:00 UTC
    Code Review
    docs/rfcs/RFC0017-Fingerprint-Based-Artifact-Cache.md:1
    @@ -0,0 +1,365 @@
    +---
    +author: Ameya Mallya (ammallya), Erman Gurses (erman-gurses)
    +created: 2026-10-26
    +modified: 2026-11-29
    +status: draft
    +discussion: https://github.com/ROCm/TheRock/issues/8651
    +---
    +
    +# Fingerprint-Based CI Artifact Cache
    +
    +## Problem
    +
    +Today reuse walks recent workflow runs to select a single baseline run, then decides
    +per build stage using change-impact analysis plus commit-compatibility, job-health,
    +and artifact-availability checks (`baseline_runs.py`, `stage_reuse_decision.py`).
    +Fingerprints are never consulted. Reuse is therefore limited to whole stages from one
    +run, cannot combine compatible artifacts from different runs, and costs GitHub API
    +queries for runs and jobs plus artifact listings on every selection. Release
    +branches disable reuse
    +([#8454](https://github.com/ROCm/TheRock/issues/8454)).
    +
    +## Proposed solution
    +
    +Select reusable artifacts by the fingerprints computed during build configuration.
    +CI queries the artifact cache index, verifies and restores usable matches, and
    +builds artifacts without usable matches. Compatible artifacts may come from
    +different producer runs.
    +
    +Trusted producer runs upload archives, checksums, and fingerprints, then publish
    +entries to the remote cache database. The database records artifact locations;
    +archives remain in the existing S3 buckets.
    +
    +## Goals
    +
    +- Preserve reuse when unrelated sources or repository commits change.
    +- Rebuild artifacts when relevant sources, configuration, selected files, or
    +  dependency fingerprints change.
    +- Support partial reuse within stages and across the build graph.
    +- Once all projects in a source set are enabled, a PR that changes only ROCm
    +  Libraries hits the cache for every ROCm Systems project.
    +- Fall back to building when cached artifacts cannot be restored safely.
    +- Keep test selection independent of reuse: a hit does not suppress tests selected
    +  by [RFC0013](./RFC0013-Consumer-Based-Test-Selection.md).
    +
    +## Non-goals
    +
    +- Replacing `ccache` or `sccache`, which cache individual compilation operations.
    +- Introducing new artifact object storage.
    +- Adding automatic remote-cache access to ordinary CMake invocations.
    +- Requiring byte-identical outputs for the explicitly accepted metadata
    +  differences described below.
    +
    +## Overall architecture
    +
    +The build system defines compatibility, the remote cache database finds candidate
    +artifacts, and CI verifies and restores them.
    +
    +![Fingerprint-based artifact cache flow](../assets/RFC0017-cache-flow.svg)
    +
    +### 1. Build system: artifact fingerprints
    +
    +TheRock computes fingerprints during CMake configuration. Input changes require
    +reconfiguration before building or querying the cache.
    +
    +| Term                   | Meaning                                                                                                                                      |
    +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    +| Source identity        | Identity of a selected source directory, using its applicable `.smrev` marker or Git tree. Additional source inputs are declared explicitly. |
    +| Subproject fingerprint | Combines source identity, selected configuration values and file hashes, and dependency fingerprints.                                        |
    +| Artifact fingerprint   | Accounts for the artifact's contributing subprojects and is used for artifact lookup.                                                        |
    +| Archive checksum       | Verifies the bytes of a particular archive; it does not establish build compatibility.                                                       |
    +
    +Equal artifact fingerprints should identify interchangeable artifacts, ideally
    +with identical bytes. Validation must detect both false hits (changed relevant
    +inputs retain a fingerprint) and false misses (equivalent inputs produce different
    +fingerprints). Invalid fingerprints must not authorize reuse, although local
    +source builds may continue.
    +
    +A **restore group** contains the components required to restore one artifact name
    +and target. For example, restoring the complete generic `amd-llvm` bundle requires
    +its `dbg`, `dev`, `doc`, `lib`, and `run` components, containing outputs from
    +`amd-llvm`, `amd-comgr`, and `hipcc`. For generic reuse, those components must share
    +one fingerprint and be restored together. A device-specific or split artifact
    +forms one restore group per `target`; a target-family request expands to one
    +restore group per target, each restored or rebuilt independently (see
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md)). This differs from `artifact_group`
    +in `BUILD_TOPOLOGY.toml`, which organizes artifacts for stage planning.
    +
    +Dependencies follow declared inputs, including inputs across repository
    +boundaries. LLVM's additional inputs include the SPIR-V translator and, on
    +applicable platforms, HSA headers. See
    +[#9907](https://github.com/ROCm/TheRock/pull/9907) for source scoping and additional
    +inputs.
    +
    +#### Coverage and stability
    +
    +Fingerprint correctness, stability, and robustness are tracked in
    +[#9525](https://github.com/ROCm/TheRock/issues/9525).
    +
    +Generic artifacts provide the initial implementation path. Device-specific and
    +split artifacts need fingerprint generation, target identification, and validated
    +restoration rules before reuse is enabled. This includes outputs described in
    +[RFC0008](./RFC0008-Multi-Arch-Packaging.md).
    +
    +`target` is a lookup-key coordinate, not a fingerprint input: archives built from
    +the same inputs for different targets share one fingerprint and are distinguished
    +by `target` in the key. `target_family` is a dispatch and planning concept only
    +and never enters the fingerprint or the key. This keeps reuse independent of build
    +granularity, so a `gfx110X-all` producer can serve a later single-`gfx1100` build,
    +provided a target's output does not depend on which sibling targets were built
    +alongside it; that independence is validated per target class under
    +[#9525](https://github.com/ROCm/TheRock/issues/9525) before enablement.
    +
    +#### Accepted metadata differences
    +
    +Non-release CI may reuse unchanged HIPCC inputs with the producer's original
    +changelog timestamp. Relevant HIPCC source changes must invalidate the applicable
    +fingerprints. Making changelog bytes reproducible across fresh builds is optional
    +and non-blocking under this policy; see
    +[#10011](https://github.com/ROCm/TheRock/issues/10011). Other metadata differences
    +require explicit justification. Release builds do not consume cached artifacts.
    +
    +### 2. CI system: cache consumption and publication
    +
    +#### Read and write policy
    +
    +Non-release CI may read artifacts enabled for reuse. Only trusted producer runs
    +may publish to the shared cache. A trusted run is a push or scheduled run on a
    +protected branch; its publish credentials are issued through CI identity (for
    +example OIDC to a scoped writer role) and are not available to `pull_request`
    +jobs, which therefore can read but never write. Readers accept any existing entry
    +because only trusted jobs can create one. CI identity and permissions must prevent
    +untrusted jobs from modifying either the database or trusted artifact objects.
    +An unrelated test failure does not by itself make a successfully produced artifact
    +unusable; complete matching outputs and trusted provenance are required.
    +
    +Release builds build from source. Artifact reuse does not change which tests run.
    +The cache does not need per-entry trust or test-validation states: only complete
    +entries from authorized producers become visible to readers.
    +
    +#### Consumer flow
    +
    +CI makes the reuse decision once, in a dedicated step before the stage builds, so
    +that stages whose restore groups are all cached can be skipped and partially
    +cached stages build only their misses. It must use the same stage configuration
    +procedure as producer builds, such as `configure_stage.py`, with an identical,
    +pinned set of fingerprint-relevant settings rather than merely "equivalent" ones.
    +Different configuration modes can produce different fingerprints from the same
    +sources, so the consumer treats any fingerprint it cannot reproduce as a miss.
    +
    +1. Configure the prepared sources and save the expected artifact fingerprints.
    +1. Query the artifact cache index in a batch and produce a hit/miss plan.
    +1. Populate the current run's artifact location, checking required components,
    +   fingerprints, and archive checksums.
    +1. Restore verified artifacts through the prebuilt-stage mechanism.
    +1. Configure again so CMake recognizes the prebuilt stages. Require selected
    +   fingerprints to match their values before restoration.
    +1. Build uncached projects and run the selected downstream work and tests.
    +
    +Steps 1 to 5 complete before any stage is skipped, so a failed check still leaves
    +the stage to build.
    +
    +A lookup hit is only a candidate. Missing objects, transfer errors, invalid
    +checksums, restoration failures, or changed post-restoration fingerprints must fall back to a source build for the affected restore group: remove its restored state and prebuilt markers, then reconfigure. Restoration of a restore group is all-or-nothing; if the fallback itself is interrupted, the next configure must detect and clear any orphaned prebuilt markers before building. Failed reuse must not leave prebuilt state that suppresses that build.
    +
    +Population copies objects into the current run's artifact location so downstream
    +jobs can keep fetching by run id through the existing artifact mechanism, rather
    +than teaching every consumer to resolve database pointers. A hit therefore still
    +pays archive transfer and saves only compute; this is a deliberate cost, measured
    +alongside reuse, and a candidate future optimization once downstream jobs can
    +fetch from the original object pointers the database retains.
    +
    +A stage is skipped only when every restore group it produces has been restored
    +and verified. A restore group that fails verification is treated as a miss, and
    +the stage that produces it runs.
    +
    +#### Producer flow
    +
    +1. Build and package the artifact.
    +1. Upload its archives, checksums, and matching fingerprints.
    +1. Publish an entry only after all required uploads succeed.
    +
    +Publish newly built outputs. Restored artifacts retain their original producer
    +information; copying them does not make the current run their producer.
    +
    +#### Rollout and local use
    +
    +Use one `stage_reuse_mode` control during migration, with exactly one reuse
    +implementation owning each restore group. Migrated restore groups use fingerprint
    +reuse; others may continue baseline-run reuse. The two paths must not restore the
    +same outputs or let baseline reuse override a fingerprint rejection.
    +
    +For automatic reuse, `off` disables restoration, `dry-run` reports decisions, and
    +`reuse-stage` permits restoration. Preserve explicit manual reuse through
    +`prebuilt_stages` and `baseline_run_id` in `dry-run`, as described in the
    +[stage reuse documentation](../development/stage_reuse.md). Release policy excludes
    +cache consumption, including manual reuse. Migrated restore groups do not require
    +a baseline run ID. Detailed mode precedence and workflow wiring belong in the CI
    +implementation plan.
    +
    +Local use remains an explicit script-driven lookup and bootstrap operation.
    +Ordinary CMake invocations do not automatically access the remote cache.
    +
    +The reuse decision is reported in the CI run summary, per stage: which restore
    +groups hit, which missed, which stages are skipped, and which still run. The same
    +decision logic serves Linux and Windows CI; fingerprints and cache entries are
    +per platform.
    +
    +### 3. Remote cache database: storage and lookup
    +
    +The **artifact cache index** is the lookup interface, implemented first by a
    +static JSON file and later by the remote cache database. The static prototype
    +([#10026](https://github.com/ROCm/TheRock/pull/10026)) is easy to inspect and edit
    +for experiments; it is not the production design.
    +
    +The remote cache database must support batched lookup, automated trusted
    +publication, and historical queries relating artifacts and fingerprints to
    +producer runs. Replacing the static backend should not require rewriting
    +restoration logic.

    @amd-shiraz another section to review here for the remote cache database aspect

    erman-gurses erman-gurses approved these changes on Nov 30, 2026 19:46 UTC
    Approved Reviewer

    LGTM - After @amd-shiraz's review and approval, we can merge it.

    Reviewers
    Assignees
    ammallya ammallya
    Labels
    risk: low confidence: 88.1% 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: 50.2% (MEDIUM) · Higher = larger blast radius
    50.2%
    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: 88.1% · Lower = rushed or shallow review
    88.1%
    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: 6.0% · Safe to merge
    6.0%
    Repository