Skip to content

feat(wif): retry the exchange and API 401s, and say what to fix on every OAuth error - #273

Open
nicknisi wants to merge 6 commits into
riker/239-spike-the-workos-cli-workos-cli-workos-afrom
wif/p13-cli-268
Open

nicknisi wants to merge 6 commits into
riker/239-spike-the-workos-cli-workos-cli-workos-afrom
wif/p13-cli-268

Conversation

@nicknisi

@nicknisi nicknisi commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Stacked on #268. Review this after it; the diff here is only what was added on top.

What changes

  • Retries. A failed exchange is retried on a network error (including a connection that drops while the response is read) or a 5xx, three attempts in total (0.5 s, then 1 s). A 4xx is final. A request sent with a WIF token is re-sent once after a 401, with a freshly exchanged token.
  • Errors that say what to fix. Every OAuth error from the exchange now has a hint, including unauthorized_client: check that the client has an active trust, that workload identity federation is on for the team, and that the client targets a non-production environment.
  • Docs. The READMEs cover retries, unauthorized_client, and WORKOS_ENVIRONMENT_ID being optional (it must match the client's bound environment when set).
  • A WIF failure during a request is reported as itself, not as "Failed to connect to WorkOS API".

The branch also merges main (release 0.24.0), so the release files show in the diff.

The server now issues one-hour tokens. The CLI reads expires_in, so only a comment changed. Its fallback when a response has no expires_in stays 300 seconds.

Checked

Not checked

  • A deployed WorkOS token endpoint. The server side is in review as a stack starting at workos/workos#79789.
  • bun run build.
  • A 503 from the exchange. The server now sends one when its replay store is down. The CLI retries any 5xx with a fresh GitHub token; that path has unit tests and was not run against a real 503.
  • The wording still says "M2M application" and "trust rule", as feat: authenticate in GitHub Actions with workload identity federation #268 does. The server side is moving to "machine client" and "trust".

github-actions Bot and others added 4 commits October 26, 2026 07:40
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ery OAuth error

Retry the token exchange on a network error or 5xx, up to three attempts,
requesting a fresh GitHub OIDC token each time because WorkOS accepts each
one once. Never retry a 4xx. Re-exchange and re-send an API call once when
the API answers 401.

Handle unauthorized_client, and make each OAuth error hint name the
setting to change.
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with both earlier findings addressed and no new actionable issues found.

Summary

Adds bounded WIF token-exchange retries, one retry after an API 401, and clearer OAuth error hints.

  • WIF token exchanges retry temporary network and server failures.
  • WIF-authenticated API requests retry once after a 401.
  • OAuth failures point users toward the settings they need to check.
  • The CLI package now carries the 0.24.0 release version.

Reviews (4) · Last reviewed commit: "fix(wif): say the WorkOS access token la..." · Reviewed by Greptile

Comment thread src/lib/wif.ts Resolved
Comment thread src/lib/wif.ts Resolved
…se before re-exchanging

A connection that dropped while the token response body was read ended the exchange as 'the response was not JSON' instead of being retried like any other network failure.

A 401 response was cancelled only after the re-exchange, so a failed re-exchange left it open.
The exchange now issues one-hour tokens. The comment on the fallback lifetime
called five minutes the documented minimum. The fallback stays at 300 seconds,
used only when the server omits expires_in, so the CLI exchanges again early.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant