fix: Use UUID thread IDs for Instance AI evals (no-changelog) (#31830)

This commit is contained in:
oleg
2026-06-05 13:15:45 +00:00
committed by GitHub
parent a54ddff3f6
commit 2925d654d1
3 changed files with 42 additions and 2 deletions
@@ -0,0 +1,40 @@
import { vi } from 'vitest';
import type { N8nClient } from '../clients/n8n-client';
import type { EvalLogger } from '../harness/logger';
import { buildWorkflow } from '../harness/runner';
const silentLogger: EvalLogger = {
info: () => {},
verbose: () => {},
success: () => {},
warn: () => {},
error: () => {},
isVerbose: false,
};
const uuidV4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
describe('buildWorkflow thread IDs', () => {
it('uses UUID thread IDs accepted by the instance-ai thread endpoint', async () => {
let capturedThreadId = '';
const client = {
ensureThread: vi.fn(async (threadId: string) => {
capturedThreadId = threadId;
await Promise.resolve();
throw new Error('stop after ensureThread');
}),
} as unknown as N8nClient;
await buildWorkflow({
client,
conversation: [{ role: 'user', text: 'build a workflow' }],
preRunWorkflowIds: new Set(),
claimedWorkflowIds: new Set(),
logger: silentLogger,
});
expect(client.ensureThread).toHaveBeenCalledTimes(1);
expect(capturedThreadId).toMatch(uuidV4Pattern);
});
});
@@ -42,7 +42,7 @@ export interface RunChatOptions {
*/
export async function runChat(options: RunChatOptions): Promise<ScenarioTrace> {
const { client, prompt, timeoutMs, logger } = options;
const threadId = `cu-eval-${crypto.randomUUID()}`;
const threadId = crypto.randomUUID();
const startTime = Date.now();
const abortController = new AbortController();
@@ -299,7 +299,7 @@ function isMultiTurnConversation(conversation: ConversationTurn[]): boolean {
export async function buildWorkflow(config: BuildWorkflowConfig): Promise<BuildResult> {
const { client, conversation, logger } = config;
const openingMessage = conversation[0]?.text ?? '';
const threadId = `eval-${crypto.randomUUID()}`;
const threadId = crypto.randomUUID();
const startTime = Date.now();
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;