Skip to content

fix: explain a PR claim conflict on the failed check (Fixes #34) - #35

Merged
vpacher merged 2 commits into
masterfrom
fix/34-fork-pr-claim-explanation
Nov 25, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/34-fork-pr-claim-explanation

Conversation

@vpacher

@vpacher vpacher commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #34

On a fork PR the pull_request token is read-only, so the claim bot's claim-conflict label and its explanatory comment fail with HTTP 403. The check goes red and the author sees no reason (obs-rust/obs-studio#5547, Claim bot runs 45288247847 and 45288308289).

Change

on_pull_request (workflow/claim_bot.py) now also reports every claim conflict on the check itself, through the new report():

  • one ::error title=Claim conflict:: annotation with the reasons and how to fix the claim (line breaks escaped as %0A, % as %25);
  • a "Claim conflict" section in the job step summary ($GITHUB_STEP_SUMMARY), with the same text.

The text says what to do: comment Claiming: <plan> on the issue (it must be Ready), ask a maintainer for /reassign, or change the closing reference to Refs #N, then push or edit the PR to run the check again.

This is option 1 of #34. It needs no new token scope and runs no PR code. On same-repository PRs the label and comment are posted as before; the annotation and summary are added there too.

RED → GREEN

  • RED 6e98a23: tests/test_claim_bot_errors.py, class ForkPrExplanation (every write returns HTTP 403). A conflict must give one ::error line and a step summary, both with the reason and Claiming:; a two-reason explanation must stay on one annotation line; a clean PR writes neither. Two of the three fail: no ::error line, no summary.
  • GREEN 70c3944: all pass.

Local checks (PR CI test runs the same unittest command)

$ uv run python -m unittest discover -s tests
Ran 261 tests in 0.476s
OK
$ uvx ruff format --check workflow/claim_bot.py tests/test_claim_bot_errors.py
2 files already formatted
$ uvx ruff check workflow/claim_bot.py tests/test_claim_bot_errors.py
SIM117 (tests/test_claim_bot_errors.py, test_read_endpoint_survives_header_and_pagination_flags)
UP017 (workflow/claim_bot.py, datetime.now(timezone.utc) in main)

Both ruff findings are on master already, in lines this PR does not change.

Not checked end to end: the annotation and summary on a real fork PR. The next fork PR with a claim conflict shows them.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 25, 2026 13:33
…D, Refs #34)

On a fork PR the pull_request token is read-only, so the claim bot's
label and comment fail with HTTP 403 (obs-rust/obs-studio#5547, Claim
bot runs 45288247847 and 45288308289). The check goes red and the
reasons appear nowhere the author can see. These tests expect the
reasons, with what to do, as one ::error:: annotation and in the job
step summary; a clean PR writes neither.

Fails now: on_pull_request prints no ::error:: line and writes no
step summary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a fork PR the pull_request token is read-only, so the claim-conflict
label and the explanatory comment fail with HTTP 403 and the author sees
only a red check. on_pull_request now also reports every conflict on the
check itself: one ::error:: annotation and a "Claim conflict" section in
the job step summary, each with the reasons and how to fix the claim.
It needs no new token scope and does the same for same-repository PRs,
where the comment is still posted as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@vpacher vpacher left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Coordinator review: no blocking findings.

  • Correctness: report() runs only when conflicts() returns reasons, after the best-effort writes, so a 403 on the label or comment can no longer hide the reasons. The exit code is unchanged (1 on conflict).
  • Injection: the annotation escapes %, CR and LF, so the PR-body-derived references cannot start a second workflow command. The references themselves are limited to owner/repo#N by CLOSING.
  • Scope: no new token permission, no PR code is executed; the reusable workflow still checks out obs-rust/.github@master, so every repo gets this on merge.
  • Tests: RED 6e98a23 fails two of three new cases; GREEN passes all 261. PR CI test and claim are green.
  • Claim: #34 is assigned and ready with an accepted Claiming: comment.

Not verified: the annotation and summary on a real fork PR; the next fork PR with a conflict shows them.

@vpacher
vpacher merged commit 608c8fc into master Nov 25, 2026
3 of 4 checks passed
@vpacher
vpacher deleted the fix/34-fork-pr-claim-explanation branch November 25, 2026 12:36
@github-actions github-actions Bot added the claim-conflict A PR closing reference conflicts with the issue claim label Nov 25, 2026
@github-actions

This comment has been minimized.

@vpacher vpacher removed the claim-conflict A PR closing reference conflicts with the issue claim label Nov 25, 2026
vpacher added a commit that referenced this pull request Nov 25, 2026
…36) (#37)

* test: a PR event that runs after the merge writes nothing (RED, Refs #36)

An `edited` event queued before #35 merged ran after the merge had
closed #34 (Claim bot run 45615324507). It read `open` from the event
payload, saw #34 closed, labelled the merged PR claim-conflict, posted
the conflict comment and failed. This test merges the PR and closes its
issue before the queued event runs and expects no write and a pass.

Fails now: on_pull_request returns False and labels the merged PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: a PR claim check that runs after the merge writes nothing (Fixes #36)

on_pull_request took the PR's open state from the event payload. A run
that waited for a runner can start after the merge, which has already
closed the issues the PR fixes, and then reported a false "is closed"
conflict on the merged PR (#35, run 45615324507). It now reads the PR's
live state first and passes without a write when the PR is closed.

The 403 tests mock the PR object, so they now give it closed=False.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

claim bot: on a fork PR the label and the explanation fail with HTTP 403, so the author never sees why the check failed

1 participant