Skip to content

Auto-merge decides by path tier, and data-safety code always needs a human

Bots write most of Sortify's changes, and scripts/auto_merge_controller.py merges the ones scripts/classify_pr.py calls low-risk. Every changed path falls into one of three tiers, and the PR takes the strictest tier any of its files hits:

  1. Docs (docs/, README.md): auto-merge without a label only when opened from an in-repository branch by a non-bot human maintainer (write, maintain, or admin collaborator permission) within the standard size limits ($\le 10$ files, $\le 500$ changed lines) once Required CI passes on the current head. Bot, fork, non-collaborator, and oversized documentation PRs require a maintainer-applied automerge label (failing closed if permission lookup fails).
  2. Code and tests: auto-merge only with the automerge label applied by a maintainer (a person with write access, not a bot), within the size limits, with Required CI green. Tests stay here rather than with docs, because a bot that deletes or weakens a failing test would otherwise merge unreviewed.
  3. Protected paths: never auto-merged without owner review; the owner must approve. These are .github/, mkdocs.yml (moved out of tier 1 because mkdocs build resolves PyYAML tags, with scripts/generate_docs.py rejecting any tag outside the allowlisted pymdownx.superfences.fence_code_format tag before mkdocs build), .pre-commit-config.yaml, .claude/, .agents/, AGENTS.md, CLAUDE.md, .gitattributes, offline_bundle/requirements.txt (derived from uv.lock at bundle build time and untracked in Git, kept here so accidental re-addition fails closed), SECURITY.md, PRIVACY.md, app/config.py, app/core/crypto.py, scripts/, smart-autosorter.spec, network_rules.json, .gitleaks.toml, dependency manifests outside Dependabot (pyproject.toml, uv.lock), every module that can lose a user's file (app/core/mover.py, resilient_file_ops.py, ledger.py, history.py, session.py, db.py, db_conn.py, db_worker.py and quarantine_interceptor.py), and snapshot and type-check baselines (tests/snapshots/api/, tests/snapshots/tui_svg/, tests/ty_baseline.json).

PROTECTED_PATHS in scripts/classify_pr.py is the one list of protected paths, written in CODEOWNERS syntax. .github/CODEOWNERS has to list every entry, and tests/test_risk_classifier.py fails when the two disagree, so GitHub's code-owner review and the controller enforce the same boundary. Dependabot updates (single-package PRs and grouped python-minor-patch or python-zero-major-patch PRs from .github/dependabot.yml) classify as minor only when verified merge-base uv.lock diffs and/or signed Dependabot updated-dependencies commit trailers and update summaries confirm every package bump is a non-0.x minor or patch; any new first version component, any new second component under 0.x (semver treats 0.x minors as breaking), downgrade, local-version tag change, or missing version metadata counts as major (falling back to single-package from A to B title parsing only when neither lockfile diffs nor Dependabot metadata are present). Only the exact dependabot[bot] login counts as Dependabot; a dependencies label does not.

We chose this because the gate today leaves the code that matters most open. The classifier protects mover.py, history.py and session.py, but not resilient_file_ops.py, ledger.py or the db* modules, which is where the move and undo bugs fixed in #757 to #768 lived. CODEOWNERS and SENSITIVE_PATHS are separate lists that already differ (CODEOWNERS lacks scripts/ and the spec file). The automerge opt-in is a label the PR's own author can add. And "major" dependency bumps are detected by searching the PR title for "major" or "breaking", which Dependabot titles don't contain.

Considered options

  • Turn auto-merge off. Safest, but the owner merges in bulk today and the bots open about 15 PRs a day; without a gate, the review load lands on one person and gets skipped.
  • Require human review on everything except docs. Simple, but it sends routine UI and test changes to the same queue as mover changes, so the queue stops being read.
  • Gate on test coverage of the changed lines instead of paths. Better in principle, but the coverage gate is a no-op today (#738), and coverage doesn't show whether a test would catch data loss.

Consequences

  • PRs touching the protected data-safety modules wait for the owner even when CI is green. That is the intent until the property test from the system design (random plans against a folder of unrelated and hidden files, killed at random points, then reconciled and undone, with every original file byte-identical) runs in Required CI. After that, revisit whether db* can drop to tier 2.
  • The label check costs two API calls per labelled PR (issue events, then the labeller's permission) and unlabelled in-repository human docs PRs check the author's collaborator permission; both checks fail closed on API errors.
  • Adding a protected path means editing PROTECTED_PATHS and CODEOWNERS together, which the test enforces, while scripts/generate_docs.py --check enforces the mkdocs.yml YAML tag allowlist locally and in CI before mkdocs build.
  • .github/workflows/classify-pr.yml filters pull_request_target to main, checks out refs/heads/main with job-scoped write permissions, verifies maintainer-applied automerge labels, evaluates lockfile diffs and signed Dependabot metadata via scripts/classify_pr.py, and separates unreviewed automerge:eligible ('Eligible for auto-merge') from @fderuiter-approved Tier 3 queue eligibility automerge:approved ('Approved for serialized merge (<risk>)') and 'Human review required (<risk>)'. Its labels and status remain a pre-filter: scripts/auto_merge_controller.py re-runs the same classifier on live API metadata (including @fderuiter review approval on the current head SHA) before updating or merging and replaces stale labels with automerge:blocked if a candidate no longer qualifies.
  • Branch protection must require code-owner review with zero bypass_actors for this to hold when someone merges by hand. .github/rulesets/main.json pins "bypass_actors": [] and "do_not_enforce_on_create": false, and scripts/validate_ruleset.py verifies both the tracked JSON in Static Checks (--check) and live repository enforcement (--live).