solver: advertise committed cache keys after exec - #6955
Merged
Conversation
Diagnose the concurrency-triggered cross-build miss: build 2/13 never queries because its shared base dependency is reused already-complete (pinned in Solver.actives by a concurrent build) and hands over an edgeState with zero cache keys, so probeCache/Query is never called and noCacheMatchPossible latches the dep to complete-only. Two probes, keyed by vertex digest: - checkDepMatchPossible: WARN when noCacheMatchPossible flips, logging the dep's state/keys/keyMap and whether its result still carries a cache key (dep_result_keys>0 with dep_keymap==0 = the starvation). - processDepReq: DEBUG on each cache-slow/complete dep delivery, logging edgeState keys vs result keys, so the fatal complete/0-key delivery in the concurrent run contrasts with the healthy cache-slow/keyed delivery in the serial run. Keeps the earlier probeCache-skip WARN as a proven-negative. Signed-off-by: Felix de Souza <fdesouza@palantir.com>
TestCacheMissStaleCompleteSharedDep reproduces the concurrency-triggered miss in-process (no docker): a producer builds step->base fresh, a holder job keeps only the shared base alive, the producer is discarded, then a consumer builds a fresh step over the same (already-complete) base. On pristine code the consumer re-executes (execCallCount=1) instead of reusing the cached result; with the probeResultCache fix it reuses (0). Verified to discriminate: fails on the pre-fix tree, passes with fafe01622. Signed-off-by: Felix de Souza <fdesouza@palantir.com>
An edge that completes by executing never adds its committed cache keys to edgeState.keys: the pre-execution cache query found nothing (that is why it executed) and Save only attaches the keys to the result. A consumer subscribing afterwards therefore receives zero keys, finds no probeable match, latches noCacheMatchPossible and re-executes even though its own cached record is intact. Normally such an edge dies with its build; the next build recreates it, re-queries the now-populated cache and delivers the key normally. But when a concurrent build keeps the shared edge referenced in Solver.actives, a later build reuses it already complete, inherits the empty key list and re-runs steps that should have been cache hits (moby#4674 family). Append the committed result keys to edgeState.keys on completion so an executed edge advertises its keys the same way a cache-hit edge does. Skipped for cache loads, whose record key is already present, and for ignore-cache edges, so that a --no-cache dependency does not let consumers match records through a step that was forced to re-run. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
The regression test's comments described the earlier consumer-side fix (probeResultCache reading a completed dep's result keys). The fix that landed instead makes processExecReq append an executed edge's committed keys to edgeState.keys on completion. Reword the mechanism references accordingly; scenarios and assertions are unchanged and still discriminate: the HeldCompleteBaseMisses subtests fail without the append, and the ignore-cache subtest fails without its IgnoreCache guard. Also use t.Context() instead of context.TODO() and drop t.Parallel(). Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
crazy-max
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
alternative for #6954
@felixdesouza
Does not fix full #4674 but should be simpler alterative to the issue/repro in #6954