Symptom
The warm rector-mcp validator returns this error on certain files:
rector.error Call to a member function toMutatingScope() on null
The cold rector binary (vendor/bin/rector process <file>) runs clean ([OK] Rector is done!) on the identical files. So this is a warm-daemon-only failure, not a real refactoring finding.
Stateful / per-file
In a single warm session the error fires on some files but not others. Concretely, in one session: it crashed analysing an abstract base class and a child class that had just been edited, but was ok on a test file analysed in the same session. The crash also persisted across repeated edits to the offending files until the daemon was restarted.
Diagnosis (clue)
toMutatingScope() is called on a PHPStan Scope. "on null" means a node's Scope attribute — populated by NodeScopeResolver — is null when a scope-dependent rule reads it.
The package keeps the Rector container bootstrapped across calls (per the package description). The most likely cause is that NodeScopeResolver / per-node Scope attributes carry stale or uncleared state between invocations, so on some files nodes are visited without a freshly populated scope -> $scope is null -> toMutatingScope() on null. A cold boot repopulates scope per run, which is why cold rector never hits it.
Environment
dpt/mcp-rector-warm, rector/rector ^2.4, PHP 8.2
- Invoked via DVSI
supertool rector-mcp validator adapter
Impact
False validator noise that reads as a code problem. Current workaround: dvsi_clearcache (restarts the warm daemons), after which the same file analyses clean.
Asks
- The supertool adapter truncates the error to one line — capture/log the full stack trace in the warm server so the failing rule + node type are visible.
- Reset
NodeScopeResolver / scope attribute state per request in the warm loop, or detect a null scope and transparently fall back to a cold analyse for that file.
Symptom
The warm
rector-mcpvalidator returns this error on certain files:The cold rector binary (
vendor/bin/rector process <file>) runs clean ([OK] Rector is done!) on the identical files. So this is a warm-daemon-only failure, not a real refactoring finding.Stateful / per-file
In a single warm session the error fires on some files but not others. Concretely, in one session: it crashed analysing an abstract base class and a child class that had just been edited, but was
okon a test file analysed in the same session. The crash also persisted across repeated edits to the offending files until the daemon was restarted.Diagnosis (clue)
toMutatingScope()is called on a PHPStanScope. "on null" means a node'sScopeattribute — populated byNodeScopeResolver— isnullwhen a scope-dependent rule reads it.The package keeps the Rector container bootstrapped across calls (per the package description). The most likely cause is that
NodeScopeResolver/ per-nodeScopeattributes carry stale or uncleared state between invocations, so on some files nodes are visited without a freshly populated scope ->$scopeisnull->toMutatingScope()on null. A cold boot repopulates scope per run, which is why cold rector never hits it.Environment
dpt/mcp-rector-warm,rector/rector ^2.4, PHP 8.2supertoolrector-mcpvalidator adapterImpact
False validator noise that reads as a code problem. Current workaround:
dvsi_clearcache(restarts the warm daemons), after which the same file analyses clean.Asks
NodeScopeResolver/ scope attribute state per request in the warm loop, or detect a null scope and transparently fall back to a cold analyse for that file.