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:
- 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, oradmincollaborator permission) within the standard size limits ($\le 10$ files, $\le 500$ changed lines) onceRequired CIpasses on the current head. Bot, fork, non-collaborator, and oversized documentation PRs require a maintainer-appliedautomergelabel (failing closed if permission lookup fails). - Code and tests: auto-merge only with the
automergelabel applied by a maintainer (a person with write access, not a bot), within the size limits, withRequired CIgreen. Tests stay here rather than with docs, because a bot that deletes or weakens a failing test would otherwise merge unreviewed. - Protected paths: never auto-merged without owner review; the owner must approve. These are
.github/,mkdocs.yml(moved out of tier 1 becausemkdocs buildresolves PyYAML tags, withscripts/generate_docs.pyrejecting any tag outside the allowlistedpymdownx.superfences.fence_code_formattag beforemkdocs build),.pre-commit-config.yaml,.claude/,.agents/,AGENTS.md,CLAUDE.md,.gitattributes,offline_bundle/requirements.txt(derived fromuv.lockat 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.pyandquarantine_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 whetherdb*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_PATHSandCODEOWNERStogether, which the test enforces, whilescripts/generate_docs.py --checkenforces themkdocs.ymlYAML tag allowlist locally and in CI beforemkdocs build. .github/workflows/classify-pr.ymlfilterspull_request_targettomain, checks outrefs/heads/mainwith job-scoped write permissions, verifies maintainer-appliedautomergelabels, evaluates lockfile diffs and signed Dependabot metadata viascripts/classify_pr.py, and separates unreviewedautomerge:eligible('Eligible for auto-merge') from@fderuiter-approved Tier 3 queue eligibilityautomerge:approved('Approved for serialized merge (<risk>)') and'Human review required (<risk>)'. Its labels and status remain a pre-filter:scripts/auto_merge_controller.pyre-runs the same classifier on live API metadata (including@fderuiterreview approval on the current head SHA) before updating or merging and replaces stale labels withautomerge:blockedif a candidate no longer qualifies.- Branch protection must require code-owner review with zero
bypass_actorsfor this to hold when someone merges by hand..github/rulesets/main.jsonpins"bypass_actors": []and"do_not_enforce_on_create": false, andscripts/validate_ruleset.pyverifies both the tracked JSON inStatic Checks(--check) and live repository enforcement (--live).