Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
Depends caches packages using $(package)_local_dir as a tarball in SOURCES_PATH. The tarball is currently recreated only when find -newer
reports a path newer than the cached archive.
This does not reliably identify directory contents:
- Two worktrees sharing
SOURCES_PATHcan contain different source trees. - A tarball created by one worktree may be newer than every path in another.
- Deleting a file leaves no path whose mtime can be checked.
- Changed or restored files may have older or equal mtimes.
- Timestamp granularity and clock differences make ordering unreliable.
native_libmultiprocess is currently the only package using local_dir.
A shared SOURCES_PATH may contain e.g. src-ipc-libmultiprocess.tar generated from another worktree. If none of the current worktree's paths are newer, Depends reuses that archive.
The fetched stamp then correctly hashes the stale archive, and its checksum correctly affects the package build ID. However, the package is built from the wrong explicit source input.
Clearing BASE_CACHE or disabling Guix substitutes does not help because the stale input remains in SOURCES_PATH.
Expected behaviour
Local source identity should change when any of the following changes:
- A file is added, removed, or modified.
- File permissions, including the executable bit, change.
- A symlink target changes.
- An empty directory is added or removed.
Filesystem timestamps, ownership paths, and absolute worktree locations should not determine the identity. Identical trees in separate worktrees should produce the same archive checksum.
Different trees using the same shared SOURCES_PATH should be able to coexist.
Steps to reproduce
Tricky to define clearly here, but I'll try:
- Have two Bitcoin Core worktrees on different branches.
- Both worktrees use the same Depends
SOURCES_PATH. - The branches contain different versions of
src/ipc/libmultiprocess. - Both worktrees already exist before either build starts, so their source-file mtimes are older than the next archive created.
- Build Depends in worktree A. This creates
src-ipc-libmultiprocess.tarin the shared source cache. - Then build Depends in worktree B.
- The cached tarball is newer than every path in worktree B, so
find -newerreports no changes. - Depends reuses worktree A’s tarball even though worktree B has different contents.
- The checksum and build ID are calculated correctly—but for A’s stale archive.
- Worktree B therefore reproducibly builds the wrong libmultiprocess source.
The same problem can happen without two worktrees when a file is deleted or restored with an older mtime: the directory contents changed, but find -newer cannot detect it.
Relevant log output
No response
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
master branch, pr-35261
Operating system and version
NixOS 26.05
Machine specifications
No response
Activity
hebasto commentedon Jul 21, 2026
cc @ryanofsky
ryanofsky commentedon Jul 21, 2026
Thanks I wasn't aware of
SOURCES_PATHwhen I implemented this so it makes sense to handle it better.A consideration here is that the tarball is refreshed while parsing the makefile every time
makeis run, even ifmakeis only invoked to do something simple like print a variable (make print-build_CC). So the point of thefind -newercheck is to be fast, while still detecting changes as well as normalmakecommands using mtimes. I think the implementation handles this pretty well, because all the changes listed above in the "when any of the following changes" list will cause mtimes to be updated except file permissions changes, which won't trigger updates in normal make commands either.But the current implementation doesn't handle
SOURCES_PATHwell at all, and a logical extension of the original approach that handles it better would be to use different tarballs for different worktrees. Following patch hashes worktree paths and adds them to tarball filenames (can test withmake print-native_libmultiprocess_file_name) to implement this:diff
#35765 could also be an good approach if it's ok to hash the whole subtree each time make is invoked, which could be the case.
willcl-ark commentedon Jul 22, 2026
Thanks, hashing the worktree path does indeed seem a reasonable (smaller) fix for the
SOURCES_PATHcollision.My preference for content addressing (approach in #35765) is that even #35618 plus a path hash still retains mtime-based invalidation, which misses mode-only changes, modifies checkout mtimes, and gives identical trees at different paths separate source archives. It also doesn't make things totally atomic.
The current local tree is a only few hundred KB, and creating the normalized archive takes about 30 ms (for me, locally), so the stronger content-based identity seems pretty affordable to me?
That said, the path hash is a fine fallback if avoiding parse-time I/O, or simply having the smallest LoC change possible. I'm ~ happy with either.
TBH, I'm pretty surprised I didn't run into this sooner with how many guix builds I do with a single shared
SOURCES_PATH...ryanofsky commentedon Jul 28, 2026
I think the content addressing approach in #35765 is reasonable, but the reasons I'd favor (at least initially) adding path hashes like #35764 (comment) are:
It directly fixes the shared
SOURCES_PATHbehavior which is just a bug. If I had known about sharedSOURCES_PATHdirectories when I implemented the Local Packages feature in #31741 I'm pretty sure would have added the hashes then. It's a more direct solution to the problem than changing the design of the local package feature.I think the local package feature can be useful for more things than just the libmultiprocess subtree, and more things that just subtrees. For example, the
local_diroption is the only way you can build straightforwardly build a package from a git checkout. Without it, you have to serve a tarball from an HTTP server and hardcode the tarball hash in the package makefile. Similarly, the only other way to test modifications to upstream packages is to generate patch files and add them to them package makefile. Thelocal_diroption is an escape from these more cumbersome approaches that allows editing and building sources naturally. It seems to me like something we might want to optimize and make more convenient, not something to make slower.It doesn't seem right to recursively hash full directories every time
makeis invoked to do anything, even printing a variable. Even if this is fast now, the approach seems fragile because a single large file being added to a directory could substantially slow down make invocations without an indication why.I don't actually see a problem with the mtime based approach. It's how make has worked since it was created and it does have limitations but I feel like they are pretty well understood and well known. The description in this issue mixes together a list of mtime limitations with a description of the SOURCES_PATH bug. Even if the mtime approach is a real problem that's worth addressing I feel like would be better justify on its own terms rather turn into a bugfix.
Would be curious what you think though. Is any of this a convincing argument that mtimes are a reasonable alternative to hashing? Do you think the diff in #35764 (comment) should be a PR? I'd be happy to make a PR or review any similar change. Also happy to review #35765 if it seems like that will be the preferred fix.
depends: isolate local archives by source path
willcl-ark commentedon Sep 21, 2026
Thanks @ryanofsky, your argument convinced me. Keeping the existing mtime-based invalidation seems reasonable here especially since
local_dirmay be used with larger source trees in the future and the archive is generated while make parses its files.I've now updated #35765 to use the smaller path-hash fix you suggested. It isolates local source archives by absolute source path while leaving the existing invalidation model unchanged.
The broader mtime limitations are separate from the shared
SOURCES_PATHbug, so the PR no longer claims to address them, and we can look at those in the future, if necessary.depends: isolate local archives by source path
achow101 commentedon Nov 17, 2026
Running into this when doing the 30.x and 31.x guix builds, although not for 32.x.
ryanofsky commentedon Nov 17, 2026
re: #35764 (comment)
Good to know if #35765 would fix
Merge #35765: depends: keep local source archives in WORK_PATH
hebasto commentedon Nov 27, 2026
Closing, as #35765 has now been merged.