Skip to content

Refresh Git version metadata when rebuilding an existing checkout - #778

Merged
fcostaoliveira merged 3 commits into
masterfrom
codex/fix773-version-refresh-20261017
Oct 17, 2026
Merged

fcostaoliveira merged 3 commits into
masterfrom
codex/fix773-version-refresh-20261017

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

After an incremental rebuild, the binary can include new source while --version still reports the previous commit. The same generated SHA supplies crash reports and Prometheus build information.

Root cause

version.h had no prerequisites, so an existing header was not reconsidered when HEAD or tracked-file state changed. The generator also queried Git in the build directory, which could be outside the source checkout or inside an unrelated repository.

Fix

Recheck metadata on each build through a phony prerequisite, preserving the existing compare-before-replace behavior so unchanged metadata does not rebuild consumers. Add explicit header dependencies for both consuming objects, covering first/direct parallel binary builds. Query the source checkout and use unknown provenance for source archives, including archives unpacked beneath another repository. On a Git metadata error, warn and use explicit unknown provenance, preserving build compatibility without retaining a potentially stale SHA. Update the release guide, including installation-triggered rebuilds.

Tests

  • The regression uses the actual configured Makefile rule, real temporary Git commits, and a compiled consumer: first/direct build, HEAD advancement, dirty/clean transitions, stable timestamps, out-of-tree source lookup and archive fallback pass.
  • Injected ls-files/rev-parse/diff-index errors produce a warning and an unknown compiled consumer; repeated unknown state preserves timestamps and restored Git access recovers the real SHA.
  • Removing the forced prerequisite makes the HEAD-advance control fail; always replacing the header makes the unchanged-build control fail.
  • A clean direct make -j8 memtier_benchmark succeeds. Repeating normal make -j8 leaves the header, both consumer objects, and executable timestamps and hashes unchanged.
  • Source instruction/skill parity check passes. Final c790b1d passes a direct build, reports c790b1d:0, and passes make -j8 distcheck, including all 15 unit programs and archive build/install/uninstall checks. Actual Git ownership refusal warns and reports unknown; recovery restores the SHA. CI is running. Full CI and seven independent reviews remain required.
  • Before: the reproduced upstream b6e9d78→563f372 rebuild retained b6e9d78 despite gaining the new progress option. After: the actual build-rule regression reports the new commit and rejects both stale-header and needless-recompile mutants. This is build provenance, so no throughput comparison is claimed.

Affected versions

Introduced by #328 (4a8ac10 on master, a399f1b on the 2.2 line). Release source 2.2.1–2.5.2 retains the dependencyless rule; current master is affected. Historical release binaries were not separately executed. Fresh clean builds avoid the original stale-header condition.

Fixes #773

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. The root cause matches #773, and I like that the regression drives the real configured version.h rule. It also checks the reverse case, so an unchanged rebuild doesn't recompile the consumer. That's the bar we want for this kind of fix.

One question on the install path. CONTRIBUTING.md and DEVELOPMENT.md both document make followed by sudo make install. With FORCE_VERSION, the install step now runs version.sh as root. On any Git with the safe.directory check, a user-owned checkout fails ls-files with status 128. .git exists, so we hit metadata_error, write 00000000 into version.h, and recompile both consumer objects and relink the binary as root. The binary that gets installed then reports unknown provenance, even though the one make just built had the right SHA. The build tree is also left with root-owned objects. Before this change, the install step never touched version.h.

The new AGENTS.md text does mention this ("Installation also rechecks metadata and can rebuild its consumers..."). Still, I'm not sure the most common install flow should regress for the sake of this fix. Did you consider leaving an existing version.h alone when Git metadata can't be read, and only falling back to 00000000 when there's no header yet? The stale-SHA risk in that branch seems small: the user would have to move HEAD and then run the build as a different user without rebuilding first. You'd keep the 00000000 behaviour for archives and first builds. The fake-git loop in check_version_build.py already covers this, so it could assert that the previous SHA survives instead. I may be missing why the second commit moved away from keeping the old header, so happy to hear the reasoning.

The rest looks good to me. I'd just like the sudo make install question settled before this merges.

(would file this as a comment, not a formal block)

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Updated in c790b1d. The hard-failure approach did break the four Debian container jobs and Alpine latest at the version.h rule, so it has been replaced with a warning and explicit unknown provenance (00000000:0). Keeping an existing SHA would let changed source compile under potentially stale provenance. Unknown provenance preserves the supported build behavior without making that claim.

The regression injects failures in ls-files, rev-parse and diff-index independently: each build succeeds with a warning and an unknown compiled consumer, repeated unknown metadata leaves timestamps unchanged, and restored Git access recovers the correct SHA. Ordinary dirty status remains distinct. Archives and no-Git builds retain their fallback. The standalone check is now named check_version_build.py to avoid RLTest discovery.

AGENTS.md now explains that installation rechecks metadata and can rebuild consumers when the SHA, dirty state or Git access changes. The updated container CI is running; this is not cleared for merge until it passes and the independent reviews converge.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Following the 09:46:49 edit: retaining an existing header was considered, but the rule runs for every build, not only install. After a checkout change, unavailable Git plus a retained header would recreate the original defect: newly compiled source claiming an older SHA. The regression now explicitly rejects that mutation. Warning plus unknown provenance is the selected compromise: builds continue and the binary makes no unverifiable revision claim. A repeated unknown state does not recompile; recovering access restores the SHA.

The statement that ordinary sudo necessarily triggers this is too broad: Git documents that root also trusts the UID in SUDO_UID on supported non-Windows sudo platforms. I did not claim a privileged local sudo test; the actual refusal was reproduced using Git's ownership-test environment. Container failures are established independently, and the new container jobs are running.

The install-time rebuild when metadata changes is intentional and documented, including changed Git access. Local final-head direct/no-op checks and distcheck (15 unit programs, archive install/uninstall) pass. BUILD and TEST independently approve the final policy; remaining reviews and CI still gate merge.

@fcostaoliveira
fcostaoliveira merged commit aa26c5e into master Oct 17, 2026
132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incremental rebuild after updating Git HEAD leaves --version reporting the previous commit SHA

1 participant