Skip to content

fix(git-review): cache confirmed absent pull requests - #618

Open
knishioka wants to merge 2 commits into
sirmalloc:mainfrom
knishioka:fix/git-review-negative-cache
Open

knishioka wants to merge 2 commits into
sirmalloc:mainfrom
knishioka:fix/git-review-negative-cache

Conversation

@knishioka

@knishioka knishioka commented Sep 28, 2026 •

Copy link
Copy Markdown

Summary

Fix stale PR and CI indicators after GitHub CLI confirms that the current branch has no pull request at either repository target. Previously, an expired positive cache survived this result without an mtime update, so each subsequent render could schedule another refresh, with up to two PR lookups per refresh.

Changes

  • Distinguish GitHub CLI's explicit no-PR diagnostic from transient errors and unresolved/empty responses.
  • Replace stale positive data with the existing version-1 negative cache, shared by the PR and CI widgets for the existing 30-second TTL.
  • Preserve the default-repository-to-origin fallback for fork checkouts. A PR found at either target still wins; stale positive data is cleared only when both targets confirm absence.
  • Preserve stale display data on network, authentication, timeout, signal, and other unconfirmed failures, including an absent result at one target with failure at the other. Existing CI-field compatibility fallbacks remain.
  • Continue checking other available providers when the remote does not identify the forge.

Testing

  • bun test src/utils/__tests__/git-review-cache.test.ts: 37 passed.
  • bun test: 2,370 passed across 148 files.
  • bun run lint: passed (TypeScript and ESLint).
  • bun run build: passed.
  • git diff --check: passed.

Local validation used Bun 1.4.2 on macOS. New tests mock the CLI, cache, and clock: stale-positive to absent transitions, repeated PR/CI reads, lock sharing, TTL boundaries, a later new PR, transient errors, a PR found on origin after default resolution reports absence, mixed absent/error results in both orders, and cross-provider fallback.

Review Focus

The default repository selected by gh may differ from origin. This change preserves those existing lookup targets and does not treat absence from the first target as globally authoritative. When either target is unavailable or returns an unconfirmed result, previously cached display data is retained.

This PR prevents a confirmed absence from causing refreshes on every render; it does not guarantee one gh pr view invocation per TTL. The existing default/origin path still uses up to two ordinary absent-PR lookups per refresh. Reducing that to one safely requires a separate repository-resolution design. Existing CI-field compatibility retries may also add calls.

The change intentionally retains the current stale-on-transient-error retry behavior and 30-second TTL. It does not add cache cleanup, change the cache format, or extend GitLab error classification.

Breaking Changes

No configuration or cache migration is required. Existing fork lookup behavior is preserved.

Checklist

  • Added regression coverage for stale negative results and fork compatibility.
  • Reviewed the complete diff.
  • Full tests, lint/type checking, and build pass locally.
  • Kept the existing cache format and asynchronous refresh lock.

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.

1 participant