Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. π₯
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
chore(api): rip out AUTUMN_EXPERIMENT and AUTUMN_EXPERIMENT_PERCENT (#3626)
firecrawl-spring[bot]c5bb852969f7
diff --git a/apps/api/src/config.ts b/apps/api/src/config.tsindex 5d41241c7..56a9cae14 100644--- a/apps/api/src/config.ts+++ b/apps/api/src/config.ts@@ -52,8 +52,6 @@ const configSchema = z.object({LLAMAPARSE_API_KEY: z.string().optional(),STRIPE_SECRET_KEY: z.string().optional(),AUTUMN_SECRET_KEY: z.string().optional(),- AUTUMN_EXPERIMENT: z.string().optional(),- AUTUMN_EXPERIMENT_PERCENT: z.coerce.number().default(100),AUTUMN_REQUEST_TRACK_EXPERIMENT: z.string().optional(),AUTUMN_REQUEST_TRACK_EXPERIMENT_PERCENT: z.coerce.number().default(100),RESEND_API_KEY: z.string().optional(),diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.tsindex 8c3b457bb..4444268e5 100644--- a/apps/api/src/controllers/auth.ts+++ b/apps/api/src/controllers/auth.ts@@ -13,10 +13,6 @@ import { redlock } from "../services/redlock";import { supabase_rr_service, supabase_service } from "../services/supabase";import { AuthResponse, RateLimiterMode } from "../types";import { AuthCreditUsageChunk, AuthCreditUsageChunkFromTeam } from "./v1/types";-import {- isAutumnCheckEnabled,- AUTUMN_BYPASS_ORG_IDS,-} from "../services/autumn/autumn.service";function normalizedApiIsUuid(potentialUuid: string): boolean {// Check if the string is a valid UUID@@ -493,12 +489,7 @@ async function ensureChunkOrgId(apiKey: string,chunk: AuthCreditUsageChunk | null,): Promise<AuthCreditUsageChunk | null> {- if (- !chunk ||- chunk.org_id ||- config.USE_DB_AUTHENTICATION !== true ||- (!isAutumnCheckEnabled() && AUTUMN_BYPASS_ORG_IDS.size === 0)- ) {+ if (!chunk || chunk.org_id || config.USE_DB_AUTHENTICATION !== true) {return chunk;}diff --git a/apps/api/src/routes/shared.ts b/apps/api/src/routes/shared.tsindex c31967d9f..af8eaa0b0 100644--- a/apps/api/src/routes/shared.ts+++ b/apps/api/src/routes/shared.ts@@ -24,10 +24,7 @@ import { validate as isUuid } from "uuid";import { config } from "../config";import { supabase_service } from "../services/supabase";-import {- autumnService,- isAutumnCheckEnabled,-} from "../services/autumn/autumn.service";+import { autumnService } from "../services/autumn/autumn.service";export function checkCreditsMiddleware(_minimum?: number,@@ -123,8 +120,7 @@ export function checkCreditsMiddleware(}const requestedCredits = minimum ?? 1;- const useAutumnCheck =- !!req.auth.org_id && isAutumnCheckEnabled(req.auth.org_id);+ const useAutumnCheck = !!req.auth.org_id;const autumnProperties = {source: "checkCreditsMiddleware",diff --git a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts b/apps/api/src/services/autumn/__tests__/autumn.service.test.tsindex 78b9b6cbc..27a343cdf 100644--- a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts+++ b/apps/api/src/services/autumn/__tests__/autumn.service.test.ts@@ -70,8 +70,6 @@ jest.mock("../../supabase", () => ({jest.mock("../../../config", () => ({config: {- AUTUMN_EXPERIMENT: "true",- AUTUMN_EXPERIMENT_PERCENT: 100,AUTUMN_REQUEST_TRACK_EXPERIMENT: undefined,AUTUMN_REQUEST_TRACK_EXPERIMENT_PERCENT: 100,},@@ -82,8 +80,6 @@ import {AutumnService,BoundedMap,BoundedSet,- isAutumnCheckEnabled,- isAutumnEnabled,isAutumnRequestTrackEnabled,orgBucket,} from "../autumn.service";@@ -109,8 +105,6 @@ beforeEach(() => {jest.clearAllMocks();autumnClientRef = mockAutumnClient;supabaseStubData = { data: { org_id: "org-1" }, error: null };- config.AUTUMN_EXPERIMENT = "true";- config.AUTUMN_EXPERIMENT_PERCENT = 100;config.AUTUMN_REQUEST_TRACK_EXPERIMENT = undefined;config.AUTUMN_REQUEST_TRACK_EXPERIMENT_PERCENT = 100;mockCheck.mockResolvedValue({@@ -515,7 +509,7 @@ describe("refundCredits", () => {});// ----------------------------------------------------------------------------// isAutumnEnabled / experiment gating+// experiment gating// ---------------------------------------------------------------------------describe("orgBucket", () => {@@ -543,114 +537,13 @@ describe("orgBucket", () => {});});-describe("isAutumnEnabled", () => {- it("returns true when experiment is enabled and percent is 100", () => {- expect(isAutumnEnabled()).toBe(true);- });-- it("returns true without orgId even when percent < 100 (fast bail-out only)", () => {- config.AUTUMN_EXPERIMENT_PERCENT = 0;- // Without orgId the percent gate is skipped β only the on/off flag matters.- expect(isAutumnEnabled()).toBe(true);- });-- it("returns false when AUTUMN_EXPERIMENT is not 'true'", () => {- config.AUTUMN_EXPERIMENT = undefined;- expect(isAutumnEnabled()).toBe(false);- });-- it("returns false for an orgId whose bucket >= percent", () => {- // orgBucket("a1b2c3d4-...") = 16, so percent=10 should exclude it.- config.AUTUMN_EXPERIMENT_PERCENT = 10;- expect(isAutumnEnabled("a1b2c3d4-0000-0000-0000-000000000000")).toBe(false);- });-- it("returns true for an orgId whose bucket < percent", () => {- // orgBucket("a1b2c3d4-...") = 16, so percent=50 should include it.- config.AUTUMN_EXPERIMENT_PERCENT = 50;- expect(isAutumnEnabled("a1b2c3d4-0000-0000-0000-000000000000")).toBe(true);- });-});--describe("isAutumnCheckEnabled", () => {- it("mirrors AUTUMN_EXPERIMENT", () => {- expect(isAutumnCheckEnabled()).toBe(true);- config.AUTUMN_EXPERIMENT = undefined;- expect(isAutumnCheckEnabled()).toBe(false);- });-});-describe("isAutumnRequestTrackEnabled", () => {it("returns false when request tracking flag is not 'true'", () => {expect(isAutumnRequestTrackEnabled()).toBe(false);});- it("returns true only when both request tracking and Autumn experiment are enabled", () => {+ it("returns true when request tracking is enabled", () => {config.AUTUMN_REQUEST_TRACK_EXPERIMENT = "true";expect(isAutumnRequestTrackEnabled()).toBe(true);});});--describe("experiment gate on lockCredits", () => {- it("lockCredits returns null when experiment is disabled", async () => {- config.AUTUMN_EXPERIMENT = undefined;- const svc = makeService();- const result = await svc.lockCredits({ teamId: "team-1", value: 10 });- expect(result).toBeNull();- expect(mockCheck).not.toHaveBeenCalled();- });-- it("lockCredits returns null when org is outside the percent bucket", async () => {- // Supabase returns org whose bucket (16) is >= percent (10).- supabaseStubData = {- data: { org_id: "a1b2c3d4-0000-0000-0000-000000000000" },- error: null,- };- config.AUTUMN_EXPERIMENT_PERCENT = 10;- const svc = makeService();- const result = await svc.lockCredits({ teamId: "team-1", value: 10 });- expect(result).toBeNull();- expect(mockCheck).not.toHaveBeenCalled();- });-- it("lockCredits succeeds when org is inside the percent bucket", async () => {- // Supabase returns org whose bucket (16) is < percent (50).- supabaseStubData = {- data: { org_id: "a1b2c3d4-0000-0000-0000-000000000000" },- error: null,- };- config.AUTUMN_EXPERIMENT_PERCENT = 50;- const svc = makeService();- const result = await svc.lockCredits({- teamId: "team-1",- value: 10,- lockId: "lock-123",- });- expect(result).toBe("lock-123");- expect(mockCheck).toHaveBeenCalled();- });-- it("refundCredits still works when experiment is disabled (guard is autumnReserved)", async () => {- config.AUTUMN_EXPERIMENT = undefined;- const svc = makeService();- // Warm the caches so refund can resolve the tracking context.- config.AUTUMN_EXPERIMENT = "true";- await svc.trackCredits({ teamId: "team-1", value: 10 });- jest.clearAllMocks();-- // Disable experiment β refund must still succeed to avoid orphaned credits.- config.AUTUMN_EXPERIMENT = undefined;- mockTrack.mockResolvedValue(undefined);- await svc.refundCredits({ teamId: "team-1", value: 10 });- expect(mockTrack).toHaveBeenCalled();- });-- it("ensureTeamProvisioned still works when experiment is disabled (handled by firecrawl-web)", async () => {- config.AUTUMN_EXPERIMENT = undefined;- const svc = makeService();- await svc.ensureTeamProvisioned({ teamId: "team-1", orgId: "org-1" });- // Provisioning should proceed β firecrawl-web edge functions do this- // regardless, so gating API-side provisioning is unnecessary.- expect(mockGetOrCreate).toHaveBeenCalled();- });-});diff --git a/apps/api/src/services/autumn/autumn.service.ts b/apps/api/src/services/autumn/autumn.service.tsindex 3e3c109bb..d9e2cfb9e 100644--- a/apps/api/src/services/autumn/autumn.service.ts+++ b/apps/api/src/services/autumn/autumn.service.ts@@ -19,18 +19,6 @@ import type {const TEAM_FEATURE_ID = "TEAM";const CREDITS_FEATURE_ID = "CREDITS";-/**- * Org IDs that always have Autumn enabled, regardless of experiment- * percentage or feature flags.- */-export const AUTUMN_BYPASS_ORG_IDS = new Set([- "318e9dfd-9d76-489d-86fa-64bcbc3682f9", // Autumn- "601f9bf3-425c-4309-97ae-4626842738d5", // Autumn- "5ee89794-c287-47c5-b621-cbfbc0dbaaff",- "0f2c26d2-e1f9-4a96-b443-7e93067fc3a9",- "8454ff9b-833f-42ee-bcdd-87457f687779",-]);-/*** Deterministic bucket for an org UUID.*@@ -43,35 +31,8 @@ export function orgBucket(orgId: string): number {return parseInt(hex, 16) % 100;}-/**- * Returns true when the Autumn experiment is active.- *- * Without an orgId the check is a simple on/off flag β useful as a fast- * bail-out before the orgId is known. When an orgId is supplied the- * stable percent gate is also evaluated so the same org always gets the- * same answer.- *- * Only checked at the top-level billing entry points (`lockCredits` and the- * direct-track `trackCredits`).- * NOT checked by `finalizeCreditsLock`, `refundCredits`, or- * `ensureTeamProvisioned`.- */-export function isAutumnEnabled(orgId?: string): boolean {- if (orgId && AUTUMN_BYPASS_ORG_IDS.has(orgId)) return true;- if (config.AUTUMN_EXPERIMENT !== "true") return false;- if (!orgId || config.AUTUMN_EXPERIMENT_PERCENT >= 100) return true;- return orgBucket(orgId) < config.AUTUMN_EXPERIMENT_PERCENT;-}--export function isAutumnCheckEnabled(orgId?: string): boolean {- if (orgId && AUTUMN_BYPASS_ORG_IDS.has(orgId)) return true;- return config.AUTUMN_EXPERIMENT === "true";-}-export function isAutumnRequestTrackEnabled(orgId?: string): boolean {- if (orgId && AUTUMN_BYPASS_ORG_IDS.has(orgId)) return true;if (config.AUTUMN_REQUEST_TRACK_EXPERIMENT !== "true") return false;- if (!isAutumnEnabled(orgId)) return false;if (!orgId || config.AUTUMN_REQUEST_TRACK_EXPERIMENT_PERCENT >= 100) {return true;}@@ -387,9 +348,6 @@ export class AutumnService {return null;}try {- const orgId = await this.resolveOrgId(teamId);- if (!isAutumnCheckEnabled(orgId)) return null;-const customerId = await this.ensureTrackingContext(teamId);const { allowed, balance } = await autumnClient.check({customerId,@@ -440,9 +398,6 @@ export class AutumnService {const resolvedLockId = lockId ?? `billing_${randomUUID()}`;try {- const orgId = await this.resolveOrgId(teamId);- if (!isAutumnEnabled(orgId)) return null;-const customerId = await this.ensureTrackingContext(teamId);const { allowed } = await autumnClient.check({customerId,@@ -528,9 +483,9 @@ export class AutumnService {/*** Records a credit usage event directly in Autumn. Returns true on success.*- * The experiment gate is evaluated here β once per request β using a stable- * bucket derived from the org UUID so the same org always gets the same- * answer for a given AUTUMN_EXPERIMENT_PERCENT value.+ * For request-scoped tracking the AUTUMN_REQUEST_TRACK_EXPERIMENT gate is+ * evaluated using a stable bucket derived from the org UUID so the same+ * org always gets the same answer for a given percent value.*/async trackCredits({teamId,@@ -538,16 +493,15 @@ export class AutumnService {properties,requestScoped = false,}: TrackCreditsParams): Promise<boolean> {- const isEnabled = requestScoped- ? isAutumnRequestTrackEnabled- : isAutumnEnabled;- if (!isEnabled()) return false;+ if (requestScoped && !isAutumnRequestTrackEnabled()) return false;if (!autumnClient) return false;if (this.isPreviewTeam(teamId)) return false;try {- const orgId = await this.resolveOrgId(teamId);- if (!isEnabled(orgId)) return false;+ if (requestScoped) {+ const orgId = await this.resolveOrgId(teamId);+ if (!isAutumnRequestTrackEnabled(orgId)) return false;+ }const customerId = await this.ensureTrackingContext(teamId);return await this.track({