Skip to content

Warm daemon: "Call to a member function toMutatingScope() on null" (cold rector clean on same file) #5

Description

@fdaviddpt

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

  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions