@shipfox/api-workflows 11.0.0 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +107 -0
- package/README.md +75 -0
- package/dist/core/agent-defaults.d.ts +2 -1
- package/dist/core/agent-defaults.d.ts.map +1 -1
- package/dist/core/agent-defaults.js.map +1 -1
- package/dist/core/checkout.d.ts +7 -21
- package/dist/core/checkout.d.ts.map +1 -1
- package/dist/core/checkout.js +122 -41
- package/dist/core/checkout.js.map +1 -1
- package/dist/core/entities/job-execution.d.ts +8 -0
- package/dist/core/entities/job-execution.d.ts.map +1 -1
- package/dist/core/entities/job-execution.js +13 -1
- package/dist/core/entities/job-execution.js.map +1 -1
- package/dist/core/entities/job-listener-event.d.ts +2 -0
- package/dist/core/entities/job-listener-event.d.ts.map +1 -1
- package/dist/core/entities/job-listener-event.js.map +1 -1
- package/dist/core/entities/step.d.ts +13 -3
- package/dist/core/entities/step.d.ts.map +1 -1
- package/dist/core/entities/step.js +6 -0
- package/dist/core/entities/step.js.map +1 -1
- package/dist/core/entities/workflow-run-attempt.d.ts +1 -0
- package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -1
- package/dist/core/entities/workflow-run-attempt.js.map +1 -1
- package/dist/core/entities/workflow-run.d.ts +17 -0
- package/dist/core/entities/workflow-run.d.ts.map +1 -1
- package/dist/core/entities/workflow-run.js.map +1 -1
- package/dist/core/errors.d.ts +9 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +10 -5
- package/dist/core/errors.js.map +1 -1
- package/dist/core/job-execution.d.ts.map +1 -1
- package/dist/core/job-execution.js +14 -8
- package/dist/core/job-execution.js.map +1 -1
- package/dist/core/job-transition/decide-job-activation.d.ts +1 -0
- package/dist/core/job-transition/decide-job-activation.d.ts.map +1 -1
- package/dist/core/job-transition/decide-job-activation.js +1 -0
- package/dist/core/job-transition/decide-job-activation.js.map +1 -1
- package/dist/core/job-transition/derive-job-success.d.ts +1 -0
- package/dist/core/job-transition/derive-job-success.d.ts.map +1 -1
- package/dist/core/job-transition/derive-job-success.js +5 -8
- package/dist/core/job-transition/derive-job-success.js.map +1 -1
- package/dist/core/listener-execution-materialization.d.ts +6 -3
- package/dist/core/listener-execution-materialization.d.ts.map +1 -1
- package/dist/core/listener-execution-materialization.js +44 -6
- package/dist/core/listener-execution-materialization.js.map +1 -1
- package/dist/core/resolve-trigger-reference.d.ts +11 -0
- package/dist/core/resolve-trigger-reference.d.ts.map +1 -0
- package/dist/core/resolve-trigger-reference.js +39 -0
- package/dist/core/resolve-trigger-reference.js.map +1 -0
- package/dist/core/run-workflow.d.ts +1 -0
- package/dist/core/run-workflow.d.ts.map +1 -1
- package/dist/core/run-workflow.js +1 -0
- package/dist/core/run-workflow.js.map +1 -1
- package/dist/core/step-config/agent.d.ts +1 -2
- package/dist/core/step-config/agent.d.ts.map +1 -1
- package/dist/core/step-config/agent.js +22 -7
- package/dist/core/step-config/agent.js.map +1 -1
- package/dist/core/step-config/assemble-run-context.d.ts +19 -8
- package/dist/core/step-config/assemble-run-context.d.ts.map +1 -1
- package/dist/core/step-config/assemble-run-context.js +51 -19
- package/dist/core/step-config/assemble-run-context.js.map +1 -1
- package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -1
- package/dist/core/step-config/complete-step-dispatch-config.js +72 -4
- package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -1
- package/dist/core/step-config/index.d.ts +1 -0
- package/dist/core/step-config/index.d.ts.map +1 -1
- package/dist/core/step-config/index.js +1 -0
- package/dist/core/step-config/index.js.map +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.d.ts +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.js +49 -8
- package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -1
- package/dist/core/step-config/materialize-workflow-model.d.ts +3 -3
- package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -1
- package/dist/core/step-config/materialize-workflow-model.js +9 -5
- package/dist/core/step-config/materialize-workflow-model.js.map +1 -1
- package/dist/core/step-config/resolve-job-execution-name.d.ts +3 -3
- package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -1
- package/dist/core/step-config/resolve-job-execution-name.js +24 -13
- package/dist/core/step-config/resolve-job-execution-name.js.map +1 -1
- package/dist/core/step-config/resolve-step-config.d.ts.map +1 -1
- package/dist/core/step-config/resolve-step-config.js +174 -9
- package/dist/core/step-config/resolve-step-config.js.map +1 -1
- package/dist/core/step-config/resolve-workflow-run-name.d.ts +19 -0
- package/dist/core/step-config/resolve-workflow-run-name.d.ts.map +1 -0
- package/dist/core/step-config/resolve-workflow-run-name.js +73 -0
- package/dist/core/step-config/resolve-workflow-run-name.js.map +1 -0
- package/dist/core/step-transition/decide-step-transition.js.map +1 -1
- package/dist/core/step-transition/evaluate-gate.d.ts +2 -1
- package/dist/core/step-transition/evaluate-gate.d.ts.map +1 -1
- package/dist/core/step-transition/evaluate-gate.js +5 -3
- package/dist/core/step-transition/evaluate-gate.js.map +1 -1
- package/dist/core/workflow-run-creation.d.ts +3 -0
- package/dist/core/workflow-run-creation.d.ts.map +1 -1
- package/dist/core/workflow-run-creation.js +22 -7
- package/dist/core/workflow-run-creation.js.map +1 -1
- package/dist/db/db.d.ts +278 -10
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +2 -0
- package/dist/db/db.js.map +1 -1
- package/dist/db/index.d.ts +3 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +2 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/job-listener-events.d.ts +2 -0
- package/dist/db/job-listener-events.d.ts.map +1 -1
- package/dist/db/job-listener-events.js +1 -0
- package/dist/db/job-listener-events.js.map +1 -1
- package/dist/db/job-listeners.d.ts +2 -0
- package/dist/db/job-listeners.d.ts.map +1 -1
- package/dist/db/job-listeners.js +81 -21
- package/dist/db/job-listeners.js.map +1 -1
- package/dist/db/schema/job-executions.d.ts +3 -3
- package/dist/db/schema/job-executions.d.ts.map +1 -1
- package/dist/db/schema/job-executions.js +8 -4
- package/dist/db/schema/job-executions.js.map +1 -1
- package/dist/db/schema/job-listener-events.d.ts +20 -0
- package/dist/db/schema/job-listener-events.d.ts.map +1 -1
- package/dist/db/schema/job-listener-events.js +2 -0
- package/dist/db/schema/job-listener-events.js.map +1 -1
- package/dist/db/schema/step-attempts.js +2 -2
- package/dist/db/schema/step-attempts.js.map +1 -1
- package/dist/db/schema/steps.d.ts +4 -2
- package/dist/db/schema/steps.d.ts.map +1 -1
- package/dist/db/schema/steps.js +1 -1
- package/dist/db/schema/steps.js.map +1 -1
- package/dist/db/schema/workflow-run-attempts.d.ts +21 -2
- package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -1
- package/dist/db/schema/workflow-run-attempts.js +2 -0
- package/dist/db/schema/workflow-run-attempts.js.map +1 -1
- package/dist/db/schema/workflow-run-counters.d.ts +43 -0
- package/dist/db/schema/workflow-run-counters.d.ts.map +1 -0
- package/dist/db/schema/workflow-run-counters.js +10 -0
- package/dist/db/schema/workflow-run-counters.js.map +1 -0
- package/dist/db/schema/workflow-runs.d.ts +54 -1
- package/dist/db/schema/workflow-runs.d.ts.map +1 -1
- package/dist/db/schema/workflow-runs.js +10 -2
- package/dist/db/schema/workflow-runs.js.map +1 -1
- package/dist/db/workflow-runs/job-executions.d.ts.map +1 -1
- package/dist/db/workflow-runs/job-executions.js +35 -14
- package/dist/db/workflow-runs/job-executions.js.map +1 -1
- package/dist/db/workflow-runs/jobs.d.ts +2 -0
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -1
- package/dist/db/workflow-runs/jobs.js +9 -5
- package/dist/db/workflow-runs/jobs.js.map +1 -1
- package/dist/db/workflow-runs/queries.d.ts +51 -0
- package/dist/db/workflow-runs/queries.d.ts.map +1 -1
- package/dist/db/workflow-runs/queries.js +82 -2
- package/dist/db/workflow-runs/queries.js.map +1 -1
- package/dist/db/workflow-runs/run-create.d.ts +1 -0
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -1
- package/dist/db/workflow-runs/run-create.js +159 -32
- package/dist/db/workflow-runs/run-create.js.map +1 -1
- package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -1
- package/dist/db/workflow-runs/run-rerun.js +13 -5
- package/dist/db/workflow-runs/run-rerun.js.map +1 -1
- package/dist/db/workflow-runs/shared.d.ts +1 -0
- package/dist/db/workflow-runs/shared.d.ts.map +1 -1
- package/dist/db/workflow-runs/shared.js +2 -1
- package/dist/db/workflow-runs/shared.js.map +1 -1
- package/dist/db/workflow-runs/steps.js +3 -3
- package/dist/db/workflow-runs/steps.js.map +1 -1
- package/dist/db/workflow-runs.d.ts +4 -3
- package/dist/db/workflow-runs.d.ts.map +1 -1
- package/dist/db/workflow-runs.js +3 -2
- package/dist/db/workflow-runs.js.map +1 -1
- package/dist/metrics/instance.d.ts +1 -0
- package/dist/metrics/instance.d.ts.map +1 -1
- package/dist/metrics/instance.js +9 -0
- package/dist/metrics/instance.js.map +1 -1
- package/dist/presentation/dto/checkout-token.d.ts +1 -0
- package/dist/presentation/dto/checkout-token.d.ts.map +1 -1
- package/dist/presentation/dto/checkout-token.js +1 -0
- package/dist/presentation/dto/checkout-token.js.map +1 -1
- package/dist/presentation/dto/index.d.ts +1 -1
- package/dist/presentation/dto/index.d.ts.map +1 -1
- package/dist/presentation/dto/index.js +1 -1
- package/dist/presentation/dto/index.js.map +1 -1
- package/dist/presentation/dto/step.d.ts.map +1 -1
- package/dist/presentation/dto/step.js +2 -2
- package/dist/presentation/dto/step.js.map +1 -1
- package/dist/presentation/dto/workflow-run.d.ts +3 -1
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -1
- package/dist/presentation/dto/workflow-run.js +34 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +31 -3
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/routes/checkout-token.d.ts +1 -1
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -1
- package/dist/presentation/routes/checkout-token.js +32 -20
- package/dist/presentation/routes/checkout-token.js.map +1 -1
- package/dist/presentation/routes/leased-step.d.ts +2 -0
- package/dist/presentation/routes/leased-step.d.ts.map +1 -1
- package/dist/presentation/routes/leased-step.js +2 -1
- package/dist/presentation/routes/leased-step.js.map +1 -1
- package/dist/presentation/routes/list-runs.d.ts.map +1 -1
- package/dist/presentation/routes/list-runs.js +9 -3
- package/dist/presentation/routes/list-runs.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -0
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/presentation/routes/report-step.d.ts.map +1 -1
- package/dist/presentation/routes/report-step.js +9 -2
- package/dist/presentation/routes/report-step.js.map +1 -1
- package/dist/presentation/subscribers/on-job-steps-settled.js +1 -1
- package/dist/presentation/subscribers/on-job-steps-settled.js.map +1 -1
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts.map +1 -1
- package/dist/presentation/subscribers/on-runner-job-claimed.js +21 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js.map +1 -1
- package/dist/temporal/activities/index.d.ts.map +1 -1
- package/dist/temporal/activities/index.js +2 -1
- package/dist/temporal/activities/index.js.map +1 -1
- package/dist/temporal/activities/orchestration-activities.d.ts +1 -0
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -1
- package/dist/temporal/activities/orchestration-activities.js.map +1 -1
- package/dist/temporal/constants.d.ts +1 -0
- package/dist/temporal/constants.d.ts.map +1 -1
- package/dist/temporal/constants.js +1 -0
- package/dist/temporal/constants.js.map +1 -1
- package/dist/temporal/index.d.ts +1 -1
- package/dist/temporal/index.d.ts.map +1 -1
- package/dist/temporal/index.js +1 -1
- package/dist/temporal/index.js.map +1 -1
- package/dist/temporal/workflows/index.bundle.js +82 -43
- package/dist/temporal/workflows/index.d.ts +1 -1
- package/dist/temporal/workflows/index.d.ts.map +1 -1
- package/dist/temporal/workflows/index.js +1 -1
- package/dist/temporal/workflows/index.js.map +1 -1
- package/dist/temporal/workflows/job-execution-orchestration.d.ts +5 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts.map +1 -1
- package/dist/temporal/workflows/job-execution-orchestration.js +77 -43
- package/dist/temporal/workflows/job-execution-orchestration.js.map +1 -1
- package/dist/temporal/workflows/test-env.d.ts +5 -1
- package/dist/temporal/workflows/test-env.d.ts.map +1 -1
- package/dist/temporal/workflows/test-env.js +32 -11
- package/dist/temporal/workflows/test-env.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0000_initial.sql +14 -2
- package/drizzle/0001_windy_sunfire.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +93 -1
- package/drizzle/meta/0001_snapshot.json +1711 -0
- package/drizzle/meta/_journal.json +2 -2
- package/package.json +19 -19
- package/src/core/agent-defaults.ts +2 -1
- package/src/core/checkout.test.ts +378 -67
- package/src/core/checkout.ts +142 -59
- package/src/core/entities/job-execution.test.ts +21 -0
- package/src/core/entities/job-execution.ts +24 -0
- package/src/core/entities/job-listener-event.ts +3 -0
- package/src/core/entities/step.ts +15 -3
- package/src/core/entities/workflow-run-attempt.ts +1 -0
- package/src/core/entities/workflow-run.ts +16 -0
- package/src/core/errors.ts +21 -7
- package/src/core/job-execution.ts +27 -4
- package/src/core/job-transition/decide-job-activation.test.ts +4 -0
- package/src/core/job-transition/decide-job-activation.ts +2 -0
- package/src/core/job-transition/derive-job-success.test.ts +12 -0
- package/src/core/job-transition/derive-job-success.ts +6 -9
- package/src/core/listener-execution-materialization.test.ts +2 -0
- package/src/core/listener-execution-materialization.ts +57 -11
- package/src/core/resolve-trigger-reference.test.ts +160 -0
- package/src/core/resolve-trigger-reference.ts +53 -0
- package/src/core/run-workflow.ts +2 -0
- package/src/core/step-config/agent.ts +29 -12
- package/src/core/step-config/assemble-run-context.test.ts +149 -6
- package/src/core/step-config/assemble-run-context.ts +87 -25
- package/src/core/step-config/complete-step-dispatch-config.test.ts +125 -2
- package/src/core/step-config/complete-step-dispatch-config.ts +83 -1
- package/src/core/step-config/index.ts +7 -0
- package/src/core/step-config/materialize-job-execution-steps.test.ts +250 -1
- package/src/core/step-config/materialize-job-execution-steps.ts +57 -10
- package/src/core/step-config/materialize-workflow-model.test.ts +212 -4
- package/src/core/step-config/materialize-workflow-model.ts +33 -28
- package/src/core/step-config/resolve-job-execution-name.test.ts +37 -15
- package/src/core/step-config/resolve-job-execution-name.ts +30 -15
- package/src/core/step-config/resolve-step-config.ts +175 -10
- package/src/core/step-config/resolve-workflow-run-name.test.ts +115 -0
- package/src/core/step-config/resolve-workflow-run-name.ts +108 -0
- package/src/core/step-transition/decide-step-transition.ts +2 -2
- package/src/core/step-transition/evaluate-gate.test.ts +8 -0
- package/src/core/step-transition/evaluate-gate.ts +8 -1
- package/src/core/workflow-run-creation.test.ts +7 -4
- package/src/core/workflow-run-creation.ts +13 -7
- package/src/db/db.ts +2 -0
- package/src/db/index.ts +6 -0
- package/src/db/job-listener-events.test.ts +19 -0
- package/src/db/job-listener-events.ts +3 -0
- package/src/db/job-listeners.test.ts +187 -5
- package/src/db/job-listeners.ts +122 -30
- package/src/db/schema/job-executions.ts +12 -5
- package/src/db/schema/job-listener-events.ts +3 -0
- package/src/db/schema/step-attempts.ts +2 -2
- package/src/db/schema/steps.ts +2 -1
- package/src/db/schema/workflow-run-attempts.ts +2 -0
- package/src/db/schema/workflow-run-counters.ts +13 -0
- package/src/db/schema/workflow-runs.ts +11 -2
- package/src/db/workflow-runs/job-executions.ts +37 -15
- package/src/db/workflow-runs/jobs.ts +17 -4
- package/src/db/workflow-runs/queries.test.ts +206 -0
- package/src/db/workflow-runs/queries.ts +146 -2
- package/src/db/workflow-runs/run-create.test.ts +606 -8
- package/src/db/workflow-runs/run-create.ts +185 -40
- package/src/db/workflow-runs/run-rerun.test.ts +61 -2
- package/src/db/workflow-runs/run-rerun.ts +15 -5
- package/src/db/workflow-runs/shared.ts +2 -0
- package/src/db/workflow-runs/steps.ts +3 -3
- package/src/db/workflow-runs.ts +7 -0
- package/src/metrics/instance.ts +14 -0
- package/src/presentation/dto/checkout-token.test.ts +19 -9
- package/src/presentation/dto/checkout-token.ts +2 -1
- package/src/presentation/dto/index.ts +1 -1
- package/src/presentation/dto/job.test.ts +9 -0
- package/src/presentation/dto/step.test.ts +12 -0
- package/src/presentation/dto/step.ts +5 -2
- package/src/presentation/dto/workflow-run.ts +44 -2
- package/src/presentation/inter-module.test.ts +165 -0
- package/src/presentation/inter-module.ts +38 -4
- package/src/presentation/routes/checkout-token.test.ts +357 -142
- package/src/presentation/routes/checkout-token.ts +56 -26
- package/src/presentation/routes/get-run.test.ts +2 -0
- package/src/presentation/routes/get-step-secrets.test.ts +7 -2
- package/src/presentation/routes/leased-step.ts +9 -1
- package/src/presentation/routes/list-runs.test.ts +57 -0
- package/src/presentation/routes/list-runs.ts +8 -3
- package/src/presentation/routes/report-step.test.ts +25 -0
- package/src/presentation/routes/report-step.ts +10 -2
- package/src/presentation/subscribers/on-job-steps-settled.ts +1 -1
- package/src/presentation/subscribers/on-runner-job-claimed.test.ts +49 -0
- package/src/presentation/subscribers/on-runner-job-claimed.ts +22 -0
- package/src/temporal/activities/index.ts +1 -0
- package/src/temporal/activities/orchestration-activities.ts +1 -0
- package/src/temporal/constants.ts +1 -0
- package/src/temporal/index.ts +1 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/job-execution-orchestration.test.ts +142 -6
- package/src/temporal/workflows/job-execution-orchestration.ts +99 -50
- package/src/temporal/workflows/run-orchestration.test.ts +1 -1
- package/src/temporal/workflows/test-env.ts +50 -13
- package/test/factories/project.ts +2 -0
- package/test/factories/workflow-model.ts +80 -26
- package/test/factories/workflow-run.ts +4 -1
- package/test/fixtures/agent-inter-module.ts +2 -1
- package/test/fixtures/job-with-steps.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/drizzle/0001_agent_tool_materialization.sql +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db/workflow-runs/run-create.ts"],"sourcesContent":["import {createWorkflowModelSnapshot, type WorkflowModel} from '@shipfox/api-definitions-dto';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';\nimport {analyzeContextKeyAccess, type ResolvedFieldSegment} from '@shipfox/expression';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {eq} from 'drizzle-orm';\nimport type {AgentDefaultsResolver} from '#core/agent-defaults.js';\nimport {\n createAgentToolMaterializationSnapshot,\n loadAgentToolMaterializationContext,\n} from '#core/agent-tools.js';\nimport type {\n TriggerPayload,\n WorkflowRun,\n WorkflowSourceSnapshot,\n} from '#core/entities/workflow-run.js';\nimport {InterpolationUnresolvableError} from '#core/errors.js';\nimport type {MaterializedWorkflowJob} from '#core/step-config/materialize-workflow-model.js';\nimport type {WorkflowStepTemplateDiagnostic} from '#core/step-config/resolve-step-config.js';\nimport {\n deriveInitialJobExecutionPlan,\n materializeWorkflowRunJobs,\n} from '#core/workflow-run-creation.js';\nimport {recordWorkflowRunCreated} from '#metrics/instance.js';\nimport {db} from '../db.js';\nimport {workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';\nimport {type MaterializedRunGraphJob, persistMaterializedRunGraph} from './run-graph.js';\n\nexport type WorkflowModelJob = WorkflowModel['jobs'][number];\n\nexport interface ReferencedVariable {\n readonly key: string;\n readonly field: InterpolationUnresolvableError['field'];\n readonly source: string;\n readonly envKey?: string | undefined;\n}\n\nexport interface CreateWorkflowRunParams {\n workspaceId: string;\n projectId: string;\n definitionId: string;\n name?: string | undefined;\n model: WorkflowModel;\n triggerPayload: TriggerPayload;\n inputs?: Record<string, unknown> | undefined;\n sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;\n triggerIdempotencyKey?: string | undefined;\n resolveAgentDefaults?: AgentDefaultsResolver | undefined;\n secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;\n integrations?: IntegrationsModuleClient | undefined;\n projects?: ProjectsModuleClient | undefined;\n}\n\nexport async function createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun> {\n const agentToolContext =\n params.integrations === undefined\n ? undefined\n : await loadAgentToolMaterializationContext({\n model: params.model,\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n integrations: params.integrations,\n projects: params.projects,\n });\n const agentToolMaterialization = createAgentToolMaterializationSnapshot({\n model: params.model,\n context: agentToolContext,\n });\n const result = await db().transaction(async (tx) => {\n const insertResult = await tx\n .insert(workflowRuns)\n .values({\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n definitionId: params.definitionId,\n name: params.name ?? params.model.name,\n status: 'pending',\n currentAttempt: 1,\n triggerProvider: params.triggerPayload.provider ?? null,\n triggerSource: params.triggerPayload.source,\n triggerEvent: params.triggerPayload.event,\n triggerPayload: params.triggerPayload,\n inputs: params.inputs ?? null,\n sourceSnapshot: params.sourceSnapshot ?? null,\n triggerIdempotencyKey: params.triggerIdempotencyKey ?? null,\n })\n .onConflictDoNothing({target: workflowRuns.triggerIdempotencyKey})\n .returning();\n\n const runRow = insertResult[0];\n if (!runRow) {\n // Conflict path: skip jobs/steps/outbox so the first insert keeps ownership of side effects.\n if (!params.triggerIdempotencyKey) {\n throw new Error('Insert returned no rows');\n }\n const existing = await tx\n .select()\n .from(workflowRuns)\n .where(eq(workflowRuns.triggerIdempotencyKey, params.triggerIdempotencyKey))\n .limit(1);\n const existingRow = existing[0];\n if (!existingRow) {\n throw new Error(\n `Idempotency conflict but existing run missing for key ${params.triggerIdempotencyKey}`,\n );\n }\n return {run: toWorkflowRun(existingRow), created: false};\n }\n\n const run = toWorkflowRun(runRow);\n const [attemptRow] = await tx\n .insert(workflowRunAttempts)\n .values({\n workflowRunId: runRow.id,\n attempt: 1,\n status: 'pending',\n model: createWorkflowModelSnapshot(params.model),\n agentToolMaterialization,\n })\n .returning();\n if (!attemptRow) throw new Error('Insert returned no rows');\n\n // Resolving one-shot templates here gives interpolation access to the inserted run id.\n // If resolution fails, the transaction rolls back the run, jobs, steps, and outbox event together.\n // Listening steps are resolved later when a job execution is created.\n const oneShotJobs = params.model.jobs.filter((job) => job.mode !== 'listening');\n const vars = await loadReferencedVariables({\n model: params.model,\n jobs: oneShotJobs,\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n definitionId: params.definitionId,\n secrets: params.secrets,\n });\n const materializedJobs = await materializeWorkflowRunJobs({\n run,\n model: params.model,\n triggerPayload: params.triggerPayload,\n inputs: params.inputs ?? null,\n vars,\n resolveAgentDefaults: params.resolveAgentDefaults,\n definitionId: params.definitionId,\n agentToolContext,\n agentToolSnapshot: agentToolMaterialization,\n });\n\n const graphJobs = materializeRunGraphJobs({\n params,\n run,\n vars,\n materializedJobs,\n });\n await persistMaterializedRunGraph(tx, {\n run,\n workflowRunAttempt: attemptRow,\n materializedJobs: graphJobs,\n });\n\n logTemplateDiagnostics({\n workflowRunId: runRow.id,\n diagnostics: materializedJobs.flatMap((job) =>\n job.steps.flatMap((step) =>\n (step.diagnostics ?? []).map((diagnostic) => ({\n jobKey: job.key,\n stepName: step.name,\n ...diagnostic,\n })),\n ),\n ),\n });\n\n return {run, created: true};\n });\n\n if (result.created)\n recordWorkflowRunCreated(result.run.triggerPayload.provider ?? result.run.triggerSource);\n\n return result.run;\n}\n\nexport async function loadReferencedVariables(params: {\n readonly model: WorkflowModel;\n readonly jobs?: readonly WorkflowModelJob[] | undefined;\n readonly workspaceId: string;\n readonly projectId: string;\n readonly definitionId: string;\n readonly secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;\n}): Promise<Record<string, string> | undefined> {\n const references = referencedVariables(params.model, params.jobs ?? params.model.jobs);\n const keys = [...new Set(references.map((reference) => reference.key))].sort();\n if (keys.length === 0) return undefined;\n\n if (!params.secrets) throw new Error('Secrets client is not configured.');\n const {values: vars} = await params.secrets.getVariablesByNamespace({\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n namespace: '',\n });\n const missingKey = keys.find((key) => !(key in vars));\n if (missingKey !== undefined) {\n const reference = references.find((candidate) => candidate.key === missingKey);\n throw new InterpolationUnresolvableError(params.definitionId, {\n field: reference?.field ?? 'env',\n source: reference?.source ?? `vars.${missingKey}`,\n ...(reference?.envKey === undefined ? {} : {envKey: reference.envKey}),\n });\n }\n\n return vars;\n}\n\nfunction materializeRunGraphJobs(params: {\n readonly params: CreateWorkflowRunParams;\n readonly run: WorkflowRun;\n readonly vars: Record<string, string> | undefined;\n readonly materializedJobs: readonly MaterializedWorkflowJob[];\n}): readonly MaterializedRunGraphJob[] {\n return params.materializedJobs.map((job, jobIndex) => ({\n job: {\n key: job.key,\n mode: job.mode,\n name: workflowTemplateSource(job.name),\n status: 'pending' as const,\n checkoutPersistCredentials: job.checkout.persistCredentials,\n checkoutPermissionsContents: job.checkout.permissions.contents,\n success: job.success ?? null,\n executionTimeoutMs: job.executionTimeoutMs ?? null,\n listeningTimeoutMs: job.listening?.timeoutMs ?? null,\n maxExecutions: job.listening?.maxExecutions ?? null,\n onResolve: job.listening?.onResolve ?? null,\n batchDebounceMs: job.listening?.batch?.debounceMs ?? null,\n batchMaxSize: job.listening?.batch?.maxSize ?? null,\n batchMaxWaitMs: job.listening?.batch?.maxWaitMs ?? null,\n listeningOn: job.listening?.on ? [...job.listening.on] : null,\n listeningUntil: job.listening?.until ? [...job.listening.until] : null,\n dependencies: [...job.dependencies],\n runner: job.runner.length === 0 ? null : [...job.runner],\n position: job.position,\n },\n createExecution: (jobRow) => {\n if (jobRow.mode === 'listening') return undefined;\n\n const fallbackName = `${jobRow.key} #1`;\n const modelJob = params.params.model.jobs[jobIndex];\n if (!modelJob) return undefined;\n const executionPlan = deriveInitialJobExecutionPlan({\n run: params.run,\n modelJob,\n job,\n jobId: jobRow.id,\n sequence: 1,\n fallbackName,\n triggerPayload: params.params.triggerPayload,\n inputs: params.params.inputs ?? null,\n vars: params.vars,\n });\n\n return {\n sequence: 1,\n name: executionPlan.name,\n runner: [...executionPlan.runner],\n status: 'pending' as const,\n evaluationTrace:\n executionPlan.evaluationTrace?.length === 0 ? null : executionPlan.evaluationTrace,\n };\n },\n createSteps: () =>\n job.steps.map((step) => ({\n key: step.key,\n name: step.name,\n sourceLocation: step.sourceLocation,\n status: step.status,\n type: step.type,\n config: step.config,\n condition: step.condition ?? null,\n configPlan: step.configPlan ?? null,\n authoredConfig: step.authoredConfig,\n position: step.position,\n })),\n }));\n}\n\nfunction referencedVariables(\n model: WorkflowModel,\n jobs: readonly WorkflowModelJob[],\n): readonly ReferencedVariable[] {\n const references: ReferencedVariable[] = [];\n\n if (jobs.length > 0) {\n collectTemplateVariableReferences(model.templates?.env, references);\n }\n\n for (const job of jobs) {\n collectFieldVariableReferences(job.name, references, {field: 'job.name'});\n for (const template of job.runnerTemplates ?? []) {\n collectFieldVariableReferences(template, references, {field: 'job.runner'});\n }\n collectTemplateVariableReferences(job.outputs, references, {field: 'job.outputs'});\n collectTemplateVariableReferences(job.templates?.env, references);\n\n for (const step of job.steps) {\n collectFieldVariableReferences(step.templates?.name, references, {field: 'step.name'});\n if (step.kind === 'run') {\n collectFieldVariableReferences(step.templates?.command, references, {field: 'run'});\n collectTemplateVariableReferences(step.templates?.env, references);\n } else {\n collectFieldVariableReferences(step.templates?.prompt, references, {field: 'agent.prompt'});\n collectFieldVariableReferences(step.templates?.model, references, {field: 'agent.model'});\n collectFieldVariableReferences(step.templates?.provider, references, {\n field: 'agent.provider',\n });\n }\n }\n }\n\n return references;\n}\n\nfunction collectTemplateVariableReferences(\n templates: Readonly<Record<string, readonly ResolvedFieldSegment[]>> | undefined,\n references: ReferencedVariable[],\n source?: {\n readonly field: InterpolationUnresolvableError['field'];\n },\n): void {\n for (const [envKey, template] of Object.entries(templates ?? {})) {\n collectFieldVariableReferences(\n template,\n references,\n source === undefined ? {field: 'env', envKey} : source,\n );\n }\n}\n\nfunction collectFieldVariableReferences(\n template: readonly ResolvedFieldSegment[] | undefined,\n references: ReferencedVariable[],\n source: {\n readonly field: InterpolationUnresolvableError['field'];\n readonly envKey?: string | undefined;\n },\n): void {\n for (const segment of template ?? []) {\n if (segment.kind === 'literal') continue;\n const keyAccess = analyzeContextKeyAccess(segment.expression);\n for (const reference of keyAccess.references) {\n if (reference.root !== 'vars') continue;\n references.push({\n key: reference.key,\n field: source.field,\n source: segment.expression.source,\n envKey: source.envKey,\n });\n }\n }\n}\n\nfunction workflowTemplateSource(template: MaterializedWorkflowJob['name']): string | null {\n if (template === undefined) return null;\n\n return template\n .map((segment) =>\n segment.kind === 'literal' ? segment.value : `$${'{{'} ${segment.expression.source} ${'}}'}`,\n )\n .join('');\n}\n\nfunction logTemplateDiagnostics(params: {\n readonly workflowRunId: string;\n readonly diagnostics: readonly (WorkflowStepTemplateDiagnostic & {\n readonly jobKey: string;\n readonly stepName: string;\n })[];\n}): void {\n if (params.diagnostics.length === 0) return;\n\n logger().warn(\n {workflowRunId: params.workflowRunId, diagnostics: params.diagnostics},\n 'Workflow interpolation resolved with diagnostics',\n );\n}\n"],"names":["createWorkflowModelSnapshot","analyzeContextKeyAccess","logger","eq","createAgentToolMaterializationSnapshot","loadAgentToolMaterializationContext","InterpolationUnresolvableError","deriveInitialJobExecutionPlan","materializeWorkflowRunJobs","recordWorkflowRunCreated","db","workflowRunAttempts","toWorkflowRun","workflowRuns","persistMaterializedRunGraph","createWorkflowRun","params","agentToolContext","integrations","undefined","model","workspaceId","projectId","projects","agentToolMaterialization","context","result","transaction","tx","insertResult","insert","values","definitionId","name","status","currentAttempt","triggerProvider","triggerPayload","provider","triggerSource","source","triggerEvent","event","inputs","sourceSnapshot","triggerIdempotencyKey","onConflictDoNothing","target","returning","runRow","Error","existing","select","from","where","limit","existingRow","run","created","attemptRow","workflowRunId","id","attempt","oneShotJobs","jobs","filter","job","mode","vars","loadReferencedVariables","secrets","materializedJobs","resolveAgentDefaults","agentToolSnapshot","graphJobs","materializeRunGraphJobs","workflowRunAttempt","logTemplateDiagnostics","diagnostics","flatMap","steps","step","map","diagnostic","jobKey","key","stepName","references","referencedVariables","keys","Set","reference","sort","length","getVariablesByNamespace","namespace","missingKey","find","candidate","field","envKey","jobIndex","workflowTemplateSource","checkoutPersistCredentials","checkout","persistCredentials","checkoutPermissionsContents","permissions","contents","success","executionTimeoutMs","listeningTimeoutMs","listening","timeoutMs","maxExecutions","onResolve","batchDebounceMs","batch","debounceMs","batchMaxSize","maxSize","batchMaxWaitMs","maxWaitMs","listeningOn","on","listeningUntil","until","dependencies","runner","position","createExecution","jobRow","fallbackName","modelJob","executionPlan","jobId","sequence","evaluationTrace","createSteps","sourceLocation","type","config","condition","configPlan","authoredConfig","collectTemplateVariableReferences","templates","env","collectFieldVariableReferences","template","runnerTemplates","outputs","kind","command","prompt","Object","entries","segment","keyAccess","expression","root","push","value","join","warn"],"mappings":"AAAA,SAAQA,2BAA2B,QAA2B,+BAA+B;AAI7F,SAAQC,uBAAuB,QAAkC,sBAAsB;AACvF,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,EAAE,QAAO,cAAc;AAE/B,SACEC,sCAAsC,EACtCC,mCAAmC,QAC9B,uBAAuB;AAM9B,SAAQC,8BAA8B,QAAO,kBAAkB;AAG/D,SACEC,6BAA6B,EAC7BC,0BAA0B,QACrB,iCAAiC;AACxC,SAAQC,wBAAwB,QAAO,uBAAuB;AAC9D,SAAQC,EAAE,QAAO,WAAW;AAC5B,SAAQC,mBAAmB,QAAO,qCAAqC;AACvE,SAAQC,aAAa,EAAEC,YAAY,QAAO,6BAA6B;AACvE,SAAsCC,2BAA2B,QAAO,iBAAiB;AA2BzF,OAAO,eAAeC,kBAAkBC,MAA+B;IACrE,MAAMC,mBACJD,OAAOE,YAAY,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,CAACV,aAAa,CAAC,GAAI;QAChEE,+BACEC,UACA9D,YACA/C,WAAWrB,YAAY;YAACgF,OAAO;YAAOC;QAAM,IAAI5D;IAEpD;AACF;AAEA,SAAS4G,+BACPC,QAAqD,EACrD9D,UAAgC,EAChC/C,MAGC;IAED,KAAK,MAAMqH,WAAWR,YAAY,EAAE,CAAE;QACpC,IAAIQ,QAAQL,IAAI,KAAK,WAAW;QAChC,MAAMM,YAAY7J,wBAAwB4J,QAAQE,UAAU;QAC5D,KAAK,MAAMpE,aAAamE,UAAUvE,UAAU,CAAE;YAC5C,IAAII,UAAUqE,IAAI,KAAK,QAAQ;YAC/BzE,WAAW0E,IAAI,CAAC;gBACd5E,KAAKM,UAAUN,GAAG;gBAClBc,OAAO3D,OAAO2D,KAAK;gBACnB3D,QAAQqH,QAAQE,UAAU,CAACvH,MAAM;gBACjC4D,QAAQ5D,OAAO4D,MAAM;YACvB;QACF;IACF;AACF;AAEA,SAASE,uBAAuB+C,QAAyC;IACvE,IAAIA,aAAalI,WAAW,OAAO;IAEnC,OAAOkI,SACJnE,GAAG,CAAC,CAAC2E,UACJA,QAAQL,IAAI,KAAK,YAAYK,QAAQK,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAEL,QAAQE,UAAU,CAACvH,MAAM,CAAC,CAAC,EAAE,MAAM,EAE7F2H,IAAI,CAAC;AACV;AAEA,SAAStF,uBAAuB7D,MAM/B;IACC,IAAIA,OAAO8D,WAAW,CAACe,MAAM,KAAK,GAAG;IAErC3F,SAASkK,IAAI,CACX;QAACxG,eAAe5C,OAAO4C,aAAa;QAAEkB,aAAa9D,OAAO8D,WAAW;IAAA,GACrE;AAEJ"}
|
|
1
|
+
{"version":3,"sources":["../../../src/db/workflow-runs/run-create.ts"],"sourcesContent":["import {\n createWorkflowModelSnapshot,\n WORKFLOW_MODEL_CHECKOUT_TARGET_FIELDS,\n type WorkflowModel,\n} from '@shipfox/api-definitions-dto';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';\nimport {\n analyzeContextKeyAccess,\n type ResolvedFieldSegment,\n type WorkflowExpression,\n} from '@shipfox/expression';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {eq, sql} from 'drizzle-orm';\nimport type {AgentDefaultsResolver} from '#core/agent-defaults.js';\nimport {\n createAgentToolMaterializationSnapshot,\n loadAgentToolMaterializationContext,\n} from '#core/agent-tools.js';\nimport type {\n TriggerPayload,\n WorkflowRun,\n WorkflowSourceSnapshot,\n} from '#core/entities/workflow-run.js';\nimport {InterpolationUnresolvableError} from '#core/errors.js';\nimport {resolveWorkflowRunTriggerReference} from '#core/resolve-trigger-reference.js';\nimport {assembleCreationContext} from '#core/step-config/assemble-run-context.js';\nimport type {MaterializedWorkflowJob} from '#core/step-config/materialize-workflow-model.js';\nimport type {WorkflowStepTemplateDiagnostic} from '#core/step-config/resolve-step-config.js';\nimport {resolveWorkflowRunName} from '#core/step-config/resolve-workflow-run-name.js';\nimport {\n deriveInitialJobExecutionPlan,\n materializeWorkflowRunJobs,\n} from '#core/workflow-run-creation.js';\nimport {\n recordWorkflowDisplayNameResolutionDegraded,\n recordWorkflowRunCreated,\n} from '#metrics/instance.js';\nimport {db, type Tx} from '../db.js';\nimport {workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {workflowRunCounters} from '../schema/workflow-run-counters.js';\nimport {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';\nimport {type MaterializedRunGraphJob, persistMaterializedRunGraph} from './run-graph.js';\n\nexport type WorkflowModelJob = WorkflowModel['jobs'][number];\n\nexport interface ReferencedVariable {\n readonly key: string;\n readonly field: InterpolationUnresolvableError['field'];\n readonly source: string;\n readonly envKey?: string | undefined;\n}\n\nexport interface CreateWorkflowRunParams {\n workspaceId: string;\n projectId: string;\n definitionId: string;\n name?: string | undefined;\n model: WorkflowModel;\n triggerPayload: TriggerPayload;\n triggerConnectionId?: string | undefined;\n inputs?: Record<string, unknown> | undefined;\n sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;\n triggerIdempotencyKey?: string | undefined;\n resolveAgentDefaults?: AgentDefaultsResolver | undefined;\n secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;\n integrations?: IntegrationsModuleClient | undefined;\n projects?: ProjectsModuleClient | undefined;\n}\n\nexport async function createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun> {\n const triggerReference = await resolveWorkflowRunTriggerReference({\n workspaceId: params.workspaceId,\n triggerConnectionId: params.triggerConnectionId,\n triggerPayload: params.triggerPayload,\n integrations: params.integrations,\n projects: params.projects,\n });\n const staticName = params.name ?? params.model.name;\n const agentToolContext =\n params.integrations === undefined\n ? undefined\n : await loadAgentToolMaterializationContext({\n model: params.model,\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n integrations: params.integrations,\n projects: params.projects,\n });\n const agentToolMaterialization = createAgentToolMaterializationSnapshot({\n model: params.model,\n context: agentToolContext,\n });\n const result = await db().transaction(async (tx) => {\n // Serialize idempotent trigger resolution separately from per-definition number\n // allocation so a replay never consumes a number, including when two deliveries\n // race before either run is visible.\n if (params.triggerIdempotencyKey) {\n await tx.execute(\n sql`select pg_advisory_xact_lock(hashtext(${params.triggerIdempotencyKey}))`,\n );\n const existing = await tx\n .select()\n .from(workflowRuns)\n .where(eq(workflowRuns.triggerIdempotencyKey, params.triggerIdempotencyKey))\n .limit(1);\n const existingRow = existing[0];\n if (existingRow) return {run: toWorkflowRun(existingRow), created: false};\n }\n\n // Keep allocation on the existing transaction so a trigger burst cannot pin\n // every pool connection and then wait for a second connection per run.\n const number = await allocateWorkflowRunNumber(tx, params.definitionId);\n\n const insertResult = await tx\n .insert(workflowRuns)\n .values({\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n definitionId: params.definitionId,\n number,\n name: null,\n workflowName: staticName,\n status: 'pending',\n currentAttempt: 1,\n triggerProvider: params.triggerPayload.provider ?? null,\n triggerSource: params.triggerPayload.source,\n triggerEvent: params.triggerPayload.event,\n triggerPayload: params.triggerPayload,\n triggerReference,\n inputs: params.inputs ?? null,\n sourceSnapshot: params.sourceSnapshot ?? null,\n triggerIdempotencyKey: params.triggerIdempotencyKey ?? null,\n })\n .onConflictDoNothing({target: workflowRuns.triggerIdempotencyKey})\n .returning();\n\n const runRow = insertResult[0];\n if (!runRow) {\n // Conflict path: skip jobs/steps/outbox so the first insert keeps ownership of side effects.\n if (!params.triggerIdempotencyKey) {\n throw new Error('Insert returned no rows');\n }\n const existing = await tx\n .select()\n .from(workflowRuns)\n .where(eq(workflowRuns.triggerIdempotencyKey, params.triggerIdempotencyKey))\n .limit(1);\n const existingRow = existing[0];\n if (!existingRow) {\n throw new Error(\n `Idempotency conflict but existing run missing for key ${params.triggerIdempotencyKey}`,\n );\n }\n return {run: toWorkflowRun(existingRow), created: false};\n }\n\n // Resolving run-creation templates and predicates here gives them a stable variable snapshot\n // and interpolation access to the inserted run id. Run-name resolution is display-only and\n // persists only a resolved override. If resolution fails, the transaction rolls back the run,\n // jobs, steps, and outbox event together. Listening steps are resolved later when a job\n // execution is created.\n const provisionalRun = toWorkflowRun(runRow);\n const oneShotJobs = params.model.jobs.filter((job) => job.mode !== 'listening');\n const vars = await loadReferencedVariables({\n model: params.model,\n jobs: oneShotJobs,\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n definitionId: params.definitionId,\n secrets: params.secrets,\n });\n const runNameResolution = resolveWorkflowRunName({\n runName: params.model.runName,\n context: assembleCreationContext({\n run: provisionalRun,\n triggerPayload: params.triggerPayload,\n inputs: params.inputs ?? null,\n vars,\n }).values,\n });\n const [resolvedRunRow] = await tx\n .update(workflowRuns)\n .set({name: runNameResolution.value, updatedAt: new Date()})\n .where(eq(workflowRuns.id, provisionalRun.id))\n .returning();\n if (!resolvedRunRow)\n throw new Error(`Workflow run missing after name resolution: ${runRow.id}`);\n const run = toWorkflowRun(resolvedRunRow);\n const [attemptRow] = await tx\n .insert(workflowRunAttempts)\n .values({\n workflowRunId: runRow.id,\n attempt: 1,\n status: 'pending',\n model: createWorkflowModelSnapshot(params.model),\n vars,\n agentToolMaterialization,\n })\n .returning();\n if (!attemptRow) throw new Error('Insert returned no rows');\n\n const materializedJobs = await materializeWorkflowRunJobs({\n run,\n model: params.model,\n triggerPayload: params.triggerPayload,\n inputs: params.inputs ?? null,\n vars,\n resolveAgentDefaults: params.resolveAgentDefaults,\n definitionId: params.definitionId,\n agentToolContext,\n agentToolSnapshot: agentToolMaterialization,\n });\n\n const graphJobs = materializeRunGraphJobs({\n params,\n run,\n vars,\n materializedJobs,\n });\n await persistMaterializedRunGraph(tx, {\n run,\n workflowRunAttempt: attemptRow,\n materializedJobs: graphJobs,\n });\n\n logTemplateDiagnostics({\n workflowRunId: runRow.id,\n diagnostics: materializedJobs.flatMap((job) =>\n job.steps.flatMap((step) =>\n (step.diagnostics ?? []).map((diagnostic) => ({\n jobKey: job.key,\n stepName: step.name,\n ...diagnostic,\n })),\n ),\n ),\n });\n\n return {\n run,\n created: true,\n nameDegradation: runNameResolution.degradation,\n };\n });\n\n if (result.created && result.nameDegradation !== undefined) {\n recordWorkflowDisplayNameResolutionDegraded('workflow.run_name', result.nameDegradation.cause);\n logger().warn(\n {\n workflowRunId: result.run.id,\n definitionId: result.run.definitionId,\n field: 'workflow.run_name',\n cause: result.nameDegradation.cause,\n ...(result.nameDegradation.expression === undefined\n ? {}\n : {expression: result.nameDegradation.expression.slice(0, 256)}),\n },\n 'Workflow run name resolution degraded to the static workflow name',\n );\n }\n\n if (result.created) {\n recordWorkflowRunCreated(result.run.triggerPayload.provider ?? result.run.triggerSource);\n }\n\n return result.run;\n}\n\nasync function allocateWorkflowRunNumber(tx: Tx, definitionId: string): Promise<number> {\n const [counterRow] = await tx\n .insert(workflowRunCounters)\n .values({definitionId, nextNumber: 2})\n .onConflictDoUpdate({\n target: workflowRunCounters.definitionId,\n set: {nextNumber: sql`${workflowRunCounters.nextNumber} + 1`},\n })\n .returning({number: sql<number>`${workflowRunCounters.nextNumber} - 1`});\n if (!counterRow) throw new Error('Run counter allocation returned no rows');\n return counterRow.number;\n}\n\nexport async function loadReferencedVariables(params: {\n readonly model: WorkflowModel;\n readonly jobs?: readonly WorkflowModelJob[] | undefined;\n readonly workspaceId: string;\n readonly projectId: string;\n readonly definitionId: string;\n readonly secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;\n}): Promise<Record<string, string> | undefined> {\n const references = referencedVariables(params.model, params.jobs ?? params.model.jobs);\n const keys = [...new Set(references.map((reference) => reference.key))].sort();\n if (keys.length === 0) return undefined;\n\n const requiresSecrets = (reference: ReferencedVariable) =>\n reference.field !== 'job.execution_name' && reference.field !== 'workflow.run_name';\n const requiredReferences = references.filter(requiresSecrets);\n const requiredKeys = new Set(requiredReferences.map((reference) => reference.key));\n if (!params.secrets) {\n if (requiredKeys.size === 0) return undefined;\n throw new Error('Secrets client is not configured.');\n }\n const {values: vars} = await params.secrets.getVariablesByNamespace({\n workspaceId: params.workspaceId,\n projectId: params.projectId,\n namespace: '',\n });\n const missingKey = [...requiredKeys].find((key) => !(key in vars));\n if (missingKey !== undefined) {\n const reference = requiredReferences.find((candidate) => candidate.key === missingKey);\n throw new InterpolationUnresolvableError(params.definitionId, {\n field: reference?.field ?? 'env',\n source: reference?.source ?? `vars.${missingKey}`,\n ...(reference?.envKey === undefined ? {} : {envKey: reference.envKey}),\n });\n }\n\n const referencedVars: Record<string, string> = {};\n for (const key of keys) {\n const value = vars[key];\n if (value !== undefined) referencedVars[key] = value;\n }\n return referencedVars;\n}\n\nfunction materializeRunGraphJobs(params: {\n readonly params: CreateWorkflowRunParams;\n readonly run: WorkflowRun;\n readonly vars: Record<string, string> | undefined;\n readonly materializedJobs: readonly MaterializedWorkflowJob[];\n}): readonly MaterializedRunGraphJob[] {\n return params.materializedJobs.map((job, jobIndex) => ({\n job: {\n key: job.key,\n mode: job.mode,\n name: job.name ?? null,\n status: 'pending' as const,\n checkoutPersistCredentials: job.checkout.persistCredentials,\n checkoutPermissionsContents: job.checkout.permissions.contents,\n success: job.success ?? null,\n executionTimeoutMs: job.executionTimeoutMs ?? null,\n listeningTimeoutMs: job.listening?.timeoutMs ?? null,\n maxExecutions: job.listening?.maxExecutions ?? null,\n onResolve: job.listening?.onResolve ?? null,\n batchDebounceMs: job.listening?.batch?.debounceMs ?? null,\n batchMaxSize: job.listening?.batch?.maxSize ?? null,\n batchMaxWaitMs: job.listening?.batch?.maxWaitMs ?? null,\n listeningOn: job.listening?.on ? [...job.listening.on] : null,\n listeningUntil: job.listening?.until ? [...job.listening.until] : null,\n dependencies: [...job.dependencies],\n runner: job.runner.length === 0 ? null : [...job.runner],\n position: job.position,\n },\n createExecution: (jobRow) => {\n if (jobRow.mode === 'listening') return undefined;\n\n const fallbackName = jobRow.name ?? jobRow.key;\n const modelJob = params.params.model.jobs[jobIndex];\n if (!modelJob) return undefined;\n const executionPlan = deriveInitialJobExecutionPlan({\n run: params.run,\n modelJob,\n job,\n jobId: jobRow.id,\n sequence: 1,\n fallbackName,\n triggerPayload: params.params.triggerPayload,\n inputs: params.params.inputs ?? null,\n vars: params.vars,\n });\n\n return {\n sequence: 1,\n // Persist only the resolved override. The core entity supplies the\n // static job name/key when this is null.\n name: executionPlan.nameOverride,\n runner: [...executionPlan.runner],\n status: 'pending' as const,\n evaluationTrace:\n executionPlan.evaluationTrace?.length === 0 ? null : executionPlan.evaluationTrace,\n };\n },\n createSteps: () =>\n job.steps.map((step) => ({\n key: step.key,\n name: step.name,\n sourceLocation: step.sourceLocation,\n status: step.status,\n type: step.type,\n config: step.config,\n condition: step.condition ?? null,\n configPlan: step.configPlan ?? null,\n authoredConfig: step.authoredConfig,\n position: step.position,\n })),\n }));\n}\n\nfunction referencedVariables(\n model: WorkflowModel,\n jobs: readonly WorkflowModelJob[],\n): readonly ReferencedVariable[] {\n const references: ReferencedVariable[] = [];\n\n for (const job of model.jobs) {\n collectPredicateVariableReferences(job.if, references);\n collectPredicateVariableReferences(job.success, references);\n\n for (const trigger of [...(job.listening?.on ?? []), ...(job.listening?.until ?? [])]) {\n collectPredicateVariableReferences(trigger.filter, references);\n }\n\n for (const step of job.steps) {\n collectPredicateVariableReferences(step.if, references);\n collectPredicateVariableReferences(step.gate?.success, references);\n }\n }\n\n collectFieldVariableReferences(model.runName, references, {field: 'workflow.run_name'});\n\n if (jobs.length > 0) {\n collectTemplateVariableReferences(model.templates?.env, references);\n }\n\n for (const job of jobs) {\n collectFieldVariableReferences(job.executionName, references, {field: 'job.execution_name'});\n for (const template of job.runnerTemplates ?? []) {\n collectFieldVariableReferences(template, references, {field: 'job.runner'});\n }\n collectTemplateVariableReferences(job.outputs, references, {field: 'job.outputs'});\n collectTemplateVariableReferences(job.templates?.env, references);\n\n for (const step of job.steps) {\n collectFieldVariableReferences(step.templates?.name, references, {field: 'step.name'});\n collectFieldVariableReferences(step.templates?.workingDirectory, references, {\n field: 'step.working_directory',\n });\n if (step.kind === 'run') {\n collectFieldVariableReferences(step.templates?.command, references, {field: 'run'});\n collectTemplateVariableReferences(step.templates?.env, references);\n } else if (step.kind === 'agent') {\n collectFieldVariableReferences(step.templates?.prompt, references, {field: 'agent.prompt'});\n collectFieldVariableReferences(step.templates?.model, references, {field: 'agent.model'});\n collectFieldVariableReferences(step.templates?.provider, references, {\n field: 'agent.provider',\n });\n } else if (step.kind === 'checkout') {\n for (const [key, field] of WORKFLOW_MODEL_CHECKOUT_TARGET_FIELDS) {\n collectFieldVariableReferences(step.checkout.templates?.[key], references, {field});\n }\n }\n }\n }\n\n return references;\n}\n\nfunction collectPredicateVariableReferences(\n expression: WorkflowExpression | string | undefined,\n references: ReferencedVariable[],\n): void {\n if (expression === undefined) return;\n\n const keyAccess = analyzeContextKeyAccess(expression);\n for (const reference of keyAccess.references) {\n if (reference.root !== 'vars') continue;\n references.push({\n key: reference.key,\n field: 'env',\n source: typeof expression === 'string' ? expression : expression.source,\n });\n }\n}\n\nfunction collectTemplateVariableReferences(\n templates: Readonly<Record<string, readonly ResolvedFieldSegment[]>> | undefined,\n references: ReferencedVariable[],\n source?: {\n readonly field: InterpolationUnresolvableError['field'];\n },\n): void {\n for (const [envKey, template] of Object.entries(templates ?? {})) {\n collectFieldVariableReferences(\n template,\n references,\n source === undefined ? {field: 'env', envKey} : source,\n );\n }\n}\n\nfunction collectFieldVariableReferences(\n template: readonly ResolvedFieldSegment[] | undefined,\n references: ReferencedVariable[],\n source: {\n readonly field: InterpolationUnresolvableError['field'];\n readonly envKey?: string | undefined;\n },\n): void {\n for (const segment of template ?? []) {\n if (segment.kind === 'literal') continue;\n const keyAccess = analyzeContextKeyAccess(segment.expression);\n for (const reference of keyAccess.references) {\n if (reference.root !== 'vars') continue;\n references.push({\n key: reference.key,\n field: source.field,\n source: segment.expression.source,\n envKey: source.envKey,\n });\n }\n }\n}\n\nfunction logTemplateDiagnostics(params: {\n readonly workflowRunId: string;\n readonly diagnostics: readonly (WorkflowStepTemplateDiagnostic & {\n readonly jobKey: string;\n readonly stepName: string;\n })[];\n}): void {\n if (params.diagnostics.length === 0) return;\n\n logger().warn(\n {workflowRunId: params.workflowRunId, diagnostics: params.diagnostics},\n 'Workflow interpolation resolved with diagnostics',\n );\n}\n"],"names":["createWorkflowModelSnapshot","WORKFLOW_MODEL_CHECKOUT_TARGET_FIELDS","analyzeContextKeyAccess","logger","eq","sql","createAgentToolMaterializationSnapshot","loadAgentToolMaterializationContext","InterpolationUnresolvableError","resolveWorkflowRunTriggerReference","assembleCreationContext","resolveWorkflowRunName","deriveInitialJobExecutionPlan","materializeWorkflowRunJobs","recordWorkflowDisplayNameResolutionDegraded","recordWorkflowRunCreated","db","workflowRunAttempts","workflowRunCounters","toWorkflowRun","workflowRuns","persistMaterializedRunGraph","createWorkflowRun","params","triggerReference","workspaceId","triggerConnectionId","triggerPayload","integrations","projects","staticName","name","model","agentToolContext","undefined","projectId","agentToolMaterialization","context","result","transaction","tx","triggerIdempotencyKey","execute","existing","select","from","where","limit","existingRow","run","created","number","allocateWorkflowRunNumber","definitionId","insertResult","insert","values","workflowName","status","currentAttempt","triggerProvider","provider","triggerSource","source","triggerEvent","event","inputs","sourceSnapshot","onConflictDoNothing","target","returning","runRow","Error","provisionalRun","oneShotJobs","jobs","filter","job","mode","vars","loadReferencedVariables","secrets","runNameResolution","runName","resolvedRunRow","update","set","value","updatedAt","Date","id","attemptRow","workflowRunId","attempt","materializedJobs","resolveAgentDefaults","agentToolSnapshot","graphJobs","materializeRunGraphJobs","workflowRunAttempt","logTemplateDiagnostics","diagnostics","flatMap","steps","step","map","diagnostic","jobKey","key","stepName","nameDegradation","degradation","cause","warn","field","expression","slice","counterRow","nextNumber","onConflictDoUpdate","references","referencedVariables","keys","Set","reference","sort","length","requiresSecrets","requiredReferences","requiredKeys","size","getVariablesByNamespace","namespace","missingKey","find","candidate","envKey","referencedVars","jobIndex","checkoutPersistCredentials","checkout","persistCredentials","checkoutPermissionsContents","permissions","contents","success","executionTimeoutMs","listeningTimeoutMs","listening","timeoutMs","maxExecutions","onResolve","batchDebounceMs","batch","debounceMs","batchMaxSize","maxSize","batchMaxWaitMs","maxWaitMs","listeningOn","on","listeningUntil","until","dependencies","runner","position","createExecution","jobRow","fallbackName","modelJob","executionPlan","jobId","sequence","nameOverride","evaluationTrace","createSteps","sourceLocation","type","config","condition","configPlan","authoredConfig","collectPredicateVariableReferences","if","trigger","gate","collectFieldVariableReferences","collectTemplateVariableReferences","templates","env","executionName","template","runnerTemplates","outputs","workingDirectory","kind","command","prompt","keyAccess","root","push","Object","entries","segment"],"mappings":"AAAA,SACEA,2BAA2B,EAC3BC,qCAAqC,QAEhC,+BAA+B;AAItC,SACEC,uBAAuB,QAGlB,sBAAsB;AAC7B,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,EAAE,EAAEC,GAAG,QAAO,cAAc;AAEpC,SACEC,sCAAsC,EACtCC,mCAAm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,aAAa0E,UAAU9E,UAAU,CAAE;YAC5C,IAAII,UAAU2E,IAAI,KAAK,QAAQ;YAC/B/E,WAAWgF,IAAI,CAAC;gBACd5F,KAAKgB,UAAUhB,GAAG;gBAClBM,OAAOnD,OAAOmD,KAAK;gBACnBnD,QAAQ4I,QAAQxF,UAAU,CAACpD,MAAM;gBACjCyE,QAAQzE,OAAOyE,MAAM;YACvB;QACF;IACF;AACF;AAEA,SAASpC,uBAAuB7E,MAM/B;IACC,IAAIA,OAAO8E,WAAW,CAACyB,MAAM,KAAK,GAAG;IAErC3H,SAAS8G,IAAI,CACX;QAACrB,eAAerE,OAAOqE,aAAa;QAAES,aAAa9E,OAAO8E,WAAW;IAAA,GACrE;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-rerun.d.ts","sourceRoot":"","sources":["../../../src/db/workflow-runs/run-rerun.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,WAAW,EAAC,MAAM,gCAAgC,CAAC;AAavF,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"run-rerun.d.ts","sourceRoot":"","sources":["../../../src/db/workflow-runs/run-rerun.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,WAAW,EAAC,MAAM,gCAAgC,CAAC;AAavF,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,WAAW,CAAC,CAkGtB"}
|
|
@@ -40,6 +40,7 @@ export async function createRerunWorkflowRun(params) {
|
|
|
40
40
|
rerunMode: params.mode,
|
|
41
41
|
rerunByUserId: params.actorUserId,
|
|
42
42
|
model: sourceAttemptRow.model,
|
|
43
|
+
vars: sourceAttemptRow.vars,
|
|
43
44
|
agentToolMaterialization: sourceAttemptRow.agentToolMaterialization
|
|
44
45
|
}).returning();
|
|
45
46
|
if (!newAttemptRow) throw new Error('Insert returned no rows');
|
|
@@ -121,6 +122,9 @@ function materializeRerunGraphJobs(params) {
|
|
|
121
122
|
}
|
|
122
123
|
return params.sourceJobs.map((sourceJob)=>{
|
|
123
124
|
const carriedOver = params.mode === 'failed' && sourceJob.status === 'succeeded';
|
|
125
|
+
const modelJob = sourceModelJobByKey.get(sourceJob.key);
|
|
126
|
+
const modelCheckout = modelJob?.checkout;
|
|
127
|
+
const resolvedModelCheckout = modelCheckout === false ? undefined : modelCheckout;
|
|
124
128
|
return {
|
|
125
129
|
job: {
|
|
126
130
|
key: sourceJob.key,
|
|
@@ -129,8 +133,8 @@ function materializeRerunGraphJobs(params) {
|
|
|
129
133
|
status: carriedOver ? 'succeeded' : 'pending',
|
|
130
134
|
statusReason: null,
|
|
131
135
|
carriedOver,
|
|
132
|
-
checkoutPersistCredentials: sourceJob.checkoutPersistCredentials,
|
|
133
|
-
checkoutPermissionsContents: sourceJob.checkoutPermissionsContents,
|
|
136
|
+
checkoutPersistCredentials: resolvedModelCheckout?.persistCredentials ?? sourceJob.checkoutPersistCredentials,
|
|
137
|
+
checkoutPermissionsContents: resolvedModelCheckout?.permissions?.contents ?? sourceJob.checkoutPermissionsContents,
|
|
134
138
|
success: sourceJob.success,
|
|
135
139
|
executionTimeoutMs: sourceJob.executionTimeoutMs,
|
|
136
140
|
listeningTimeoutMs: sourceJob.listeningTimeoutMs,
|
|
@@ -161,19 +165,23 @@ function materializeRerunGraphJobs(params) {
|
|
|
161
165
|
createExecution: (job)=>{
|
|
162
166
|
if (job.mode === 'listening') return undefined;
|
|
163
167
|
const sourceExecution = params.sourceJobExecutionByJobId.get(sourceJob.id);
|
|
164
|
-
const
|
|
165
|
-
const executionName =
|
|
168
|
+
const nameOverride = sourceExecution?.name ?? null;
|
|
169
|
+
const executionName = nameOverride ?? job.name ?? job.key;
|
|
166
170
|
const runner = carriedOver || modelJob === undefined ? sourceExecution?.runner ?? job.runner ?? null : deriveJobExecutionRunner({
|
|
167
171
|
run: params.sourceRun,
|
|
168
172
|
modelJob,
|
|
169
173
|
jobId: job.id,
|
|
170
174
|
sequence: 1,
|
|
175
|
+
nameOverride,
|
|
171
176
|
executionName,
|
|
177
|
+
jobName: job.name,
|
|
172
178
|
status: 'pending'
|
|
173
179
|
});
|
|
174
180
|
return {
|
|
175
181
|
sequence: 1,
|
|
176
|
-
|
|
182
|
+
// Reruns preserve the authored/resolved override, never the
|
|
183
|
+
// effective fallback exposed by the core entity.
|
|
184
|
+
name: nameOverride,
|
|
177
185
|
runner: runner ? [
|
|
178
186
|
...runner
|
|
179
187
|
] : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db/workflow-runs/run-rerun.ts"],"sourcesContent":["import {readPersistedWorkflowModel} from '@shipfox/api-definitions-dto';\nimport {and, asc, eq, inArray, sql} from 'drizzle-orm';\nimport {isWorkflowRunTerminal, type WorkflowRun} from '#core/entities/workflow-run.js';\nimport {NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError} from '#core/errors.js';\nimport {deriveJobExecutionRunner} from '#core/workflow-run-creation.js';\nimport {recordWorkflowRunCreated} from '#metrics/instance.js';\nimport {db, type Tx} from '../db.js';\nimport {type JobExecutionDb, jobExecutions} from '../schema/job-executions.js';\nimport {type JobDb, jobs} from '../schema/jobs.js';\nimport {type StepDb, steps} from '../schema/steps.js';\nimport {type WorkflowRunAttemptDb, workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';\nimport {type MaterializedRunGraphJob, persistMaterializedRunGraph} from './run-graph.js';\nimport {lockWorkflowRun} from './shared.js';\n\nexport interface CreateRerunWorkflowRunParams {\n workflowRunId: string;\n mode: 'all' | 'failed';\n actorUserId: string;\n}\n\nexport async function createRerunWorkflowRun(\n params: CreateRerunWorkflowRunParams,\n): Promise<WorkflowRun> {\n const result = await db().transaction(async (tx) => {\n const workflowRunId = params.workflowRunId;\n await tx.execute(sql`select pg_advisory_xact_lock(hashtext(${workflowRunId}))`);\n\n const sourceRow = await lockWorkflowRun(workflowRunId, tx);\n if (!sourceRow) throw new SourceRunNotFoundError(workflowRunId);\n\n const [sourceAttemptRow] = await tx\n .select()\n .from(workflowRunAttempts)\n .where(\n and(\n eq(workflowRunAttempts.workflowRunId, sourceRow.id),\n eq(workflowRunAttempts.attempt, sourceRow.currentAttempt),\n ),\n )\n .limit(1)\n .for('update');\n if (!sourceAttemptRow) {\n throw new Error(\n `Current attempt ${sourceRow.currentAttempt} missing for run ${sourceRow.id}`,\n );\n }\n if (!isWorkflowRunTerminal(sourceAttemptRow.status)) {\n throw new RunNotTerminalError(sourceRow.id);\n }\n\n const sourceJobs = await tx\n .select()\n .from(jobs)\n .where(eq(jobs.workflowRunAttemptId, sourceAttemptRow.id))\n .orderBy(asc(jobs.position), asc(jobs.id));\n\n if (\n params.mode === 'failed' &&\n !sourceJobs.some((job) => job.status === 'failed' || job.status === 'cancelled')\n ) {\n throw new NoFailedJobsError(sourceRow.id);\n }\n\n const [attemptRow] = await tx\n .select({value: sql<number>`coalesce(max(${workflowRunAttempts.attempt}), 1)`})\n .from(workflowRunAttempts)\n .where(eq(workflowRunAttempts.workflowRunId, sourceRow.id));\n const attempt = Number(attemptRow?.value ?? 1) + 1;\n\n const [newAttemptRow] = await tx\n .insert(workflowRunAttempts)\n .values({\n workflowRunId: sourceRow.id,\n attempt,\n status: 'pending',\n rerunMode: params.mode,\n rerunByUserId: params.actorUserId,\n model: sourceAttemptRow.model,\n agentToolMaterialization: sourceAttemptRow.agentToolMaterialization,\n })\n .returning();\n if (!newAttemptRow) throw new Error('Insert returned no rows');\n\n const sourceGraph = await loadRerunSourceGraph(tx, sourceJobs);\n\n const sourceRun = toWorkflowRun(sourceRow);\n const graphJobs = materializeRerunGraphJobs({\n mode: params.mode,\n sourceRun,\n sourceAttempt: sourceAttemptRow,\n sourceJobs,\n ...sourceGraph,\n });\n await persistMaterializedRunGraph(tx, {\n run: sourceRun,\n workflowRunAttempt: newAttemptRow,\n materializedJobs: graphJobs,\n });\n\n const [newRunRow] = await tx\n .update(workflowRuns)\n .set({\n currentAttempt: attempt,\n status: 'pending',\n version: sql`${workflowRuns.version} + 1`,\n updatedAt: new Date(),\n startedAt: null,\n finishedAt: null,\n })\n .where(eq(workflowRuns.id, sourceRow.id))\n .returning();\n if (!newRunRow) throw new Error(`Workflow run missing after rerun: ${sourceRow.id}`);\n\n return toWorkflowRun(newRunRow);\n });\n\n recordWorkflowRunCreated(result.triggerPayload.provider ?? result.triggerSource);\n\n return result;\n}\n\nasync function loadRerunSourceGraph(\n tx: Tx,\n sourceJobs: readonly JobDb[],\n): Promise<{\n readonly sourceJobExecutionByJobId: ReadonlyMap<string, JobExecutionDb>;\n readonly sourceJobByJobExecutionId: ReadonlyMap<string, JobDb>;\n readonly sourceSteps: readonly StepDb[];\n}> {\n const sourceJobIds = sourceJobs.map((job) => job.id);\n const sourceJobExecutionRows =\n sourceJobIds.length === 0\n ? []\n : await tx\n .select()\n .from(jobExecutions)\n .where(inArray(jobExecutions.jobId, sourceJobIds))\n .orderBy(asc(jobExecutions.jobId), asc(jobExecutions.sequence), asc(jobExecutions.id));\n const sourceJobExecutionByJobId = new Map<string, JobExecutionDb>();\n for (const jobExecution of sourceJobExecutionRows) {\n if (!sourceJobExecutionByJobId.has(jobExecution.jobId)) {\n sourceJobExecutionByJobId.set(jobExecution.jobId, jobExecution);\n }\n }\n\n const sourceJobExecutionIds = [...sourceJobExecutionByJobId.values()].map(\n (jobExecution) => jobExecution.id,\n );\n const sourceSteps =\n sourceJobExecutionIds.length === 0\n ? []\n : await tx\n .select()\n .from(steps)\n .where(inArray(steps.jobExecutionId, sourceJobExecutionIds))\n .orderBy(asc(steps.jobExecutionId), asc(steps.position), asc(steps.id));\n\n const sourceJobById = new Map(sourceJobs.map((job) => [job.id, job]));\n const sourceJobByJobExecutionId = new Map(\n [...sourceJobExecutionByJobId.entries()].flatMap(([jobId, jobExecution]) => {\n const job = sourceJobById.get(jobId);\n return job ? [[jobExecution.id, job] as const] : [];\n }),\n );\n\n return {sourceJobExecutionByJobId, sourceJobByJobExecutionId, sourceSteps};\n}\n\nfunction materializeRerunGraphJobs(params: {\n readonly mode: CreateRerunWorkflowRunParams['mode'];\n readonly sourceRun: WorkflowRun;\n readonly sourceAttempt: WorkflowRunAttemptDb;\n readonly sourceJobs: readonly JobDb[];\n readonly sourceJobExecutionByJobId: ReadonlyMap<string, JobExecutionDb>;\n readonly sourceJobByJobExecutionId: ReadonlyMap<string, JobDb>;\n readonly sourceSteps: readonly StepDb[];\n}): readonly MaterializedRunGraphJob[] {\n const sourceModel =\n params.sourceAttempt.model === null\n ? null\n : readPersistedWorkflowModel(params.sourceAttempt.model);\n const sourceModelJobByKey = new Map((sourceModel?.jobs ?? []).map((job) => [job.key, job]));\n const sourceStepsByJobId = new Map<string, StepDb[]>();\n for (const step of params.sourceSteps) {\n const sourceJob = params.sourceJobByJobExecutionId.get(step.jobExecutionId);\n if (!sourceJob) continue;\n const sourceJobSteps = sourceStepsByJobId.get(sourceJob.id) ?? [];\n sourceJobSteps.push(step);\n sourceStepsByJobId.set(sourceJob.id, sourceJobSteps);\n }\n\n return params.sourceJobs.map((sourceJob) => {\n const carriedOver = params.mode === 'failed' && sourceJob.status === 'succeeded';\n\n return {\n job: {\n key: sourceJob.key,\n name: sourceJob.name,\n mode: sourceJob.mode,\n status: carriedOver ? ('succeeded' as const) : ('pending' as const),\n statusReason: null,\n carriedOver,\n checkoutPersistCredentials: sourceJob.checkoutPersistCredentials,\n checkoutPermissionsContents: sourceJob.checkoutPermissionsContents,\n success: sourceJob.success,\n executionTimeoutMs: sourceJob.executionTimeoutMs,\n listeningTimeoutMs: sourceJob.listeningTimeoutMs,\n maxExecutions: sourceJob.maxExecutions,\n onResolve: sourceJob.onResolve,\n batchDebounceMs: sourceJob.batchDebounceMs,\n batchMaxSize: sourceJob.batchMaxSize,\n batchMaxWaitMs: sourceJob.batchMaxWaitMs,\n listenerStatus: 'inactive' as const,\n resolutionReason: null,\n listeningOn: sourceJob.listeningOn ? [...sourceJob.listeningOn] : null,\n listeningUntil: sourceJob.listeningUntil ? [...sourceJob.listeningUntil] : null,\n outputs: carriedOver && sourceJob.outputs ? {...sourceJob.outputs} : null,\n dependencies: [...sourceJob.dependencies],\n runner: sourceJob.runner ? [...sourceJob.runner] : null,\n position: sourceJob.position,\n },\n createExecution: (job) => {\n if (job.mode === 'listening') return undefined;\n\n const sourceExecution = params.sourceJobExecutionByJobId.get(sourceJob.id);\n const modelJob = sourceModelJobByKey.get(job.key);\n const executionName = sourceExecution?.name ?? `${job.key} #1`;\n const runner =\n carriedOver || modelJob === undefined\n ? (sourceExecution?.runner ?? job.runner ?? null)\n : deriveJobExecutionRunner({\n run: params.sourceRun,\n modelJob,\n jobId: job.id,\n sequence: 1,\n executionName,\n status: 'pending',\n });\n\n return {\n sequence: 1,\n name: executionName,\n runner: runner ? [...runner] : null,\n status: carriedOver ? ('succeeded' as const) : ('pending' as const),\n statusReason: null,\n outputs: carriedOver && sourceExecution?.outputs ? {...sourceExecution.outputs} : null,\n ...(carriedOver ? {finishedAt: sql`now()`} : {}),\n };\n },\n createSteps: () =>\n (sourceStepsByJobId.get(sourceJob.id) ?? []).map((step) => ({\n key: step.key,\n name: step.name,\n sourceLocation: step.sourceLocation,\n status: carriedOver ? step.status : ('pending' as const),\n statusReason: carriedOver ? step.statusReason : null,\n type: step.type,\n config: step.config,\n condition: step.condition ?? null,\n configPlan: step.configPlan,\n authoredConfig: step.authoredConfig,\n error: null,\n position: step.position,\n currentAttempt: 1,\n })),\n };\n });\n}\n"],"names":["readPersistedWorkflowModel","and","asc","eq","inArray","sql","isWorkflowRunTerminal","NoFailedJobsError","RunNotTerminalError","SourceRunNotFoundError","deriveJobExecutionRunner","recordWorkflowRunCreated","db","jobExecutions","jobs","steps","workflowRunAttempts","toWorkflowRun","workflowRuns","persistMaterializedRunGraph","lockWorkflowRun","createRerunWorkflowRun","params","result","transaction","tx","workflowRunId","execute","sourceRow","sourceAttemptRow","select","from","where","id","attempt","currentAttempt","limit","for","Error","status","sourceJobs","workflowRunAttemptId","orderBy","position","mode","some","job","attemptRow","value","Number","newAttemptRow","insert","values","rerunMode","rerunByUserId","actorUserId","model","agentToolMaterialization","returning","sourceGraph","loadRerunSourceGraph","sourceRun","graphJobs","materializeRerunGraphJobs","sourceAttempt","run","workflowRunAttempt","materializedJobs","newRunRow","update","set","version","updatedAt","Date","startedAt","finishedAt","triggerPayload","provider","triggerSource","sourceJobIds","map","sourceJobExecutionRows","length","jobId","sequence","sourceJobExecutionByJobId","Map","jobExecution","has","sourceJobExecutionIds","sourceSteps","jobExecutionId","sourceJobById","sourceJobByJobExecutionId","entries","flatMap","get","sourceModel","sourceModelJobByKey","key","sourceStepsByJobId","step","sourceJob","sourceJobSteps","push","carriedOver","name","statusReason","checkoutPersistCredentials","checkoutPermissionsContents","success","executionTimeoutMs","listeningTimeoutMs","maxExecutions","onResolve","batchDebounceMs","batchMaxSize","batchMaxWaitMs","listenerStatus","resolutionReason","listeningOn","listeningUntil","outputs","dependencies","runner","createExecution","undefined","sourceExecution","modelJob","executionName","createSteps","sourceLocation","type","config","condition","configPlan","authoredConfig","error"],"mappings":"AAAA,SAAQA,0BAA0B,QAAO,+BAA+B;AACxE,SAAQC,GAAG,EAAEC,GAAG,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,QAAO,cAAc;AACvD,SAAQC,qBAAqB,QAAyB,iCAAiC;AACvF,SAAQC,iBAAiB,EAAEC,mBAAmB,EAAEC,sBAAsB,QA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IqD,GAAG,CAAC,GAAG,CAAC;gBAC9D,MAAMyB,SACJnB,eAAeuB,aAAaF,YACvBC,iBAAiBH,UAAU9E,IAAI8E,MAAM,IAAI,OAC1ClH,yBAAyB;oBACvBuD,KAAK3C,OAAOuC,SAAS;oBACrBmE;oBACA7C,OAAOrC,IAAIb,EAAE;oBACbmD,UAAU;oBACV6C;oBACA1F,QAAQ;gBACV;gBAEN,OAAO;oBACL6C,UAAU;oBACVsB,MAAMuB;oBACNL,QAAQA,SAAS;2BAAIA;qBAAO,GAAG;oBAC/BrF,QAAQkE,cAAe,cAAyB;oBAChDE,cAAc;oBACde,SAASjB,eAAesB,iBAAiBL,UAAU;wBAAC,GAAGK,gBAAgBL,OAAO;oBAAA,IAAI;oBAClF,GAAIjB,cAAc;wBAAC9B,YAAYtE,GAAG,CAAC,KAAK,CAAC;oBAAA,IAAI,CAAC,CAAC;gBACjD;YACF;YACA6H,aAAa,IACX,AAAC9B,CAAAA,mBAAmBJ,GAAG,CAACM,UAAUrE,EAAE,KAAK,EAAE,AAAD,EAAG+C,GAAG,CAAC,CAACqB,OAAU,CAAA;wBAC1DF,KAAKE,KAAKF,GAAG;wBACbO,MAAML,KAAKK,IAAI;wBACfyB,gBAAgB9B,KAAK8B,cAAc;wBACnC5F,QAAQkE,cAAcJ,KAAK9D,MAAM,GAAI;wBACrCoE,cAAcF,cAAcJ,KAAKM,YAAY,GAAG;wBAChDyB,MAAM/B,KAAK+B,IAAI;wBACfC,QAAQhC,KAAKgC,MAAM;wBACnBC,WAAWjC,KAAKiC,SAAS,IAAI;wBAC7BC,YAAYlC,KAAKkC,UAAU;wBAC3BC,gBAAgBnC,KAAKmC,cAAc;wBACnCC,OAAO;wBACP9F,UAAU0D,KAAK1D,QAAQ;wBACvBR,gBAAgB;oBAClB,CAAA;QACJ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/db/workflow-runs/run-rerun.ts"],"sourcesContent":["import {readPersistedWorkflowModel} from '@shipfox/api-definitions-dto';\nimport {and, asc, eq, inArray, sql} from 'drizzle-orm';\nimport {isWorkflowRunTerminal, type WorkflowRun} from '#core/entities/workflow-run.js';\nimport {NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError} from '#core/errors.js';\nimport {deriveJobExecutionRunner} from '#core/workflow-run-creation.js';\nimport {recordWorkflowRunCreated} from '#metrics/instance.js';\nimport {db, type Tx} from '../db.js';\nimport {type JobExecutionDb, jobExecutions} from '../schema/job-executions.js';\nimport {type JobDb, jobs} from '../schema/jobs.js';\nimport {type StepDb, steps} from '../schema/steps.js';\nimport {type WorkflowRunAttemptDb, workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';\nimport {type MaterializedRunGraphJob, persistMaterializedRunGraph} from './run-graph.js';\nimport {lockWorkflowRun} from './shared.js';\n\nexport interface CreateRerunWorkflowRunParams {\n workflowRunId: string;\n mode: 'all' | 'failed';\n actorUserId: string;\n}\n\nexport async function createRerunWorkflowRun(\n params: CreateRerunWorkflowRunParams,\n): Promise<WorkflowRun> {\n const result = await db().transaction(async (tx) => {\n const workflowRunId = params.workflowRunId;\n await tx.execute(sql`select pg_advisory_xact_lock(hashtext(${workflowRunId}))`);\n\n const sourceRow = await lockWorkflowRun(workflowRunId, tx);\n if (!sourceRow) throw new SourceRunNotFoundError(workflowRunId);\n\n const [sourceAttemptRow] = await tx\n .select()\n .from(workflowRunAttempts)\n .where(\n and(\n eq(workflowRunAttempts.workflowRunId, sourceRow.id),\n eq(workflowRunAttempts.attempt, sourceRow.currentAttempt),\n ),\n )\n .limit(1)\n .for('update');\n if (!sourceAttemptRow) {\n throw new Error(\n `Current attempt ${sourceRow.currentAttempt} missing for run ${sourceRow.id}`,\n );\n }\n if (!isWorkflowRunTerminal(sourceAttemptRow.status)) {\n throw new RunNotTerminalError(sourceRow.id);\n }\n\n const sourceJobs = await tx\n .select()\n .from(jobs)\n .where(eq(jobs.workflowRunAttemptId, sourceAttemptRow.id))\n .orderBy(asc(jobs.position), asc(jobs.id));\n\n if (\n params.mode === 'failed' &&\n !sourceJobs.some((job) => job.status === 'failed' || job.status === 'cancelled')\n ) {\n throw new NoFailedJobsError(sourceRow.id);\n }\n\n const [attemptRow] = await tx\n .select({value: sql<number>`coalesce(max(${workflowRunAttempts.attempt}), 1)`})\n .from(workflowRunAttempts)\n .where(eq(workflowRunAttempts.workflowRunId, sourceRow.id));\n const attempt = Number(attemptRow?.value ?? 1) + 1;\n\n const [newAttemptRow] = await tx\n .insert(workflowRunAttempts)\n .values({\n workflowRunId: sourceRow.id,\n attempt,\n status: 'pending',\n rerunMode: params.mode,\n rerunByUserId: params.actorUserId,\n model: sourceAttemptRow.model,\n vars: sourceAttemptRow.vars,\n agentToolMaterialization: sourceAttemptRow.agentToolMaterialization,\n })\n .returning();\n if (!newAttemptRow) throw new Error('Insert returned no rows');\n\n const sourceGraph = await loadRerunSourceGraph(tx, sourceJobs);\n\n const sourceRun = toWorkflowRun(sourceRow);\n const graphJobs = materializeRerunGraphJobs({\n mode: params.mode,\n sourceRun,\n sourceAttempt: sourceAttemptRow,\n sourceJobs,\n ...sourceGraph,\n });\n await persistMaterializedRunGraph(tx, {\n run: sourceRun,\n workflowRunAttempt: newAttemptRow,\n materializedJobs: graphJobs,\n });\n\n const [newRunRow] = await tx\n .update(workflowRuns)\n .set({\n currentAttempt: attempt,\n status: 'pending',\n version: sql`${workflowRuns.version} + 1`,\n updatedAt: new Date(),\n startedAt: null,\n finishedAt: null,\n })\n .where(eq(workflowRuns.id, sourceRow.id))\n .returning();\n if (!newRunRow) throw new Error(`Workflow run missing after rerun: ${sourceRow.id}`);\n\n return toWorkflowRun(newRunRow);\n });\n\n recordWorkflowRunCreated(result.triggerPayload.provider ?? result.triggerSource);\n\n return result;\n}\n\nasync function loadRerunSourceGraph(\n tx: Tx,\n sourceJobs: readonly JobDb[],\n): Promise<{\n readonly sourceJobExecutionByJobId: ReadonlyMap<string, JobExecutionDb>;\n readonly sourceJobByJobExecutionId: ReadonlyMap<string, JobDb>;\n readonly sourceSteps: readonly StepDb[];\n}> {\n const sourceJobIds = sourceJobs.map((job) => job.id);\n const sourceJobExecutionRows =\n sourceJobIds.length === 0\n ? []\n : await tx\n .select()\n .from(jobExecutions)\n .where(inArray(jobExecutions.jobId, sourceJobIds))\n .orderBy(asc(jobExecutions.jobId), asc(jobExecutions.sequence), asc(jobExecutions.id));\n const sourceJobExecutionByJobId = new Map<string, JobExecutionDb>();\n for (const jobExecution of sourceJobExecutionRows) {\n if (!sourceJobExecutionByJobId.has(jobExecution.jobId)) {\n sourceJobExecutionByJobId.set(jobExecution.jobId, jobExecution);\n }\n }\n\n const sourceJobExecutionIds = [...sourceJobExecutionByJobId.values()].map(\n (jobExecution) => jobExecution.id,\n );\n const sourceSteps =\n sourceJobExecutionIds.length === 0\n ? []\n : await tx\n .select()\n .from(steps)\n .where(inArray(steps.jobExecutionId, sourceJobExecutionIds))\n .orderBy(asc(steps.jobExecutionId), asc(steps.position), asc(steps.id));\n\n const sourceJobById = new Map(sourceJobs.map((job) => [job.id, job]));\n const sourceJobByJobExecutionId = new Map(\n [...sourceJobExecutionByJobId.entries()].flatMap(([jobId, jobExecution]) => {\n const job = sourceJobById.get(jobId);\n return job ? [[jobExecution.id, job] as const] : [];\n }),\n );\n\n return {sourceJobExecutionByJobId, sourceJobByJobExecutionId, sourceSteps};\n}\n\nfunction materializeRerunGraphJobs(params: {\n readonly mode: CreateRerunWorkflowRunParams['mode'];\n readonly sourceRun: WorkflowRun;\n readonly sourceAttempt: WorkflowRunAttemptDb;\n readonly sourceJobs: readonly JobDb[];\n readonly sourceJobExecutionByJobId: ReadonlyMap<string, JobExecutionDb>;\n readonly sourceJobByJobExecutionId: ReadonlyMap<string, JobDb>;\n readonly sourceSteps: readonly StepDb[];\n}): readonly MaterializedRunGraphJob[] {\n const sourceModel =\n params.sourceAttempt.model === null\n ? null\n : readPersistedWorkflowModel(params.sourceAttempt.model);\n const sourceModelJobByKey = new Map((sourceModel?.jobs ?? []).map((job) => [job.key, job]));\n const sourceStepsByJobId = new Map<string, StepDb[]>();\n for (const step of params.sourceSteps) {\n const sourceJob = params.sourceJobByJobExecutionId.get(step.jobExecutionId);\n if (!sourceJob) continue;\n const sourceJobSteps = sourceStepsByJobId.get(sourceJob.id) ?? [];\n sourceJobSteps.push(step);\n sourceStepsByJobId.set(sourceJob.id, sourceJobSteps);\n }\n\n return params.sourceJobs.map((sourceJob) => {\n const carriedOver = params.mode === 'failed' && sourceJob.status === 'succeeded';\n const modelJob = sourceModelJobByKey.get(sourceJob.key);\n const modelCheckout = modelJob?.checkout;\n const resolvedModelCheckout = modelCheckout === false ? undefined : modelCheckout;\n\n return {\n job: {\n key: sourceJob.key,\n name: sourceJob.name,\n mode: sourceJob.mode,\n status: carriedOver ? ('succeeded' as const) : ('pending' as const),\n statusReason: null,\n carriedOver,\n checkoutPersistCredentials:\n resolvedModelCheckout?.persistCredentials ?? sourceJob.checkoutPersistCredentials,\n checkoutPermissionsContents:\n resolvedModelCheckout?.permissions?.contents ?? sourceJob.checkoutPermissionsContents,\n success: sourceJob.success,\n executionTimeoutMs: sourceJob.executionTimeoutMs,\n listeningTimeoutMs: sourceJob.listeningTimeoutMs,\n maxExecutions: sourceJob.maxExecutions,\n onResolve: sourceJob.onResolve,\n batchDebounceMs: sourceJob.batchDebounceMs,\n batchMaxSize: sourceJob.batchMaxSize,\n batchMaxWaitMs: sourceJob.batchMaxWaitMs,\n listenerStatus: 'inactive' as const,\n resolutionReason: null,\n listeningOn: sourceJob.listeningOn ? [...sourceJob.listeningOn] : null,\n listeningUntil: sourceJob.listeningUntil ? [...sourceJob.listeningUntil] : null,\n outputs: carriedOver && sourceJob.outputs ? {...sourceJob.outputs} : null,\n dependencies: [...sourceJob.dependencies],\n runner: sourceJob.runner ? [...sourceJob.runner] : null,\n position: sourceJob.position,\n },\n createExecution: (job) => {\n if (job.mode === 'listening') return undefined;\n\n const sourceExecution = params.sourceJobExecutionByJobId.get(sourceJob.id);\n const nameOverride = sourceExecution?.name ?? null;\n const executionName = nameOverride ?? job.name ?? job.key;\n const runner =\n carriedOver || modelJob === undefined\n ? (sourceExecution?.runner ?? job.runner ?? null)\n : deriveJobExecutionRunner({\n run: params.sourceRun,\n modelJob,\n jobId: job.id,\n sequence: 1,\n nameOverride,\n executionName,\n jobName: job.name,\n status: 'pending',\n });\n\n return {\n sequence: 1,\n // Reruns preserve the authored/resolved override, never the\n // effective fallback exposed by the core entity.\n name: nameOverride,\n runner: runner ? [...runner] : null,\n status: carriedOver ? ('succeeded' as const) : ('pending' as const),\n statusReason: null,\n outputs: carriedOver && sourceExecution?.outputs ? {...sourceExecution.outputs} : null,\n ...(carriedOver ? {finishedAt: sql`now()`} : {}),\n };\n },\n createSteps: () =>\n (sourceStepsByJobId.get(sourceJob.id) ?? []).map((step) => ({\n key: step.key,\n name: step.name,\n sourceLocation: step.sourceLocation,\n status: carriedOver ? step.status : ('pending' as const),\n statusReason: carriedOver ? step.statusReason : null,\n type: step.type,\n config: step.config,\n condition: step.condition ?? null,\n configPlan: step.configPlan,\n authoredConfig: step.authoredConfig,\n error: null,\n position: step.position,\n currentAttempt: 1,\n })),\n };\n });\n}\n"],"names":["readPersistedWorkflowModel","and","asc","eq","inArray","sql","isWorkflowRunTerminal","NoFailedJobsError","RunNotTerminalError","SourceRunNotFoundError","deriveJobExecutionRunner","recordWorkflowRunCreated","db","jobExecutions","jobs","steps","workflowRunAttempts","toWorkflowRun","workflowRuns","persistMaterializedRunGraph","lockWorkflowRun","createRerunWorkflowRun","params","result","transaction","tx","workflowRunId","execute","sourceRow","sourceAttemptRow","select","from","where","id","attempt","currentAttempt","limit","for","Error","status","sourceJobs","workflowRunAttemptId","orderBy","position","mode","some","job","attemptRow","value","Number","newAttemptRow","insert","values","rerunMode","rerunByUserId","actorUserId","model","vars","agentToolMaterialization","returning","sourceGraph","loadRerunSourceGraph","sourceRun","graphJobs","materializeRerunGraphJobs","sourceAttempt","run","workflowRunAttempt","materializedJobs","newRunRow","update","set","version","updatedAt","Date","startedAt","finishedAt","triggerPayload","provider","triggerSource","sourceJobIds","map","sourceJobExecutionRows","length","jobId","sequence","sourceJobExecutionByJobId","Map","jobExecution","has","sourceJobExecutionIds","sourceSteps","jobExecutionId","sourceJobById","sourceJobByJobExecutionId","entries","flatMap","get","sourceModel","sourceModelJobByKey","key","sourceStepsByJobId","step","sourceJob","sourceJobSteps","push","carriedOver","modelJob","modelCheckout","checkout","resolvedModelCheckout","undefined","name","statusReason","checkoutPersistCredentials","persistCredentials","checkoutPermissionsContents","permissions","contents","success","executionTimeoutMs","listeningTimeoutMs","maxExecutions","onResolve","batchDebounceMs","batchMaxSize","batchMaxWaitMs","listenerStatus","resolutionReason","listeningOn","listeningUntil","outputs","dependencies","runner","createExecution","sourceExecution","nameOverride","executionName","jobName","createSteps","sourceLocation","type","config","condition","configPlan","authoredConfig","error"],"mappings":"AAAA,SAAQA,0BAA0B,QAAO,+BAA+B;AACxE,SAAQC,GAAG,EAAEC,GAAG,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,QAAO,cAAc;AACvD,SAAQC,qBAAqB,QAAyB,iCAAiC;AACvF,SAAQC,iBAAiB,EAAEC,mBAAmB,EAAEC,sBAAsB,QAAO,kBAAkB;AAC/F,SAAQC,wBAAwB,QAAO,iCAAiC;AACxE,SAAQC,wBAAwB,QAAO,uBAAuB;AAC9D,SAAQC,EAAE,QAAgB,WAAW;AACrC,SAA6BC,aAAa,QAAO,8BAA8B;AAC/E,SAAoBC,IAAI,QAAO,oBAAoB;AACnD,SAAqBC,KAAK,QAAO,qBAAqB;AACtD,SAAmCC,mBAAmB,QAAO,qCAAqC;AAClG,SAAQC,aAAa,EAAEC,YAAY,QAAO,6BAA6B;AACvE,SAAsCC,2BAA2B,QAAO,iBAAiB;AACzF,SAAQC,eAAe,QAAO,cAAc;AAQ5C,OAAO,eAAeC,uBACpBC,MAAoC;IAEpC,MAAMC,SAAS,MAAMX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ContextForJob(jobId, tx) {
|
|
|
40
40
|
workflowRunId: workflowRuns.id,
|
|
41
41
|
workflowRunAttemptId: workflowRunAttempts.id,
|
|
42
42
|
workspaceId: workflowRuns.workspaceId,
|
|
43
|
-
projectId: workflowRuns.projectId
|
|
43
|
+
projectId: workflowRuns.projectId,
|
|
44
|
+
vars: workflowRunAttempts.vars
|
|
44
45
|
}).from(jobs).innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id)).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).where(eq(jobs.id, jobId)).limit(1);
|
|
45
46
|
const context = rows[0];
|
|
46
47
|
if (!context) throw new Error(`Cannot load workflow context: job ${jobId} not found`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db/workflow-runs/shared.ts"],"sourcesContent":["import {eq, sql} from 'drizzle-orm';\nimport type {JobStatus} from '#core/entities/job.js';\nimport type {JobExecutionStatus} from '#core/entities/job-execution.js';\nimport type {WorkflowRunStatus} from '#core/entities/workflow-run.js';\nimport type {Tx} from '../db.js';\nimport {jobs} from '../schema/jobs.js';\nimport {steps} from '../schema/steps.js';\nimport {workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {workflowRuns} from '../schema/workflow-runs.js';\n\nexport const TERMINAL_WORKFLOW_RUN_STATUSES: WorkflowRunStatus[] = [\n 'succeeded',\n 'failed',\n 'cancelled',\n];\n\nexport const TERMINAL_JOB_STATUSES: JobStatus[] = ['succeeded', 'failed', 'cancelled', 'skipped'];\n\nexport const TERMINAL_EXECUTION_STATUSES: JobExecutionStatus[] = [\n 'succeeded',\n 'failed',\n 'cancelled',\n];\n\nexport const NON_TERMINAL_STEP_STATUS_FILTER = sql`${steps.status} NOT IN ('succeeded','failed','cancelled','skipped')`;\n\nexport async function lockWorkflowRun(\n id: string,\n tx: Tx,\n): Promise<typeof workflowRuns.$inferSelect | undefined> {\n const rows = await tx\n .select()\n .from(workflowRuns)\n .where(eq(workflowRuns.id, id))\n .limit(1)\n .for('update');\n return rows[0];\n}\n\nexport async function optimisticLockRetry<TResult, TFetched>(params: {\n updateFn: () => Promise<TResult | null>;\n fetchFn: () => Promise<TFetched | undefined>;\n matchFn: (value: TFetched) => TResult | null;\n failureMessage: string;\n}): Promise<TResult> {\n const updated = await params.updateFn();\n if (updated) return updated;\n\n const existing = await params.fetchFn();\n if (existing) {\n const matched = params.matchFn(existing);\n if (matched) return matched;\n }\n\n throw new Error(params.failureMessage);\n}\n\nexport async function getWorkflowContextForJob(\n jobId: string,\n tx: Tx,\n): Promise<{\n jobId: string;\n workflowRunId: string;\n workflowRunAttemptId: string;\n workspaceId: string;\n projectId: string;\n}> {\n const rows = await tx\n .select({\n jobId: jobs.id,\n workflowRunId: workflowRuns.id,\n workflowRunAttemptId: workflowRunAttempts.id,\n workspaceId: workflowRuns.workspaceId,\n projectId: workflowRuns.projectId,\n })\n .from(jobs)\n .innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(eq(jobs.id, jobId))\n .limit(1);\n const context = rows[0];\n if (!context) throw new Error(`Cannot load workflow context: job ${jobId} not found`);\n return context;\n}\n"],"names":["eq","sql","jobs","steps","workflowRunAttempts","workflowRuns","TERMINAL_WORKFLOW_RUN_STATUSES","TERMINAL_JOB_STATUSES","TERMINAL_EXECUTION_STATUSES","NON_TERMINAL_STEP_STATUS_FILTER","status","lockWorkflowRun","id","tx","rows","select","from","where","limit","for","optimisticLockRetry","params","updated","updateFn","existing","fetchFn","matched","matchFn","Error","failureMessage","getWorkflowContextForJob","jobId","workflowRunId","workflowRunAttemptId","workspaceId","projectId","innerJoin","context"],"mappings":"AAAA,SAAQA,EAAE,EAAEC,GAAG,QAAO,cAAc;AAKpC,SAAQC,IAAI,QAAO,oBAAoB;AACvC,SAAQC,KAAK,QAAO,qBAAqB;AACzC,SAAQC,mBAAmB,QAAO,qCAAqC;AACvE,SAAQC,YAAY,QAAO,6BAA6B;AAExD,OAAO,MAAMC,iCAAsD;IACjE;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,wBAAqC;IAAC;IAAa;IAAU;IAAa;CAAU,CAAC;AAElG,OAAO,MAAMC,8BAAoD;IAC/D;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,kCAAkCR,GAAG,CAAC,EAAEE,MAAMO,MAAM,CAAC,oDAAoD,CAAC,CAAC;AAExH,OAAO,eAAeC,gBACpBC,EAAU,EACVC,EAAM;IAEN,MAAMC,OAAO,MAAMD,GAChBE,MAAM,GACNC,IAAI,CAACX,cACLY,KAAK,CAACjB,GAAGK,aAAaO,EAAE,EAAEA,KAC1BM,KAAK,CAAC,GACNC,GAAG,CAAC;IACP,OAAOL,IAAI,CAAC,EAAE;AAChB;AAEA,OAAO,eAAeM,oBAAuCC,MAK5D;IACC,MAAMC,UAAU,MAAMD,OAAOE,QAAQ;IACrC,IAAID,SAAS,OAAOA;IAEpB,MAAME,WAAW,MAAMH,OAAOI,OAAO;IACrC,IAAID,UAAU;QACZ,MAAME,UAAUL,OAAOM,OAAO,CAACH;QAC/B,IAAIE,SAAS,OAAOA;IACtB;IAEA,MAAM,IAAIE,MAAMP,OAAOQ,cAAc;AACvC;AAEA,OAAO,eAAeC,yBACpBC,KAAa,EACblB,EAAM;
|
|
1
|
+
{"version":3,"sources":["../../../src/db/workflow-runs/shared.ts"],"sourcesContent":["import {eq, sql} from 'drizzle-orm';\nimport type {JobStatus} from '#core/entities/job.js';\nimport type {JobExecutionStatus} from '#core/entities/job-execution.js';\nimport type {WorkflowRunStatus} from '#core/entities/workflow-run.js';\nimport type {Tx} from '../db.js';\nimport {jobs} from '../schema/jobs.js';\nimport {steps} from '../schema/steps.js';\nimport {workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {workflowRuns} from '../schema/workflow-runs.js';\n\nexport const TERMINAL_WORKFLOW_RUN_STATUSES: WorkflowRunStatus[] = [\n 'succeeded',\n 'failed',\n 'cancelled',\n];\n\nexport const TERMINAL_JOB_STATUSES: JobStatus[] = ['succeeded', 'failed', 'cancelled', 'skipped'];\n\nexport const TERMINAL_EXECUTION_STATUSES: JobExecutionStatus[] = [\n 'succeeded',\n 'failed',\n 'cancelled',\n];\n\nexport const NON_TERMINAL_STEP_STATUS_FILTER = sql`${steps.status} NOT IN ('succeeded','failed','cancelled','skipped')`;\n\nexport async function lockWorkflowRun(\n id: string,\n tx: Tx,\n): Promise<typeof workflowRuns.$inferSelect | undefined> {\n const rows = await tx\n .select()\n .from(workflowRuns)\n .where(eq(workflowRuns.id, id))\n .limit(1)\n .for('update');\n return rows[0];\n}\n\nexport async function optimisticLockRetry<TResult, TFetched>(params: {\n updateFn: () => Promise<TResult | null>;\n fetchFn: () => Promise<TFetched | undefined>;\n matchFn: (value: TFetched) => TResult | null;\n failureMessage: string;\n}): Promise<TResult> {\n const updated = await params.updateFn();\n if (updated) return updated;\n\n const existing = await params.fetchFn();\n if (existing) {\n const matched = params.matchFn(existing);\n if (matched) return matched;\n }\n\n throw new Error(params.failureMessage);\n}\n\nexport async function getWorkflowContextForJob(\n jobId: string,\n tx: Tx,\n): Promise<{\n jobId: string;\n workflowRunId: string;\n workflowRunAttemptId: string;\n workspaceId: string;\n projectId: string;\n vars: Record<string, string> | null;\n}> {\n const rows = await tx\n .select({\n jobId: jobs.id,\n workflowRunId: workflowRuns.id,\n workflowRunAttemptId: workflowRunAttempts.id,\n workspaceId: workflowRuns.workspaceId,\n projectId: workflowRuns.projectId,\n vars: workflowRunAttempts.vars,\n })\n .from(jobs)\n .innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(eq(jobs.id, jobId))\n .limit(1);\n const context = rows[0];\n if (!context) throw new Error(`Cannot load workflow context: job ${jobId} not found`);\n return context;\n}\n"],"names":["eq","sql","jobs","steps","workflowRunAttempts","workflowRuns","TERMINAL_WORKFLOW_RUN_STATUSES","TERMINAL_JOB_STATUSES","TERMINAL_EXECUTION_STATUSES","NON_TERMINAL_STEP_STATUS_FILTER","status","lockWorkflowRun","id","tx","rows","select","from","where","limit","for","optimisticLockRetry","params","updated","updateFn","existing","fetchFn","matched","matchFn","Error","failureMessage","getWorkflowContextForJob","jobId","workflowRunId","workflowRunAttemptId","workspaceId","projectId","vars","innerJoin","context"],"mappings":"AAAA,SAAQA,EAAE,EAAEC,GAAG,QAAO,cAAc;AAKpC,SAAQC,IAAI,QAAO,oBAAoB;AACvC,SAAQC,KAAK,QAAO,qBAAqB;AACzC,SAAQC,mBAAmB,QAAO,qCAAqC;AACvE,SAAQC,YAAY,QAAO,6BAA6B;AAExD,OAAO,MAAMC,iCAAsD;IACjE;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,wBAAqC;IAAC;IAAa;IAAU;IAAa;CAAU,CAAC;AAElG,OAAO,MAAMC,8BAAoD;IAC/D;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,kCAAkCR,GAAG,CAAC,EAAEE,MAAMO,MAAM,CAAC,oDAAoD,CAAC,CAAC;AAExH,OAAO,eAAeC,gBACpBC,EAAU,EACVC,EAAM;IAEN,MAAMC,OAAO,MAAMD,GAChBE,MAAM,GACNC,IAAI,CAACX,cACLY,KAAK,CAACjB,GAAGK,aAAaO,EAAE,EAAEA,KAC1BM,KAAK,CAAC,GACNC,GAAG,CAAC;IACP,OAAOL,IAAI,CAAC,EAAE;AAChB;AAEA,OAAO,eAAeM,oBAAuCC,MAK5D;IACC,MAAMC,UAAU,MAAMD,OAAOE,QAAQ;IACrC,IAAID,SAAS,OAAOA;IAEpB,MAAME,WAAW,MAAMH,OAAOI,OAAO;IACrC,IAAID,UAAU;QACZ,MAAME,UAAUL,OAAOM,OAAO,CAACH;QAC/B,IAAIE,SAAS,OAAOA;IACtB;IAEA,MAAM,IAAIE,MAAMP,OAAOQ,cAAc;AACvC;AAEA,OAAO,eAAeC,yBACpBC,KAAa,EACblB,EAAM;IASN,MAAMC,OAAO,MAAMD,GAChBE,MAAM,CAAC;QACNgB,OAAO7B,KAAKU,EAAE;QACdoB,eAAe3B,aAAaO,EAAE;QAC9BqB,sBAAsB7B,oBAAoBQ,EAAE;QAC5CsB,aAAa7B,aAAa6B,WAAW;QACrCC,WAAW9B,aAAa8B,SAAS;QACjCC,MAAMhC,oBAAoBgC,IAAI;IAChC,GACCpB,IAAI,CAACd,MACLmC,SAAS,CAACjC,qBAAqBJ,GAAGE,KAAK+B,oBAAoB,EAAE7B,oBAAoBQ,EAAE,GACnFyB,SAAS,CAAChC,cAAcL,GAAGI,oBAAoB4B,aAAa,EAAE3B,aAAaO,EAAE,GAC7EK,KAAK,CAACjB,GAAGE,KAAKU,EAAE,EAAEmB,QAClBb,KAAK,CAAC;IACT,MAAMoB,UAAUxB,IAAI,CAAC,EAAE;IACvB,IAAI,CAACwB,SAAS,MAAM,IAAIV,MAAM,CAAC,kCAAkC,EAAEG,MAAM,UAAU,CAAC;IACpF,OAAOO;AACT"}
|
|
@@ -191,8 +191,8 @@ export async function finishStepAttempt(params, tx) {
|
|
|
191
191
|
// Restart-only: rewind every step at or after `fromPosition` back to pending,
|
|
192
192
|
// clearing its result and bumping both `version` and `current_attempt` so the next
|
|
193
193
|
// dispatch opens a fresh attempt. This DELIBERATELY bypasses the never-downgrade
|
|
194
|
-
// guard used everywhere else
|
|
195
|
-
//
|
|
194
|
+
// guard used everywhere else. It is the one place that resurrects terminal steps,
|
|
195
|
+
// so it must only be called from the durable-restart path, never the ordinary
|
|
196
196
|
// report path. It must run in the same transaction as the failed-attempt write.
|
|
197
197
|
export async function rewindStepsToPending(params, tx) {
|
|
198
198
|
await tx.update(steps).set({
|
|
@@ -205,7 +205,7 @@ export async function rewindStepsToPending(params, tx) {
|
|
|
205
205
|
}).where(and(eq(steps.jobExecutionId, params.jobExecutionId), gte(steps.position, params.fromPosition)));
|
|
206
206
|
}
|
|
207
207
|
// Count a single step's own attempts. Used to bound the restart cap on the
|
|
208
|
-
// gating step's actual executions
|
|
208
|
+
// gating step's actual executions: `steps.current_attempt` can't be used for
|
|
209
209
|
// the cap because a rewind also bumps it for downstream steps swept into the
|
|
210
210
|
// rewind range (which would inflate a later gate's cap in a multi-gate job).
|
|
211
211
|
export async function countStepAttempts(stepId, tx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db/workflow-runs/steps.ts"],"sourcesContent":["import type {LogOutcomeDto} from '@shipfox/api-workflows-dto';\nimport {and, asc, count, eq, gte, inArray, sql} from 'drizzle-orm';\nimport type {\n PersistedEvaluationTraceEntry,\n Step,\n StepAttempt,\n StepAttemptStatus,\n StepStatus,\n StepStatusReason,\n} from '#core/entities/step.js';\nimport {deriveCompletion, isTerminal} from '#core/step-transition/decide-step-transition.js';\nimport {db, type Tx} from '../db.js';\nimport {jobExecutions} from '../schema/job-executions.js';\nimport {stepAttempts, toStepAttempt} from '../schema/step-attempts.js';\nimport {steps, toStep} from '../schema/steps.js';\nimport {writeJobStepsSettledOutbox, writeStepAttemptTerminatedOutbox} from './outbox.js';\nimport {NON_TERMINAL_STEP_STATUS_FILTER} from './shared.js';\n\nexport async function getStepByIdForJobExecution(params: {\n stepId: string;\n jobExecutionId: string;\n}): Promise<Step | undefined> {\n const rows = await db()\n .select()\n .from(steps)\n .where(and(eq(steps.id, params.stepId), eq(steps.jobExecutionId, params.jobExecutionId)))\n .limit(1);\n\n const row = rows[0];\n if (!row) return undefined;\n return toStep(row);\n}\n\nexport async function getStepById(stepId: string): Promise<Step | undefined> {\n const rows = await db().select().from(steps).where(eq(steps.id, stepId)).limit(1);\n\n const row = rows[0];\n if (!row) return undefined;\n return toStep(row);\n}\n\nexport async function getStepsByJobId(jobId: string): Promise<Step[]> {\n const rows = await db()\n .select({step: steps})\n .from(steps)\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(eq(jobExecutions.jobId, jobId))\n .orderBy(asc(steps.position));\n return rows.map((row) => toStep(row.step));\n}\n\nexport async function getStepsByJobExecutionId(jobExecutionId: string): Promise<Step[]> {\n const rows = await db()\n .select()\n .from(steps)\n .where(eq(steps.jobExecutionId, jobExecutionId))\n .orderBy(asc(steps.position));\n return rows.map(toStep);\n}\n\nexport interface BulkUpdateStepStatusesParams {\n jobExecutionId: string;\n status: Extract<StepStatus, 'failed' | 'cancelled'>;\n}\n\nexport async function bulkUpdateStepStatuses(\n params: BulkUpdateStepStatusesParams,\n tx?: Tx,\n): Promise<void> {\n if (!tx) {\n await db().transaction((transaction) => bulkUpdateStepStatuses(params, transaction));\n return;\n }\n\n await tx\n .update(steps)\n .set({\n status: params.status,\n statusReason: null,\n updatedAt: new Date(),\n })\n .where(and(eq(steps.jobExecutionId, params.jobExecutionId), NON_TERMINAL_STEP_STATUS_FILTER));\n\n // Finalize open attempt rows so a timed-out/cancelled sweep does not leave\n // phantom in-flight work for gate and restart logic.\n const finalizedAttempts = await tx\n .update(stepAttempts)\n .set({status: params.status, logOutcome: 'abandoned', finishedAt: new Date()})\n .from(steps)\n .where(\n and(\n eq(stepAttempts.stepId, steps.id),\n eq(steps.jobExecutionId, params.jobExecutionId),\n eq(stepAttempts.status, 'running'),\n ),\n )\n .returning({\n stepId: stepAttempts.stepId,\n attempt: stepAttempts.attempt,\n logOutcome: stepAttempts.logOutcome,\n });\n\n if (finalizedAttempts.length > 0) {\n for (const attempt of finalizedAttempts) {\n await writeStepAttemptTerminatedOutbox(tx, {\n stepId: attempt.stepId,\n attempt: attempt.attempt,\n logOutcome: attempt.logOutcome ?? 'abandoned',\n });\n }\n }\n}\n\n// Per-step progression primitives. They take a mandatory `tx` because they only\n// run inside the job-execution service's transaction, and every write guards on\n// the never-downgrade predicate so a late or duplicate write cannot overwrite an\n// already-terminal row.\n\nexport async function getStepsByJobExecutionIdForUpdate(\n jobExecutionId: string,\n tx: Tx,\n): Promise<Step[]> {\n const rows = await tx\n .select()\n .from(steps)\n .where(eq(steps.jobExecutionId, jobExecutionId))\n .orderBy(asc(steps.position))\n .for('update');\n return rows.map(toStep);\n}\n\nexport async function getStepAttemptsByJobExecutionId(\n jobExecutionId: string,\n tx: Tx,\n): Promise<StepAttempt[]> {\n const rows = await tx\n .select()\n .from(stepAttempts)\n .where(eq(stepAttempts.jobExecutionId, jobExecutionId))\n .orderBy(asc(stepAttempts.executionOrder), asc(stepAttempts.id));\n return rows.map(toStepAttempt);\n}\n\nexport interface MarkStepRunningParams {\n jobExecutionId: string;\n stepId: string;\n}\n\nexport async function markStepRunning(params: MarkStepRunningParams, tx: Tx): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'running',\n statusReason: null,\n evaluationTrace: null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n )\n .returning();\n const row = rows[0];\n if (!row) return null;\n const step = toStep(row);\n // Open the attempt this dispatch runs. onConflictDoNothing makes a racing\n // re-dispatch a no-op against the unique (step_id, attempt) anchor; normal\n // re-delivery returns the already-running step without calling this.\n await insertRunningStepAttempt(\n {\n jobExecutionId: step.jobExecutionId,\n stepId: step.id,\n attempt: step.currentAttempt,\n config: step.config,\n },\n tx,\n );\n return step;\n}\n\nexport interface DispatchStepWithCompletedConfigParams {\n jobExecutionId: string;\n stepId: string;\n config: Record<string, unknown>;\n evaluationTrace: readonly PersistedEvaluationTraceEntry[] | null;\n}\n\nexport async function dispatchStepWithCompletedConfig(\n params: DispatchStepWithCompletedConfigParams,\n tx: Tx,\n): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'running',\n statusReason: null,\n evaluationTrace: null,\n config: params.config,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n )\n .returning();\n const row = rows[0];\n if (!row) return null;\n const step = toStep(row);\n await insertRunningStepAttempt(\n {\n jobExecutionId: step.jobExecutionId,\n stepId: step.id,\n attempt: step.currentAttempt,\n config: params.config,\n evaluationTrace: params.evaluationTrace,\n },\n tx,\n );\n return step;\n}\n\nexport interface MarkStepSkippedParams {\n jobExecutionId: string;\n stepId: string;\n statusReason: StepStatusReason;\n evaluationTrace: readonly PersistedEvaluationTraceEntry[];\n}\n\nexport async function markStepSkipped(params: MarkStepSkippedParams, tx: Tx): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'skipped',\n statusReason: params.statusReason,\n evaluationTrace: params.evaluationTrace,\n error: null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n eq(steps.status, 'pending'),\n ),\n )\n .returning();\n const row = rows[0];\n return row ? toStep(row) : null;\n}\n\nexport async function settleJobFailed(\n tx: Tx,\n params: {\n jobId: string;\n jobExecutionId: string;\n failedStepId: string;\n error: Record<string, unknown>;\n },\n): Promise<'succeeded' | 'failed' | null> {\n await applyStepResult(\n {\n jobExecutionId: params.jobExecutionId,\n stepId: params.failedStepId,\n status: 'failed',\n error: params.error,\n },\n tx,\n );\n\n const after = await getStepsByJobExecutionIdForUpdate(params.jobExecutionId, tx);\n if (!after.every((step) => isTerminal(step.status))) return null;\n\n const status = deriveCompletion(after);\n await writeJobStepsSettledOutbox(tx, {\n jobId: params.jobId,\n jobExecutionId: params.jobExecutionId,\n status,\n });\n return status;\n}\n\nexport interface InsertRunningStepAttemptParams {\n jobExecutionId: string;\n stepId: string;\n attempt: number;\n config?: Record<string, unknown> | null;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null;\n}\n\nexport async function insertRunningStepAttempt(\n params: InsertRunningStepAttemptParams,\n tx: Tx,\n): Promise<void> {\n const [{nextExecutionOrder} = {nextExecutionOrder: 1}] = await tx\n .select({\n nextExecutionOrder: sql<number>`coalesce(max(${stepAttempts.executionOrder}), 0) + 1`,\n })\n .from(stepAttempts)\n .where(eq(stepAttempts.jobExecutionId, params.jobExecutionId));\n\n await tx\n .insert(stepAttempts)\n .values({\n jobExecutionId: params.jobExecutionId,\n stepId: params.stepId,\n attempt: params.attempt,\n executionOrder: nextExecutionOrder,\n status: 'running',\n config: params.config ?? null,\n evaluationTrace: params.evaluationTrace ?? null,\n })\n .onConflictDoNothing({target: [stepAttempts.stepId, stepAttempts.attempt]});\n}\n\nexport interface FinishStepAttemptParams {\n stepId: string;\n attempt: number;\n status: Exclude<StepAttemptStatus, 'running'>;\n error?: Record<string, unknown> | null;\n output?: Record<string, unknown> | null;\n response?: string | null;\n exitCode?: number | null;\n logOutcome: LogOutcomeDto;\n gateResult?: Record<string, unknown> | null;\n restartFeedback?: string | null;\n}\n\n// Finalize the running attempt to a terminal state. The `status='running'` guard\n// makes this idempotent: a duplicate report finds the attempt already terminal\n// and updates nothing (never-downgrade for the audit row).\nexport async function finishStepAttempt(params: FinishStepAttemptParams, tx: Tx): Promise<void> {\n const rows = await tx\n .update(stepAttempts)\n .set({\n status: params.status,\n output: params.output ?? null,\n response: params.response ?? null,\n error: params.error ?? null,\n exitCode: params.exitCode ?? null,\n logOutcome: params.logOutcome,\n gateResult: params.gateResult ?? null,\n restartFeedback: params.restartFeedback ?? null,\n finishedAt: new Date(),\n })\n .where(\n and(\n eq(stepAttempts.stepId, params.stepId),\n eq(stepAttempts.attempt, params.attempt),\n eq(stepAttempts.status, 'running'),\n ),\n )\n .returning({\n stepId: stepAttempts.stepId,\n attempt: stepAttempts.attempt,\n logOutcome: stepAttempts.logOutcome,\n });\n\n const row = rows[0];\n if (!row) return;\n\n await writeStepAttemptTerminatedOutbox(tx, {\n stepId: row.stepId,\n attempt: row.attempt,\n logOutcome: row.logOutcome ?? params.logOutcome,\n });\n}\n\nexport interface RewindStepsToPendingParams {\n jobExecutionId: string;\n fromPosition: number;\n}\n\n// Restart-only: rewind every step at or after `fromPosition` back to pending,\n// clearing its result and bumping both `version` and `current_attempt` so the next\n// dispatch opens a fresh attempt. This DELIBERATELY bypasses the never-downgrade\n// guard used everywhere else — it is the one place that resurrects terminal steps\n// — so it must only be called from the durable-restart path, never the ordinary\n// report path. It must run in the same transaction as the failed-attempt write.\nexport async function rewindStepsToPending(\n params: RewindStepsToPendingParams,\n tx: Tx,\n): Promise<void> {\n await tx\n .update(steps)\n .set({\n status: 'pending',\n statusReason: null,\n error: null,\n version: sql`${steps.version} + 1`,\n currentAttempt: sql`${steps.currentAttempt} + 1`,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.jobExecutionId, params.jobExecutionId),\n gte(steps.position, params.fromPosition),\n ),\n );\n}\n\n// Count a single step's own attempts. Used to bound the restart cap on the\n// gating step's actual executions — `steps.current_attempt` can't be used for\n// the cap because a rewind also bumps it for downstream steps swept into the\n// rewind range (which would inflate a later gate's cap in a multi-gate job).\nexport async function countStepAttempts(stepId: string, tx: Tx): Promise<number> {\n const rows = await tx\n .select({total: count()})\n .from(stepAttempts)\n .where(eq(stepAttempts.stepId, stepId));\n return Number(rows[0]?.total ?? 0);\n}\n\nexport async function getStepAttempts(jobId: string): Promise<StepAttempt[]> {\n const rows = await db()\n .select({stepAttempt: stepAttempts})\n .from(stepAttempts)\n .innerJoin(steps, eq(stepAttempts.stepId, steps.id))\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(eq(jobExecutions.jobId, jobId))\n .orderBy(asc(stepAttempts.executionOrder));\n return rows.map((row) => toStepAttempt(row.stepAttempt));\n}\n\nexport async function getStepAttemptsByJobIds(jobIds: string[]): Promise<StepAttempt[]> {\n if (jobIds.length === 0) return [];\n const rows = await db()\n .select({stepAttempt: stepAttempts, jobId: jobExecutions.jobId})\n .from(stepAttempts)\n .innerJoin(steps, eq(stepAttempts.stepId, steps.id))\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(inArray(jobExecutions.jobId, jobIds))\n .orderBy(asc(jobExecutions.jobId), asc(stepAttempts.executionOrder));\n return rows.map((row) => toStepAttempt(row.stepAttempt));\n}\n\nexport interface ApplyStepResultParams {\n jobExecutionId: string;\n stepId: string;\n status: 'succeeded' | 'failed';\n error: Record<string, unknown> | null;\n}\n\nexport async function applyStepResult(params: ApplyStepResultParams, tx: Tx): Promise<void> {\n await tx\n .update(steps)\n .set({\n status: params.status,\n statusReason: null,\n error: params.error ?? null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n );\n}\n\nexport interface CancelRemainingStepsParams {\n jobExecutionId: string;\n}\n\nexport async function cancelRemainingSteps(\n params: CancelRemainingStepsParams,\n tx: Tx,\n): Promise<void> {\n await bulkUpdateStepStatuses({jobExecutionId: params.jobExecutionId, status: 'cancelled'}, tx);\n}\n"],"names":["and","asc","count","eq","gte","inArray","sql","deriveCompletion","isTerminal","db","jobExecutions","stepAttempts","toStepAttempt","steps","toStep","writeJobStepsSettledOutbox","writeStepAttemptTerminatedOutbox","NON_TERMINAL_STEP_STATUS_FILTER","getStepByIdForJobExecution","params","rows","select","from","where","id","stepId","jobExecutionId","limit","row","undefined","getStepById","getStepsByJobId","jobId","step","innerJoin","orderBy","position","map","getStepsByJobExecutionId","bulkUpdateStepStatuses","tx","transaction","update","set","status","statusReason","updatedAt","Date","finalizedAttempts","logOutcome","finishedAt","returning","attempt","length","getStepsByJobExecutionIdForUpdate","for","getStepAttemptsByJobExecutionId","executionOrder","markStepRunning","evaluationTrace","insertRunningStepAttempt","currentAttempt","config","dispatchStepWithCompletedConfig","markStepSkipped","error","settleJobFailed","applyStepResult","failedStepId","after","every","nextExecutionOrder","insert","values","onConflictDoNothing","target","finishStepAttempt","output","response","exitCode","gateResult","restartFeedback","rewindStepsToPending","version","fromPosition","countStepAttempts","total","Number","getStepAttempts","stepAttempt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9E;QAAcqB,OAAOtB,cAAcsB,KAAK;IAAA,GAC7DV,IAAI,CAACX,cACLuB,SAAS,CAACrB,OAAOV,GAAGQ,aAAac,MAAM,EAAEZ,MAAMW,EAAE,GACjDU,SAAS,CAACxB,eAAeP,GAAGU,MAAMa,cAAc,EAAEhB,cAAcc,EAAE,GAClED,KAAK,CAAClB,QAAQK,cAAcsB,KAAK,EAAE2D,SACnCxD,OAAO,CAAClC,IAAIS,cAAcsB,KAAK,GAAG/B,IAAIU,aAAa8C,cAAc;IACpE,OAAOrC,KAAKiB,GAAG,CAAC,CAACT,MAAQhB,cAAcgB,IAAI6D,WAAW;AACxD;AASA,OAAO,eAAetB,gBAAgBhD,MAA6B,EAAEqB,EAAM;IACzE,MAAMA,GACHE,MAAM,CAAC7B,OACP8B,GAAG,CAAC;QACHC,QAAQzB,OAAOyB,MAAM;QACrBC,cAAc;QACdoB,OAAO9C,OAAO8C,KAAK,IAAI;QACvBnB,WAAW,IAAIC;IACjB,GACCxB,KAAK,CACJvB,IACEG,GAAGU,MAAMW,EAAE,EAAEL,OAAOM,MAAM,GAC1BtB,GAAGU,MAAMa,cAAc,EAAEP,OAAOO,cAAc,GAC9CT;AAGR;AAMA,OAAO,eAAe2E,qBACpBzE,MAAkC,EAClCqB,EAAM;IAEN,MAAMD,uBAAuB;QAACb,gBAAgBP,OAAOO,cAAc;QAAEkB,QAAQ;IAAW,GAAGJ;AAC7F"}
|
|
1
|
+
{"version":3,"sources":["../../../src/db/workflow-runs/steps.ts"],"sourcesContent":["import type {LogOutcomeDto} from '@shipfox/api-workflows-dto';\nimport {and, asc, count, eq, gte, inArray, sql} from 'drizzle-orm';\nimport type {\n PersistedEvaluationTraceEntry,\n Step,\n StepAttempt,\n StepAttemptStatus,\n StepStatus,\n StepStatusReason,\n} from '#core/entities/step.js';\nimport {deriveCompletion, isTerminal} from '#core/step-transition/decide-step-transition.js';\nimport {db, type Tx} from '../db.js';\nimport {jobExecutions} from '../schema/job-executions.js';\nimport {stepAttempts, toStepAttempt} from '../schema/step-attempts.js';\nimport {steps, toStep} from '../schema/steps.js';\nimport {writeJobStepsSettledOutbox, writeStepAttemptTerminatedOutbox} from './outbox.js';\nimport {NON_TERMINAL_STEP_STATUS_FILTER} from './shared.js';\n\nexport async function getStepByIdForJobExecution(params: {\n stepId: string;\n jobExecutionId: string;\n}): Promise<Step | undefined> {\n const rows = await db()\n .select()\n .from(steps)\n .where(and(eq(steps.id, params.stepId), eq(steps.jobExecutionId, params.jobExecutionId)))\n .limit(1);\n\n const row = rows[0];\n if (!row) return undefined;\n return toStep(row);\n}\n\nexport async function getStepById(stepId: string): Promise<Step | undefined> {\n const rows = await db().select().from(steps).where(eq(steps.id, stepId)).limit(1);\n\n const row = rows[0];\n if (!row) return undefined;\n return toStep(row);\n}\n\nexport async function getStepsByJobId(jobId: string): Promise<Step[]> {\n const rows = await db()\n .select({step: steps})\n .from(steps)\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(eq(jobExecutions.jobId, jobId))\n .orderBy(asc(steps.position));\n return rows.map((row) => toStep(row.step));\n}\n\nexport async function getStepsByJobExecutionId(jobExecutionId: string): Promise<Step[]> {\n const rows = await db()\n .select()\n .from(steps)\n .where(eq(steps.jobExecutionId, jobExecutionId))\n .orderBy(asc(steps.position));\n return rows.map(toStep);\n}\n\nexport interface BulkUpdateStepStatusesParams {\n jobExecutionId: string;\n status: Extract<StepStatus, 'failed' | 'cancelled'>;\n}\n\nexport async function bulkUpdateStepStatuses(\n params: BulkUpdateStepStatusesParams,\n tx?: Tx,\n): Promise<void> {\n if (!tx) {\n await db().transaction((transaction) => bulkUpdateStepStatuses(params, transaction));\n return;\n }\n\n await tx\n .update(steps)\n .set({\n status: params.status,\n statusReason: null,\n updatedAt: new Date(),\n })\n .where(and(eq(steps.jobExecutionId, params.jobExecutionId), NON_TERMINAL_STEP_STATUS_FILTER));\n\n // Finalize open attempt rows so a timed-out/cancelled sweep does not leave\n // phantom in-flight work for gate and restart logic.\n const finalizedAttempts = await tx\n .update(stepAttempts)\n .set({status: params.status, logOutcome: 'abandoned', finishedAt: new Date()})\n .from(steps)\n .where(\n and(\n eq(stepAttempts.stepId, steps.id),\n eq(steps.jobExecutionId, params.jobExecutionId),\n eq(stepAttempts.status, 'running'),\n ),\n )\n .returning({\n stepId: stepAttempts.stepId,\n attempt: stepAttempts.attempt,\n logOutcome: stepAttempts.logOutcome,\n });\n\n if (finalizedAttempts.length > 0) {\n for (const attempt of finalizedAttempts) {\n await writeStepAttemptTerminatedOutbox(tx, {\n stepId: attempt.stepId,\n attempt: attempt.attempt,\n logOutcome: attempt.logOutcome ?? 'abandoned',\n });\n }\n }\n}\n\n// Per-step progression primitives. They take a mandatory `tx` because they only\n// run inside the job-execution service's transaction, and every write guards on\n// the never-downgrade predicate so a late or duplicate write cannot overwrite an\n// already-terminal row.\n\nexport async function getStepsByJobExecutionIdForUpdate(\n jobExecutionId: string,\n tx: Tx,\n): Promise<Step[]> {\n const rows = await tx\n .select()\n .from(steps)\n .where(eq(steps.jobExecutionId, jobExecutionId))\n .orderBy(asc(steps.position))\n .for('update');\n return rows.map(toStep);\n}\n\nexport async function getStepAttemptsByJobExecutionId(\n jobExecutionId: string,\n tx: Tx,\n): Promise<StepAttempt[]> {\n const rows = await tx\n .select()\n .from(stepAttempts)\n .where(eq(stepAttempts.jobExecutionId, jobExecutionId))\n .orderBy(asc(stepAttempts.executionOrder), asc(stepAttempts.id));\n return rows.map(toStepAttempt);\n}\n\nexport interface MarkStepRunningParams {\n jobExecutionId: string;\n stepId: string;\n}\n\nexport async function markStepRunning(params: MarkStepRunningParams, tx: Tx): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'running',\n statusReason: null,\n evaluationTrace: null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n )\n .returning();\n const row = rows[0];\n if (!row) return null;\n const step = toStep(row);\n // Open the attempt this dispatch runs. onConflictDoNothing makes a racing\n // re-dispatch a no-op against the unique (step_id, attempt) anchor; normal\n // re-delivery returns the already-running step without calling this.\n await insertRunningStepAttempt(\n {\n jobExecutionId: step.jobExecutionId,\n stepId: step.id,\n attempt: step.currentAttempt,\n config: step.config,\n },\n tx,\n );\n return step;\n}\n\nexport interface DispatchStepWithCompletedConfigParams {\n jobExecutionId: string;\n stepId: string;\n config: Record<string, unknown>;\n evaluationTrace: readonly PersistedEvaluationTraceEntry[] | null;\n}\n\nexport async function dispatchStepWithCompletedConfig(\n params: DispatchStepWithCompletedConfigParams,\n tx: Tx,\n): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'running',\n statusReason: null,\n evaluationTrace: null,\n config: params.config,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n )\n .returning();\n const row = rows[0];\n if (!row) return null;\n const step = toStep(row);\n await insertRunningStepAttempt(\n {\n jobExecutionId: step.jobExecutionId,\n stepId: step.id,\n attempt: step.currentAttempt,\n config: params.config,\n evaluationTrace: params.evaluationTrace,\n },\n tx,\n );\n return step;\n}\n\nexport interface MarkStepSkippedParams {\n jobExecutionId: string;\n stepId: string;\n statusReason: StepStatusReason;\n evaluationTrace: readonly PersistedEvaluationTraceEntry[];\n}\n\nexport async function markStepSkipped(params: MarkStepSkippedParams, tx: Tx): Promise<Step | null> {\n const rows = await tx\n .update(steps)\n .set({\n status: 'skipped',\n statusReason: params.statusReason,\n evaluationTrace: params.evaluationTrace,\n error: null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n eq(steps.status, 'pending'),\n ),\n )\n .returning();\n const row = rows[0];\n return row ? toStep(row) : null;\n}\n\nexport async function settleJobFailed(\n tx: Tx,\n params: {\n jobId: string;\n jobExecutionId: string;\n failedStepId: string;\n error: Record<string, unknown>;\n },\n): Promise<'succeeded' | 'failed' | null> {\n await applyStepResult(\n {\n jobExecutionId: params.jobExecutionId,\n stepId: params.failedStepId,\n status: 'failed',\n error: params.error,\n },\n tx,\n );\n\n const after = await getStepsByJobExecutionIdForUpdate(params.jobExecutionId, tx);\n if (!after.every((step) => isTerminal(step.status))) return null;\n\n const status = deriveCompletion(after);\n await writeJobStepsSettledOutbox(tx, {\n jobId: params.jobId,\n jobExecutionId: params.jobExecutionId,\n status,\n });\n return status;\n}\n\nexport interface InsertRunningStepAttemptParams {\n jobExecutionId: string;\n stepId: string;\n attempt: number;\n config?: Record<string, unknown> | null;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null;\n}\n\nexport async function insertRunningStepAttempt(\n params: InsertRunningStepAttemptParams,\n tx: Tx,\n): Promise<void> {\n const [{nextExecutionOrder} = {nextExecutionOrder: 1}] = await tx\n .select({\n nextExecutionOrder: sql<number>`coalesce(max(${stepAttempts.executionOrder}), 0) + 1`,\n })\n .from(stepAttempts)\n .where(eq(stepAttempts.jobExecutionId, params.jobExecutionId));\n\n await tx\n .insert(stepAttempts)\n .values({\n jobExecutionId: params.jobExecutionId,\n stepId: params.stepId,\n attempt: params.attempt,\n executionOrder: nextExecutionOrder,\n status: 'running',\n config: params.config ?? null,\n evaluationTrace: params.evaluationTrace ?? null,\n })\n .onConflictDoNothing({target: [stepAttempts.stepId, stepAttempts.attempt]});\n}\n\nexport interface FinishStepAttemptParams {\n stepId: string;\n attempt: number;\n status: Exclude<StepAttemptStatus, 'running'>;\n error?: Record<string, unknown> | null;\n output?: Record<string, unknown> | null;\n response?: string | null;\n exitCode?: number | null;\n logOutcome: LogOutcomeDto;\n gateResult?: Record<string, unknown> | null;\n restartFeedback?: string | null;\n}\n\n// Finalize the running attempt to a terminal state. The `status='running'` guard\n// makes this idempotent: a duplicate report finds the attempt already terminal\n// and updates nothing (never-downgrade for the audit row).\nexport async function finishStepAttempt(params: FinishStepAttemptParams, tx: Tx): Promise<void> {\n const rows = await tx\n .update(stepAttempts)\n .set({\n status: params.status,\n output: params.output ?? null,\n response: params.response ?? null,\n error: params.error ?? null,\n exitCode: params.exitCode ?? null,\n logOutcome: params.logOutcome,\n gateResult: params.gateResult ?? null,\n restartFeedback: params.restartFeedback ?? null,\n finishedAt: new Date(),\n })\n .where(\n and(\n eq(stepAttempts.stepId, params.stepId),\n eq(stepAttempts.attempt, params.attempt),\n eq(stepAttempts.status, 'running'),\n ),\n )\n .returning({\n stepId: stepAttempts.stepId,\n attempt: stepAttempts.attempt,\n logOutcome: stepAttempts.logOutcome,\n });\n\n const row = rows[0];\n if (!row) return;\n\n await writeStepAttemptTerminatedOutbox(tx, {\n stepId: row.stepId,\n attempt: row.attempt,\n logOutcome: row.logOutcome ?? params.logOutcome,\n });\n}\n\nexport interface RewindStepsToPendingParams {\n jobExecutionId: string;\n fromPosition: number;\n}\n\n// Restart-only: rewind every step at or after `fromPosition` back to pending,\n// clearing its result and bumping both `version` and `current_attempt` so the next\n// dispatch opens a fresh attempt. This DELIBERATELY bypasses the never-downgrade\n// guard used everywhere else. It is the one place that resurrects terminal steps,\n// so it must only be called from the durable-restart path, never the ordinary\n// report path. It must run in the same transaction as the failed-attempt write.\nexport async function rewindStepsToPending(\n params: RewindStepsToPendingParams,\n tx: Tx,\n): Promise<void> {\n await tx\n .update(steps)\n .set({\n status: 'pending',\n statusReason: null,\n error: null,\n version: sql`${steps.version} + 1`,\n currentAttempt: sql`${steps.currentAttempt} + 1`,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.jobExecutionId, params.jobExecutionId),\n gte(steps.position, params.fromPosition),\n ),\n );\n}\n\n// Count a single step's own attempts. Used to bound the restart cap on the\n// gating step's actual executions: `steps.current_attempt` can't be used for\n// the cap because a rewind also bumps it for downstream steps swept into the\n// rewind range (which would inflate a later gate's cap in a multi-gate job).\nexport async function countStepAttempts(stepId: string, tx: Tx): Promise<number> {\n const rows = await tx\n .select({total: count()})\n .from(stepAttempts)\n .where(eq(stepAttempts.stepId, stepId));\n return Number(rows[0]?.total ?? 0);\n}\n\nexport async function getStepAttempts(jobId: string): Promise<StepAttempt[]> {\n const rows = await db()\n .select({stepAttempt: stepAttempts})\n .from(stepAttempts)\n .innerJoin(steps, eq(stepAttempts.stepId, steps.id))\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(eq(jobExecutions.jobId, jobId))\n .orderBy(asc(stepAttempts.executionOrder));\n return rows.map((row) => toStepAttempt(row.stepAttempt));\n}\n\nexport async function getStepAttemptsByJobIds(jobIds: string[]): Promise<StepAttempt[]> {\n if (jobIds.length === 0) return [];\n const rows = await db()\n .select({stepAttempt: stepAttempts, jobId: jobExecutions.jobId})\n .from(stepAttempts)\n .innerJoin(steps, eq(stepAttempts.stepId, steps.id))\n .innerJoin(jobExecutions, eq(steps.jobExecutionId, jobExecutions.id))\n .where(inArray(jobExecutions.jobId, jobIds))\n .orderBy(asc(jobExecutions.jobId), asc(stepAttempts.executionOrder));\n return rows.map((row) => toStepAttempt(row.stepAttempt));\n}\n\nexport interface ApplyStepResultParams {\n jobExecutionId: string;\n stepId: string;\n status: 'succeeded' | 'failed';\n error: Record<string, unknown> | null;\n}\n\nexport async function applyStepResult(params: ApplyStepResultParams, tx: Tx): Promise<void> {\n await tx\n .update(steps)\n .set({\n status: params.status,\n statusReason: null,\n error: params.error ?? null,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(steps.id, params.stepId),\n eq(steps.jobExecutionId, params.jobExecutionId),\n NON_TERMINAL_STEP_STATUS_FILTER,\n ),\n );\n}\n\nexport interface CancelRemainingStepsParams {\n jobExecutionId: string;\n}\n\nexport async function cancelRemainingSteps(\n params: CancelRemainingStepsParams,\n tx: Tx,\n): Promise<void> {\n await bulkUpdateStepStatuses({jobExecutionId: params.jobExecutionId, status: 'cancelled'}, tx);\n}\n"],"names":["and","asc","count","eq","gte","inArray","sql","deriveCompletion","isTerminal","db","jobExecutions","stepAttempts","toStepAttempt","steps","toStep","writeJobStepsSettledOutbox","writeStepAttemptTerminatedOutbox","NON_TERMINAL_STEP_STATUS_FILTER","getStepByIdForJobExecution","params","rows","select","from","where","id","stepId","jobExecutionId","limit","row","undefined","getStepById","getStepsByJobId","jobId","step","innerJoin","orderBy","position","map","getStepsByJobExecutionId","bulkUpdateStepStatuses","tx","transaction","update","set","status","statusReason","updatedAt","Date","finalizedAttempts","logOutcome","finishedAt","returning","attempt","length","getStepsByJobExecutionIdForUpdate","for","getStepAttemptsByJobExecutionId","executionOrder","markStepRunning","evaluationTrace","insertRunningStepAttempt","currentAttempt","config","dispatchStepWithCompletedConfig","markStepSkipped","error","settleJobFailed","applyStepResult","failedStepId","after","every","nextExecutionOrder","insert","values","onConflictDoNothing","target","finishStepAttempt","output","response","exitCode","gateResult","restartFeedback","rewindStepsToPending","version","fromPosition","countStepAttempts","total","Number","getStepAttempts","stepAttempt","getStepAttemptsByJobIds","jobIds","cancelRemainingSteps"],"mappings":"AACA,SAAQA,GAAG,EAAEC,GAAG,EAAEC,KAAK,EAAEC,EAAE,EAAEC,GAAG,EAAEC,OAAO,EAAEC,GAAG,QAAO,cAAc;AASnE,SAAQC,gBAAgB,EAAEC,UAAU,QAAO,kDAAkD;AAC7F,SAAQC,EAAE,QAAgB,WAAW;AACrC,SAAQC,aAAa,QAAO,8BAA8B;AAC1D,SAAQC,YAAY,EAAEC,aAAa,QAAO,6BAA6B;AACvE,SAAQC,KAAK,EAAEC,MAAM,QAAO,qBAAqB;AACjD,SAAQC,0BAA0B,EAAEC,gCAAgC,QAAO,cAAc;AACzF,SAAQC,+BAA+B,QAAO,cAAc;AAE5D,OAAO,eAAeC,2BAA2BC,MAGhD;IACC,MAAMC,OAAO,MAAMX,KAChBY,MAAM,GACNC,IAAI,CAACT,OACLU,KAAK,CAACvB,IAAIG,GAAGU,MAAMW,EAAE,EAAEL,OAAOM,MAAM,GAAGtB,GAAGU,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ACJvB,IACEG,GAAGU,MAAMW,EAAE,EAAEL,OAAOM,MAAM,GAC1BtB,GAAGU,MAAMa,cAAc,EAAEP,OAAOO,cAAc,GAC9CT;AAGR;AAMA,OAAO,eAAe2E,qBACpBzE,MAAkC,EAClCqB,EAAM;IAEN,MAAMD,uBAAuB;QAACb,gBAAgBP,OAAOO,cAAc;QAAEkB,QAAQ;IAAW,GAAGJ;AAC7F"}
|
|
@@ -3,10 +3,11 @@ export { failJobExecutionAsTimedOut, getFirstJobExecutionByJobId, getJobExecutio
|
|
|
3
3
|
export type { EvaluateJobActivationsParams, EvaluateJobSuccessResult, JobActivationDecision, JobScope, UpdateJobStatusAtVersionParams, UpdateJobStatusParams, } from './workflow-runs/jobs.js';
|
|
4
4
|
export { evaluateJobActivations, evaluateJobSuccess, getDirectDependencyJobContexts, getJobById, getJobScope, getJobsByWorkflowRunAttemptId, getJobsByWorkflowRunId, resolveJobStatusFromJobExecutions, updateJobStatus, updateJobStatusAtVersion, } from './workflow-runs/jobs.js';
|
|
5
5
|
export { writeJobStepsSettledOutbox, writeStepAttemptTerminatedOutbox, writeStepRestartEnqueuedOutbox, } from './workflow-runs/outbox.js';
|
|
6
|
-
export type { ListWorkflowRunsParams, ListWorkflowRunsResult, WorkflowJobExecutionDepth, WorkflowJobExecutionDepthParams, WorkflowRunAggregates, WorkflowRunCursor, WorkflowRunFilters, } from './workflow-runs/queries.js';
|
|
7
|
-
export { buildWorkflowRunListConditions, getJobExecutionDetail, getLatestAttempt, getWorkflowJobExecutionDepth, getWorkflowRunAggregates, getWorkflowRunAttemptById, getWorkflowRunByAttemptId, getWorkflowRunById, getWorkflowRunDetail, listRunAttempts, listWorkflowRuns, listWorkflowRunsByProject, } from './workflow-runs/queries.js';
|
|
6
|
+
export type { ListWorkflowRunsParams, ListWorkflowRunsResult, WorkflowJobExecutionDepth, WorkflowJobExecutionDepthParams, WorkflowRunAggregates, WorkflowRunCursor, WorkflowRunFilters, WorkflowRunJobStatusCount, WorkflowRunJobSummary, WorkflowRunJobSummaryTarget, WorkflowRunJobsSummary, } from './workflow-runs/queries.js';
|
|
7
|
+
export { buildWorkflowRunListConditions, getJobExecutionDetail, getLatestAttempt, getWorkflowJobExecutionDepth, getWorkflowRunAggregates, getWorkflowRunAttemptById, getWorkflowRunByAttemptId, getWorkflowRunById, getWorkflowRunDetail, listRunAttempts, listWorkflowRunJobSummaries, listWorkflowRuns, listWorkflowRunsByProject, } from './workflow-runs/queries.js';
|
|
8
8
|
export type { CancelWorkflowRunParams, CreateRerunWorkflowRunParams, CreateWorkflowRunParams, FailWorkflowRunAsTimedOutParams, UpdateWorkflowRunStatusParams, } from './workflow-runs/runs.js';
|
|
9
|
-
export { cancelWorkflowRun, createRerunWorkflowRun, createWorkflowRun, failWorkflowRunAsTimedOut, updateWorkflowRunStatus, } from './workflow-runs/runs.js';
|
|
9
|
+
export { cancelWorkflowRun, createRerunWorkflowRun, createWorkflowRun, failWorkflowRunAsTimedOut, loadReferencedVariables, updateWorkflowRunStatus, } from './workflow-runs/runs.js';
|
|
10
|
+
export { getWorkflowContextForJob } from './workflow-runs/shared.js';
|
|
10
11
|
export type { ApplyStepResultParams, BulkUpdateStepStatusesParams, CancelRemainingStepsParams, DispatchStepWithCompletedConfigParams, FinishStepAttemptParams, InsertRunningStepAttemptParams, MarkStepRunningParams, MarkStepSkippedParams, RewindStepsToPendingParams, } from './workflow-runs/steps.js';
|
|
11
12
|
export { applyStepResult, bulkUpdateStepStatuses, cancelRemainingSteps, countStepAttempts, dispatchStepWithCompletedConfig, finishStepAttempt, getStepAttempts, getStepAttemptsByJobExecutionId, getStepAttemptsByJobIds, getStepById, getStepByIdForJobExecution, getStepsByJobExecutionId, getStepsByJobExecutionIdForUpdate, getStepsByJobId, insertRunningStepAttempt, markStepRunning, markStepSkipped, rewindStepsToPending, settleJobFailed, } from './workflow-runs/steps.js';
|
|
12
13
|
//# sourceMappingURL=workflow-runs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-runs.d.ts","sourceRoot":"","sources":["../../src/db/workflow-runs.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,8BAA8B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,sCAAsC,EACtC,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,mCAAmC,EACnC,wBAAwB,GACzB,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EACrB,QAAQ,EACR,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,8BAA8B,EAC9B,UAAU,EACV,WAAW,EACX,6BAA6B,EAC7B,sBAAsB,EACtB,iCAAiC,EACjC,eAAe,EACf,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,+BAA+B,EAC/B,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"workflow-runs.d.ts","sourceRoot":"","sources":["../../src/db/workflow-runs.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,8BAA8B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,sCAAsC,EACtC,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,mCAAmC,EACnC,wBAAwB,GACzB,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EAC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EACf,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,+BAA+B,EAC/B,iBAAiB,EACjB,eAAe,EACf,+BAA+B,EAC/B,uBAAuB,EACvB,WAAW,EACX,0BAA0B,EAC1B,wBAAwB,EACxB,iCAAiC,EACjC,eAAe,EACf,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,eAAe,GAChB,MAAM,0BAA0B,CAAC"}
|
package/dist/db/workflow-runs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { failJobExecutionAsTimedOut, getFirstJobExecutionByJobId, getJobExecutionById, getJobExecutionsByJobId, getJobExecutionsByWorkflowRunAttemptId, getLatestJobExecutionByJobId, recordJobExecutionQueuedAt, recordJobExecutionStartedAt, resolveJobExecutionAfterLeaseExpiry, updateJobExecutionStatus } from './workflow-runs/job-executions.js';
|
|
2
2
|
export { evaluateJobActivations, evaluateJobSuccess, getDirectDependencyJobContexts, getJobById, getJobScope, getJobsByWorkflowRunAttemptId, getJobsByWorkflowRunId, resolveJobStatusFromJobExecutions, updateJobStatus, updateJobStatusAtVersion } from './workflow-runs/jobs.js';
|
|
3
3
|
export { writeJobStepsSettledOutbox, writeStepAttemptTerminatedOutbox, writeStepRestartEnqueuedOutbox } from './workflow-runs/outbox.js';
|
|
4
|
-
export { buildWorkflowRunListConditions, getJobExecutionDetail, getLatestAttempt, getWorkflowJobExecutionDepth, getWorkflowRunAggregates, getWorkflowRunAttemptById, getWorkflowRunByAttemptId, getWorkflowRunById, getWorkflowRunDetail, listRunAttempts, listWorkflowRuns, listWorkflowRunsByProject } from './workflow-runs/queries.js';
|
|
5
|
-
export { cancelWorkflowRun, createRerunWorkflowRun, createWorkflowRun, failWorkflowRunAsTimedOut, updateWorkflowRunStatus } from './workflow-runs/runs.js';
|
|
4
|
+
export { buildWorkflowRunListConditions, getJobExecutionDetail, getLatestAttempt, getWorkflowJobExecutionDepth, getWorkflowRunAggregates, getWorkflowRunAttemptById, getWorkflowRunByAttemptId, getWorkflowRunById, getWorkflowRunDetail, listRunAttempts, listWorkflowRunJobSummaries, listWorkflowRuns, listWorkflowRunsByProject } from './workflow-runs/queries.js';
|
|
5
|
+
export { cancelWorkflowRun, createRerunWorkflowRun, createWorkflowRun, failWorkflowRunAsTimedOut, loadReferencedVariables, updateWorkflowRunStatus } from './workflow-runs/runs.js';
|
|
6
|
+
export { getWorkflowContextForJob } from './workflow-runs/shared.js';
|
|
6
7
|
export { applyStepResult, bulkUpdateStepStatuses, cancelRemainingSteps, countStepAttempts, dispatchStepWithCompletedConfig, finishStepAttempt, getStepAttempts, getStepAttemptsByJobExecutionId, getStepAttemptsByJobIds, getStepById, getStepByIdForJobExecution, getStepsByJobExecutionId, getStepsByJobExecutionIdForUpdate, getStepsByJobId, insertRunningStepAttempt, markStepRunning, markStepSkipped, rewindStepsToPending, settleJobFailed } from './workflow-runs/steps.js';
|
|
7
8
|
|
|
8
9
|
//# sourceMappingURL=workflow-runs.js.map
|