Skip to content

Conversation

@iav
Copy link
Contributor

@iav iav commented Jan 20, 2026

Summary

Two improvements to kernel artifact hash stability and correctness:

1. Normalize kernel config hash inputs

Problem
The current kernel config hashing makes kernel_config_modification_hash sensitive to option insertion order, which causes two issues:

  1. Unstable hash due to insertion order.
    kernel_config_modifying_hashes is populated in hook order; identical final option sets can produce different hashes and artifact versions.

  2. Overridden assignments still affect the hash.
    If the same option is set multiple times (e.g. FOO=y then FOO=n), both entries influence the hash even though only the last value takes effect.

Additionally, iteration order for opts_val (assoc array) can be nondeterministic.

Solution

  1. Normalize per-group lists (opts_n/opts_y/opts_m).
    Each group is sorted and deduplicated (sort -u). This makes ordering deterministic and removes duplicates without changing behavior (all values in a group are the same: n/y/m).

  2. Deterministic ordering for opts_val.
    opts_val keys are sorted before hashing and before applying to .config.

  3. Drop overridden assignments when hashing.
    Before computing kernel_config_modification_hash, only the last value per key is kept, so overridden assignments no longer affect versioning.

2. Include toolchain version in kernel artifact hash

Problem
Compiler version (gcc/clang) was not included in the kernel artifact hash. Changing the toolchain would not invalidate the cache, even though different compiler versions produce different binaries.

Solution

  • Add KERNEL_COMPILER prefix and compiler version to the hash
  • Use only major.minor version (e.g., 13.3), drop patch version to avoid unnecessary cache invalidation
  • Falls back to "unknown" if compiler is not available at hash calculation time
  • Adds -T${hash} component to artifact version string

Result

  • Hash is stable for the same effective option set, regardless of insertion order
  • Overridden values no longer affect versioning
  • Toolchain changes now properly invalidate kernel cache
  • Build behavior and final .config stay the same

Tests

Not added.

Summary by CodeRabbit

  • New Features

    • Toolchain version and a short toolchain hash are now included in artifact versioning and debug output for clearer build traceability.
  • Improvements

    • Kernel configuration inputs are normalized, sorted and deduplicated before processing for more consistent and stable builds.
    • Hashing now ignores overridden options, producing a stable, reduced hash and clearer reason logs.

✏️ Tip: You can customize this high-level summary in your review settings.

@iav iav requested a review from a team as a code owner January 20, 2026 05:05
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Stabilizes kernel configuration hashing by reducing duplicate config-change entries to their last occurrence and adding a toolchain-derived hash; also normalizes kernel option lists by sorting and deduplicating opts arrays and opts_val keys before hashing and applying changes.

Changes

Cohort / File(s) Summary
Kernel hash deduplication & toolchain
lib/functions/artifacts/artifact-kernel.sh
Two-pass reduction to keep only the last entry per config key before hashing; compute sha256 of reduced entries (shortened); derive toolchain_version from compiler, add toolchain hash to reasons and common_version_suffix, log toolchain info in debug output.
Kernel option normalization
lib/functions/compilation/armbian-kernel.sh
Sort & deduplicate opts_n, opts_y, opts_m into normalized arrays; sort opts_val keys; use normalized arrays/keys for building kernel_config_modifying_hashes and applying .config changes.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

11

Suggested reviewers

  • pyavitz
  • teknoid
  • leggewie
  • igorpecovnik
  • chraac
  • EvilOlaf

Poem

🐰 I sorted leaves and kept the last,

I hashed the path the old ones passed,
I sniffed the toolchain, gave it name,
A tiny hop to steady frame,
Now builds can dance without the past.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary focus of the changes: normalizing kernel config hash inputs by sorting, deduplicating, and removing overridden entries.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines 02 Milestone: First quarter release Needs review Seeking for review Framework Framework components labels Jan 20, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@lib/functions/compilation/armbian-kernel.sh`:
- Around line 520-540: The sort invocations that build
opts_n_norm/opts_y_norm/opts_m_norm and opts_val_keys are locale-dependent and
can yield non-deterministic ordering; update the commands that use sort -u and
sort to force a stable C locale (e.g., prefix with LC_ALL=C) so the arrays
(opts_n_norm, opts_y_norm, opts_m_norm, opts_val_keys) and derived
kernel_config_modifying_hashes are built deterministically across environments.
Ensure you apply this change to every occurrence of sort used for these lists in
the block surrounding opts_n_norm/opts_y_norm/opts_m_norm and opts_val_keys.
- Around line 519-540: The variable opts_val_keys is being created in function
scope (global) and should be local like the other arrays; declare opts_val_keys
as a local variable (e.g., add it to the existing local/declare array line with
opts_n_norm/opts_y_norm/opts_m_norm) so it doesn't leak to global scope, then
keep the subsequent mapfile usage and for-loop over opts_val_keys unchanged;
ensure you reference the same symbol names (opts_val_keys, opts_n_norm,
opts_y_norm, opts_m_norm, kernel_config_modifying_hashes) when updating the
declaration.

@iav iav marked this pull request as draft January 20, 2026 05:50
@iav iav force-pushed the fix/kernel-config-hash-normalization branch from a8ff3b5 to 9b3d44d Compare January 20, 2026 18:15
@iav iav marked this pull request as ready for review January 21, 2026 02:08
@iav iav force-pushed the fix/kernel-config-hash-normalization branch from 06adbfe to f88a095 Compare January 21, 2026 02:35
iav and others added 2 commits January 23, 2026 08:26
Add compiler (gcc/clang) version to the kernel artifact hash to ensure
cache invalidation when the toolchain changes.

- Hash includes KERNEL_COMPILER prefix and compiler version
- Uses only major.minor version (e.g., 13.3), drops patch version
- Falls back to "unknown" if compiler is not available
- Adds -T${hash} component to artifact version string

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@iav iav force-pushed the fix/kernel-config-hash-normalization branch from f88a095 to d2cf555 Compare January 23, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

02 Milestone: First quarter release Framework Framework components Needs review Seeking for review size/medium PR with more then 50 and less then 250 lines

Development

Successfully merging this pull request may close these issues.

1 participant