Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. πŸ”₯

refactor(billing): route every org through Firebill when configured (#5481)

Rakshith Ramprakash607c2f959564
diff --git a/apps/api/src/config.ts b/apps/api/src/config.ts
index 2837f0c07..1d93e9e44 100644
--- a/apps/api/src/config.ts
+++ b/apps/api/src/config.ts
@@ -774,12 +774,10 @@ const configSchema = z.object({
// Billing
AUTO_RECHARGE_ENABLED: z.stringbool().default(false),
// firebill β€” durable usage-event store that sits in front of Autumn. When
- // both URL and SECRET are set, usage tracking for orgs listed in
- // FIREBILL_ORG_IDS (comma-separated org UUIDs) is routed through firebill
- // instead of directly to Autumn (gradual rollout).
+ // both URL and SECRET are set, every org's usage is routed through firebill
+ // instead of directly to Autumn.
FIREBILL_URL: emptyStringAsUndefined(z.string().url()),
FIREBILL_SECRET: emptyStringAsUndefined(z.string().trim().min(1)),
- FIREBILL_ORG_IDS: delimitedList(",").optional(),
// How long "this team is not partner-provisioned" is trusted. Only the
// negative is bounded: provisioning is one-way, so a positive cannot go
// stale, while a negative does the moment a partner provisions an account.
@@ -793,12 +791,6 @@ const configSchema = z.object({
.min(0)
.max(300)
.default(60),
- // Sticky percentage ramp, on top of the allowlist above. The bucket is a
- // hash of the org id, so an org that is in at 5 is still in at 30 β€” a ramp
- // only ever adds, and never reshuffles who is on which path mid-rollout.
- // 0 (the default) is also the kill switch: the allowlist still routes, and
- // nothing else does.
- FIREBILL_ROLLOUT_PERCENT: z.coerce.number().min(0).max(100).default(0),
// Miscellaneous
// The commit the image was built from, set by the Dockerfile's GIT_SHA.
diff --git a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts b/apps/api/src/services/autumn/__tests__/autumn.service.test.ts
index 97a037ede..a5f67e769 100644
--- a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts
+++ b/apps/api/src/services/autumn/__tests__/autumn.service.test.ts
@@ -1048,7 +1048,7 @@ describe("getTeamLimits", () => {
});
// ---------------------------------------------------------------------------
-// firebill routing (gradual rollout by org allowlist)
+// firebill routing
// ---------------------------------------------------------------------------
describe("firebill routing", () => {
@@ -1057,7 +1057,6 @@ describe("firebill routing", () => {
const firebillConfig = () => ({
FIREBILL_URL: "http://firebill.test",
FIREBILL_SECRET: "fb-secret",
- FIREBILL_ORG_IDS: ["org-1", "org-2"],
});
const firebillResponse = (success: boolean) =>
@@ -1158,7 +1157,7 @@ describe("firebill routing", () => {
expect(trackKey).not.toBe(refundKey);
});
- it("routes trackCredits for an allowlisted org to firebill, not Autumn", async () => {
+ it("routes trackCredits to firebill, not Autumn", async () => {
state.configRef = firebillConfig();
const svc = makeService();
@@ -1220,7 +1219,7 @@ describe("firebill routing", () => {
// Autumn about the ghost's balance alone β€” and a gateway ghost is designed to
// spend credits it does not have, so it 402'd exactly the requests the
// partner pool exists to fund.
- it("routes checkCredits for an allowlisted org to /v1/check, not Autumn", async () => {
+ it("routes checkCredits to /v1/check, not Autumn", async () => {
state.configRef = firebillConfig();
mockFetch.mockResolvedValue(
new Response(
@@ -1256,14 +1255,9 @@ describe("firebill routing", () => {
// The same property as the charge paths, and it bites harder on the gate: a
// provisioned org that misses firebill on a charge is billed to the wrong
// account, but one that misses firebill on the *gate* is refused outright β€”
- // Autumn is asked about a balance the org was never meant to pay from. So a
- // sampling bucket must not decide it.
- it("routes a gateway-provisioned team's CHECK off the allowlist and at 0 percent", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- FIREBILL_ROLLOUT_PERCENT: 0,
- };
+ // Autumn is asked about a balance the org was never meant to pay from.
+ it("routes a gateway-provisioned team's CHECK through firebill, flagged as gateway", async () => {
+ state.configRef = firebillConfig();
state.gatewayStubRow = { team_id: "team-1" };
mockFetch.mockResolvedValue(
new Response(
@@ -1313,11 +1307,8 @@ describe("firebill routing", () => {
expect(mockCheck).not.toHaveBeenCalled();
});
- it("checks directly in Autumn for orgs NOT on the allowlist", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
+ it("checks directly in Autumn when firebill is not configured", async () => {
+ state.configRef = {};
const svc = makeService();
await svc.checkCredits({
@@ -1354,88 +1345,33 @@ describe("firebill routing", () => {
expect(body.properties.endpoint).toBe("extract");
});
- it("routes a gateway-provisioned team even when it is off the allowlist and at 0 percent", async () => {
- // The property the whole branch exists for: a partner's usage cannot depend
- // on a sampling bucket. Only firebill knows how to split it between the
- // provisioned org's balance and the partner's pool.
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- FIREBILL_ROLLOUT_PERCENT: 0,
- };
- state.gatewayStubRow = { team_id: "team-1" };
- const svc = makeService();
-
- const result = await svc.trackCredits({
- teamId: "team-1",
- orgId: "org-1",
- value: 42,
- });
-
- expect(result).toBe(true);
- expect(mockFetch).toHaveBeenCalledTimes(1);
- expect(mockTrack).not.toHaveBeenCalled();
- });
-
- it("caches a positive without re-querying, since provisioning is one-way", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: [],
- FIREBILL_ROLLOUT_PERCENT: 0,
- };
+ it("caches a positive gateway lookup without re-querying, since provisioning is one-way", async () => {
+ state.configRef = firebillConfig();
state.gatewayStubRow = { team_id: "team-1" };
- // A fresh Response per call: firebill reads the body, and a reused one looks
- // like a failure and triggers its retry.
- mockFetch.mockImplementation(async () => firebillResponse(true));
const svc = makeService();
- await svc.trackCredits({ teamId: "team-1", orgId: "org-1", value: 1 });
- // The row vanishing must not un-route the team: provisioning is one-way,
+ expect(await svc.hostedMcpFeatureId("team-1", "CREDITS")).toBe("CREDITS");
+ // The row vanishing must not un-flag the team: provisioning is one-way,
// and re-reading would put a query on every billing event.
state.gatewayStubRow = null;
- await svc.trackCredits({ teamId: "team-1", orgId: "org-1", value: 1 });
-
- expect(mockFetch).toHaveBeenCalledTimes(2);
- expect(mockTrack).not.toHaveBeenCalled();
+ expect(await svc.hostedMcpFeatureId("team-1", "CREDITS")).toBe("CREDITS");
});
- it("does not cache a negative when the lookup fails", async () => {
+ it("does not cache a negative when the gateway lookup fails", async () => {
// A blip must not become a TTL's worth of partner usage billed to the
- // provisioned account alone: that event routes direct, the next asks again.
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: [],
- FIREBILL_ROLLOUT_PERCENT: 0,
- };
+ // provisioned account alone: that call answers "not gateway", the next
+ // asks again.
+ state.configRef = firebillConfig();
state.gatewayStubThrows = true;
state.gatewayStubRow = { team_id: "team-1" };
- mockFetch.mockImplementation(async () => firebillResponse(true));
const svc = makeService();
- await svc.trackCredits({ teamId: "team-1", orgId: "org-1", value: 1 });
- expect(mockFetch).not.toHaveBeenCalled();
+ expect(await svc.hostedMcpFeatureId("team-1", "CREDITS")).not.toBe(
+ "CREDITS",
+ );
state.gatewayStubThrows = false;
- await svc.trackCredits({ teamId: "team-1", orgId: "org-1", value: 1 });
- expect(mockFetch).toHaveBeenCalledTimes(1);
- });
-
- it("uses the direct Autumn path for orgs NOT on the allowlist", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
- const svc = makeService();
-
- const result = await svc.trackCredits({
- teamId: "team-1",
- orgId: "org-1",
- value: 42,
- });
-
- expect(result).toBe(true);
- expect(mockFetch).not.toHaveBeenCalled();
- expect(mockTrack).toHaveBeenCalledTimes(1);
+ expect(await svc.hostedMcpFeatureId("team-1", "CREDITS")).toBe("CREDITS");
});
it("uses the direct Autumn path when FIREBILL_SECRET is missing", async () => {
@@ -1448,19 +1384,6 @@ describe("firebill routing", () => {
expect(mockTrack).toHaveBeenCalledTimes(1);
});
- it("trims whitespace and ignores empty entries in FIREBILL_ORG_IDS", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: [" org-1 ", "", " "],
- };
- const svc = makeService();
-
- await svc.trackCredits({ teamId: "team-1", orgId: "org-1", value: 1 });
-
- expect(mockFetch).toHaveBeenCalledTimes(1);
- expect(mockTrack).not.toHaveBeenCalled();
- });
-
it("returns false when firebill responds success:false β€” no Autumn fallback", async () => {
state.configRef = firebillConfig();
mockFetch.mockResolvedValue(firebillResponse(false));
@@ -1515,7 +1438,7 @@ describe("firebill routing", () => {
const lockResponse = (body: Record<string, unknown>) =>
new Response(JSON.stringify(body), { status: 200 });
- it("routes lockCredits for an allowlisted org to /v1/lock, not Autumn", async () => {
+ it("routes lockCredits to /v1/lock, not Autumn", async () => {
state.configRef = firebillConfig();
mockFetch.mockResolvedValue(
lockResponse({
@@ -1796,10 +1719,7 @@ describe("firebill routing", () => {
// Unreachable (#4403), but a token here would silently skip the gate.
it("refuses a hold when a job token reaches the direct-Autumn path", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
+ state.configRef = {};
const svc = makeService();
expect(
@@ -1865,33 +1785,6 @@ describe("firebill routing", () => {
).toEqual({ status: "skipped" });
});
- // Routing can flip in the hour between a lock and its finalize; going direct
- // would drop the partner's only report of the run.
- it("follows the run token to firebill even when routing says otherwise", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
- const svc = makeService();
-
- await svc.finalizeCreditsLock({
- lockId: "monitor_check-1",
- action: "confirm",
- overrideValue: 7,
- team: { teamId: "team-1", orgId: "org-1" },
- externalRequestId: "run-42",
- });
-
- expect(mockFinalize).not.toHaveBeenCalled();
- const finalizeCall = mockFetch.mock.calls.find(([url]) =>
- String(url).endsWith("/v1/finalize"),
- );
- expect(finalizeCall).toBeDefined();
- expect(JSON.parse(finalizeCall![1].body).external_request_id).toBe(
- "run-42",
- );
- });
-
it("hands the run token back on the finalize as the operation id", async () => {
state.configRef = firebillConfig();
const svc = makeService();
@@ -2055,11 +1948,8 @@ describe("firebill routing", () => {
);
});
- it("uses the direct Autumn lock path for orgs NOT on the allowlist", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
+ it("uses the direct Autumn lock path when firebill is not configured", async () => {
+ state.configRef = {};
const svc = makeService();
const result = await svc.lockCredits({
@@ -2074,7 +1964,7 @@ describe("firebill routing", () => {
expect(mockCheck).toHaveBeenCalledTimes(1);
});
- it("routes finalizeCreditsLock through /v1/finalize when teamId is on the rollout", async () => {
+ it("routes finalizeCreditsLock through /v1/finalize for a team", async () => {
state.configRef = firebillConfig();
const svc = makeService();
@@ -2146,17 +2036,6 @@ describe("firebill routing", () => {
expect(await routeCount("firebill", "finalize")).toBe(before + 1);
});
- it("routes an orgless finalize through firebill even when no org is on the rollout", async () => {
- state.configRef = { ...firebillConfig(), FIREBILL_ORG_IDS: [] };
- const svc = makeService();
-
- await svc.finalizeCreditsLock({ lockId: "lock-1", action: "release" });
-
- expect(mockFinalize).not.toHaveBeenCalled();
- const body = JSON.parse(mockFetch.mock.calls[0]![1].body);
- expect(body.idempotency_key).toBe("fc:finalize:release:lock-1");
- });
-
// Same contract as the direct settle it replaces: one attempt, and `false`
// back to the caller when it did not land. No retry is added here.
it("answers false for an orgless finalize firebill did not take, after one attempt", async () => {
@@ -2188,11 +2067,8 @@ describe("firebill routing", () => {
expect(await routeCount("direct", "finalize")).toBe(before + 1);
});
- it("finalizes directly in Autumn when the team's org is NOT on the allowlist", async () => {
- state.configRef = {
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- };
+ it("finalizes a team's lock directly in Autumn when firebill is not configured", async () => {
+ state.configRef = {};
const svc = makeService();
await svc.finalizeCreditsLock({
@@ -2243,7 +2119,6 @@ describe("the org the caller supplies", () => {
state.configRef = {
FIREBILL_URL: "http://firebill.test",
FIREBILL_SECRET: "fb-secret",
- FIREBILL_ORG_IDS: [CALLER_ORG],
};
try {
@@ -2343,16 +2218,11 @@ describe("provisioning by route", () => {
const firebillConfig = () => ({
FIREBILL_URL: "http://firebill.test",
FIREBILL_SECRET: "fb-secret",
- FIREBILL_ORG_IDS: ["org-1"],
});
- // The same team, off the allowlist and at 0 percent, so it bills straight to
- // Autumn. The route is the only thing that differs between the two halves.
- const directConfig = () => ({
- ...firebillConfig(),
- FIREBILL_ORG_IDS: ["some-other-org"],
- FIREBILL_ROLLOUT_PERCENT: 0,
- });
+ // The same team with firebill unconfigured, so it bills straight to Autumn.
+ // The route is the only thing that differs between the two halves.
+ const directConfig = () => ({});
// A fresh Response per call: firebill reads the body, and a reused one looks
// like a failure and triggers its retry.
diff --git a/apps/api/src/services/autumn/__tests__/firebill.test.ts b/apps/api/src/services/autumn/__tests__/firebill.test.ts
index 3bd37e0b0..0a5c90c99 100644
--- a/apps/api/src/services/autumn/__tests__/firebill.test.ts
+++ b/apps/api/src/services/autumn/__tests__/firebill.test.ts
@@ -7,7 +7,6 @@ import {
firebillLock,
firebillTrack,
processFirebillTrackRetry,
- shouldRouteToFirebill,
} from "../firebill";
import { logger } from "../../../lib/logger";
import {
@@ -24,8 +23,6 @@ const { configState } = vi.hoisted(() => ({
configState: {
FIREBILL_URL: "https://firebill.test",
FIREBILL_SECRET: "secret",
- FIREBILL_ORG_IDS: ["allow-listed-org"] as string[] | undefined,
- FIREBILL_ROLLOUT_PERCENT: 0,
FIRECRAWL_BUILD_SHA: undefined as string | undefined,
},
}));
@@ -78,8 +75,6 @@ const params = {
beforeEach(() => {
configState.FIREBILL_URL = "https://firebill.test";
configState.FIREBILL_SECRET = "secret";
- configState.FIREBILL_ORG_IDS = ["allow-listed-org"];
- configState.FIREBILL_ROLLOUT_PERCENT = 0;
configState.FIRECRAWL_BUILD_SHA = undefined;
firebillTrackTotal.reset();
firebillRetryTotal.reset();
@@ -95,45 +90,6 @@ beforeEach(() => {
});
afterEach(() => vi.unstubAllGlobals());
-describe("shouldRouteToFirebill", () => {
- it("routes the allowlist even at 0 percent", () => {
- expect(shouldRouteToFirebill("allow-listed-org")).toBe(true);
- });
-
- it("routes nobody else at 0 percent β€” the kill switch", () => {
- const others = Array.from({ length: 200 }, (_, i) => `other-${i}`);
- expect(others.some(orgId => shouldRouteToFirebill(orgId))).toBe(false);
- });
-
- it("routes roughly the configured share once ramped", () => {
- const orgs = Array.from({ length: 1000 }, (_, i) => `ramp-${i}`);
- configState.FIREBILL_ROLLOUT_PERCENT = 30;
- const share =
- (orgs.filter(orgId => shouldRouteToFirebill(orgId)).length /
- orgs.length) *
- 100;
- expect(Math.abs(share - 30)).toBeLessThan(6);
- });
-
- it("ignores a non-object second argument, so callback use cannot route everyone", () => {
- // `orgs.filter(shouldRouteToFirebill)` would pass the array index as the
- // options argument. TypeScript rejects that now, but the runtime must be
- // safe too: destructuring a field off a number yields undefined.
- configState.FIREBILL_ROLLOUT_PERCENT = 0;
- const asCallback = shouldRouteToFirebill as unknown as (
- orgId: string,
- index: number,
- ) => boolean;
- expect(asCallback("not-allow-listed", 7)).toBe(false);
- });
-
- it("stays off entirely when firebill is not configured", () => {
- configState.FIREBILL_ROLLOUT_PERCENT = 100;
- configState.FIREBILL_SECRET = "";
- expect(shouldRouteToFirebill("allow-listed-org")).toBe(false);
- });
-});
-
/**
* The outcome counter alone β€” the one the alerts read, which must keep exactly
* the labels it always had.
diff --git a/apps/api/src/services/autumn/__tests__/mcp-credits.test.ts b/apps/api/src/services/autumn/__tests__/mcp-credits.test.ts
index df0f6e67a..8cb3fcd1a 100644
--- a/apps/api/src/services/autumn/__tests__/mcp-credits.test.ts
+++ b/apps/api/src/services/autumn/__tests__/mcp-credits.test.ts
@@ -56,7 +56,6 @@ vi.mock("../../../config", () => ({
? {
FIREBILL_URL: "http://firebill.test",
FIREBILL_SECRET: "fb-secret",
- FIREBILL_ORG_IDS: ["org-1"],
}
: {}),
};
diff --git a/apps/api/src/services/autumn/autumn.service.ts b/apps/api/src/services/autumn/autumn.service.ts
index ae6610b50..99db94582 100644
--- a/apps/api/src/services/autumn/autumn.service.ts
+++ b/apps/api/src/services/autumn/autumn.service.ts
@@ -12,7 +12,6 @@ import {
firebillTrack,
firebillCheck,
firebillConfigured,
- shouldRouteToFirebill,
} from "./firebill";
import {
autumnCustomerGetOrCreateTotal,
@@ -157,8 +156,7 @@ export class AutumnService {
/**
* Whether this team is an account a gateway partner provisioned, which is
- * what makes the partner responsible for part of its usage, and forces it
- * through firebill.
+ * what makes the partner responsible for part of its usage.
*
* Reads `partner_provisioned_accounts` rather than any config, because these
* are created at runtime by the partner API β€” an allowlist of org ids cannot
@@ -320,20 +318,15 @@ export class AutumnService {
* Whether this team's usage is currently routed through firebill. Used by
* billers to pick route-specific failure handling (on the firebill route a
* recorded charge stands and dedupes, so compensating refunds and duplicate
- * enqueues behave differently). Never throws: an error means "not routed",
- * falling back to the pre-firebill behavior.
+ * enqueues behave differently). Every non-preview team routes whenever
+ * firebill is configured.
*/
async isRoutedThroughFirebill(
teamId: string,
- orgId: string,
+ _orgId: string,
): Promise<boolean> {
if (this.isPreviewTeam(teamId)) return false;
- try {
- const gatewayProvisioned = await this.isGatewayProvisioned(teamId);
- return shouldRouteToFirebill(orgId, { gatewayProvisioned });
- } catch {
- return false;
- }
+ return firebillConfigured();
}
/**
@@ -355,8 +348,7 @@ export class AutumnService {
}: TrackParams,
routed: boolean,
): Promise<boolean> {
- // Gradual rollout: allowlisted orgs, partner-provisioned orgs, and those in
- // sticky FIREBILL_ROLLOUT_PERCENT bucket bill through firebill. No fallback
+ // Every org bills through firebill when it is configured. No fallback
// to Autumn on failure β€” firebill may already own the event, and the SDK
// sends no idempotency key, so the pair could not be deduped.
if (routed) {
@@ -500,7 +492,7 @@ export class AutumnService {
gatewayProvisioned: boolean;
}> {
const gatewayProvisioned = await this.isGatewayProvisioned(teamId);
- const routed = shouldRouteToFirebill(orgId, { gatewayProvisioned });
+ const routed = firebillConfigured();
if (!routed && !this.ensuredTeams.has(this.ensuredTeamKey(orgId, teamId))) {
await this.ensureTeamProvisioned({ teamId, orgId });
}
@@ -546,8 +538,7 @@ export class AutumnService {
// partner-provisioned org that misses firebill on a *charge* is billed to
// the wrong account; one that misses firebill on the *gate* is refused
// outright, because Autumn is asked about a balance the org was never
- // meant to pay from. So the org this most needs to reach firebill is
- // exactly the one a sampling bucket might leave behind.
+ // meant to pay from.
if (routed) {
const result = await firebillCheck({
customerId,
@@ -675,8 +666,7 @@ export class AutumnService {
orgId,
);
- // Gradual firebill rollout, mirroring track(): allowlisted orgs take
- // their holds through firebill. The hold still lives in Autumn (firebill
+ // Mirroring track(): holds go through firebill when it is configured. The hold still lives in Autumn (firebill
// keeps no lock state), but only firebill pins the retry/timeout budget
// around the call. An unavailable answer maps to "skipped" β€” proceed
// unlocked β€” like a direct-Autumn check failure below, except when a
@@ -787,23 +777,18 @@ export class AutumnService {
/**
* Finalizes a previously-acquired Autumn lock.
*
- * When the caller supplies the lock's team and that team's org is on the
- * firebill rollout, the settle goes through firebill, which queues it
+ * When firebill is configured the settle goes through it, which queues it
* durably and retries delivery β€” a dropped direct finalize means the hold
* just expires, leaving a confirm's work unbilled. Either route lands on the
* same Autumn lock, so routing is a durability choice, not a correctness one.
*
- * A caller that cannot name the org passes no team, and there is no org to
- * ask the rollout about. That settle goes through firebill whenever firebill
- * is configured: the lock id is all a finalize needs, so an ordinary settle
- * loses nothing by not knowing the org (a run-token settle loses its partner
- * report, as below), and a direct settle would be the one write to Autumn
- * left outside firebill.
+ * A caller that cannot name the org passes no team. The lock id is all a
+ * finalize needs, so an ordinary settle loses nothing by not knowing the org
+ * (a run-token settle loses its partner report, as below).
*
* **Except with a run token in hand**, where it is a correctness choice: only
- * firebill reports the operation to the partner, and the routing predicate is
- * not stable across the hour between a lock and its finalize. The token is
- * proof of the route the lock took, so it wins over asking again.
+ * firebill reports the operation to the partner. The token is proof of the
+ * route the lock took, so it wins over asking again.
*/
async finalizeCreditsLock({
lockId,
diff --git a/apps/api/src/services/autumn/firebill.ts b/apps/api/src/services/autumn/firebill.ts
index 0ad4b232e..f0fe0eb05 100644
--- a/apps/api/src/services/autumn/firebill.ts
+++ b/apps/api/src/services/autumn/firebill.ts
@@ -3,7 +3,6 @@ import type { Job } from "bullmq";
import { z } from "zod";
import { config } from "../../config";
import { logger } from "../../lib/logger";
-import { sampled } from "../../lib/rollout";
import {
getFirebillTrackRetryQueue,
type FirebillTrackRetryJobData,
@@ -266,69 +265,14 @@ const lockAnswerSchema = z.discriminatedUnion("success", [
z.object({ success: z.literal(false) }),
]);
-// FIREBILL_ORG_IDS is decoded once at startup by the config schema; the Set is
-// built lazily on first use and cached, keyed on the decoded array reference.
-let allowlistCache: { source: string[] | undefined; ids: Set<string> } | null =
- null;
-
-function firebillOrgIds(): Set<string> {
- const source = config.FIREBILL_ORG_IDS;
- if (!allowlistCache || allowlistCache.source !== source) {
- allowlistCache = {
- source,
- ids: new Set(
- (source ?? []).map(id => id.trim()).filter(id => id.length > 0),
- ),
- };
- }
- return allowlistCache.ids;
-}
-
/**
- * Configured, without the rollout question β€” a finalize carrying a run token
- * follows the lock through firebill whatever the ramp says.
+ * Whether firebill is configured. When it is, every org's usage goes through
+ * firebill rather than straight to Autumn.
*/
export function firebillConfigured(): boolean {
return Boolean(config.FIREBILL_URL && config.FIREBILL_SECRET);
}
-/**
- * Whether this org's usage goes through firebill rather than straight to Autumn.
- * Needs firebill configured, then any of: the allowlist, being
- * partner-provisioned, or the sticky percentage.
- *
- * `gatewayProvisioned` is deliberately a parameter rather than a lookup in here:
- * this stays a pure function of config so it can be reasoned about and tested
- * without a database, and the caller already has the answer cached.
- *
- * It arrives in an options object rather than as a second positional argument
- * because this predicate is used as a callback β€” `orgs.filter(shouldRouteToFirebill)`
- * would otherwise pass the array *index* as it, routing everything but element
- * zero. Destructuring a field off a number yields undefined, so the object form
- * cannot be fooled that way.
- *
- * **This whole gateway branch is meant to be deleted.** It exists only because
- * the ramp is below 100: a gateway partner's usage must route deterministically,
- * and a sticky sample is a probability. At `FIREBILL_ROLLOUT_PERCENT=100` every
- * org routes anyway, the branch stops changing any outcome, and it β€” along with
- * the lookup feeding it β€” should go.
- */
-export function shouldRouteToFirebill(
- orgId: string,
- opts?: { gatewayProvisioned?: boolean },
-): boolean {
- if (!firebillConfigured()) return false;
- // Always-on set: test orgs stay routed even at 0 percent.
- if (firebillOrgIds().has(orgId)) return true;
- // A partner-provisioned org always routes: firebill is the only thing that
- // knows how to split its usage between that org's own balance and the
- // partner's, so a charge that misses firebill is billed wholly to an account
- // nobody pays for, and the partner is silently never charged.
- if (opts?.gatewayProvisioned) return true;
- // Sticky by org, so a ramp only ever adds and 0 is the kill switch.
- return sampled(orgId, config.FIREBILL_ROLLOUT_PERCENT);
-}
-
// Plain concatenation rather than new URL(path, base): a leading-slash path
// would drop any base-path prefix (e.g. a reverse proxy at /firebill).
function firebillUrl(path: string): string {
diff --git a/apps/api/src/services/monitoring/runner.reservation.test.ts b/apps/api/src/services/monitoring/runner.reservation.test.ts
index 3aa0cd438..1d85f1861 100644
--- a/apps/api/src/services/monitoring/runner.reservation.test.ts
+++ b/apps/api/src/services/monitoring/runner.reservation.test.ts
@@ -38,7 +38,6 @@ vi.mock("../../config", () => ({
vi.mock("../../lib/logger", () => ({ logger }));
vi.mock("../autumn/client", () => ({ autumnClient: sdk }));
vi.mock("../autumn/firebill", () => ({
- shouldRouteToFirebill: () => false,
firebillConfigured: () => false,
}));
vi.mock("../autumn/metrics", () => ({