-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(execution): complete async and resume jobs on marked workflow user failures #8380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,10 @@ import { | |
| createResumeAttemptTimeoutController, | ||
| PauseResumeManager, | ||
| } from '@/lib/workflows/executor/human-in-the-loop-manager' | ||
| import { | ||
| buildWorkflowJobFailureResult, | ||
| classifySettledWorkflowJobFailure, | ||
| } from '@/lib/workflows/executor/job-failure' | ||
| import { RESUME_EXECUTION_CONCURRENCY_LIMIT } from '@/background/concurrency-limits' | ||
| import { ExecutionSnapshot } from '@/executor/execution/snapshot' | ||
| import type { SerializedSnapshot } from '@/executor/types' | ||
|
|
@@ -230,6 +234,15 @@ export async function executeResumeJob(payload: ResumeExecutionPayload, signal?: | |
| workflowId, | ||
| }) | ||
| ) | ||
| // The resumed run executes under its parent's id, and the manager settles | ||
| // its post-execution work before re-throwing. | ||
| if (classifySettledWorkflowJobFailure(error, parentExecutionId) === 'workflow_failure') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This handled failure returns before the cell-context terminal writer runs. Marked workflow failures in table cells will therefore leave the cell/group stuck in its pre-resume state; write the cell terminal error state before returning this workflow-failure result. Prompt for AI agents |
||
| return { | ||
| ...buildWorkflowJobFailureResult({ error, workflowId, executionId: resumeExecutionId }), | ||
| parentExecutionId, | ||
| status: 'failed' as const, | ||
| } | ||
| } | ||
| throw error | ||
| } finally { | ||
| timeoutController?.cleanup() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { | ||
| executionPreprocessingMock, | ||
| executionPreprocessingMockFns, | ||
| LoggingSessionMock, | ||
| loggingSessionMock, | ||
| loggingSessionMockFns, | ||
| } from '@sim/testing' | ||
| import { | ||
| executionLimitsMock, | ||
| executionLimitsMockFns, | ||
| } from '@sim/testing/mocks/execution-limits.mock' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockExecuteWorkflowCore, mockWasExecutionFinalizedByCore } = vi.hoisted(() => ({ | ||
| mockExecuteWorkflowCore: vi.fn(), | ||
| mockWasExecutionFinalizedByCore: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/execution/preprocessing', () => executionPreprocessingMock) | ||
| vi.mock('@/lib/logs/execution/logging-session', () => loggingSessionMock) | ||
| vi.mock('@/lib/core/execution-limits', () => executionLimitsMock) | ||
| vi.mock('@/lib/workflows/executor/execution-core', () => ({ | ||
| executeWorkflowCore: mockExecuteWorkflowCore, | ||
| wasExecutionFinalizedByCore: mockWasExecutionFinalizedByCore, | ||
| })) | ||
| vi.mock('@/lib/workflows/executor/pause-persistence', () => ({ | ||
| handlePostExecutionPauseState: vi.fn(), | ||
| })) | ||
| vi.mock('@/lib/logs/execution/trace-spans/trace-spans', () => ({ | ||
| buildTraceSpans: vi.fn(() => ({ traceSpans: [] })), | ||
| })) | ||
| vi.mock('@/executor/execution/snapshot', () => ({ ExecutionSnapshot: vi.fn() })) | ||
| vi.mock('@/lib/uploads/utils/user-file-base64.server', () => ({ | ||
| cleanupExecutionBase64Cache: vi.fn(async () => {}), | ||
| })) | ||
|
|
||
| import * as usageReservation from '@/lib/billing/calculations/usage-reservation' | ||
| import { executeWorkflowJob, type WorkflowExecutionPayload } from '@/background/workflow-execution' | ||
| import { buildBlockExecutionError, markWorkflowUserFailure } from '@/executor/utils/errors' | ||
| import type { SerializedBlock } from '@/serializer/types' | ||
|
|
||
| const billingAttribution = { | ||
| actorUserId: 'user-1', | ||
| workspaceId: 'workspace-1', | ||
| organizationId: null, | ||
| billedAccountUserId: 'user-1', | ||
| billingEntity: { type: 'user' as const, id: 'user-1' }, | ||
| billingPeriod: { start: '2026-09-01T00:00:00.000Z', end: '2026-10-01T00:00:00.000Z' }, | ||
| payerSubscription: null, | ||
| } | ||
|
|
||
| const payload: WorkflowExecutionPayload = { | ||
| workflowId: 'workflow-1', | ||
| principal: { | ||
| version: 1, | ||
| principal: { | ||
| kind: 'system', | ||
| serviceId: 'internal', | ||
| workspaceId: 'workspace-1', | ||
| workflowId: 'workflow-1', | ||
| }, | ||
| }, | ||
| userId: 'user-1', | ||
| billingAttribution, | ||
| workspaceId: 'workspace-1', | ||
| executionId: 'execution-1', | ||
| requestId: 'request-1', | ||
| triggerType: 'api', | ||
| } | ||
|
|
||
| const planPanels = { | ||
| id: 'plan-panels', | ||
| metadata: { id: 'function', name: 'planPanels' }, | ||
| } as SerializedBlock | ||
|
|
||
| describe('executeWorkflowJob fault vs workflow failure', () => { | ||
| beforeEach(() => { | ||
| vi.spyOn(usageReservation, 'refreshExecutionSlotExpiry').mockResolvedValue(true) | ||
| vi.spyOn(usageReservation, 'releaseExecutionSlot').mockResolvedValue(undefined) | ||
| executionLimitsMockFns.mockCreateTimeoutAbortController.mockImplementation(() => ({ | ||
| signal: new AbortController().signal, | ||
| cleanup: vi.fn(), | ||
| abort: vi.fn(), | ||
| isTimedOut: () => false, | ||
| timeoutMs: 120_000, | ||
| })) | ||
| LoggingSessionMock.mockImplementation(function LoggingSession() { | ||
| return { | ||
| safeCompleteWithError: loggingSessionMockFns.mockSafeCompleteWithError, | ||
| waitForPostExecution: loggingSessionMockFns.mockWaitForPostExecution, | ||
| markAsFailed: loggingSessionMockFns.mockMarkAsFailed, | ||
| setExecutionDeadlineAt: loggingSessionMockFns.mockSetExecutionDeadlineAt, | ||
| projectDiagnosticError: loggingSessionMockFns.mockProjectDiagnosticError, | ||
| } | ||
| }) | ||
| executionPreprocessingMockFns.mockPreprocessExecution.mockResolvedValue({ | ||
| success: true, | ||
| actorUserId: 'user-1', | ||
| billingAttribution, | ||
| workflowRecord: { | ||
| id: 'workflow-1', | ||
| workspaceId: 'workspace-1', | ||
| userId: 'user-1', | ||
| variables: {}, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| it('completes the job when a workflow user failure is recorded only after core throws', async () => { | ||
| const blockError = buildBlockExecutionError({ | ||
| block: planPanels, | ||
| error: markWorkflowUserFailure( | ||
| new Error("ValueError: Doctrine has no sheet layout for kind ''") | ||
| ), | ||
| }) | ||
| let recorded = false | ||
| mockExecuteWorkflowCore.mockRejectedValue(blockError) | ||
| loggingSessionMockFns.mockWaitForPostExecution.mockImplementation(async () => { | ||
| recorded = true | ||
| }) | ||
| mockWasExecutionFinalizedByCore.mockImplementation(() => recorded) | ||
|
|
||
| const result = await executeWorkflowJob(payload) | ||
|
|
||
| expect(result).toMatchObject({ | ||
| success: false, | ||
| workflowId: 'workflow-1', | ||
| executionId: 'execution-1', | ||
| error: blockError.message, | ||
| }) | ||
| expect(loggingSessionMockFns.mockSafeCompleteWithError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('faults the job on an unmarked block failure even when core recorded it', async () => { | ||
| const internalError = buildBlockExecutionError({ | ||
| block: planPanels, | ||
| error: new Error('An internal error occurred while running this block'), | ||
| }) | ||
| mockExecuteWorkflowCore.mockRejectedValue(internalError) | ||
| mockWasExecutionFinalizedByCore.mockReturnValue(true) | ||
|
|
||
| await expect(executeWorkflowJob(payload)).rejects.toBe(internalError) | ||
| expect(loggingSessionMockFns.mockSafeCompleteWithError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('faults the job when core never recorded the failure', async () => { | ||
| const setupError = new Error('Workflow state not found') | ||
| mockExecuteWorkflowCore.mockRejectedValue(setupError) | ||
| mockWasExecutionFinalizedByCore.mockReturnValue(false) | ||
|
|
||
| await expect(executeWorkflowJob(payload)).rejects.toBe(setupError) | ||
| expect(loggingSessionMockFns.mockSafeCompleteWithError).toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions check whether mocked functions were called. The repository’s testing directive prohibits mock-call assertions; the new workflow-execution test also uses them. Please verify the resulting behavior instead. This requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!