Invalidate the whole result cache when a changed package registers a container class#6088
Open
SanderMuller wants to merge 1 commit into
Open
Invalidate the whole result cache when a changed package registers a container class#6088SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
staabm
reviewed
Jul 22, 2026
SanderMuller
force-pushed
the
fix-result-cache-extension-package
branch
2 times, most recently
from
July 22, 2026 17:01
4812aa5 to
cc5ce71
Compare
ondrejmirtes
requested changes
Jul 22, 2026
ondrejmirtes
left a comment
Member
There was a problem hiding this comment.
Please add another E2E project to test. One that doesn't include extension's neon file via includes but registers an extension via phpstan/extension-installer.
SanderMuller
force-pushed
the
fix-result-cache-extension-package
branch
2 times, most recently
from
July 22, 2026 19:39
555dfca to
33306c0
Compare
…container class The package-granular invalidation only re-seeds files that depend on a changed Composer package through code references. A package that registers a rule or extension in the PHPStan container (larastan and similar) is not referenced by the analysed code, yet its code can change the analysis of every file, so the granular re-seed left the cache serving stale results after such a package was updated. Before the package-granular invalidation any composerInstalled change forced a full re-analysis, which happened to cover this. Detect it: when a changed package owns a class registered in the container (ProjectConfigHelper::getServiceClassNames resolved to a package via PackageDependencyResolver::resolvePackage), re-analyse everything instead of only the file-granular dependents. Packages that contribute nothing to the container keep the granular path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SanderMuller
force-pushed
the
fix-result-cache-extension-package
branch
from
July 22, 2026 19:52
33306c0 to
00d5e6d
Compare
Contributor
Author
|
Added |
staabm
approved these changes
Jul 23, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
I verified the e2e tests locally and they work as expected. I am not 100% into the impl details of ResultCacheManager.
@ondrejmirtes please give it a final go
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.
Follow-up to #6086 and a discussion with @staabm. The package-granular result-cache invalidation from #5933 does not invalidate the cache when a Composer package that registers a class in the PHPStan container (a rule or extension, e.g. larastan) is updated.
getChangedComposerPackages()reports the changed package, and the incremental loop then re-seeds only the files that depend on it through code references. An extension package is not referenced by the analysed code, so zero files are re-seeded and the previous results are served from the cache even though a rule changed.projectExtensionFilesdoes not cover this either, becausegetProjectExtensionFiles()skips service classes whose file is undervendor/with no tracked dependencies.This is a regression from #5933. Before it, any
composerInstalled/composerLockschange forced a full re-analysis, which happened to catch this.The fix: when a changed package owns a class registered in the container (
ProjectConfigHelper::getServiceClassNames()resolved to a package viaPackageDependencyResolver::resolvePackage()), re-analyse everything instead of only the file-granular dependents. Packages that contribute nothing to the container keep the granular path.Added an e2e test (
result-cache-extension-update): a package ships a rule through itsextension.neon, the package is then updated (rule body changed and itsreferenceinvendor/composer/installed.phpbumped, ascomposer updatewould), and the run must re-analyse everything and report the new rule output. It fails before this change (granular re-seed, 0 files, stale output) and passes after. The existingresult-cache-package-updatee2e keeps asserting that a normal package update stays file-granular, so this does not over-invalidate.Closes phpstan/phpstan#14986