Skip to content

fix: refresh stack token on 400 invalid-token responses#29

Merged
rezk2ll merged 2 commits into
mainfrom
fix/refresh-app-token-on-400
May 11, 2026
Merged

fix: refresh stack token on 400 invalid-token responses#29
rezk2ll merged 2 commits into
mainfrom
fix/refresh-app-token-on-400

Conversation

@rezk2ll

@rezk2ll rezk2ll commented May 11, 2026

Copy link
Copy Markdown
Member

Summary

  • Cloudery-minted app-audience JWTs have no session_id, so the Stack treats them as konnector tokens (30 min TTL) and returns HTTP 400 with WWW-Authenticate: Bearer error="invalid_token" once they expire. The previous refresh path only triggered on 401, so any migration running longer than ~30 minutes died mid-traversal and the recovery flushAndFail write failed the same way, leaving the tracking doc stuck in running.
  • withTokenRefresh now refreshes on 401 and on 400 whose error message matches Expired token / Invalid (JWT)? token, then retries once. Unrelated 400 errors still propagate.

rezk2ll added 2 commits May 11, 2026 14:53
Cloudery-minted app-audience JWTs have no session_id, so the Stack
treats them as konnector tokens with a 30-minute TTL. On expiry the
Stack returns HTTP 400 with `WWW-Authenticate: Bearer
error="invalid_token"`, which cozy-stack-client folds into a
FetchError whose .message is "Invalid token" or "Expired token" —
not the 401 the existing refresh path was waiting for.

Long-running migrations therefore die silently around the half-hour
mark and the recovery flushAndFail write fails the same way, leaving
the tracking doc stuck in `running`. withTokenRefresh now refreshes
on 401 plus 400-with-token-rejection-message and retries once.
Have the helper return the rejection status so withTokenRefresh
does not re-cast the error. Consolidate the two 400-case tests
into an it.each over the three matching messages.
@rezk2ll rezk2ll merged commit 8c4c193 into main May 11, 2026
3 checks passed
@github-actions github-actions Bot deleted the fix/refresh-app-token-on-400 branch May 11, 2026 12:58
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