diff --git a/packages/cli/src/__tests__/active-executions.test.ts b/packages/cli/src/__tests__/active-executions.test.ts index a8c7b0f18e..5432bf5c4a 100644 --- a/packages/cli/src/__tests__/active-executions.test.ts +++ b/packages/cli/src/__tests__/active-executions.test.ts @@ -108,6 +108,15 @@ describe('ActiveExecutions', () => { expect(activeExecutions.getActiveExecutions().length).toBe(0); }); + test('Should not try to resolve a post-execute promise for an inactive execution', async () => { + // @ts-expect-error Private method + const getExecutionSpy = jest.spyOn(activeExecutions, 'getExecution'); + + activeExecutions.finalizeExecution('inactive-execution-id', mockFullRunData()); + + expect(getExecutionSpy).not.toHaveBeenCalled(); + }); + test('Should resolve post execute promise on removal', async () => { const newExecution = mockExecutionData(); const executionId = await activeExecutions.add(newExecution); diff --git a/packages/cli/src/active-executions.ts b/packages/cli/src/active-executions.ts index f5835ca164..bc18eade16 100644 --- a/packages/cli/src/active-executions.ts +++ b/packages/cli/src/active-executions.ts @@ -154,6 +154,7 @@ export class ActiveExecutions { /** Resolve the post-execution promise in an execution. */ finalizeExecution(executionId: string, fullRunData?: IRun) { + if (!this.has(executionId)) return; const execution = this.getExecution(executionId); execution.postExecutePromise.resolve(fullRunData); this.logger.debug('Execution finalized', { executionId });