Skip to content

Commit fbc7b17

Browse files
fix(executor): restore child-cost aggregation dropped by the staging merge
Staging's custom-block rewrite deleted `aggregateChildCost` from workflow-handler.ts, and git merged that file cleanly — but this branch's workflow-tool-runner.ts, added for the v2 execute migration, still imports it. A silent semantic conflict: no marker, broken build. Taking staging's rewrite is correct, so the helper is defined locally in its one remaining consumer rather than resurrected in the file staging just rewrote. Same four lines over the still-exported `calculateCostSummary`, so a failed child workflow keeps billing the hosted-key spend it consumed instead of reporting $0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 528b52d commit fbc7b17

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)