Skip to content

org-wide discovery aborts on a flaky multi-page GraphQL listing: --limit 1000 502s where --limit 100 does not #290

Closed

Description

@aitrawog

What happened

Every org-wide script aborts before doing any work:

$ bash scripts/reconcile-tag-on-merge-callers.sh
HTTP 502: 502 Bad Gateway (https://api.github.com/graphql)
FATAL: discover_repos failed

That is discover_repos in scripts/lib-org.sh — the first step of org-ruleset.sh verify, reconcile-tag-on-merge-callers.sh, retire-per-repo-dispatchers.sh, retire-per-repo-candy-gates.sh and governance-reconcile.sh. None of them has an alternative path, so a flake in discovery means no org report at all.

The mechanism

The org's discovery query is one GraphQL listing at --limit 1000 with four fields. The org now holds 486 repos, so that listing is five paginated requests. Under current gateway conditions the later pages intermittently return 502/504, and the whole command fails:

$ gh repo list opencharly --limit 1000 --json name,isArchived,isFork,defaultBranchRef --jq 'length'
486

$ gh repo list opencharly --limit 200 --json name,isArchived,isFork,defaultBranchRef --jq 'length'
200

$ gh repo list opencharly --limit 1000 --json name,isArchived,isFork,defaultBranchRef --jq 'length'
HTTP 502: 502 Bad Gateway (https://api.github.com/graphql)

$ gh repo list opencharly --limit 200 --json name,isArchived,isFork,defaultBranchRef --jq 'length'
200

Interleaved in that order, so the variable is the QUERY SIZE, not the minute. The same shape shows at the other sizes tried: --limit 100 and --limit 200 succeeded on every attempt, --limit 500 and --limit 1000 produced 502, and one --limit 1000 produced 504 Gateway Timeout.

Small queries are healthy throughout, which rules out "the API is down":

$ gh api graphql -f query='{viewer{login}}' --jq '.data.viewer.login'
aitrawog

$ gh api graphql -f query='{organization(login:"opencharly"){repositories(first:1){nodes{name}}}}' --jq '.data.organization.repositories.nodes[0].name'
marketplace

$ gh api "orgs/opencharly/repos?per_page=100&page=5" --jq 'length'
86

REST paging answered pages 2-5 as 100, 100, 100, 86 without a single failure while the GraphQL listing was failing (page 1 was not separately requested; the org total 486 is from the GraphQL listing that did succeed).

The missed control

discover_repos and discover_excludes have no classification of a provider error: they run under set -o pipefail, return non-zero on any gh failure, and every caller turns that into FATAL. There is no distinction between "the org has no repos", "this token cannot read them" and "page 4 of 5 502'd" — all three abort identically, and nothing retries or narrows the request.

The repo's own tests cannot see this class at all: org-ruleset_test.sh, reconcile-tag-on-merge-callers_test.sh and the retirement tests substitute a mock gh, so the coverage proves the logic around discovery and never the provider behaviour of discovery itself.

Blast radius

Every org-wide operation, measured today:

  • reconcile-tag-on-merge-callers.sh — four consecutive attempts across ~25 minutes failed at discovery, so the #204 rollout (which also carries the #286 assertion and the #215 schedule backstop into every per-repo caller) could not start.
  • org-ruleset.sh verify — the org end-state assertion is unreachable for the same reason.
  • The retirement scripts — same discovery, same abort.

This is not a content defect in any repo; it is the org's inability to enumerate its own repos reliably right now.

What would close it

Either one closes the immediate failure; both are small and local to lib-org.sh:

  1. Page discovery at a size the gateway serves reliably. --limit 100/--limit 200 were stable across every attempt while 500/1000 were not. Chunking the listing (or using REST orgs/:org/repos paging, which served 5/5 pages cleanly here) removes the failure without any retry.
  2. Classify the transient class in discovery only — a bounded retry of a 5xx on a discovery page, failing loud when it persists, so a socket reset costs a second rather than the whole report.

The same tension as #286 applies to (2): a blind retry is what R3 forbids, so it is worth taking (1) first — it removes the failure rather than absorbing it.

Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

Activity

  1. aitrawog commented on Nov 9, 2026

    @aitrawog
    ContributorAuthor

    CLAIM

    Taking option 1 from the issue body — remove the failure rather than absorb it: discovery pages at a size the gateway serves reliably, so no retry is involved (option 2 would be the R3-sensitive one, and I would rather not have a retry in the org's step zero).

    Intended shape, to be measured before it is written:

    • discover_repos / discover_excludes stop issuing one --limit 1000 listing and page explicitly, with the page size named once.
    • Each page's response is checked before it is parsed, so a truncated or failed page cannot read as "no repos" — that is the second half of the defect, since a silent empty list would look like a smaller org to every caller (the same class the mapfile < <(fn) note in the file already warns about).
    • The existing mock-gh tests get a fixture that serves MULTIPLE pages and one whose second page fails, so the coverage distinguishes a complete discovery from a partial one.

    I will not run the #204 rollout from this same change: that is 486 outward writes and belongs in its own operation once discovery is trustworthy.

    Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
    Assisted-by: Claude Code deepseek-v4.1-flash:cloud

  2. aitrawog commented on Nov 9, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED

    #291 MERGED 2026-11-09T18:49:49Z, squash 38a0b65c30e1c30bbc6973653fc48d3c4e9d385e, tag v2026.313.1849 verified pointing at exactly that merge. Verdict ## Review — PASS; workflow-checks and lint green on every head of the branch.

    What landed: discover_all pages REST at one named page size and refuses a truncated repo set (count checked against the org's own total), with the two filters and the membership arm deriving from it; org-ruleset.sh's membership arm no longer issues its own --limit 1000 listing. No retry anywhere (R3) — the failure was removed, not absorbed.

    Proof it removed the failure: the reconcile that died four times at FATAL: discover_repos failed now walks the org and exits 0 —

    repos examined     : 431
      pin-mutable (still unpinned)  : 406
      prose-drifted                 : 415
    RC=0

    Closed explicitly, not by Closes — native auto-merge does not run GitHub's post-merge side effects, which is the same platform behaviour this programme has recorded repeatedly; the keyword was in the body and the issue was still OPEN after the merge.

    Residual, filed rather than left implicit: #292 — the filters each issue their own read, so a script performs two or three paged listings and a repo created between them lands in neither set. That is a consolidation, not a correctness gap: every read is count-checked and every call site aborts on failure.

    Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
    Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions