Skip to content

fix(auth): refresh a short-lived OAuth token once a third of its life has passed, not on every command - #56

Merged
AltaMills merged 3 commits into
mainfrom
ark/refresh-window-short-tokens
Nov 18, 2026
Merged

AltaMills merged 3 commits into
mainfrom
ark/refresh-window-short-tokens

Conversation

@AltaMills

Copy link
Copy Markdown
Contributor

Summary

The CLI refreshed a stored OAuth token whenever it had less than 30 minutes left (D-088). The API now also issues access tokens that live 15 minutes (expires_in: 900). Such a token is always inside a 30-minute window, so every command refreshed before running, and a quick run of commands (an agent working through a batch) hit the token endpoint's per-address limit with HTTP 429.

  • The refresh window is now 30 minutes or two thirds of the token's lifetime, whichever is shorter (refreshSkewMs). A 15-minute token is refreshed with 10 minutes left, still enough for the default 10-minute wait. A token that lives 45 minutes or more keeps the 30-minute window, so nothing changes for it.
  • Logins and refreshes record issued_at in the profile, so the lifetime is expires_at - issued_at. A profile saved by an older CLI has none and keeps the 30-minute window until its next refresh records one.
  • A wait longer than the token's remaining life still ends on its 401, as before; refreshing during a wait is separate work.
  • Docs: docs/usage.md (OAuth token refresh) and docs/decisions.md D-095.

Tests

  • pnpm build, pnpm typecheck: clean.
  • pnpm test: 717 tests, 716 pass, 1 skipped, 0 fail.
  • New: tests/refresh-skew.test.ts (the window for 15-, 45- and 60-minute tokens and for a profile without issued_at), and three buildRuntime cases in tests/runtime.test.ts (13 minutes left on a 15-minute token: no refresh; 9 minutes left: one refresh that records the 900 s lifetime; no issued_at with 20 minutes left: refreshed under the 30-minute window).
  • Reverting refreshSkewMs to the fixed 30 minutes turns the 15-minute cases red.

… left, not on every command

The CLI refreshed a stored OAuth token whenever it had less than 30 minutes
left. The API now also issues access tokens that live 15 minutes, which are
always inside that window, so every command refreshed before running and a
quick run of commands hit the token endpoint's per-address limit (HTTP 429).

The window is now 30 minutes or two thirds of the token's lifetime, whichever
is shorter: a 15-minute token is refreshed with 10 minutes left, still enough
for the default 10-minute wait, and a token that lives 45 minutes or more
keeps the 30-minute window. Logins and refreshes record issued_at so the
lifetime is known; a profile saved without it keeps the 30-minute window until
its next refresh.
The REFRESH_SKEW_MS comment, the OAuth refresh paragraph in docs/usage.md and
D-088 still promised every command at least 30 minutes left; for a token that
lives less than 45 minutes the window is two thirds of its lifetime instead.
@AltaMills AltaMills changed the title fix(auth): refresh a short-lived OAuth token with a third of its life left, not on every command fix(auth): refresh a short-lived OAuth token once a third of its life has passed, not on every command Nov 18, 2026
@AltaMills
AltaMills marked this pull request as ready for review November 18, 2026 06:24
@AltaMills
AltaMills merged commit 1b2c5d9 into main Nov 18, 2026
7 checks passed
AltaMills added a commit that referenced this pull request Nov 18, 2026
Version 0.8.7 for the release: a short-lived OAuth token is refreshed once a
third of its life has passed instead of before every command (D-095, #56).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant