agentleFS
muon-m2muon-m2/magento2-tools/skills/fix/SKILL.md

fix

Skill4 starsChanged 57 days agoMITView on GitHub

End-to-end Magento 2 bug-fix workflow. Use when the user reports a defect, error, crash, exception, unexpected behaviour, or regression in an existing module. Requires user approval at the RCA gate before any code change. Calls magento2-tools:review, and magento2-tools:deploy only when authorized. Accepts a diagnosed finding via --from-finding=<report.json>#<id>; magento2-tools:remediate then owns the gate (plans: magento2-tools:triage on a magento2-tools:audit report).

44 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use pr-creator, frontend-code-review and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • GoogleSkill

    pr-creator

    Also in 3 projects that use this

  • DauQuangThanhSkill

    frontend-code-review

    Conducts comprehensive frontend code reviews including React/Vue/Angular component analysis, TypeScript/JavaScript quality assessment, CSS/styling review, performance optimization, accessibility compliance, security vulnerabilities, and best practices validation. Produces detailed review reports with specific issues, severity ratings, and actionable recommendations. Use when reviewing frontend code, analyzing React/Vue/Angular components, checking JavaScript/TypeScript quality, validating CSS/SCSS, assessing web performance, or when users mention "review frontend code", "check React components", "analyze JavaScript", "review TypeScript", "validate accessibility", or "frontend code quality".

    Also in 3 projects that use this

  • Microsoft AzureSkill

    test

    Also in 10 projects that use this

  • MicrosoftSkill

    merge

    Merge changes from the topic branch to the merge base branch. Use when the user wants to merge their session's work back to the base branch.

    Also in 3 projects that use this

  • GitHubSkill

    refactor

    Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.

    Also in 6 projects that use this

  • BlockSkill

    plan

    Draft a TDD, PRD, or lightweight plan in the conversation without committing it.

    Also in 10 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

20 rules. 0 are common, 10 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 36 edited versions we read keep these.

  • 10

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    One approval gate: Do not change any production code until the user approves the root cause + proposed fix in Phase 3.

    line 28
  2. Distinctive:

    Regression test required, with two narrow waivers: Every bug fix produces a test that fails before the fix and passes after.

    line 38
  3. Distinctive:

    No scope expansion: If reproduction or RCA reveals additional bugs, file them as separate tasks rather than expanding the current fix.

    line 44
  4. Distinctive:

    Reproduce first: If the bug can't be reproduced after 2 attempts, stop and report "cannot reproduce" with all evidence collected.

    line 46
  5. Very specific:

    Output budget: Follow context/references/output-budget.md — targeted reads, summary-first test/lint output, long logs to files.

    line 64
  6. Distinctive:

    Run the reproduction (or hand it to the user if it requires interactive auth).

    line 127
  7. Very specific:

    If a live reproduction fails twice, do not immediately give up: attempt to encode the defect as a failing automated test straight from the …

    line 129
  8. Very specific:

    Follow the stack trace from the entry point through the module(s).

    line 143
  9. Distinctive:

    Read the surrounding code, git blame, and recent commits.

    line 154
  10. Very specific:

    Write the RCA per references/rca-format.md:

    line 155
  11. Very specific:

    Write the test first (RED): Add the test under {ctx.magento_root}/app/code/{Vendor}/{Module}/Test/Unit/...

    line 174
  12. Distinctive:

    Run the test. Confirm it fails for the right reason — the assertion must fail with the bug's symptom, not a setup error, fatal, or …

    line 181
  13. Distinctive:

    Run the test. Confirm it passes.

    line 187
  14. Very specific:

    Run the full test suite for the affected module, then the project's static checks ({ctx.tools} — PHPCS/PHPStan).

    line 188
  15. Distinctive:

    Apply the shared module-hygiene baseline (required): After modifying or adding PHP files (the patch and the new regression test), run

    line 191
  16. Very specific:

    Commit each review-fix as [bug-fix] {Module}: review fix - {finding}.

    line 213
  17. Very specific:

    If user authorizes deploy: invoke deploy --env={target}.

    line 217
  18. Distinctive:

    After deploy, re-run the original reproduction recipe.

    line 218
  19. Very specific:

    If smoke fails after deploy, follow deploy's rollback recipe and report.

    line 219
  20. Very specific:

    Never edit vendor/ or vendor/magento/ — fix via a plugin/observer in a project module.

    line 250

“Common” is measured: kept by at least 6 in 10 of the 36 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Magento 2 Bug Fix

Surgical defect remediation. The user describes a bug; this skill drives reproduction, root-cause analysis, the minimal fix, a regression test, and review across eight phases (Phase 0 setup, then Phases 1–7).

Core Rules

  • TDD is the preferred approach. Implement every fix test-first (red → green → refactor): write the failing regression test, watch it fail for the right reason, then write the minimal production code to make it pass. The test encodes the reproduction; the patch exists only to turn it green. Reach for a non-TDD flow only when the bug is genuinely untestable (see the regression-test rule below), and document why. The shared red → green → refactor loop and the behaviour/boilerplate line live in context/references/tdd-discipline.md — this skill applies it to defect remediation.
  • One approval gate. Do not change any production code until the user approves the root cause + proposed fix in Phase 3.
  • Report-driven entry. --from-finding=<report.json>#<finding-id> pre-fills Phases 1–2 from a finding that is already diagnosed, and delegates the Phase 3 approval to the calling orchestrator when one is present. It skips the interrogation, never the discipline — TDD, minimal change, and the mandatory regression test all still apply. A finding whose confidence is not confirmed must be confirmed by reading its evidence before any test is written. See references/from-finding.md.
  • Minimal change. The diff must affect only what the bug demands. No surrounding cleanup. No refactor. No "while we're here" edits.
  • Regression test required, with two narrow waivers. Every bug fix produces a test that fails before the fix and passes after. The only exceptions are (a) a bug that is provably untestable (e.g. a third-party gateway outage — and most "untestable" bugs are actually testable with a clock injection or a mock, so push back first), and (b) a purely config/XML change validated by XSD instead. Either waiver must be recorded in the RCA and confirmed by the user before the fix lands.
  • No scope expansion. If reproduction or RCA reveals additional bugs, file them as separate tasks rather than expanding the current fix.
  • Reproduce first. If the bug can't be reproduced after 2 attempts, stop and report "cannot reproduce" with all evidence collected.
  • Never edit vendor/. Fix in a project module via plugin/observer/preference. Editing vendor/magento/ or any third-party module is forbidden.
  • Per-task commits. Each phase that modifies files commits independently with the [bug-fix] prefix. See references/commit-format.md.
  • Coding style. Patched/added PHP follows PER-CS 3.0 as the baseline, with the Magento 2 coding standard taking precedence on any conflict; --standard=Magento2 PHPCS is the gate. See context/references/php-coding-style.md. (Stay within the minimal-change rule — do not restyle surrounding code.)
  • Process surface is owned — don't defer it. The reproduce → root-cause → fix loop (Phases 1–3) and the test-first discipline (Phase 4) are domain-tuned, owned surfaces. Do not route them through a generic process skill (superpowers:systematic-debugging, superpowers:test-driven-development) and do not replace the Phase 5 review with a generic one — each duplicates owned work and lacks the Magento specifics (log paths, stack-trace frames, ACL/escaping/EQP). Unlike feature, bug-fix has no sanctioned defer-if-present hand-wave — it is surgical and single-threaded, so there is nothing to defer. The governing policy and the reasons are in context/references/process-skills.md.
  • Output budget. Follow context/references/output-budget.md — targeted reads, summary-first test/lint output, long logs to files.
  • After a context compaction, re-read the reference for the phase in progress before continuing.

Workflow

Phase 0 — Context Resolution

Invoke context. Capture {ctx.vendor}, {ctx.runner}, {ctx.magento_cli}, {ctx.magento_root}, {ctx.tools}. If magento_cli is null, reproduction Phase 2 will be limited to static log analysis — note this up-front.

Then ensure work happens on a dedicated branch. If the current branch is the default (main) or a detached HEAD, create bugfix/{slug} before any commit. All per-phase commits land on that branch; the skill never pushes (see references/commit-format.md).

Phase 1 — Collect

Goal: have enough information to attempt reproduction.

  1. Parse the user's bug description.
  2. With --from-finding: skip this question batch entirely — the finding supplies symptom, scope, severity and file:line evidence. Record the source report path and finding id in the collection notes, then go to step 3. Otherwise, ask for any of the following that's missing (one batch — do not interrupt later):
    • Symptom: visible failure?
    • Trigger: action that causes it?
    • Scope: customer-facing / admin / REST / GraphQL / cron / queue / CLI?
    • Environment: production / staging / local; Magento version; module list.
    • Error: exact error message or stack trace.
    • First seen: date / commit / deploy.
  3. Pull relevant log files. With --from-finding, do this only when the finding's category is runtime-class (controllers, cron, queue, api, graphql-auth, n_plus_one, slow_query); a purely static finding has nothing in var/log to find. Defaults (resolved against {ctx.magento_root}):
    • var/log/system.log
    • var/log/exception.log
    • var/log/debug.log
    • var/report/** — recursive, including var/report/api/. A report file is often the ONLY record: Webapi\ErrorProcessor::apiShutdownFunction() writes var/report/api/{id} on a PHP fatal with no logger call at all.
    • Any module-specific log mentioned in the symptom (ls -t var/log/*.log | head).
  4. Grep logs for the symptom signature. When the user says "the error is not in the logs", treat that as a routing fact, not a dead end: exception.log receives a record only when context['exception'] is set, so string-level criticals (e.g. the ObjectManager's Type Error occurred when creating object: …) are in system.log instead. See debug/references/log-locations.md §"What to Search When the Symptom Is 'No Log Entry'".

Save the initial collection notes to {output_root}/bug-fixes/{slug}/collect.md.

Phase 2 — Reproduce

Goal: make the failure happen deterministically.

With --from-finding: the finding's verification string plus its file:line evidence is the reproduction, and the 2-attempt live-reproduction rule below does not apply — a statically derived finding has no runtime recipe to attempt, and demanding one yields a spurious "cannot reproduce" for a defect whose evidence is sitting in the file. Go straight to encoding it as the failing test in Phase 4 (step 5 below already sanctions this route). See references/from-finding.md.

  1. Identify the entry point (URL / CLI / cron job / queue topic).
  2. Build the minimal reproduction recipe — see references/reproduction-patterns.md.
  3. Run the reproduction (or hand it to the user if it requires interactive auth).
  4. Capture the failure output and any new log entries.
  5. If a live reproduction fails twice, do not immediately give up: attempt to encode the defect as a failing automated test straight from the stack trace and RCA evidence (inject a clock, mock the third party — see references/regression-test-patterns.md). A failing test is itself a valid reproduction. Only report "cannot reproduce" when neither a live recipe nor a failing test can be produced.

The runtime recipe is scaffolding to find the failing assertion; the regression test written in Phase 4 is the durable reproduction artifact. Save the recipe to {output_root}/bug-fixes/{slug}/reproduction.md.

Phase 3 — Root-Cause Analysis (APPROVAL GATE)

Goal: locate the exact code line(s) responsible.

  1. Follow the stack trace from the entry point through the module(s). See references/stack-trace-reading.md for tips on plugin/observer/preference frames. In agents mode (--agents flag, or execution_mode in .claude/m2.json surfaced as {ctx.execution_mode} — selection contract in context/references/execution-modes.md), delegate this path-tracing to the read-only explorer agent and work from its comprehension map; default is auto (agents when the plugin's context-budget hook reports this conversation above its threshold, inline otherwise). The RCA approval gate below always runs in the main conversation, in either mode.
  2. For each frame: is the call legitimate? Does it return the expected value?
  3. Identify the first frame where behaviour diverges from intent.
  4. Read the surrounding code, git blame, and recent commits.
  5. Write the RCA per references/rca-format.md:
    • Defect location: file:line
    • Defect description: what's wrong, in plain English
    • Why: history (last-touched commit, original intent)
    • Proposed fix: minimal change description (do not write code yet)
    • Regression test plan: which test class, what assertion
  6. Save RCA to {output_root}/bug-fixes/{slug}/rca.md.
  7. Present RCA. Wait for explicit approval ("proceed", "yes", "approved"). Exception — invoked by remediate: the RCA is still written, but the approval is delegated upward: it is included in the batch presentation and the caller takes ONE approval for the whole batch, then this skill proceeds without re-prompting per finding. This mirrors the carve-out review already documents for skill-to-skill invocation. Invoked standalone, --from-finding keeps this gate.

Phase 4 — Patch + Regression Test (TDD)

Goal: minimal patch + a test that fails before, passes after. Follow red → green → refactor.

  1. Write the test first (RED). Add the test under {ctx.magento_root}/app/code/{Vendor}/{Module}/Test/Unit/... (or Test/Integration/... if the bug requires DB state). Prefer appending a testRegression{Behaviour}() method to the module's existing test class for that subject; create a new file only when none exists. Follow the location and naming convention in references/regression-test-patterns.md and start from the matching templates/regression-test-*.php skeleton.
  2. Run the test. Confirm it fails for the right reason — the assertion must fail with the bug's symptom, not a setup error, fatal, or missing-class error. If the test passes before any fix, the test does not capture the bug or the RCA is wrong: stop and return to Phase 3 before writing any production code.
  3. Apply the minimal patch (GREEN). Write only the code needed to satisfy the failing assertion — no more.
  4. Run the test. Confirm it passes.
  5. Run the full test suite for the affected module, then the project's static checks ({ctx.tools} — PHPCS/PHPStan). Confirm no other tests broke and the patch is clean (REFACTOR: tidy only the lines you touched, keeping the test green).
  6. Apply the shared module-hygiene baseline (required). After modifying or adding PHP files (the patch and the new regression test), run ${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/add-license-headers.sh {ctx.magento_root}/app/code/{Vendor}/{Module} {Vendor} to stamp the standard copyright header onto every new .php (idempotent — it skips files that already carry it, so existing patched files are left as-is). On the rare occasion the fix adds a composer.json require entry, resolve a bounded constraint via ${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/resolve-dep-constraint.sh <vendor/package> — never "*". See context/references/module-hygiene.md.
  7. Commit per references/commit-format.md:
    [bug-fix] {Module}: {symptom}
    
    RCA: {output_root}/bug-fixes/{slug}/rca.md
    Files: {list}

Phase 5 — Review

  1. Invoke review --diff on each modified module.
  2. Fix any new Critical/High findings introduced by the patch (do not silently leave them — they would re-introduce risk on top of the bug fix).
  3. Re-run tests after each fix.
  4. Commit each review-fix as [bug-fix] {Module}: review fix - {finding}.

Phase 6 — Deploy (Optional)

  1. If user authorizes deploy: invoke deploy --env={target}.
  2. After deploy, re-run the original reproduction recipe. Assert success.
  3. If smoke fails after deploy, follow deploy's rollback recipe and report.

Phase 7 — Report

Save report per templates/report.md to {output_root}/bug-fixes/{slug}/report.md:

  • Symptom
  • Reproduction recipe (path)
  • Root cause (link to RCA)
  • Fix description + files changed
  • Regression test path
  • Review findings remediated
  • Deploy result (if Phase 6 ran)
  • Severity classification

Optional: open a PR. Same shape as feature PR step.

Bug Classification

Classify at the start of Phase 7 (do not let classification gate Phase 6 — the fix is already in):

ClassDefinitionDefault deploy timing
CriticalProduction down, data loss, security breachImmediate
HighMajor functional break on common pathNext deploy window
MediumEdge case with workaroundBundled with next feature deploy
LowCosmetic / minor inconvenienceDiscretionary

Edge Cases

Never edit vendor/ or vendor/magento/ — fix via a plugin/observer in a project module. A schema change (db_schema.xml) stops the fix and redirects to feature --mode=extend; a data repair stays in-skill via data-migration. Read references/edge-cases.md from Phase 1 onward (cases: vendor/core bug, multi-module, cannot reproduce, schema, data repair, config-only).

Inputs

/fix "<bug description>"

Optional flags:

  • --from-finding=<report.json>#<finding-id> — take the defect from an existing findings document (schemaVersion ≥ 1.1) instead of a user description. See references/from-finding.md.
  • --module=<Vendor>_<Module> — constrain RCA to a single module.
  • --log=<path> — additional log file beyond the defaults.
  • --no-deploy — skip Phase 6.
  • --severity=critical|high|medium|low — pre-classify.
  • --docs-root=<path> — output-root override; see "Output root" below.

Outputs

{output_root}/bug-fixes/{slug}/          # {fingerprint-short} under --from-finding
├── collect.md      # Phase 1 evidence
├── reproduction.md # Phase 2 recipe
├── rca.md          # Phase 3 RCA
└── report.md       # Phase 7 final report

{output_root} defaults to .docs ({ctx.docs_root}), anchored at the project root, never under {ctx.magento_root}, app/code, or a module dir. See the Artifact location rule in context/SKILL.md.

Output root (--docs-root)

This skill accepts --docs-root=<path> (see context/references/artifact-layout.md). When set, write the run report (and any report artifacts) under <path>/bug-fixes/; otherwise default to {ctx.docs_root}/bug-fixes/. feature passes this so a feature run's reports collect under its folder. The dossier root for a given fix is {output_root}/bug-fixes/{slug}/.

Plus per-task git commits per references/commit-format.md.

Reference Files

  • references/edge-cases.md — edge-case behaviour table (vendor/core bug, multi-module, cannot reproduce, schema/data/config-only).
  • references/log-targets.md — bug-fix log-collection specifics; defers to the shared debug/references/log-locations.md for the canonical log-path catalogue.
  • references/reproduction-patterns.md — HTTP / CLI / cron / queue / GraphQL recipes.
  • references/stack-trace-reading.md — how to follow a Magento stack trace through plugins.
  • references/from-finding.md — report-driven entry: the phase deltas, what is NOT relaxed, the delegated approval gate, and the fingerprint-keyed dossier.
  • references/rca-format.md — RCA document structure and required sections.
  • references/regression-test-patterns.md — patterns by bug class (DI, plugin, observer, query, controller).
  • references/deferred-bugs.md — when to file a new bug vs expand current scope.
  • references/commit-format.md — [bug-fix] commit message format.

Templates

  • templates/rca.md
  • templates/report.md
  • templates/regression-test-unit.php
  • templates/regression-test-integration.php
  • templates/regression-test-controller.php

Related Skills

PhaseSkill
0context
4data-migration (only when the fix is a data repair)
5review (with --diff)
6deploy (if user authorizes)
(alternative)debug — when reproduction fails and you need to investigate logs/DI graph

This skill does not invoke module-create (no new modules) or feature (different shape).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.