Skip to content

fix: compile-gate mutated children and guard invalid OR patterns - #892

Merged
devdanzin merged 1 commit into
mainfrom
fix/compile-gate-match-pattern-waste
Jul 3, 2026
Merged

devdanzin merged 1 commit into
mainfrom
fix/compile-gate-match-pattern-waste

Conversation

@devdanzin

Copy link
Copy Markdown
Owner

Summary

  • Health analysis of ~/runs/jit_run12 (session-fuzz) found 37.5% of ignored_crash events (2,150 of 5,738) were children that fail at compile() in the executor and never run — 0 coverage, 0 JIT trace, pure wasted executions that also count toward sterility/coldness.
  • Root cause: the mutation pipeline validated children only via ast.parse/ast.unparse round-trips, which do not catch match-statement semantic errors — only compile() does. Dominated by alternative patterns bind different names (from _add_pattern_complexity wrapping a name-binding pattern in case P | [_]:) and mapping pattern checks duplicate key (from a constant mutator flipping a key in case {'x': _, 'y': _}:).
  • Fix 1 (general): prepare_child_script now compile()s the generated core and skips the mutation on SyntaxError, logging a core_code_syntax_error health event. compile() is far cheaper than the wasted subprocess run it prevents, and it kills the entire class (both variants + any future semantic-SyntaxError generator). SyntaxWarnings are suppressed during this side-effect-free validation.
  • Fix 2 (targeted): _add_pattern_complexity now skips patterns that capture any name, since the alternatives it adds bind none.

Test plan

  • TestCompileGate: a child that round-trips through ast.parse but fails compile() is rejected (returns None, records the health event); a valid child passes and the assembled child compiles.
  • _pattern_binds_names detection (capture / star / mapping-rest); _add_pattern_complexity skips name-binding patterns and still wraps non-binding ones — both outputs compile.
  • Full suite: 2182 passed, 492 subtests (no new warnings).
  • mypy lafleur clean (38 files); ruff check / ruff format clean.

Closes #891

🤖 Generated with Claude Code

Health analysis of a session run (~/runs/jit_run12) showed 37.5% of
ignored_crash events (2,150 of 5,738) were children that failed at
compile() in the executor and never ran — 0 coverage, 0 JIT trace, pure
wasted executions that also counted toward sterility.

The mutation pipeline validated children only via ast.parse/ast.unparse
round-trips, which do NOT catch match-statement semantic errors — only
compile() does. Two dominant offenders:
- "alternative patterns bind different names" (1,880): from
  PatternMatchingChaosMutator._add_pattern_complexity wrapping a
  name-binding pattern in `case P | [_]:`.
- "mapping pattern checks duplicate key" (252): from a constant mutator
  flipping a key in `case {'x': _, 'y': _}:`.

Two fixes:
1. prepare_child_script now compile()s the generated core and skips the
   mutation on SyntaxError (logging a core_code_syntax_error health
   event), killing the entire class cheaply — compile() is far cheaper
   than the wasted subprocess run it prevents. SyntaxWarnings are
   suppressed during this side-effect-free validation.
2. _add_pattern_complexity now skips patterns that capture any name,
   since the alternatives it adds bind none.

Adds TestCompileGate and _add_pattern_complexity/_pattern_binds_names
tests. Full suite: 2182 passed; mypy clean.

Closes #891

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@devdanzin
devdanzin merged commit 31c229d into main Jul 3, 2026
2 checks passed
@devdanzin
devdanzin deleted the fix/compile-gate-match-pattern-waste branch July 3, 2026 00: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.

Match-pattern mutations waste ~37% of ignored-crash executions on compile-time SyntaxErrors

1 participant