Skip to content

fix(github): gate non-origin remote probes in getGitHubApiRepositoryForRemote - #22684

Closed
h5kk wants to merge 1 commit into
stablyai:mainfrom
h5kk:fix/upstream-probe-loop
Closed

h5kk wants to merge 1 commit into
stablyai:mainfrom
h5kk:fix/upstream-probe-loop

Conversation

@h5kk

@h5kk h5kk commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

ELI5

On repos that have no upstream remote (most repos), Orca kept running git remote get-url upstream, which always fails, as a background subprocess over and over. This PR makes the shared lookup function check the cached list of remotes first, so it never asks git about a remote that doesn't exist.

What Changed

getGitHubApiRepositoryForRemote (src/main/github/github-api-repository-remote-probe.ts) now calls shouldProbeGitRemote for every remote name except origin before probing. Before, only some callers gated it (e.g. resolveGitHubApiRepositoryCandidates, which #18455 fixed). Others call it directly: getRepoUpstream, the tracked-upstream-branch fallback in branch-lookup-resolution.ts, and issue source preference 'upstream'. Also, one cold call for a missing remote runs get-url twice: in getOwnerRepoForRemote and again in getEnterpriseGitHubRepoSlugForRemote, whose originRepoCache has a flat 30 s TTL.

origin is still probed unconditionally, because callers depend on that. Adding an upstream remote later is picked up on the next remote-listing refresh (config-signature revalidated).

Why

Field data from one Windows machine (trace logs):

Honest caveat: I could not identify which caller produced those runs. Trace spans carry no parent span context, and ~35 min of running a build with this fix (plus a stack-trace log on the new gate) didn't reproduce the trigger. Gating at the shared function covers every caller, current and future, instead of patching one call site.

Linked Issue

Related: #18455 (partial fix of the same symptom). No open issue found for the remaining case.

Visual Proof

N/A: background subprocess behavior, no UI change.

Testing

  • I manually tested these changes locally. The build ran on Windows with no get-url upstream execs over ~35 min (384 git execs total), but the original trigger didn't occur in that window either, so this isn't proof.
  • Automated tests added/updated: new github-api-repository-remote-probe.test.ts drives the real implementation (only git exec mocked). It asserts zero get-url upstream execs across repeated 60 s-apart calls when the remote is missing, that upstream detection still works when the remote exists or is added later, and that origin is always probed.

Related suites pass (github-api-repository, github-repository-identity, remote-name-listing, review-head-remote, client). tsc (node) clean, oxlint and oxfmt clean on changed files. Platform: Windows 11.

AI Disclosure

Investigation and implementation by Claude Opus 5.5 (Claude Code), reviewed by me.

Agent skill upstream boundary

  • Not applicable

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A with reason for visuals
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (the gate uses the existing SSH-aware remote listing)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass: targeted suites, typecheck and lint pass locally; full suite left to CI

🤖 Generated with Claude Code

…orRemote

getGitHubApiRepositoryForRemote is the shared entry point for GitHub
identity lookups on a named remote. Some callers gate it with
shouldProbeGitRemote (resolveGitHubApiRepositoryCandidates), but others
call it directly (getRepoUpstream, the tracked-upstream-branch fallback in
branch-lookup-resolution.ts, issue source preference 'upstream'). For a
missing remote, one cold call runs `git remote get-url <name>` twice:
once in getOwnerRepoForRemote and again in
getEnterpriseGitHubRepoSlugForRemote, whose cache has a flat 30s TTL.

Field data (Windows, v1.4.206): 1,421 failing `git remote get-url upstream`
execs in one day for a repo whose `git remote` listing (which succeeded
778 times) contains only `origin`. They came in back-to-back pairs, which
matches this function's double probe. The exact caller was not identified.

Fix: gate the function itself with shouldProbeGitRemote for every remote
except `origin`, reusing the cached remote-name listing
(config-signature revalidated), so every current and future caller
inherits it. Adding an upstream remote later is still picked up on the
next listing refresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f409dc19-524d-4f5c-ab9e-24fbf358bb17

📥 Commits

Reviewing files that changed from the base of the PR and between 122b8c2 and b23ab70.

📒 Files selected for processing (2)
  • src/main/github/github-api-repository-remote-probe.test.ts
  • src/main/github/github-api-repository-remote-probe.ts

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


📝 Walkthrough

Walkthrough

Non-origin remote lookups now check shouldProbeGitRemote before requesting a remote URL. The function returns null when a non-origin remote is not eligible. Origin lookups remain unconditional. Tests cover absent and configured upstream remotes, re-probing after the remote-name listing TTL, and origin lookup when the listing is empty.

Merge Risk: ⚪ Minimal · up to b23ab

Missing non-origin remotes no longer trigger repeated URL probes, while configured and newly added remotes remain discoverable. No issue requiring a fix before merge was established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the main change: gating non-origin remote probes in getGitHubApiRepositoryForRemote.
Description check ✅ Passed The description covers the change, motivation, linked issue context, testing, AI disclosure, platform considerations, and checklist status. It also explains that full validation is deferred to CI. The…
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.
  • Fix all pre-merge checks with AI

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.

@pullfrog pullfrog 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.

Important

The changed-code quality gate fails on the new test — pnpm run check:code-quality:changed reports typescript(consistent-type-assertions) at github-api-repository-remote-probe.test.ts:59 and exits non-zero, so this needs a fix before merge.

Reviewed changes

  • Gated non-origin remote probes: getGitHubApiRepositoryForRemote now runs shouldProbeGitRemote for every remote except origin and returns null when the cached remote listing proves the remote is absent, so ungated callers (getRepoUpstream, the tracked-upstream branch fallback, explicit-upstream preference) stop spawning a failing git remote get-url <name> on each poll.
  • Regression test: new github-api-repository-remote-probe.test.ts drives the real implementation with only gitExecFileAsync mocked, asserting zero get-url upstream execs across repeated 60 s-apart polls, that upstream detection still works when configured or added later, and that origin is still probed unconditionally.

The gate placement is sound: every skipped call is one where git remote get-url <name> would have failed anyway, shouldProbeGitRemote fails open when the listing errors, and origin keeps its unconditional probe. I verified the new tests are real coverage — reverting the gate makes 3 of the 5 fail (2 get-url upstream execs on a single cold call, 10 across 5 polls).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +59 to +63
const error = new Error(`Command failed: git remote get-url ${remoteName}`) as Error & {
stderr: string
}
error.stderr = `error: No such remote '${remoteName}'`
return error

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.

The changed-code quality gate rejects this bare assertion (casting code quality: 1 new finding(s), typescript(consistent-type-assertions) at line 59). AGENTS.md requires avoiding type assertions or adding a line-scoped // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: … rationale. The identical pattern at github-repository-identity.fork-owner-repo.test.ts:69 is unchanged, so it isn't gated — this line is.

Suggested change
const error = new Error(`Command failed: git remote get-url ${remoteName}`) as Error & {
stderr: string
}
error.stderr = `error: No such remote '${remoteName}'`
return error
return Object.assign(new Error(`Command failed: git remote get-url ${remoteName}`), {
stderr: `error: No such remote '${remoteName}'`
})

nwparker added a commit that referenced this pull request Nov 11, 2026
…orRemote (#41276)

Callers such as getRepoUpstream and the tracked-upstream branch fallback called getGitHubApiRepositoryForRemote without checking the cached remote listing, causing repos without an upstream remote to run failing git remote get-url upstream execs on cold lookups. Gate non-origin remotes on shouldProbeGitRemote at the shared entry point while keeping origin unconditional.

Refs #22684

Co-authored-by: h5k <31630310+h5kk@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks for this optimization! Rebased onto current main (keeping origin unconditional while gating non-origin probes on shouldProbeGitRemote) and merged via #41276 (856eb03223) with Co-authored-by credit.

@nwparker nwparker closed this Nov 11, 2026
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.

2 participants