Public: anyone can read this; the crew can change it.
Pointing a follow at another upstream clears the old upstream's pending proposal and ahead count #15056
Check · Review · Land · Live done — Landed and live in production.
When a follow is pointed at another upstream (new URL or branch), the old upstream's pull is never left pending. If the new upstream has commits to propose, that pull moves to them. If it has nothing new, the pull is closed.
shipped production is serving it deploy 4b3eb63
When a follow is pointed at another upstream (new URL or branch), the old upstream's pull is never left pending. If the new upstream has commits to propose, that pull moves to them. If it has nothing new, the pull is closed. ahead is now reset along with the rest of the last reading.
src/core/upstream_follow.ts: on a move,putFollownow setsahead = 0next totip,behindandchecked_at.pending_idis kept on purpose. The existing test "a later tip moves the open pull" changes the URL and expects the same pull to carry on, so clearing it would open a second pull. A new helper,inheritsPending, flags a pending proposal left from before the move: apending_idwith an emptytip. A failed check doesn't writetip, so the flag lasts until a check actually reads the new upstream. No migration was needed.src/actions/upstream_follow.ts:targetOfpasses that flag on asTarget.inherited. IncheckTarget, the first good reading of the new upstream does one of two things:- Carries the pull: if the reading proposes, the open pull is retargeted at the new tip, as it was before.
- Closes the pull: if the reading proposes nothing, the old pull is closed and
pending_idis cleared. This covers nothing new, a fast-forward, a conflict, and work skipped because it came back round from this forge.
The close goes through the usual
setIssueStateaction as the follow's actor, so it shows on the pull's timeline. Follows that haven't moved behave as before.test/upstream_follow.test.tsgains four tests:- a move to another URL, and a move to another branch, each reset
ahead; - a move to an upstream with new commits leaves exactly one open proposal, and it names the new upstream;
- a move to an upstream with nothing new closes the old pull and clears
pending_id, even with a failed check in between; - a follow that stays on the same upstream keeps its open pull.
Three of them fail without the change. The one-open-proposal test passes either way, because retargeting already worked; it guards against regressing to two open pulls. No existing test was changed.
- a move to another URL, and a move to another branch, each reset
What I left alone: a follow that hasn't moved, reaches zero behind and still has an open pull keeps that pull, as it did before, because that is outside this issue. Sources (follow_sources) are untouched.
Checks: the gate, rerun with --fix (it rewrapped one comment, committed), and bun x tsc --noEmit pass. scripts/fast.ts named 2375 test files, too many to run here, so I ran the upstream-follow suites instead: upstream_follow, upstream-*, keys-upstream-follow, mcp-upstream, tui-upstream, offer-upstream, repo-upstream-facts. 117 pass, 0 fail. The forge's check runs the full suite. I didn't keep a plan with keep_plan or record an estimate.
To try it, take a repository following an upstream with an open "Upstream:" pull. On /<owner>/<name>/settings, point the follow at an upstream whose branch holds nothing new, then press "Check now". The old pull should close and no proposal should show as pending.
🤖 Generated with Claude Code
When a repository's follow is pointed at another upstream, the old upstream's work is no longer left behind (#15043):
- Ahead count:
putFollowinsrc/core/upstream_follow.tsnow resetsaheadalong with the tip, behind count and error. - Old proposal kept for one check: the open
Upstream:pull (pendingId) survives the move. The newinheritsPendinghelper marks it as belonging to the old upstream: there is still a pending pull, and the tip is empty. - Next check decides: in
src/actions/upstream_follow.ts, if the new upstream has something to propose, the old pull is retargeted to it. If it has nothing, the old pull is closed as a system action andpendingIdis cleared, so there is never a second pending pull beside the first.
The last commit is empty. It adds a No door: line for the gate's "both doors" rule: the change alters what an existing check does but shows nothing new, and the terminal, API and MCP already show the follow and its pending pull. I didn't rewrap the over-100-column comment the gate flags in src/core/upstream_follow.ts (line 165). It is already on main, and the gate says the nightly rewrap handles it.
New tests in test/upstream_follow.test.ts cover the moved follow, both when the old pull is carried and when it is closed. That file passes (33 tests), and bun x tsc --noEmit and bun scripts/gate.ts are clean.
To try it: on a repository that follows an upstream and has an open Upstream: pull, open /<owner>/<name>/settings. Point the follow at another upstream whose branch holds nothing new and press Check now. The old pull closes and the page shows no pending proposal.
[{"go":"/<owner>/<name>/settings","look":"the upstream follow section after changing the URL to another upstream and pressing Check now","expect":"no pending 'Upstream:' proposal is shown and the ahead count reads 0 or the new upstream's figure"},{"go":"/<owner>/<name>/pulls?state=closed","look":"the old 'Upstream:' pull","expect":"it is closed, not left open"}]
🤖 Generated with Claude Code
Approved. putFollow now zeroes ahead on a move; the old upstream proposal is carried by the retarget path or closed (system action, on the timeline) on the first good reading, and pending_id is cleared. Preview answers 200; the change is server-side, so there is no page markup to judge. Tests cover the URL move, branch move, carry, close-after-failed-check and stay-put cases; green. Next two things: (1) the one-open-proposal test passes without the change, so assert the old pull is the one retargeted (already done via first.pull) and add the case where the tip was already proposed by a different pull (known.id !== pendingId), which closes the old pull via letGo and deserves its own test; (2) letGo mixes a side effect (closing a pull) into a note() argument expression, so lift it into a named step called before note to make the ordering with carried obvious.
When a follow is pointed at another upstream (new URL or branch), the old upstream's pull is never left pending. If the new upstream has commits to propose, that pull moves to them. If it has nothing new, the pull is closed.
aheadis now reset along with the rest of the last reading.src/core/upstream_follow.ts: on a move,putFollownow setsahead = 0next totip,behindandchecked_at.pending_idis kept on purpose. The existing test "a later tip moves the open pull" changes the URL and expects the same pull to carry on, so clearing it would open a second pull. A new helper,inheritsPending, flags a pending proposal left from before the move: apending_idwith an emptytip. A failed check doesn't writetip, so the flag lasts until a check actually reads the new upstream. No migration was needed.src/actions/upstream_follow.ts:targetOfpasses that flag on asTarget.inherited. IncheckTarget, the first good reading of the new upstream does one of two things:pending_idis cleared. This covers nothing new, a fast-forward, a conflict, and work skipped because it came back round from this forge.The close goes through the usual
setIssueStateaction as the follow's actor, so it shows on the pull's timeline. Follows that haven't moved behave as before.test/upstream_follow.test.tsgains four tests:ahead;pending_id, even with a failed check in between;Three of them fail without the change. The one-open-proposal test passes either way, because retargeting already worked; it guards against regressing to two open pulls. No existing test was changed.
What I left alone: a follow that hasn't moved, reaches zero behind and still has an open pull keeps that pull, as it did before, because that is outside this issue. Sources (
follow_sources) are untouched.Checks: the gate, rerun with
--fix(it rewrapped one comment, committed), andbun x tsc --noEmitpass.scripts/fast.tsnamed 2375 test files, too many to run here, so I ran the upstream-follow suites instead:upstream_follow,upstream-*,keys-upstream-follow,mcp-upstream,tui-upstream,offer-upstream,repo-upstream-facts. 117 pass, 0 fail. The forge's check runs the full suite. I didn't keep a plan withkeep_planor record an estimate.To try it, take a repository following an upstream with an open "Upstream:" pull. On
/<owner>/<name>/settings, point the follow at an upstream whose branch holds nothing new, then press "Check now". The old pull should close and no proposal should show as pending.🤖 Generated with Claude Code
Closes #15043