fix(gateway-session): retry a transient mint failure instead of ending the run - #1261
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The mint treated every status outside its refusal set as terminal, so one HTTP 503 ended the run before any work started. A 503 there is routine: the app answers one for any gateway transport failure, and the gateway answers one while a pod drains during a normal deploy. 5xx and 408 are now transient. The mint re-asks up to three times with a doubling backoff, honours Retry-After, and shares the one 20s mint budget, so the worst-case wall clock does not grow. A refusal still ends the attempts. The thrown message now carries the server's own reason, and a retry captures `gateway mint retried`, so a recovered mint is measurable against the failures that still end a run. Generated-By: PostHog Desktop Task-Id: 8968884d-aaba-4285-8ccd-ccb074764953
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Test against a Context Mill branch:
Add Results will be posted here when complete. |
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
mintGatewayTokenclassified only 400, 401, 403, 404 and 429 as a refusal it can explain. Every other status fell through to a terminalGatewayMintFailed— no retry, no body read, noRetry-After.Changes
Retry-Afterin both its seconds and HTTP-date forms, and stops as soon as the remaining budget cannot hold another attempt.outcomeanddetail) and the attempt count, so the next 5xx is diagnosable from the message alone.gateway mint retried, next to the existinggateway mint refused. Without it a mint that recovers leaves no trace, so there is no way to measure the fix.Test plan
src/lib/__tests__/gateway-session.test.tscovers: recovery on the second attempt, the bounded give-up at three attempts for 500/502/503/408, a refusal never re-asked,Retry-Afterin both forms, the budget refusing an absurdRetry-After, the server reason in the message, and thegateway mint retriedcapture.tsc --noEmitreports nothing new in the changed files.Agent context
posthog/ai-gatewayas the repository, butsrc/lib/gateway-session.tslives here. The gateway repo only holds the two sources of the 503 the CLI reacts to.fetchWithRetryfromsrc/lib/fetch-retry.ts. It takes no request init (so no POST body or auth header), treats 429 as retryable where the mint treats it as a terminal refusal, has noRetry-Afterawareness, and times out per attempt rather than against one shared deadline.Retry-Afterparser and backoff primitive. This is the third place in the repo to want one (fetch-retry.tsandsrc/lib/task-stream/destinations/posthog.tsare the others), but the extraction would change two modules outside this fix, one of them on the skill-download critical path. Worth its own change.Created with PostHog Desktop from this inbox report.