Skip to content

fix(source-control): hold unattended GitHub loops to the API budget - #7769

Merged
kyle-sexton merged 3 commits into
mainfrom
fix/source-control-api-budget
Oct 17, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
fix/source-control-api-budget

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: owner-approved change to hold unattended loops to the per-user GitHub API budget.

Summary

Every gh call by every agent shares one per-user budget (5,000 REST requests and 5,000 GraphQL points an hour), and gh never backs off. The pull-request monitor, babysit-prs and babysit-loop polled faster than that budget allows and re-read GraphQL-only fields in loops.

Fix

  • reference/providers/github/README.md: new API budget section (buckets, 60 s background waits, GraphQL-only fields read once, writes 1 s apart, stop on the first rate-limit error). Skills point at it rather than restating it.
  • pull-request monitor: the Monitor watch polls at 60 s (was 30 s), and exits 2 with RATE-LIMITED on a rate-limit error instead of polling on.
  • pull-request merge: merge-state, merge-queue and queue-entry waits poll REST pulls/<n> at 60 s (were GraphQL gh pr view/gh api graphql at 15-30 s); the queue wait reads isInMergeQueue once, when the REST state or queue event changes.
  • babysit-prs: Monitor fallback at 60 s; babysit_merge.py polls an async merge at 60 s (was 3 s) and reads the queue state once after a CLI merge (was up to 4 GraphQL reads 3 s apart; later runs already confirm an unseen result). New gotcha points workers at the budget.
  • babysit-loop: a rate-limit error ends the cycle's forge work until the reset.

Verification

  • python3 -m unittest discover over skills/babysit-prs/scripts/tests: 1705 tests OK.
  • scripts/check-affected.sh --no-fetch: 7 passed, 1 skipped.
  • bash -n on the monitor poll script: OK.

Related

Source of the cadence: GitHub's REST best practices and REST/GraphQL rate-limit pages, linked in the new section.

🤖 Generated with Claude Code

https://claude.ai/code/session_01R3zhSKMdk2UotJNUF3cJ4n

Add one API budget section to the GitHub provider reference and point the
pull-request monitor, babysit-prs and babysit-loop at it. Monitor and
babysit watches poll at 60 s and stop on a rate-limit error; merge-state,
merge-queue and queue-entry waits poll REST at 60 s and read isInMergeQueue
once; the babysit merge gate polls an async merge at 60 s and reads queue
state once after a CLI merge instead of re-reading GraphQL every 3 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R3zhSKMdk2UotJNUF3cJ4n
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T17:09:02.862275Z f75a32d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 13s —— View job


Security review complete

  • Gather context (PR diff, changed files)
  • Review changed files for security-relevant issues
  • Check instruction-surface deletions against protected classes
  • Post findings / summary

No security issues found.

This PR only changes polling cadence (15s/30s/3s → 60s), reduces GraphQL-only re-reads to a single read, and adds a stop-on-rate-limit-error behavior to the pull-request monitor (monitor.md), babysit_merge.py, and babysit-loop. It touches no auth, injection, or secrets-handling surface:

  • plugins/source-control/skills/babysit-prs/scripts/babysit_merge.py (diff): removes read_merge_queue_after_merge's 4-attempt re-read loop in favor of a single read_merge_queue call. This is a correctness trade-off (more merge-pending/unconfirmed holds when a read lags the merge), not a security weakening — the unconfirmed path still reports exit 10 / ready: false rather than a false success.
  • plugins/source-control/reference/providers/github/pull-request/monitor.md: the new rate-limit branch in the watch loop is additive hardening (stop instead of probing for recovery). Checked for an instruction-surface deletion per the review's guardrail-removal lens — this diff only adds/tightens cadence rules, it doesn't delete or soften a standing instruction, so the protected-class register in docs/conventions/instruction-exception-register/README.md (present in this checkout) doesn't apply here.
  • Doc-only cadence/number changes across README.md, loop.md, merge.md, monitor.md, and the SKILL.md/reference files are consistent with each other and with the stated 60s/once-per-change budget.

No command-injection, credential-handling, or authorization-boundary changes in this diff.

0 findings.

claude-lane-summary: lane=claude-security-review sha=f75a32d247c0a82be81933481e255ebffc52bbec run=39052287817

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 7m 8s —— View job


Code review complete

  • Gather context (PR diff, changed files, CLAUDE.md/REVIEW.md)
  • Review each changed file for correctness, error handling, maintainability
  • Check alignment with REVIEW.md / project standards (paved paths)
  • Adversarially verify candidate findings
  • Post inline comments and summary

Summary

Reviewed all 14 changed files (docs/reference changes plus babysit_merge.py and its tests). The budget-cadence rework (30s→60s polling, GraphQL-only reads collapsed to a single read, rate-limit-stops-the-loop) is internally consistent across the pull-request monitor/merge docs, the babysit-prs/babysit-loop skills, and babysit_merge.py: the removed read_merge_queue_after_merge/queue_result_unseen helpers and QUEUE_READ_BACK_ATTEMPTS constant have no dangling references, and the matching tests were updated in lockstep with no orphaned references left behind. The REST mergeable_state vs GraphQL mergeStateStatus case handling (lowercase vs uppercase enum values) is also correctly threaded through.

One finding posted inline on pull-request/merge.md (lines 210-218): the new "poll the merge queue" loop's API-call-saving optimization depends on GitHub's REST Issue Events endpoint returning added_to_merge_queue/removed_from_merge_queue event values — a claim new to this PR, with no citation, unlike every neighboring fact in that same file. I couldn't independently confirm this against live GitHub docs (this lane has no web access), so flagging it as a verification gap rather than a confirmed defect: worth the author's double-check before merge, since a wrong assumption here wouldn't be caught by any test (it's a markdown code fence) and would quietly make the "read once" claim inaccurate.

Author-claimed-but-unverified: the PR body's test/lint run results (python3 -m unittest discover, scripts/check-affected.sh, bash -n) — this lane's sandbox denies arbitrary Bash/python3 execution, so I read the code and diff rather than re-running the suite myself.

claude-lane-summary: lane=claude-review sha=f75a32d247c0a82be81933481e255ebffc52bbec run=39052287759

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review has reviewed this pull request through c923898; a later push is reviewed from there.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f75a32d247

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

claude-review has reviewed this pull request through c923898; a later push is reviewed from there.

Keep the babysit SKILL.md files under the 500-line cap, stop the
pull-request monitor on a rate limit from any of its gh calls, scale
watcher cadence by watcher count, and cite the issue-events read the
merge-queue poll relies on.

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

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 6m 16s —— View job


Code review complete

  • Gather context (incremental diff, review files)
  • Review changed files since f75a32d for correctness, error handling, maintainability
  • Adversarially verify candidate findings
  • Post inline comments and summary

Summary

Reviewed the incremental diff since f75a32d (the 5 listed files), which addresses the Codex and Claude review comments from that commit:

  • pull-request/merge.md: added the missing pointer/as-of/recheck-trigger citation for the merge-queue events claim Claude's prior review flagged as unverified — now in the format the rest of that file uses.
  • pull-request/monitor.md: routes every later gh call's stderr through a shared $err temp file, checked once per poll for a rate-limit signature before truncating it for the next iteration — this correctly extends rate-limit detection beyond just the initial PR-state check per Codex's P2 comment, and the redirection/grouping ({ ... } 2>>"$err") is syntactically sound.
  • babysit-loop/SKILL.md, babysit-prs/SKILL.md: pure line-unwrapping/trim edits, no content lost.

One finding posted inline on README.md:149-151: the new concurrent-watcher cadence formula (addressing Codex's P1 comment) is prose only. I had a second, independent agent adversarially check this before posting — it confirmed: the literal poll script (pull-request/monitor.md:127) still hardcodes sleep 60 unconditionally, the skill contract (skills/pull-request/reference/monitor.md:107) still documents a fixed "60 seconds," and babysit_merge.py:401's ASYNC_MERGE_POLL_INTERVAL_SECONDS is also a fixed 60.0 with a test pinning that value. Nothing in the plugin reads watcher count or computes the documented 2 s × watchers × requests interval. At the skill's own default concurrency (babysit_worker_concurrency_cap: 10) — exactly the worked example this new text uses — the real behavior is ~4,200 REST req/hr (84% of budget), not the ~1,800 req/hr ("near a third") the text claims. The P1 concern reads as resolved in the diff but isn't implemented anywhere.

Author-claimed-but-unverified: the PR body's test/lint results and the merge.md citation to melodic-software/claude-code-plugins#7771 — this lane's sandbox denies gh/WebFetch, so I could not independently confirm either.

claude-lane-summary: lane=claude-review sha=4b48248b74ddaf15cbc6832f403ef9b2ed322840 run=39053637440

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 50s —— View job


Security review complete

  • Gather context (incremental diff, changed files)
  • Review changed files for security-relevant issues
  • Check instruction-surface deletions against protected classes
  • Post findings / summary

No security issues found.

Reviewed the incremental change since f75a32d (.claude-lane/incremental.diff), scoped to:

  • plugins/source-control/reference/providers/github/README.md: clarifies the 60s cadence as a per-watcher floor, not a shared budget, and gives a scaling formula for concurrent watchers. Prose/guidance only, no executable surface.
  • plugins/source-control/reference/providers/github/pull-request/merge.md: adds a citation (a linked issue + the as-of date) for the added_to_merge_queue/removed_from_merge_queue REST issue-events claim flagged in the prior claude-review pass. Documentation fix, no logic change.
  • plugins/source-control/reference/providers/github/pull-request/monitor.md: adds err=$(mktemp) and redirects each poll's gh api/review-threads stderr into it (2>>"$err" in place of 2>/dev/null), then once per poll iteration greps $err for rate limit/HTTP 429, exits 2 with RATE-LIMITED on a match, and truncates it (: >"$err") otherwise. This generalizes the existing single-call rate-limit check (added in the prior commit, flagged by chatgpt-codex-connector for only covering the first request) to every gh call in the poll loop, closing that gap. mktemp's default mode (0600, unpredictable name, private to the invoking user) leaves no meaningful exposure or race for the captured stderr text, and nothing in it is interpreted as code — it's matched with a fixed grep -qiE pattern only.
  • plugins/source-control/skills/babysit-loop/SKILL.md, plugins/source-control/skills/babysit-prs/SKILL.md: line-wrap/prose compression of the existing rate-limit-stops-the-loop and API-budget guidance. Checked each against the instruction-exception register lens (removed rules that were actually enforced elsewhere): both keep "stop at the first rate-limit error" / "never a retry" intact in meaning — these are reformatting, not a removed or softened rule.

No command-injection, credential-handling, authorization-boundary, or Actions-workflow changes in this increment.

claude-lane-summary: lane=claude-security-review sha=4b48248b74ddaf15cbc6832f403ef9b2ed322840 run=39053636821

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 23s —— View job


Code review complete

  • Gather context (incremental diff, review files)
  • Review changed files since 4b48248 for correctness, error handling, maintainability
  • Adversarially verify candidate findings
  • Post inline comments and summary

Summary

Reviewed the incremental diff since 4b48248, scoped to the 3 listed files. This increment resolves the two outstanding scaling comments on this PR (Codex's P1 and the prior claude-review follow-up that the watcher-scaling formula was "prose only"):

  • pull-request/monitor.md: the literal poll script now declares INTERVAL=60 (comment points at ../README.md#api-budget) and calls sleep "$INTERVAL" instead of the previously hardcoded sleep 60. The variable is used correctly (set once at the top, read once at the loop's end), so the cadence is now genuinely adjustable per the README's scaling formula rather than fixed regardless of watcher count.
  • README.md: the worked example (ten monitors, ~7 requests/poll → 140 s) now says explicitly to set that figure as the monitor's INTERVAL, closing the gap between the documented formula and the actual knob.
  • skills/pull-request/reference/monitor.md: the arming instructions and the poll-script contract both switched from the fixed "every 60 seconds" wording to INTERVAL-based wording, consistent with the other two files.

Checked both relative links resolve to README.md#api-budget from their respective files, and the INTERVAL default (60) and variable name are consistent across all three files. No remaining gap between the documented cadence formula and the implementation in this increment, and no new issue introduced by the change.

0 findings.

claude-lane-summary: lane=claude-review sha=c92389867a8028cda57cfa71f0db8be664ebe1ba run=39054266510

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 35s —— View job


Security review complete

  • Gather context (incremental diff, changed files)
  • Review changed files for security-relevant issues
  • Check instruction-surface deletions against protected classes
  • Post findings / summary

No security issues found.

Reviewed the incremental diff since 4b48248 (.claude-lane/incremental.diff), scoped to the three listed files. This addresses Claude's prior P1 comment ("new scaling guidance is prose only — nothing implements it") by parameterizing the cadence instead of hardcoding it:

  • README.md: clarifies the 140 s worked example is "set as the monitor's INTERVAL" — a wording addition, no executable surface.
  • pull-request/monitor.md: introduces INTERVAL=60 as a named variable at the top of the poll script and changes the final sleep 60 to sleep "$INTERVAL". The variable is a plain integer set by whoever fills in the script template before handing it to the Monitor tool — not derived from any PR/issue/API data — and "$INTERVAL" is correctly quoted, so there's no command-injection or word-splitting surface here even if it were attacker-influenced.
  • skills/pull-request/reference/monitor.md: updates the contract prose to say "Polls every INTERVAL seconds" and tells the operator to raise it above 60 when other watchers run, per the API budget section. Documentation-only.

This is a pure addition (no instruction deletion, narrowing, or softening), so the instruction-exception-register lens doesn't apply. No command-injection, credential-handling, authorization-boundary, or Actions-workflow changes in this increment.

claude-lane-summary: lane=claude-security-review sha=c92389867a8028cda57cfa71f0db8be664ebe1ba run=39054266470

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 17, 2026
Merged via the queue into main with commit 887fcf8 Oct 17, 2026
27 checks passed
@kyle-sexton
kyle-sexton deleted the fix/source-control-api-budget branch October 17, 2026 17:40
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.

1 participant