← Back to Pull requests

fix: Scope source fingerprints to Git trees and additional inputs #9907

Closed
erman-gurses closed this pull request without merging on Dec 02, 2026 02:47 UTC
View on GitHub
erman-gurses erman-gurses commented on Nov 11, 2026 18:38 UTC
Author

Description:


Implements the simpler source-identity approach discussed in #9732. Repository-wide commit changes currently invalidate fingerprints even when a subproject’s sources are unchanged. This change uses the selected directory’s Git tree and explicitly records additional source directories.

Changes:


  • Use git rev-parse HEAD:./ for Git source identity and scope the tracked-file dirty check to the same directory. Preserve .smrev priority.

  • Add ADDITIONAL_SOURCE_INPUTS, using the existing source-identity helper for each directory. Missing or invalid inputs invalidate the subproject fingerprint.

  • Declare LLVM’s external SPIR-V translator and, on non-Windows platforms, HSA headers as additional inputs.

  • Include ordered CMake arguments and per-project overrides in fingerprints, including when importing prebuilt stages.

  • Update the consumer-graph parser to recognize additional source inputs without treating them as project dependency edges.

  • -Add baseline tests for existing subproject behavior, covering configure/build/stage ordering, dependency discovery, unchanged rebuilds, duplicate declarations and package providers, distribution contents, custom install destinations, and excluded targets. Share fixture setup through therock_fingerprint_test_utils.py.

    Testing:

    Fingerprint tests cover source identity, scoped dirty-source invalidation,
    source restoration, CMake arguments and overrides, additional source inputs,
    dependency propagation, and repeat stability.

    Baseline subproject tests cover existing configuration, build, and staging
    behavior independently of fingerprint assertions.

    Run from the repository root:

    python -m pytest \
      cmake/tests/therock_source_identity_test.py \
      cmake/tests/therock_subproject_cmake_args_test.py \
      cmake/tests/therock_subproject_source_deps_test.py \
      cmake/tests/therock_subproject_test.py \
      cmake/tests/therock_subproject_prebuilt_test.py \
      build_tools/tests/cmake_consumer_graph_test.py \
      -v
    

    Validation findings and follow-ups

    Addressed by this PR

  • Use the selected directory’s Git tree for source identity, preserving .smrev priority. Unrelated commits and tracked edits outside that directory no longer invalidate its identity.

  • Include explicitly declared ADDITIONAL_SOURCE_INPUTS in fingerprints, including LLVM’s SPIR-V translator and non-Windows HSA headers.

  • Include ordered CMake arguments and per-project overrides in fingerprints, including when importing prebuilt stages.
  • Resolved separately

  • HIPCC timestamp newline: Fixed in ROCm/llvm-project#5411. OUTPUT_STRIP_TRAILING_WHITESPACE prevents the timestamp from changing when CMake saves and reloads its cache. This fixes initial-versus-repeated configuration differences, but fresh builds can still produce different timestamps.
  • MLIR configuration consistency: Fixed in TheRock#9936. Setting MLIR_INSTALL_AGGREGATE_OBJECTS to OFF CACHE BOOL ... FORCE keeps its effective and cached values consistently OFF. Previously, the effective value could change from 1 on initial configuration to OFF on repeated configuration, changing generated MLIR exports.
  • Remaining work

  • Checkout/build paths can affect fingerprints: Earlier experiments showed that identical sources and requested build settings could produce different final fingerprints when checkout or build directories changed. This can cause unnecessary cache misses between otherwise equivalent builds. This PR improves source identity but does not remove path sensitivity from the rest of fingerprint calculation; see #9060.
  • Accepted behavior or outside the current CI scope

  • Git revision metadata: Different commits with identical source trees may generate different revision headers. This is accepted under the tree-based reuse policy: cached artifacts may retain their original build revision.

  • Removed arguments in reused inner caches: This remains unresolved for incremental builds. It is excluded from the current CI model because every run starts with empty outer and inner build directories.

  • Untracked files and submodule working-tree changes: The existing dirty-check behavior is unchanged. These cases are outside the current CI scope, which assumes clean committed sources, submodules at their recorded revisions, and no unrepresented inputs introduced during preparation.

  • HIPCC changelog timestamp: Accepted under the cache policy in #10011. CI may reuse artifacts containing the original changelog timestamp when HIPCC inputs are unchanged. HIPCC source changes must invalidate the relevant artifact fingerprint and trigger a rebuild. Release builds bypass artifact reuse and generate a current timestamp. Byte-for-byte changelog reproducibility across fresh builds is not required by this PR.
  • Note:


    Fingerprint calculations occur during configuration; input changes require reconfiguration before building.

    Local tests related files:
    Test Results
    README
    Test Script

    Diff: 1123 lines (+1112 / -11) across 9 files Reviewer: ammallya Review duration: 29289m
    All Vouch review confidence checks passed
    Residual risk 0.08 = Change Risk (0.55) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 1123 lines diff across 9 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.78 · 5 substantive comment(s)
    0.78
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    85%
    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.400
    Real PR Conversation Timeline
    14 items
    therock-pr-bot[bot] therock-pr-bot[bot] commented on Nov 11, 2026 18:38 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 | — |
    | 🔎 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 Nov 11, 2026 21:39 UTC
    Bot

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

    ammallya ammallya commented on Nov 19, 2026 18:30 UTC
    Contributor

    Tree-scoped identity a good call, and the source-identity tests are solid.

    ammallya ammallya commented on Nov 19, 2026 18:30 UTC
    Contributor

    Locally tested and reverified the change

    ammallya ammallya commented on code on Nov 19, 2026 18:56 UTC
    Code Review
    cmake/therock_subproject.cmake:1
    @@ -716,6 +727,28 @@ function(therock_cmake_subproject_activate target_name)
         file(GLOB_RECURSE _fprint_source_globs "${_fprint_source_dir}/*")
         list(APPEND _fprint_files ${_fprint_source_globs})
       endif()
    +  # Include sources outside the primary source directory, also for prebuilts.
    +  foreach(_additional_source_input IN LISTS _additional_source_inputs)
    +    set(_additional_source_input_fprint)
    +    if(IS_DIRECTORY "${_additional_source_input}")
    +      _therock_subproject_fprint_source_dir(_additional_source_input_fprint "${_additional_source_input}")
    +    endif()
    +    if(_additional_source_input_fprint)
    +      cmake_path(RELATIVE_PATH _additional_source_input BASE_DIRECTORY "${THEROCK_SOURCE_DIR}"
    +        OUTPUT_VARIABLE _additional_source_input_relative)
    +      # Hash the path and identity separately to preserve their boundaries,
    +      # including when a marker contains newlines or CMake list separators.
    +      string(SHA256 _additional_source_input_path_hash "${_additional_source_input_relative}")
    +      string(SHA256 _additional_source_input_identity_hash "${_additional_source_input_fprint}")
    +      list(APPEND _fprint_content
    +        "SOURCE_DEP_V1=${_additional_source_input_path_hash}:${_additional_source_input_identity_hash}")
    +    else()
    +      set(_fprint_is_valid FALSE)

    Missing/invalid declared input silently disables caching

    ammallya ammallya commented on Nov 19, 2026 18:57 UTC
    Contributor

    I think this goes with the discussed design plan and RFC, the test cases pass and the new fprint generation also works I think in my opinion it is ready

    ammallya ammallya approved these changes on Nov 19, 2026 18:57 UTC
    Approved Reviewer

    Approved these changes.

    ammallya ammallya commented on code on Nov 19, 2026 18:58 UTC
    Code Review
    cmake/therock_subproject.cmake:1
    @@ -716,6 +727,28 @@ function(therock_cmake_subproject_activate target_name)
         file(GLOB_RECURSE _fprint_source_globs "${_fprint_source_dir}/*")
         list(APPEND _fprint_files ${_fprint_source_globs})
       endif()
    +  # Include sources outside the primary source directory, also for prebuilts.
    +  foreach(_additional_source_input IN LISTS _additional_source_inputs)
    +    set(_additional_source_input_fprint)
    +    if(IS_DIRECTORY "${_additional_source_input}")
    +      _therock_subproject_fprint_source_dir(_additional_source_input_fprint "${_additional_source_input}")
    +    endif()
    +    if(_additional_source_input_fprint)
    +      cmake_path(RELATIVE_PATH _additional_source_input BASE_DIRECTORY "${THEROCK_SOURCE_DIR}"
    +        OUTPUT_VARIABLE _additional_source_input_relative)
    +      # Hash the path and identity separately to preserve their boundaries,
    +      # including when a marker contains newlines or CMake list separators.
    +      string(SHA256 _additional_source_input_path_hash "${_additional_source_input_relative}")
    +      string(SHA256 _additional_source_input_identity_hash "${_additional_source_input_fprint}")
    +      list(APPEND _fprint_content
    +        "SOURCE_DEP_V1=${_additional_source_input_path_hash}:${_additional_source_input_identity_hash}")
    +    else()
    +      set(_fprint_is_valid FALSE)

    This should be fine but it might be better to make it a configure error

    erman-gurses erman-gurses commented on code on Nov 20, 2026 01:42 UTC
    Code Review
    cmake/therock_subproject.cmake:1
    @@ -716,6 +727,28 @@ function(therock_cmake_subproject_activate target_name)
         file(GLOB_RECURSE _fprint_source_globs "${_fprint_source_dir}/*")
         list(APPEND _fprint_files ${_fprint_source_globs})
       endif()
    +  # Include sources outside the primary source directory, also for prebuilts.
    +  foreach(_additional_source_input IN LISTS _additional_source_inputs)
    +    set(_additional_source_input_fprint)
    +    if(IS_DIRECTORY "${_additional_source_input}")
    +      _therock_subproject_fprint_source_dir(_additional_source_input_fprint "${_additional_source_input}")
    +    endif()
    +    if(_additional_source_input_fprint)
    +      cmake_path(RELATIVE_PATH _additional_source_input BASE_DIRECTORY "${THEROCK_SOURCE_DIR}"
    +        OUTPUT_VARIABLE _additional_source_input_relative)
    +      # Hash the path and identity separately to preserve their boundaries,
    +      # including when a marker contains newlines or CMake list separators.
    +      string(SHA256 _additional_source_input_path_hash "${_additional_source_input_relative}")
    +      string(SHA256 _additional_source_input_identity_hash "${_additional_source_input_fprint}")
    +      list(APPEND _fprint_content
    +        "SOURCE_DEP_V1=${_additional_source_input_path_hash}:${_additional_source_input_identity_hash}")
    +    else()
    +      set(_fprint_is_valid FALSE)

    I understand the concern. I prefer to keep configuration running because an invalid source identity can also result from local tracked edits. Those should prevent cache reuse without blocking development builds.

    I removed the THEROCK_VERBOSE guard so configuration always reports the affected input and explains that fingerprint-based cache reuse is unavailable. Would that address your concern?

    ScottTodd ScottTodd commented on code on Nov 24, 2026 00:10 UTC
    Code Review
    compiler/CMakeLists.txt:1
    @@ -102,13 +102,22 @@ if(THEROCK_ENABLE_COMPILER)
         message(STATUS "Using stable amd-llvm revision info: Repo='${LLVM_SMREV_REPO}', Revision='${LLVM_SMREV_REVISION}'")
       endif()
     
    +  # Sources read by LLVM that are outside the amd-llvm checkout.
    +  set(_llvm_source_inputs "${CMAKE_CURRENT_SOURCE_DIR}/spirv-llvm-translator")
    +  if(THEROCK_CONDITION_IS_NON_WINDOWS)
    +    # SANITIZER_AMDGPU uses these headers without building ROCR-Runtime first.
    +    list(APPEND _llvm_source_inputs
    +      "${THEROCK_ROCM_SYSTEMS_SOURCE_DIR}/projects/rocr-runtime/runtime/hsa-runtime/inc")
    +  endif()
    +
       therock_cmake_subproject_declare(amd-llvm
         USE_DIST_AMDGPU_TARGETS
         NO_INSTALL_RPATH  # See manual handling in the pre_hook.
         EXTERNAL_SOURCE_DIR "amd-llvm"
         # Note that LLVM top level CMakeLists.txt is in the llvm subdir of the
         # monorepo.
         CMAKE_LISTS_RELPATH "llvm"
    +    ADDITIONAL_SOURCE_INPUTS ${_llvm_source_inputs}

    We'll need to at least follow up on other subprojects that will also need this. Just adding to amd-llvm will not be sufficient and stopping there on this PR weakens the fprint calculations for other subprojects.

    Can you check across the codebase for how many subprojects will need ADDITIONAL_SOURCE_INPUTS?

    I want to know
    1. How many changes total will be needed
    2. If any changes will be especially large or complicated -- so if this mechanism is actually sufficient for all uses or if we'll need a different design

    Depending on the answers to those questions we may want to make all the changes in this PR itself and not just start with amd-llvm.

    ScottTodd ScottTodd commented on code on Nov 24, 2026 00:15 UTC
    Code Review
    cmake/therock_subproject.cmake:1
    @@ -933,6 +967,19 @@ function(therock_cmake_subproject_activate target_name)
     
       list(APPEND _cmake_args "${${target_name}_CMAKE_ARGS}")
     
    +  # Fingerprint the combined arguments in configure-command order, including
    +  # per-project overrides. Match the command's unquoted list expansion. Hash
    +  # each argument separately to retain argument boundaries and duplicates.
    +  # Keep this outside the prebuilt branch so requested options still contribute
    +  # when a stage is imported. Absolute paths remain significant, as elsewhere
    +  # in this fingerprint implementation.
    +  set(_cmake_args_fprint "")
    +  foreach(_cmake_arg ${_cmake_args})
    +    string(SHA256 _cmake_arg_fprint "${_cmake_arg}")
    +    string(APPEND _cmake_args_fprint "${_cmake_arg_fprint}")
    +  endforeach()
    +  list(APPEND _fprint_content "CMAKE_ARGS_V1=${_cmake_args_fprint}")

    Please split this into a separate PR from the ADDITIONAL_SOURCE_INPUTS and git rev-parse changes. Both need careful review on their own. One PR for git trees, one for CMake args.

    Here, this is looking at literal arguments and _not_ evaluating expressions.

    Agent finding with more context:

    ### BLOCKING: Hashing generator-expression text can reuse a fingerprint for different effective arguments

    > Location: cmake/therock_subproject.cmake:970–981.

    > string(SHA256 ...) runs during configuration and hashes the unevaluated argument. add_custom_command() evaluates generator expressions when generating the build command. Values consulted by an unchanged expression can change without changing any argument text or fingerprinted file.

    > Reproduced against the unmodified PR implementation, using its existing argument-test fixture with this constant argument:

    >
    > CMAKE_ARGS "-DVALUE=$<TARGET_PROPERTY:args_source,TEST_ARG_VALUE>"
    > 

    > The fixture assigns that property from an outer TEST_ARG_VALUE cache entry. Changing the entry from first to second, reconfiguring, and invoking args_source+configure changes the generated output from first\n to second\n. Both the project and consumer retain exactly the same fingerprints:

    >
    > args_source   98318c3629e491734a7eea8303c81946bd298020ef56352ebff7c40508659927
    > args_consumer 32ccd5d542bb795b95eba275a8ebca94c67b5782be03a32c64f01a4ff30edf5c
    > 

    > No source or declaration text changed between configurations, and the inner configure really ran with the changed value. The control fingerprint stayed unchanged as expected. Reproduction and results: probe_genex.py, genex-result.json in the scratch directory below.

    > The existing generator-expression test changes $<BOOL:1> to $<BOOL:0>, so the literal text changes too. That establishes text sensitivity and correct command evaluation, but does not establish effective-argument coverage.

    > Required action: Represent effective argument values in the identity, constrain the argument interface so it can be evaluated reliably before fingerprint production, or conservatively invalidate fingerprints for expressions whose effective values cannot be represented. Do not accept their literal text as sufficient identity. Add the constant-expression/changing-value regression. Existing configure-expanded values inside expressions are a different, narrower case.

    ScottTodd ScottTodd requested changes on Nov 24, 2026 00:16 UTC
    Changes Requested Reviewer

    Let's split this into two PRs and resolve bugs on each independently. Too risky to land both at the same time.

    erman-gurses erman-gurses commented on Dec 02, 2026 02:47 UTC
    Author
    Reviewers
    Assignees
    erman-gurses erman-gurses
    Labels
    risk: low confidence: 85.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: 54.7% (MEDIUM) · Higher = larger blast radius
    54.7%
    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: 85.1% · Lower = rushed or shallow review
    85.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: 8.2% · Safe to merge
    8.2%
    Repository