Repository navigation
fix(host-service): solve #5596 — stop attaching stale/wrong PRs to the sidebar - #5619
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you:
Chapters generated by Stage for commit eab4ae8 on Jul 11, 2026 10:45pm UTC. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two related PR-attachment bugs surfaced by the July 2026 GitHub/PR stale-issue tracker (#5596): the default branch showing a spurious closed-PR icon, and a branch with multiple PRs showing the wrong (closed) one.
Bug 1 — default branch shows a stale closed/merged PR (#4508, #4260, #4513 item 1)
Root cause. In v2, PR→workspace linking lives in
PullRequestRuntimeManager(packages/host-service/src/runtime/pull-requests/pull-requests.ts).performProjectRefreshlooks up PRs by the workspace's upstream head branch (state=all) and links whatever comes back, with no state check.When someone opens a throwaway PR from the default branch (e.g. "merge main into feature", so
head=main) and closes it, the per-head lookup for themainworkspace returns that closed PR and links it — even thoughmainhas long since advanced past the PR's head commit. The old v1 renderer path (pr-resolution.ts) guarded against exactly this (historical PRs only attach when the workspace HEAD still equals the PR head OID); the v2 host-service path dropped that guard.Fix. Port the guard: closed/merged PRs are treated as historical and only stay attached while
workspace.headShastill matches the PR'sheadRefOid. Otherwise the link is skipped (and any stale persisted link cleared). Open/draft/queued PRs are unaffected, and a merged/closed PR still shows while the workspace is sitting on that exact commit.Bug 2 — branch with multiple PRs shows the closed one (#4513 item 2)
Root cause.
normalizePullRequestCandidates(utils/github-query/github-query.ts) picked the first candidate matching the head branch. GitHub returns the list sorted byupdated desc, so a recently-touched closed PR won out over the live open PR on the same branch.Fix. Prefer the
OPENcandidate among head-branch matches, falling back to the most-recently-updated only when none is open.Tests
packages/host-service/src/runtime/pull-requests/:pull-requests.test.ts— newdefault branch stale PR isolationblock: default branch does not link a closed PR it has advanced past; still links a closed PR while HEAD matches; clears a stale persisted link once HEAD moves on.utils/github-query/github-query.test.ts— prefers the open PR when a head branch has both closed and open PRs.All three reproduction tests failed before the fix and pass after. Full
src/runtime/pull-requests/suite (28 tests) andtsc --noEmitare green.Refs #5596
Closes #4508
Closes #4260
Closes #4513
Summary by cubic
Stops attaching stale or wrong PRs to the workspace sidebar by treating closed/merged PRs as historical and preferring open PRs when multiple exist for a branch. Addresses #5596 and prevents spurious PR icons on the default branch.
PullRequestRuntimeManager, closed/merged PRs only link ifworkspace.headShaequals the PRheadRefOid; otherwise we skip and clear any stale link.utils/github-query/github-query.ts,normalizePullRequestCandidatesnow prefers theOPENcandidate, falling back to the latest only when none is open.pull-requests.test.tsandgithub-query.test.tscover default-branch isolation and open-over-closed selection.Written for commit eab4ae8. Summary will update on new commits.