@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
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Actor,
|
|
3
|
+
AutomaticStartupRecoverySummary,
|
|
3
4
|
ProcessInput,
|
|
4
5
|
ProcessInstance,
|
|
5
6
|
ProcessLifecycleStatus,
|
|
@@ -17,6 +18,8 @@ import type {
|
|
|
17
18
|
DeferredProcessActivationSnapshotResult,
|
|
18
19
|
PreparedDeferredProcessActivation,
|
|
19
20
|
ProcessActionServiceLike,
|
|
21
|
+
ProcessObservationUpdate,
|
|
22
|
+
WaitingProcessRestart,
|
|
20
23
|
} from "@leitwerk-dev/process-sdk";
|
|
21
24
|
import type { LeitwerkConfig } from "../config/config-types.js";
|
|
22
25
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
@@ -241,6 +244,11 @@ export type RecordResult<TOp extends OperationSpec<string, OperationInputBase, u
|
|
|
241
244
|
|
|
242
245
|
/** @internal */
|
|
243
246
|
export interface ProcessEngine {
|
|
247
|
+
/** @internal */
|
|
248
|
+
applyProcessObservation(
|
|
249
|
+
instanceId: string,
|
|
250
|
+
input: ProcessObservationUpdate,
|
|
251
|
+
): Promise<EngineResult<void>>;
|
|
244
252
|
/** @internal */
|
|
245
253
|
getDeferredProcessActivationSnapshots(
|
|
246
254
|
query: DeferredProcessActivationSnapshotQuery,
|
|
@@ -278,6 +286,8 @@ export interface ProcessEngine {
|
|
|
278
286
|
opts?: {
|
|
279
287
|
/** @internal */
|
|
280
288
|
actor?: Actor;
|
|
289
|
+
/** @internal */
|
|
290
|
+
restart?: WaitingProcessRestart;
|
|
281
291
|
},
|
|
282
292
|
): Promise<EngineResult<void>>;
|
|
283
293
|
/** @internal */
|
|
@@ -317,6 +327,8 @@ export interface ProcessEngine {
|
|
|
317
327
|
instanceId: string,
|
|
318
328
|
startRecordId: string,
|
|
319
329
|
opts?: {
|
|
330
|
+
/** @internal */
|
|
331
|
+
actor?: Actor;
|
|
320
332
|
/** @internal */
|
|
321
333
|
nextTurnModelProfileId?: string | null;
|
|
322
334
|
/** @internal */
|
|
@@ -328,6 +340,15 @@ export interface ProcessEngine {
|
|
|
328
340
|
startRecordId: string;
|
|
329
341
|
}>
|
|
330
342
|
>;
|
|
343
|
+
/** Automatic recovery never retries accepted turns or resets the startup budget. @internal */
|
|
344
|
+
retryStartupAutomatically(
|
|
345
|
+
instanceId: string,
|
|
346
|
+
startRecordId: string,
|
|
347
|
+
opts?: {
|
|
348
|
+
/** @internal */
|
|
349
|
+
availabilityCause?: "availability_transition" | "startup_reconciliation";
|
|
350
|
+
},
|
|
351
|
+
): Promise<EngineResult<AutomaticStartupRecoverySummary>>;
|
|
331
352
|
/** @internal */
|
|
332
353
|
continueFailedTurn(
|
|
333
354
|
instanceId: string,
|
|
@@ -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,25 +48,7 @@ export function buildAbortProcessWrites(input: {
|
|
|
20
48
|
return writes;
|
|
21
49
|
}
|
|
22
50
|
|
|
23
|
-
writes.
|
|
24
|
-
if (input.currentWorkerStart?.state.kind === "starting") {
|
|
25
|
-
writes.turnStartWrites.push({
|
|
26
|
-
kind: "cas_state",
|
|
27
|
-
id: input.currentWorkerStart.id,
|
|
28
|
-
expectedKind: "starting",
|
|
29
|
-
state: { kind: "superseded", start: input.currentWorkerStart.state.start },
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (input.activeTurnRecord?.status === "running") {
|
|
33
|
-
writes.turnRecordWrites.push({
|
|
34
|
-
kind: "update",
|
|
35
|
-
id: input.activeTurnRecord.id,
|
|
36
|
-
input: {
|
|
37
|
-
status: "superseded",
|
|
38
|
-
endedAt: input.recordedAt ?? new Date().toISOString(),
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
51
|
+
supersedeExecution(writes, input.activeTurnRecord, input.currentWorkerStart, input.recordedAt);
|
|
42
52
|
|
|
43
53
|
// Without a selected turn, abort has no turn_selected event to attribute.
|
|
44
54
|
if (input.process.selectedTurnId === null) {
|
|
@@ -4,7 +4,11 @@ import type {
|
|
|
4
4
|
ProcessProject,
|
|
5
5
|
TurnOutcomePayload,
|
|
6
6
|
} from "@leitwerk-dev/domain";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
applyOutcomeContract,
|
|
9
|
+
resolveOutcomeContract,
|
|
10
|
+
SafeOutcomePlanningError,
|
|
11
|
+
} from "@leitwerk-dev/process-sdk";
|
|
8
12
|
import type { RepositoryBundle } from "../../db/repositories.js";
|
|
9
13
|
import {
|
|
10
14
|
checkTurnOutcomeAvailability,
|
|
@@ -123,6 +127,8 @@ async function buildProcessTurnOutcomeEffectWrites(
|
|
|
123
127
|
|
|
124
128
|
/** @internal */
|
|
125
129
|
export interface TurnOutcomePlanningInput {
|
|
130
|
+
/** Frozen declarations from the accepted start. @internal */
|
|
131
|
+
outcomeContract?: Record<string, unknown>;
|
|
126
132
|
/** @internal */
|
|
127
133
|
process: ProcessInstance;
|
|
128
134
|
/** @internal */
|
|
@@ -148,10 +154,41 @@ export async function buildTurnOutcomeWrites(
|
|
|
148
154
|
input: TurnOutcomePlanningInput,
|
|
149
155
|
): Promise<WriteBuildResult> {
|
|
150
156
|
const knownProjectKeys = new Set(input.projects.map((project) => project.key));
|
|
151
|
-
|
|
157
|
+
let turnDefinition = input.processActionRegistry.getTurnDefinition(
|
|
152
158
|
input.process.processId,
|
|
153
159
|
input.payload.turnId,
|
|
154
160
|
);
|
|
161
|
+
if (turnDefinition?.kind === "llm") {
|
|
162
|
+
try {
|
|
163
|
+
let snapshot = input.outcomeContract;
|
|
164
|
+
if (!snapshot) {
|
|
165
|
+
const ref = input.iteration;
|
|
166
|
+
const item = ref ? input.mappedRuns?.getItem(ref.runId, ref.itemIndex) : undefined;
|
|
167
|
+
const run = ref ? input.mappedRuns?.getById(ref.runId) : undefined;
|
|
168
|
+
snapshot = {
|
|
169
|
+
...resolveOutcomeContract(
|
|
170
|
+
turnDefinition,
|
|
171
|
+
input.processActionRegistry.resolveContextData(input.process.processId, input.process),
|
|
172
|
+
ref && item && run
|
|
173
|
+
? {
|
|
174
|
+
...ref,
|
|
175
|
+
item: JSON.parse(item.itemJson),
|
|
176
|
+
itemLabel: item.label,
|
|
177
|
+
itemCount: run.itemCount,
|
|
178
|
+
}
|
|
179
|
+
: undefined,
|
|
180
|
+
),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
turnDefinition = applyOutcomeContract(turnDefinition, snapshot);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
ok: false,
|
|
187
|
+
code: "invalid_outcome_contract",
|
|
188
|
+
message: error instanceof Error ? error.message : "Invalid outcome contract",
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
155
192
|
const availabilityError = checkTurnOutcomeAvailability(
|
|
156
193
|
input.processGraphs,
|
|
157
194
|
turnDefinition,
|