d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { describeError, toError } from '@sim/utils/errors'
|
|
import { isRetryableInfrastructureError } from '@/lib/core/errors/retryable-infrastructure'
|
|
import type { LoggingSession } from '@/lib/logs/execution/logging-session'
|
|
import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-manager'
|
|
import type { ExecutionResult } from '@/executor/types'
|
|
|
|
const logger = createLogger('PausePersistence')
|
|
|
|
interface HandlePostExecutionPauseStateArgs {
|
|
result: ExecutionResult
|
|
workflowId: string
|
|
executionId: string
|
|
loggingSession: LoggingSession
|
|
}
|
|
|
|
/**
|
|
* Handles pause persistence and resume queue processing after `executeWorkflowCore` returns.
|
|
*
|
|
* Every caller of `executeWorkflowCore` must call this after execution completes
|
|
* to ensure HITL pause state is persisted to the database and queued resumes are drained.
|
|
*
|
|
* - If execution is paused with a valid snapshot: persists to `paused_executions` table
|
|
* - If execution is paused without a snapshot: marks execution as failed
|
|
* - If execution is not paused: processes any queued resume entries
|
|
*/
|
|
export async function handlePostExecutionPauseState({
|
|
result,
|
|
workflowId,
|
|
executionId,
|
|
loggingSession,
|
|
}: HandlePostExecutionPauseStateArgs): Promise<void> {
|
|
if (result.status === 'paused') {
|
|
if (!result.snapshotSeed) {
|
|
logger.error('Missing snapshot seed for paused execution', { executionId })
|
|
await loggingSession.markAsFailed('Missing snapshot seed for paused execution')
|
|
} else {
|
|
try {
|
|
await PauseResumeManager.persistPauseResult({
|
|
workflowId,
|
|
executionId,
|
|
pausePoints: result.pausePoints || [],
|
|
snapshotSeed: result.snapshotSeed,
|
|
executorUserId: result.metadata?.userId,
|
|
})
|
|
} catch (pauseError) {
|
|
logger.error('Failed to persist pause result', {
|
|
executionId,
|
|
error: toError(pauseError).message,
|
|
cause: describeError(pauseError),
|
|
retryable: isRetryableInfrastructureError(pauseError),
|
|
})
|
|
await loggingSession.markAsFailed(
|
|
`Failed to persist pause state: ${toError(pauseError).message}`
|
|
)
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
await PauseResumeManager.processQueuedResumes(executionId, workflowId)
|
|
} catch (resumeError) {
|
|
logger.error('Failed to process queued resumes', {
|
|
executionId,
|
|
error: toError(resumeError).message,
|
|
cause: describeError(resumeError),
|
|
retryable: isRetryableInfrastructureError(resumeError),
|
|
})
|
|
}
|
|
}
|
|
}
|