Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions worker/src/lib/ai-gateway/AttemptExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export class AttemptExecutor {

const awaitedEscrow = await pendingEscrow;
if (awaitedEscrow.error) {
// Trigger auto-topoff check when escrow fails due to insufficient credits
// This ensures auto-topoff can trigger even when requests are being rejected
if (awaitedEscrow.error.type === "insufficient_credit_limit") {
const walletId = this.env.WALLET.idFromName(props.orgId);
const walletStub = this.env.WALLET.get(walletId);
this.ctx.waitUntil(
walletStub.checkAndScheduleAutoTopoffAlarm(props.orgId)
);
}
if (walletSpanId) {
this.tracer.setError(walletSpanId, awaitedEscrow.error.message);
this.tracer.finishSpan(walletSpanId);
Expand Down
Loading