fix(cli): treat a wrapper-polluted gh auth token capture as no token #138457
All Vouch review confidence checks passed
Residual risk 0.44 = Change Risk (0.80) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.80 · 609 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.384
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.080
Real PR Conversation Timeline
1 comments
"Review active on #138457"
general
weight: 0.35
PRATHAMESH75
What does this PR do?
Fixes the updater failing closed whenever
ghresolves to a PATH wrapper that prints to stdout (#138444) — mise/asdf shims, corporate hooks.gh auth token's capture then holds wrapper chatter plus the token; the embedded newline makeshttp.clientreject theAuthorizationheader (Invalid header value b'Bearer …') before any bytes are sent, so the 401→anonymous fallback never engages andhermes update(and the Desktop update check, which shares the ladder) aborts.Two complementary hardenings, both suggested in the issue:
1. Capture time (root fix) —
hermes_cli/github_api.py::_gh_cli_token()no longer trusts the raw capture. The token is the last non-empty line, and only when it is shaped like a GitHub token (gh[a-z]_…classic prefixes,github_pat_…fine-grained). Anything else means no token: the ladder continues to anonymous, with a debug log (the capture itself is never logged).2. Request time (defense in depth) —
hermes_cli/source_check.py::_request()catches the invalid-headerValueErrorand retries anonymously, mirroring the existing 401 fallback. This also covers a malformedGITHUB_TOKEN/GH_TOKENenv value, and it keeps thatValueError's message — which quotes the header, token included — out of the user-facing failure copy (describe_github_failurerenders unknown exceptions asapi.github.com: {exc}).The env rungs are deliberately not shape-checked: a token the user set explicitly is their intent, and the request-time fallback already covers it.
Related Issue
Fixes #138444
Type of Change
Changes Made
hermes_cli/github_api.py—_gh_cli_token()takes the last non-empty line of the capture and requires a GitHub token shape (_GITHUB_TOKEN_SHAPE); a non-matching capture is treated as no token (debug-logged without the capture, ladder falls through to anonymous).hermes_cli/source_check.py—_request()retries anonymously on an invalid-headerValueError(only when a token was used; with no token the error still propagates); docstring updated.tests/hermes_cli/test_github_token_capture.py— new: wrapper noise dropped, clean capture kept, no-shape capture ignored, fine-grained shape accepted, non-zero exit ignored, probe-once caching preserved,ValueError→ anonymous retry, malformed token never leaks into logs, unrelatedValueErrorstill propagates.How to Test
1.
pytest tests/hermes_cli/test_github_token_capture.py -q— Observed result:9 passed.2. Ladder regressions:
pytest tests/hermes_cli/test_source_check.py tests/hermes_cli/test_doctor_github_token_probe.py -q— Observed result:87 passed. (tests/hermes_cli/test_source_release_channels.pyhas 2 failures on this host that reproduce identically on a cleanupstream/mainworktree —home_io_guardenvironment noise, files untouched by this PR.)3.
python -m ruff check hermes_cli/github_api.py hermes_cli/source_check.py tests/hermes_cli/test_github_token_capture.py— Observed result:All checks passed!.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass — targeted suites quoted above; the changed-code suites are green on this hostpython scripts/checkpasses —ruff checkgreen on all three changed files; hostruff format --checkdiverges only on pre-existing code (reproduces on untouched files such ashermes_cli/main.py), formatting of the changed lines follows the file's existing styleDocumentation & Housekeeping
docs/, docstrings) — docstrings updated in place; or N/A beyond thatcli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/Aghprobe is already Windows-hardened viawindows_hide_flags(); the change itself is pure-Python string handling