Skip to content

fix(platform): repeat a gateway call its busy store turned away - #3975

Merged
yannickmonney merged 1 commit into
mainfrom
fix/gateway-store-busy-retry
Sep 30, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/gateway-store-busy-retry

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Why

The model gateway keeps its configuration in SQLite, and SQLite refuses a write that collides with another write. The gateway then answers the call with a 500 "database is locked". This happens in two situations:

  • Right after the gateway starts, while it syncs its own catalogs. In live checks, the first provider writes after a restart failed this way, so a session started just after a deploy could fail its provisioning.
  • Under concurrent writes from the platform, for example a revoke running beside a budget move. With 8 request lifecycles running in parallel (mint, call, read spend, move the cap, revoke), 9 of 64 revokes and 7 of 64 cap moves failed on v2.2.4; v1.6.11 was worse (16 and 14).

The platform's sweeps retry revokes later. A failed cap move, however, refuses the turn's image generation.

What changes

Every management call now goes through one client in llm_gateway_admin.ts, which also owns the admin credentials and the per-attempt timeout. A call answered with a 5xx is sent again after 250 ms, 750 ms and 2000 ms, but only where that is safe:

  • Any method, when the answer names the locked store: the transaction rolled back, so nothing was written.
  • GET, PUT and DELETE, whatever the 5xx says, because they are idempotent. A virtual key's DELETE answers only "Failed to delete virtual key", without naming the store.
  • A POST answered any other way comes back at once, because it may have created what it asked for.

Verified

  • Unit: the retry rules, including the exact waits (fake timers), a POST that is repeated only after a locked store, and no repeat below 500.
  • Live, against Bifrost v2.2.4:
    • The 8-way churn from above: 64 of 64 revokes and cap moves succeeded, absorbing 6 lock refusals.
    • Provisioning, pricing, mint, cap move and revoke right after each of three gateway restarts: nothing failed, absorbing 2 to 4 lock refusals per restart.

The gateway keeps its config in SQLite and answers a write that collides
with another one with a 500: right after it starts, while it syncs its own
catalogs, and under concurrent writes such as a revoke beside a budget
move. At 8 concurrent model-endpoint requests, 9 of 64 key revokes and 7
of 64 budget moves failed that way, and a session started just after a
gateway restart could fail its provisioning; an image admission whose cap
move failed was refused.

Every management call now goes through one client that sends a call
again, after 250, 750 and 2000 ms, when the answer names the locked store,
or for GET, PUT and DELETE on any 5xx. A POST answered otherwise returns at
once, since it may have created what it asked for. Live: the same load and
three provisions right after a restart then failed nothing.
@yannickmonney
yannickmonney merged commit 88259af into main Sep 30, 2026
60 checks passed
@yannickmonney
yannickmonney deleted the fix/gateway-store-busy-retry branch September 30, 2026 07:06
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