Skip to content

fix(git-sync): measure ahead_working against the agent's own branch (#2105) - #3025

Merged
vybe merged 3 commits into
devfrom
fix/2105-ahead-working-own-branch
Sep 25, 2026
Merged

vybe merged 3 commits into
devfrom
fix/2105-ahead-working-own-branch

Conversation

@dolho

@dolho dolho commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

_dual_ahead_behind_payload (agent server, docker/base-image/agent_server/routers/git.py) measured the working tuple against origin/<current_branch> only for trinity/* branches. Every other branch got the origin/main counts under the ahead_working / behind_working label. fleet_audit_service reads ahead_working as unpushed commits, so a fleet renamed to asus/* reported ~9,000 unpushed commits while the true gap was 0.

  • Fix: the working tuple is measured against origin/<current_branch> whatever the branch is named. The prefix gate is gone.
  • No upstream (a branch that was never pushed, or a detached HEAD): ahead_working counts the commits that no remote holds (rev-list HEAD --not --remotes), and behind_working is null. A detached HEAD is never compared with origin/HEAD, because that is the default branch, not the agent's.
  • Unknown means null, never 0. This is the second field report on the issue: a master repo with no main read 0 ahead for 7 days while one commit sat unpushed. Now the working tuple reports 1, and the main tuple (plus the legacy ahead / behind aliases) is null rather than a believable 0. Consumers are already null-safe: sync_health_service._coerce_counter stores null as 0, and the UI checks > 0 or || 0.
  • _compute_ahead_behind (the conflict classifier's best-effort (0, 0)) is unchanged.

This unblocks the numbers that trinity-enterprise#706 (divergence age) and #707 (sync surfaces) key on.

Tests

Notes

Fixes #2105

🤖 Generated with Claude Code

dolho and others added 3 commits September 25, 2026 16:53
…2105)

`_dual_ahead_behind_payload` measured the working tuple against
`origin/<current_branch>` only for `trinity/*` branches. Every other branch
got the `origin/main` counts under the working label. The fleet audit reads
`ahead_working` as unpushed commits, so a fleet renamed to `asus/*` reported
~9,000 unpushed commits while the true gap was 0.

- The working tuple uses `origin/<current_branch>` whatever the branch is
  named.
- With no upstream (never pushed, detached HEAD), `ahead_working` counts the
  commits no remote holds, and `behind_working` is null.
- A count that can't be computed is null, never 0. This covers the main tuple
  on a `master` repo with no `main`, which read 0 ahead for 7 days while one
  commit sat unpushed. The backend already stores null as 0, and the UI
  checks `> 0`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…mechanical, per the merge-train note on the PR

`ahead` aliases the main tuple, which this PR makes None on a repo with no
`main`; `None == 0` is false, so a clean `master` repo flipped from
"Synced" to "Changes pending". Restores dev's behaviour on that line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@vybe

vybe commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

merge-train: pushed two commits to this branch (mechanical, no change to the fix's intent):

  1. Merged dev (picks up fix(ci): cap test SQLAlchemy below 2.1 — pg-migrations broke on the new default driver #3015's SQLAlchemy cap).
  2. docker/base-image/agent_server/routers/git.py status route: sync_status now reads (ahead or 0) == 0. ahead aliases the main tuple, which this PR makes None on a repo with no main; None == 0 is false, so a clean, fully pushed master repo flipped from "Synced" to "Changes pending" in GitPanel.vue. This restores dev's behaviour on that one line.

Follow-up for you, not a blocker: should sync_status be derived from the working tuple instead of the main alias? That's a design call, so I left it. Also noted by validation: the detached-HEAD branch of _dual_ahead_behind_payload has no test.

Riding the current merge train.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20260925-1608 (#3027, full suite green).

@vybe
vybe merged commit a07561e into dev Sep 25, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants