Repository navigation
fix(upload): refresh the upload token when Storage reports it expired - #361
Merged
Merged
Conversation
Storage checks a signed upload token with a JWT library that rejects an expired token with `"exp" claim timestamp check failed`, before Storage's own expiry message. The check for a refused token looked only for "jwt", "signature" or "expired", so it missed that message. A request refused for an expired token then failed the signed upload instead of getting a fresh token and carrying on. Also match "Invalid Compact JWS", which Storage sends for a token that is not a JWT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
When Storage refuses a signed upload because of its token, the CLI should get a fresh token and carry on (#360). It decides that from the error text, and it only looked for "jwt", "signature" or "expired".
Storage checks the token with a JWT library first. For an expired token, that library fails with
"exp" claim timestamp check failed, before Storage's own "The provided token has expired." That message contains none of those words.So a request refused for an expired token failed the signed upload instead of refreshing. The CLI then fell back to the temp path, so the upload still worked, but slower.
It rarely happens, because the CLI already refreshes before any request when the token has under 10 minutes left. It mostly matters when the client's clock is off.
The fix
The check now also matches
"exp" claimandJWS. Storage sends "Invalid Compact JWS" for a token that isn't a JWT at all. The comment lists the messages Storage sends:Tests
A unit test now checks all four messages.
pnpm lint,pnpm typecheck,pnpm test:unit(780 passing) andpnpm buildpass.🤖 Generated with Claude Code