Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

api: read team flag overrides through auth_chunk_2 (#4949)

claude[bot]ce8ed1233035
diff --git a/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts b/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
index 9c86ae119..86629c064 100644
--- a/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
+++ b/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
@@ -90,7 +90,7 @@ function managedRow(flags: Record<string, unknown> | null = null) {
};
}
-// auth_chunk_1 answers only when the key's purpose matches the lookup's.
+// auth_chunk_2 answers only when the key's purpose matches the lookup's.
function keyResolvesAs(flags?: Record<string, unknown>) {
mocks.authChunk.mockImplementation(
async (_db: unknown, key: string, purpose = "general") =>
diff --git a/apps/api/src/controllers/__tests__/auth.test.ts b/apps/api/src/controllers/__tests__/auth.test.ts
index 9ede0f9f8..6ca3ebb81 100644
--- a/apps/api/src/controllers/__tests__/auth.test.ts
+++ b/apps/api/src/controllers/__tests__/auth.test.ts
@@ -981,7 +981,7 @@ describe("authenticateUser", () => {
vi.mocked(redlock.using).mockImplementation(
async (_keys, _ttl, _options, fn) => fn({ aborted: false } as never),
);
- // Mirrors auth_chunk_1: a row only when the key's purpose matches.
+ // Mirrors auth_chunk_2: a row only when the key's purpose matches.
vi.mocked(authCreditUsageChunk).mockImplementation(
async (_db, key, purpose = "general") =>
key === managedKey && purpose === "hosted_mcp_oauth"
diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.ts
index 17bf0b078..14250612b 100644
--- a/apps/api/src/controllers/auth.ts
+++ b/apps/api/src/controllers/auth.ts
@@ -964,7 +964,7 @@ async function supaAuthenticateUser(
// Banned teams are rejected here, where the mcp / OAuth / API-key paths
// converge. Ban enforcement used to rely on auth_credit_usage_chunk zeroing
// the rate_limits payload, but authenticated limiting now derives from Autumn
- // and never reads that field, so bans went unenforced. auth_chunk_1 surfaces
+ // and never reads that field, so bans went unenforced. auth_chunk_2 surfaces
// teams.banned as is_banned and we deny it explicitly.
if (chunk?.is_banned) {
return {
diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts
index f80d7a0c1..4a5297282 100644
--- a/apps/api/src/controllers/v1/types.ts
+++ b/apps/api/src/controllers/v1/types.ts
@@ -1329,7 +1329,7 @@ export type AuthCreditUsageChunk = {
org_id: string;
flags: TeamFlags;
- // teams.banned surfaced from auth_chunk_1 — banned teams are rejected (403)
+ // teams.banned surfaced from auth_chunk_2 — banned teams are rejected (403)
// in supaAuthenticateUser. Optional because pre-rollout cached ACUC entries
// and the bypass/preview mocks omit it (treated as not banned).
is_banned?: boolean;
diff --git a/apps/api/src/db/rpc.ts b/apps/api/src/db/rpc.ts
index c196b12c7..3679e7506 100644
--- a/apps/api/src/db/rpc.ts
+++ b/apps/api/src/db/rpc.ts
@@ -35,7 +35,7 @@ export async function authCreditUsageChunk(
): Promise<AuthCreditUsageChunkRow[]> {
const rows = await execRows<AuthCreditUsageChunkRow>(
database,
- sql`select * from auth_chunk_1(input_key => ${input_key}, input_credential_purpose => ${input_credential_purpose})`,
+ sql`select * from auth_chunk_2(input_key => ${input_key}, input_credential_purpose => ${input_credential_purpose})`,
);
// api_key_id is a bigint column, so the pg driver hands it back as a string.
for (const row of rows) {
@@ -53,7 +53,7 @@ export function authCreditUsageChunkFromTeam(
): Promise<AuthCreditUsageChunkRow[]> {
return execRows(
database,
- sql`select * from auth_chunk_1_from_team(input_team => ${input_team})`,
+ sql`select * from auth_chunk_2_from_team(input_team => ${input_team})`,
);
}