Skip to content

Bug: detectPR fails when agent renames branch after spawn #368

@sigvardt

Description

@sigvardt

Description

When an agent is spawned via ao spawn, ao creates a worktree with a branch name like feat/issue-2 and stores it in session metadata. However, coding agents (Codex, Claude Code) often rename the branch before pushing (e.g. feat/2, feat/1-followup-after-acceptance).

The detectPR method in scm-github searches by --head session.branch, which uses the original branch name from metadata. Since the PR was opened on the renamed branch, the lookup returns nothing. This means:

  1. Session status never transitions from working to pr_open
  2. No webhook notifications fire for PR events
  3. CI status, review state, and merge detection all break

Reproduction

  1. ao spawn project 2 (creates branch feat/issue-2)
  2. Agent renames branch to feat/2 and pushes
  3. Agent opens PR from feat/2
  4. ao status shows PR=--, CI=--, status=working indefinitely
  5. No webhook events fire

Suggested Fix

Option A (recommended): On each lifecycle poll, re-detect the actual branch from the git worktree (git -C <worktree> branch --show-current) and update session metadata if it changed.

Option B: Lock the branch name so agents can't rename it (less robust, agents may still force-push to new branches).

Impact

All webhook-driven automation (notifications, CI self-healing, review routing) is silently broken when agents rename branches. This is the default behavior for Codex agents.

Workaround

Manually patch session metadata files in ~/.agent-orchestrator/*/sessions/ to match actual branch names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions