Skip to content

Commit e263f59

Browse files
Merge remote-tracking branch 'origin/improvement/v2-endpoints' into improvement/orchestration-migration
2 parents 8ff7967 + fbc7b17 commit e263f59

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

apps/sim/executor/handlers/workflow/workflow-tool-runner.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
import { createLogger } from '@sim/logger'
22
import { getErrorMessage } from '@sim/utils/errors'
33
import { generateId } from '@sim/utils/id'
4+
import { calculateCostSummary } from '@/lib/logs/execution/logging-factory'
5+
import type { TraceSpan } from '@/lib/logs/types'
46
import { ChildWorkflowError } from '@/executor/errors/child-workflow-error'
57
import {
68
buildCustomBlockExecutionContext,
79
type CustomBlockExecutorContext,
810
} from '@/executor/handlers/workflow/custom-block-tool-runner'
9-
import {
10-
aggregateChildCost,
11-
WorkflowBlockHandler,
12-
} from '@/executor/handlers/workflow/workflow-handler'
11+
import { WorkflowBlockHandler } from '@/executor/handlers/workflow/workflow-handler'
1312
import { classifyExecutionError } from '@/executor/utils/errors'
1413
import { parseJSON } from '@/executor/utils/json'
1514
import type { SerializedBlock } from '@/serializer/types'
1615
import type { ToolResponse } from '@/tools/types'
1716

1817
const logger = createLogger('WorkflowToolRunner')
1918

19+
/**
20+
* Hosted-key spend of a failed child run, the way the parent bills it: recurse
21+
* nested spans and de-dupe model breakdowns, then subtract the base execution
22+
* charge the parent already applies once itself. A naive top-level `cost.total`
23+
* sum undercounts when spend sits on nested children.
24+
*/
25+
function aggregateChildCost(childTraceSpans: TraceSpan[]): number {
26+
if (childTraceSpans.length === 0) return 0
27+
const summary = calculateCostSummary(childTraceSpans)
28+
return Math.max(0, summary.totalCost - summary.baseExecutionCharge)
29+
}
30+
2031
interface WorkflowToolParams {
2132
workflowId?: string
2233
inputMapping?: Record<string, unknown> | string

0 commit comments

Comments
 (0)