Skip to content

Fix cached results surviving a change of --autoload-file#8034

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
SanderMuller:fix/autoload-file-cache-invalidation
Jun 11, 2026
Merged

Fix cached results surviving a change of --autoload-file#8034
TomasVotruba merged 1 commit into
rectorphp:mainfrom
SanderMuller:fix/autoload-file-cache-invalidation

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

--autoload-file changes what PHPStan can resolve, but it lives only in CLI input — unlike withBootstrapFiles() / withAutoloadPaths() it never reaches the configuration hash. So cached results survive it:

  1. rector process --dry-run without -a on a project whose helper functions live in an extra autoload → the helpers are unresolvable, files get cached as unchanged
  2. rector process --dry-run -a vendor/autoload.php → PHPStan can now infer through the helpers, a fresh run reports new suggestions — but the warm run reports [OK] Rector is done! until --clear-cache

Fix

bin/rector.php already reads the option at boot (to load the file early); now it also registers the resolved path as a parameter there, before the configuration hash is computed — and FileHashComputer already includes the parameter bag in that hash, so a changed -a invalidates the cache like any config change.

ArgvInput::getParameterOption() handles all spellings (--autoload-file path, --autoload-file=path, -a path), and realpath() normalization keeps the hash identical across them — verified: switching spellings or repeating the flag does not re-invalidate, and parallel workers (which receive the space-separated form) compute the same hash as the main process.

The resolution lives in AutoloadFileParameterResolver so it is unit-testable: every spelling resolves to the same real path, no flag leaves the parameter untouched, and the resolved file changes FileHashComputer's configuration hash.

🤖 Generated with Claude Code

A different extra autoload changes what PHPStan can resolve, so cached
results must not survive it. Repro: run without -a (helper functions
unresolvable, files cached clean), then run with -a — the fresh
inference suggestions stay hidden until --clear-cache.

The configuration hash already includes the parameter bag, so registering
the resolved autoload file path there at boot is enough.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TomasVotruba TomasVotruba merged commit 1f43c36 into rectorphp:main Jun 11, 2026
64 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM 👍

Comment thread bin/rector.php
// ArgvInput handles both "--autoload-file path" and "--autoload-file=path"
$autoloadFileOption = (new ArgvInput())->getParameterOption(['--autoload-file', '-a'], null);
if (is_string($autoloadFileOption) && $autoloadFileOption !== '') {
SimpleParameterProvider::setParameter(Option::AUTOLOAD_FILE, realpath($autoloadFileOption) ?: $autoloadFileOption);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, where is this Option::AUTOLOAD_FILE parameter used later?

@SanderMuller SanderMuller Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nowhere directly — it only feeds SimpleParameterProvider::hash(), which FileHashComputer folds into the configuration hash. So a different -a changes that hash and the cache clears at boot, same as editing rector.php.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 👍

Btw, feels like I'm talking to chatbot, it's very hard to process these long responses.
Lots of unnecessary clutter, unrelated methods, links to decipher. Human response would be better :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, will slow down a bit with the AI replies, although Fable 5 is quite trigger happy with these, more so than previous models, now need to actually instruct it NOT to do it where in the past you have to tell it to do it explicitly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but we're not :D I don't want to turn this codebase into an AI slop. So far it costs more attention than it brings value.

@samsonasik

Copy link
Copy Markdown
Member

Where is the AutoloadFileParameterResolver mentioned in the PR description :| ?

@samsonasik

samsonasik commented Jun 11, 2026

Copy link
Copy Markdown
Member

@SanderMuller this AI generated PR and description make us harder to verify, as you mentioned something that never exists in rector code base: AutoloadFileParameterResolver:

Screenshot 2026-06-11 at 16 46 21

which means that exactly the hallucination.

We need contributor that actually understand and can explain the issue cleanly as a human, understand the flow and has effort to fix the notice feedback as a human. That will help us (maintainer) to review.

@SanderMuller

SanderMuller commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, that one is on me. I pushed the class + tests at 09:09, two minutes after the merge, and updated the description without noticing it had already merged. So the class is real, just badly timed — it is in #8035 now.

Fair point on the long AI-flavored responses. I will keep PRs and comments shorter.

samsonasik pushed a commit that referenced this pull request Jun 11, 2026
…8035)

Follow-up to #8034, which merged before its last revision: the parameter
registration moves from inline bin code into a unit-testable class. Tests
pin that every CLI spelling (--autoload-file path, --autoload-file=path,
-a path) resolves to the same real path, that the parameter stays
untouched without the flag, and that registering it changes
FileHashComputer's configuration hash.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants