Skip to content

Add automatic short-lived API token refresh (GL-1709)#446

Closed
timmarkhuff wants to merge 4 commits into
mainfrom
thuff/gl-1709-sdk-token-autorefresh-v2
Closed

Add automatic short-lived API token refresh (GL-1709)#446
timmarkhuff wants to merge 4 commits into
mainfrom
thuff/gl-1709-sdk-token-autorefresh-v2

Conversation

@timmarkhuff

@timmarkhuff timmarkhuff commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treats GROUNDLIGHT_API_TOKEN as a bootstrap credential: the client mints a short-lived working token, caches it on disk, and refreshes it daily in a background thread.
  • Syncs the public OpenAPI spec (api-tokens list/create/delete + by-snippet) and regenerates the client so token management goes through the generated API.
  • Coordinates multi-process refresh with a sibling file lock and atomic writes; remints via the bootstrap token if a cached working token gets a 401.

Design notes

  • Token TTL is 30 days; refresh interval is 1 day; previous tokens are deleted after a 2x grace window.
  • Cache slots live under the platform user data dir (override with GROUNDLIGHT_TOKEN_DIR), keyed by the bootstrap token snippet.
  • Name lookup currently pages through GET /v1/api-tokens and matches raw_key_snippet. _get_token_name_by_snippet is implemented but unused until zuuul#6579 is live; TODOs mark the switch-before-merge.

Test plan

  • poetry run pytest test/unit/test_token_manager.py -v --noconftest
  • Start Groundlight() against integ/prod; confirm a slot file is written and whoami succeeds with the minted token
  • Second process sharing the same token dir does not double-mint while the first holds the lock
  • Before merge: switch _lookup_token_name to _get_token_name_by_snippet once zuuul#6579 is deployed

Bootstrap tokens mint a cached working credential with daily background rotation, file-locked multi-process coordination, and temporary list-and-match name lookup until the by-snippet endpoint is live.

Co-authored-by: Cursor <cursoragent@cursor.com>
@timmarkhuff timmarkhuff changed the title Add automatic short-lived API token refresh in the SDK client. Add automatic short-lived API token refresh (GL-1709) Jul 9, 2026
Tim Huff and others added 3 commits July 9, 2026 12:07
Silence pylint on TokenManager, narrow Optional slot access for mypy, and reinstall the previous working token if a 401 remint fails mid-flight.

Co-authored-by: Cursor <cursoragent@cursor.com>
Adding Groundlight.close for token-refresh lifecycle made the CLI crash on KeyError because close was not in _COMMAND_GROUPS. Also harden expires_at timezone comparisons.

Co-authored-by: Cursor <cursoragent@cursor.com>
Prod does not expose /v1/api-tokens yet, which broke docs tests that construct Groundlight(). Keep using the bootstrap credential and skip auto-refresh until those endpoints exist.

Co-authored-by: Cursor <cursoragent@cursor.com>
@timmarkhuff timmarkhuff closed this Jul 9, 2026
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