diff --git a/apps/docs/openapi-v2-logs.json b/apps/docs/openapi-v2-logs.json index 046b37bb072..9544e65e629 100644 --- a/apps/docs/openapi-v2-logs.json +++ b/apps/docs/openapi-v2-logs.json @@ -1395,6 +1395,10 @@ "type": "string", "description": "Workflow block associated with the span." }, + "childDeploymentVersionId": { + "type": "string", + "description": "Deployment version of the child workflow this call ran, on a workflow block span or a workflow Agent tool span. Match it to the child workflow's versions list. Absent for draft children, custom blocks, failed Agent tool calls, and runs recorded before this field existed." + }, "input": { "description": "Input captured for the traced operation." }, diff --git a/apps/sim/executor/errors/child-workflow-error.ts b/apps/sim/executor/errors/child-workflow-error.ts index a5505acfbd3..4fc22d1deb1 100644 --- a/apps/sim/executor/errors/child-workflow-error.ts +++ b/apps/sim/executor/errors/child-workflow-error.ts @@ -8,6 +8,8 @@ interface ChildWorkflowErrorOptions { childTraceSpans?: TraceSpan[] executionResult?: ExecutionResult childWorkflowSnapshotId?: string + /** The deployment version a deployed workflow-block child ran; unset for draft and custom-block children. */ + childDeploymentVersionId?: string childWorkflowInstanceId?: string /** Child workflow names from this invocation down to the failing run, outermost first. */ workflowChain?: string[] @@ -38,6 +40,7 @@ export class ChildWorkflowError extends Error { readonly childWorkflowName: string readonly executionResult?: ExecutionResult readonly childWorkflowSnapshotId?: string + readonly childDeploymentVersionId?: string /** Per-invocation unique ID used to correlate child block events with this workflow block. */ readonly childWorkflowInstanceId?: string /** @@ -59,6 +62,7 @@ export class ChildWorkflowError extends Error { this.childTraceSpans = options.childTraceSpans ?? [] this.executionResult = options.executionResult this.childWorkflowSnapshotId = options.childWorkflowSnapshotId + this.childDeploymentVersionId = options.childDeploymentVersionId this.childWorkflowInstanceId = options.childWorkflowInstanceId this.workflowChain = options.workflowChain ?? [options.childWorkflowName] this.rootErrorMessage = options.rootErrorMessage ?? options.message diff --git a/apps/sim/executor/execution/block-executor.test.ts b/apps/sim/executor/execution/block-executor.test.ts index 0a7f700288e..d6d86217225 100644 --- a/apps/sim/executor/execution/block-executor.test.ts +++ b/apps/sim/executor/execution/block-executor.test.ts @@ -736,6 +736,44 @@ describe('BlockExecutor', () => { ) }) + it.each([ + [BlockType.WORKFLOW_INPUT, 'dv-7'], + ['custom_block_abc', undefined], + ])( + 'records the child deployment version on a failed %s block only when it is a workflow block', + async (blockType, expected) => { + const block = { ...createBlock(), metadata: { id: blockType, name: 'Child' } } + const state = new ExecutionState() + const workflow: SerializedWorkflow = { + version: '1', + blocks: [block], + connections: [], + loops: {}, + parallels: {}, + } + const handler: BlockHandler = { + canHandle: () => true, + execute: async () => { + throw new ChildWorkflowError({ + message: '"Child" failed: boom', + childWorkflowName: 'Child', + childDeploymentVersionId: 'dv-7', + }) + }, + } + const executor = new BlockExecutor( + [handler], + new VariableResolver(workflow, {}, state), + {}, + state + ) + + await executor.execute(createContext(state), createNode(block), block).catch(() => undefined) + + expect(state.getBlockOutput(block.id)?.childDeploymentVersionId).toBe(expected) + } + ) + it('does not soft-succeed non-agent blocks on user AbortError', async () => { const block = createBlock() const workflow: SerializedWorkflow = { diff --git a/apps/sim/executor/execution/block-executor.ts b/apps/sim/executor/execution/block-executor.ts index 84378d59839..96dcc1f1061 100644 --- a/apps/sim/executor/execution/block-executor.ts +++ b/apps/sim/executor/execution/block-executor.ts @@ -760,6 +760,9 @@ export class BlockExecutor { if (error.childWorkflowSnapshotId) { errorOutput.childWorkflowSnapshotId = error.childWorkflowSnapshotId } + if (error.childDeploymentVersionId) { + errorOutput.childDeploymentVersionId = error.childDeploymentVersionId + } } // A custom block's consumer gets a machine-readable failure class and an // opaque handle to the failed run — enough to branch on and to quote in a diff --git a/apps/sim/executor/handlers/agent/handler.test.ts b/apps/sim/executor/handlers/agent/handler.test.ts index 198a68d5b9f..7216c58c843 100644 --- a/apps/sim/executor/handlers/agent/handler.test.ts +++ b/apps/sim/executor/handlers/agent/handler.test.ts @@ -3540,6 +3540,34 @@ describe('AgentBlockHandler', () => { }) }) + it('keeps a custom tool titled like the workflow tool from claiming a child version', async () => { + mockExecuteProviderRequest.mockResolvedValueOnce({ + content: 'done', + model: 'mock-model', + tokens: { input: 10, output: 20, total: 30 }, + toolCalls: [ + { name: 'custom_workflow_executor', result: { childDeploymentVersionId: 'forged' } }, + { name: 'workflow_executor', result: { childDeploymentVersionId: 'dv-7' } }, + { name: 'custom_lookup', result: { childDeploymentVersionId: 'user-data' } }, + ], + cost: 0.001, + timing: { total: 100 }, + }) + + const result = await handler.execute(mockContext, mockBlock, { + model: 'gpt-4o', + userPrompt: 'Score it', + apiKey: 'test-api-key', + }) + + const [custom, workflow, otherCustom] = ( + result as { toolCalls: { list: Array<{ result: Record }> } } + ).toolCalls.list + expect(custom.result).not.toHaveProperty('childDeploymentVersionId') + expect(workflow.result.childDeploymentVersionId).toBe('dv-7') + expect(otherCustom.result.childDeploymentVersionId).toBe('user-data') + }) + it('uses a secret-backed skillId for lookup without carrying it into output provenance', async () => { const skillId = 'x' mockContext.workspaceId = 'workspace-1' diff --git a/apps/sim/executor/handlers/agent/handler.ts b/apps/sim/executor/handlers/agent/handler.ts index 183ae88d95f..90c44d3e588 100644 --- a/apps/sim/executor/handlers/agent/handler.ts +++ b/apps/sim/executor/handlers/agent/handler.ts @@ -63,7 +63,13 @@ import { validateBlockType, validateModelProvider, } from '@/ee/access-control/utils/permission-check' -import { AGENT, BlockType, DEFAULTS, stripCustomToolPrefix } from '@/executor/constants' +import { + AGENT, + BlockType, + DEFAULTS, + isCustomTool, + stripCustomToolPrefix, +} from '@/executor/constants' import { getMemoryMessageAppendKey, getMemoryMessageTurnId, @@ -3227,6 +3233,7 @@ export class AgentBlockHandler implements BlockHandler { private formatToolCall(tc: any) { const toolName = stripCustomToolPrefix(tc.name) + const result = tc.result || tc.output return { ...tc, @@ -3235,7 +3242,12 @@ export class AgentBlockHandler implements BlockHandler { endTime: tc.endTime, duration: tc.duration, arguments: tc.arguments || tc.input || {}, - result: tc.result || tc.output, + // The span factory trusts this key only on a `workflow_executor` call. Stripping the prefix + // would let a custom tool titled `workflow_executor` claim a child version it never ran. + result: + isCustomTool(tc.name) && toolName === 'workflow_executor' && isRecordLike(result) + ? omit(result, ['childDeploymentVersionId']) + : result, } } } diff --git a/apps/sim/executor/handlers/workflow/handler.test.ts b/apps/sim/executor/handlers/workflow/handler.test.ts index 2f0cbad2274..095e8c499c4 100644 --- a/apps/sim/executor/handlers/workflow/handler.test.ts +++ b/apps/sim/executor/handlers/workflow/handler.test.ts @@ -358,6 +358,86 @@ describe('WorkflowBlockHandler', () => { }) }) + describe('child deployment version', () => { + const inputs = { workflowId: 'child-workflow-id' } + const deployedCtx = () => + ({ + ...mockContext, + workspaceId: 'workspace-parent', + isDeployedContext: true, + }) as unknown as ExecutionContext + + beforeEach(() => { + mockReadWorkflowDefinitionAsExecutor.mockResolvedValue({ + workflow: { id: 'child-workflow-id', name: 'Score', variables: {} }, + workspaceId: 'workspace-parent', + state: { + blocks: {}, + edges: [], + loops: {}, + parallels: {}, + deploymentVersionId: 'dv-7', + }, + }) + mockResolveSnapshot.mockResolvedValue({ id: 'snapshot-1', workflowId: 'w', stateHash: 'h' }) + }) + + it('records the version a deployed child ran', async () => { + mockExecutorExecute.mockResolvedValue({ success: true, output: { data: 'ok' } }) + + const output = await handler.execute(deployedCtx(), mockBlock, inputs) + + expect(output).toMatchObject({ childDeploymentVersionId: 'dv-7' }) + }) + + it('records the version on a deployed child that reports a failure', async () => { + mockExecutorExecute.mockResolvedValue({ success: false, error: 'boom', output: {} }) + + const failure = await handler.execute(deployedCtx(), mockBlock, inputs).catch((e) => e) + + expect(failure).toMatchObject({ childDeploymentVersionId: 'dv-7' }) + }) + + it('records the version on a deployed child that throws', async () => { + mockExecutorExecute.mockRejectedValue(new Error('engine blew up')) + + const failure = await handler.execute(deployedCtx(), mockBlock, inputs).catch((e) => e) + + expect(failure).toMatchObject({ childDeploymentVersionId: 'dv-7' }) + }) + + it('records no version for a deployed child refused by the workspace check', async () => { + mockReadWorkflowDefinitionAsExecutor.mockResolvedValue({ + workflow: { id: 'child-workflow-id', name: 'Score', variables: {} }, + workspaceId: 'workspace-other', + state: { blocks: {}, edges: [], loops: {}, parallels: {}, deploymentVersionId: 'dv-7' }, + }) + + const failure = await handler.execute(deployedCtx(), mockBlock, inputs).catch((e) => e) + + expect(failure.message).toContain('belongs to a different workspace') + expect(failure).not.toHaveProperty('childDeploymentVersionId', 'dv-7') + }) + + it('records no version for a draft child', async () => { + mockReadWorkflowDefinitionAsExecutor.mockResolvedValue({ + workflow: { id: 'child-workflow-id', name: 'Score', variables: {} }, + workspaceId: 'workspace-parent', + state: { blocks: {}, edges: [], loops: {}, parallels: {} }, + }) + mockExecutorExecute.mockResolvedValue({ success: true, output: { data: 'ok' } }) + + const output = await handler.execute( + { ...mockContext, workspaceId: 'workspace-parent' } as unknown as ExecutionContext, + mockBlock, + inputs + ) + + expect(output).toMatchObject({ childWorkflowId: 'child-workflow-id' }) + expect(output).not.toHaveProperty('childDeploymentVersionId') + }) + }) + describe('workspace containment', () => { const inputs = { workflowId: 'child-workflow-id' } diff --git a/apps/sim/executor/handlers/workflow/handler.ts b/apps/sim/executor/handlers/workflow/handler.ts index 62b37772388..a2d8bc4cf4c 100644 --- a/apps/sim/executor/handlers/workflow/handler.ts +++ b/apps/sim/executor/handlers/workflow/handler.ts @@ -1,7 +1,7 @@ import { createLogger } from '@sim/logger' import { findCause, getErrorMessage, toError } from '@sim/utils/errors' import { generateId } from '@sim/utils/id' -import { isRecordLike } from '@sim/utils/object' +import { filterUndefined, isRecordLike } from '@sim/utils/object' import type { Variable, WorkflowState } from '@sim/workflow-types/workflow' import { resolveBillingAttribution } from '@/lib/billing/core/attribution' import { DelegatedWorkspaceAuthorizationError } from '@/lib/core/application' @@ -350,6 +350,8 @@ export class WorkflowBlockHandler implements BlockHandler { } let childWorkflowSnapshotId: string | undefined + /** Unset for draft children, and for custom blocks so the consumer learns nothing of the source. */ + let childDeploymentVersionId: string | undefined /** Set for custom blocks only: the child's own execution id / log row. */ let childExecutionId: string | undefined let childSession: LoggingSession | undefined @@ -444,6 +446,9 @@ export class WorkflowBlockHandler implements BlockHandler { // skipped or every custom-block invocation from another workspace throws. if (!isCustomBlock) { this.assertChildWorkflowInWorkspace(workflowId, childWorkflow.workspaceId, ctx.workspaceId) + // Recorded only once the child is known to be this workspace's, so a refusal never names + // another workspace's version. + childDeploymentVersionId = childWorkflow.deploymentVersionId } childWorkflowName = childWorkflow.name || 'Unknown Workflow' @@ -999,7 +1004,7 @@ export class WorkflowBlockHandler implements BlockHandler { childWorkflowName, instanceId, childTraceSpans, - childWorkflowSnapshotId, + { childWorkflowSnapshotId, childDeploymentVersionId }, { executionId: ctx.executionId, blockId: block.id } ) @@ -1097,6 +1102,7 @@ export class WorkflowBlockHandler implements BlockHandler { childTraceSpans, executionResult, childWorkflowSnapshotId, + childDeploymentVersionId, childWorkflowInstanceId: instanceId, cause: error instanceof Error ? error : undefined, }) @@ -1587,7 +1593,7 @@ export class WorkflowBlockHandler implements BlockHandler { childWorkflowName: string, instanceId: string, childTraceSpans?: WorkflowTraceSpan[], - childWorkflowSnapshotId?: string, + childRun: { childWorkflowSnapshotId?: string; childDeploymentVersionId?: string } = {}, parent?: { executionId?: string; blockId: string } ): BlockOutput { const success = childResult.success !== false @@ -1606,7 +1612,7 @@ export class WorkflowBlockHandler implements BlockHandler { workflowChain: chain, rootErrorMessage, childTraceSpans: childTraceSpans || [], - childWorkflowSnapshotId, + ...childRun, childWorkflowInstanceId: instanceId, }) /** The warning above is this failure's log line. */ @@ -1618,7 +1624,7 @@ export class WorkflowBlockHandler implements BlockHandler { success: true, childWorkflowName, childWorkflowId, - ...(childWorkflowSnapshotId ? { childWorkflowSnapshotId } : {}), + ...filterUndefined(childRun), result, childTraceSpans: childTraceSpans || [], _childWorkflowInstanceId: instanceId, diff --git a/apps/sim/lib/api/contracts/logs.ts b/apps/sim/lib/api/contracts/logs.ts index 0c85e989a31..6db317d1793 100644 --- a/apps/sim/lib/api/contracts/logs.ts +++ b/apps/sim/lib/api/contracts/logs.ts @@ -213,6 +213,7 @@ export type LogTraceSpan = { errorType?: string errorMessage?: string blockId?: string + childDeploymentVersionId?: string input?: unknown output?: unknown tokens?: number | { total?: number; input?: number; output?: number } @@ -244,6 +245,12 @@ export const traceSpanSchema: z.ZodType = z errorType: z.string().describe('Recorded error type.').optional(), errorMessage: z.string().describe('Recorded error message.').optional(), blockId: z.string().describe('Workflow block associated with the span.').optional(), + childDeploymentVersionId: z + .string() + .describe( + "Deployment version of the child workflow this call ran, on a workflow block span or a workflow Agent tool span. Match it to the child workflow's versions list. Absent for draft children, custom blocks, failed Agent tool calls, and runs recorded before this field existed." + ) + .optional(), input: z.unknown().describe('Input captured for the traced operation.').optional(), output: z.unknown().describe('Output captured for the traced operation.').optional(), tokens: z diff --git a/apps/sim/lib/logs/execution/trace-spans/factory.ts b/apps/sim/lib/logs/execution/trace-spans/factory.ts index af9b981aed5..63e3f1849a1 100644 --- a/apps/sim/lib/logs/execution/trace-spans/factory.ts +++ b/apps/sim/lib/logs/execution/trace-spans/factory.ts @@ -1,5 +1,5 @@ import { createLogger } from '@sim/logger' -import { isRecordLike } from '@sim/utils/object' +import { isRecordLike, omit } from '@sim/utils/object' import type { ProviderTiming, TraceSpan } from '@/lib/logs/types' import { CHILD_EXECUTION_ID_OUTPUT_KEY, @@ -17,6 +17,9 @@ import type { const logger = createLogger('SpanFactory') +/** The Agent tool that runs a workflow in-process through the workflow block handler. */ +const WORKFLOW_TOOL_ID = 'workflow_executor' + /** A BlockLog that has already passed the id/type validity check. */ type ValidBlockLog = BlockLog & { blockType: string } @@ -95,7 +98,7 @@ export function createSpanFromLog(log: BlockLog): TraceSpan | null { function createBaseSpan(log: ValidBlockLog): TraceSpan { const spanId = `${log.blockId}-${new Date(log.startedAt).getTime()}` const output = extractDisplayOutput(log) - const childIds = extractChildWorkflowIds(log.output) + const childIds = extractChildWorkflowIds(log) return { id: spanId, @@ -141,22 +144,54 @@ function extractDisplayOutput(log: ValidBlockLog): Record { childTraceSpans: _childTraceSpans, ...rest } = log.output ?? {} - return log.error ? { ...rest, error: log.error } : rest + const display = isWorkflowBlockType(log.blockType) + ? omit(rest, ['childDeploymentVersionId']) + : rest + return log.error ? { ...display, error: log.error } : display } -/** Pulls child-workflow identifiers off the output so they can live on the span. */ -function extractChildWorkflowIds( - output: NormalizedBlockOutput | undefined -): { childWorkflowSnapshotId?: string; childWorkflowId?: string } | undefined { +type ChildWorkflowIds = Pick< + TraceSpan, + 'childWorkflowSnapshotId' | 'childWorkflowId' | 'childDeploymentVersionId' +> + +/** + * Pulls child-workflow identifiers off the output so they can live on the span. The deployment + * version is taken only from a workflow block, so no other block can claim one by returning the key. + */ +function extractChildWorkflowIds(log: ValidBlockLog): ChildWorkflowIds | undefined { + const output = log.output if (!output) return undefined - const ids: { childWorkflowSnapshotId?: string; childWorkflowId?: string } = {} + const ids: ChildWorkflowIds = {} if (typeof output.childWorkflowSnapshotId === 'string') { ids.childWorkflowSnapshotId = output.childWorkflowSnapshotId } if (typeof output.childWorkflowId === 'string') { ids.childWorkflowId = output.childWorkflowId } - return ids.childWorkflowSnapshotId || ids.childWorkflowId ? ids : undefined + if (isWorkflowBlockType(log.blockType)) { + Object.assign(ids, childDeploymentVersionOf(output)) + } + return Object.keys(ids).length > 0 ? ids : undefined +} + +/** The deployment version a child workflow run reports, as a span field. */ +function childDeploymentVersionOf( + output: Record | undefined +): Pick { + const versionId = output?.childDeploymentVersionId + return typeof versionId === 'string' ? { childDeploymentVersionId: versionId } : {} +} + +/** + * The deployment version a workflow run as an Agent tool reported. Read only for + * `workflow_executor`, so another tool returning the same key records nothing. + */ +function workflowToolVersion( + toolName: string, + output: Record | undefined +): Pick { + return toolName === WORKFLOW_TOOL_ID ? childDeploymentVersionOf(output) : {} } /** Enriches a span with provider timing, cost, tokens, and model from block output. */ @@ -263,6 +298,7 @@ function buildChildrenFromTimeSegments( input: match?.arguments ?? match?.input, output: match?.error ? { error: match.error, ...output } : output, ...handle, + ...workflowToolVersion(normalizedName, output), } if (segment.toolCallId) toolChild.toolCallId = segment.toolCallId if (segment.errorType) toolChild.errorType = segment.errorType @@ -330,9 +366,10 @@ function buildChildrenFromToolCalls(span: TraceSpan, log: ValidBlockLog): TraceS const startTime = tc.startTime ?? log.startedAt const endTime = tc.endTime ?? log.endedAt const { output, handle } = liftChildTraceHandle(normalizeTraceOutput(tc.result ?? tc.output)) + const name = stripCustomToolPrefix(tc.name ?? 'unnamed-tool') return { id: `${span.id}-tool-${index}`, - name: stripCustomToolPrefix(tc.name ?? 'unnamed-tool'), + name, type: 'tool', duration: tc.duration ?? 0, startTime, @@ -341,6 +378,7 @@ function buildChildrenFromToolCalls(span: TraceSpan, log: ValidBlockLog): TraceS input: tc.arguments ?? tc.input, output: tc.error ? { error: tc.error, ...output } : output, ...handle, + ...workflowToolVersion(name, output), } }) } diff --git a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts index 85c66c845f3..a6bd517ff9f 100644 --- a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts +++ b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts @@ -1639,3 +1639,128 @@ describe('findFailedTraceBlock', () => { expect(findFailedTraceBlock(root([span({ blockId: 'ok', status: 'success' })]))).toBeNull() }) }) + +describe('child deployment version on spans', () => { + const baseLog = { + startedAt: '2024-01-01T10:00:00.000Z', + endedAt: '2024-01-01T10:00:02.000Z', + durationMs: 2000, + executionOrder: 1, + input: {}, + } + + function spanFor(log: Record): TraceSpan { + const { traceSpans } = buildTraceSpans({ + success: true, + output: {}, + logs: [{ ...baseLog, ...log }], + } as unknown as ExecutionResult) + return traceSpans[0].children?.find((s) => s.blockId === log.blockId) ?? traceSpans[0] + } + + function agentToolSpan(name: string, result: Record, withSegments: boolean) { + const toolCall = { + name, + arguments: {}, + result, + startTime: '2024-01-01T10:00:00.500Z', + endTime: '2024-01-01T10:00:01.500Z', + duration: 1000, + } + const agent = spanFor({ + blockId: 'agent-1', + blockName: 'Agent 1', + blockType: 'agent', + success: true, + output: { + content: 'done', + toolCalls: { list: [toolCall], count: 1 }, + ...(withSegments + ? { + providerTiming: { + duration: 2000, + startTime: baseLog.startedAt, + endTime: baseLog.endedAt, + timeSegments: [ + { + type: 'tool', + name, + startTime: Date.parse(toolCall.startTime), + endTime: Date.parse(toolCall.endTime), + duration: 1000, + }, + ], + }, + } + : {}), + }, + }) + return agent.children?.find((s) => s.type === 'tool') + } + + it('records the version a workflow block ran, on success and on failure', () => { + const succeeded = spanFor({ + blockId: 'wf-1', + blockName: 'Score', + blockType: 'workflow_input', + success: true, + output: { + result: { score: 3 }, + childWorkflowId: 'child-1', + childDeploymentVersionId: 'dv-7', + }, + }) + const failed = spanFor({ + blockId: 'wf-2', + blockName: 'Score', + blockType: 'workflow', + success: false, + error: 'boom', + output: { error: 'boom', childDeploymentVersionId: 'dv-8' }, + }) + + expect(succeeded.childDeploymentVersionId).toBe('dv-7') + expect(succeeded.output).not.toHaveProperty('childDeploymentVersionId') + expect(failed.childDeploymentVersionId).toBe('dv-8') + }) + + it('does not take the version from a non-workflow block that returns the same key', () => { + const span = spanFor({ + blockId: 'fn-1', + blockName: 'Function 1', + blockType: 'function', + success: true, + output: { result: 1, childDeploymentVersionId: 'forged' }, + }) + + expect(span.childDeploymentVersionId).toBeUndefined() + expect(span.output?.childDeploymentVersionId).toBe('forged') + }) + + it.each([true, false])( + 'records the version a workflow Agent tool ran (time segments: %s)', + (withSegments) => { + const toolSpan = agentToolSpan( + 'workflow_executor', + { success: true, result: {}, childDeploymentVersionId: 'dv-9' }, + withSegments + ) + + expect(toolSpan?.childDeploymentVersionId).toBe('dv-9') + } + ) + + it.each([true, false])( + 'ignores the key on any other Agent tool (time segments: %s)', + (withSegments) => { + const toolSpan = agentToolSpan( + 'http_request', + { childDeploymentVersionId: 'forged' }, + withSegments + ) + + expect(toolSpan).toBeDefined() + expect(toolSpan?.childDeploymentVersionId).toBeUndefined() + } + ) +}) diff --git a/apps/sim/lib/logs/types.ts b/apps/sim/lib/logs/types.ts index 186a7140ced..8929615d21c 100644 --- a/apps/sim/lib/logs/types.ts +++ b/apps/sim/lib/logs/types.ts @@ -296,6 +296,12 @@ export interface TraceSpan { output?: Record childWorkflowSnapshotId?: string childWorkflowId?: string + /** + * The deployment version a child workflow call ran, on a workflow block's span or a + * `workflow_executor` Agent tool span. Absent for draft children and custom blocks. It names the + * stored version, not later variable edits or block migrations applied when it was loaded. + */ + childDeploymentVersionId?: string /** * For a custom-block span: the child run's own execution id, in the SOURCE * workspace. Only this opaque handle is persisted — the child's spans are diff --git a/packages/sim-cli/src/generated/v2-api.ts b/packages/sim-cli/src/generated/v2-api.ts index 7c64008d196..18719bda10e 100644 --- a/packages/sim-cli/src/generated/v2-api.ts +++ b/packages/sim-cli/src/generated/v2-api.ts @@ -8066,6 +8066,7 @@ type GetLogResponseRef1 = { errorType?: string errorMessage?: string blockId?: string + childDeploymentVersionId?: string input?: unknown output?: unknown tokens?: @@ -12335,6 +12336,7 @@ type ListLogsResponseRef2 = { errorType?: string errorMessage?: string blockId?: string + childDeploymentVersionId?: string input?: unknown output?: unknown tokens?: diff --git a/packages/sim-cli/src/output/trace.test.ts b/packages/sim-cli/src/output/trace.test.ts new file mode 100644 index 00000000000..b75eb0cf213 --- /dev/null +++ b/packages/sim-cli/src/output/trace.test.ts @@ -0,0 +1,27 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { printTraceSpans } from './trace' + +let logged: string[] + +beforeEach(() => { + logged = [] + vi.spyOn(console, 'log').mockImplementation((line: string) => { + logged.push(line) + }) +}) + +describe('printTraceSpans', () => { + it('shows which deployment version a child workflow call ran', () => { + printTraceSpans('text', [ + { + id: 'span-1', + name: 'Score', + type: 'workflow', + blockId: 'wf-1', + childDeploymentVersionId: 'dv-7', + }, + ]) + + expect(logged.join('\n')).toContain('child version: dv-7') + }) +}) diff --git a/packages/sim-cli/src/output/trace.ts b/packages/sim-cli/src/output/trace.ts index 0ad09463ff4..f0517da698f 100644 --- a/packages/sim-cli/src/output/trace.ts +++ b/packages/sim-cli/src/output/trace.ts @@ -77,6 +77,8 @@ function renderSpan(value: unknown, depth: number): string[] { const lines = [summary, `${detailIndent}id: ${requiredText(span, 'id')}`] const blockId = optionalText(span, 'blockId') if (blockId) lines.push(`${detailIndent}block: ${blockId}`) + const childVersion = optionalText(span, 'childDeploymentVersionId') + if (childVersion) lines.push(`${detailIndent}child version: ${childVersion}`) const startTime = optionalText(span, 'startTime') const endTime = optionalText(span, 'endTime') if (startTime || endTime) {