Skip to content

Commit b4ad292

Browse files
fix(enrichment): clear stale manual outputs with unmet deps
1 parent 0b2a637 commit b4ad292

4 files changed

Lines changed: 66 additions & 7 deletions

File tree

apps/sim/lib/table/deps.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ describe('optimisticallyScheduleNewlyEligibleGroups — enrichment inputs', () =
162162
).toEqual({})
163163
})
164164

165+
it('clears a manual enrichment when a mapped input change leaves dependencies unmet', () => {
166+
const manualGroup = {
167+
...group,
168+
autoRun: false,
169+
dependencies: { columns: ['enabled'] },
170+
}
171+
const before = makeRow(
172+
{
173+
name: 'Person Name',
174+
domain: 'old.example',
175+
enabled: false,
176+
g1_out: 'person@old.example',
177+
},
178+
{ g1: { ...completedExec('wf-g1'), isManualRun: true } }
179+
)
180+
181+
expect(
182+
optimisticallyScheduleNewlyEligibleGroups([manualGroup], columns, before, {
183+
domain: 'new.example',
184+
})
185+
).toEqual({})
186+
expect(
187+
getInvalidatedManualEnrichmentOutputClears([manualGroup], before, {
188+
domain: 'new.example',
189+
})
190+
).toEqual({ g1_out: null })
191+
})
192+
165193
it('ignores legacy input mappings that point at the enrichment output', () => {
166194
const legacyGroup = {
167195
...group,

apps/sim/lib/table/deps.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,10 @@ export function getInvalidatedManualEnrichmentOutputClears(
150150
patch: Partial<RowData>
151151
): RowData {
152152
const patchedColumns = new Set(Object.keys(patch))
153-
const afterRow = {
154-
data: { ...beforeRow.data, ...patch } as RowData,
155-
} as TableRow
156153
const clears: RowData = {}
157154

158155
for (const group of groups) {
159156
if (group.type !== 'enrichment' || group.autoRun !== false) continue
160-
if (!areGroupDepsSatisfied(group, afterRow)) continue
161157
if (!getGroupInvalidationColumns(group).some((columnId) => patchedColumns.has(columnId))) {
162158
continue
163159
}
@@ -222,7 +218,9 @@ export function optimisticallyScheduleNewlyEligibleGroups(
222218
}
223219

224220
if (group.autoRun === false) {
225-
if (areGroupDepsSatisfied(group, afterRow)) clearInvalidatedTerminalExecution()
221+
if (group.type === 'enrichment' || areGroupDepsSatisfied(group, afterRow)) {
222+
clearInvalidatedTerminalExecution()
223+
}
226224
skipped++
227225
continue
228226
}

apps/sim/lib/table/rows/executions.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,37 @@ describe('deriveExecClearsForDataPatch enrichment inputs', () => {
206206
expect(result.executionsPatch).toEqual({ [MANUAL_ENRICHMENT_GROUP.id]: null })
207207
})
208208

209+
it('re-arms a completed manual enrichment when dependencies remain unmet', () => {
210+
const manualGroup: WorkflowGroup = {
211+
...MANUAL_ENRICHMENT_GROUP,
212+
dependencies: { columns: ['enabled'] },
213+
}
214+
const schema: TableSchema = {
215+
columns: [
216+
{ id: 'domain', name: 'Domain', type: 'string' },
217+
{ id: 'enabled', name: 'Enabled', type: 'boolean' },
218+
{
219+
id: 'email',
220+
name: 'Email',
221+
type: 'string',
222+
workflowGroupId: manualGroup.id,
223+
},
224+
],
225+
workflowGroups: [manualGroup],
226+
}
227+
const completed = { ...EXECUTION_STATE, status: 'completed' as const }
228+
229+
const result = deriveExecClearsForDataPatch(
230+
{ domain: 'new.example' },
231+
schema,
232+
{ [manualGroup.id]: completed },
233+
undefined,
234+
{ domain: 'new.example', enabled: false, email: '' }
235+
)
236+
237+
expect(result.executionsPatch).toEqual({ [manualGroup.id]: null })
238+
})
239+
209240
it('does not re-arm when a legacy input mapping points at the enrichment output', () => {
210241
const legacyGroup: WorkflowGroup = {
211242
...MANUAL_ENRICHMENT_GROUP,

apps/sim/lib/table/rows/executions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ export function deriveExecClearsForDataPatch(
200200
// after the patch — a checkbox was unchecked or a text dep cleared — there's
201201
// nothing to recompute. Leave the prior result alone instead of re-arming or
202202
// cancelling it; only checking a box / filling a dep drives downstream work.
203-
if (!areGroupDepsSatisfied(group, afterRow)) continue
204-
205203
const exec = existingExecutions[group.id]
204+
const hasInvalidatedManualEnrichment =
205+
group.type === 'enrichment' && group.autoRun === false && exec !== undefined
206+
if (!hasInvalidatedManualEnrichment && !areGroupDepsSatisfied(group, afterRow)) continue
207+
206208
if (exec) {
207209
const status = exec.status
208210
if (status === 'completed' || status === 'error' || status === 'cancelled') {

0 commit comments

Comments
 (0)