@leitwerk-dev/server 0.3.1 → 0.4.1
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/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
- package/dist/app-KR3N2JAE.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-QCHS3X33.js → chunk-OUA5EZS2.js} +3127 -689
- package/dist/chunk-OUA5EZS2.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
- package/dist/chunk-YLWY4UTT.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +16 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/dashboard-model-issues.d.ts +10 -0
- package/dist/dashboard-model-issues.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- package/dist/db/process-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +21 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +4 -0
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- package/dist/db/repositories.d.ts +12 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +693 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +10 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/domain-logic/worker-lease-lifecycle.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +1 -6
- package/dist/process-action-presenter.d.ts.map +1 -1
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/mapped-turns.d.ts.map +1 -1
- package/dist/process-engine/ops/automatic-retry-startup.d.ts +8 -0
- package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
- package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts +2 -0
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +13 -2
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +2 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/writes.d.ts +28 -60
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-availability-recovery.d.ts +1 -1
- package/dist/process-model-availability-recovery.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +14 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/dashboard.d.ts +17 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.d.ts.map +1 -1
- package/dist/routes/process-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-route-helpers.d.ts +8 -9
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +98 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +7 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +4 -3
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/startup-retry-policy.d.ts +8 -0
- package/dist/startup-retry-policy.d.ts.map +1 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.js +2 -1
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +177 -25
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +42 -2
- package/src/config/config-types.ts +16 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/dashboard-model-issues.ts +199 -0
- package/src/db/database.ts +131 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +33 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +45 -12
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repositories.ts +17 -0
- package/src/db/schema.ts +103 -1
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +13 -3
- package/src/db/turn-summary-repo.ts +36 -4
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +18 -216
- package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +7 -8
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +22 -57
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +25 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- package/src/process-engine/ops/automatic-retry-startup.ts +93 -0
- package/src/process-engine/ops/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +20 -16
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +61 -60
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +34 -5
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +21 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
- package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
- package/src/process-engine/writes/commit-writes.ts +16 -4
- package/src/process-engine/writes/writes.ts +59 -74
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-availability-recovery.ts +6 -4
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +210 -295
- package/src/routes/dashboard.ts +106 -0
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +10 -10
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-route-helpers.ts +153 -162
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +797 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +12 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +94 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +19 -6
- package/src/skills/source-importer.ts +7 -13
- package/src/startup-evidence.ts +29 -8
- package/src/startup-retry-policy.ts +106 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +2 -0
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +17 -0
- package/src/supervisor/worker-supervisor.ts +26 -1
- package/src/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -1
- package/dist/app-MSJXFK33.js +0 -8
- package/dist/chunk-HK6BLLHA.js.map +0 -1
- package/dist/chunk-QCHS3X33.js.map +0 -1
- /package/dist/{app-MSJXFK33.js.map → app-KR3N2JAE.js.map} +0 -0
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
maybeBroadcastErrorAttentionToast as maybeBroadcastErrorAttentionToastCore,
|
|
4
4
|
} from "../process-attention-notifier.js";
|
|
5
5
|
import { broadcastProcessAttentionToast } from "../process-operator-attention.js";
|
|
6
|
+
import { automaticStartupRecovery, startupRetryState } from "../startup-retry-policy.js";
|
|
7
|
+
import { AutomaticRetryStartup } from "./ops/automatic-retry-startup.js";
|
|
6
8
|
import {
|
|
7
9
|
AbortProcess,
|
|
8
10
|
AbortTurn,
|
|
@@ -22,7 +24,10 @@ import {
|
|
|
22
24
|
UpdateSemanticRefs,
|
|
23
25
|
WorkerFailure,
|
|
24
26
|
} from "./ops/index.js";
|
|
27
|
+
import { ApplyProcessObservation } from "./ops/process-observation.js";
|
|
28
|
+
import { RetryTurnWait } from "./ops/turn-wait.js";
|
|
25
29
|
import { createEngineRunner } from "./runner.js";
|
|
30
|
+
import { pendingTurnWait } from "./turn-wait-state.js";
|
|
26
31
|
import type {
|
|
27
32
|
ActionExecutionResult,
|
|
28
33
|
EngineResult,
|
|
@@ -92,6 +97,9 @@ export function createProcessEngine(deps: ProcessEngineDeps): ProcessEngine {
|
|
|
92
97
|
|
|
93
98
|
engine = {
|
|
94
99
|
run,
|
|
100
|
+
applyProcessObservation(instanceId, input) {
|
|
101
|
+
return run(ApplyProcessObservation, { instanceId, ...input });
|
|
102
|
+
},
|
|
95
103
|
|
|
96
104
|
getDeferredProcessActivationSnapshots({ instanceId, processId, projectKey }) {
|
|
97
105
|
const processes = instanceId
|
|
@@ -134,7 +142,7 @@ export function createProcessEngine(deps: ProcessEngineDeps): ProcessEngine {
|
|
|
134
142
|
},
|
|
135
143
|
|
|
136
144
|
startProcess(instanceId, startTurnId, opts) {
|
|
137
|
-
return run(StartProcess, { instanceId, startTurnId,
|
|
145
|
+
return run(StartProcess, { instanceId, startTurnId, ...opts });
|
|
138
146
|
},
|
|
139
147
|
|
|
140
148
|
abortProcess(instanceId, opts) {
|
|
@@ -150,7 +158,10 @@ export function createProcessEngine(deps: ProcessEngineDeps): ProcessEngine {
|
|
|
150
158
|
},
|
|
151
159
|
|
|
152
160
|
async retryProcess(instanceId, opts) {
|
|
153
|
-
const
|
|
161
|
+
const process = deps.processes.getById(instanceId);
|
|
162
|
+
if (process && pendingTurnWait(process)?.status === "error")
|
|
163
|
+
return run(RetryTurnWait, { instanceId, ...opts });
|
|
164
|
+
const current = process?.currentExecution;
|
|
154
165
|
const start = current?.kind === "worker_start" ? deps.turnStarts.getById(current.id) : null;
|
|
155
166
|
if (start?.state.kind === "preparation_failed" || start?.state.kind === "bootstrap_failed") {
|
|
156
167
|
// RetryStartup fences this ID and lifecycle state under the process lock.
|
|
@@ -168,6 +179,18 @@ export function createProcessEngine(deps: ProcessEngineDeps): ProcessEngine {
|
|
|
168
179
|
retryStartup(instanceId, startRecordId, opts) {
|
|
169
180
|
return run(RetryStartup, { instanceId, startRecordId, ...(opts ?? {}) });
|
|
170
181
|
},
|
|
182
|
+
async retryStartupAutomatically(instanceId, startRecordId, opts) {
|
|
183
|
+
const result = await run(AutomaticRetryStartup, { instanceId, startRecordId, ...opts });
|
|
184
|
+
if (!result.ok || result.data.status !== "retried") return result;
|
|
185
|
+
const current = deps.processes.getById(instanceId)?.currentExecution;
|
|
186
|
+
const start = current?.kind === "worker_start" ? deps.turnStarts.getById(current.id) : null;
|
|
187
|
+
if (
|
|
188
|
+
start &&
|
|
189
|
+
(start.state.kind === "preparation_failed" || start.state.kind === "bootstrap_failed")
|
|
190
|
+
)
|
|
191
|
+
return { ...result, data: automaticStartupRecovery(start, startupRetryState(start, [])) };
|
|
192
|
+
return result;
|
|
193
|
+
},
|
|
171
194
|
|
|
172
195
|
continueFailedTurn(instanceId, turnRecordId, options) {
|
|
173
196
|
return run(ContinueFailedTurn, { instanceId, turnRecordId, options });
|
|
@@ -16,6 +16,7 @@ import { generateId } from "../db/repo-helpers.js";
|
|
|
16
16
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
17
17
|
import type { ProcessActionRegistry } from "../process-action-registry.js";
|
|
18
18
|
import type { ProcessGraphRegistry } from "../process-graph.js";
|
|
19
|
+
import { deferTurnWaitStarts } from "./turn-wait-state.js";
|
|
19
20
|
import { buildServerTransitionWrites } from "./writes/build-server-transition-writes.js";
|
|
20
21
|
import { reserveSelectedTurnStart } from "./writes/reserve-selected-turn-start.js";
|
|
21
22
|
import {
|
|
@@ -129,6 +130,8 @@ export async function planMappedTurnEntries(input: {
|
|
|
129
130
|
const active = input.mappedRuns?.getActiveByInstance(input.process.id) ?? null;
|
|
130
131
|
let activeAborted = false;
|
|
131
132
|
for (let entry = 0; entry <= MAX_EMPTY_MAPPED_ENTRIES; entry += 1) {
|
|
133
|
+
// An empty mapped run may route straight into another gated turn.
|
|
134
|
+
deferTurnWaitStarts(input.processGraphs, input.process, writes);
|
|
132
135
|
const candidate: ProcessInstance = { ...input.process, ...writes.processPatch };
|
|
133
136
|
const startIndex = writes.turnStartWrites.findIndex(
|
|
134
137
|
(write) =>
|
|
@@ -181,12 +184,7 @@ export async function planMappedTurnEntries(input: {
|
|
|
181
184
|
instanceId: input.process.id,
|
|
182
185
|
turnId,
|
|
183
186
|
status: frozen.items.length > 0 ? "active" : "completed",
|
|
184
|
-
items: frozen.items
|
|
185
|
-
itemIndex: item.index,
|
|
186
|
-
itemKey: item.key,
|
|
187
|
-
label: item.label,
|
|
188
|
-
itemJson: item.itemJson,
|
|
189
|
-
})),
|
|
187
|
+
items: frozen.items,
|
|
190
188
|
},
|
|
191
189
|
});
|
|
192
190
|
appendProcessEvent(writes, candidate, {
|
|
@@ -201,7 +199,7 @@ export async function planMappedTurnEntries(input: {
|
|
|
201
199
|
}
|
|
202
200
|
const first = frozen.items[0];
|
|
203
201
|
if (first) {
|
|
204
|
-
start.input.iteration = { runId, itemKey: first.
|
|
202
|
+
start.input.iteration = { runId, itemKey: first.itemKey, itemIndex: 0 };
|
|
205
203
|
return { ok: true };
|
|
206
204
|
}
|
|
207
205
|
writes.turnStartWrites.splice(startIndex, 1);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { AutomaticStartupRecoverySummary } from "@leitwerk-dev/domain";
|
|
2
|
+
import { automaticStartupRecovery, startupRetryState } from "../../startup-retry-policy.js";
|
|
3
|
+
import { accept, reject } from "../decision.js";
|
|
4
|
+
import { defineOperation } from "../operation.js";
|
|
5
|
+
import { RetryStartup } from "./retry-startup.js";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const AutomaticRetryStartup = defineOperation<
|
|
9
|
+
"automatic_retry_startup",
|
|
10
|
+
{
|
|
11
|
+
instanceId: string;
|
|
12
|
+
startRecordId: string;
|
|
13
|
+
availabilityCause?: "availability_transition" | "startup_reconciliation";
|
|
14
|
+
},
|
|
15
|
+
AutomaticStartupRecoverySummary
|
|
16
|
+
>({
|
|
17
|
+
kind: "automatic_retry_startup",
|
|
18
|
+
label: "Automatic startup recovery",
|
|
19
|
+
admission: "new_turn",
|
|
20
|
+
async decide(ctx, input) {
|
|
21
|
+
if (
|
|
22
|
+
ctx.process.lifecycleStatus !== "error" ||
|
|
23
|
+
ctx.process.currentExecution?.kind !== "worker_start" ||
|
|
24
|
+
ctx.process.currentExecution.id !== input.startRecordId
|
|
25
|
+
)
|
|
26
|
+
return reject("stale_turn_start", "Startup recovery target is no longer current");
|
|
27
|
+
const start = ctx.deps.turnStarts.getById(input.startRecordId);
|
|
28
|
+
if (
|
|
29
|
+
!start ||
|
|
30
|
+
(start.state.kind !== "preparation_failed" && start.state.kind !== "bootstrap_failed")
|
|
31
|
+
)
|
|
32
|
+
return reject(
|
|
33
|
+
"retry_target_missing",
|
|
34
|
+
"Automatic recovery requires an unaccepted failed start",
|
|
35
|
+
);
|
|
36
|
+
const retry =
|
|
37
|
+
start.state.automaticRetry ??
|
|
38
|
+
startupRetryState(
|
|
39
|
+
start,
|
|
40
|
+
ctx.deps.turnStarts.listByInstance(ctx.process.id),
|
|
41
|
+
ctx.deps.events.listByInstanceEventTypes(ctx.process.id, ["startup_retry_scheduled"], -1),
|
|
42
|
+
);
|
|
43
|
+
let modelRestored = false;
|
|
44
|
+
if (input.availabilityCause && start.state.kind === "preparation_failed") {
|
|
45
|
+
const evaluation = ctx.deps.processModelPolicy.evaluate({
|
|
46
|
+
kind: "preparation_recovery",
|
|
47
|
+
cause: input.availabilityCause,
|
|
48
|
+
process: ctx.process,
|
|
49
|
+
currentStart: start,
|
|
50
|
+
availability: ctx.deps.getModelAvailabilitySnapshot(),
|
|
51
|
+
});
|
|
52
|
+
modelRestored = evaluation.ok && evaluation.selection !== null;
|
|
53
|
+
}
|
|
54
|
+
const summary = automaticStartupRecovery(start, retry, Date.now(), modelRestored);
|
|
55
|
+
if (summary.status !== "ready") {
|
|
56
|
+
if (start.state.automaticRetry && retry.nextRetryAt === summary.nextRetryAt)
|
|
57
|
+
return accept({ data: summary });
|
|
58
|
+
const metadata = { ...retry, nextRetryAt: summary.nextRetryAt };
|
|
59
|
+
return accept({
|
|
60
|
+
data: summary,
|
|
61
|
+
writes: {
|
|
62
|
+
turnStartWrites: [
|
|
63
|
+
{
|
|
64
|
+
kind: "cas_state",
|
|
65
|
+
id: start.id,
|
|
66
|
+
expectedKind: start.state.kind,
|
|
67
|
+
state: { ...start.state, automaticRetry: metadata },
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
// Refresh the recovery projection only when retained metadata changes.
|
|
71
|
+
processPatch: { currentExecution: ctx.process.currentExecution },
|
|
72
|
+
changedFields: ["currentExecution"],
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const decision = await RetryStartup.decide(ctx, {
|
|
77
|
+
...input,
|
|
78
|
+
automaticRetry: { ...retry, starts: retry.starts + 1, nextRetryAt: null },
|
|
79
|
+
});
|
|
80
|
+
if (!decision.ok) return reject(decision.code, decision.message);
|
|
81
|
+
return accept({
|
|
82
|
+
writes: decision.writes,
|
|
83
|
+
metadata: decision.metadata,
|
|
84
|
+
data: {
|
|
85
|
+
...summary,
|
|
86
|
+
starts: retry.starts + 1,
|
|
87
|
+
status: "retried",
|
|
88
|
+
nextRetryAt: null,
|
|
89
|
+
reason: "Worker startup retry requested.",
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveTurnContinuationUserPrompt,
|
|
10
10
|
} from "@leitwerk-dev/protocol";
|
|
11
11
|
import type { ReadonlyPiSessionTree } from "../../pi-session-tree.js";
|
|
12
|
-
import { accept, reject } from "../decision.js";
|
|
12
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
13
13
|
import { defineOperation } from "../operation.js";
|
|
14
14
|
import { readCurrentPrimaryPathLeafEntryId } from "../state-json.js";
|
|
15
15
|
import type { ProcessEngine, ProcessEngineDeps } from "../types.js";
|
|
@@ -138,18 +138,7 @@ export const ContinueFailedTurn = defineOperation<
|
|
|
138
138
|
stampActorOnEvents(writes, input.options?.actor, "continue_scheduled");
|
|
139
139
|
return accept({
|
|
140
140
|
writes,
|
|
141
|
-
metadata:
|
|
142
|
-
input.options?.nextTurnModelProfileId !== undefined ||
|
|
143
|
-
input.options?.providerOptions !== undefined
|
|
144
|
-
? {
|
|
145
|
-
...(input.options.nextTurnModelProfileId !== undefined
|
|
146
|
-
? { nextTurnModelProfileId: input.options.nextTurnModelProfileId }
|
|
147
|
-
: {}),
|
|
148
|
-
...(input.options.providerOptions !== undefined
|
|
149
|
-
? { providerOptions: input.options.providerOptions }
|
|
150
|
-
: {}),
|
|
151
|
-
}
|
|
152
|
-
: undefined,
|
|
141
|
+
metadata: modelOverrideMetadata(input.options),
|
|
153
142
|
});
|
|
154
143
|
},
|
|
155
144
|
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ProcessObservationUpdate } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { planCancelScheduledAction } from "../../future-execution/transition-planner.js";
|
|
3
|
+
import { resolveCurrentExecutionTurnRecordId } from "../../process-execution.js";
|
|
4
|
+
import { accept, reject } from "../decision.js";
|
|
5
|
+
import { defineOperation } from "../operation.js";
|
|
6
|
+
import { writeTurnWait } from "../turn-wait-state.js";
|
|
7
|
+
import { supersedeExecution } from "../writes/build-process-abort-writes.js";
|
|
8
|
+
import { reserveSelectedTurnStart } from "../writes/reserve-selected-turn-start.js";
|
|
9
|
+
import {
|
|
10
|
+
appendProcessEvent,
|
|
11
|
+
applyMetadataPatch,
|
|
12
|
+
applyProcessPatchField,
|
|
13
|
+
createWrites,
|
|
14
|
+
} from "../writes/writes.js";
|
|
15
|
+
|
|
16
|
+
/** Background reads happen outside the process lock; their writes never bypass coordination. @internal */
|
|
17
|
+
export const ApplyProcessObservation = defineOperation<
|
|
18
|
+
"process_observation",
|
|
19
|
+
ProcessObservationUpdate & { instanceId: string },
|
|
20
|
+
void
|
|
21
|
+
>({
|
|
22
|
+
kind: "process_observation",
|
|
23
|
+
label: "Record integration observation",
|
|
24
|
+
decide({ process, deps }, input) {
|
|
25
|
+
const expected = input.expected;
|
|
26
|
+
if (
|
|
27
|
+
expected.id !== process.id ||
|
|
28
|
+
expected.processId !== process.processId ||
|
|
29
|
+
expected.planRevision !== process.planRevision ||
|
|
30
|
+
expected.paramsJson !== process.paramsJson ||
|
|
31
|
+
expected.stateJson !== process.stateJson ||
|
|
32
|
+
expected.selectedTurnId !== process.selectedTurnId ||
|
|
33
|
+
expected.lifecycleStatus !== process.lifecycleStatus ||
|
|
34
|
+
JSON.stringify(expected.currentExecution) !== JSON.stringify(process.currentExecution) ||
|
|
35
|
+
Object.keys(input.metadata ?? {}).some(
|
|
36
|
+
(key) =>
|
|
37
|
+
JSON.stringify(expected.metadata?.[key]) !== JSON.stringify(process.metadata?.[key]),
|
|
38
|
+
) ||
|
|
39
|
+
(input.projectsJson !== undefined &&
|
|
40
|
+
input.projectsJson !== JSON.stringify(deps.projects.listByInstance(process.id)))
|
|
41
|
+
)
|
|
42
|
+
return reject("observation_superseded", "The process changed during the integration read");
|
|
43
|
+
const definition = deps.processGraphs.get(process.processId);
|
|
44
|
+
if (!definition) return reject("process_not_found", "Process definition is unavailable");
|
|
45
|
+
const writes = createWrites({ preserveUpdatedAt: input.preserveUpdatedAt });
|
|
46
|
+
if (input.state !== undefined) {
|
|
47
|
+
const state = definition.stateCodec.parse(input.state);
|
|
48
|
+
applyProcessPatchField(
|
|
49
|
+
writes,
|
|
50
|
+
process,
|
|
51
|
+
"stateJson",
|
|
52
|
+
JSON.stringify(definition.stateCodec.serialize(state)),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (input.metadata)
|
|
56
|
+
applyMetadataPatch(writes, process, { ...process.metadata, ...input.metadata });
|
|
57
|
+
if (input.lifecycleStatus || input.interrupt) {
|
|
58
|
+
if (["completed", "aborted"].includes(process.lifecycleStatus))
|
|
59
|
+
return reject("invalid_transition", "Terminal processes cannot resume maintenance");
|
|
60
|
+
if (input.interrupt && !definition.turns.has(input.interrupt.turnId))
|
|
61
|
+
return reject("invalid_transition", "Maintenance recovery turn is unavailable");
|
|
62
|
+
const recordId = resolveCurrentExecutionTurnRecordId(process, deps.turnStarts);
|
|
63
|
+
const record = recordId ? deps.turnRecords.getById(recordId) : null;
|
|
64
|
+
const start =
|
|
65
|
+
process.currentExecution?.kind === "worker_start"
|
|
66
|
+
? deps.turnStarts.getById(process.currentExecution.id)
|
|
67
|
+
: null;
|
|
68
|
+
supersedeExecution(writes, record, start);
|
|
69
|
+
for (const execution of deps.futureExecutions.listByInstance(process.id)) {
|
|
70
|
+
const plan = planCancelScheduledAction(execution, process.id);
|
|
71
|
+
if (plan) writes.futureExecutionPlans.push(plan);
|
|
72
|
+
}
|
|
73
|
+
writeTurnWait(
|
|
74
|
+
writes,
|
|
75
|
+
{ ...process, metadata: writes.processPatch.metadata ?? process.metadata },
|
|
76
|
+
null,
|
|
77
|
+
);
|
|
78
|
+
applyProcessPatchField(writes, process, "currentExecution", null);
|
|
79
|
+
applyProcessPatchField(
|
|
80
|
+
writes,
|
|
81
|
+
process,
|
|
82
|
+
"selectedTurnId",
|
|
83
|
+
input.lifecycleStatus ? null : (input.interrupt?.turnId ?? process.selectedTurnId),
|
|
84
|
+
);
|
|
85
|
+
applyProcessPatchField(
|
|
86
|
+
writes,
|
|
87
|
+
process,
|
|
88
|
+
"lifecycleStatus",
|
|
89
|
+
input.lifecycleStatus ?? "waiting",
|
|
90
|
+
);
|
|
91
|
+
if (input.interrupt && !input.lifecycleStatus) {
|
|
92
|
+
const turn = definition.turns.get(input.interrupt.turnId)?.definition;
|
|
93
|
+
if (!turn || (turn.kind !== "llm" && turn.kind !== "automatic") || !turn.waitFor)
|
|
94
|
+
return reject(
|
|
95
|
+
"invalid_transition",
|
|
96
|
+
"Maintenance recovery requires an existing gated worker turn",
|
|
97
|
+
);
|
|
98
|
+
reserveSelectedTurnStart(
|
|
99
|
+
writes,
|
|
100
|
+
{ ...process, ...writes.processPatch },
|
|
101
|
+
input.interrupt.turnId,
|
|
102
|
+
turn.kind,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
writes.workerIntent = {
|
|
106
|
+
kind: "stop_with_reason",
|
|
107
|
+
reason: input.interrupt?.reason ?? "MR maintenance finished",
|
|
108
|
+
};
|
|
109
|
+
appendProcessEvent(writes, process, {
|
|
110
|
+
eventType: input.lifecycleStatus
|
|
111
|
+
? `process_${input.lifecycleStatus}`
|
|
112
|
+
: "maintenance_interrupted",
|
|
113
|
+
level: "info",
|
|
114
|
+
message: input.interrupt?.reason ?? "MR maintenance finished",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return accept({ writes });
|
|
118
|
+
},
|
|
119
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
2
|
import { buildRetryWrites } from "../../process-engine/writes/build-retry-writes.js";
|
|
3
3
|
import { stampActorOnEvents } from "../../process-engine/writes/writes.js";
|
|
4
|
-
import { accept, reject } from "../decision.js";
|
|
4
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
5
5
|
import { defineOperation } from "../operation.js";
|
|
6
6
|
|
|
7
7
|
export interface RetryFailedTurnInput {
|
|
@@ -49,17 +49,7 @@ export const RetryFailedTurn = defineOperation<"retry_failed_turn", RetryFailedT
|
|
|
49
49
|
stampActorOnEvents(writes, input.actor, "retry_scheduled");
|
|
50
50
|
return accept({
|
|
51
51
|
writes,
|
|
52
|
-
metadata:
|
|
53
|
-
input.nextTurnModelProfileId !== undefined || input.providerOptions !== undefined
|
|
54
|
-
? {
|
|
55
|
-
...(input.nextTurnModelProfileId !== undefined
|
|
56
|
-
? { nextTurnModelProfileId: input.nextTurnModelProfileId }
|
|
57
|
-
: {}),
|
|
58
|
-
...(input.providerOptions !== undefined
|
|
59
|
-
? { providerOptions: input.providerOptions }
|
|
60
|
-
: {}),
|
|
61
|
-
}
|
|
62
|
-
: undefined,
|
|
52
|
+
metadata: modelOverrideMetadata(input),
|
|
63
53
|
});
|
|
64
54
|
},
|
|
65
55
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Actor } from "@leitwerk-dev/domain";
|
|
1
|
+
import type { Actor, TurnStartRecordState } from "@leitwerk-dev/domain";
|
|
2
2
|
import { generateId } from "../../db/repo-helpers.js";
|
|
3
|
-
import { accept, reject } from "../decision.js";
|
|
3
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
4
4
|
import { defineOperation } from "../operation.js";
|
|
5
5
|
import {
|
|
6
6
|
appendProcessEvent,
|
|
@@ -15,6 +15,8 @@ export interface RetryStartupInput {
|
|
|
15
15
|
nextTurnModelProfileId?: string | null;
|
|
16
16
|
providerOptions?: Readonly<Record<string, string>>;
|
|
17
17
|
actor?: Actor;
|
|
18
|
+
/** Only the server's automatic recovery operation supplies inherited counters. */
|
|
19
|
+
automaticRetry?: import("@leitwerk-dev/domain").StartupRetryState;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/** Replaces only the current failed worker start; it never creates a turn attempt. */
|
|
@@ -42,9 +44,15 @@ export const RetryStartup = defineOperation<
|
|
|
42
44
|
return reject("retry_target_missing", "Startup retry requires a failed current start");
|
|
43
45
|
}
|
|
44
46
|
const id = generateId("tsr");
|
|
45
|
-
const state =
|
|
47
|
+
const state: TurnStartRecordState =
|
|
46
48
|
failed.state.kind === "preparation_failed"
|
|
47
|
-
?
|
|
49
|
+
? {
|
|
50
|
+
...failed.state,
|
|
51
|
+
// A new operator retry must validate current inputs; the previous
|
|
52
|
+
// failure remains on its original start record.
|
|
53
|
+
code: "model_required" as const,
|
|
54
|
+
safeSummary: "LLM start requires retry preparation",
|
|
55
|
+
}
|
|
48
56
|
: failed.state.start.kind === "automatic"
|
|
49
57
|
? { kind: "starting" as const, start: failed.state.start }
|
|
50
58
|
: {
|
|
@@ -57,6 +65,7 @@ export const RetryStartup = defineOperation<
|
|
|
57
65
|
? { modelSelectionProvenance: failed.state.start.modelSelectionProvenance }
|
|
58
66
|
: {}),
|
|
59
67
|
};
|
|
68
|
+
state.automaticRetry = input.automaticRetry;
|
|
60
69
|
const writes = createWrites({
|
|
61
70
|
workerIntent: state.kind === "starting" ? { kind: "restart_worker" } : undefined,
|
|
62
71
|
});
|
|
@@ -86,23 +95,18 @@ export const RetryStartup = defineOperation<
|
|
|
86
95
|
eventType: "startup_retry_scheduled",
|
|
87
96
|
level: "info",
|
|
88
97
|
message: "Startup retry scheduled",
|
|
89
|
-
data: {
|
|
98
|
+
data: {
|
|
99
|
+
previousStartRecordId: failed.id,
|
|
100
|
+
startRecordId: id,
|
|
101
|
+
state: state.kind,
|
|
102
|
+
retrySource: input.automaticRetry ? "automatic" : "manual",
|
|
103
|
+
},
|
|
90
104
|
});
|
|
91
105
|
stampActorOnEvents(writes, input.actor, "startup_retry_scheduled");
|
|
92
106
|
return accept({
|
|
93
107
|
writes,
|
|
94
108
|
data: { startRecordId: id },
|
|
95
|
-
metadata:
|
|
96
|
-
input.nextTurnModelProfileId !== undefined || input.providerOptions !== undefined
|
|
97
|
-
? {
|
|
98
|
-
...(input.nextTurnModelProfileId !== undefined
|
|
99
|
-
? { nextTurnModelProfileId: input.nextTurnModelProfileId }
|
|
100
|
-
: {}),
|
|
101
|
-
...(input.providerOptions !== undefined
|
|
102
|
-
? { providerOptions: input.providerOptions }
|
|
103
|
-
: {}),
|
|
104
|
-
}
|
|
105
|
-
: undefined,
|
|
109
|
+
metadata: modelOverrideMetadata(input),
|
|
106
110
|
});
|
|
107
111
|
},
|
|
108
112
|
});
|
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
import type { Actor, TurnId } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { WaitingProcessRestart } from "@leitwerk-dev/process-sdk";
|
|
2
3
|
import { buildTurnSelectionWrites } from "../../process-engine/writes/build-turn-selection-writes.js";
|
|
3
|
-
import { accept, noWrites } from "../decision.js";
|
|
4
|
+
import { accept, noWrites, reject } from "../decision.js";
|
|
4
5
|
import { defineOperation } from "../operation.js";
|
|
5
|
-
import { stampActorOnEvents } from "../writes/writes.js";
|
|
6
|
+
import { applyProcessPatchField, stampActorOnEvents } from "../writes/writes.js";
|
|
6
7
|
|
|
7
8
|
export interface StartProcessInput {
|
|
8
9
|
instanceId: string;
|
|
9
10
|
startTurnId: TurnId;
|
|
10
11
|
actor?: Actor;
|
|
11
12
|
onlyIfUnstarted?: boolean;
|
|
13
|
+
restart?: WaitingProcessRestart;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export const StartProcess = defineOperation<"start_process", StartProcessInput, void>({
|
|
15
17
|
kind: "start_process",
|
|
16
18
|
label: "Start process",
|
|
17
19
|
decide(ctx, input) {
|
|
20
|
+
const restart = input.restart;
|
|
21
|
+
if (
|
|
22
|
+
restart &&
|
|
23
|
+
(ctx.process.lifecycleStatus !== "waiting" ||
|
|
24
|
+
ctx.process.currentExecution !== null ||
|
|
25
|
+
ctx.process.selectedTurnId !== restart.expected.turnId ||
|
|
26
|
+
ctx.process.paramsJson !== restart.expected.paramsJson ||
|
|
27
|
+
ctx.process.stateJson !== restart.expected.stateJson)
|
|
28
|
+
) {
|
|
29
|
+
return reject("restart_superseded", "The captured waiting process has changed");
|
|
30
|
+
}
|
|
31
|
+
if (restart && ctx.deps.isNewTurnBlocked?.(input.instanceId)) {
|
|
32
|
+
return reject("session_transfer_in_progress", "A local session transfer is in progress");
|
|
33
|
+
}
|
|
34
|
+
const project = restart?.project
|
|
35
|
+
? ctx.deps.projects.getByInstanceAndKey(input.instanceId, restart.project.key)
|
|
36
|
+
: null;
|
|
37
|
+
if (
|
|
38
|
+
restart?.project &&
|
|
39
|
+
(!project || project.baseBranch !== restart.project.expectedBaseBranch)
|
|
40
|
+
) {
|
|
41
|
+
return reject("restart_superseded", "The captured process repository has changed");
|
|
42
|
+
}
|
|
43
|
+
if (restart) JSON.parse(restart.stateJson);
|
|
18
44
|
if (
|
|
19
45
|
input.onlyIfUnstarted &&
|
|
20
46
|
(ctx.process.lifecycleStatus !== "discovered" ||
|
|
@@ -29,6 +55,12 @@ export const StartProcess = defineOperation<"start_process", StartProcessInput,
|
|
|
29
55
|
trigger: "start",
|
|
30
56
|
});
|
|
31
57
|
if ("ok" in writes) return writes;
|
|
58
|
+
if (restart) {
|
|
59
|
+
applyProcessPatchField(writes, ctx.process, "stateJson", restart.stateJson);
|
|
60
|
+
if (project && restart.project) {
|
|
61
|
+
writes.projectWrite = { id: project.id, input: { baseBranch: restart.project.baseBranch } };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
32
64
|
stampActorOnEvents(writes, input.actor, "turn_selected");
|
|
33
65
|
return accept({ writes });
|
|
34
66
|
},
|