Q67: in-flight requests reserve monthly quota

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 11:37:35 -04:00
1 parent d184e82e2a
commit c38b424f4b
4 files changed
+66 -20

No files matched your search

@@ -9,7 +9,7 @@ import {
type ProviderAuthType,
type ProviderExecutionMode,
} from "../../shared/domain";
import { currentProviderUsageWindow, PROVIDER_MONTHLY_LIMIT_MESSAGE, type ProviderObservedRateLimitState } from "../../shared/provider-runtime-domain";
import type { ProviderObservedRateLimitState } from "../../shared/provider-runtime-domain";
import { AuditService } from "./audit-service";
import { AuthBrokerService, type ProviderSecretVault } from "./auth-broker-service";
import { OperationsService } from "./operations-service";
@@ -249,14 +249,7 @@ export class ProviderBackgroundService {
throw new Error("Provider background execution is disabled by feature flag.");
}
if (provider.background_enabled !== 1) throw new Error("Background execution is disabled for this provider policy.");
const window = currentProviderUsageWindow();
const usage = this.db.prepare(`
select request_count
from provider_usage_windows
where org_id = ? and provider_id = ? and window_start = ?
`).get(orgId, provider.id, window.start) as { request_count: number } | undefined;
const requestCount = usage?.request_count ?? 0;
if (requestCount >= provider.monthly_request_limit) throw new Error(PROVIDER_MONTHLY_LIMIT_MESSAGE);
this.requestStore.assertMonthlyCapacity(orgId, provider);
}
private normalizeWorkspaceId(orgId: string, workspaceId: string | null): string | null {