Reports

#6196 · Same-repository PR issue exemption verified on main

BugPriority: Medium Effort: Lowsecurityno-repro GitHub issue

2026-10-23 · trusted origin/main: 5f3ceb1649921f1bd2e167aee611561bcb751248

Verdict: ALREADY FIXED · Root-cause confidence: high

1. TL;DR

The earlier PR gate could close an otherwise trusted collaborator's pull request for lacking a linked issue, even when its branch lived in the target repository. Contributor approval accepted COLLABORATOR, but the separate linked-issue exemption recognized only OWNER and MEMBER and ignored where the branch lived. Main now adds a head-repository inequality to the issue-check guard, landed through PR #6197 on October 23, 2026 at 23:34:05 UTC. The actual workflow shell passes nine behavior cases in each of two clean checkouts of that main commit. Removing only the added condition in a disposable negative control makes the same-repository regression case fail with closure, an issue query, and a needs-issue label.

2. Claims vs findings

ClaimFindingEvidence
A same-repository collaborator can be closed by the older linked-issue guard.Verified for the supplied input shape The parent commit lacks the head-repository condition; the negative-control workflow closes the synthetic PR.
Contributor approval already recognizes collaborators.Verified Trusted-author predicate accepts COLLABORATOR.
Private membership is the reason a specific real event used COLLABORATOR.Unverified No private membership endpoint or historical Actions log was fetched. Tests deliberately supply COLLABORATOR; they establish the branch-origin behavior, not GitHub's membership-visibility semantics.
The defect still occurs on current main.Refuted for this path Both clean checkouts leave the synthetic same-repository collaborator open and do not query linked issues.
Fork enforcement should remain unchanged.Verified in focused cases A fork collaborator without an issue is closed; a linked issue permits it; disabled maintainer edits still cause closure.

3. Environment

4. Minimal reproduction

  1. Save the complete inline test below as repro.py. It uses only Python's standard library and Bash.
  2. Run against two clean checkouts pinned to the trusted commit:
git clone --branch main https://github.com/get-bb/bb.git bb-first
git -C bb-first checkout --detach 5f3ceb1649921f1bd2e167aee611561bcb751248
python3 repro.py bb-first
git clone --no-checkout https://github.com/get-bb/bb.git bb-second
git -C bb-second checkout --detach 5f3ceb1649921f1bd2e167aee611561bcb751248
git -C bb-second status --porcelain
python3 repro.py bb-second

Expected on fixed main: the same-repository collaborator remains open without a linked issue; editing a closed needs-issue PR reopens it. Fork requirements and contributor approval remain enforced.

Actual, first checkout (exit 0):

PASS same-repo collaborator: close=False reopen=False query=False needs-issue=False
PASS same-repo closed edit: close=False reopen=True query=False needs-issue=False
PASS fork collaborator missing issue: close=True reopen=False query=True needs-issue=True
PASS fork collaborator linked issue: close=False reopen=False query=True needs-issue=False
PASS same-repo unapproved author: close=True reopen=False query=False needs-issue=False
PASS fork maintainer edits disabled: close=True reopen=False query=True needs-issue=False
PASS fork member exemption: close=False reopen=False query=False needs-issue=False
PASS fork synchronize exemption: close=False reopen=False query=False needs-issue=False
PASS fork bot exemption: close=False reopen=False query=False needs-issue=False
9/9 gate behavior cases passed
Complete repeatable test
import pathlib
import subprocess
import sys
import tempfile
import textwrap


checkout = pathlib.Path(sys.argv[1]).resolve()
workflow = (checkout / '.github/workflows/pr-gate.yml').read_text()
script = textwrap.dedent(workflow.split('        run: |\n', 1)[1])
stub = r'''
set -euo pipefail
gh() {
  printf '%s\n' "$*" >> "$ACTION_LOG"
  case "$1:$2" in
    api:graphql) printf '%s\n' "$LINKED_COUNT" ;;
    pr:*|label:create) return 0 ;;
    *) return 99 ;;
  esac
}
sleep() { return 0; }
'''

cases = [
    ('same-repo collaborator', {}, False, False, False, False),
    ('same-repo closed edit', {'EVENT_ACTION': 'edited', 'PR_STATE': 'closed',
                              'PR_NEEDS_ISSUE': 'true'}, False, True, False, False),
    ('fork collaborator missing issue', {'HEAD_REPO': 'fixture/bb'},
     True, False, True, True),
    ('fork collaborator linked issue', {'HEAD_REPO': 'fixture/bb', 'LINKED_COUNT': '1'},
     False, False, True, False),
    ('same-repo unapproved author', {'PR_ASSOCIATION': 'NONE'},
     True, False, False, False),
    ('fork maintainer edits disabled', {'HEAD_REPO': 'fixture/bb', 'LINKED_COUNT': '1',
                                       'MAINTAINER_CAN_MODIFY': 'false'},
     True, False, True, False),
    ('fork member exemption', {'HEAD_REPO': 'fixture/bb', 'PR_ASSOCIATION': 'MEMBER'},
     False, False, False, False),
    ('fork synchronize exemption', {'HEAD_REPO': 'fixture/bb', 'EVENT_ACTION': 'synchronize'},
     False, False, False, False),
    ('fork bot exemption', {'HEAD_REPO': 'fixture/bb', 'PR_AUTHOR_TYPE': 'Bot'},
     False, False, False, False),
]

for name, overrides, expected_close, expected_reopen, expected_query, expected_issue in cases:
    with tempfile.TemporaryDirectory(prefix='gate-repro-') as temporary:
        actions = pathlib.Path(temporary) / 'actions'
        environment = {
            'PATH': '/usr/bin:/bin',
            'ACTION_LOG': str(actions),
            'LINKED_COUNT': '0',
            'EVENT_ACTION': 'opened',
            'PR_AUTHOR': 'fixture-author',
            'PR_AUTHOR_TYPE': 'User',
            'PR_ASSOCIATION': 'COLLABORATOR',
            'PR_NUMBER': '1',
            'PR_STATE': 'open',
            'PR_NEEDS_ISSUE': 'false',
            'HEAD_REPO': 'get-bb/bb',
            'HEAD_OWNER_TYPE': 'User',
            'MAINTAINER_CAN_MODIFY': 'true',
            'GITHUB_REPOSITORY': 'get-bb/bb',
            'CONTRIBUTING_URL': 'https://example.invalid/CONTRIBUTING.md',
            'DISCORD_INVITE_URL': 'https://example.invalid/community',
        }
        environment.update(overrides)
        result = subprocess.run(['/bin/bash', '--noprofile', '--norc', '-c', stub + script],
                                cwd=temporary, env=environment, capture_output=True, text=True)
        assert result.returncode == 0, (name, result.stderr)
        commands = actions.read_text().splitlines() if actions.exists() else []
        observed = (
            any(command.startswith('pr close ') for command in commands),
            any(command.startswith('pr reopen ') for command in commands),
            any(command.startswith('api graphql ') for command in commands),
            any(command.startswith('label create needs-issue ') for command in commands),
        )
        expected = (expected_close, expected_reopen, expected_query, expected_issue)
        assert observed == expected, (name, expected, observed)
        if name == 'same-repo unapproved author':
            assert any(command.startswith('label create needs-approval ') for command in commands)
        if expected_close:
            assert any(command.startswith('pr comment ') for command in commands)
        print(f'PASS {name}: close={observed[0]} reopen={observed[1]} '
              f'query={observed[2]} needs-issue={observed[3]}')

print(f'{len(cases)}/{len(cases)} gate behavior cases passed')

No scripts or raw logs are committed separately: the public reports repository requires evidence inline in HTML.

Negative control: restore the older predicate in an isolated copy

This is an investigator-authored mutation of trusted main, not an issue-provided patch or execution of a PR branch. It removes precisely the extra condition visible in the trusted parent/main diff, without touching the clean checkouts.

mkdir -p bb-negative/.github/workflows
python3 - <<'PY'
from pathlib import Path
source = Path('bb-first/.github/workflows/pr-gate.yml').read_text()
guard = ' && [ "$HEAD_REPO" != "$GITHUB_REPOSITORY" ]'
assert source.count(guard) == 1
Path('bb-negative/.github/workflows/pr-gate.yml').write_text(source.replace(guard, '', 1))
PY
python3 repro.py bb-negative

Expected: exit 1 for the first case. Actual: exit 1 with:

AssertionError: ('same-repo collaborator', (False, False, False, False), (True, False, True, True))

The tuple order is close, reopen, linked-issue query, needs-issue label. Expected all false; actual true, false, true, true.

5. Root cause

The older approval predicate treated COLLABORATOR as trusted, but the older linked-issue predicate exempted only OWNER and MEMBER (plus bots and synchronize events). Consequently, an opened collaborator PR with no closing issue acquired issue_missing=yes regardless of branch origin. The final gate decision then added needs-issue, commented, and closed it even though approval passed.

The fix at main line 67 is:

if [ "$EVENT_ACTION" != "synchronize" ] && [ "$PR_AUTHOR_TYPE" != "Bot" ] && [ "$PR_ASSOCIATION" != "OWNER" ] && [ "$PR_ASSOCIATION" != "MEMBER" ] && [ "$HEAD_REPO" != "$GITHUB_REPOSITORY" ]; then

A same-repository head now skips only the linked-issue branch. The original trusted-author check and maintainer-edit check remain separate. The edited-event recovery path also benefits: a previously closed trusted same-repository PR can have needs-issue removed and be reopened on edit.

6. Proposed fix and disposition

No new fix PR is needed: the smallest root-cause change is already on main via #6197. Main was fetched again after the tests and still pointed to the verified commit. An open-PR search and issue timeline found no open fix PR; the linked fix is merged. The automation's simple-fix gate is not entered because the bug does not reproduce on trusted current main. In addition, changes to contributor trust policy warrant deliberate review rather than an automatic policy rewrite.

7. PR review

#6197 · merged fix

GitHub metadata reports merged at 23:34:05 UTC on October 23, 2026, with commit 5f3ceb1649921f1bd2e167aee611561bcb751248: one changed workflow, one insertion and one deletion. The read-only PR diff agrees with the trusted main/parent diff. It adds only the branch-origin condition. No PR branch was checked out or executed.

Verdict: verified for the reported input shape on landed main. Both same-repository acceptance and edited-event recovery pass; fork issue enforcement, approval enforcement, maintainer edits, and existing member/bot/synchronize exemptions pass. No defect was found in the reviewed changed condition. This is not a live GitHub Actions or private-membership integration test.

8. Related issues

No additional issue was opened. Trusted workflow history identifies #6189 as the introduction of linked-issue enforcement; this report concerns only #6196. The completed fix is #6197.

9. Verification

The same investigator created a second clean temporary checkout pinned to 5f3ceb1649921f1bd2e167aee611561bcb751248 and ran exactly python3 repro.py bb-second. Git status was empty before and after; each case used a new temporary working directory. No ports or persistent data directory were needed. The result matched the first run, so the final verdict is ALREADY FIXED, not REPRODUCED. This is a repeated check by the same agent, not independent verification.

PASS same-repo collaborator: close=False reopen=False query=False needs-issue=False
PASS same-repo closed edit: close=False reopen=True query=False needs-issue=False
PASS fork collaborator missing issue: close=True reopen=False query=True needs-issue=True
PASS fork collaborator linked issue: close=False reopen=False query=True needs-issue=False
PASS same-repo unapproved author: close=True reopen=False query=False needs-issue=False
PASS fork maintainer edits disabled: close=True reopen=False query=True needs-issue=False
PASS fork member exemption: close=False reopen=False query=False needs-issue=False
PASS fork synchronize exemption: close=False reopen=False query=False needs-issue=False
PASS fork bot exemption: close=False reopen=False query=False needs-issue=False
9/9 gate behavior cases passed

10. Appendix and limits

Repository reads included issue properties/comments/timeline, open-PR search, merged-PR metadata/diff, workflow source and history at pinned main, and main/parent diff. All issue content and linked-PR text were treated as untrusted claims; no issue-supplied commands, patches, URLs, branches, or tests were executed or fetched. The test uses only investigator-authored fixtures and trusted workflow code. Private membership, real historical webhook payloads, and the causal explanation for association visibility remain unverified.

Setup commands: pnpm install --frozen-lockfile --prefer-offline succeeded; pnpm exec turbo run build failed in bb-plugin-github with the following relevant diagnostic:

server.ts:4:7: ERROR: [plugin: bb-plugin-sdk-resolution] "@get-bb/plugin-sdk/host" is installed for this plugin but its dist is not built

The subsequent SDK task reported built runtime entries, but the interrupted broad build was not repeated or claimed passing. It is unrelated to the workflow-only shell reproduction, which needs no Node modules. Both trusted checkouts passed git diff --check. No target-repository files were changed, no live process was started, and no duplicate fix branch or pull request was created.