feat(routing): A/B Test Numerical Complexity Scoring for Gemini 3 (#16041)

Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
matt korwel
2026-01-22 16:12:07 -06:00
committed by GitHub
parent 50985d38c4
commit 57601adc90
23 changed files with 975 additions and 87 deletions
@@ -110,7 +110,7 @@ describe('FixLLMEditWithInstruction', () => {
// Verify the warning was logged
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Could not find promptId in context. This is unexpected. Using a fallback ID: llm-fixer-fallback-',
'Could not find promptId in context for llm-fixer. This is unexpected. Using a fallback ID: llm-fixer-fallback-',
),
);
+7 -9
View File
@@ -8,7 +8,7 @@ import { createHash } from 'node:crypto';
import { type Content, Type } from '@google/genai';
import { type BaseLlmClient } from '../core/baseLlmClient.js';
import { LRUCache } from 'mnemonist';
import { promptIdContext } from './promptIdContext.js';
import { getPromptIdWithFallback } from './promptIdContext.js';
import { debugLogger } from './debugLogger.js';
const MAX_CACHE_SIZE = 50;
@@ -108,7 +108,11 @@ async function generateJsonWithTimeout<T>(
]),
});
return result as T;
} catch (_err) {
} catch (err) {
debugLogger.debug(
'[LLM Edit Fixer] Timeout or error during generateJson',
err,
);
// An AbortError will be thrown on timeout.
// We catch it and return null to signal that the operation timed out.
return null;
@@ -136,13 +140,7 @@ export async function FixLLMEditWithInstruction(
baseLlmClient: BaseLlmClient,
abortSignal: AbortSignal,
): Promise<SearchReplaceEdit | null> {
let promptId = promptIdContext.getStore();
if (!promptId) {
promptId = `llm-fixer-fallback-${Date.now()}-${Math.random().toString(16).slice(2)}`;
debugLogger.warn(
`Could not find promptId in context. This is unexpected. Using a fallback ID: ${promptId}`,
);
}
const promptId = getPromptIdWithFallback('llm-fixer');
const cacheKey = createHash('sha256')
.update(
@@ -5,5 +5,24 @@
*/
import { AsyncLocalStorage } from 'node:async_hooks';
import { debugLogger } from './debugLogger.js';
export const promptIdContext = new AsyncLocalStorage<string>();
/**
* Retrieves the prompt ID from the context, or generates a fallback if not found.
* @param componentName The name of the component requesting the ID (used for the fallback prefix).
* @returns The retrieved or generated prompt ID.
*/
export function getPromptIdWithFallback(componentName: string): string {
const promptId = promptIdContext.getStore();
if (promptId) {
return promptId;
}
const fallbackId = `${componentName}-fallback-${Date.now()}-${Math.random().toString(16).slice(2)}`;
debugLogger.warn(
`Could not find promptId in context for ${componentName}. This is unexpected. Using a fallback ID: ${fallbackId}`,
);
return fallbackId;
}