refactor(project): Drop resurrected resources from delta merge - #1465
Merged
Conversation
On a delta signature transition whose changedProjectResourcePaths lists a path the delta task did not re-emit, the merge loop in recordTaskResult replayed the previous stage's copy into the new stage writer. When a source file is deleted between builds, the delta task emits nothing for it and the merge resurrects the pre-deletion output, so downstream readers keep serving the file after its source is gone. Affects every differential task (replaceCopyright, replaceVersion, replaceBuildtime, minify). Filter the merge by cacheInfo.changedProjectResourcePaths: if a path was flagged changed and the task did not write it, drop the stale copy instead of replaying it. Paths not flagged changed merge as before. Track the dropped count alongside the merged count in the perf log. Add four fail-then-succeed tests covering invariants across a failed-attempt/retry boundary on one ProjectBuildCache instance: 1. #writtenResultResourcePaths accumulates across failed attempts, because allTasksCompleted (which clears it) never runs on a thrown build. The worst outcome is redundant I/O on the retry, not wrong output: the retry re-hashes each leaked path against its fresh reader, so unchanged content yields the same signature and changed content invalidates. Clearing the set cleanly needs a separate fail/abort hook, since #initSourceIndex seeds the array with delta paths on the first build after loading persistent cache. 2. #currentStageSignatures reflect only the retry's stages. 3. The delta merge does not resurrect a deleted-source resource. 4. #frozenSourceReader is nulled by the retry's initStages call before task inputs are computed.
The delta merge in recordTaskResult scanned writtenResourcePaths with Array.includes once per previous-stage resource: O(n*m) string comparisons on every incremental serve rebuild, scaling with a project's total written-resource count. Build a Set for the membership check; the array stays for the ordered downstream uses.
RandomByte
marked this pull request as ready for review
July 21, 2026 19:15
matz3
approved these changes
Jul 22, 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.
Problem
When a task runs as a delta, its output is merged with the previous stage's cached output: any previously-written resource whose path the delta task did not re-emit is copied forward. The membership check only asked whether the delta re-emitted the path:
A path can be flagged changed yet not re-emitted, because its source is gone or now excluded. The previous stage still holds a copy of that path, so the merge writes it forward and resurrects content that no longer belongs in the output.
Fix
Distinguish "not re-emitted because unchanged" from "not re-emitted because it should no longer exist" by consulting
changedProjectResourcePaths:The membership check uses a
Set(writtenResourcePathSet); the array is retained for the ordered downstream uses (recordStageCache, verbose counts). The perf log gained adroppedcount alongsidepreviousandmerged.Tests
New cases in
test/lib/build/cache/ProjectBuildCache.jscover the drop path (changed-but-not-written) and confirm unchanged resources still merge forward.