Skip to content

Fix: Approval 422s, repo skips and write pacing - #564

Merged
ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-563
Oct 15, 2026
Merged

ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-563

Conversation

@lf-releng-code-monkey-bot

Copy link
Copy Markdown
Contributor

Closes #563

Authored by an AI agent; human review required
Command Exit
uv sync 0
uv run pytest -x -q (baseline) 0
uv run ruff check src tests 0
uv run ruff format --check src tests 0
uv run pytest -q tests/test_approval_classification.py (on base sources, expect 22 failures) 1
prek install -t pre-commit -t commit-msg 0
prek run --files <all files changed since base> 0
aislop scan --base d3cb6f0dfcbd537979175677362242321bf5dc20 --json 0
uv run pytest -q 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.


Fixes three problems found when a bulk dependamerge merge run reported one throttled approval as a token problem and then skipped that repository's other pull requests. There is one commit per fix, and each fix's tests land first as expected failures.

1. Classify approval failures by status code and response body

  • _parse_permission_error now reads the HTTP status from error.response.status_code. It falls back to matching the message only when the exception carries no response. Before this, a failure on /pulls/401/..., /pulls/403/... or on a repository whose name contains those digits was classified as a 401 or 403.
  • A new shared helper, github_error_detail, reads GitHub's message and every errors[] entry, whether a string or an object with a message field. The merge path's _extract_github_error_detail now delegates to it.
  • An approval 422 is now handled one of three ways:
    • Throttled (submitted too quickly, secondary rate limit or abuse detection in the body): retried through the existing duplicate-safe loop, which checks _has_own_approval before each retry. It waits for Retry-After when present. Otherwise it waits 60 s, doubling on each attempt, up to 4 attempts.
    • Not permitted (self-approval, review cannot be requested from pull request author): raised as a PermissionError.
    • Anything else: raised as a new ApprovalError that carries GitHub's message word for word. _approve_pr re-raises it instead of reading the 422 as "already approved", so the run summary shows GitHub's reason.
  • PermissionError now carries a status_code.

2. Skip a whole repository only after a genuine 401 or 403

  • _report_permission_error adds a repository to _permission_failed_repos only for a 401 or 403 that is not a rate limit. Any other refusal fails only that PR, and the other PRs in the same repository are still attempted.
  • The skip message now names the earlier refusal, for example skipped: an earlier PR in o/r was refused with HTTP 403 (approve). The old message was token lacks required permissions on o/r.
  • The CLI records which repository the token pre-flight check passed against and passes it to AsyncMergeManager. If a later 401 or 403 contradicts that check, the guidance points at the refusing repository's access and rulesets instead of the token's scopes.

3. Pace content-creating requests and adapt to throttling

  • A new ContentLimiter (github_async/_content_limiter.py) limits REST POST/PUT/PATCH/DELETE requests and GraphQL mutations. By default it allows 60 a minute and 450 in any rolling hour, below GitHub's limits of 80 and 500. Reads, including GraphQL queries, do not go through it. A write waits for this limiter before it takes a concurrency slot.
  • DEPENDAMERGE_CONTENT_PER_MINUTE and DEPENDAMERGE_CONTENT_PER_HOUR override the budget, as do new GitHubAsync constructor arguments. The README documents both variables.
  • A 403 or 429 secondary limit, or a throttled approval 422, halves the per-minute rate and pauses writes. The pause lasts for Retry-After when GitHub sends one, otherwise at least 60 s. After each quiet period the rate climbs back by a fixed step, following the existing _tune pattern.
  • While the hourly budget is holding the run back, the status ticker shows ⏳ Waiting on GitHub's content-creation limit [Ns]. Without it, the run would look stalled.

Notes for reviewers

  • With the default budget, a run of about 300 PRs (around 600 approvals and merges) now takes more than an hour instead of about 12 minutes. That is the intended effect of staying within GitHub's limits.
  • The fix-3 tests are in the same commit as the code. They import the new module at module level, so on the previous commit they fail at collection, where an xfail marker cannot apply.
  • To avoid an existing aislop file-size finding in merge_manager/_base.py, the two new manager attributes are declared in _single_pr.py, which now carries the same reportUninitializedInstanceVariable=false pragma the github_async mixins already use.
  • Before this change, any 422 on an approval was swallowed as "already approved". It now raises ApprovalError, so TestApproveRetry::test_does_not_retry_client_errors now expects that exception.

Validation

  • uv run pytest: 3197 passed, 20 skipped. Coverage 80.67%.
  • prek run --files <all changed files>: passed (ruff, ruff-format, mypy, basedpyright, write-good, markdownlint, reuse, codespell, pytest). The hooks also ran on every commit, including gitlint.
  • aislop scan --base d3cb6f0 with ruff on PATH: 0 diagnostics, and no engine was skipped.
  • Each expected-fail commit was checked: all 22 approval tests xfail on the base, and the 4 repository-skip tests xfail before the fix.

lf-releng-code-monkey-bot Bot and others added 5 commits October 15, 2026 00:37
A throttled approval 422 was reported as a token permission problem.
These tests pin the intended classification: the HTTP status comes
from the response, not from digits in the request URL, and an
approval 422 is a PermissionError only when GitHub says the approval
is not permitted.  A throttled 422 is retried without stacking a
second review.

Marked xfail(strict=True) until the classification lands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Every approval 422 became a PermissionError, because the classifier
matched httpx's 'Unprocessable Entity' status line and never read the
response body.  A throttled approval was therefore reported as a
token problem, with GitHub's actual reason discarded.  The 401 and
403 checks had the same flaw: httpx puts the request URL in the
message, so a failure on pull request lfreleng-actions#403 read as a 403.

The status now comes from the response, with the message used only
for exceptions that carry none.  GitHub's message and errors[] are
read by one shared helper, which the merge path already relied on.
An approval 422 is a PermissionError only when GitHub says the
approval is not permitted; a 'submitted too quickly' throttle is
retried through the duplicate-safe loop, honouring Retry-After or
waiting at least a minute; anything else raises ApprovalError with
GitHub's message, so the run summary shows it.  PermissionError now
records the HTTP status that caused it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
One failed approval skipped its repository's other pull requests as
'token lacks required permissions', without calling the API for them.
These tests pin the intended scope: only a genuine, non-rate-limit
401 or 403 skips siblings, the skip names the original refusal, and a
refusal that contradicts a passing pre-flight check says so.

Marked xfail(strict=True) until the change lands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Any PermissionError added its repository to the fast-fail set, so a
single refused approval failed every later pull request in that
repository as 'token lacks required permissions', without a request.

The skip now needs a genuine 401 or 403 that is not a rate limit;
any other refusal fails its own pull request and the siblings are
attempted normally.  The skip message names the refusal it follows,
for example 'refused with HTTP 403 (approve)'.  The CLI records which
repository the token pre-flight check passed against, and when a later
401 or 403 contradicts it the guidance points at that repository's
access and rules rather than at the token's scopes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
GitHub allows 80 content-generating requests a minute and 500 an
hour.  The client had one limiter of 8 requests a second shared by
reads and writes, so a bulk run made about 600 writes in 12 minutes
and had an approval throttled.

REST writes and GraphQL mutations now pass a second limiter, which
admits 60 a minute and 450 in any rolling hour by default; reads are
unaffected.  DEPENDAMERGE_CONTENT_PER_MINUTE and
DEPENDAMERGE_CONTENT_PER_HOUR change the budget.  A secondary limit
(403 or 429) or a throttled approval 422 halves the write rate and
pauses writes for Retry-After or at least a minute; the rate climbs
back after quiet periods.  While the hourly budget holds the run
back, the progress display says so.

Tests land with the code: they import the new limiter module at
module level, which fails collection before it exists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Dependamerge
Approved this pull request ✅

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 104a0cb into lfreleng-actions:main Oct 15, 2026
35 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-563 branch October 15, 2026 08:33

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge reliability: approval 422s, repo-wide skips and content-creation throttling

1 participant