Git safety
Patchmill fetches origin before deriving the phase. Ungated documents share
the implementation branch and worktree. Required spec and plan gates use
separate workspaces. A matching remote branch is reused. With no branch, the
worktree starts from the base branch. Several implementation branches stop the
attempt with needs-info rather than selecting one.
git.baseBranch: null uses the remote default branch. Set a string to choose
another target branch. Branch names use agent/issue-N-<slug>, with at most 48
slug characters. Worktree names replace branch slashes with hyphens. The kernel
removes issue worktrees and local branches only after fresh host facts prove an
implementation merge into the base and issue closure. Every real run sweeps
local candidates before selection, including non-interactive runs. A confirmed
interactive merge also cleans up immediately. Dry runs never clean up.
An unattended run without --issue also checks for merge conflicts before
selection. It runs git merge-tree --write-tree on the fetched base and issue
branches, which changes no working tree, index, or ref. This needs Git 2.38 or
later. An agent resolves a conflict with a merge of the base, never a rebase or
force push. After the session, Patchmill checks that the pushed branch merges
cleanly and still contains its previous head and the base commit. If it does
not, the issue stops with Needs Info.
The optional cleanupHook runs from the implementation worktree with Bash
before any removal. After hook success, Patchmill keeps each dirty worktree and
its branch. Hook failure keeps every target without changing done status.
Cleanup holds the issue OS lock, preserves mismatched checkouts, and never
removes remote branches. It also preserves the primary checkout, current
directory, and lock parent, including through symlinks. A target containing
another registered checkout stays too, even when Git ignores that nested
directory.
Ownership
Section titled “Ownership”An OS-managed advisory lock prevents cooperating processes in one clone from owning the same issue. This assumes a local filesystem with working advisory locks. The kernel retains the handle through agent work, resource cleanup, worktree removal, and label cleanup. Across clones, the ready-to-in-progress label swap has a narrow accepted race. Do not treat it as a distributed lock.
The permanent <runsDir>/issue-N/lock file must keep its inode, the filesystem
object behind its path. Never remove or replace the file or its parent
directory. This rule applies after release and crash recovery too. The PID and
start time are diagnostic only. Neither their presence nor absence proves
ownership. The OS releases the lock when the handle closes or owner exits.
After a hard crash, patchmill release --issue N acquires the same lock before
resetting in-progress to agent-ready. Contention refuses the operation
without changing host labels. Label reset is not a lasting cleanup lock.
Publication and branch protection
Section titled “Publication and branch protection”The skills tell agents to commit and push the issue branch, never push the base branch, and never force-push. Shell access cannot enforce those instructions. Direct landing is a host control, not a Patchmill feature. Use branch protection on the host to prevent direct base-branch pushes.
Implementation success requires an open, non-draft pull request with the issue
branch as head and a body that closes the issue. The kernel then sets
agent-done. It does not wait for merge. Uncommitted changes or unpushed
commits produce warnings rather than invalidating a real ready pull request.
Operator safety
Section titled “Operator safety”For independent concurrent issues, allocate separate ports, databases, and external services. Do not change shared configuration or Git state during active attempts. Keep logs and sessions local because they can contain secrets.
Use the human-controlled patchmill-cleanup skill for manual worktree removal.
It inspects implementation and optional gated planning workspaces and offers the
configured hook first. Require explicit loss confirmation and the same OS lock
throughout the hook and removal. Never use file removal or diagnostic PID checks
as lock recovery.
Keep <runsDir>/issue-N/cleanup.json and cleanup.log with run artifacts. The
receipt prevents repeated successful hooks during partial cleanup retries. A
corrupt receipt or missing hook directory requires inspection, not automatic
receipt removal. See Run-once for failure recovery
and safe hook-script guidance.