Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(eval): allow run reactivate (#17500)

Rylan Caiae82674aa9fe
diff --git a/apps/cli/src/commands/eval.test.ts b/apps/cli/src/commands/eval.test.ts
index be9e515c223..fb6858d3652 100644
--- a/apps/cli/src/commands/eval.test.ts
+++ b/apps/cli/src/commands/eval.test.ts
@@ -557,7 +557,7 @@ describe('eval command', () => {
expect(mockTrpcClient.agentEval.deleteRun.mutate).toHaveBeenCalledWith({ id: 'r1' });
});
- it('should set run status via external API', async () => {
+ it('should set terminal run status via the external API', async () => {
mockTrpcClient.agentEvalExternal.runSetStatus.mutate.mockResolvedValue({
runId: 'run-1',
status: 'completed',
@@ -584,10 +584,10 @@ describe('eval command', () => {
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('status updated to'));
});
- it('should set run status to failed via external API', async () => {
+ it('should set run status to running', async () => {
mockTrpcClient.agentEvalExternal.runSetStatus.mutate.mockResolvedValue({
runId: 'run-1',
- status: 'failed',
+ status: 'running',
success: true,
});
@@ -601,12 +601,12 @@ describe('eval command', () => {
'--id',
'run-1',
'--status',
- 'failed',
+ 'running',
]);
expect(mockTrpcClient.agentEvalExternal.runSetStatus.mutate).toHaveBeenCalledWith({
runId: 'run-1',
- status: 'failed',
+ status: 'running',
});
});
diff --git a/apps/cli/src/commands/eval.ts b/apps/cli/src/commands/eval.ts
index f06daf2955a..7f28d4c07ef 100644
--- a/apps/cli/src/commands/eval.ts
+++ b/apps/cli/src/commands/eval.ts
@@ -124,7 +124,7 @@ const parseJsonObject = (option: string) => (value: string) => {
return parsed;
};
-const RUN_SET_STATUSES = ['completed', 'external', 'failed', 'aborted'] as const;
+const RUN_SET_STATUSES = ['running', 'completed', 'external', 'failed', 'aborted'] as const;
type RunSetStatus = (typeof RUN_SET_STATUSES)[number];
const parseRunStatus = (value: string): RunSetStatus => {
@@ -889,11 +889,11 @@ export function registerEvalCommand(program: Command) {
runCmd
.command('set-status')
- .description('Set run status (external eval API: completed | external | failed | aborted)')
+ .description('Set run status')
.requiredOption('--id <id>', 'Run ID')
.requiredOption(
'--status <status>',
- 'Status (completed | external | failed | aborted)',
+ 'Status (running | completed | external | failed | aborted)',
parseRunStatus,
)
.option('--json', 'Output JSON envelope')
diff --git a/apps/server/src/routers/lambda/agentEvalExternal.test.ts b/apps/server/src/routers/lambda/agentEvalExternal.test.ts
index 3d24a73b65e..759d5cbc495 100644
--- a/apps/server/src/routers/lambda/agentEvalExternal.test.ts
+++ b/apps/server/src/routers/lambda/agentEvalExternal.test.ts
@@ -47,7 +47,7 @@ beforeEach(() => {
});
describe('agentEvalExternalRouter.reportResult', () => {
- it('keeps a partially executed multi-case run running', async () => {
+ it('promotes an external error while keeping a partially executed run running', async () => {
const run = {
config: { k: 1 },
datasetId: 'dataset-1',
@@ -60,34 +60,48 @@ describe('agentEvalExternalRouter.reportResult', () => {
status: 'external',
topicId: 'topic-1',
};
- const completedTopic = {
+ const error = { message: 'Agent execution timed out', type: 'AgentTimeoutError' };
+ const erroredTopic = {
evalResult: { awaitingExternalEval: false },
- passed: true,
- score: 1,
- status: 'passed',
+ passed: false,
+ score: 0,
+ status: 'error',
topicId: 'topic-1',
};
mocks.findRunById.mockResolvedValue(run);
mocks.findRunTopics
.mockResolvedValueOnce([awaitingTopic])
- .mockResolvedValueOnce([completedTopic]);
+ .mockResolvedValueOnce([erroredTopic]);
mocks.countByDatasetId.mockResolvedValue(10);
mocks.evaluateAndFinalizeRun.mockResolvedValue({
completedCases: 1,
- errorCases: 0,
+ errorCases: 1,
timeoutCases: 0,
totalCases: 10,
});
mocks.updateRun.mockResolvedValue({ ...run, status: 'running' });
const result = await caller().reportResult({
- correct: true,
+ correct: false,
+ result: { error },
runId: run.id,
- score: 1,
+ score: 0,
topicId: awaitingTopic.topicId,
});
+ expect(mocks.updateRunTopic).toHaveBeenCalledWith(
+ run.id,
+ awaitingTopic.topicId,
+ expect.objectContaining({
+ evalResult: expect.objectContaining({
+ error: 'AgentTimeoutError: Agent execution timed out',
+ errorDetail: error,
+ externalResult: { error },
+ }),
+ status: 'error',
+ }),
+ );
expect(result.runStatus).toBe('running');
expect(mocks.updateRun).toHaveBeenCalledWith(
run.id,
@@ -137,4 +151,69 @@ describe('agentEvalExternalRouter.reportResult', () => {
);
expect(result.runStatus).toBe('completed');
});
+
+ it.each(['pending', 'running'] as const)(
+ 'keeps the run running while another topic is still %s',
+ async (activeStatus) => {
+ const run = {
+ config: { caseSelection: { caseIds: ['c1', 'c2'], mode: 'include' }, k: 1 },
+ datasetId: 'dataset-1',
+ id: 'run-1',
+ metrics: null,
+ startedAt: new Date(),
+ };
+ const reportingTopic = {
+ evalResult: { awaitingExternalEval: true },
+ status: 'external',
+ topicId: 'topic-1',
+ };
+ const passedTopic = {
+ evalResult: { awaitingExternalEval: false },
+ passed: true,
+ score: 1,
+ status: 'passed',
+ topicId: 'topic-1',
+ };
+ const activeTopic = { status: activeStatus, topicId: 'topic-2' };
+
+ mocks.findRunById.mockResolvedValue(run);
+ mocks.findRunTopics
+ .mockResolvedValueOnce([reportingTopic, activeTopic])
+ .mockResolvedValueOnce([passedTopic, activeTopic]);
+ mocks.countByDatasetId.mockResolvedValue(2);
+ mocks.evaluateAndFinalizeRun.mockResolvedValue({
+ completedCases: 2,
+ errorCases: 0,
+ timeoutCases: 0,
+ totalCases: 2,
+ });
+ mocks.updateRun.mockResolvedValue({ ...run, status: 'running' });
+
+ const result = await caller().reportResult({
+ correct: true,
+ runId: run.id,
+ score: 1,
+ topicId: reportingTopic.topicId,
+ });
+
+ expect(result.runStatus).toBe('running');
+ expect(mocks.updateRun).toHaveBeenCalledWith(
+ run.id,
+ expect.objectContaining({ status: 'running' }),
+ );
+ },
+ );
+});
+
+describe('agentEvalExternalRouter.runSetStatus', () => {
+ it('sets an existing run to running', async () => {
+ mocks.findRunById.mockResolvedValue({ id: 'run-1', status: 'external' });
+ mocks.updateRun.mockResolvedValue({ id: 'run-1', status: 'running' });
+
+ const result = await caller().runSetStatus({ runId: 'run-1', status: 'running' });
+
+ expect(mocks.updateRun).toHaveBeenCalledWith('run-1', { status: 'running' });
+ expect(mocks.evaluateAndFinalizeRun).not.toHaveBeenCalled();
+ expect(result).toEqual({ runId: 'run-1', status: 'running', success: true });
+ });
});
diff --git a/apps/server/src/routers/lambda/agentEvalExternal.ts b/apps/server/src/routers/lambda/agentEvalExternal.ts
index 135545a356b..f9fccf18c38 100644
--- a/apps/server/src/routers/lambda/agentEvalExternal.ts
+++ b/apps/server/src/routers/lambda/agentEvalExternal.ts
@@ -148,7 +148,10 @@ const recomputeRunAggregation = async (
topic.status === 'external' ||
(topic.evalResult as Record<string, unknown> | null)?.awaitingExternalEval === true,
);
- const status = resolveRunStatus(metrics, hasAwaitingExternal);
+ const hasActiveTopic = refreshedTopics.some(
+ (topic) => topic.status === 'pending' || topic.status === 'running',
+ );
+ const status = hasActiveTopic ? 'running' : resolveRunStatus(metrics, hasAwaitingExternal);
await ctx.runModel.update(runId, { metrics, status });
@@ -309,8 +312,14 @@ const applyReportResult = async (
});
}
} else {
+ const externalError = externalResult.error as Record<string, unknown> | string | undefined;
+ const errorMessage =
+ typeof externalError === 'string'
+ ? externalError
+ : [externalError?.type, externalError?.message].filter(Boolean).join(': ') || undefined;
+ const topicStatus = errorMessage ? 'error' : input.correct ? 'passed' : 'failed';
const alreadyReported =
- runTopic.status === (input.correct ? 'passed' : 'failed') &&
+ runTopic.status === topicStatus &&
runTopic.score === input.score &&
runTopic.passed === input.correct &&
isEqual(existingEvalResult.externalResult, externalResult);
@@ -323,12 +332,19 @@ const applyReportResult = async (
externalResult,
rubricScores,
} satisfies EvalRunTopicResult & Record<string, unknown>;
+ if (errorMessage) {
+ nextEvalResult.error = errorMessage;
+ nextEvalResult.errorDetail = externalError;
+ } else {
+ delete nextEvalResult.error;
+ delete nextEvalResult.errorDetail;
+ }
await ctx.runTopicModel.updateByRunAndTopic(input.runId, input.topicId, {
evalResult: nextEvalResult,
passed: input.correct,
score: input.score,
- status: input.correct ? 'passed' : 'failed',
+ status: topicStatus,
});
}
@@ -544,6 +560,11 @@ export const agentEvalExternalRouter = router({
throw new TRPCError({ code: 'NOT_FOUND', message: 'Run not found' });
}
+ if (input.status === 'running') {
+ const updated = await ctx.runModel.update(input.runId, { status: 'running' });
+ return { runId: input.runId, status: updated?.status ?? 'running', success: true };
+ }
+
// Worker-driven terminal failure/abort: allowed from any non-terminal
// state. Marks remaining non-terminal RunTopics aborted and finalizes.
if (input.status === 'failed' || input.status === 'aborted') {