fix(core): enable numerical routing for api key users (#21977)

This commit is contained in:
Sehoon Shon
2026-03-11 14:54:52 -04:00
committed by GitHub
parent 08e174a05c
commit 36ce2ba96e
6 changed files with 163 additions and 146 deletions
+89
View File
@@ -492,6 +492,95 @@ describe('Server Config (config.ts)', () => {
expect(await config.getUserCaching()).toBeUndefined();
});
});
describe('getNumericalRoutingEnabled', () => {
it('should return true by default if there are no experiments', async () => {
const config = new Config(baseParams);
expect(await config.getNumericalRoutingEnabled()).toBe(true);
});
it('should return true if the remote flag is set to true', async () => {
const config = new Config({
...baseParams,
experiments: {
flags: {
[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]: {
boolValue: true,
},
},
experimentIds: [],
},
} as unknown as ConfigParameters);
expect(await config.getNumericalRoutingEnabled()).toBe(true);
});
it('should return false if the remote flag is explicitly set to false', async () => {
const config = new Config({
...baseParams,
experiments: {
flags: {
[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]: {
boolValue: false,
},
},
experimentIds: [],
},
} as unknown as ConfigParameters);
expect(await config.getNumericalRoutingEnabled()).toBe(false);
});
});
describe('getResolvedClassifierThreshold', () => {
it('should return 90 by default if there are no experiments', async () => {
const config = new Config(baseParams);
expect(await config.getResolvedClassifierThreshold()).toBe(90);
});
it('should return the remote flag value if it is within range (0-100)', async () => {
const config = new Config({
...baseParams,
experiments: {
flags: {
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
intValue: '75',
},
},
experimentIds: [],
},
} as unknown as ConfigParameters);
expect(await config.getResolvedClassifierThreshold()).toBe(75);
});
it('should return 90 if the remote flag is out of range (less than 0)', async () => {
const config = new Config({
...baseParams,
experiments: {
flags: {
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
intValue: '-10',
},
},
experimentIds: [],
},
} as unknown as ConfigParameters);
expect(await config.getResolvedClassifierThreshold()).toBe(90);
});
it('should return 90 if the remote flag is out of range (greater than 100)', async () => {
const config = new Config({
...baseParams,
experiments: {
flags: {
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
intValue: '110',
},
},
experimentIds: [],
},
} as unknown as ConfigParameters);
expect(await config.getResolvedClassifierThreshold()).toBe(90);
});
});
});
describe('refreshAuth', () => {
+24 -2
View File
@@ -2512,8 +2512,30 @@ export class Config implements McpContext, AgentLoopContext {
async getNumericalRoutingEnabled(): Promise<boolean> {
await this.ensureExperimentsLoaded();
return !!this.experiments?.flags[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]
?.boolValue;
const flag =
this.experiments?.flags[ExperimentFlags.ENABLE_NUMERICAL_ROUTING];
return flag?.boolValue ?? true;
}
/**
* Returns the resolved complexity threshold for routing.
* If a remote threshold is provided and within range (0-100), it is returned.
* Otherwise, the default threshold (90) is returned.
*/
async getResolvedClassifierThreshold(): Promise<number> {
const remoteValue = await this.getClassifierThreshold();
const defaultValue = 90;
if (
remoteValue !== undefined &&
!isNaN(remoteValue) &&
remoteValue >= 0 &&
remoteValue <= 100
) {
return remoteValue;
}
return defaultValue;
}
async getClassifierThreshold(): Promise<number | undefined> {