How-to guide

Fail a pull request that breaks an ADR

Add a GitHub Actions workflow that runs mneme check on every added or modified text file in a pull request. A file that breaks an architecture decision record (ADR) makes the check fail, and a required status check then blocks the merge. The workflow also fails if someone edited an ADR without re-importing it.

You’ll end up with: a pull request check that fails when a change adds a direct database import under app/handlers/, plus a JSON verdict for each changed file.

Goal

Teams that aren't ready to put a hook in front of every agent can still catch a violation at merge. The workflow below runs on every pull request into main. It checks that the committed memory file (.mneme/project_memory.json, where Mneme stores the decisions compiled from your ADRs) is up to date with edited ADRs, then runs mneme check on each added or modified text file. If any file breaks a decision, the job fails and the pull request shows a failed check.

Prerequisites

  • A GitHub repository with ADR-012 in docs/adr/ and the memory file committed. This is ADR-012, which bans importing the database client under app/handlers/:
File · docs/adr/ADR-012-handlers-use-repositories.md
---
id: ADR-012
title: Request handlers do not import the database client
status: accepted
priority: foundational
date: "2026-10-01"
scope: handlers
---
Handlers call repositories. A direct client import skips the transaction
and tenancy handling that lives in app/repositories.

## Constraints
- FORBID_LITERAL:
    value: from app.db.client import
    include_paths:
      - "app/handlers/**"
  • The memory file, created with mneme init and mneme adr import docs/adr --memory .mneme/project_memory.json --apply. Turn an ADR into an enforceable decision explains both; Install Mneme and activate your first protection covers installing Mneme.
  • Permission to add workflows under .github/workflows/. To block merging, make the check required: in the repository settings, add a branch ruleset (or branch protection rule) for main with “Require status checks to pass”, and select this workflow’s mneme job.

Configure

Save this as .github/workflows/mneme-decisions.yml:

File · .github/workflows/mneme-decisions.yml
name: Architecture decisions

on:
  pull_request:
    branches: [main]

permissions:
  contents: read

jobs:
  mneme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install Mneme
        run: python -m pip install "mneme-hq==0.11.0"

      - name: Check the memory file matches the ADRs
        run: |
          mneme adr import docs/adr --memory .mneme/project_memory.json --apply --update-existing
          git diff --exit-code -- .mneme/project_memory.json

      - name: Check changed files against decisions
        shell: bash
        env:
          BASE_REF: ${{ github.base_ref }}
        run: |
          set -uo pipefail
          # Added and modified files, one per line as "added<TAB>deleted<TAB>path".
          # Binary files show "-" counts; mneme check reads text only.
          changes=$(git diff --numstat --no-renames --diff-filter=AM "origin/$BASE_REF...HEAD") || exit 2
          worst=0
          mkdir -p mneme-results
          while IFS=$'\t' read -r added _ f; do
            [ -n "$f" ] || continue
            if [ "$added" = "-" ]; then echo "skip    $f (binary)"; continue; fi
            out="mneme-results/$(printf '%s' "$f" | tr '/' '_').json"
            # GitHub runs this shell with -e; "|| code=$?" records a failing
            # check instead of ending the step at the first violation
            code=0
            mneme check --memory .mneme/project_memory.json \
              --input "$f" --target-path "$f" \
              --query "PR change: $f" --json > "$out" || code=$?
            echo "exit=$code  $f"
            if [ "$code" -gt "$worst" ]; then worst=$code; fi
          done <<< "$changes"
          exit "$worst"

      - name: Keep the verdicts
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: mneme-verdicts
          path: mneme-results/
  • fetch-depth: 0 fetches the history the workflow needs to compare the pull request against main.
  • The second step re-imports the ADRs and fails if that changes the memory file, which means someone edited an ADR without re-importing it. The import also prints a note that the ADRs already exist in the memory file. That is expected; the step passes when git diff finds no change.
  • That step catches edited ADRs only. Marking an ADR deprecated or superseded, or deleting it, leaves its decision active.
  • To retire a decision, write a new ADR that lists the old one under supersedes, keep the old file in docs/adr, and re-import with --update-existing (see Troubleshooting). Don’t edit the memory file by hand: from 0.10.0 a hand-edited file can fail to load.
  • --target-path "$f" tells Mneme where each file lives. Path-scoped rules like ADR-012 depend on it. --query describes the change; Mneme uses it to choose which decisions to show as guidance, and checks FORBID_LITERAL rules like ADR-012 either way.
  • Binary files (images, archives) are skipped, because mneme check reads text only. Renamed files count as added.
  • The loop keeps the worst exit code, so a passing file checked later can't hide an earlier failure. If git diff itself fails, the step exits 2 instead of passing with nothing checked.
  • The last step uploads every JSON verdict, even when the check fails.

Run

Open a pull request that adds three files. The first is a handler with the forbidden import, saved as app/handlers/invoices.py:

File · inputs/invoices_direct.py
from app.db.client import get_connection


def list_invoices(customer_id: str):
    conn = get_connection()
    return conn.execute("SELECT * FROM invoices WHERE customer_id = ?", (customer_id,))

The second is a repository file, which is allowed to import the client, saved as app/repositories/invoices.py:

File · inputs/repository_invoices.py
from app.db.client import get_connection

The third is any image, saved as app/static/logo.png.

The workflow starts on its own. We tested it by running the workflow's exact run: scripts against a local copy of that pull request, not on GitHub's runners.

Expected result

The memory check passes. The decision check prints one line per changed file, with the exit code mneme check returned for it, or skip for a binary file. The job itself exits with code 2:

Recorded output
exit=2  app/handlers/invoices.py
exit=0  app/repositories/invoices.py
skip    app/static/logo.png (binary)

The handler fails. The repository file passes, because ADR-012 applies only under app/handlers/. The image is skipped.

Evidence

Download the mneme-verdicts artifact from the workflow run. It holds one JSON verdict per changed file. The one for the handler names the decision, its rule (FORBID_LITERAL, a ban on exact text), the matched text and the path selector that made the rule apply:

Recorded output
{
    "schema": "mneme.check/v1",
    "verdict": "FAIL",
    "mode": "strict",
    "evaluation_complete": true,
    "applicability": [
        {
            "decision_id": "ADR-012",
            "rule_type": "FORBID_LITERAL",
            "rule_value": "from app.db.client import",
            "rule_index": 0,
            "path_scoped": true,
            "input_path": "app/handlers/invoices.py",
            "outcome": "APPLIED",
            "selector": "app/handlers/**",
            "reason": "an include selector matched",
            "rule_id": "ADR-012:FORBID_LITERAL:e7f58cdee4107aea2503f458432cbf7f",
            "decision_version_id": "dver-07b2d935ba6c357186624774df0c2845"
        }
    ],
    "violations": [
        {
            "decision_id": "ADR-012",
            "decision_text": "Request handlers do not import the database client",
            "severity": "FAIL",
            "rule": "from app.db.client import",
            "trigger": "from app.db.client import",
            "kind": "typed_rule",
            "rule_type": "FORBID_LITERAL",
            "input_path": "app/handlers/invoices.py",
            "selector": "app/handlers/**",
            "rule_id": "ADR-012:FORBID_LITERAL:e7f58cdee4107aea2503f458432cbf7f",
            "decision_version_id": "dver-07b2d935ba6c357186624774df0c2845"
        }
    ],
    "freshness": []
}

Trust a verdict only when evaluation_complete is true. An evaluation that can't complete reports INCOMPLETE and exits 2, so it fails the job instead of passing it.

Stop an agent from weakening the check

A required check only means something if the agent it judges can't quietly change the check after it fails. An agent may fix its code. It should not be able, on its own, to edit the ADR, rewrite the memory file, disable this workflow, or approve its own exception. Together those files are the check's governance surface.

GitHub documented this failure mode during its AI-assisted Copilot runtime migration: a compatibility check caught a missing SDK method, and the agent applied an escape-hatch label instead of restoring the method. Human review rejected the waiver and required the implementation to be fixed. GitHub's resulting lesson was to make sure the agent changing the code can't redefine correctness without oversight.

Put the governance surface behind separate ownership and approval:

  • Require the Mneme status check in the branch ruleset or branch protection rule, and restrict bypass permission.
  • Use .github/CODEOWNERS plus required code-owner review for authoritative ADRs, .mneme/project_memory.json, the Mneme workflow, exception configuration, and CODEOWNERS itself.
  • Dismiss stale approvals, or require approval of the most recent reviewable push, so an agent cannot add a governance change after approval.
  • Keep exception labels, baseline changes, and waiver decisions human-owned. A green check produced by weakening the contract is not evidence that the implementation complies.
  • Layer Mneme with independent tests and compatibility checks. One bypass should not be enough to ship a regression.

GitHub's documentation explains how to protect sensitive paths with code owners and how rulesets combine required reviews, required status checks, and bypass controls.

Troubleshooting

The memory check fails after an ADR edit

The ADR changed but the committed memory file didn't, so git diff --exit-code exits 1. Re-import locally and commit the result. If it fails on every pull request, check the ADRs’ line endings: the memory file records a hash of each ADR’s bytes, so add docs/adr/*.md text eol=lf to .gitattributes.

Command
mneme adr import docs/adr --memory .mneme/project_memory.json --apply --update-existing

The check step fails before checking any file

The step exits 2 when git diff can't compare against origin/$BASE_REF, usually because the checkout is shallow. Keep fetch-depth: 0 on the checkout step.

Every file passes, even one with the import

The --target-path flag is missing. Without it, Mneme can't tell which path-scoped rules apply. Turn an ADR into an enforceable decision shows the output.

You want to see findings without failing pull requests yet

Add --mode warn to the mneme check line. Mneme still prints every verdict, but exits 0 for WARN and FAIL. An INCOMPLETE evaluation still exits 2:

Command
mneme check --memory .mneme/project_memory.json \
  --input app/handlers/invoices.py --target-path app/handlers/invoices.py \
  --query "PR change: app/handlers/invoices.py" --mode warn
Recorded output
FAIL  [ADR-012] FORBID_LITERAL "from app.db.client import" -- trigger: from app.db.client import
      Request handlers do not import the database client
      path: app/handlers/invoices.py via app/handlers/**

PATH  APPLIED  [ADR-012] app/handlers/invoices.py via app/handlers/** -- an include selector matched

Result: FAIL

Remove the flag once the findings look right.

Limits

  • The check reads each changed file whole. A file that already broke ADR-012 before the pull request fails as soon as someone touches it.
  • Deleted files aren't checked, because there is nothing left to read.
  • The rule matches exact text. See Turn an ADR into an enforceable decision for the import forms it misses.
  • The workflow syntax is GitHub-only. The same loop runs in GitLab CI with $CI_MERGE_REQUEST_DIFF_BASE_SHA as the base; the GitLab page has that version.

Next