Skip to content

Fix PR lookup for renamed fork upstreams - #1312

Merged
ymichael merged 3 commits into
mainfrom
bb/fix-github-pr-banner-lookup-for-fork-upstreams-thr_xbcw8kqpr6
Aug 11, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/fix-github-pr-banner-lookup-for-fork-upstreams-thr_xbcw8kqpr6

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Summary

  • resolve PRs through the configured upstream remote and branch when a BB managed local branch has a different name
  • preserve distinct no-PR and unavailable GitHub CLI outcomes
  • add real-Git regression coverage for fork remotes, renamed branches, no-PR, authentication, and missing CLI cases
  • bump the host-daemon protocol to 97 so enrolled hosts receive the corrected lookup behavior

Validation

  • pnpm exec turbo run test --filter=@bb/host-workspace --force
  • pnpm exec turbo run test --filter=@bb/host-daemon-contract --force
  • pnpm exec turbo run typecheck --filter=@bb/host-workspace
  • pnpm exec turbo run typecheck --filter=@bb/host-daemon-contract --filter=@bb/host-daemon
  • live read-only lookup against env_yikdjjfryt resolved Apply Claude turn settings without replacing live sessions #1236

@SawyerHood

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am SlopCop. I started the review for PR #1312.

I will check security, code quality, performance, architecture, and practical test coverage.

Comment thread packages/host-workspace/src/git-host.ts Outdated
const repoViewArgs = [
"repo",
"view",
remoteUrl,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — High: Validate the remote host before you give this URL to gh repo view.

A workspace controls remoteUrl. The daemon also gives its GH_ENTERPRISE_TOKEN to gh.

I reproduced this issue with a dummy token and https://httpbin.org/owner/repo.git.

gh sent a GraphQL request to httpbin.org with an authorization header.

An agent can change .git/config and set a renamed upstream on a hostile remote. The automatic PR check then contacts that remote.

This path can expose an enterprise token. It also permits a server-side request to an arbitrary host.

Accept only the trusted GitHub host for the base repository. Add a test with a hostile remote and a dummy token.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 930ade3. Configured remote URLs are now parsed locally and are never passed to gh. The upstream host must match the origin host before BB constructs the owner:branch selector. The regression test sets a dummy enterprise token and a hostile httpbin remote, then verifies gh is never invoked.

Comment thread packages/host-workspace/src/git-host.ts Outdated
];
let repoViewStdout: string;
try {
({ stdout: repoViewStdout } = await execFileAsync("gh", repoViewArgs, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Medium: Cache the canonical repository for each remote URL.

The app checks an open PR with pending checks every five seconds.

This path now starts two Git processes and one serial gh repo view request before each gh pr view request.

One active environment can add 720 network requests and 1,440 Git processes each hour.

Use a bounded cache by remote URL. Remove the entry when the URL changes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 930ade3 by removing canonical repository lookup over the network entirely. Upstream branch config plus origin/upstream URLs are now read in one local git config process, followed only by the existing gh pr view request. A regression test changes the remote URL between lookups and verifies the next selector changes immediately.

export async function getPullRequestForCurrentBranch(
args: GetPullRequestForCurrentBranchArgs,
): Promise<GitHostPullRequestLookup> {
const target = await getPullRequestTarget(args);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Medium: Use this resolved target for PR actions too.

The lookup now finds the renamed upstream. However, ready, draft, and merge still run gh without this target.

For local-name tracking fork-owner:upstream-name, those actions search for fork-owner:local-name and fail.

Pass localBranch into the action path. Use the same target selector for lookup and actions.

Add action tests for a differently named upstream branch.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 930ade3. Lookup and actions now share the same target resolver, Workspace passes the local branch into the action path, and ready, draft, and merge receive the qualified upstream selector. The real-Git integration test covers all three action argument lists.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

ELI5

Think of two labels on one toy box.

This PR helps BB use the second label to find the box. That part works.

Some buttons still use the first label. A bad address can also receive a secret key.

BB also repeats extra work every five seconds.

Review result

I found one high issue and two medium issues.

  • High security: A workspace remote can make gh send GH_ENTERPRISE_TOKEN to an arbitrary host. This issue blocks a safe merge.

  • Medium correctness: The ready, draft, and merge actions do not use the new upstream target. They can fail after the lookup succeeds.

  • Medium performance: Each renamed-upstream refresh adds a serial network request and two Git processes. Pending checks can cause a refresh every five seconds.

The new target resolver should serve both lookup and actions. A bounded cache should own the canonical repository result for each remote URL.

I found no other security, quality, duplication, naming, or test issue.

Validation

  • The live dev app found cross-repository PR #1236 from a local branch with a different name.

  • I did not select the ready, draft, or merge actions.

  • A dummy-token probe showed that gh repo view sent an authorization header to httpbin.org.

  • Turbo passed 189 host-workspace tests and 49 contract tests.

  • Turbo passed the host-workspace, host-daemon-contract, and host-daemon type checks.

  • git diff --check passed.

  • All GitHub checks passed for the reviewed SHA.

I submitted a comment-only review. I did not approve the PR or request changes.

@ymichael
ymichael force-pushed the bb/fix-github-pr-banner-lookup-for-fork-upstreams-thr_xbcw8kqpr6 branch from 996eab5 to a5ea63c Compare August 11, 2026 16:08
@ymichael
ymichael merged commit 3a3e3e0 into main Aug 11, 2026
10 checks passed
@ymichael
ymichael deleted the bb/fix-github-pr-banner-lookup-for-fork-upstreams-thr_xbcw8kqpr6 branch August 11, 2026 16:33
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