@leitwerk-dev/server 0.3.1 → 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-BuJCdkvy.d.ts → app-CsuxFZT5.d.ts} +262 -121
- 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-QCHS3X33.js → chunk-FPMDWQF7.js} +2617 -562
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-MBHRCQFE.js} +2303 -1576
- 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/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 +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 +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.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/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 +5 -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-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-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/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 +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.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 +115 -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 +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 +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 +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 +8 -2
- 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 -193
- 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 +11 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- 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 +9 -13
- 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 +21 -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 +9 -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 +15 -2
- 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-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/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +9 -9
- 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 +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 +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 +3 -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/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-JM4CBTND.js.map} +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { InitialProcessBinding } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { accept, modelOverrideMetadata, noWrites, reject } from "../decision.js";
|
|
4
|
+
import { defineOperation } from "../operation.js";
|
|
5
|
+
import { pendingTurnWait, turnWaitPredicate, writeTurnWait } from "../turn-wait-state.js";
|
|
6
|
+
import { buildTurnSelectionWrites } from "../writes/build-turn-selection-writes.js";
|
|
7
|
+
import {
|
|
8
|
+
appendProcessEvent,
|
|
9
|
+
applyProcessPatchField,
|
|
10
|
+
createWrites,
|
|
11
|
+
type DecisionMetadata,
|
|
12
|
+
isWriteBuildFailure,
|
|
13
|
+
stampActorOnEvents,
|
|
14
|
+
} from "../writes/writes.js";
|
|
15
|
+
|
|
16
|
+
/** Initialize waiting after a compatible process-definition migration. */
|
|
17
|
+
export const ArmTurnWait = defineOperation<"arm_turn_wait", { instanceId: string }, void>({
|
|
18
|
+
kind: "arm_turn_wait",
|
|
19
|
+
label: "Wait for turn readiness",
|
|
20
|
+
admission: "new_turn",
|
|
21
|
+
decide({ process, deps }) {
|
|
22
|
+
if (
|
|
23
|
+
pendingTurnWait(process) ||
|
|
24
|
+
process.currentExecution ||
|
|
25
|
+
!process.selectedTurnId ||
|
|
26
|
+
process.lifecycleStatus !== "active" ||
|
|
27
|
+
!turnWaitPredicate(deps.processGraphs, process)
|
|
28
|
+
)
|
|
29
|
+
return noWrites();
|
|
30
|
+
const writes = buildTurnSelectionWrites(deps.processGraphs, process, {
|
|
31
|
+
toTurnId: process.selectedTurnId,
|
|
32
|
+
});
|
|
33
|
+
return isWriteBuildFailure(writes) ? writes : accept({ writes });
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
interface ResolveTurnWaitInput {
|
|
38
|
+
instanceId: string;
|
|
39
|
+
waitId: string;
|
|
40
|
+
revision: number;
|
|
41
|
+
paramsJson: string | null;
|
|
42
|
+
stateJson: string | null;
|
|
43
|
+
projectsJson: string;
|
|
44
|
+
/** State validated and encoded by the readiness service. */
|
|
45
|
+
nextStateJson?: string;
|
|
46
|
+
initialBinding?: InitialProcessBinding;
|
|
47
|
+
result: "ready" | "waiting" | "complete" | "abort" | "bind" | "retry" | "error";
|
|
48
|
+
message?: string;
|
|
49
|
+
now: number;
|
|
50
|
+
pollIntervalMs: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Commit a check made outside the process lock, only if its inputs are still current. */
|
|
54
|
+
export const ResolveTurnWait = defineOperation<"resolve_turn_wait", ResolveTurnWaitInput, void>({
|
|
55
|
+
kind: "resolve_turn_wait",
|
|
56
|
+
label: "Resolve turn readiness",
|
|
57
|
+
admission: "new_turn",
|
|
58
|
+
decide({ process, deps }, input) {
|
|
59
|
+
const wait = pendingTurnWait(process);
|
|
60
|
+
if (
|
|
61
|
+
!wait ||
|
|
62
|
+
wait.id !== input.waitId ||
|
|
63
|
+
wait.revision !== input.revision ||
|
|
64
|
+
process.selectedTurnId !== wait.turnId ||
|
|
65
|
+
process.lifecycleStatus !== "waiting" ||
|
|
66
|
+
process.paramsJson !== input.paramsJson ||
|
|
67
|
+
process.stateJson !== input.stateJson ||
|
|
68
|
+
JSON.stringify(deps.projects.listByInstance(process.id)) !== input.projectsJson
|
|
69
|
+
) {
|
|
70
|
+
return reject("turn_wait_superseded", "The waiting condition has changed");
|
|
71
|
+
}
|
|
72
|
+
const writes = createWrites();
|
|
73
|
+
if (input.nextStateJson !== undefined && !["retry", "error"].includes(input.result))
|
|
74
|
+
applyProcessPatchField(writes, process, "stateJson", input.nextStateJson);
|
|
75
|
+
if (input.result === "bind") {
|
|
76
|
+
const binding = input.initialBinding;
|
|
77
|
+
if (
|
|
78
|
+
!binding?.projects.length ||
|
|
79
|
+
!wait.initialSelection ||
|
|
80
|
+
process.currentExecution ||
|
|
81
|
+
deps.projects.listByInstance(process.id).length ||
|
|
82
|
+
deps.turnStarts.listByInstance(process.id).length ||
|
|
83
|
+
deps.turnRecords.listByInstance(process.id).length
|
|
84
|
+
)
|
|
85
|
+
return reject(
|
|
86
|
+
"startup_binding_unavailable",
|
|
87
|
+
"Initial bindings require a process without projects or execution history",
|
|
88
|
+
);
|
|
89
|
+
if (
|
|
90
|
+
Object.keys(binding.metadata ?? {}).some(
|
|
91
|
+
(key) => key === "turnWait" || Object.hasOwn(process.metadata ?? {}, key),
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
return reject(
|
|
95
|
+
"startup_binding_superseded",
|
|
96
|
+
"Initial repository binding cannot replace retained metadata",
|
|
97
|
+
);
|
|
98
|
+
const definition = deps.processGraphs.get(process.processId);
|
|
99
|
+
if (!definition) return reject("process_not_found", "Process definition is unavailable");
|
|
100
|
+
applyProcessPatchField(
|
|
101
|
+
writes,
|
|
102
|
+
process,
|
|
103
|
+
"paramsJson",
|
|
104
|
+
JSON.stringify(
|
|
105
|
+
definition.paramsCodec.serialize(definition.paramsCodec.parse(binding.params)),
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
applyProcessPatchField(writes, process, "metadata", {
|
|
109
|
+
...process.metadata,
|
|
110
|
+
...binding.metadata,
|
|
111
|
+
...(binding.settingsContext ? { settingsContext: binding.settingsContext } : {}),
|
|
112
|
+
});
|
|
113
|
+
writes.initialProjects = binding.projects.map((project) => ({
|
|
114
|
+
...project,
|
|
115
|
+
instanceId: process.id,
|
|
116
|
+
}));
|
|
117
|
+
writeTurnWait(writes, process, {
|
|
118
|
+
...wait,
|
|
119
|
+
revision: wait.revision + 1,
|
|
120
|
+
message: null,
|
|
121
|
+
failures: 0,
|
|
122
|
+
nextCheckAt: 0,
|
|
123
|
+
});
|
|
124
|
+
appendProcessEvent(writes, process, {
|
|
125
|
+
eventType: "initial_repositories_bound",
|
|
126
|
+
level: "info",
|
|
127
|
+
message: "Startup repository bindings resolved",
|
|
128
|
+
data: { projectKeys: binding.projects.map((p) => p.key) },
|
|
129
|
+
});
|
|
130
|
+
return accept({ writes });
|
|
131
|
+
}
|
|
132
|
+
if (input.result === "ready") {
|
|
133
|
+
writeTurnWait(writes, process, null);
|
|
134
|
+
writes.waitForAdmission = wait.id;
|
|
135
|
+
writes.turnStartWrites.push({ kind: "create", input: wait.start });
|
|
136
|
+
applyProcessPatchField(writes, process, "currentExecution", {
|
|
137
|
+
kind: "worker_start",
|
|
138
|
+
id: wait.start.id as string,
|
|
139
|
+
});
|
|
140
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "active");
|
|
141
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
142
|
+
return accept({ writes, metadata: wait.metadata });
|
|
143
|
+
}
|
|
144
|
+
if (input.result === "complete" || input.result === "abort") {
|
|
145
|
+
writeTurnWait(writes, process, null);
|
|
146
|
+
applyProcessPatchField(writes, process, "selectedTurnId", null);
|
|
147
|
+
applyProcessPatchField(writes, process, "currentExecution", null);
|
|
148
|
+
applyProcessPatchField(
|
|
149
|
+
writes,
|
|
150
|
+
process,
|
|
151
|
+
"lifecycleStatus",
|
|
152
|
+
input.result === "abort" ? "aborted" : "completed",
|
|
153
|
+
);
|
|
154
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
155
|
+
appendProcessEvent(writes, process, {
|
|
156
|
+
eventType: input.result === "abort" ? "process_aborted" : "process_completed",
|
|
157
|
+
level: "info",
|
|
158
|
+
message: input.message ?? "Waiting condition completed the process",
|
|
159
|
+
});
|
|
160
|
+
return accept({ writes });
|
|
161
|
+
}
|
|
162
|
+
const failures = input.result === "retry" ? wait.failures + 1 : 0;
|
|
163
|
+
const message = input.message ?? null;
|
|
164
|
+
writeTurnWait(writes, process, {
|
|
165
|
+
...wait,
|
|
166
|
+
revision: wait.revision + 1,
|
|
167
|
+
status: input.result === "error" ? "error" : "waiting",
|
|
168
|
+
failures,
|
|
169
|
+
message,
|
|
170
|
+
nextCheckAt:
|
|
171
|
+
input.now +
|
|
172
|
+
(failures
|
|
173
|
+
? Math.min(300_000, input.pollIntervalMs * 2 ** Math.min(failures, 8))
|
|
174
|
+
: input.pollIntervalMs),
|
|
175
|
+
});
|
|
176
|
+
if (input.result === "error")
|
|
177
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "error");
|
|
178
|
+
if (message !== wait.message)
|
|
179
|
+
appendProcessEvent(writes, process, {
|
|
180
|
+
eventType: message ? "turn_wait_failed" : "turn_wait_recovered",
|
|
181
|
+
level: message ? "warn" : "info",
|
|
182
|
+
message: message ?? "Waiting condition recovered",
|
|
183
|
+
data: { turnId: wait.turnId, retryable: input.result === "retry", safeSummary: message },
|
|
184
|
+
});
|
|
185
|
+
writes.preserveUpdatedAt =
|
|
186
|
+
input.result !== "error" &&
|
|
187
|
+
message === wait.message &&
|
|
188
|
+
writes.changedFields.every((field) => field === "metadata");
|
|
189
|
+
return accept({ writes });
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export const RetryTurnWait = defineOperation<
|
|
194
|
+
"retry_turn_wait",
|
|
195
|
+
DecisionMetadata & { instanceId: string; actor?: Actor },
|
|
196
|
+
void
|
|
197
|
+
>({
|
|
198
|
+
kind: "retry_turn_wait",
|
|
199
|
+
label: "Retry waiting condition",
|
|
200
|
+
admission: "new_turn",
|
|
201
|
+
decide({ process }, input) {
|
|
202
|
+
const wait = pendingTurnWait(process);
|
|
203
|
+
if (!wait || wait.status !== "error" || process.lifecycleStatus !== "error")
|
|
204
|
+
return reject("retry_target_missing", "No failed waiting condition is current");
|
|
205
|
+
const writes = createWrites();
|
|
206
|
+
writeTurnWait(writes, process, {
|
|
207
|
+
...wait,
|
|
208
|
+
status: "waiting",
|
|
209
|
+
revision: wait.revision + 1,
|
|
210
|
+
nextCheckAt: 0,
|
|
211
|
+
failures: 0,
|
|
212
|
+
message: null,
|
|
213
|
+
metadata: { ...wait.metadata, ...modelOverrideMetadata(input) },
|
|
214
|
+
});
|
|
215
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "waiting");
|
|
216
|
+
appendProcessEvent(writes, process, {
|
|
217
|
+
eventType: "turn_wait_retry",
|
|
218
|
+
level: "info",
|
|
219
|
+
message: "Waiting condition retry requested",
|
|
220
|
+
data: { turnId: wait.turnId },
|
|
221
|
+
});
|
|
222
|
+
stampActorOnEvents(writes, input.actor, "turn_wait_retry");
|
|
223
|
+
return accept({ writes });
|
|
224
|
+
},
|
|
225
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
|
+
import type {
|
|
3
|
+
ProcessModelConfigPatch,
|
|
4
|
+
ProcessModelConfigResponseBody,
|
|
5
|
+
} from "@leitwerk-dev/protocol/http-contracts";
|
|
6
|
+
import { prepareProcessModelConfig } from "../../process-model-config.js";
|
|
7
|
+
import { accept, reject } from "../decision.js";
|
|
8
|
+
import { defineOperation } from "../operation.js";
|
|
9
|
+
import { appendProcessEvent, applyProcessPatchField, createWrites } from "../writes/writes.js";
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const UpdateModelConfig = defineOperation<
|
|
13
|
+
"update_model_config",
|
|
14
|
+
{
|
|
15
|
+
instanceId: string;
|
|
16
|
+
patch: ProcessModelConfigPatch;
|
|
17
|
+
actor: Actor;
|
|
18
|
+
},
|
|
19
|
+
ProcessModelConfigResponseBody
|
|
20
|
+
>({
|
|
21
|
+
kind: "update_model_config",
|
|
22
|
+
decide(ctx, input) {
|
|
23
|
+
let prepared: ReturnType<typeof prepareProcessModelConfig>;
|
|
24
|
+
try {
|
|
25
|
+
prepared = prepareProcessModelConfig({
|
|
26
|
+
process: ctx.process,
|
|
27
|
+
patch: input.patch,
|
|
28
|
+
policy: ctx.deps.processModelPolicy,
|
|
29
|
+
availability: ctx.deps.getModelAvailabilitySnapshot(),
|
|
30
|
+
});
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return reject(
|
|
33
|
+
"invalid_model_config",
|
|
34
|
+
error instanceof Error ? error.message : "Invalid model configuration",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const writes = createWrites();
|
|
38
|
+
applyProcessPatchField(
|
|
39
|
+
writes,
|
|
40
|
+
ctx.process,
|
|
41
|
+
"defaultModelProfileId",
|
|
42
|
+
prepared.settings.defaultModelProfileId,
|
|
43
|
+
);
|
|
44
|
+
applyProcessPatchField(
|
|
45
|
+
writes,
|
|
46
|
+
ctx.process,
|
|
47
|
+
"turnConfigsJson",
|
|
48
|
+
prepared.settings.turnConfigsJson,
|
|
49
|
+
);
|
|
50
|
+
appendProcessEvent(writes, ctx.process, {
|
|
51
|
+
eventType: "model_configuration_changed",
|
|
52
|
+
level: "info",
|
|
53
|
+
message: "Model defaults updated for future executions",
|
|
54
|
+
data: {
|
|
55
|
+
actor: input.actor,
|
|
56
|
+
patch: input.patch,
|
|
57
|
+
previous: {
|
|
58
|
+
defaultModelProfileId: ctx.process.defaultModelProfileId,
|
|
59
|
+
turnConfigsJson: ctx.process.turnConfigsJson,
|
|
60
|
+
},
|
|
61
|
+
settings: prepared.settings,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return accept({ writes, data: { modelConfiguration: prepared.modelConfiguration } });
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
OperationInputBase,
|
|
21
21
|
OperationSpec,
|
|
22
22
|
} from "./operation.js";
|
|
23
|
+
import { deferTurnWaitStarts, pendingTurnWait } from "./turn-wait-state.js";
|
|
23
24
|
import type {
|
|
24
25
|
EngineErrorCode,
|
|
25
26
|
ProcessEngineDeps,
|
|
@@ -162,6 +163,7 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
162
163
|
* commits all writes in one SQLite transaction, then derives a complete
|
|
163
164
|
* reaction list for the post-commit stage.
|
|
164
165
|
*/
|
|
166
|
+
deferTurnWaitStarts(deps.processGraphs, initialProcess, decision.writes, decision.metadata);
|
|
165
167
|
const mappedPlan = await planMappedTurnEntries({
|
|
166
168
|
processGraphs: deps.processGraphs,
|
|
167
169
|
registry: deps.getProcessActionRegistry?.(),
|
|
@@ -173,6 +175,7 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
173
175
|
if (!mappedPlan.ok) {
|
|
174
176
|
return { ok: false, stage: "pre_commit", code: mappedPlan.code, message: mappedPlan.message };
|
|
175
177
|
}
|
|
178
|
+
deferTurnWaitStarts(deps.processGraphs, initialProcess, decision.writes, decision.metadata);
|
|
176
179
|
const baselineWrites = structuredClone(decision.writes);
|
|
177
180
|
const runModelPreparation = async (availability: ModelStatusCacheSnapshot) => {
|
|
178
181
|
const candidateProcess: ProcessInstance = {
|
|
@@ -184,13 +187,24 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
184
187
|
write.kind === "create" && write.input.turnType === "llm",
|
|
185
188
|
);
|
|
186
189
|
const shouldResolveSelection =
|
|
190
|
+
!pendingTurnWait(candidateProcess) &&
|
|
187
191
|
!!candidateProcess.selectedTurnId &&
|
|
188
192
|
(!!createdStart ||
|
|
189
193
|
candidateProcess.selectedTurnId !== initialProcess.selectedTurnId ||
|
|
190
194
|
(candidateProcess.lifecycleStatus === "active" &&
|
|
191
195
|
initialProcess.lifecycleStatus !== "active") ||
|
|
192
196
|
Object.hasOwn(decision.metadata ?? {}, "nextTurnModelProfileId"));
|
|
193
|
-
if (
|
|
197
|
+
if (
|
|
198
|
+
(candidateProcess.selectedTurnId &&
|
|
199
|
+
deps.processGraphs
|
|
200
|
+
.get(candidateProcess.processId)
|
|
201
|
+
?.turns.get(candidateProcess.selectedTurnId)?.definition.kind !== "llm") ||
|
|
202
|
+
(!candidateProcess.selectedTurnId &&
|
|
203
|
+
!(
|
|
204
|
+
candidateProcess.lifecycleStatus === "discovered" &&
|
|
205
|
+
candidateProcess.selectedTurnModelSource === "launch_override"
|
|
206
|
+
))
|
|
207
|
+
) {
|
|
194
208
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelProfileId", null);
|
|
195
209
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelKind", null);
|
|
196
210
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelSource", null);
|
|
@@ -202,10 +216,12 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
202
216
|
availability,
|
|
203
217
|
startKind: createdStart?.input.startKind,
|
|
204
218
|
initialSelection:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
(decision.writes.waitForAdmission === pendingTurnWait(initialProcess)?.id &&
|
|
220
|
+
pendingTurnWait(initialProcess)?.initialSelection === true) ||
|
|
221
|
+
(createdStart?.input.startKind === "selected_turn" &&
|
|
222
|
+
initialProcess.selectedTurnId === null &&
|
|
223
|
+
initialProcess.lifecycleStatus === "discovered" &&
|
|
224
|
+
initialProcess.planRevision === 0),
|
|
209
225
|
...(Object.hasOwn(decision.metadata ?? {}, "nextTurnModelProfileId")
|
|
210
226
|
? { modelOverride: decision.metadata?.nextTurnModelProfileId ?? null }
|
|
211
227
|
: {}),
|