Skip to content

fix(github): a slow gh auth token on a loaded host reads as logged out #4940

Closed

Description

@dan-petty

Problem Description

devops gh api failed once with "GitHub is not authenticated: gh auth token could not run (no answer within 5 s)". The same command passed when it ran again some seconds later. The devcontainer had a load average of about 40 on 16 cores at that time, because other agents ran tests.

_lookup_github_token in src/devops_cli/core/process.py gives gh auth token DEFAULT_GH_AUTH_TOKEN_TIMEOUT_SECONDS (5.0 s, src/devops_cli/config/defaults.py). On a loaded host, the start of the gh process alone can take more than 5 s, so a valid login reads as "not authenticated". The command then stops with no retry.

Reproduction Steps

  1. Put load on the host (for example, three pytest -n 3 runs at the same time).
  2. Run uv run devops gh api repos/<owner>/<repo>/pulls/<n> --jq .state some times.
  3. One run in some fails with the message above.

Expected vs Actual Behavior

Expected: a slow gh auth token on a loaded host does not make a valid login read as "not authenticated". For example, the lookup tries once more, or its limit fits the measured start time of gh under load.

Actual: the first lookup that takes more than 5 s ends the command with an authentication error.

Environment Diagnostics

devops-cli main at ed84240, the devcontainer (rootless Podman on WSL2), 2026-11-12.

Logs, Traces, or Terminal Output

✗ GitHub is not authenticated: `gh auth token` could not run (no answer within 5 s). Check that gh is installed, on PATH and answering, then run 'gh auth login' or set GH_TOKEN.

Alternatives check of 2026-11-15: none.
Tool: none found.

Proposed design

Problem statement

_lookup_github_token in src/devops_cli/core/process.py gives gh auth token a limit of 5 s, from DEFAULT_GH_AUTH_TOKEN_TIMEOUT_SECONDS. On a loaded host the start of the gh process alone can take longer than 5 s. A valid login then reads as not authenticated, and the command stops with no retry. The change makes the lookup try once more, so a slow host does not turn a valid login into an authentication error.

Acceptance criteria

Requirement: Retry after a timeout

The token lookup SHALL run gh auth token again when an attempt times out and an attempt remains.

Scenario: The first attempt times out and the second answers

  • WHEN the first gh auth token call raises subprocess.TimeoutExpired and the second call returns a token
  • THEN the lookup returns that token and run_subprocess is called exactly twice.

Requirement: Bounded attempts

The lookup MUST stop after DEFAULT_GH_AUTH_TOKEN_ATTEMPTS attempts and return the unauthenticated message.

Scenario: Every attempt times out

  • WHEN each attempt of gh auth token raises subprocess.TimeoutExpired
  • THEN the lookup returns an empty token and the timed-out message, and run_subprocess is called exactly DEFAULT_GH_AUTH_TOKEN_ATTEMPTS times.

Requirement: No retry of a missing gh

The lookup MUST NOT retry an attempt that fails with OSError or with an exit status other than zero.

Scenario: gh is not on PATH

  • WHEN the first gh auth token call raises OSError
  • THEN the lookup returns the not-found message and run_subprocess is called exactly once.

Requirement: The retried token is kept

The process SHALL keep a token that a retry finds, so a later GitHub call runs no gh auth token.

Scenario: A second GitHub call after a retried lookup

  • WHEN the lookup finds a token on its second attempt and github_token() is called again
  • THEN github_token() returns the same token and runs no subprocess.

Existing Tool Considered

No open tool covers this need. The alternatives check of 2026-11-15 found none: no external tool changes the 5 s limit that _lookup_github_token gives gh auth token, and no external tool retries the lookup inside the process code of the project. The change builds its own code: an estimated 3,000 tokens to build the retry, 1,000 tokens to keep and fix it, and about 1 hour of elapsed time.

Key questions

  • How does the lookup recover from a gh auth token that a loaded host slows past the timeout?: Retry the call once, with the same limit of 5 s for each attempt and 2 attempts in total. (best practice) [sources: src/devops_cli/core/process.py:330, src/devops_cli/config/defaults.py:802]
    • Chosen: One retry with the same per-attempt limit. The reported run passes some seconds later, and the total wait stays at 10 s.
    • Rejected: Raise DEFAULT_GH_AUTH_TOKEN_TIMEOUT_SECONDS to 30 s. github_token() passes retry_now=True, so a broken gh blocks every GitHub call for 30 s.
    • Rejected: A larger limit for the second attempt. It doubles the worst case and makes the test depend on the second limit.
  • Where does the retry go?: Inside _lookup_github_token, the one place that sets the limit and reads the timeout error. (best practice) [sources: src/devops_cli/core/process.py]
    • Chosen: Inside _lookup_github_token. It sets the timeout of the call and it turns the timeout into the error message.
    • Rejected: Inside _session_github_token. It keeps a failure for DEFAULT_GH_AUTH_TOKEN_RETRY_SECONDS, and github_token() skips that record with retry_now=True, so a retry there never runs for devops gh api.
    • Rejected: Inside DefaultProcessRunner.run. It would retry every subprocess, not only the token lookup.
  • What holds the number of attempts?: A new constant DEFAULT_GH_AUTH_TOKEN_ATTEMPTS in src/devops_cli/config/defaults.py, beside DEFAULT_GH_AUTH_TOKEN_TIMEOUT_SECONDS, with the value 2. (best practice) [sources: src/devops_cli/config/defaults.py:802]
    • Chosen: DEFAULT_GH_AUTH_TOKEN_ATTEMPTS in src/devops_cli/config/defaults.py. The sibling limit lives there, and a test can set the value to 1 to check the one-attempt path.
    • Rejected: A literal 2 in _lookup_github_token. No test can change it to 1.
    • Rejected: A new settings key. No setting holds the sibling limit, and this change adds no operational key.
  • Does an OSError from the start of gh also retry?: No. Only a timeout retries. An OSError returns its message at once. (best practice) [sources: src/devops_cli/core/process.py]
    • Chosen: Only a timeout retries. The issue shows a timeout, and an OSError that repeats, such as a missing gh, would only double the error path.
    • Rejected: An OSError also retries. The issue shows no such failure, and the not-found message must stay fast.
  • Does the retry need a new metric or span?: No. Each attempt runs in DefaultProcessRunner.run, so it gets its own subprocess.gh span and its own SUBPROCESS_DURATION sample. (best practice) [sources: src/devops_cli/core/process.py]
    • Chosen: No new metric. The duration of each attempt is already measured and emitted.
    • Rejected: A retry counter. The second attempt is a second span of the same program, and a counter adds a metric with no reader.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/github. The (github) scope of the title gives the scope.
    • Priority: P2-Medium. Intermittent spurious failure under load, not a data-loss or security issue.
    • Value: Medium. Causes a valid login to read as unauthenticated only on a loaded host, so impact is limited to that condition.
    • Effort: Low. The fix is a retry or a longer constant in one function in process.py.
    • Related: fix(github): the session retries a read that loses its connection #3506, which asks for a different change. Both retry a failed GitHub interaction, but the candidate fixes the gh auth token subprocess timeout while #3506 retries a lost HTTP connection on a GET.
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches for a library that handles subprocess timeouts or retries around gh auth token returned only generic Python/HTTP retry documentation, not a tool that addresses this. The need is a change inside the project's own _lookup_github_token (a retry, or a timeout that fits the measured start time of gh under load), which no external library can supply.

    Tool: none found

    Lacks:

    • No external tool changes the 5 s limit that _lookup_github_token gives gh auth token
    • No external tool retries the token lookup inside the project's process code
    • The fix is a retry or a longer timeout constant in src/devops_cli/core/process.py / src/devops_cli/config/defaults.py

    Searches run:

    • gh auth token subprocess timeout retry CLI, results: 5
    • python retry subprocess timeout library tenacity, results: 5
    • library to retry flaky subprocess calls with timeout python, results: 5
    • tenacity python retry library, results: 5

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

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

    @devops-cli-service
    Contributor

    Status set to Ready at fccb781 (see proposed design in issue body).

  7. added
    status/in-progress
    and removed
    status/ready
    on Nov 17, 2026
  8. removed
    status/in-progress
    on Nov 17, 2026
  9. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor
  10. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-17 19:36 UTC

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