Skip to content

Agent PRs branch off stale main → squash-merge silently reverts intervening work #516

Description

@samxu01

Surfaced: 2026-06-29. Agent-authored PR #503 (by Cody/cloud-codex) was cut from a stale main — Cody cloned the repo when main was at 7c4b6230, then PRs #506 and #507 merged, but Cody's branch never updated. When the PR was squash-merged, the squash overwrote main's tree with the stale branch tree, silently reverting #506 + #507 (the landing real-work screenshots + positioning, and a set of docs). GitHub's PR diff looked clean because it's computed against the merge-base, so the regression wasn't visible in review. Fixed by reverting (#515).

Two distinct gaps:

  1. Agent branching hygiene. Cody (and any agent that clones once and works for a while) opens PRs from a base that drifts behind main. Agents should git fetch origin && git rebase origin/main (or branch fresh off origin/main) before committing/pushing a PR, and re-sync before any follow-up push. The cloud-codex run wrapper could enforce/automate this. Relatedly, a fresh codex session doesn't know the repo path and clones a fresh stale copy each time (see cloud-codex: iterative follow-up tasks don't reliably commit/push #512).

  2. Merge technique. The squash-merge used git reset --soft origin/main && git commit from the PR branch. That technique is only safe when the branch's merge-base is origin/main; for a stale-based branch it overwrites main with the branch tree and reverts everything in between, with no conflict to warn you. Safe merges must rebase the branch onto current origin/main first (which surfaces conflicts), or use a real merge — never a blind tree-overwrite squash. Worth a documented merge runbook + a guard (refuse to squash if merge-base(branch, origin/main) != origin/main).

Why it matters: silent reversion of merged work is the worst kind of regression — invisible in review, only caught by a human noticing their work vanished.

Direction: (a) make agents rebase-before-PR (wrapper-enforced); (b) document the safe squash-merge procedure + add a stale-base guard; (c) consider branch-protection "require branch up to date before merge."

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-taskCan be worked on by dev agentsbugSomething isn't workingdevops

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions