Skip to content

Commit 1bd73bd

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(logs): recognize nested tool failure results
1 parent efd0dd5 commit 1bd73bd

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

apps/sim/lib/logs/execution/trace-spans/span-factory.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function nonEmptyString(value: unknown): string | undefined {
3333
/**
3434
* Returns the canonical error message for a failed agent tool call.
3535
*
36-
* Providers expose failures through several normalized shapes. The nested
37-
* fallback intentionally requires Sim's complete error envelope so ordinary
38-
* successful tool data with an `error` field is not misclassified.
36+
* Providers expose failures through several normalized shapes. A nested
37+
* `success: false` is explicit; the generic nested fallback requires Sim's
38+
* complete error envelope so successful tool data with an `error` field is
39+
* not misclassified.
3940
*/
4041
function getToolCallErrorMessage(
4142
toolCall: BlockToolCall | undefined,
@@ -48,6 +49,7 @@ function getToolCallErrorMessage(
4849
const hasExplicitFailure =
4950
toolCall?.success === false ||
5051
toolCall?.status === 'error' ||
52+
result?.success === false ||
5153
topLevelError !== undefined ||
5254
segmentError !== undefined
5355
const hasStandardSimError =

apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,23 @@ describe('buildTraceSpans', () => {
341341
expect(toolCall.output).toEqual({ analysis: 'completed' })
342342
})
343343

344-
it.concurrent('handles tool calls with errors in timeSegments', () => {
344+
it.concurrent.each([
345+
{
346+
toolResult: {
347+
error: true,
348+
message: 'Tool execution failed',
349+
tool: 'custom_failing_tool',
350+
},
351+
expectedMessage: 'Tool execution failed',
352+
},
353+
{
354+
toolResult: {
355+
success: false,
356+
error: 'MCP server connection failed',
357+
},
358+
expectedMessage: 'MCP server connection failed',
359+
},
360+
])('handles tool calls with errors in timeSegments', ({ toolResult, expectedMessage }) => {
345361
const mockExecutionResult: ExecutionResult = {
346362
success: true,
347363
output: { content: 'Final output' },
@@ -392,11 +408,7 @@ describe('buildTraceSpans', () => {
392408
{
393409
name: 'failing_tool',
394410
arguments: { input: 'test' },
395-
result: {
396-
error: true,
397-
message: 'Tool execution failed',
398-
tool: 'custom_failing_tool',
399-
},
411+
result: toolResult,
400412
duration: 1000,
401413
startTime: '2024-01-01T10:00:01.000Z',
402414
endTime: '2024-01-01T10:00:02.000Z',
@@ -425,13 +437,9 @@ describe('buildTraceSpans', () => {
425437
expect(toolSegment.type).toBe('tool')
426438
expect(toolSegment.status).toBe('error')
427439
expect(toolSegment.errorHandled).toBe(true)
428-
expect(toolSegment.errorMessage).toBe('Tool execution failed')
440+
expect(toolSegment.errorMessage).toBe(expectedMessage)
429441
expect(toolSegment.input).toEqual({ input: 'test' })
430-
expect(toolSegment.output).toEqual({
431-
error: true,
432-
message: 'Tool execution failed',
433-
tool: 'custom_failing_tool',
434-
})
442+
expect(toolSegment.output).toEqual(toolResult)
435443
})
436444

437445
it.concurrent('handles blocks without tool calls', () => {

0 commit comments

Comments
 (0)