Fix handler

This commit is contained in:
Siddharth Ganesan
2026-03-14 11:31:11 -07:00
parent cd055842e3
commit 160aa7b664
2 changed files with 57 additions and 0 deletions

View File

@@ -561,15 +561,35 @@ export const subAgentHandlers: Record<string, SSEHandler> = {
const { requiresConfirmation, clientExecutable, internal } = getEventUI(event)
logger.info('[DIAG] subAgentHandlers.tool_call decision point', {
toolCallId,
toolName,
parentToolCallId,
isPartial,
internal,
requiresConfirmation,
clientExecutable,
isAvailableOnSimSide: isToolAvailableOnSimSide(toolName),
interactive: options.interactive,
autoExecuteTools: options.autoExecuteTools,
wasResultSeen: wasToolResultSeen(toolCallId),
})
if (internal) {
logger.info('[DIAG] subAgentHandlers.tool_call SKIPPED (internal)', { toolCallId, toolName })
return
}
if (!isToolAvailableOnSimSide(toolName)) {
logger.info('[DIAG] subAgentHandlers.tool_call SKIPPED (not available on sim side)', {
toolCallId,
toolName,
})
return
}
const fireToolExecution = () => {
logger.info('[DIAG] subAgentHandlers.tool_call FIRING execution', { toolCallId, toolName })
executeToolAndReport(toolCallId, context, execContext, options).catch((err) => {
logger.error('Parallel subagent tool execution failed', {
toolCallId,
@@ -593,6 +613,11 @@ export const subAgentHandlers: Record<string, SSEHandler> = {
}
if (options.autoExecuteTools !== false) {
fireToolExecution()
} else {
logger.info('[DIAG] subAgentHandlers.tool_call SKIPPED (autoExecuteTools=false)', {
toolCallId,
toolName,
})
}
return
}
@@ -737,5 +762,14 @@ export function handleSubagentRouting(event: SSEEvent, context: StreamingContext
})
return false
}
if (event.type === 'tool_call') {
logger.info('[DIAG] handleSubagentRouting routing tool_call to subAgentHandlers', {
toolCallId: event.toolCallId,
toolName: event.toolName,
subagent: event.subagent,
parentToolCallId: context.subAgentParentToolCallId,
stackDepth: context.subAgentParentStack.length,
})
}
return true
}

View File

@@ -149,11 +149,34 @@ export async function runStreamLoop(
const normalizedEvent = normalizeSseEvent(event)
// [DIAG] Log all tool_call and subagent events for nested agent debugging
if (
normalizedEvent.type === 'tool_call' ||
normalizedEvent.type === 'subagent_start' ||
normalizedEvent.type === 'subagent_end'
) {
logger.info('[DIAG] SSE event received', {
type: normalizedEvent.type,
subagent: normalizedEvent.subagent,
agent: (normalizedEvent as any).agent,
toolCallId: normalizedEvent.toolCallId,
toolName: normalizedEvent.toolName,
parentStack: [...context.subAgentParentStack],
parentToolCallId: context.subAgentParentToolCallId,
})
}
// Skip duplicate tool events — both forwarding AND handler dispatch.
const shouldSkipToolCall = shouldSkipToolCallEvent(normalizedEvent)
const shouldSkipToolResult = shouldSkipToolResultEvent(normalizedEvent)
if (shouldSkipToolCall || shouldSkipToolResult) {
if (shouldSkipToolCall) {
logger.info('[DIAG] Skipping duplicate tool_call', {
toolCallId: normalizedEvent.toolCallId,
toolName: normalizedEvent.toolName,
})
}
continue
}