Skip to content

Use wall-clock time for staging IAP token expiry - #17016

Merged
IsaiahWitzke merged 5 commits into
masterfrom
iw/iap-wall-clock-expiry
Nov 30, 2026
Merged

IsaiahWitzke merged 5 commits into
masterfrom
iw/iap-wall-clock-expiry

Conversation

@IsaiahWitzke

Copy link
Copy Markdown
Contributor

Description

Local staging builds sometimes fail an agent request with ErrorStatus(401, "OpenID Connect token expired: JWT has expired"). IAP returns this error when the client sends an expired IAP token.

Root cause: CachedToken.expires_at was an Instant. On macOS, Instant uses CLOCK_UPTIME_RAW, and that clock stops while the system sleeps. After a sleep, the cache counted the token as valid even when its JWT exp had passed, so IapState::get_cached attached the expired token.

Changes:

  • CachedToken.expires_at is now a SystemTime from the JWT exp claim. Validity checks, the refresh schedule, the on-disk WIF cache, and the settings widget now use wall-clock time.
  • IapManager::handle_system_wake re-arms the refresh on SystemStatsEvent::CpuWasAwakened. Refresh timers also stop during sleep, so the wake handler fixes a late refresh. If the token is near expiry, the refresh starts immediately.

Reading order: crates/warp_server_client/src/iap.rs, then the wake subscription in app/src/lib.rs.

Linked Issue

None.

Testing

  • cargo nextest run -p warp_server_client iap: 33 tests pass. Existing tests now use SystemTime, and two new tests cover the wake handler.
  • cargo clippy -p warp_server_client -p warp --all-targets --tests -- -D warnings: clean.
  • Not tested manually. To test: use a staging build, sleep the Mac past the token's expiry, wake it, and send an agent query.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Conversation: https://staging.warp.dev/conversation/ac8551f7-4525-46a3-80ae-152870de18f6

CHANGELOG-NONE

Co-Authored-By: Warp agent@warp.dev

On macOS, `Instant` does not advance while the system sleeps, so the
`Instant`-based IAP token expiry outlived the real token after a sleep.
The client then attached an expired token and IAP returned
"OpenID Connect token expired: JWT has expired".

Store the expiry as `SystemTime` from the JWT `exp` claim, and re-arm
the IAP refresh when the system wakes, because refresh timers are also
late by the sleep duration.

Co-Authored-By: Warp <agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Nov 30, 2026
IsaiahWitzke and others added 4 commits November 30, 2026 13:47
Co-Authored-By: Warp <agent@warp.dev>
Co-Authored-By: Warp <agent@warp.dev>
Co-Authored-By: Warp <agent@warp.dev>
@IsaiahWitzke
IsaiahWitzke marked this pull request as ready for review November 30, 2026 19:21
@IsaiahWitzke
IsaiahWitzke enabled auto-merge (squash) November 30, 2026 19:22
@IsaiahWitzke
IsaiahWitzke merged commit 156b3a0 into master Nov 30, 2026
38 of 39 checks passed
@IsaiahWitzke
IsaiahWitzke deleted the iw/iap-wall-clock-expiry branch November 30, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants