Repository navigation
Description
Problem
Lines are at 132ecc5 on release/v0.2.25. At the branch head d37120b, the cited lines of config/constants.py moved down 10 and those of config/defaults.py moved down 5; every other cited line is unchanged. Paths are under src/devops_cli/ unless they start with tests/; a bare :N is a line of github/rate_limiter.py.
run_gh gives a request GitHub's write pacing only when _is_mutation_command (:498-509, called at :1919) says it is a write. Then _calculate_target_delay (:976-981) raises its wait to at least DEFAULT_GH_MUTATION_MIN_INTERVAL_SECONDS (1.0 s, config/defaults.py:773). That interval is GitHub's advice in "Best practices for using the REST API": when making many POST, PATCH, PUT or DELETE requests, wait at least one second between each. It is the limiter's only write-specific guard against GitHub's secondary limits: 80 content-generating requests a minute and 500 an hour, counted across REST, GraphQL and the web interface, and 2,000 GraphQL points a minute, where a request with a mutation costs 5. The classifier reads argv tokens only:
- A high-level gh command is a write when any token after the first is in
CONST_GH_MUTATION_VERBS(config/constants.py:2156-2178). - A
gh apicall is a write only when it has an explicit method token of POST, PUT, PATCH or DELETE (_is_api_mutation,:484-495). It misses-X=POST, a form gh accepts.
An offline run of _is_mutation_command at 132ecc5:
| Request | What gh sends | Answer today |
|---|---|---|
api graphql -f 'query=mutation ResolveThread(...) {...}' |
a GraphQL mutation | read |
api graphql --input -, with {"query": "mutation(...) {...}"} on stdin |
a GraphQL mutation | read |
api repos/o/r/pulls -f title=t -f head=h |
POST (implicit) | read |
api repos/o/r/rulesets --input file.json |
POST (implicit) | read |
project link 3 --owner o --repo o/r |
a write | read |
issue list --label sync |
a read | write |
api -X POST repos/o/r/issues -f title=t |
POST | write |
gh's rule is in gh api --help (gh 2.102.0): "The default HTTP request method is GET normally and POST if any parameters were added. Override the method with --method." gh's source (pkg/cmd/api/api.go at tag v2.102.0, line 329) applies the same switch to --input: if !opts.RequestMethodPassed && (len(params) > 0 || opts.RequestInputFile != "") { method = "POST" }. A gh api graphql call that carries a query therefore always POSTs, and whether it writes depends on the operation in the document, which nothing reads.
These writes skip the interval today:
github/pr_threads.py:_run_graphql_query(:72-87) sends theaddPullRequestReviewThreadReply,resolveReviewThreadandunresolveReviewThreadmutations (:146-180).resolve_all_pr_review_threads(:331-353,devops pr threads resolve-all) sends one resolve per thread, back to back.github/projects.py:_create_project_view(:1335-1347) and_rename_default_view(:1350-1362) sendcreateProjectV2ViewandupdateProjectV2View.roadmap/github_store.py:_graphql(:1456-1461) sendscreateProjectV2FieldandupdateProjectV2Field(:521-529) asgh api graphql --input -. The document is only inrun_gh'sinput, which the classifier never receives. The same module'sproject link(:1008) is a write missing from the verb list.commands/pr.py:_fallback_create_pr(:851-895) opens the pull request withgh api repos/{owner}/{repo}/pulls -f title=... -f head=...(implicit POST, argv at:876-890). Its docstring says it runs whengh pr createfails, for example on GraphQL rate limits, which is exactly when pacing matters.
There are two smaller gaps in the same path:
- The schedule is per resource. Each recognized write sleeps at least the interval before it goes out, so the writes one caller sends in sequence are at least 1 s apart, whatever their resource. Callers on different threads of one process are serialized per target only:
_acquire_locked(:1014-1042) schedules from_next_allowed_time[target], so a REST write (core) and a GraphQL write (graphql) acquired at the same moment are scheduled for the same instant. GitHub's best practices also ask for serial, not concurrent, requests._last_mutation_epochis set at:1036, initialized at:762, and never read. - No test calls
_is_mutation_commandor checks the interval._is_api_mutationis exercised only through the cache predicate (test_is_cacheable_api_call_rejects_all_mutations,tests/test_github_rate_limiter.py:779).rg -n "is_mutation|mutation_min_interval|_is_api_mutation" testsfinds nothing.
Acceptance criteria
- One classifier decides read or write from the request gh will send.
run_ghpasses itinput, pluscwdfor relative paths. Forgh api:- The method is the explicit
-X/--methodvalue in any form gh accepts (-X POST,-XPOST,-X=POST,--method POST,--method=POST, any case). - With no explicit method, it is POST when any
-f/--raw-field/-F/--field(attached forms included) or--inputis given, and GET otherwise. - A REST request is a write when its method is POST, PUT, PATCH or DELETE.
- A
graphqlrequest is a write when the operation it runs is a mutation. The document comes from thequeryfield (-f query=...,-F query=..., or-F query=@<file>and-F query=@-, which gh reads from a file or stdin;-fnever reads files) or from thequerykey of the--inputbody (stdin or a file). TheoperationNamefield or body key selects among several operations.
- The method is the explicit
- A table-driven test in
tests/test_github_rate_limiter.pycovers at least these cases:- every row of the table above, with the corrected answer;
- a mutation after a
#comment, and a mutation after a fragment definition; - a
{ ... }shorthand query (read); - a two-operation document whose
operationNameselects the query (read) or the mutation (write); -F query=@<file>with a mutation in a temporary file (write), and-f query=@<file>, whose file is not read because gh sends the value as a literal string;--method GET search/issues -f q=xand-XGET(read);-H 'Accept: ...'with no field (read);- a document that does not parse, an
--inputbody that is not JSON, an unreadable@fileand an argv that does not parse (all writes).
- High-level gh commands are classified by the verb in the verb position, not by any token.
gh project linkis a write, andgh issue list --label syncis a read. Every high-level read used insrctoday stays a read:issue list,label list,pr checks|diff|list|view,project field-list|item-list|list,release list|view,repo view,run list|view. Every high-level write used insrctoday stays a write, for exampleissue close|create,label create,pr close|create|edit|ready,project create|field-create|field-delete|item-add|item-create|item-delete|item-editandrelease edit. - The interval holds across resources. With the clock frozen and
time.sleeppatched, a REST write and a GraphQL write acquired at the same instant are scheduled at leastmutation_min_intervalapart; today both are scheduled for the same instant. A GraphQL query acquired at that instant is paced by its quota alone._last_mutation_epochis either read by the scheduler or removed. - The call sites get the interval. The subprocess runner is patched and
GitHubRateLimiter.acquireis spied. These acquire withis_mutation=True:resolve_all_pr_review_threadsover three threads (tests/test_github_pr_threads.py),_fallback_create_pr(tests/test_pr_cmd.py),_create_project_view(tests/test_github_projects.py) and the roadmap store's field creation throughrun_gh(tests/test_roadmap_github_store.py). The threads' list query acquires withis_mutation=False. - Caching is unchanged.
test_should_cache_predicates(tests/test_github_rate_limiter.py:273) andtest_is_cacheable_api_call_rejects_all_mutations(:779) pass unedited. - GraphQL documents are read with graphql-core (see Key questions). It is exact-pinned in
[project].dependencieslike the other runtime dependencies, anduv.lockis updated. It is imported only when agraphqlrequest is classified:python -X importtime -c "import devops_cli.github.rate_limiter"lists nographqlmodule. - The tests run offline. They start no real
gh, open no socket (prevent_external_network_calls,tests/conftest.py:99) and do not really sleep. Each new test takes under 1 s (pytest --durations=0), anduv run devops cipasses within its 5-minute budget. -
changelog.d/<issue>.mdexists,CHANGELOG.mdanddocs/ROADMAP.mdare untouched, anddevops pr check-readinesspasses. - Pending a person: on a throwaway pull request with four replied review threads, in a repository they own,
time uv run devops pr threads resolve-all <number> -R <owner>/<repo>resolves all four and takes at least 3 s, the floor that 1 s between four writes sets.
Key questions
- Should the classifier detect writes from the request, or should callers declare them? Proposed: detect them from the request. fix(github): gh calls no longer stall silently for up to a minute behind a fixed 60-call window, and the unmaintained
ratelimitpackage is removed #1118 sketches the other way: REST callers add--method POST, and GraphQL callers set a newrun_ghkeyword that is threaded through the roadmap store'sGhRunnerprotocol. A declaration is the step every call site above already missed.devops gh api(commands/gh.py:1285-1297) passes user arguments that no caller can declare. The document is already in argv or ininput, both of whichrun_ghholds, so no signature changes. That keeps the call sites that refactor(github): one github session per identity owning token, quota and transport #767 and refactor(github): the github session owns transport, ledger, error classes and link pagination #983 rewrite free of a new keyword, and refactor(github): the github session owns transport, ledger, error classes and link pagination #983 keepsrun_gh's call sites on their argv. Callers may still spell out--method POSTfor readability, but correctness no longer depends on it. - Should the GraphQL document be read with graphql-core or with a prefix check? Proposed: graphql-core, using
graphql.parseandgraphql.utilities.get_operation_ast. It is the reference Python port of GraphQL.js; 3.3.0 was released on 2026-09-27, lists Python 3.14 and has no dependencies. A "starts withmutation" check misreads a mutation that follows a comment or a fragment, and a multi-operation document selected byoperationName. It is also the kind of hand-written string check the project replaces with libraries. If the dependency is declined, no string check replaces it: the GraphQL callers insrcdeclare their writes the way fix(github): gh calls no longer stall silently for up to a minute behind a fixed 60-call window, and the unmaintainedratelimitpackage is removed #1118 sketches, and an undeclaredgh api graphqlrequest, such as one fromdevops gh api, counts as a write. Pending a person: approval of the new runtime dependency. - How should gh's argv be parsed? Proposed: with the standard library's
argparse, declaring every flaggh api --helplists and usingparse_known_argsfor the rest. No library parses gh's flags. On Python 3.14, argparse accepts the attached,=and combined forms that gh's flag parser accepts (-XPOST,-X=POST,--method=POST,-fkey=v,-iXPOST). The parser is built withallow_abbrev=False, because gh accepts no abbreviated long flags, andexit_on_error=False, so a malformed argv raisesargparse.ArgumentErrorinstead of exiting. An argv that fails to parse is a write. - Which way do uncertain cases fall? Proposed: they count as writes. A false write costs at most one second. A false read sends an unpaced write toward a secondary limit, and the backoff after that is 60 s to 300 s (
DEFAULT_GH_SECONDARY_RATE_WAIT,DEFAULT_GH_SECONDARY_MAX_CAP,config/defaults.py:774-775). For high-level commands this means replacing the write-verb list with a read-verb set:view,list,status,checks,diff,show,item-listandfield-list, which_is_cacheable_cli_readalready uses (:1345-1359), plus thesearchgroup. Every other verb is a write.gh authstays exempt from pacing (_is_rate_limit_exempt,:1440-1447), soauth tokenandauth statuspay nothing. The known commands that change side areproject linkand commands with a verb-like option value. - Should the interval span resources and processes? Proposed: it should span resources, but not processes in this item. GitHub's advice covers mutative requests whichever API they use, its content-creation limits count REST and GraphQL together, and
_last_mutation_epochexists for this purpose but is never read. Sequential callers already get the spacing, because each write sleeps first; the gap is concurrent callers in one process. Cross-process spacing is a separate gap: the per-target schedule is not persisted either (_persist_to_disk_locked,:800-810). A shared write clock belongs with the per-identity session of refactor(github): one github session per identity owning token, quota and transport #767 and refactor(github): the github session owns transport, ledger, error classes and link pagination #983. - Should the limiter count GitHub's secondary points or the hourly content-creation limit? Proposed: no. The 1 s interval keeps one process at 60 writes a minute, under the 80-a-minute limit. Counting points or the hourly 500 belongs to refactor(github): the github session owns transport, ledger, error classes and link pagination #983's ledger, if the throttle counters (feat(github): github api request and throttle counters for the devops-cli dashboard #814) ever show secondary-limit hits.
- Is this a release fix? Proposed: no. No secondary-limit incident has been traced to these writes. The roadmap tooling places it.
Strategic alignment
- Priority P2, no milestone. The item closes a pacing gap on writes the limiter already means to pace; there is no measured incident.
- Value / Effort: Medium / Medium. Bulk thread resolves, roadmap field writes, project view writes and the REST pull request fallback get GitHub's write pacing, and
devops gh apipassthroughs get it without the user spelling out a method. The change is one module (classifier and scheduler), one new runtime dependency, one table-driven test and call-site assertions in four existing test files. One PR. - fix(github): gh calls no longer stall silently for up to a minute behind a fixed 60-call window, and the unmaintained
ratelimitpackage is removed #1118 removes theratelimitburst ceiling from the same module (:31,:59-83, call sites at:1546,:1642and:1750). After fix(github): gh calls no longer stall silently for up to a minute behind a fixed 60-call window, and the unmaintainedratelimitpackage is removed #1118, the writes listed above have nothing but quota spacing: its "Do the writes_is_mutation_commandmisses lose protection?" answer names this gap and leaves it to a separate item, which this is. Neither item depends on the other, and they edit different functions: this one changes:484-509,:976-981,:1014-1042, therun_ghcall at:1919and, if the read-verb set is shared with the cache,:1345-1367. Whichever lands second rebases. Landing this item in the same release as fix(github): gh calls no longer stall silently for up to a minute behind a fixed 60-call window, and the unmaintainedratelimitpackage is removed #1118, or earlier, keeps the gap from widening. - fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120 (the deptry gate) also edits
[project].dependenciesanduv.lock. Whichever lands second re-runsuv lock. graphql-core is imported directly, so deptry reports nothing for it. - refactor(github): the github session owns transport, ledger, error classes and link pagination #983 (v0.2.28) moves GitHub onto a session with
session.rest(method, path)andsession.graphql(query, variables). Those requests already know their method and document. So the classifier takes a request description (method, endpoint, document, operation name), and the gh argv parser only builds that description. refactor(github): the github session owns transport, ledger, error classes and link pagination #983's adapter then calls the same classifier. refactor(github): the github session owns transport, ledger, error classes and link pagination #983's answer to "DoesMutationBudgetgo?" already names_is_mutation_commandas the place where GitHub's content-creation limits stay. - refactor(github): one github session per identity owning token, quota and transport #767 (v0.2.26) removes the GraphQL client, so its
gh api graphql -f query=...fallback (github/graphql.py:753) is not listed above; until then it gets the same detection from its argv. refactor(github): the github, roadmap and git tables move out of config/ next to their owners #1026 moves thegithub/tables out ofconfig/after refactor(github): the github session owns transport, ledger, error classes and link pagination #983. If this item lands first, refactor(github): the github, roadmap and git tables move out of config/ next to their owners #1026 moves the verb tables as this item leaves them; otherwise this item edits them where refactor(github): the github, roadmap and git tables move out of config/ next to their owners #1026 put them. feat(ci):devops pr update --dispatch-cistarts ci.yml on each branch it updates, and only update-prs.yml may holdactions: write#984 relies ongh api -X POSTbeing paced as a write, and that answer is kept. - Libraries first: graphql-core for GraphQL documents and
argparsefor gh's flags. The only rule written by hand is gh's documented method default.
Amended 2026-10-03: board reads stay within GitHub's GraphQL budget
The owner asked (2026-10-03) to "ensure that we aren't handling old closed items during these github iterations … to help manage the gh api limits". Measured the same day:
-
Two
devops roadmap migrateattempts used 4,971 of the 5,000-point hourly GraphQL budget in about five minutes, roughly 2,500 points each. Board 2 holds 931 items: 662 issues and 269 pull requests, 651 of them closed. -
The store reads the board with
gh project item-list --limit N(roadmap/github_store.py:1308-1327), which fetches every field of every item and applies no filter.ProjectV2.itemscounts archived items by default: 932 in total, 931 witharchivedStates: [NOT_ARCHIVED], and 280 withquery: "is:open". Archiving therefore does not shrink the read. -
gh api rate_limit(REST) reported 4,899 GraphQL points left while GraphQL's ownrateLimit{remaining}was 17. -
Every board read passes a Projects filter at the source, such as
gh project item-list --query "is:open is:issue"oritems(query:, archivedStates: [NOT_ARCHIVED]). Each job declares the filter it needs; migrate's one-time reads may include closed items. The fail-closed count check compares against the filtered total, and no full listing is filtered by hand. -
Before a board read, a run asks GraphQL for
rateLimit{remaining}and stops with a clear message, spending nothing, when the remaining budget is below the read's measured cost. -
A count that changes during a read is re-read once before the run fails closed. A count of 931 against 932 stopped a migrate run on 2026-10-03.
-
A test pins the GraphQL cost of a reprioritize run against a fixture board of 931 items, 280 of them open.
-
Archived items never fail the read.
gh project item-listleaves archived items out, but the total the store checks against counts them. On 2026-10-04 one archived item made migrate stop with "Read 930 of 931 board feat(release): v0.1.8 #2 items" twice. The check compares the read against the total for the same filter (archivedStates: [NOT_ARCHIVED]or the same--query), and a test archives one fixture item. The board's auto-archive workflow (is:closed updated:<@today-1w) stays off until this lands.
Amended 2026-10-04: the limiter charges GraphQL points, and dry runs are cheap
The owner (2026-10-04): "if you used request quota, then it's not really a dry run … I bet the dry run even bypasses the rate limit".
-
The limiter counts calls, not points. The roadmap store sends every call through
run_gh(roadmap/github_store.py:669), andrun_ghcharges 1 perghinvocation (github/rate_limiter.py:1561,_post_process_run(..., cost=1)).gh project item-list --limit Nis one invocation, but it pages the board internally with GraphQL queries that request every field of every item.devops roadmap reprioritize --dry-runspent 2,025 GraphQL points on 2026-10-04 (5,000 before, 2,975 after) while the limiter recorded 1. The limiter cannot see the cost, so it cannot pace or refuse it. -
A dry run costs as much as a real run. It writes nothing but reads the whole board.
-
Board and other GraphQL reads go through the store's own paged GraphQL query, not
gh project item-list. Each page requestsrateLimit { cost remaining resetAt }, charges the limiter the reported cost, and stops before a page whenremainingis below a budget floor (a named constant). -
run_ghcharges GraphQL commands by points where the response reports them. Aghcommand that can't report its cost (for examplegh project …) is not used for reads that page. -
A dry run makes no request at all (feat(cli): reachable
--dry-runpreviews for delegated commands #412, owner's definition of 2026-10-04). Every real run, and every read-only preview (--plan, feat(cli): reachable--dry-runpreviews for delegated commands #412), ends with one line giving the GraphQL points spent and the points left, read from GraphQL itself. -
A test with a fake runner pins the charged cost of a fixture board read and the refusal below the floor.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
test(release): the offline uv lock check names its interpreter, so it…
fix(github): github writes are paced from the request gh sends, and b…
dan-petty commentedon Oct 4, 2026
Closed by #1166, merged into
release/v0.2.26.GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by
devops gh issues close-merged.feat(release): v0.2.26 (#1178)
refactor(github): the internal paginated reads go through the session…
refactor(roadmap): the roadmap store reads its REST listings through …
feat(release): v0.2.37 (#1720)