Repository navigation
fix(platform): repeat a gateway POST only when its write rolled back - #5105
Closed
tale-code-bot wants to merge 1 commit into
Closed
tale-code-bot wants to merge 1 commit into
tale-code-bot wants to merge 1 commit into
Conversation
managementFetch sent a POST again whenever its 5xx named the gateway's locked SQLite store, reading that as proof the write rolled back. The pinned gateway (Bifrost transports v2.2.4) commits a provider key, then re-reads it; a lock on that read answers 500 "failed to re-read provider key after create: database is locked" with the key stored, so the second create met its unique name and the caller got a 409 instead of the original error. A POST now goes out again only when its 5xx matches the answer its own endpoint gives when it stored nothing (storedNothing): a key create on "failed to create provider key in store: ... database is locked", a mint on any locked-store answer (its writes share one transaction, and it answers 200 once that commits), a pricing override create never. GET, PUT and DELETE keep their retries. Closes #3982
tale-review-bot
approved these changes
Oct 29, 2026
tale-review-bot
left a comment
Collaborator
There was a problem hiding this comment.
Approve at 739db3aece749497fa0a42b8adfa4750fdaa2b2b (task TALE-48, Closes #3982).
- Scope matches the triage's "done means" and the plan.
managementFetchnow sends a POST again only when the caller passes its endpoint's proven nothing-stored pattern (storedNothing). Every other 5xx to a POST comes back at once, with its original status and body.- Key create (
writeProviderKey) is resent only onfailed to create provider key in store: … database is locked. A lock on the read-back (failed to re-read provider key after create) now surfaces as the original 500, not the replay's 409. - The mint keeps the lock resend.
- A pricing-override create is never resent.
- GET, PUT and DELETE are unchanged, and no 409 is taken as success.
- Key create (
- Correctness.
- The file has exactly three POST call sites (
:683mint,:1078pricing override,:1624key create), and each passes what the plan's audit of pinned Bifrosted8371a9says. PROVIDER_KEY_STORE_BUSYmatches the insert's refusal and not the read-back's.- The PUT rotate path keeps the idempotent resend.
- The file has exactly three POST call sites (
- Tests. There are four new tests: read-back lock, insert lock, healthy create, and pricing override never repeated. I staged and read the Coder's logs:
vitest-red-first-unfixed.log: against the unfixed file, the read-back test fails (expected 2 to be 1creates,:1904), and the pricing-override test fails (4 POSTs instead of 1,:1960).vitest-fixed-head.log: 3 files, 182 tests passed.- CI's server unit shards passed at this head.
- Contract.
- Branch
fix/gateway-post-retry-post-commit-lock, offmain9be5cadac. - One commit; its header and the PR title are both 68 characters.
- It is backend core, not a domain, so no spec card is owed.
- No integration lane imports
llm_gateway_admin.ts, so the queue-only Backend integration does not exercise this client. Its unit tests and the loopback reproduction are its proof.
- Branch
- Security: two files (the client and its test); no secret, permission, dependency or workflow change.
- Required checks at this head: all seven
CI ready (...)contexts passed. The runs are Commitlint 40930266692, SAST 40930267105, Security 40930266417, CLI 40930266722, E2E 40930266496, Build 40930266522 and Checks 40930266436. - Not run by me: the tests locally, and no live Bifrost fault injection (triage did not require one).
- Note: the Coder's out-of-scope follow-up stays open: after a failed read-back, the key is in the DB but not in memory, so the next provision may 409 until the gateway reloads. It could be its own issue.
tale-review-bot
added this pull request to the merge queue
Oct 29, 2026
yannickmonney
removed this pull request from the merge queue due to a manual request
Oct 29, 2026
tale-review-bot
enabled auto-merge (squash)
October 29, 2026 20:19
tale-review-bot
disabled auto-merge
October 29, 2026 20:27
Collaborator
|
Reviewer: not landing yet. The approved head
|
Contributor
|
Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into |
Contributor
|
Landed on |
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.
Task: TALE-48 (Development board), from issue #3982. Plan: posted on the task before the first edit; this PR follows it.
What was wrong
#3975 (
88259afe5) mademanagementFetch(services/platform/backend/core/node_only/sandbox/llm_gateway_admin.ts) send a POST again whenever its 5xx body matched/database is locked/i. It assumed a locked SQLite store always means the write rolled back. That holds for an insert the store turned away. It does not hold for a provider key's create, because the gateway commits the key first and then reads it back.The pinned gateway is
maximhq/bifrost:v2.2.4(services/sandbox-llm-gateway/Dockerfile). Tagtransports/v2.2.4is commited8371a9779bfbc8aa689d4d77964cf8ce9308bf. ItsAddProviderKeydoes two things in order:ConfigStore.CreateProviderKeyruns in its own gorm transaction. The file is the same blob,0d3449c1, at theframework/v1.7.5thattransports/go.modpins.failed to create provider key in store: %w.ROLLBACKwhenCOMMITfails. So this answer means nothing was stored.ConfigStore.GetProviderKeyreads the key again.failed to re-read provider key after create: %w. Its own comment there says "The DB write succeeded".The handler turns the read-back failure into 500
Failed to create provider key: … database is locked. Bifrost's client error sanitizer (lib/errorsanitizer.go) leaves that text in. A second POST then hits the stored key's unique name and gets 409 "API key names must be unique across providers".So the caller got that 409 instead of the original 500.
The change
managementFetchtakes a new per-call option,storedNothing?: RegExp. A POST is sent again only when its 5xx matches the answer its own endpoint gives when it stored nothing.storedNothing.resend: falseare unchanged. GET, PUT and DELETE are still retried on any 5xx, after 250, 750 and 2000 ms.Every POST that goes through the helper (all three are in this file; the helper is module-private):
storedNothingwriteProviderKey(key create)POST /api/providers/:p/keysPROVIDER_KEY_STORE_BUSY=/failed to create provider key in store: [^"]*database is locked/ifailed to re-read provider key after create) andfailed to update provider.postVirtualKey(mint)POST /api/governance/virtual-keysSTORE_BUSY(/database is locked/i)ensureModelPricingOverride(create)POST /api/governance/pricing-overridesMint. The gateway can hit the lock in two places only, both before anything is stored: while loading providers before the write (500
Failed to load providers), or inside the oneExecuteTransactionthat writes the key, which rolls back. Once that transaction commits, it always answers 200 and only logs a failedReloadVirtualKey(createVirtualKey).Pricing override. The gateway's 5xx answers here never include the store's error: they are "Failed to create pricing override" and "Failed to upsert pricing override" (L4814, L4820). The second comes after the override was stored. Against this gateway the old code never resent it either. Now the contract says so, and a test pins it.
The PUT branches keep the idempotent retry: key rotate in
writeProviderKeyand update inensureModelPricingOverride. A later gateway that rewords these messages can only lose a resend. It can never cause a committed create to be replayed.Tests
Four cases added to the #3975 block in
llm_gateway_admin.test.ts("management calls the gateway store turned away for a moment"). A fixture,stubKeyCreate, models the gateway's key create; once the key is stored, a second create gets the 409 for the taken name.provisionProvidersreports the original(500): {"error":{"message":"Failed to create provider key: failed to re-read provider key after create: database is locked"}}, not a 409.onProviderKey.The retries this PR leaves alone keep their existing tests:
sends a write again after a locked store…)repeats a mint only when the store said it was locked…)repeats an idempotent call whatever its 5xx says…)never repeats a refusal below 500)schedules the pass again at the next call when its listing failed)Results
All at head
739db3aece749497fa0a42b8adfa4750fdaa2b2bon basemain9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2, Bun 1.4.2, afterbun install --frozen-lockfile. Every command ran with the GitHub credential removed from its environment.services/platform)bunx vitest --run --project server backend/core/node_only/sandbox/llm_gateway_admin.test.tsgateway_provisioning.test.tsandgateway_key_settlement.test.tsllm_gateway_admin.ts(blob45b836ee, as onmain)NODE_OPTIONS=--max-old-space-size=6144 bunx tsc --noEmit(whole platform program)bunx oxlint --type-awareon the two filesbunx oxfmt --checkon the two filesLoopback reproduction. This is the issue's script, extended to three cases. It imports the complete module and calls
provisionProvidersagainst aBun.servegateway on 127.0.0.1 that answers the way pinned Bifrost can. Requests to any other origin are refused.45b836ee)46d79648)Not done
fetch, and the reproduction serves loopback HTTP, with the gateway's exact answers taken from the pinned source. Triage did not require a live gateway run. This PR does not claim end-to-end recovery.GET /api/providers/:p/keysreads memory (listProviderKeys). So the next provision lists no key and POSTs again, which gets the 409 until the gateway reloads its config. This is inferred from source, not observed.Closes #3982