Skip to content

Cut ci-monitor's GraphQL call volume and harmonize poll cadence - #217

Merged
haacked merged 2 commits into
mainfrom
haacked/optimize-gh-api
Sep 22, 2026
Merged

haacked merged 2 commits into
mainfrom
haacked/optimize-gh-api

Conversation

@haacked

@haacked haacked commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Reduces GraphQL API call volume in the ci-monitor skill's polling loops, which was implicated in hitting the account's GraphQL rate limit.

  • Steps 3 and 6e now poll at 60 seconds, matching Step 7a's existing interval. CI-check and approval state don't change meaningfully faster than queue state does.
  • ci-check-status.sh merges its gh pr checks and gh pr view calls into one gh pr view --json statusCheckRollup call. A new jq helper, checks-rollup.jq, reimplements gh's own pass/fail/pending bucketing against the raw rollup. It also deduplicates repeated check runs, so a flaky rerun doesn't leave a stale failure sitting next to the fresh pass.
  • gh pr view succeeds with an empty rollup in the window before a fresh commit's checks register, where the old gh pr checks errored. SKILL.md's Step 2 now gives a no_checks report one grace retry against the same head SHA before concluding a PR has no CI. That keeps a fix push from racing straight through to re-enqueueing without ever seeing the fix's own CI.

Test plan

  • Ran the skill's full test suite (ai/skills/ci-monitor/scripts/tests/*.sh), including a new test-checks-rollup.sh covering every bucket category, action_required, and dedup of stale reruns.
  • Verified the bucketing logic against gh's actual source (aggregateChecks in cli/cli) and against live posthog/posthog PRs. status, all_passed, failed, pending, and passed matched the old script exactly. total differed only by a documented edge case, where a job fires on two trigger events and gh pr view's exported JSON doesn't carry enough data to fully dedupe.
  • Ran shellcheck and shfmt against the changed and new scripts.

https://claude.ai/code/session_01C1aAmYe7fvjH5ddF9QhovU

Steps 3 and 6e now poll at 60s, matching Step 7a's existing interval;
CI-check and approval state don't change meaningfully faster than queue
state does, and polling faster just burns API calls.

ci-check-status.sh merges its `gh pr checks` and `gh pr view` calls into
one `gh pr view --json statusCheckRollup` call, one fewer gh call per
poll. checks-rollup.jq reimplements gh's pass/fail/pending bucketing
against the raw rollup (verified against gh's aggregateChecks source)
and dedupes repeated CheckRun/StatusContext nodes, so a flaky rerun
doesn't leave a stale failure sitting next to the fresh pass.

Unlike the old `gh pr checks`, `gh pr view` succeeds with an empty
rollup in the few seconds before a fresh commit's checks register,
instead of erroring. SKILL.md's Step 2 now gives a `no_checks` report
one grace retry against the same head_sha before concluding a PR has
no CI, so a fix push can't race straight through to Step 7 without
ever seeing the fix's own CI.

Claude-Session: https://claude.ai/code/session_01C1aAmYe7fvjH5ddF9QhovU
@haacked
haacked requested a lite review from Copilot September 22, 2026 19:52
@haacked
haacked marked this pull request as ready for review September 22, 2026 19:52

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Critical correctness issues remain in check pagination and event-aware deduplication, and the new tests are not covered by CI.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Reduces ci-monitor GraphQL polling volume and standardizes polling at 60 seconds.

Changes:

  • Consolidates PR metadata and check-status queries.
  • Adds rollup bucketing, deduplication, and grace retry handling.
  • Adds regression coverage for rollup behavior.
File Summary Findings
ai/​skills/​ci-monitor/​SKILL.md Updates polling cadence and no-check retry behavior. None
ai/​skills/​ci-monitor/​scripts/​tests/​test-checks-rollup.sh Tests rollup bucketing and deduplication. Moderate: not invoked by CI (2 votes)
ai/​skills/​ci-monitor/​scripts/​helpers/​ci-helpers.sh Sets the poll interval to 60 seconds. None
ai/​skills/​ci-monitor/​scripts/​helpers/​checks-rollup.jq Reconstructs check-status buckets and deduplicates runs. Critical: deduplication omits check-suite event identity (3 votes)
ai/​skills/​ci-monitor/​scripts/​ci-check-status.sh Uses a combined PR status query. Critical: rollup is limited to the first 100 contexts without pagination (1 vote)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ai/skills/ci-monitor/scripts/ci-check-status.sh
Comment thread ai/skills/ci-monitor/scripts/helpers/checks-rollup.jq
@@ -0,0 +1,203 @@
#!/usr/bin/env bash
@haacked
haacked merged commit 159cfd2 into main Sep 22, 2026
1 check passed
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