Repository navigation
Description
Problem Description
When Argo CD rejects the stored API token, every devops argo cd apps command that calls the Argo CD API ends in a Python traceback, and devops-cli never gets a new token.
cd_apps_sync(src/devops_cli/commands/argo.py) callsresp.raise_for_status(), so a 401 raiseshttpx2.HTTPStatusError. It is not aDevOpsCLIError, so the exit seam ofnew_typer()(fix(cli): every command reports a DevOpsCLIError through one exit seam #2502) does not report it, and the user sees a full traceback.resolve_argocd_server_and_token(src/devops_cli/argo/credentials.py) takes the storedargocd.tokenfirst.get_or_mint_argocd_token(src/devops_cli/k8s/credentials.py) mints a token withargocd.passwordonly when no token is stored. A stored token that the server rejects is never replaced. Argo CD session tokens expire, so after that every Argo CD API command fails until a person deletes the keyring entryargocd_tokenby hand.
Reproduction Steps
- Store an expired or revoked Argo CD token as
argocd.token(keyringargocd_token), withargocd.passwordalso stored. - Run
uv run devops argo cd apps sync <application>.
Expected vs Actual Behavior
- Expected: on a 401, the command mints a new token with the stored admin password, stores it, and sends the request again one time. When no password is stored, or the new token is also refused, it stops with one error line that names
argocd.tokenand the command that sets it. Any other HTTP error status is one error line with the status, with no traceback. - Actual (2026-10-29, origin/main
cabfcd43):
HTTPStatusError: Client error '401 Unauthorized' for url
'https://argocd.<domain>/api/v1/applications/prometheus-operator-crds/sync'
after a traceback through core/cli.py:197, core/cli.py:98 and commands/argo.py:295.
Environment Diagnostics
devops config show:argocd.tokenset,argocd.passwordset,argocd.urlset.- The same Application synced through
kubectl -n argocd patch application <name> --type merge -p '{"operation":{"sync":{...}}}', so the server and the Application were healthy; only the token was refused.
Logs, Traces, or Terminal Output
The traceback above. devops argo cd apps retire-helm-records, which reads through kubectl and not the Argo CD API, worked in the same session.
Existing Tool Considered
Argo CD's own session API (POST /api/v1/session) mints the token, and mint_argocd_token already calls it. The fix reuses it and maps HTTP errors to the existing Argo CD error class. Nothing new is built.
Proposed design
Problem statement
When Argo CD rejects the stored token with HTTP 401, each Argo CD API command ends in a Python traceback. The httpx2.HTTPStatusError is not a DevOpsCLIError, so the exit seam does not report it. The token path never replaces a stored token that the server refuses. The user must delete the keyring entry by hand.
Acceptance criteria
Requirement: Retry on 401 with stored password
When the Argo CD API returns HTTP 401 and an admin password is stored, the command SHALL mint a new token, store it in the keyring, and retry the request once.
Scenario: 401 with password stored
- WHEN the Argo CD API returns HTTP 401 and
argocd.passwordis stored in the keyring - THEN the command mints a new token via
POST /api/v1/session, stores it asargocd_token, and sends the original request again
Requirement: Error on 401 without password
When the Argo CD API returns HTTP 401 and no admin password is stored, the command SHALL stop with one error line that names argocd.token and the credential sync command.
Scenario: 401 without password
- WHEN the Argo CD API returns HTTP 401 and
argocd.passwordis not stored - THEN the command exits with one error line naming
argocd.tokenand the credential sync command, with no traceback
Requirement: Error on retry 401
When the retried request after minting a new token also returns HTTP 401, the command SHALL stop with one error line.
Scenario: retry also returns 401
- WHEN the command mints a new token and retries, and the Argo CD API returns HTTP 401 again
- THEN the command exits with one error line, with no traceback
Requirement: Error on other HTTP status
When the Argo CD API returns any HTTP status other than 401, the command SHALL stop with one error line containing the status code.
Scenario: HTTP 500 response
- WHEN the Argo CD API returns HTTP 500
- THEN the command exits with one error line containing the text '500', with no traceback
Requirement: Error is DevOpsCLIError
Every Argo CD API error SHALL be raised as a DevOpsCLIError subclass so the exit seam reports it.
Scenario: error type check
- WHEN the Argo CD API returns an error status
- THEN the raised exception is an instance of
DevOpsCLIError
Existing Tool Considered
No alternatives check has run. Argo CD's own session API (POST /api/v1/session) mints the token, and mint_argocd_token in src/devops_cli/k8s/credentials.py already calls it. The fix reuses this function and maps HTTP errors to the existing ArgoError class. Nothing new is built.
Key questions
- How should the 401 retry work across the Argo CD API commands?: A shared helper in
src/devops_cli/argo/credentials.pywraps the Argo CD API call. On HTTP 401, it mints a new token viamint_argocd_token, stores it, and retries the request once. The commands insrc/devops_cli/commands/argo.pycall this helper instead of a rawclient.postplusresp.raise_for_status. (best practice) [sources: src/devops_cli/argo/credentials.py, src/devops_cli/k8s/credentials.py, src/devops_cli/commands/argo.py]- Chosen: Shared helper in argo/credentials.py. One place for the retry logic, beside the existing token functions. Avoids duplicating the retry across four or more commands.
- Rejected: Per-command try/except in commands/argo.py. Duplicates the mint-and-retry logic in every command that calls the Argo CD API.
- Rejected: Pre-verify the token in resolve_argocd_server_and_token. Adds an extra HTTP call to every command. The body specifies a reactive retry on 401, not a proactive check.
- Which exception should the Argo CD API commands raise on HTTP errors?: Raise
ArgoErrorfromsrc/devops_cli/exceptions/argo.py. It is aDevOpsCLIErrorsubclass, so the exit seam ofnew_typer()reports it as one error line with no traceback. (best practice) [sources: src/devops_cli/exceptions/argo.py, src/devops_cli/commands/argo.py]- Chosen: ArgoError. Existing Argo CD error class. It is a DevOpsCLIError subclass, so the exit seam reports it with its message and exit code.
- Rejected: typer.Exit(1). Bypasses the exit seam. The user sees no structured error message.
- Rejected: A new exception class. Unnecessary. ArgoError already exists and is imported by the Argo commands.
- What should the error message say when no password is stored and the token is refused?: The error line names
argocd.tokenand the credential sync command that sets it, so the user knows what to fix. (best practice) [sources: src/devops_cli/k8s/credentials.py]- Chosen: Name the key and the sync command. Tells the user exactly which keyring entry to fix and which command to run.
- Rejected: A generic authentication-failed message. Does not tell the user how to fix the problem.
- Where should the retry helper function live?: In
src/devops_cli/argo/credentials.py, beside the existingresolve_argocd_server_and_tokenfunction. (best practice) [sources: src/devops_cli/argo/credentials.py]- Chosen: argo/credentials.py. Already holds Argo CD credential and token resolution logic. The helper belongs with the code it calls.
- Rejected: commands/argo.py. Mixes command logic with credential logic. The commands should call the helper, not define it.
- Rejected: A new module. Unnecessary for one function. Adds a file with no other content.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 29, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
A stored token rejection causes an unhandled traceback and blocks all Argo CD API commands.It blocks Argo CD API commands until a person deletes the keyring entry by hand, but a workaround exists.It restores all Argo CD API commands after token expiry without manual keyring edits.It needs a 401 retry path, token re-mint, and error mapping in two modules.Both manage Argo CD tokens, but #764 mints the token during deploy-stack while this candidate handles a rejected token at runtime with retry and clean errors.devops-cli-service commentedon Oct 30, 2026
Status set to Ready at 07fb4c2 (see proposed design in issue body).
devops-cli-service commentedon Nov 1, 2026
Staged: branch
fix/2576-a-token-that-argo-cd-refuses, draft pull request #3002. The pull request plans the item and closes no issue.The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:
docs(openspec): plan #2576 retry argo cd token on 401 (#3002)
docs(openspec): fix plan #2576 retry once on 401, real paths, tests (#…