- Book: Ship It — the pragmatic startup tech stack
- Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go
- My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
- Me: xgabriel.com | GitHub
Two Alembic migration files with the same down_revision merged into main without a conflict, and your next deploy stopped here:
$ alembic upgrade head
FAILED: Multiple head revisions are present for given argument
'head'; please specify a specific target revision,
'<branchname>@head' to narrow to a specific head, or 'heads' for
all heads
That wording comes from Alembic's docs on branches, wrapped to fit here. Claude Code wrote one file and Codex wrote the other, each in its own git worktree on its own branch. Neither agent wrote a bad migration, and git merged exactly what you asked it to merge. Git and Alembic disagree about what those two new files mean.
The repair is one command. The harder part is the check that should stop it coming back, because it passes on every task branch until you run it against main.
Why git waves this through
Alembic keeps history as a graph. Every migration file names its parent in down_revision, and a branch is two or more revisions sharing one parent. When two agents start from the same commit and each runs alembic revision, both new files point at the same parent.
Git sees two new files with different names, so it has nothing to conflict on. Alembic sees two leaves, and head no longer points at one thing. The docs use this same shape as their example: ae1027a6acf and 27c6a30d7c24 both descend from 1975ea83b712.

Two migrations, one parent: git merges both files and Alembic is left with two heads.
The failure spreads past the deploy. While the fork exists, alembic revision raises its own error: "Multiple heads are present; please specify the head revision on which the new revision should be based, or perform a merge." The next agent that needs a migration on main hits the same wall.
This predates coding agents. OpenStack Magnum's troubleshooting guide describes it for human developers: a local migration and one already merged both revise the same head. Parallel agents raise the odds, because starting several branches from one commit is how you run them.
Reproduce it on a throwaway repo
You need git, Python 3 and a shell. The current Alembic is 1.20.1, released October 22, 2026.
mkdir heads-demo && cd heads-demo
git init -b main
python3 -m venv .venv && . .venv/bin/activate
echo alembic > requirements.txt
pip install -r requirements.txt
printf '.venv/\n*.db\n__pycache__/\n' > .gitignore
alembic init alembic
url='sqlalchemy.url = sqlite:///demo.db'
sed -i.bak "s#^sqlalchemy.url.*#$url#" alembic.ini
rm alembic.ini.bak
alembic revision -m "create users"
alembic upgrade head
git add . && git commit -m "base revision"
The migration bodies can stay empty. The graph depends only on revision and down_revision, and the tutorial covers what each generated file holds.
Now play both agents. Two worktrees from one commit, one migration each. The activated venv stays on your PATH inside those subshells:
git worktree add -b hermes/add-phone ../add-phone
git worktree add -b hermes/add-status ../add-status
(cd ../add-phone && alembic revision -m "add phone" \
&& git add alembic && git commit -m "add phone")
(cd ../add-status && alembic revision -m "add status" \
&& git add alembic && git commit -m "add status")
git merge --no-edit hermes/add-phone
git merge --no-edit hermes/add-status
alembic heads
alembic upgrade head
Both merges go through. alembic heads then lists one revision per line. Shown here with the docs' example hashes; yours will differ, and the docs print these with and without a (head) marker:
$ alembic heads
27c6a30d7c24 (head)
ae1027a6acf (head)
alembic upgrade head fails with the error from the top of this post. Those strings are the ones Alembic documents. I haven't run this exact sequence myself, so compare them with your terminal.
Fix it with alembic heads and alembic merge
A merge revision is a new migration whose job is to join the heads:
alembic merge -m "merge add-phone and add-status" heads
alembic heads
alembic upgrade head
git add alembic && git commit -m "merge alembic heads"
Passing heads means merge all of them. The generated file has a tuple for its parents, as in the docs' example:
down_revision = ('ae1027a6acf', '27c6a30d7c24')
After that, alembic heads shows one revision and the upgrade runs. Alembic applies migrations in topological order, and a merge point can't be crossed until everything it depends on has been applied, so a database that had already run one side still gets the other.
Before you run it, three things to know:
- It doesn't check that the two migrations agree. Two agents can add a column with the same name and the graph is still valid, and you find out when the database rejects the upgrade. Julien Danjou's post on this problem draws the same line between ordering and semantic conflicts, so read both migrations before you join them.
-
alembic upgrade headsis a workaround. It targets all heads at once, which gets the deploy past the error and leaves the fork in the graph. - If one branch hasn't landed yet, a merge file is more than you need. Point its
down_revisionat the other migration, which is Magnum's documented fix, and the history stays linear. Keep that for a migration no shared database has applied.
The one-line check, and its blind spot
heads=$(alembic heads) && test "$(echo "$heads" | grep -c .)" -eq 1
alembic heads reads the script directory and prints each head. It doesn't run env.py, so the job needs no database. If Alembic exits non-zero, the && stops there and the step fails. Counting lines alone would miss that, because Alembic prints its FAILED: errors to stdout.
In GitHub Actions:
name: migrations
on:
pull_request:
merge_group:
jobs:
single-head:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: pip install -r requirements.txt
- run: |
heads=$(alembic heads)
test "$(echo "$heads" | grep -c .)" -eq 1
A task branch on its own has one head. hermes/add-status has never heard of add-phone, so the check passes there every time. The check only works when it runs against the merged result.
On pull_request, GitHub's GITHUB_SHA is the merge commit on the merge branch, so a PR opened after the other one landed goes red. Two PRs open at the same time can both go green against the old main, though, and once one merges, the other's green is stale.
Close that gap with Require branches to be up to date before merging, or with a merge queue, which gives the same protection without authors updating by hand. A merge queue needs the merge_group trigger in the workflow above, or your required checks won't run when a PR joins the queue.
Run a stricter check before Land in Hermes
I build Hermes IDE, so weigh this section with that in mind. Hermes starts each task on its own hermes/<name> branch in its own worktree, with the task as the agent's first prompt. That isolation is why the one-liner proves nothing there. So count heads with main's migrations laid over the worktree's:
#!/bin/sh
# scripts/check-heads.sh
# Counts Alembic heads for this tree plus main's migrations.
set -eu
cd "$(git rev-parse --show-toplevel)"
base="${BASE_BRANCH:-main}"
git rev-parse --verify "$base" >/dev/null
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
cp alembic.ini "$tmp/"
cp -R alembic "$tmp/alembic"
git archive "$base" alembic/versions | tar -x -C "$tmp"
cd "$tmp"
heads=$(alembic heads) || {
echo "$heads" >&2
exit 1
}
count=$(echo "$heads" | grep -c . || true)
if [ "$count" -ne 1 ]; then
echo "expected 1 Alembic head with $base, got $count" >&2
exit 1
fi
It copies the worktree's alembic/ folder, so an uncommitted migration counts, then extracts main's versions on top with git archive. Worktrees share refs, so main is up to date the moment another task lands locally. If you land through pull requests, run git fetch origin main first and set BASE_BRANCH=origin/main.
The script is for macOS and Linux. It assumes alembic/ at the repo root and an activated venv with alembic installed. If your migrations import app code, install the app in that venv, or Alembic exits with an error and the check fails.
Run it from inside the task's worktree. From your main checkout it lays main over main and always counts one. Commit the script to main before you start, so every task branch has it. Hermes lets your own checks decide when a task is done, and this is one to run before you Land.
Use a real project for the next part, or a fresh copy of the demo whose create users migration really creates the table. Press ⌘N (Ctrl+Shift+N on Windows and Linux) and give Claude Code the first task: "Add a nullable phone column to users with an Alembic migration." Press ⌘N again and give Codex the second: "Add a status column to users with an Alembic migration."

The ⌘N New task sheet: agent, project, a new hermes/ worktree, approval mode, model and effort, with a preview of the command Hermes will run.
Let both agents finish and land the first task. Then ask the second agent, in its own terminal, to run the check in its worktree:
Create .venv if it is missing, install requirements.txt,
activate it, and run sh scripts/check-heads.sh. Show me the output.
The script counts add-phone from main and add-status from the worktree, finds two heads and exits 1. Send the agent back to fix it:
The Alembic head check failed against main. Merge main into
this branch, point this migration's down_revision at the head
from main, and run sh scripts/check-heads.sh again.
Then read both migrations together. ⌘G (Ctrl+Shift+G) opens the Review Desk, which shows changes by turn or by file. A green check tells you the graph has one head and says nothing about two agents picking the same column name.

The Review Desk (⌘G) in By turn view: two turns with their file counts, one turn's diff, the changed files and a commit message drafted from the turns.
The check is your script. Whether you land after it goes red is your call. Land commits, opens a pull request or merges locally into the branch the task started from, and it can be undone.
If this was useful
A migration graph that breaks after a clean merge is the kind of bug that lives between your laptop and production. Ship It is about that stretch for a small team: hosting, payments, auth, CI/CD and monitoring, so checks like this one have a pipeline to live in. Hermes IDE is free to download, source-available under BSL 1.1, runs on macOS, Windows and Linux, and isn't affiliated with Nous Research, Anthropic, OpenAI or any agent vendor: download it or read the source.

Top comments (1)
When check-heads.sh catches two heads before landing, does Hermes run the repoint step automatically from the task rule or do you still paste that follow-up prompt into the second agent's terminal by hand?