Skip to content

fix(rector-mcp): config-driven engine-glitch suppression, catch toMutatingScope#350

Merged
fdaviddpt merged 2 commits into
masterfrom
fix/rector-engine-glitch-config
Jun 26, 2026
Merged

fix(rector-mcp): config-driven engine-glitch suppression, catch toMutatingScope#350
fdaviddpt merged 2 commits into
masterfrom
fix/rector-engine-glitch-config

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Context

The warm rector daemon intermittently trips a PHP fatal inside rector's own engine — Call to a member function toMutatingScope() on null — a non-deterministic glitch a cold rector CLI does not reproduce. Like the June System error: ClassReflection case it surfaced as a false red and — because the validator cache keys on file content — froze into the cache and replayed on every later run until the file changed (the 2100-poisoned-entries failure mode, new signature).

The old guard string-matched System error: inside _validator_result_is_cacheable in the core — which violates SCHEMA.md's contract: "Validator core never parses tool-specific output." This PR removes that and pushes glitch knowledge down to the adapter, config-driven.

Changes

  • validators/rector-mcp/rector-mcp.py — reads its glitch signatures from .supertool.jsonvalidators.rector.engine_glitches (the adapter loads the file directly, the same one daemon.py already reads from cwd), drops a matching error at the source. Built-in defaults ["System error:", "toMutatingScope() on null"] when the prop is absent.
  • supertool.py — deleted the System error: string-match in _validator_result_is_cacheable. The core cache filter is now fully generic: it keys only off non-deterministic error codes, never message text.
  • validators/SCHEMA.md — documents the new engine_glitches validator-entry field.
  • docs/validators.md — updated the "never cached" section.
  • Tests — new tests/test_rector_mcp_engine_glitches.py (prop override, empty-disables, defaults, substring match, source-drop); updated one security-hardening test to the new generic-core contract.

A new glitch signature is now a one-line config edit, not a code change.

Test plan

  • python3 -m pytest -q3489 passed, 34 skipped (8 new).

Notes

Only addresses the rector half of #345. The phpunit-mcp transient-DB-red half is a different mechanism (verify-on-red, not signature-matching) and lands separately — hence "Part of", not "Closes".

🤖 Generated by Max — the core forgot rector exists, which is exactly how it should be.

…atingScope

Move glitch knowledge out of the generic core (it was string-matching
"System error:" in _validator_result_is_cacheable, breaking SCHEMA.md's
"core never parses tool-specific output") into the rector-mcp adapter,
where signatures are a config prop: validators.rector.engine_glitches in
.supertool.json. The adapter reads its own prop straight from the file and
drops a matching error at the source, so a non-deterministic engine glitch
(e.g. "toMutatingScope() on null") never surfaces as a red or freezes into
the file-hash-keyed validator cache. Defaults to the two known signatures
when the prop is absent.

Part of #345.

Co-Authored-By: Max <noreply>
…f, edge tests

- Memoize engine_glitch_signatures() (lru_cache): the adapter is a fresh
  process per validator call, so config can't change underneath a run —
  avoids re-reading/parsing .supertool.json once per rector error in the loop.
- Comment accuracy: the signature *values* are config not env; the file is
  located via WORKING_DIR (a single read, no parent-dir walk unlike daemon.py
  / the core loader), which holds because the daemon cmd runs at project root.
- CHANGELOG: state the tradeoff honestly — removing the core message-backstop
  means a brand-new uncatalogued glitch can still reach the cache until added
  to config (bounded to unknown signatures, one-line config fix).
- Tests: malformed .supertool.json and a non-list engine_glitches prop both
  fall back to built-in defaults.

Co-Authored-By: Max <noreply>
@fdaviddpt fdaviddpt merged commit 808c40a into master Jun 26, 2026
12 checks passed
@fdaviddpt fdaviddpt deleted the fix/rector-engine-glitch-config branch June 26, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant