agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

sessions.branch is never reconciled with the branch the session actually pushed (18 of 21 session-to-PR pairs disagree)

Open louiemenard opened this issue 3 months ago • 3 comments

This was generated by AI during triage. Measured against AO v0.12.10 on 2026-09-04, across three separate AO instances (a Linux VM install, a macOS host install, and an OrbStack VM install). Repository names and URLs are withheld because the repositories are private; everything below is product-level state.

sessions.branch is never reconciled with the branch the session actually pushed

AO sets sessions.branch to the branch it creates with the worktree — ao/<session-id>/root. When the worker then does git checkout -b <name>, commits, pushes and opens a pull request, sessions.branch is never updated.

AO does learn the real head: it lands in pr.source_branch on the row AO's own poller writes, in the same database. The two fields then disagree, and the one the session view shows is the wrong one.

Measured

Joining sessions to pr on session_id, per instance:

Instance Pairs Disagree
Linux VM 4 3
OrbStack VM 17 15
macOS host sampled disagrees on the sampled session

18 of 21 session-to-PR pairs disagree, across two repositories and both the claude-code and codex harnesses.

Representative rows:

session=A-4    sessions.branch=ao/A-4/root    pr.source_branch=ao/A-4/range-span
session=A-15   sessions.branch=ao/A-15/root   pr.source_branch=ao/A-15/geometric-mean
session=A-16   sessions.branch=ao/A-16/root   pr.source_branch=ao/A-16/geometric-mean
session=B-1    sessions.branch=ao/B-1/root    pr.source_branch=ao/B-1/gui-save-settings-finding
session=B-8    sessions.branch=ao/B-8/root    pr.source_branch=ao/B-8/urgent-intake

The API surfaces the stale value directly. GET /api/v1/sessions/<id> for a session whose pull request is open and mergeable:

{
  "id": "A-16",
  "status": "mergeable",
  "branch": "ao/A-16/root",
  "prs": [
    { "number": 14, "state": "open", "ci": "passing", "mergeability": "mergeable" }
  ]
}

branch says ao/A-16/root. That branch holds none of the work. The commits are on ao/A-16/geometric-mean, which is in the same response's prs[0] and in pr.source_branch.

Not always

Two of the 21 agree, so the field is not inert — some path does set it. On the agreeing rows the recorded branch is the pushed one. Whatever writes it did not run for the other nineteen. I did not identify which path that is.

Why it matters

branch is what a person reads to go and find a session's work. For 18 of 21 sessions it names an empty branch while the same record already holds the right one. It is also the field most likely to be used to reconcile a session against a remote, so a consumer that trusts it will look at the wrong ref and conclude the session produced nothing.

Suggested fix

Reconcile sessions.branch from the observed head when the SCM poller writes a pr row for the session — the value is already in hand at that moment. Failing that, have the session API return the head from pr.source_branch when one exists, so the two surfaces cannot disagree.

Verified read-only

Every measurement was a GET or a query against a copy of the database. No AO state was mutated.

louiemenard avatar Sep 04 '26 10:09 louiemenard

I'd like to work on this

ousamabenyounes avatar Sep 10 '26 00:09 ousamabenyounes

I'm stepping back for now because the repository requires assignment before implementation. Please leave this available for another contributor.

ousamabenyounes avatar Sep 10 '26 00:09 ousamabenyounes

Assigned to @MohitGoyal09

Rishet11 avatar Sep 15 '26 19:09 Rishet11