Skip to content

fix(github): keep the gh quota cache out of the working repository #6529

Done

Description

@dan-petty

Problem

devops gh writes its quota ledger and response cache under data.cache_dir of the repository of the working directory: .data/cache/<identity digest>/gh_quota.json and gh_quota.lock (resolve_identity_cache_dir, src/devops_cli/github/rate_limiter.py:1449-1463). A repository that does not ignore .data/ then shows these files as new files. On 2026-11-20 a builder ran devops gh in a clone of dan-petty/devtools and committed both files to dan-petty/devtools#14. They held quota counts and reset times, and no token. A person removed them in a later commit.

The quota ledger belongs to the GitHub identity, not to a repository. Two repositories that use one identity keep two ledgers that do not know about each other.

Change

Keep the quota ledger and the response cache of an identity in the user cache directory (for example platformdirs.user_cache_dir, which the project already uses for other user data), not under the repository of the working directory. A run in any repository then writes no file into that repository.

Proof

  • A test runs the quota cache path resolution with the working directory in a temporary Git repository and finds no path under that repository.
  • git status --porcelain in a repository with no .data/ ignore rule shows no new file after devops gh api rate_limit.

Source: dan-petty/devtools#14

Alternatives check of 2026-11-20: in-use.
The repository already uses this tool.
Tool: platformdirs (https://pypi.org/project/platformdirs), MIT, last activity 2026-11-20, maintained.
Reason: Searches returned no dedicated tool for relocating a quota ledger; platformdirs, already used by the project, gives the per-user cache directory the change needs, but the path resolution, identity-scoped files and tests stay project code.

Covers:

  • Per-user cache directory path per platform
  • Windows, macOS and Linux path conventions
  • Pure-Python, no configuration needed

Lacks:

  • Moving the quota ledger and lock files
  • Identity-scoped cache layout and locking
  • Tests that no file lands in the repository

Proposed design

Problem statement

The quota ledger and response cache of a GitHub identity live under data.cache_dir of the working repository. A devops gh run in a clone writes gh_quota.json and gh_quota.lock into that clone, and a person can commit them. The ledger belongs to the identity, not the repository, so two repositories keep separate ledgers. Move the identity cache to the user cache directory, so a run in any repository writes no cache file into that repository.

Acceptance criteria

Requirement: Identity cache root outside the repository

The identity cache root SHALL resolve under the user cache directory that platformdirs.user_cache_dir returns for the application, not under the working repository.

Scenario: Path resolution from a temporary Git repository

  • WHEN A test sets the working directory to a temporary Git repository and calls resolve_identity_cache_dir with a fixed identity.
  • THEN The returned path is not inside the temporary repository and has the platformdirs user cache directory as a parent.

Requirement: Identity-scoped quota path

The quota ledger path SHALL keep the identity digest directory under the user cache root.

Scenario: Quota ledger path for one identity

  • WHEN A test fixes the session identity and calls resolve_quota_cache_path.
  • THEN The path parent is resolve_identity_cache_dir for that identity and the file name is gh_quota.json.

Requirement: No cache file in the working repository

A devops gh api rate_limit run SHALL write no quota ledger, lock file or response cache file under the working repository.

Scenario: Rate-limit command in a temporary Git repository

  • WHEN A test runs the rate-limit command path with a stubbed GitHub response and the working directory in a temporary Git repository that has no .data ignore rule.
  • THEN git status --porcelain reports no new file for the quota ledger, lock file or response cache.

Existing Tool Considered

platformdirs (https://pypi.org/project/platformdirs) has the verdict in-use in the alternatives check in the issue body. The check records that the repository already uses platformdirs and gives what it covers and lacks. The proposal uses platformdirs.user_cache_dir for the per-user cache root, keeps the identity-scoped digest directory and the quota ledger, lock and response-cache files as project code, and tests that no cache path lands in the working repository.

Key questions

  • Which base directory should hold the identity-scoped quota ledger and response cache?: Use platformdirs.user_cache_dir for the devops-cli application, then keep the identity digest directory below it. (best practice) [sources: src/devops_cli/github/rate_limiter.py:1449]
    • Chosen: platformdirs user cache directory. It gives the per-user cache path on each platform, and the alternatives check records platformdirs as in use.
    • Rejected: repository data.cache_dir. It writes under the working repository, which is the defect.
    • Rejected: project-built per-platform path. It repeats platformdirs path rules and adds platform-specific code to keep.
  • Should the identity digest directory remain below the new cache root?: Yes. Keep the SHA-256 digest directory so different identities and tokens keep separate ledgers and response caches. (best practice) [sources: src/devops_cli/github/rate_limiter.py:1449]
    • Chosen: Keep the identity digest directory. The current function separates identities and tokens by digest, and platformdirs does not supply that layout.
    • Rejected: Use one flat user cache directory. It mixes identities and breaks the per-identity quota accounting.
  • Should the response cache and quota ledger share one identity cache root?: Yes. Both callers use resolve_identity_cache_dir, so one root moves both caches out of the repository. (best practice) [sources: src/devops_cli/github/rate_limiter.py:1463, src/devops_cli/github/session.py:71]
    • Chosen: One identity cache root for both caches. The quota ledger and response cache already share the root, and one root keeps identity data together.
    • Rejected: Separate roots for quota and responses. It adds two layouts and can split one identity's cache across directories.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/github
    source/agent
    status/new
    value/medium
    effort/low
    on Nov 20, 2026
  2. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor
    • Related: One data directory across git worktrees #553, which asks for a different change. Both items change where the data directory resolves; #553 pins it to the main worktree while the candidate moves the quota cache out of the repository to the user cache dir.
  3. added
    priority/p2-medium
    on Nov 20, 2026
  4. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (4)

    Tools considered:

    Searches run:

    • platformdirs user_cache_dir python library, results: 5
    • platformdirs documentation user cache directory XDG, results: 5
    • platformdirs python package github tox-dev user cache dir, results: 5
    • platformdirs.readthedocs.io api user_cache_dir, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  6. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    on Nov 23, 2026
  8. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 23, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/githubsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions