Repository navigation
Renew a ChatGPT subscription login that ChatGPT rejects during a run - #351
Open
arseniycodes wants to merge 1 commit into
Open
arseniycodes wants to merge 1 commit into
arseniycodes wants to merge 1 commit into
Conversation
ChatGPT can reject a stored access token before its stated expiry. A run holds no refresh token, and the worker renews the login only near expiry, so every run failed with a 401 until something else refreshed the login. When a subscription run fails with a ChatGPT 401, the worker now renews the stored login right away, so the next run uses a fresh token.
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
A customer's ChatGPT-subscription automation failed every run for about 20 hours with:
Before a turn, Codex calls
chatgpt.com/backend-api/accounts/check. ChatGPT returned 401 for the stored access token, even though the token had not reached itsexp. Codex would normally refresh after a 401, but a run sandbox holds only the run-only refresh token. The worker renews the stored login only when the token is close to expiry (subscriptionAuthCoveringRun), so nothing renewed it. Runs recovered only after someone opened the model picker, which runs Codex with the real refresh token and saved a new login.Change
runCodexAutomationthrowsSubscriptionLoginRejectedError(a subclass ofAutomationHarnessError) when a subscription run ends with a ChatGPT 401 (unauthorized (401)or401 Unauthorizedin the final Codex error).processAutomationRuncalls the newrefreshSubscriptiondependency (refreshSubscriptionInSandbox).account/readwithrefreshToken: truerefreshes even when the token has not expired, so the next run gets a new token.SubscriptionCredentialUnavailableError, which means another operation is already renewing the login.Re-running the failed turn is out of scope. It would need a new Daytona secret and sandbox and would affect notification handling.
Verification
pnpm typecheck, eslint on the changed files, andvitest run apps/worker(673 passed) pass.Summary by cubic
Renews a stored ChatGPT subscription login as soon as a run reports a ChatGPT 401, instead of waiting until the token nears expiry.
unauthorized (401)or401 Unauthorizednow throws aSubscriptionLoginRejectedError, and the worker immediately refreshes the stored login so the next run uses a fresh token.SubscriptionCredentialUnavailableError, which means another run is already renewing the login.Written for commit 2b9227c. Summary will update on new commits.