Skip to content

Commit c07041b

Browse files
fix(table): backfill on add_workflow_group_output, don't re-run
addWorkflowGroupOutput (the one-shot single-output add path used by the copilot user_table tool) was calling triggerWorkflowGroupRun({ mode: 'all' }) after appending the output — that re-fired the workflow on every row. Trace a307ed8fd5fe2d931aa84dedab5a60f0 shows ~75 workflow-group-cell jobs enqueued in the seconds after a single add_workflow_group_output call. Replace with backfillGroupOutputsFromLogs (overwrite: false), the same flow updateWorkflowGroup uses when receiving newOutputColumns. Reads each row's saved trace spans and writes the new output's value back — no compute beyond a JSONB write per row, no double-billing the user for runs they didn't ask for. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 087f52d commit c07041b

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

apps/sim/lib/table/service.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,32 +3265,35 @@ export async function addWorkflowGroupOutput(
32653265
`[${requestId}] Added output "${columnName}" (${newColDef.type}) to workflow group "${data.groupId}" in table ${data.tableId}`
32663266
)
32673267

3268-
// Backfill: re-run the group on every dep-satisfied row (including ones
3269-
// that previously completed) so the new column actually gets populated.
3270-
// Adding an output without values defeats the point — the user wants the
3271-
// values, not just the empty header.
3272-
void (async () => {
3273-
try {
3274-
const { triggerWorkflowGroupRun } = await import('./workflow-columns')
3275-
const { triggered } = await triggerWorkflowGroupRun({
3276-
tableId: data.tableId,
3277-
groupId: data.groupId,
3278-
workspaceId: table.workspaceId,
3279-
mode: 'all',
3280-
requestId,
3281-
})
3282-
logger.info(
3283-
`[${requestId}] Backfilled ${triggered} row(s) after adding output "${columnName}"`
3284-
)
3285-
} catch (err) {
3286-
logger.error(
3287-
`[${requestId}] Failed to backfill rows after adding output "${columnName}":`,
3288-
err
3289-
)
3290-
}
3291-
})()
3268+
// Backfill from saved execution logs — same flow `updateWorkflowGroup`
3269+
// uses for added outputs. Reads each row's saved trace spans for the
3270+
// group's executionId and writes the new output's value back. Existing
3271+
// rows that have hand-edited values are left alone (overwrite: false).
3272+
// Cheap compared to re-running the workflow on every row, which is what
3273+
// an earlier version of this code did — that mistakenly fanned out N
3274+
// workflow-group-cell jobs and burned compute the user didn't ask for.
3275+
const updatedTable: TableDefinition = {
3276+
...table,
3277+
schema: updatedSchema,
3278+
metadata: updatedMetadata,
3279+
updatedAt: now,
3280+
}
3281+
try {
3282+
await backfillGroupOutputsFromLogs({
3283+
table: updatedTable,
3284+
groupId: data.groupId,
3285+
outputs: [newOutput],
3286+
overwrite: false,
3287+
requestId,
3288+
})
3289+
} catch (err) {
3290+
logger.warn(
3291+
`[${requestId}] Backfill from execution logs failed for ${data.tableId} group ${data.groupId} after adding output "${columnName}":`,
3292+
err
3293+
)
3294+
}
32923295

3293-
return { ...table, schema: updatedSchema, metadata: updatedMetadata, updatedAt: now }
3296+
return updatedTable
32943297
}
32953298

32963299
/**

0 commit comments

Comments
 (0)