Skip to content

fix(checks): hide stale merged PRs after workspace HEAD changes - #7815

Merged
nwparker merged 11 commits into
stablyai:mainfrom
xianjianlf2:fix/hosted-review-swr-stale-merged
Oct 24, 2026
Merged

nwparker merged 11 commits into
stablyai:mainfrom
xianjianlf2:fix/hosted-review-swr-stale-merged

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When new commits move a workspace past an old merged GitHub PR, Source Control now shows Create PR while Orca checks the new commit. The merged PR remains visible when the workspace is still at its original commit.

What changed

  • Retain the contributor's HEAD-scoped request deduplication, completion cleanup, monotonic request ownership, and stale-merged guard on stale-while-revalidate reads.
  • Apply the existing merged-HEAD guard to direct Source Control, Checks, and folder-overview cache readers. A valid current hosted review can replace an obsolete queued PR; obsolete PR identity also stops supplying fallback actions.
  • Preserve raw cached data, permissive behavior for unknown/missing HEAD information, same-head and contained-head reviews, nonmerged reviews, and other providers. No IPC or remote wire format changes.

Verification

  • Reproduced on untouched main with real Git history, installed gh, production resolver/IPC/store, and a controlled local HTTPS provider. After moving A → B, Source Control showed the old merged PR until delayed commit membership returned []. No review/card/cache data was injected.
  • Repeated after independent review and latest-main integration at b443994558b064b9fdc56ddab62fd3c64d841557 (tree 20656e8dd2b8656d2887ef2b3cc91853ab103bf2). At fresh real commit c3bf811f56075956cd6db5b3ff027361f9673d5f, Source Control shows Create PR while both naturally populated raw caches still hold merged PR Improve terminal font rendering, per-pane zoom, and UI zoom #7 and membership lookup is pending for 12 seconds. The settled state also remains correct.
  • 134 focused tests across 11 suites, renderer TypeScript, seven changed-code-quality checks, formatting, max-lines ratchet, and git diff --check pass. Independent review found no blockers and separately exercised response-order races and the merged-HEAD predicate matrix.
  • Hidden macOS Electron renderer verified through Playwright CDP after fresh main/preload builds, with ORCA_BACKGROUND_LAUNCH=1. Native mobile, Linux/Windows, live SSH, full build, and full suite were not run locally; broader coverage is left to CI.

Visual proof

Untouched main, after advancing beyond the old merged PR (membership pending):

Before: stale merged PR #7 remains visible

Final candidate, still at the merged PR's original commit:

Same HEAD: PR #7 remains valid

Final candidate, after advancing to a new real commit (membership pending):

After: Create PR while old merged data remains cached

Credit and disclosure

Original contribution by @xianjianlf2 / MarkXian. Original contributor HEAD remains an ancestor, and Co-authored-by: MarkXian <mark-xian@foxmail.com> is retained. This investigation, extension, verification, and publication were assisted by OpenAI Codex. The contributor's original disclosure and description are retained below.

Follow-up to #7277. No dedicated issue is currently linked.

Contributor description retained from before this update

ELI5

After new commits move a worktree past a merged PR, Orca should check the current branch before returning that old merged card. Overlapping checks for different commits must also keep their results separate.

What Changed

  • Apply the existing stale-merged-head guard to the stale-while-revalidate path.
  • Deduplicate in-flight review requests by both their existing repository/branch/hint identity and normalized Git head. An A → B → A request sequence shares the pending A lookup instead of issuing a third one.
  • Use unique request-generation tokens so an older pending request cannot become the current cache writer again after a newer request finishes and its generation entry is cleaned up.
  • Remove completed entries using the same head-scoped key; preserve force-refresh supersession and the existing revalidation admission lanes.

Why

One in-flight slot per branch/hint loses track of A when B starts. Merely checking the head before reusing that slot avoids a wrong-head result but still duplicates requests. Resetting numeric generations after completion also permits an older request to regain write ownership after cache eviction.

Linked Issue

Follow-up to #7277 and the review feedback on this PR. No dedicated issue is currently linked; the contribution-template issue-link requirement remains outstanding.

Visual Proof

Rendered validation remains outstanding: a before/after recording of the Source Control stale-card transition has not been captured. The automated request/cache tests below are not presented as visual proof.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

On macOS with ORCA_BACKGROUND_LAUNCH=1:

  • pnpm test src/renderer/src/store/slices/hosted-review.test.ts src/renderer/src/store/slices/hosted-review-cache.test.ts src/renderer/src/store/slices/hosted-review-cache-race.test.ts src/renderer/src/store/slices/github-pr-branch-hosted-review-cache.test.ts src/renderer/src/store/slices/github-pr-refresh-hosted-review-cache-leak.test.ts: 61 tests passed.
  • Three new regressions fail against the previous implementation: A/B/A with either completion order, and generation reuse after a newer request completes and the cache is evicted. Tests also verify both head entries are released for later refreshes.
  • pnpm tc:web, formatting, changed-code quality checks, and git diff --check passed.
  • Full build/full suite, rendered UI, and live SSH/Linux/Windows execution were not run in this update.

AI Disclosure

Originally developed with Claude Code; this follow-up used OpenAI Codex for diagnosis, implementation, regression tests, and self-review.

Review

Reviewed both response orders, cache eviction, completed-request cleanup, force-refresh behavior, and existing cache race/leak coverage. The new key retains repository/runtime/hint isolation and uses the existing null normalization. Changes are provider-neutral in-flight bookkeeping shared by local IPC and remote runtime RPC; no wire payload, Git command, permission, path, or shortcut changes. Unique symbols stay in process-local request state and are not persisted or serialized.

Agent skill upstream boundary

  • Not applicable; no agent-skill installation code or upstream skill material changed.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Full lint, typecheck, test, and build pass; focused local checks are listed above, broader coverage is left to CI

Author

X: @mark86202384100

October 8 upstream refresh

Merged current upstream main and retained its monotonic lookup generation sequence alongside request isolation by Git HEAD. All 50 hosted-review tests across 4 suites, renderer type checking, and focused oxlint checks pass with ORCA_BACKGROUND_LAUNCH=1. This refresh was AI-assisted.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d566f2fe-250d-4c53-a7df-78905ce16aac
📥 Commits

Reviewing files that changed from the base of the PR and between 969336b and b443994.

📒 Files selected for processing: 11
  • src/renderer/src/components/right-sidebar/checks-panel/use-checks-panel-context-state.tsx
  • src/renderer/src/components/right-sidebar/parent-pr-checks-rows.test.ts
  • src/renderer/src/components/right-sidebar/parent-pr-checks-rows.ts
  • src/renderer/src/components/right-sidebar/source-control/review/use-hosted-review-state.test.tsx
  • src/renderer/src/components/right-sidebar/source-control/review/use-hosted-review-state.ts
  • src/renderer/src/components/right-sidebar/source-control/review/use-review-context.ts
  • src/renderer/src/store/slices/hosted-review-cache-state.ts
  • src/renderer/src/store/slices/hosted-review-cache.test.ts
  • src/renderer/src/store/slices/hosted-review-request-state.ts
  • src/renderer/src/store/slices/hosted-review.test.ts
  • src/renderer/src/store/slices/hosted-review.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Walkthrough

This change tracks hosted-review requests by the current worktree head and applies generation checks during request cleanup. When a merged review is stale for the active head, the fetch path revalidates it instead of returning it through the stale-while-revalidate path. Sidebar review state also filters stale merged reviews. Tests cover request reuse, response order, cache eviction, revalidation, and review visibility as the head changes.

Priority: Low

Merge Risk: Minimal · up to b4439

No actionable issue remains in the reviewed change; it is ready to merge after normal checks.

Security architecture risk: Low · up to 96933

The change improves review freshness without expanding repository access. Concurrent request handling has explicit safeguards, but end-to-end ordering of overlapping refresh results has not been fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated changed exposure is request scheduling and review-metadata freshness within existing repository-scoped lookup paths. Different heads can now produce independent requests, but the inspected change does not grant a new repository selector or execution-host authority.

Trust Boundaries and Controls

  • observed — The desktop lookup validates repository registration before invoking source-control lookup. When an execution-host owner is supplied, the guard requires a unique match on repository ID, normalized path, and execution-host identity. The new revalidation path still enters this existing handler.

Resilience and Maintainability Implications

  • observed — The generation-reuse regression test exercises an older pending request after a newer completion, cache eviction, and a subsequent request. It asserts that the old response cannot repopulate shared cache state. This supports stale-writer containment, but does not establish ordering for independently returned results consumed by the UI.
Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the user impact, implementation, verification, visual proof, AI disclosure, and limitations. However, it does not provide the required linked issue. Link an actual issue in the required Fixes #... section. Do not leave the issue requirement as “No dedicated issue is currently linked.”
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: hiding stale merged PRs after the workspace HEAD changes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
The synchronous fresh-return path guards on `staleMergedHeadRefetch` so a
worktree that advanced off a merged PR's head does not reuse the now-stale
merged review (added in stablyai#7277). The stale-while-revalidate fast path was
missing that same guard, so it served the stale merged card synchronously
(and kicked only a background refetch) whenever the parent-PR-checks overview
polled with `{ staleWhileRevalidate: true, currentHeadOid }`.

Result: a worktree that commits new work on top of a merged branch keeps
showing the old "Merged" card instead of going branch-only — persistently
while the background revalidation keeps failing (rate limit / gh error).

Add `!staleMergedHeadRefetch` to the SWR condition so the read revalidates
synchronously, matching the fresh-return path. Adds a regression test that
fails without the guard.

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

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main and preserved the current queued SWR revalidation implementation. The SWR fast path now shares the fresh-return path's stale-merged-head guard, so advancing a worktree beyond a merged review's head forces synchronous revalidation instead of briefly returning the stale merged card.

Validation:

  • focused hosted-review.test.ts: 27 tests passed
  • Oxlint passes on both changed files
  • git diff --check

@xianjianlf2
xianjianlf2 force-pushed the fix/hosted-review-swr-stale-merged branch from 00275be to dfa03a0 Compare August 31, 2026 06:20
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

The PR prevents stale-while-revalidate reads from immediately returning a merged GitHub review after the worktree advances beyond its head.

  • Adds the stale merged-head guard to the SWR fast path so affected reads revalidate synchronously.
  • Adds a regression test covering a merged review cached at one head and an SWR lookup at a newer head.

Confidence Score: 4/5

The stale-card fix should be completed before merging because an old-head request already in flight can still return the merged review after the worktree advances.

The new guard fixes the normal cached-return path, but request deduplication does not distinguish head OIDs and returns an existing promise without rechecking its result against the current head.

Files Needing Attention: src/renderer/src/store/slices/hosted-review.ts and src/renderer/src/store/slices/hosted-review.test.ts

Important Files Changed

Filename Overview
src/renderer/src/store/slices/hosted-review.ts Adds the intended SWR cache guard, but the subsequent head-insensitive in-flight deduplication can still return the stale merged review during a head-change race.
src/renderer/src/store/slices/hosted-review.test.ts Covers the ordinary stale merged-head revalidation path, but not an old-head request remaining in flight when the new-head SWR read occurs.

Reviews (1): Last reviewed commit: "fix(checks): stop stale-while-revalidate..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4d7502f2-9a15-40a8-8a1c-e6a77e9b369d

📥 Commits

Reviewing files that changed from the base of the PR and between dfa03a0 and bc26a62.

📒 Files selected for processing (3)
  • src/renderer/src/store/slices/hosted-review-request-state.ts
  • src/renderer/src/store/slices/hosted-review.test.ts
  • src/renderer/src/store/slices/hosted-review.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

xianjianlf2 and others added 5 commits October 3, 2026 15:44
Retain the contributor's HEAD-scoped request ownership and stale-while-revalidate guard. Apply the existing merged-head ownership check to Source Control, Checks, and completed folder-overview outcomes, since these consumers also read branch caches directly.

Preserve same-head, confirmed-contained, and unknown-head cache behavior while avoiding stale merged-review action fallbacks after new work advances the branch.

Original contribution: stablyai#7815
Original head: d6e106c
Co-authored-by: MarkXian <mark-xian@foxmail.com>
@nwparker nwparker changed the title fix(checks): stop stale-while-revalidate from flashing a stale merged PR fix(checks): hide stale merged PRs after workspace HEAD changes Oct 23, 2026
# Conflicts:
#	src/renderer/src/components/right-sidebar/source-control/review/use-hosted-review-state.test.tsx
Replace the HEAD-keyed in-flight map with the original single slot per
request key, and skip joining an in-flight lookup only when it was started
for a different known HEAD. Keep the stale-merged guard on the
stale-while-revalidate path and the merged-HEAD guards on the readers.
@nwparker

Copy link
Copy Markdown
Contributor

Maintainer follow-up (merged current main, which resolved the test conflict, plus ceb5f3a):

  • I replaced the HEAD-keyed in-flight map (inflightHostedReviewRequestKey / getHostedReviewRequestForHead / finishInflightHostedReviewRequest) with the original single slot per request key. In-flight entries now record currentHeadOid. A caller skips joining an in-flight lookup only when both sides have a known HEAD and those HEADs differ. Same-HEAD callers and callers without a HEAD dedupe exactly as on main, so request volume doesn't grow for mixed callers.
  • Some fencing is still required. Without it, a stale-while-revalidate read at HEAD B joins a pending HEAD-A lookup and gets back the merged PR (covered by does not reuse an old-head request after the branch advances). The A/B/A dedup optimization and its tests were dropped as scope creep: that rare race now costs one extra lookup. Generation ownership already relies on main's monotonic nextLookupGeneration.
  • Kept: the !staleMergedHeadRefetch guard on the SWR path, plus the merged-HEAD guards in Source Control, Checks and parent-PR rows. Together these are the visible fix. There are no IPC or wire changes.

@nwparker
nwparker merged commit 55ed5f8 into stablyai:main Oct 24, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants