@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
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MappedTurnItemRef,
|
|
3
|
+
ProcessInstance,
|
|
4
|
+
ProcessProject,
|
|
5
|
+
TurnOutcomePayload,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
7
|
+
import {
|
|
8
|
+
collectMappedResults,
|
|
9
|
+
freezeMappedItems,
|
|
10
|
+
type MappedLlmTurnSpec,
|
|
11
|
+
type MappedTurnServerContext,
|
|
12
|
+
SafeOutcomePlanningError,
|
|
13
|
+
yieldMappedItemResult,
|
|
14
|
+
} from "@leitwerk-dev/process-sdk";
|
|
15
|
+
import { generateId } from "../db/repo-helpers.js";
|
|
16
|
+
import type { RepositoryBundle } from "../db/repositories.js";
|
|
17
|
+
import type { ProcessActionRegistry } from "../process-action-registry.js";
|
|
18
|
+
import type { ProcessGraphRegistry } from "../process-graph.js";
|
|
19
|
+
import { deferTurnWaitStarts } from "./turn-wait-state.js";
|
|
20
|
+
import { buildServerTransitionWrites } from "./writes/build-server-transition-writes.js";
|
|
21
|
+
import { reserveSelectedTurnStart } from "./writes/reserve-selected-turn-start.js";
|
|
22
|
+
import {
|
|
23
|
+
appendProcessEvent,
|
|
24
|
+
applyProcessPatchField,
|
|
25
|
+
createWrites,
|
|
26
|
+
isWriteBuildFailure,
|
|
27
|
+
mergeWrites,
|
|
28
|
+
type WriteBuildFailure,
|
|
29
|
+
type WriteBuildResult,
|
|
30
|
+
type Writes,
|
|
31
|
+
} from "./writes/writes.js";
|
|
32
|
+
|
|
33
|
+
type MappedRunRepo = RepositoryBundle["mappedRuns"];
|
|
34
|
+
type Registry = Pick<ProcessActionRegistry, "getTurnDefinition" | "resolveContextData">;
|
|
35
|
+
|
|
36
|
+
/** Bounds consecutive empty mapped turns routed within one decision. */
|
|
37
|
+
const MAX_EMPTY_MAPPED_ENTRIES = 16;
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
export function getMappedTurnSpec(
|
|
41
|
+
registry: Pick<ProcessActionRegistry, "getTurnDefinition"> | undefined,
|
|
42
|
+
processId: string,
|
|
43
|
+
turnId: string | null,
|
|
44
|
+
): MappedLlmTurnSpec | undefined {
|
|
45
|
+
if (!registry || !turnId) return undefined;
|
|
46
|
+
const turn = registry.getTurnDefinition(processId, turnId);
|
|
47
|
+
return turn?.kind === "llm" ? turn.forEach : undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function failure(code: string, message: string): WriteBuildFailure {
|
|
51
|
+
return { ok: false, code, message };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function planningFailure(error: unknown, code: string): WriteBuildFailure {
|
|
55
|
+
if (error instanceof SafeOutcomePlanningError) return failure(error.code, error.message);
|
|
56
|
+
throw error instanceof Error ? error : new Error(`${code}: ${String(error)}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function serverContext(
|
|
60
|
+
registry: Registry,
|
|
61
|
+
process: ProcessInstance,
|
|
62
|
+
projects: readonly ProcessProject[],
|
|
63
|
+
): MappedTurnServerContext {
|
|
64
|
+
const { params, state } = registry.resolveContextData(process.processId, process);
|
|
65
|
+
return { process, projects, params, state };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function appendInto(target: Writes, source: Writes): void {
|
|
69
|
+
Object.assign(target, mergeWrites(target, source));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function collectAndRoute(input: {
|
|
73
|
+
processGraphs: ProcessGraphRegistry;
|
|
74
|
+
process: ProcessInstance;
|
|
75
|
+
ctx: MappedTurnServerContext;
|
|
76
|
+
spec: MappedLlmTurnSpec;
|
|
77
|
+
turnId: string;
|
|
78
|
+
runId: string;
|
|
79
|
+
resultJsons: readonly string[];
|
|
80
|
+
}): Promise<WriteBuildResult> {
|
|
81
|
+
let collected: Awaited<ReturnType<typeof collectMappedResults>>;
|
|
82
|
+
try {
|
|
83
|
+
collected = await collectMappedResults({
|
|
84
|
+
turnId: input.turnId,
|
|
85
|
+
spec: input.spec,
|
|
86
|
+
ctx: input.ctx,
|
|
87
|
+
resultJsons: input.resultJsons,
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return planningFailure(error, "mapped_collect_failed");
|
|
91
|
+
}
|
|
92
|
+
const writes = buildServerTransitionWrites(input.processGraphs, input.process, {
|
|
93
|
+
turnId: collected.route.nextTurnId ?? null,
|
|
94
|
+
...(collected.route.lifecycleStatus
|
|
95
|
+
? { lifecycleStatus: collected.route.lifecycleStatus }
|
|
96
|
+
: {}),
|
|
97
|
+
trigger: collected.route.trigger,
|
|
98
|
+
state: collected.state,
|
|
99
|
+
});
|
|
100
|
+
if (isWriteBuildFailure(writes)) return writes;
|
|
101
|
+
appendProcessEvent(writes, input.process, {
|
|
102
|
+
eventType: "mapped_run_collected",
|
|
103
|
+
level: "info",
|
|
104
|
+
message: `Collected ${input.resultJsons.length} result(s) for ${input.turnId}`,
|
|
105
|
+
data: {
|
|
106
|
+
runId: input.runId,
|
|
107
|
+
turnId: input.turnId,
|
|
108
|
+
itemCount: input.resultJsons.length,
|
|
109
|
+
trigger: collected.route.trigger,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
return writes;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Freezes items for every newly selected mapped turn in `writes`, before model
|
|
117
|
+
* preflight. A non-empty run reserves only its first item; an empty run collects
|
|
118
|
+
* and routes immediately. Leaving a mapped turn by any other route aborts its run.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export async function planMappedTurnEntries(input: {
|
|
122
|
+
processGraphs: ProcessGraphRegistry;
|
|
123
|
+
registry: Registry | undefined;
|
|
124
|
+
mappedRuns: MappedRunRepo | undefined;
|
|
125
|
+
projects: Pick<RepositoryBundle["projects"], "listByInstance">;
|
|
126
|
+
process: ProcessInstance;
|
|
127
|
+
writes: Writes;
|
|
128
|
+
}): Promise<{ ok: true } | WriteBuildFailure> {
|
|
129
|
+
const { writes } = input;
|
|
130
|
+
const active = input.mappedRuns?.getActiveByInstance(input.process.id) ?? null;
|
|
131
|
+
let activeAborted = false;
|
|
132
|
+
for (let entry = 0; entry <= MAX_EMPTY_MAPPED_ENTRIES; entry += 1) {
|
|
133
|
+
// An empty mapped run may route straight into another gated turn.
|
|
134
|
+
deferTurnWaitStarts(input.processGraphs, input.process, writes);
|
|
135
|
+
const candidate: ProcessInstance = { ...input.process, ...writes.processPatch };
|
|
136
|
+
const startIndex = writes.turnStartWrites.findIndex(
|
|
137
|
+
(write) =>
|
|
138
|
+
write.kind === "create" &&
|
|
139
|
+
write.input.turnType === "llm" &&
|
|
140
|
+
write.input.startKind === "selected_turn" &&
|
|
141
|
+
!write.input.iteration &&
|
|
142
|
+
write.input.turnId === candidate.selectedTurnId,
|
|
143
|
+
);
|
|
144
|
+
const start = startIndex >= 0 ? writes.turnStartWrites[startIndex] : undefined;
|
|
145
|
+
const spec =
|
|
146
|
+
start?.kind === "create"
|
|
147
|
+
? getMappedTurnSpec(input.registry, candidate.processId, start.input.turnId)
|
|
148
|
+
: undefined;
|
|
149
|
+
if (!start || start.kind !== "create" || !spec || !input.registry) {
|
|
150
|
+
const leavesActiveRun =
|
|
151
|
+
active !== null &&
|
|
152
|
+
!activeAborted &&
|
|
153
|
+
!writes.mappedRunWrites.some((write) => write.kind === "complete_item") &&
|
|
154
|
+
(candidate.selectedTurnId !== active.turnId ||
|
|
155
|
+
candidate.lifecycleStatus === "completed" ||
|
|
156
|
+
candidate.lifecycleStatus === "aborted");
|
|
157
|
+
if (leavesActiveRun) writes.mappedRunWrites.push({ kind: "abort_active" });
|
|
158
|
+
return { ok: true };
|
|
159
|
+
}
|
|
160
|
+
if (entry === MAX_EMPTY_MAPPED_ENTRIES) {
|
|
161
|
+
return failure("mapped_turn_loop", "Too many consecutive empty mapped turns");
|
|
162
|
+
}
|
|
163
|
+
if (!input.mappedRuns) {
|
|
164
|
+
return failure("mapped_runs_unavailable", "Mapped turn storage is not available");
|
|
165
|
+
}
|
|
166
|
+
if (active && !activeAborted) {
|
|
167
|
+
writes.mappedRunWrites.push({ kind: "abort_active" });
|
|
168
|
+
activeAborted = true;
|
|
169
|
+
}
|
|
170
|
+
const turnId = start.input.turnId;
|
|
171
|
+
const projects = input.projects.listByInstance(input.process.id);
|
|
172
|
+
let ctx = serverContext(input.registry, candidate, projects);
|
|
173
|
+
let frozen: ReturnType<typeof freezeMappedItems>;
|
|
174
|
+
try {
|
|
175
|
+
frozen = freezeMappedItems(turnId, spec, ctx);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return planningFailure(error, "invalid_mapped_items");
|
|
178
|
+
}
|
|
179
|
+
const runId = generateId("mlr");
|
|
180
|
+
writes.mappedRunWrites.push({
|
|
181
|
+
kind: "create",
|
|
182
|
+
input: {
|
|
183
|
+
id: runId,
|
|
184
|
+
instanceId: input.process.id,
|
|
185
|
+
turnId,
|
|
186
|
+
status: frozen.items.length > 0 ? "active" : "completed",
|
|
187
|
+
items: frozen.items,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
appendProcessEvent(writes, candidate, {
|
|
191
|
+
eventType: "mapped_run_started",
|
|
192
|
+
level: "info",
|
|
193
|
+
message: `Froze ${frozen.items.length} item(s) for ${turnId}`,
|
|
194
|
+
data: { runId, turnId, itemCount: frozen.items.length },
|
|
195
|
+
});
|
|
196
|
+
if (frozen.state !== undefined) {
|
|
197
|
+
applyProcessPatchField(writes, candidate, "stateJson", JSON.stringify(frozen.state));
|
|
198
|
+
ctx = { ...ctx, state: frozen.state };
|
|
199
|
+
}
|
|
200
|
+
const first = frozen.items[0];
|
|
201
|
+
if (first) {
|
|
202
|
+
start.input.iteration = { runId, itemKey: first.itemKey, itemIndex: 0 };
|
|
203
|
+
return { ok: true };
|
|
204
|
+
}
|
|
205
|
+
writes.turnStartWrites.splice(startIndex, 1);
|
|
206
|
+
const routed = await collectAndRoute({
|
|
207
|
+
processGraphs: input.processGraphs,
|
|
208
|
+
process: { ...input.process, ...writes.processPatch },
|
|
209
|
+
ctx,
|
|
210
|
+
spec,
|
|
211
|
+
turnId,
|
|
212
|
+
runId,
|
|
213
|
+
resultJsons: [],
|
|
214
|
+
});
|
|
215
|
+
if (isWriteBuildFailure(routed)) return routed;
|
|
216
|
+
appendInto(writes, routed);
|
|
217
|
+
}
|
|
218
|
+
return failure("mapped_turn_loop", "Too many consecutive empty mapped turns");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Records one item's validated result. Reserves the next item's start, or,
|
|
223
|
+
* after the last item, collects all results in order and applies the single
|
|
224
|
+
* collection route.
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
export async function buildMappedItemOutcomeWrites(input: {
|
|
228
|
+
processGraphs: ProcessGraphRegistry;
|
|
229
|
+
registry: Registry;
|
|
230
|
+
mappedRuns: MappedRunRepo | undefined;
|
|
231
|
+
process: ProcessInstance;
|
|
232
|
+
projects: readonly ProcessProject[];
|
|
233
|
+
payload: TurnOutcomePayload;
|
|
234
|
+
spec: MappedLlmTurnSpec;
|
|
235
|
+
iteration: MappedTurnItemRef | null | undefined;
|
|
236
|
+
prepared?: unknown;
|
|
237
|
+
}): Promise<WriteBuildResult> {
|
|
238
|
+
const { payload, iteration } = input;
|
|
239
|
+
if (!input.mappedRuns) {
|
|
240
|
+
return failure("mapped_runs_unavailable", "Mapped turn storage is not available");
|
|
241
|
+
}
|
|
242
|
+
if (!iteration) {
|
|
243
|
+
return failure("mapped_item_missing", `Turn '${payload.turnId}' has no active mapped item`);
|
|
244
|
+
}
|
|
245
|
+
const run = input.mappedRuns.getById(iteration.runId);
|
|
246
|
+
const item = input.mappedRuns.getItem(iteration.runId, iteration.itemIndex);
|
|
247
|
+
if (
|
|
248
|
+
!run ||
|
|
249
|
+
!item ||
|
|
250
|
+
run.status !== "active" ||
|
|
251
|
+
run.turnId !== payload.turnId ||
|
|
252
|
+
run.nextIndex !== iteration.itemIndex ||
|
|
253
|
+
item.itemKey !== iteration.itemKey ||
|
|
254
|
+
item.status !== "pending"
|
|
255
|
+
) {
|
|
256
|
+
return failure(
|
|
257
|
+
"stale_mapped_item",
|
|
258
|
+
`Mapped item '${iteration.itemKey}' is no longer the current item of '${payload.turnId}'`,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
const ctx = serverContext(input.registry, input.process, input.projects);
|
|
262
|
+
let resultJson: string;
|
|
263
|
+
try {
|
|
264
|
+
resultJson = await yieldMappedItemResult({
|
|
265
|
+
turnId: payload.turnId,
|
|
266
|
+
spec: input.spec,
|
|
267
|
+
ctx,
|
|
268
|
+
iteration: {
|
|
269
|
+
runId: run.id,
|
|
270
|
+
itemKey: item.itemKey,
|
|
271
|
+
itemLabel: item.label,
|
|
272
|
+
itemIndex: item.itemIndex,
|
|
273
|
+
itemCount: run.itemCount,
|
|
274
|
+
item: JSON.parse(item.itemJson) as unknown,
|
|
275
|
+
},
|
|
276
|
+
event: {
|
|
277
|
+
turnRecordId: payload.turnRecordId,
|
|
278
|
+
turnId: payload.turnId,
|
|
279
|
+
outcome: payload.outcome,
|
|
280
|
+
params: payload.params ?? {},
|
|
281
|
+
turnResultMarkdown: payload.turnResultMarkdown ?? null,
|
|
282
|
+
...(input.prepared !== undefined ? { prepared: input.prepared } : {}),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
} catch (error) {
|
|
286
|
+
return planningFailure(error, "invalid_mapped_result");
|
|
287
|
+
}
|
|
288
|
+
const writes = createWrites();
|
|
289
|
+
writes.mappedRunWrites.push({
|
|
290
|
+
kind: "complete_item",
|
|
291
|
+
input: {
|
|
292
|
+
runId: run.id,
|
|
293
|
+
itemIndex: item.itemIndex,
|
|
294
|
+
outcome: payload.outcome,
|
|
295
|
+
resultJson,
|
|
296
|
+
turnRecordId: payload.turnRecordId,
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
const nextIndex = item.itemIndex + 1;
|
|
300
|
+
if (nextIndex < run.itemCount) {
|
|
301
|
+
const next = input.mappedRuns.getItem(run.id, nextIndex);
|
|
302
|
+
if (!next) return failure("stale_mapped_item", `Mapped run '${run.id}' lost item ${nextIndex}`);
|
|
303
|
+
reserveSelectedTurnStart(writes, input.process, payload.turnId, "llm", {
|
|
304
|
+
runId: run.id,
|
|
305
|
+
itemKey: next.itemKey,
|
|
306
|
+
itemIndex: nextIndex,
|
|
307
|
+
});
|
|
308
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
309
|
+
return writes;
|
|
310
|
+
}
|
|
311
|
+
const resultJsons = input.mappedRuns
|
|
312
|
+
.listItems(run.id)
|
|
313
|
+
.map((stored) => (stored.itemIndex === item.itemIndex ? resultJson : stored.resultJson));
|
|
314
|
+
if (resultJsons.some((json) => json === null)) {
|
|
315
|
+
return failure("stale_mapped_item", `Mapped run '${run.id}' is missing item results`);
|
|
316
|
+
}
|
|
317
|
+
const routed = await collectAndRoute({
|
|
318
|
+
processGraphs: input.processGraphs,
|
|
319
|
+
process: input.process,
|
|
320
|
+
ctx,
|
|
321
|
+
spec: input.spec,
|
|
322
|
+
turnId: payload.turnId,
|
|
323
|
+
runId: run.id,
|
|
324
|
+
resultJsons: resultJsons as string[],
|
|
325
|
+
});
|
|
326
|
+
if (isWriteBuildFailure(routed)) return routed;
|
|
327
|
+
return mergeWrites(writes, routed);
|
|
328
|
+
}
|
|
@@ -59,7 +59,7 @@ export interface OperationSpec<TKind extends string, TInput extends OperationInp
|
|
|
59
59
|
/** @internal */
|
|
60
60
|
decide: DecideFunction<TInput, TData>;
|
|
61
61
|
|
|
62
|
-
/** Runs after
|
|
62
|
+
/** Runs after durable recording and lock release, even if reaction derivation fails. @internal */
|
|
63
63
|
afterRecord?: AfterRecordFunction<TInput, TData>;
|
|
64
64
|
/** @internal */
|
|
65
65
|
messages?: OperationMessages | MessageResolver<TInput>;
|
|
@@ -9,6 +9,8 @@ export interface AcceptWorkerTurnStartInput {
|
|
|
9
9
|
workerLeaseId: string;
|
|
10
10
|
startRecordId: string;
|
|
11
11
|
proposedTurnRecordId: string;
|
|
12
|
+
/** @internal */
|
|
13
|
+
onRecorded?: (turnRecordId: string) => void;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
function receiptMatchesStart(
|
|
@@ -62,6 +64,9 @@ export const AcceptWorkerTurnStart = defineOperation<
|
|
|
62
64
|
>({
|
|
63
65
|
kind: "accept_worker_turn_start",
|
|
64
66
|
label: "Accept worker turn start",
|
|
67
|
+
afterRecord(input, data) {
|
|
68
|
+
input.onRecorded?.(data.turnRecordId);
|
|
69
|
+
},
|
|
65
70
|
decide(ctx, input) {
|
|
66
71
|
if (
|
|
67
72
|
ctx.process.lifecycleStatus !== "active" ||
|
|
@@ -161,6 +166,7 @@ export const AcceptWorkerTurnStart = defineOperation<
|
|
|
161
166
|
acceptedWorkerLeaseId: lease.id,
|
|
162
167
|
modelProfileId: acceptedLlmStart?.model.profileId ?? null,
|
|
163
168
|
modelSelectionProvenance: acceptedLlmStart?.modelSelectionProvenance ?? null,
|
|
169
|
+
iteration: start.iteration ?? null,
|
|
164
170
|
},
|
|
165
171
|
},
|
|
166
172
|
],
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveTurnContinuationUserPrompt,
|
|
10
10
|
} from "@leitwerk-dev/protocol";
|
|
11
11
|
import type { ReadonlyPiSessionTree } from "../../pi-session-tree.js";
|
|
12
|
-
import { accept, reject } from "../decision.js";
|
|
12
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
13
13
|
import { defineOperation } from "../operation.js";
|
|
14
14
|
import { readCurrentPrimaryPathLeafEntryId } from "../state-json.js";
|
|
15
15
|
import type { ProcessEngine, ProcessEngineDeps } from "../types.js";
|
|
@@ -138,18 +138,7 @@ export const ContinueFailedTurn = defineOperation<
|
|
|
138
138
|
stampActorOnEvents(writes, input.options?.actor, "continue_scheduled");
|
|
139
139
|
return accept({
|
|
140
140
|
writes,
|
|
141
|
-
metadata:
|
|
142
|
-
input.options?.nextTurnModelProfileId !== undefined ||
|
|
143
|
-
input.options?.providerOptions !== undefined
|
|
144
|
-
? {
|
|
145
|
-
...(input.options.nextTurnModelProfileId !== undefined
|
|
146
|
-
? { nextTurnModelProfileId: input.options.nextTurnModelProfileId }
|
|
147
|
-
: {}),
|
|
148
|
-
...(input.options.providerOptions !== undefined
|
|
149
|
-
? { providerOptions: input.options.providerOptions }
|
|
150
|
-
: {}),
|
|
151
|
-
}
|
|
152
|
-
: undefined,
|
|
141
|
+
metadata: modelOverrideMetadata(input.options),
|
|
153
142
|
});
|
|
154
143
|
},
|
|
155
144
|
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ProcessObservationUpdate } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { planCancelScheduledAction } from "../../future-execution/transition-planner.js";
|
|
3
|
+
import { resolveCurrentExecutionTurnRecordId } from "../../process-execution.js";
|
|
4
|
+
import { accept, reject } from "../decision.js";
|
|
5
|
+
import { defineOperation } from "../operation.js";
|
|
6
|
+
import { writeTurnWait } from "../turn-wait-state.js";
|
|
7
|
+
import { supersedeExecution } from "../writes/build-process-abort-writes.js";
|
|
8
|
+
import { reserveSelectedTurnStart } from "../writes/reserve-selected-turn-start.js";
|
|
9
|
+
import {
|
|
10
|
+
appendProcessEvent,
|
|
11
|
+
applyMetadataPatch,
|
|
12
|
+
applyProcessPatchField,
|
|
13
|
+
createWrites,
|
|
14
|
+
} from "../writes/writes.js";
|
|
15
|
+
|
|
16
|
+
/** Background reads happen outside the process lock; their writes never bypass coordination. @internal */
|
|
17
|
+
export const ApplyProcessObservation = defineOperation<
|
|
18
|
+
"process_observation",
|
|
19
|
+
ProcessObservationUpdate & { instanceId: string },
|
|
20
|
+
void
|
|
21
|
+
>({
|
|
22
|
+
kind: "process_observation",
|
|
23
|
+
label: "Record integration observation",
|
|
24
|
+
decide({ process, deps }, input) {
|
|
25
|
+
const expected = input.expected;
|
|
26
|
+
if (
|
|
27
|
+
expected.id !== process.id ||
|
|
28
|
+
expected.processId !== process.processId ||
|
|
29
|
+
expected.planRevision !== process.planRevision ||
|
|
30
|
+
expected.paramsJson !== process.paramsJson ||
|
|
31
|
+
expected.stateJson !== process.stateJson ||
|
|
32
|
+
expected.selectedTurnId !== process.selectedTurnId ||
|
|
33
|
+
expected.lifecycleStatus !== process.lifecycleStatus ||
|
|
34
|
+
JSON.stringify(expected.currentExecution) !== JSON.stringify(process.currentExecution) ||
|
|
35
|
+
Object.keys(input.metadata ?? {}).some(
|
|
36
|
+
(key) =>
|
|
37
|
+
JSON.stringify(expected.metadata?.[key]) !== JSON.stringify(process.metadata?.[key]),
|
|
38
|
+
) ||
|
|
39
|
+
(input.projectsJson !== undefined &&
|
|
40
|
+
input.projectsJson !== JSON.stringify(deps.projects.listByInstance(process.id)))
|
|
41
|
+
)
|
|
42
|
+
return reject("observation_superseded", "The process changed during the integration read");
|
|
43
|
+
const definition = deps.processGraphs.get(process.processId);
|
|
44
|
+
if (!definition) return reject("process_not_found", "Process definition is unavailable");
|
|
45
|
+
const writes = createWrites({ preserveUpdatedAt: input.preserveUpdatedAt });
|
|
46
|
+
if (input.state !== undefined) {
|
|
47
|
+
const state = definition.stateCodec.parse(input.state);
|
|
48
|
+
applyProcessPatchField(
|
|
49
|
+
writes,
|
|
50
|
+
process,
|
|
51
|
+
"stateJson",
|
|
52
|
+
JSON.stringify(definition.stateCodec.serialize(state)),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (input.metadata)
|
|
56
|
+
applyMetadataPatch(writes, process, { ...process.metadata, ...input.metadata });
|
|
57
|
+
if (input.lifecycleStatus || input.interrupt) {
|
|
58
|
+
if (["completed", "aborted"].includes(process.lifecycleStatus))
|
|
59
|
+
return reject("invalid_transition", "Terminal processes cannot resume maintenance");
|
|
60
|
+
if (input.interrupt && !definition.turns.has(input.interrupt.turnId))
|
|
61
|
+
return reject("invalid_transition", "Maintenance recovery turn is unavailable");
|
|
62
|
+
const recordId = resolveCurrentExecutionTurnRecordId(process, deps.turnStarts);
|
|
63
|
+
const record = recordId ? deps.turnRecords.getById(recordId) : null;
|
|
64
|
+
const start =
|
|
65
|
+
process.currentExecution?.kind === "worker_start"
|
|
66
|
+
? deps.turnStarts.getById(process.currentExecution.id)
|
|
67
|
+
: null;
|
|
68
|
+
supersedeExecution(writes, record, start);
|
|
69
|
+
for (const execution of deps.futureExecutions.listByInstance(process.id)) {
|
|
70
|
+
const plan = planCancelScheduledAction(execution, process.id);
|
|
71
|
+
if (plan) writes.futureExecutionPlans.push(plan);
|
|
72
|
+
}
|
|
73
|
+
writeTurnWait(
|
|
74
|
+
writes,
|
|
75
|
+
{ ...process, metadata: writes.processPatch.metadata ?? process.metadata },
|
|
76
|
+
null,
|
|
77
|
+
);
|
|
78
|
+
applyProcessPatchField(writes, process, "currentExecution", null);
|
|
79
|
+
applyProcessPatchField(
|
|
80
|
+
writes,
|
|
81
|
+
process,
|
|
82
|
+
"selectedTurnId",
|
|
83
|
+
input.lifecycleStatus ? null : (input.interrupt?.turnId ?? process.selectedTurnId),
|
|
84
|
+
);
|
|
85
|
+
applyProcessPatchField(
|
|
86
|
+
writes,
|
|
87
|
+
process,
|
|
88
|
+
"lifecycleStatus",
|
|
89
|
+
input.lifecycleStatus ?? "waiting",
|
|
90
|
+
);
|
|
91
|
+
if (input.interrupt && !input.lifecycleStatus) {
|
|
92
|
+
const turn = definition.turns.get(input.interrupt.turnId)?.definition;
|
|
93
|
+
if (!turn || (turn.kind !== "llm" && turn.kind !== "automatic") || !turn.waitFor)
|
|
94
|
+
return reject(
|
|
95
|
+
"invalid_transition",
|
|
96
|
+
"Maintenance recovery requires an existing gated worker turn",
|
|
97
|
+
);
|
|
98
|
+
reserveSelectedTurnStart(
|
|
99
|
+
writes,
|
|
100
|
+
{ ...process, ...writes.processPatch },
|
|
101
|
+
input.interrupt.turnId,
|
|
102
|
+
turn.kind,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
writes.workerIntent = {
|
|
106
|
+
kind: "stop_with_reason",
|
|
107
|
+
reason: input.interrupt?.reason ?? "MR maintenance finished",
|
|
108
|
+
};
|
|
109
|
+
appendProcessEvent(writes, process, {
|
|
110
|
+
eventType: input.lifecycleStatus
|
|
111
|
+
? `process_${input.lifecycleStatus}`
|
|
112
|
+
: "maintenance_interrupted",
|
|
113
|
+
level: "info",
|
|
114
|
+
message: input.interrupt?.reason ?? "MR maintenance finished",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return accept({ writes });
|
|
118
|
+
},
|
|
119
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
2
|
import { buildRetryWrites } from "../../process-engine/writes/build-retry-writes.js";
|
|
3
3
|
import { stampActorOnEvents } from "../../process-engine/writes/writes.js";
|
|
4
|
-
import { accept, reject } from "../decision.js";
|
|
4
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
5
5
|
import { defineOperation } from "../operation.js";
|
|
6
6
|
|
|
7
7
|
export interface RetryFailedTurnInput {
|
|
@@ -49,17 +49,7 @@ export const RetryFailedTurn = defineOperation<"retry_failed_turn", RetryFailedT
|
|
|
49
49
|
stampActorOnEvents(writes, input.actor, "retry_scheduled");
|
|
50
50
|
return accept({
|
|
51
51
|
writes,
|
|
52
|
-
metadata:
|
|
53
|
-
input.nextTurnModelProfileId !== undefined || input.providerOptions !== undefined
|
|
54
|
-
? {
|
|
55
|
-
...(input.nextTurnModelProfileId !== undefined
|
|
56
|
-
? { nextTurnModelProfileId: input.nextTurnModelProfileId }
|
|
57
|
-
: {}),
|
|
58
|
-
...(input.providerOptions !== undefined
|
|
59
|
-
? { providerOptions: input.providerOptions }
|
|
60
|
-
: {}),
|
|
61
|
-
}
|
|
62
|
-
: undefined,
|
|
52
|
+
metadata: modelOverrideMetadata(input),
|
|
63
53
|
});
|
|
64
54
|
},
|
|
65
55
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
2
|
import { generateId } from "../../db/repo-helpers.js";
|
|
3
|
-
import { accept, reject } from "../decision.js";
|
|
3
|
+
import { accept, modelOverrideMetadata, reject } from "../decision.js";
|
|
4
4
|
import { defineOperation } from "../operation.js";
|
|
5
5
|
import {
|
|
6
6
|
appendProcessEvent,
|
|
@@ -44,7 +44,13 @@ export const RetryStartup = defineOperation<
|
|
|
44
44
|
const id = generateId("tsr");
|
|
45
45
|
const state =
|
|
46
46
|
failed.state.kind === "preparation_failed"
|
|
47
|
-
?
|
|
47
|
+
? {
|
|
48
|
+
...failed.state,
|
|
49
|
+
// A new operator retry must validate current inputs; the previous
|
|
50
|
+
// failure remains on its original start record.
|
|
51
|
+
code: "model_required" as const,
|
|
52
|
+
safeSummary: "LLM start requires retry preparation",
|
|
53
|
+
}
|
|
48
54
|
: failed.state.start.kind === "automatic"
|
|
49
55
|
? { kind: "starting" as const, start: failed.state.start }
|
|
50
56
|
: {
|
|
@@ -72,6 +78,7 @@ export const RetryStartup = defineOperation<
|
|
|
72
78
|
recoveryTurnRecordId: failed.recoveryTurnRecordId,
|
|
73
79
|
continuation: failed.continuation,
|
|
74
80
|
state,
|
|
81
|
+
iteration: failed.iteration ?? null,
|
|
75
82
|
},
|
|
76
83
|
});
|
|
77
84
|
applyProcessPatchField(writes, ctx.process, "currentExecution", { kind: "worker_start", id });
|
|
@@ -91,17 +98,7 @@ export const RetryStartup = defineOperation<
|
|
|
91
98
|
return accept({
|
|
92
99
|
writes,
|
|
93
100
|
data: { startRecordId: id },
|
|
94
|
-
metadata:
|
|
95
|
-
input.nextTurnModelProfileId !== undefined || input.providerOptions !== undefined
|
|
96
|
-
? {
|
|
97
|
-
...(input.nextTurnModelProfileId !== undefined
|
|
98
|
-
? { nextTurnModelProfileId: input.nextTurnModelProfileId }
|
|
99
|
-
: {}),
|
|
100
|
-
...(input.providerOptions !== undefined
|
|
101
|
-
? { providerOptions: input.providerOptions }
|
|
102
|
-
: {}),
|
|
103
|
-
}
|
|
104
|
-
: undefined,
|
|
101
|
+
metadata: modelOverrideMetadata(input),
|
|
105
102
|
});
|
|
106
103
|
},
|
|
107
104
|
});
|
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
import type { Actor, TurnId } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { WaitingProcessRestart } from "@leitwerk-dev/process-sdk";
|
|
2
3
|
import { buildTurnSelectionWrites } from "../../process-engine/writes/build-turn-selection-writes.js";
|
|
3
|
-
import { accept, noWrites } from "../decision.js";
|
|
4
|
+
import { accept, noWrites, reject } from "../decision.js";
|
|
4
5
|
import { defineOperation } from "../operation.js";
|
|
5
|
-
import { stampActorOnEvents } from "../writes/writes.js";
|
|
6
|
+
import { applyProcessPatchField, stampActorOnEvents } from "../writes/writes.js";
|
|
6
7
|
|
|
7
8
|
export interface StartProcessInput {
|
|
8
9
|
instanceId: string;
|
|
9
10
|
startTurnId: TurnId;
|
|
10
11
|
actor?: Actor;
|
|
11
12
|
onlyIfUnstarted?: boolean;
|
|
13
|
+
restart?: WaitingProcessRestart;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export const StartProcess = defineOperation<"start_process", StartProcessInput, void>({
|
|
15
17
|
kind: "start_process",
|
|
16
18
|
label: "Start process",
|
|
17
19
|
decide(ctx, input) {
|
|
20
|
+
const restart = input.restart;
|
|
21
|
+
if (
|
|
22
|
+
restart &&
|
|
23
|
+
(ctx.process.lifecycleStatus !== "waiting" ||
|
|
24
|
+
ctx.process.currentExecution !== null ||
|
|
25
|
+
ctx.process.selectedTurnId !== restart.expected.turnId ||
|
|
26
|
+
ctx.process.paramsJson !== restart.expected.paramsJson ||
|
|
27
|
+
ctx.process.stateJson !== restart.expected.stateJson)
|
|
28
|
+
) {
|
|
29
|
+
return reject("restart_superseded", "The captured waiting process has changed");
|
|
30
|
+
}
|
|
31
|
+
if (restart && ctx.deps.isNewTurnBlocked?.(input.instanceId)) {
|
|
32
|
+
return reject("session_transfer_in_progress", "A local session transfer is in progress");
|
|
33
|
+
}
|
|
34
|
+
const project = restart?.project
|
|
35
|
+
? ctx.deps.projects.getByInstanceAndKey(input.instanceId, restart.project.key)
|
|
36
|
+
: null;
|
|
37
|
+
if (
|
|
38
|
+
restart?.project &&
|
|
39
|
+
(!project || project.baseBranch !== restart.project.expectedBaseBranch)
|
|
40
|
+
) {
|
|
41
|
+
return reject("restart_superseded", "The captured process repository has changed");
|
|
42
|
+
}
|
|
43
|
+
if (restart) JSON.parse(restart.stateJson);
|
|
18
44
|
if (
|
|
19
45
|
input.onlyIfUnstarted &&
|
|
20
46
|
(ctx.process.lifecycleStatus !== "discovered" ||
|
|
@@ -29,6 +55,12 @@ export const StartProcess = defineOperation<"start_process", StartProcessInput,
|
|
|
29
55
|
trigger: "start",
|
|
30
56
|
});
|
|
31
57
|
if ("ok" in writes) return writes;
|
|
58
|
+
if (restart) {
|
|
59
|
+
applyProcessPatchField(writes, ctx.process, "stateJson", restart.stateJson);
|
|
60
|
+
if (project && restart.project) {
|
|
61
|
+
writes.projectWrite = { id: project.id, input: { baseBranch: restart.project.baseBranch } };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
32
64
|
stampActorOnEvents(writes, input.actor, "turn_selected");
|
|
33
65
|
return accept({ writes });
|
|
34
66
|
},
|