@leitwerk-dev/server 0.3.0 → 0.4.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/dist/{app-WfwKzrVk.d.ts → app-CsuxFZT5.d.ts} +332 -111
- package/dist/app-JM4CBTND.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-LK3RO6C7.js → chunk-FPMDWQF7.js} +3050 -645
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-KIOQNNG6.js → chunk-MBHRCQFE.js} +2781 -1822
- package/dist/chunk-MBHRCQFE.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 +14 -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/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/mapped-llm-run-repo.d.ts +56 -0
- package/dist/db/mapped-llm-run-repo.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 +4 -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 +7 -1
- 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/repo-helpers.d.ts +6 -0
- package/dist/db/repo-helpers.d.ts.map +1 -1
- package/dist/db/repositories.d.ts +16 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +1177 -71
- 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 +1 -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/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 +4 -14
- 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-test-harness.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 +11 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- 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 +45 -0
- package/dist/process-engine/mapped-turns.d.ts.map +1 -0
- package/dist/process-engine/operation.d.ts +1 -1
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts +2 -0
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts.map +1 -1
- 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.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 +10 -1
- 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-recovery-start-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +10 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-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/reserve-selected-turn-start.d.ts +5 -0
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts.map +1 -0
- package/dist/process-engine/writes/writes.d.ts +35 -49
- 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-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-navigation.d.ts +12 -2
- package/dist/process-turn-navigation.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +15 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- 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-diagnostics-assembler.d.ts +3 -1
- package/dist/routes/process-diagnostics-assembler.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-primary-path-assembler.d.ts +4 -12
- package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
- package/dist/routes/process-route-helpers.d.ts +15 -41
- 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 +83 -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 +5 -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 +3 -0
- package/dist/startup-evidence.d.ts.map +1 -1
- 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 +2 -0
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +4 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +2 -2
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/test-helpers/accepted-turn-start.d.ts +18 -4
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/owned-test-deps.d.ts +18 -0
- package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
- 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.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +14 -10
- 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 +117 -5
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +40 -2
- package/src/config/config-types.ts +14 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/db/database.ts +159 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +9 -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 +53 -13
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +22 -0
- package/src/db/schema.ts +173 -2
- 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 +12 -3
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +4 -149
- 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 +14 -22
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator-test-harness.ts +8 -4
- 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 +98 -0
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +13 -4
- package/src/process-engine/mapped-turns.ts +328 -0
- package/src/process-engine/operation.ts +1 -1
- package/src/process-engine/ops/accept-worker-turn-start.ts +6 -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 +10 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +65 -62
- 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 +33 -5
- package/src/process-engine/runner.ts +8 -8
- 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 +15 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -19
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +118 -21
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +20 -2
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +73 -61
- 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-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-navigation.ts +86 -8
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +249 -298
- 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-diagnostics-assembler.ts +32 -6
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +161 -327
- 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 +736 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +7 -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 +97 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +3 -0
- package/src/startup-evidence.ts +20 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +29 -18
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +42 -0
- package/src/supervisor/worker-supervisor.ts +5 -0
- package/src/supervisor/worker-turn-ipc-recorder.ts +13 -1
- package/src/test-helpers/accepted-turn-start.ts +51 -27
- package/src/test-helpers/owned-test-deps.ts +45 -0
- 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/testing.ts +4 -1
- 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-4QSV4FUQ.js +0 -8
- package/dist/chunk-KIOQNNG6.js.map +0 -1
- package/dist/chunk-LK3RO6C7.js.map +0 -1
- /package/dist/{app-4QSV4FUQ.js.map → app-JM4CBTND.js.map} +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { VERSION as PI_RUNTIME_VERSION } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import type {
|
|
2
|
-
ModelSelectionProvenance,
|
|
3
3
|
ProcessInstance,
|
|
4
4
|
ResolvedTurnStart,
|
|
5
|
-
TurnStartPreparationFailureCode,
|
|
6
5
|
TurnStartRecordState,
|
|
7
6
|
} from "@leitwerk-dev/domain";
|
|
8
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
filterProviderOptionsForDefinition,
|
|
9
|
+
resolveOutcomeContract,
|
|
10
|
+
} from "@leitwerk-dev/process-sdk";
|
|
9
11
|
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
10
12
|
import type { LeitwerkConfig } from "../config/config-types.js";
|
|
11
13
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
@@ -16,6 +18,9 @@ import type {
|
|
|
16
18
|
import { resolveRegisteredProviderOptions } from "../model-providers/provider-options.js";
|
|
17
19
|
import type { ModelProviderRegistry } from "../model-providers/registry.js";
|
|
18
20
|
import { assemblePiResourceSnapshot, type PiResourceBundleCache } from "../pi-resources/index.js";
|
|
21
|
+
import type { ServerProcessModelPolicy } from "../process-model-policy/index.js";
|
|
22
|
+
import { presentProcessModelPolicyFailure } from "../process-model-policy-presenter.js";
|
|
23
|
+
import type { ScopedSettingsService } from "../scoped-settings-service.js";
|
|
19
24
|
import {
|
|
20
25
|
buildRuntimeProfileSelectionInput,
|
|
21
26
|
defaultWorkerRuntimeProfile,
|
|
@@ -23,9 +28,14 @@ import {
|
|
|
23
28
|
} from "../worker-runtime-profile-selection.js";
|
|
24
29
|
import type { Writes } from "./writes/writes.js";
|
|
25
30
|
|
|
26
|
-
const PI_RUNTIME_VERSION = "0.81.1";
|
|
27
|
-
|
|
28
31
|
export interface TurnStartPreflightDeps {
|
|
32
|
+
processActionRegistry?: Pick<
|
|
33
|
+
import("../process-action-registry.js").ProcessActionRegistry,
|
|
34
|
+
"getTurnDefinition" | "resolveContextData" | "getProcessGraph"
|
|
35
|
+
>;
|
|
36
|
+
mappedRuns?: Pick<RepositoryBundle["mappedRuns"], "getById" | "getItem">;
|
|
37
|
+
scopedSettings?: Pick<ScopedSettingsService, "capture">;
|
|
38
|
+
processModelPolicy: ServerProcessModelPolicy;
|
|
29
39
|
config: LeitwerkConfig;
|
|
30
40
|
registry: ModelProviderRegistry;
|
|
31
41
|
modelStatusCache: ModelStatusCache;
|
|
@@ -37,31 +47,9 @@ export interface TurnStartPreflightDeps {
|
|
|
37
47
|
|
|
38
48
|
export type TurnStartPreflightResult = { ok: true } | { ok: false; code: string; message: string };
|
|
39
49
|
|
|
40
|
-
function failure(
|
|
41
|
-
requestedModelProfileId: string | null,
|
|
42
|
-
providerOptions: Record<string, string>,
|
|
43
|
-
code: TurnStartPreparationFailureCode,
|
|
44
|
-
safeSummary: string,
|
|
45
|
-
modelSelectionProvenance?: ModelSelectionProvenance,
|
|
46
|
-
availabilityRevision?: number,
|
|
47
|
-
): TurnStartRecordState {
|
|
48
|
-
return {
|
|
49
|
-
kind: "preparation_failed",
|
|
50
|
-
requestedModelProfileId,
|
|
51
|
-
providerOptions,
|
|
52
|
-
code,
|
|
53
|
-
safeSummary,
|
|
54
|
-
...(modelSelectionProvenance ? { modelSelectionProvenance } : {}),
|
|
55
|
-
...(availabilityRevision !== undefined ? { availabilityRevision } : {}),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
50
|
function previousProviderOptions(state: TurnStartRecordState): Record<string, string> {
|
|
60
51
|
if (state.kind === "preparation_failed") return { ...state.providerOptions };
|
|
61
|
-
|
|
62
|
-
return state.start?.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
63
|
-
}
|
|
64
|
-
return state.start.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
52
|
+
return state.start?.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
65
53
|
}
|
|
66
54
|
|
|
67
55
|
function previousProviderId(
|
|
@@ -77,22 +65,6 @@ function previousProviderId(
|
|
|
77
65
|
: null;
|
|
78
66
|
}
|
|
79
67
|
|
|
80
|
-
function parkPreparationFailure(
|
|
81
|
-
writes: Writes,
|
|
82
|
-
write: Extract<Writes["turnStartWrites"][number], { kind: "create" }>,
|
|
83
|
-
state: TurnStartRecordState,
|
|
84
|
-
): void {
|
|
85
|
-
write.input.state = state;
|
|
86
|
-
writes.processPatch.lifecycleStatus = "error";
|
|
87
|
-
// Reconciliation may stop an obsolete worker, but it must not launch the
|
|
88
|
-
// preparation-failed start.
|
|
89
|
-
writes.workerIntent = { kind: "reconcile" };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function candidateProcess(process: ProcessInstance, writes: Writes): ProcessInstance {
|
|
93
|
-
return { ...process, ...writes.processPatch };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
68
|
function resolveRuntimeProfile(
|
|
97
69
|
deps: TurnStartPreflightDeps,
|
|
98
70
|
process: ProcessInstance,
|
|
@@ -105,6 +77,8 @@ function resolveRuntimeProfile(
|
|
|
105
77
|
config: deps.config,
|
|
106
78
|
processId: process.processId,
|
|
107
79
|
componentKeys: deps.projects.listByInstance(process.id).map((project) => project.key),
|
|
80
|
+
docker:
|
|
81
|
+
deps.processActionRegistry?.getProcessGraph(process.processId)?.runtime?.docker === true,
|
|
108
82
|
}),
|
|
109
83
|
);
|
|
110
84
|
return selection.ok
|
|
@@ -165,42 +139,154 @@ export async function prepareCreatedTurnStarts(
|
|
|
165
139
|
explicitProviderOptions?: Readonly<Record<string, string>>,
|
|
166
140
|
availabilitySnapshot?: ModelStatusCacheSnapshot,
|
|
167
141
|
): Promise<TurnStartPreflightResult> {
|
|
168
|
-
const nextProcess =
|
|
142
|
+
const nextProcess = { ...process, ...writes.processPatch };
|
|
169
143
|
const availability = availabilitySnapshot ?? deps.modelStatusCache.snapshot();
|
|
170
|
-
const provenance =
|
|
171
|
-
nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource
|
|
172
|
-
? {
|
|
173
|
-
kind: nextProcess.selectedTurnModelKind,
|
|
174
|
-
source: nextProcess.selectedTurnModelSource,
|
|
175
|
-
}
|
|
176
|
-
: undefined;
|
|
177
|
-
for (let index = 0; index < writes.turnStartWrites.length; index += 1) {
|
|
178
|
-
const write = writes.turnStartWrites[index];
|
|
179
|
-
if (!write || write.kind !== "create" || write.input.turnType !== "llm") continue;
|
|
180
144
|
|
|
145
|
+
for (const write of writes.turnStartWrites) {
|
|
146
|
+
if (write.kind !== "create" || write.input.turnType !== "llm") continue;
|
|
147
|
+
const parkFailure = (
|
|
148
|
+
failure: Omit<Extract<TurnStartRecordState, { kind: "preparation_failed" }>, "kind">,
|
|
149
|
+
) => {
|
|
150
|
+
write.input.state = { ...failure, kind: "preparation_failed" };
|
|
151
|
+
writes.processPatch.lifecycleStatus = "error";
|
|
152
|
+
// Reconcile obsolete workers without launching this failed start.
|
|
153
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
let outcomeContract: Record<string, unknown> | undefined;
|
|
157
|
+
if (deps.processActionRegistry) {
|
|
158
|
+
try {
|
|
159
|
+
const registry = deps.processActionRegistry;
|
|
160
|
+
const turn = registry.getTurnDefinition(nextProcess.processId, write.input.turnId);
|
|
161
|
+
if (!turn || turn.kind !== "llm") throw new Error("Selected LLM turn is unavailable");
|
|
162
|
+
const ref = write.input.iteration;
|
|
163
|
+
const pendingRun = writes.mappedRunWrites.find(
|
|
164
|
+
(candidate) => candidate.kind === "create" && candidate.input.id === ref?.runId,
|
|
165
|
+
);
|
|
166
|
+
const item = ref
|
|
167
|
+
? pendingRun?.kind === "create"
|
|
168
|
+
? pendingRun.input.items[ref.itemIndex]
|
|
169
|
+
: deps.mappedRuns?.getItem(ref.runId, ref.itemIndex)
|
|
170
|
+
: undefined;
|
|
171
|
+
const count =
|
|
172
|
+
pendingRun?.kind === "create"
|
|
173
|
+
? pendingRun.input.items.length
|
|
174
|
+
: ref
|
|
175
|
+
? deps.mappedRuns?.getById(ref.runId)?.itemCount
|
|
176
|
+
: undefined;
|
|
177
|
+
if (
|
|
178
|
+
ref &&
|
|
179
|
+
(!item ||
|
|
180
|
+
item.itemKey !== ref.itemKey ||
|
|
181
|
+
item.itemIndex !== ref.itemIndex ||
|
|
182
|
+
count === undefined)
|
|
183
|
+
)
|
|
184
|
+
throw new Error("Frozen mapped item is unavailable");
|
|
185
|
+
outcomeContract = {
|
|
186
|
+
...resolveOutcomeContract(
|
|
187
|
+
turn,
|
|
188
|
+
registry.resolveContextData(nextProcess.processId, nextProcess),
|
|
189
|
+
ref && item
|
|
190
|
+
? {
|
|
191
|
+
...ref,
|
|
192
|
+
item: JSON.parse(item.itemJson),
|
|
193
|
+
itemLabel: item.label,
|
|
194
|
+
itemCount: count!,
|
|
195
|
+
}
|
|
196
|
+
: undefined,
|
|
197
|
+
),
|
|
198
|
+
};
|
|
199
|
+
} catch (error) {
|
|
200
|
+
return {
|
|
201
|
+
ok: false,
|
|
202
|
+
code: "invalid_outcome_contract",
|
|
203
|
+
message: error instanceof Error ? error.message : "Unable to resolve outcome contract",
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Resolve the model and required settings without yielding. An edit while the
|
|
209
|
+
// resource bundle is assembled belongs to the next start, not this snapshot.
|
|
210
|
+
const evaluated = deps.processModelPolicy.evaluate({
|
|
211
|
+
kind: "process_turn",
|
|
212
|
+
process: nextProcess,
|
|
213
|
+
turnId: write.input.turnId,
|
|
214
|
+
initialSelection: true,
|
|
215
|
+
startKind: write.input.startKind,
|
|
216
|
+
availability,
|
|
217
|
+
});
|
|
218
|
+
if (!evaluated.ok) {
|
|
219
|
+
const code =
|
|
220
|
+
evaluated.code === "model_unavailable" ||
|
|
221
|
+
evaluated.code === "model_stale" ||
|
|
222
|
+
evaluated.code === "model_required"
|
|
223
|
+
? evaluated.code
|
|
224
|
+
: "invalid_model_configuration";
|
|
225
|
+
parkFailure({
|
|
226
|
+
requestedModelProfileId: evaluated.selection?.modelProfileId ?? null,
|
|
227
|
+
providerOptions: previousProviderOptions(write.input.state),
|
|
228
|
+
code,
|
|
229
|
+
safeSummary: presentProcessModelPolicyFailure(evaluated),
|
|
230
|
+
...(evaluated.selection
|
|
231
|
+
? { modelSelectionProvenance: evaluated.selection.provenance }
|
|
232
|
+
: {}),
|
|
233
|
+
availabilityRevision: availability.revision,
|
|
234
|
+
});
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (evaluated.selection) {
|
|
238
|
+
const patch = {
|
|
239
|
+
selectedTurnModelProfileId: evaluated.selection.modelProfileId,
|
|
240
|
+
selectedTurnModelKind: evaluated.selection.provenance.kind,
|
|
241
|
+
selectedTurnModelSource: evaluated.selection.provenance.source,
|
|
242
|
+
};
|
|
243
|
+
Object.assign(nextProcess, patch);
|
|
244
|
+
Object.assign(writes.processPatch, patch);
|
|
245
|
+
}
|
|
246
|
+
const provenance =
|
|
247
|
+
nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource
|
|
248
|
+
? {
|
|
249
|
+
kind: nextProcess.selectedTurnModelKind,
|
|
250
|
+
source: nextProcess.selectedTurnModelSource,
|
|
251
|
+
}
|
|
252
|
+
: undefined;
|
|
181
253
|
const requestedProfileId = nextProcess.selectedTurnModelProfileId?.trim() || null;
|
|
254
|
+
let scopedSettings: ReturnType<ScopedSettingsService["capture"]>;
|
|
255
|
+
try {
|
|
256
|
+
scopedSettings = deps.scopedSettings?.capture(
|
|
257
|
+
nextProcess,
|
|
258
|
+
write.input.turnId,
|
|
259
|
+
provenance?.source === "scoped_purpose_default",
|
|
260
|
+
);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
parkFailure({
|
|
263
|
+
requestedModelProfileId: requestedProfileId,
|
|
264
|
+
providerOptions: {},
|
|
265
|
+
code: "invalid_model_configuration",
|
|
266
|
+
safeSummary:
|
|
267
|
+
error instanceof Error
|
|
268
|
+
? error.message
|
|
269
|
+
: "Correct invalid scoped settings before retrying",
|
|
270
|
+
});
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
182
273
|
const retainedState = write.input.state;
|
|
183
274
|
const retainedOptions = previousProviderOptions(retainedState);
|
|
184
275
|
if (
|
|
185
276
|
retainedState.kind === "preparation_failed" &&
|
|
186
277
|
retainedState.code === "invalid_model_configuration"
|
|
187
278
|
) {
|
|
188
|
-
|
|
279
|
+
parkFailure(retainedState);
|
|
189
280
|
continue;
|
|
190
281
|
}
|
|
191
282
|
if (!requestedProfileId) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
"Choose a model before retrying startup",
|
|
200
|
-
undefined,
|
|
201
|
-
availability.revision,
|
|
202
|
-
),
|
|
203
|
-
);
|
|
283
|
+
parkFailure({
|
|
284
|
+
requestedModelProfileId: null,
|
|
285
|
+
providerOptions: retainedOptions,
|
|
286
|
+
code: "model_required",
|
|
287
|
+
safeSummary: "Choose a model before retrying startup",
|
|
288
|
+
availabilityRevision: availability.revision,
|
|
289
|
+
});
|
|
204
290
|
continue;
|
|
205
291
|
}
|
|
206
292
|
|
|
@@ -235,33 +321,12 @@ export async function prepareCreatedTurnStarts(
|
|
|
235
321
|
message: optionResult.issues.map((issue) => issue.message).join("; "),
|
|
236
322
|
};
|
|
237
323
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
"provider_options_required",
|
|
245
|
-
optionResult.issues.map((issue) => issue.message).join("; "),
|
|
246
|
-
),
|
|
247
|
-
);
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const status = availability.profiles.find((candidate) => candidate.profileId === profile.id);
|
|
252
|
-
if (!status || status.availability !== "available") {
|
|
253
|
-
parkPreparationFailure(
|
|
254
|
-
writes,
|
|
255
|
-
write,
|
|
256
|
-
failure(
|
|
257
|
-
profile.id,
|
|
258
|
-
recoveryOptions,
|
|
259
|
-
!status || status.availability === "stale" ? "model_stale" : "model_unavailable",
|
|
260
|
-
status?.safeReason ?? "The selected model status is stale",
|
|
261
|
-
provenance,
|
|
262
|
-
availability.revision,
|
|
263
|
-
),
|
|
264
|
-
);
|
|
324
|
+
parkFailure({
|
|
325
|
+
requestedModelProfileId: profile.id,
|
|
326
|
+
providerOptions: recoveryOptions,
|
|
327
|
+
code: "provider_options_required",
|
|
328
|
+
safeSummary: optionResult.issues.map((issue) => issue.message).join("; "),
|
|
329
|
+
});
|
|
265
330
|
continue;
|
|
266
331
|
}
|
|
267
332
|
|
|
@@ -302,6 +367,8 @@ export async function prepareCreatedTurnStarts(
|
|
|
302
367
|
kind: "starting",
|
|
303
368
|
start: {
|
|
304
369
|
kind: "llm",
|
|
370
|
+
...(outcomeContract ? { outcomeContract } : {}),
|
|
371
|
+
...(scopedSettings ? { scopedSettings } : {}),
|
|
305
372
|
model,
|
|
306
373
|
...(provenance ? { modelSelectionProvenance: provenance } : {}),
|
|
307
374
|
availabilityRevision: availability.revision,
|
|
@@ -315,16 +382,12 @@ export async function prepareCreatedTurnStarts(
|
|
|
315
382
|
writes.processPatch.lifecycleStatus = "active";
|
|
316
383
|
writes.workerIntent = { kind: "restart_worker" };
|
|
317
384
|
} catch {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
"provider_preflight_failed",
|
|
325
|
-
"The provider could not prepare this worker start",
|
|
326
|
-
),
|
|
327
|
-
);
|
|
385
|
+
parkFailure({
|
|
386
|
+
requestedModelProfileId: profile.id,
|
|
387
|
+
providerOptions: { ...optionResult.value },
|
|
388
|
+
code: "provider_preflight_failed",
|
|
389
|
+
safeSummary: "The provider could not prepare this worker start",
|
|
390
|
+
});
|
|
328
391
|
}
|
|
329
392
|
}
|
|
330
393
|
return { ok: true };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { ProcessGraphRegistry, TurnWaitPredicate } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { generateId } from "../db/repo-helpers.js";
|
|
4
|
+
import {
|
|
5
|
+
applyMetadataPatch,
|
|
6
|
+
type DecisionMetadata,
|
|
7
|
+
type TurnStartWrite,
|
|
8
|
+
type Writes,
|
|
9
|
+
} from "./writes/writes.js";
|
|
10
|
+
|
|
11
|
+
const KEY = "turnWait";
|
|
12
|
+
|
|
13
|
+
/** Durable scheduling state, separate from worker starts and turn attempts. */
|
|
14
|
+
export interface PendingTurnWait {
|
|
15
|
+
id: string;
|
|
16
|
+
turnId: string;
|
|
17
|
+
revision: number;
|
|
18
|
+
status: "waiting" | "error";
|
|
19
|
+
nextCheckAt: number;
|
|
20
|
+
failures: number;
|
|
21
|
+
message: string | null;
|
|
22
|
+
start: Extract<TurnStartWrite, { kind: "create" }>["input"];
|
|
23
|
+
metadata?: DecisionMetadata;
|
|
24
|
+
initialSelection?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function pendingTurnWait(
|
|
28
|
+
process: Pick<ProcessInstance, "metadata">,
|
|
29
|
+
): PendingTurnWait | null {
|
|
30
|
+
const value = process.metadata?.[KEY] as PendingTurnWait | undefined;
|
|
31
|
+
if (!value) return null;
|
|
32
|
+
if (
|
|
33
|
+
typeof value.id !== "string" ||
|
|
34
|
+
typeof value.turnId !== "string" ||
|
|
35
|
+
!Number.isInteger(value.revision) ||
|
|
36
|
+
!Number.isFinite(value.nextCheckAt) ||
|
|
37
|
+
!value.start ||
|
|
38
|
+
value.start.turnId !== value.turnId ||
|
|
39
|
+
(value.status !== "waiting" && value.status !== "error")
|
|
40
|
+
) {
|
|
41
|
+
throw new Error("Invalid persisted turn waiting state");
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function turnWaitPredicate(
|
|
47
|
+
graphs: ProcessGraphRegistry,
|
|
48
|
+
process: Pick<ProcessInstance, "processId" | "selectedTurnId">,
|
|
49
|
+
): TurnWaitPredicate | undefined {
|
|
50
|
+
if (!process.selectedTurnId) return undefined;
|
|
51
|
+
const turn = graphs.get(process.processId)?.turns.get(process.selectedTurnId)?.definition;
|
|
52
|
+
return turn?.kind === "llm" || turn?.kind === "automatic" ? turn.waitFor : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function writeTurnWait(
|
|
56
|
+
writes: Writes,
|
|
57
|
+
process: ProcessInstance,
|
|
58
|
+
wait: PendingTurnWait | null,
|
|
59
|
+
): void {
|
|
60
|
+
const metadata = {
|
|
61
|
+
...((Object.hasOwn(writes.processPatch, "metadata")
|
|
62
|
+
? writes.processPatch.metadata
|
|
63
|
+
: process.metadata) ?? {}),
|
|
64
|
+
};
|
|
65
|
+
if (wait) metadata[KEY] = wait;
|
|
66
|
+
else delete metadata[KEY];
|
|
67
|
+
applyMetadataPatch(writes, process, Object.keys(metadata).length ? metadata : null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Every start-producing engine path passes here before a start is persisted. */
|
|
71
|
+
export function deferTurnWaitStarts(
|
|
72
|
+
graphs: ProcessGraphRegistry,
|
|
73
|
+
process: ProcessInstance,
|
|
74
|
+
writes: Writes,
|
|
75
|
+
metadata?: DecisionMetadata,
|
|
76
|
+
): void {
|
|
77
|
+
const next = { ...process, ...writes.processPatch };
|
|
78
|
+
const previous = pendingTurnWait(process);
|
|
79
|
+
const predicate = turnWaitPredicate(graphs, next);
|
|
80
|
+
const index = writes.turnStartWrites.findIndex(
|
|
81
|
+
(write) => write.kind === "create" && write.input.turnId === next.selectedTurnId,
|
|
82
|
+
);
|
|
83
|
+
const start = index >= 0 ? writes.turnStartWrites[index] : undefined;
|
|
84
|
+
if (!predicate || !start || start.kind !== "create") {
|
|
85
|
+
const currentWait = pendingTurnWait(next);
|
|
86
|
+
if (
|
|
87
|
+
currentWait &&
|
|
88
|
+
(next.selectedTurnId !== currentWait.turnId ||
|
|
89
|
+
next.lifecycleStatus === "completed" ||
|
|
90
|
+
next.lifecycleStatus === "aborted")
|
|
91
|
+
)
|
|
92
|
+
writeTurnWait(writes, process, null);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (writes.waitForAdmission === previous?.id && previous?.turnId === start.input.turnId) return;
|
|
96
|
+
// Subsequent items belong to an already admitted mapped run. Explicit recovery still checks.
|
|
97
|
+
if (start.input.iteration && start.input.startKind === "selected_turn") return;
|
|
98
|
+
writes.turnStartWrites.splice(index, 1);
|
|
99
|
+
const wait: PendingTurnWait =
|
|
100
|
+
previous &&
|
|
101
|
+
previous.turnId === start.input.turnId &&
|
|
102
|
+
start.input.startKind === "selected_turn" &&
|
|
103
|
+
previous.status === "waiting"
|
|
104
|
+
? previous
|
|
105
|
+
: {
|
|
106
|
+
id: generateId("wait"),
|
|
107
|
+
turnId: start.input.turnId,
|
|
108
|
+
revision: 0,
|
|
109
|
+
status: "waiting",
|
|
110
|
+
nextCheckAt: 0,
|
|
111
|
+
failures: 0,
|
|
112
|
+
message: null,
|
|
113
|
+
start: start.input,
|
|
114
|
+
initialSelection:
|
|
115
|
+
process.selectedTurnId === null &&
|
|
116
|
+
process.lifecycleStatus === "discovered" &&
|
|
117
|
+
process.planRevision === 0,
|
|
118
|
+
...(metadata ? { metadata } : {}),
|
|
119
|
+
};
|
|
120
|
+
writeTurnWait(writes, process, wait);
|
|
121
|
+
writes.processPatch.currentExecution = null;
|
|
122
|
+
writes.processPatch.lifecycleStatus = "waiting";
|
|
123
|
+
for (const field of ["currentExecution", "lifecycleStatus"])
|
|
124
|
+
if (!writes.changedFields.includes(field)) writes.changedFields.push(field);
|
|
125
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
126
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { isWorkerOwnedTurnType, type ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
2
|
import type { ProcessGraphRegistry } from "../process-graph.js";
|
|
3
|
+
import { pendingTurnWait } from "./turn-wait-state.js";
|
|
3
4
|
|
|
4
5
|
type ProcessWorkerRequirementInput = Pick<ProcessInstance, "selectedTurnId" | "lifecycleStatus"> & {
|
|
5
6
|
processId?: string | null;
|
|
7
|
+
metadata?: ProcessInstance["metadata"];
|
|
8
|
+
currentExecution?: ProcessInstance["currentExecution"];
|
|
6
9
|
};
|
|
7
10
|
|
|
8
11
|
export function selectedTurnRequiresWorker(
|
|
@@ -12,6 +15,7 @@ export function selectedTurnRequiresWorker(
|
|
|
12
15
|
if (!process.selectedTurnId || process.lifecycleStatus !== "active") {
|
|
13
16
|
return false;
|
|
14
17
|
}
|
|
18
|
+
if (pendingTurnWait({ metadata: process.metadata ?? null })) return false;
|
|
15
19
|
const turn = process.processId
|
|
16
20
|
? processGraphs?.get(process.processId)?.turns.get(process.selectedTurnId)?.definition
|
|
17
21
|
: undefined;
|
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
DeferredProcessActivationSnapshotResult,
|
|
18
18
|
PreparedDeferredProcessActivation,
|
|
19
19
|
ProcessActionServiceLike,
|
|
20
|
+
ProcessObservationUpdate,
|
|
21
|
+
WaitingProcessRestart,
|
|
20
22
|
} from "@leitwerk-dev/process-sdk";
|
|
21
23
|
import type { LeitwerkConfig } from "../config/config-types.js";
|
|
22
24
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
@@ -76,6 +78,8 @@ export interface ProcessEngineDeps
|
|
|
76
78
|
| "turnAnnotations"
|
|
77
79
|
| "transaction"
|
|
78
80
|
> {
|
|
81
|
+
/** Required for processes that declare mapped LLM turns. @internal */
|
|
82
|
+
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
79
83
|
/** @internal */
|
|
80
84
|
processOperations: ProcessOperationCoordinator;
|
|
81
85
|
/** @internal */
|
|
@@ -239,6 +243,11 @@ export type RecordResult<TOp extends OperationSpec<string, OperationInputBase, u
|
|
|
239
243
|
|
|
240
244
|
/** @internal */
|
|
241
245
|
export interface ProcessEngine {
|
|
246
|
+
/** @internal */
|
|
247
|
+
applyProcessObservation(
|
|
248
|
+
instanceId: string,
|
|
249
|
+
input: ProcessObservationUpdate,
|
|
250
|
+
): Promise<EngineResult<void>>;
|
|
242
251
|
/** @internal */
|
|
243
252
|
getDeferredProcessActivationSnapshots(
|
|
244
253
|
query: DeferredProcessActivationSnapshotQuery,
|
|
@@ -276,6 +285,8 @@ export interface ProcessEngine {
|
|
|
276
285
|
opts?: {
|
|
277
286
|
/** @internal */
|
|
278
287
|
actor?: Actor;
|
|
288
|
+
/** @internal */
|
|
289
|
+
restart?: WaitingProcessRestart;
|
|
279
290
|
},
|
|
280
291
|
): Promise<EngineResult<void>>;
|
|
281
292
|
/** @internal */
|
|
@@ -375,6 +386,10 @@ export interface ProcessEngine {
|
|
|
375
386
|
/** @internal */
|
|
376
387
|
workerLeaseId: string;
|
|
377
388
|
},
|
|
389
|
+
options?: {
|
|
390
|
+
/** Runs after durable acceptance and lock release, before reactions. @internal */
|
|
391
|
+
onRecorded?: (turnRecordId: string) => void;
|
|
392
|
+
},
|
|
378
393
|
): Promise<
|
|
379
394
|
EngineResult<{
|
|
380
395
|
/** @internal */
|
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import type { ProcessInstance, ProcessTurnRecord, TurnStartRecord } from "@leitwerk-dev/domain";
|
|
2
2
|
import type { ProcessGraphRegistry } from "../../process-graph.js";
|
|
3
3
|
import { buildTurnSelectionWrites } from "./build-turn-selection-writes.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
appendProcessEvent,
|
|
6
|
+
isWriteBuildFailure,
|
|
7
|
+
type WriteBuildResult,
|
|
8
|
+
type Writes,
|
|
9
|
+
} from "./writes.js";
|
|
10
|
+
|
|
11
|
+
/** Fence accepted and pending execution without choosing the next business position. @internal */
|
|
12
|
+
export function supersedeExecution(
|
|
13
|
+
writes: Writes,
|
|
14
|
+
record: ProcessTurnRecord | null,
|
|
15
|
+
start?: TurnStartRecord | null,
|
|
16
|
+
recordedAt?: string,
|
|
17
|
+
): void {
|
|
18
|
+
writes.mappedRunWrites.push({ kind: "abort_active" });
|
|
19
|
+
if (start?.state.kind === "starting")
|
|
20
|
+
writes.turnStartWrites.push({
|
|
21
|
+
kind: "cas_state",
|
|
22
|
+
id: start.id,
|
|
23
|
+
expectedKind: "starting",
|
|
24
|
+
state: { kind: "superseded", start: start.state.start },
|
|
25
|
+
});
|
|
26
|
+
if (record?.status === "running")
|
|
27
|
+
writes.turnRecordWrites.push({
|
|
28
|
+
kind: "update",
|
|
29
|
+
id: record.id,
|
|
30
|
+
input: { status: "superseded", endedAt: recordedAt ?? new Date().toISOString() },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
export function buildAbortProcessWrites(input: {
|
|
7
35
|
processGraphs: ProcessGraphRegistry;
|
|
@@ -20,24 +48,7 @@ export function buildAbortProcessWrites(input: {
|
|
|
20
48
|
return writes;
|
|
21
49
|
}
|
|
22
50
|
|
|
23
|
-
|
|
24
|
-
writes.turnStartWrites.push({
|
|
25
|
-
kind: "cas_state",
|
|
26
|
-
id: input.currentWorkerStart.id,
|
|
27
|
-
expectedKind: "starting",
|
|
28
|
-
state: { kind: "superseded", start: input.currentWorkerStart.state.start },
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (input.activeTurnRecord?.status === "running") {
|
|
32
|
-
writes.turnRecordWrites.push({
|
|
33
|
-
kind: "update",
|
|
34
|
-
id: input.activeTurnRecord.id,
|
|
35
|
-
input: {
|
|
36
|
-
status: "superseded",
|
|
37
|
-
endedAt: input.recordedAt ?? new Date().toISOString(),
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
51
|
+
supersedeExecution(writes, input.activeTurnRecord, input.currentWorkerStart, input.recordedAt);
|
|
41
52
|
|
|
42
53
|
// Without a selected turn, abort has no turn_selected event to attribute.
|
|
43
54
|
if (input.process.selectedTurnId === null) {
|
|
@@ -47,6 +47,7 @@ export function buildRecoveryStartWrites(
|
|
|
47
47
|
turnId: failedRun.turnId,
|
|
48
48
|
proposedTurnRecordId: generateId("trn"),
|
|
49
49
|
recoveryTurnRecordId: failedRun.id,
|
|
50
|
+
iteration: failedRun.iteration ?? null,
|
|
50
51
|
state:
|
|
51
52
|
recovery.turnType === "automatic"
|
|
52
53
|
? { kind: "starting", start: { kind: "automatic" } }
|