@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
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { assertRepoLocator } from "@leitwerk-dev/domain";
|
|
2
|
+
import {
|
|
3
|
+
type InitialProcessBinding,
|
|
4
|
+
RetryableWaitError,
|
|
5
|
+
type TurnWaitContext,
|
|
6
|
+
} from "@leitwerk-dev/process-sdk";
|
|
7
|
+
import type { CommitMessageConfig } from "./config/config-types.js";
|
|
8
|
+
import type { RepositoryBundle } from "./db/repositories.js";
|
|
9
|
+
import type { ProcessActionRegistry } from "./process-action-registry.js";
|
|
10
|
+
import { ArmTurnWait, ResolveTurnWait } from "./process-engine/ops/turn-wait.js";
|
|
11
|
+
import { pendingTurnWait, turnWaitPredicate } from "./process-engine/turn-wait-state.js";
|
|
12
|
+
import type { ProcessEngine } from "./process-engine/types.js";
|
|
13
|
+
import type { ProcessGraphRegistry } from "./process-graph.js";
|
|
14
|
+
import { normalizeProjectInputs } from "./process-launch-plan.js";
|
|
15
|
+
|
|
16
|
+
interface TurnWaitServiceDeps {
|
|
17
|
+
processes: RepositoryBundle["processes"];
|
|
18
|
+
projects: RepositoryBundle["projects"];
|
|
19
|
+
processGraphs: ProcessGraphRegistry;
|
|
20
|
+
registry: Pick<ProcessActionRegistry, "resolveContextData">;
|
|
21
|
+
commands: ProcessEngine;
|
|
22
|
+
require: TurnWaitContext["require"];
|
|
23
|
+
now?: () => number;
|
|
24
|
+
pollIntervalMs?: number;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
commitMessages?: CommitMessageConfig;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Runs read-only predicates outside lifecycle locks. The engine fences every result. */
|
|
30
|
+
export function createTurnWaitService(deps: TurnWaitServiceDeps) {
|
|
31
|
+
const running = new Map<string, Promise<void>>();
|
|
32
|
+
const controllers = new Set<AbortController>();
|
|
33
|
+
const now = deps.now ?? Date.now;
|
|
34
|
+
const interval = deps.pollIntervalMs ?? 30_000;
|
|
35
|
+
let stopped = false;
|
|
36
|
+
let activeChecks = 0;
|
|
37
|
+
const queued: Array<() => void> = [];
|
|
38
|
+
function schedule(work: () => Promise<void>): Promise<void> {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const start = () => {
|
|
41
|
+
if (stopped) {
|
|
42
|
+
resolve();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
activeChecks++;
|
|
46
|
+
void work()
|
|
47
|
+
.then(resolve, reject)
|
|
48
|
+
.finally(() => {
|
|
49
|
+
activeChecks--;
|
|
50
|
+
queued.shift()?.();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
if (activeChecks < 4) start();
|
|
54
|
+
else queued.push(start);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!Number.isFinite(interval) || interval <= 0) throw new Error("Invalid wait polling interval");
|
|
58
|
+
|
|
59
|
+
async function evaluate(instanceId: string): Promise<void> {
|
|
60
|
+
let process = deps.processes.getById(instanceId);
|
|
61
|
+
if (!process || !turnWaitPredicate(deps.processGraphs, process)) return;
|
|
62
|
+
if (!pendingTurnWait(process)) {
|
|
63
|
+
if (process.currentExecution || process.lifecycleStatus !== "active") return;
|
|
64
|
+
await deps.commands.run(ArmTurnWait, { instanceId });
|
|
65
|
+
process = deps.processes.getById(instanceId);
|
|
66
|
+
}
|
|
67
|
+
if (!process || stopped) return;
|
|
68
|
+
const wait = pendingTurnWait(process);
|
|
69
|
+
if (
|
|
70
|
+
!wait ||
|
|
71
|
+
wait.status !== "waiting" ||
|
|
72
|
+
process.lifecycleStatus !== "waiting" ||
|
|
73
|
+
wait.nextCheckAt > now()
|
|
74
|
+
)
|
|
75
|
+
return;
|
|
76
|
+
const predicate = turnWaitPredicate(deps.processGraphs, process);
|
|
77
|
+
if (!predicate) return;
|
|
78
|
+
const projects = deps.projects.listByInstance(instanceId);
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
controllers.add(controller);
|
|
81
|
+
let state: unknown;
|
|
82
|
+
let nextStateJson: string | undefined;
|
|
83
|
+
let result: "ready" | "waiting" | "complete" | "abort" | "bind" | "retry" | "error";
|
|
84
|
+
let initialBinding: InitialProcessBinding | undefined;
|
|
85
|
+
let message: string | undefined;
|
|
86
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
87
|
+
let onAbort: (() => void) | undefined;
|
|
88
|
+
try {
|
|
89
|
+
const data = deps.registry.resolveContextData(process.processId, process);
|
|
90
|
+
const context: TurnWaitContext = {
|
|
91
|
+
process: structuredClone(process),
|
|
92
|
+
projects: structuredClone(projects),
|
|
93
|
+
params: data.params,
|
|
94
|
+
state: data.state,
|
|
95
|
+
signal: controller.signal,
|
|
96
|
+
require: deps.require,
|
|
97
|
+
setState(value) {
|
|
98
|
+
if (!controller.signal.aborted) state = value;
|
|
99
|
+
},
|
|
100
|
+
complete: () => ({ kind: "complete" }),
|
|
101
|
+
waiting: (message) => ({ kind: "waiting", message }),
|
|
102
|
+
abort: (message) => ({ kind: "abort", message }),
|
|
103
|
+
bindInitialProjects: (binding) => ({ kind: "bind", binding }),
|
|
104
|
+
};
|
|
105
|
+
const timedOut = new Promise<never>((_, reject) => {
|
|
106
|
+
onAbort = () => reject(new RetryableWaitError("Waiting condition interrupted"));
|
|
107
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
108
|
+
timeout = setTimeout(() => {
|
|
109
|
+
reject(new RetryableWaitError("Waiting condition timed out"));
|
|
110
|
+
controller.abort();
|
|
111
|
+
}, deps.timeoutMs ?? 30_000);
|
|
112
|
+
});
|
|
113
|
+
const value = await Promise.race([
|
|
114
|
+
Promise.resolve().then(() => predicate(context)),
|
|
115
|
+
timedOut,
|
|
116
|
+
]);
|
|
117
|
+
if (typeof value === "boolean") result = value ? "ready" : "waiting";
|
|
118
|
+
else if (value && value.kind === "complete") result = "complete";
|
|
119
|
+
else if (value && (value.kind === "waiting" || value.kind === "abort")) {
|
|
120
|
+
if (typeof value.message !== "string" || !value.message.trim())
|
|
121
|
+
throw new Error("Readiness guidance must be nonempty text");
|
|
122
|
+
result = value.kind;
|
|
123
|
+
message = value.message.slice(0, 2000);
|
|
124
|
+
} else if (value?.kind === "bind") {
|
|
125
|
+
if (!wait.initialSelection || projects.length || !value.binding.projects.length)
|
|
126
|
+
throw new Error(
|
|
127
|
+
"Initial repository binding requires an unstarted process without projects",
|
|
128
|
+
);
|
|
129
|
+
const codec = deps.processGraphs.get(process.processId)?.paramsCodec;
|
|
130
|
+
if (!codec) throw new Error("Process params codec is unavailable");
|
|
131
|
+
const keys = new Set<string>();
|
|
132
|
+
for (const project of value.binding.projects) {
|
|
133
|
+
if (
|
|
134
|
+
!/^[a-zA-Z0-9_-]+$/.test(project.key) ||
|
|
135
|
+
keys.has(project.key) ||
|
|
136
|
+
!project.baseBranch?.trim()
|
|
137
|
+
)
|
|
138
|
+
throw new Error("Invalid initial repository binding");
|
|
139
|
+
assertRepoLocator(project.repoLocator);
|
|
140
|
+
keys.add(project.key);
|
|
141
|
+
}
|
|
142
|
+
// Extension metadata cannot overwrite lifecycle or launch metadata.
|
|
143
|
+
if (
|
|
144
|
+
Object.keys(value.binding.metadata ?? {}).some(
|
|
145
|
+
(key) => key === "turnWait" || Object.hasOwn(process.metadata ?? {}, key),
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
throw new Error("Initial repository binding cannot replace retained metadata");
|
|
149
|
+
initialBinding = structuredClone({
|
|
150
|
+
params: codec.serialize(codec.parse(value.binding.params)),
|
|
151
|
+
projects: normalizeProjectInputs(value.binding, deps.commitMessages),
|
|
152
|
+
metadata: value.binding.metadata,
|
|
153
|
+
settingsContext: value.binding.settingsContext,
|
|
154
|
+
});
|
|
155
|
+
result = "bind";
|
|
156
|
+
} else throw new Error("Invalid turn readiness decision");
|
|
157
|
+
if (state !== undefined) {
|
|
158
|
+
const codec = deps.processGraphs.get(process.processId)?.stateCodec;
|
|
159
|
+
if (!codec) throw new Error("Process state codec is unavailable");
|
|
160
|
+
nextStateJson = JSON.stringify(codec.serialize(codec.parse(state)));
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
result = error instanceof RetryableWaitError ? "retry" : "error";
|
|
164
|
+
message = error instanceof Error ? error.message.slice(0, 500) : "Waiting condition failed";
|
|
165
|
+
} finally {
|
|
166
|
+
if (timeout) clearTimeout(timeout);
|
|
167
|
+
if (onAbort) controller.signal.removeEventListener("abort", onAbort);
|
|
168
|
+
controllers.delete(controller);
|
|
169
|
+
}
|
|
170
|
+
if (stopped) return;
|
|
171
|
+
await deps.commands.run(ResolveTurnWait, {
|
|
172
|
+
instanceId,
|
|
173
|
+
waitId: wait.id,
|
|
174
|
+
revision: wait.revision,
|
|
175
|
+
paramsJson: process.paramsJson,
|
|
176
|
+
stateJson: process.stateJson,
|
|
177
|
+
projectsJson: JSON.stringify(projects),
|
|
178
|
+
nextStateJson,
|
|
179
|
+
initialBinding,
|
|
180
|
+
result,
|
|
181
|
+
message,
|
|
182
|
+
now: now(),
|
|
183
|
+
pollIntervalMs: interval,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function check(instanceId: string): Promise<void> {
|
|
188
|
+
if (stopped) return Promise.resolve();
|
|
189
|
+
const current = running.get(instanceId);
|
|
190
|
+
if (current) return current;
|
|
191
|
+
// Defer evaluation until its single-flight identity is installed. Engine hooks can reenter.
|
|
192
|
+
const promise = Promise.resolve()
|
|
193
|
+
.then(() => schedule(() => evaluate(instanceId)))
|
|
194
|
+
.finally(() => running.delete(instanceId));
|
|
195
|
+
running.set(instanceId, promise);
|
|
196
|
+
return promise;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
check,
|
|
201
|
+
async poll() {
|
|
202
|
+
const errors: string[] = [];
|
|
203
|
+
const candidates = deps.processes
|
|
204
|
+
.listAll()
|
|
205
|
+
.filter(
|
|
206
|
+
(process) =>
|
|
207
|
+
["waiting", "active"].includes(process.lifecycleStatus) &&
|
|
208
|
+
turnWaitPredicate(deps.processGraphs, process),
|
|
209
|
+
);
|
|
210
|
+
await Promise.all(
|
|
211
|
+
candidates.map(async (process) => {
|
|
212
|
+
try {
|
|
213
|
+
await check(process.id);
|
|
214
|
+
} catch {
|
|
215
|
+
errors.push(`${process.id}:waiting_check_failed`);
|
|
216
|
+
}
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
return { errors };
|
|
220
|
+
},
|
|
221
|
+
async stop() {
|
|
222
|
+
stopped = true;
|
|
223
|
+
for (const start of queued.splice(0)) start();
|
|
224
|
+
for (const controller of controllers) controller.abort();
|
|
225
|
+
await Promise.allSettled(running.values());
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
@@ -151,6 +151,8 @@ export function buildRuntimeProfileSelectionInput(args: {
|
|
|
151
151
|
processId: string;
|
|
152
152
|
/** @internal */
|
|
153
153
|
componentKeys: string[];
|
|
154
|
+
/** The registered process definition requires Docker. @internal */
|
|
155
|
+
docker?: boolean;
|
|
154
156
|
}): RuntimeProfileSelectionInput {
|
|
155
157
|
const { config, processId, componentKeys } = args;
|
|
156
158
|
const componentProfiles: ComponentRuntimeProfileSelection[] = componentKeys.map((component) => ({
|
|
@@ -161,7 +163,12 @@ export function buildRuntimeProfileSelectionInput(args: {
|
|
|
161
163
|
processId,
|
|
162
164
|
processOverride: config.process_configs?.[processId]?.worker_runtime_profile,
|
|
163
165
|
componentProfiles,
|
|
164
|
-
defaultProfile:
|
|
166
|
+
defaultProfile:
|
|
167
|
+
(config.workers.runner === "kubernetes" && args.docker
|
|
168
|
+
? config.kubernetes?.docker?.worker_runtime_profile
|
|
169
|
+
: undefined) ??
|
|
170
|
+
defaultWorkerRuntimeProfile(config) ??
|
|
171
|
+
undefined,
|
|
165
172
|
profiles: config.worker_runtime_profiles ?? {},
|
|
166
173
|
};
|
|
167
174
|
}
|