fix(publisher): refresh session tokens (Bluesky) before publishing#120
Merged
JanSchm merged 1 commit intoJul 2, 2026
Merged
Conversation
The publish engine only refreshed access tokens for OAuth2 providers, skipping session-based providers. Bluesky uses AT Protocol session auth: its accessJwt expires after only a few hours, so scheduled posts failed with `ExpiredToken: Token has expired` whenever the stored token had aged past its TTL. Gate the refresh on the presence of a stored refresh token instead of the auth type, so Bluesky (and any session provider that stores a refreshJwt) renews via refreshSession before each publish. Refresh stays best-effort: on failure we keep the old token and let the publish surface the error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
Contributor
|
thank you for fixing, I'll merge it in. |
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.

Problem
Scheduled Bluesky posts intermittently fail with:
The publish engine only refreshes access tokens for OAuth2 providers. The gate in
PublishEngine._dispatch_to_provideris:Bluesky uses AT Protocol session auth (
AuthType.SESSION), so this branch is never taken for it. ItsaccessJwtexpires after only a few hours, so any scheduled post that waits past the token's TTL publishes with a stale token and getsExpiredToken. OAuth2 platforms (Meta, Google, LinkedIn) are unaffected because their tokens are long-lived and already covered.Fix
Gate the refresh on the presence of a stored refresh token instead of the auth type:
This makes session providers that store a refresh token (Bluesky stores the
refreshJwtinoauth_refresh_token) renew viacom.atproto.server.refreshSessionbefore each publish. The whole mechanism already existed —SocialAccount.refresh_oauth_token()→provider.refresh_token()→refreshSession, persisting the rotatedrefreshJwt— only the engine gate was excluding it.BlueskyProvider.create_sessionalready populatestoken_expires_atfrom the JWT'sexpclaim, sois_token_expiring_soonfires correctly.The refresh stays best-effort (wrapped in try/except): on failure the old token is kept and the publish attempt surfaces the real error, so this is safe for any provider whose
refresh_token()may raise. The now-unusedAuthTypeimport is dropped.Testing
Verified end-to-end against a live self-hosted deployment: a Bluesky post that had been failing with
ExpiredTokenpublished successfully after this change.