@leitwerk-dev/server 0.1.7 → 0.1.9
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.d.ts.map +1 -1
- package/dist/app.js +24 -15
- package/dist/app.js.map +1 -1
- package/dist/{chunk-GIWHTJSL.js → chunk-2ESDXLNE.js} +228 -101
- package/dist/chunk-2ESDXLNE.js.map +1 -0
- package/dist/{chunk-OO6VH4FX.js → chunk-DFHOPJRZ.js} +405 -259
- package/dist/chunk-DFHOPJRZ.js.map +1 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-loader.js +14 -25
- package/dist/config/config-loader.js.map +1 -1
- package/dist/config/config-types.d.ts +5 -17
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/db/skill-repo.d.ts +2 -2
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/skill-repo.js +24 -32
- package/dist/db/skill-repo.js.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/external-source-service.js +5 -2
- package/dist/external-source-service.js.map +1 -1
- package/dist/future-execution/execution.d.ts +1 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/execution.js +1 -13
- package/dist/future-execution/execution.js.map +1 -1
- package/dist/integration-tool-registry.js +1 -1
- package/dist/integration-tool-registry.js.map +1 -1
- package/dist/model-providers/builtin-server-adapter.d.ts.map +1 -1
- package/dist/model-providers/builtin-server-adapter.js +10 -2
- package/dist/model-providers/builtin-server-adapter.js.map +1 -1
- package/dist/process-action-registry.d.ts +2 -4
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-action-registry.js +31 -28
- package/dist/process-action-registry.js.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/engine.js +4 -4
- package/dist/process-engine/engine.js.map +1 -1
- package/dist/process-engine/operation.d.ts +4 -0
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/ops/execute-action.d.ts.map +1 -1
- package/dist/process-engine/ops/execute-action.js +0 -3
- package/dist/process-engine/ops/execute-action.js.map +1 -1
- package/dist/process-engine/ops/worker-failure.d.ts +2 -0
- package/dist/process-engine/ops/worker-failure.d.ts.map +1 -1
- package/dist/process-engine/ops/worker-failure.js +2 -0
- package/dist/process-engine/ops/worker-failure.js.map +1 -1
- package/dist/process-engine/runner.d.ts +2 -2
- package/dist/process-engine/runner.d.ts.map +1 -1
- package/dist/process-engine/runner.js +13 -1
- package/dist/process-engine/runner.js.map +1 -1
- package/dist/process-engine/types.d.ts +10 -4
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-server-transition-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-server-transition-writes.js +2 -8
- package/dist/process-engine/writes/build-server-transition-writes.js.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.js +1 -2
- package/dist/process-engine/writes/build-turn-outcome-writes.js.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts +1 -2
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-writes.js +1 -57
- package/dist/process-engine/writes/build-turn-selection-writes.js.map +1 -1
- package/dist/process-engine/writes/build-worker-failure-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-worker-failure-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-worker-failure-writes.js +2 -1
- package/dist/process-engine/writes/build-worker-failure-writes.js.map +1 -1
- package/dist/process-launch-executor.d.ts +6 -4
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-executor.js +16 -1
- package/dist/process-launch-executor.js.map +1 -1
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launch-plan.js +1 -0
- package/dist/process-launch-plan.js.map +1 -1
- package/dist/process-operator-attention.d.ts +1 -1
- package/dist/process-operator-attention.d.ts.map +1 -1
- package/dist/process-operator-attention.js +1 -1
- package/dist/process-operator-attention.js.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.js +24 -3
- package/dist/process-ui-snapshot-presenter.js.map +1 -1
- package/dist/process-watcher-registry.d.ts.map +1 -1
- package/dist/process-watcher-registry.js +13 -5
- package/dist/process-watcher-registry.js.map +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +1 -2
- package/dist/routes/skills.js.map +1 -1
- package/dist/server-automatic-turn-drainer.d.ts.map +1 -1
- package/dist/server-automatic-turn-drainer.js +15 -0
- package/dist/server-automatic-turn-drainer.js.map +1 -1
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/build-host-capabilities.js +1 -0
- package/dist/server-bootstrap/build-host-capabilities.js.map +1 -1
- package/dist/skills/skill-frontmatter.d.ts +4 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.js +13 -0
- package/dist/skills/skill-frontmatter.js.map +1 -0
- package/dist/skills/source-importer.d.ts +2 -3
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/skills/source-importer.js +16 -62
- package/dist/skills/source-importer.js.map +1 -1
- package/dist/supervisor/accepted-turn-start-replay.d.ts +9 -0
- package/dist/supervisor/accepted-turn-start-replay.d.ts.map +1 -0
- package/dist/supervisor/accepted-turn-start-replay.js +23 -0
- package/dist/supervisor/accepted-turn-start-replay.js.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +9 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/ipc-handler.js +9 -4
- package/dist/supervisor/ipc-handler.js.map +1 -1
- package/dist/supervisor/stale-heartbeat-watchdog.d.ts +1 -1
- package/dist/supervisor/stale-heartbeat-watchdog.d.ts.map +1 -1
- package/dist/supervisor/stale-heartbeat-watchdog.js +47 -5
- package/dist/supervisor/stale-heartbeat-watchdog.js.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.js +16 -0
- package/dist/supervisor/worker-event-ingestor.js.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +2 -4
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.js +3 -1
- package/dist/supervisor/worker-start-payload-builder.js.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +4 -5
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.js +31 -0
- package/dist/supervisor/worker-supervisor.js.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +12 -3
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.js +129 -33
- package/dist/supervisor/worker-turn-ipc-recorder.js.map +1 -1
- package/dist/supervisor/worker-websocket-ipc.d.ts.map +1 -1
- package/dist/supervisor/worker-websocket-ipc.js +20 -10
- package/dist/supervisor/worker-websocket-ipc.js.map +1 -1
- package/dist/test-helpers/fake-worker-supervisor.d.ts.map +1 -1
- package/dist/test-helpers/fake-worker-supervisor.js +4 -0
- package/dist/test-helpers/fake-worker-supervisor.js.map +1 -1
- package/dist/test-helpers/ipc-handler-harness.d.ts.map +1 -1
- package/dist/test-helpers/ipc-handler-harness.js +1 -20
- package/dist/test-helpers/ipc-handler-harness.js.map +1 -1
- package/dist/test-helpers/process-fixtures.d.ts +1 -1
- package/dist/test-helpers/process-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/process-fixtures.js +0 -6
- package/dist/test-helpers/process-fixtures.js.map +1 -1
- package/dist/turn-progress.d.ts +12 -0
- package/dist/turn-progress.d.ts.map +1 -0
- package/dist/turn-progress.js +108 -0
- package/dist/turn-progress.js.map +1 -0
- package/dist/{writes-DUwQe8MD.d.ts → writes-DNXpryd0.d.ts} +68 -36
- package/package.json +10 -10
- package/src/app.ts +25 -15
- package/src/config/config-loader.ts +33 -25
- package/src/config/config-types.ts +6 -13
- package/src/db/skill-repo.ts +26 -36
- package/src/external-source-service.ts +5 -2
- package/src/future-execution/execution.ts +2 -13
- package/src/integration-tool-registry.ts +1 -1
- package/src/model-providers/builtin-server-adapter.ts +10 -2
- package/src/process-action-registry.ts +48 -40
- package/src/process-engine/engine.ts +6 -4
- package/src/process-engine/operation.ts +5 -0
- package/src/process-engine/ops/execute-action.ts +0 -3
- package/src/process-engine/ops/worker-failure.ts +4 -0
- package/src/process-engine/runner.ts +13 -0
- package/src/process-engine/types.ts +14 -2
- package/src/process-engine/writes/build-server-transition-writes.ts +1 -14
- package/src/process-engine/writes/build-turn-outcome-writes.ts +1 -2
- package/src/process-engine/writes/build-turn-selection-writes.ts +0 -75
- package/src/process-engine/writes/build-worker-failure-writes.ts +4 -1
- package/src/process-launch-executor.ts +24 -15
- package/src/process-launch-plan.ts +1 -0
- package/src/process-operator-attention.ts +7 -3
- package/src/process-ui-snapshot-presenter.ts +24 -6
- package/src/process-watcher-registry.ts +15 -5
- package/src/routes/skills.ts +1 -3
- package/src/server-automatic-turn-drainer.ts +20 -1
- package/src/server-bootstrap/build-host-capabilities.ts +1 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +20 -82
- package/src/supervisor/accepted-turn-start-replay.ts +40 -0
- package/src/supervisor/ipc-handler.ts +18 -4
- package/src/supervisor/stale-heartbeat-watchdog.ts +55 -6
- package/src/supervisor/worker-event-ingestor.ts +15 -0
- package/src/supervisor/worker-start-payload-builder.ts +5 -2
- package/src/supervisor/worker-supervisor.ts +43 -4
- package/src/supervisor/worker-turn-ipc-recorder.ts +185 -46
- package/src/supervisor/worker-websocket-ipc.ts +28 -13
- package/src/test-helpers/fake-worker-supervisor.ts +4 -0
- package/src/test-helpers/ipc-handler-harness.ts +1 -22
- package/src/test-helpers/process-fixtures.ts +1 -6
- package/src/turn-progress.ts +114 -0
- package/dist/chunk-GIWHTJSL.js.map +0 -1
- package/dist/chunk-OO6VH4FX.js.map +0 -1
- package/dist/skills/catalog-sync.d.ts +0 -9
- package/dist/skills/catalog-sync.d.ts.map +0 -1
- package/dist/skills/catalog-sync.js +0 -7
- package/dist/skills/catalog-sync.js.map +0 -1
- package/src/skills/catalog-sync.ts +0 -13
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
type WorkerHelloPayload,
|
|
23
23
|
type WorkerIntegrationToolResultPayload,
|
|
24
24
|
type WorkerQuestionResponsePayload,
|
|
25
|
+
type WorkerTurnTerminalRecordedPayload,
|
|
25
26
|
} from "@leitwerk-dev/worker-protocol";
|
|
26
27
|
import type {
|
|
27
28
|
ProcessVolume,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
selectWorkerRuntimeProfile,
|
|
40
41
|
} from "../worker-runtime-profile-selection.js";
|
|
41
42
|
import type { Broadcaster } from "../ws/broadcast.js";
|
|
43
|
+
import { resolveAcceptedTurnStartReplay } from "./accepted-turn-start-replay.js";
|
|
42
44
|
import { createWorkerAdoptionCoordinator } from "./adoption/worker-adoption-coordinator.js";
|
|
43
45
|
import { decideIdleWorkerStop } from "./idle-worker-ttl.js";
|
|
44
46
|
import type { createIpcHandler } from "./ipc-handler.js";
|
|
@@ -81,10 +83,7 @@ export interface SupervisorDeps
|
|
|
81
83
|
resolveResourceBundle?: (digest: string) => PiResourceBundle | null;
|
|
82
84
|
resolveRepositoryCredentials?: WorkerStartPayloadBuilderDeps["resolveRepositoryCredentials"];
|
|
83
85
|
integrationTools?: WorkerStartPayloadBuilderDeps["integrationTools"];
|
|
84
|
-
resolveCredential?:
|
|
85
|
-
providerId: string,
|
|
86
|
-
options: Readonly<Record<string, string>>,
|
|
87
|
-
) => { revision: number; values: Record<string, string> } | null;
|
|
86
|
+
resolveCredential?: WorkerStartPayloadBuilderDeps["resolveCredential"];
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
export interface WorkerHandle {
|
|
@@ -125,6 +124,12 @@ export interface WorkerSupervisor {
|
|
|
125
124
|
startRecordId: string,
|
|
126
125
|
turnRecordId: string,
|
|
127
126
|
): void;
|
|
127
|
+
reconcileAcceptedTurnStart(instanceId: string, workerId: string): boolean;
|
|
128
|
+
acknowledgeTurnTerminal(
|
|
129
|
+
instanceId: string,
|
|
130
|
+
workerId: string,
|
|
131
|
+
payload: WorkerTurnTerminalRecordedPayload,
|
|
132
|
+
): void;
|
|
128
133
|
questionResponse(
|
|
129
134
|
instanceId: string,
|
|
130
135
|
workerId: string,
|
|
@@ -377,6 +382,17 @@ export function createWorkerSupervisor(deps: SupervisorDeps): WorkerSupervisor {
|
|
|
377
382
|
);
|
|
378
383
|
}
|
|
379
384
|
|
|
385
|
+
function reconcileAcceptedTurnStart(instanceId: string, workerId: string): boolean {
|
|
386
|
+
if (workers.get(instanceId)?.workerId !== workerId) return false;
|
|
387
|
+
const replay = resolveAcceptedTurnStartReplay(deps, instanceId, workerId);
|
|
388
|
+
if (!replay) return false;
|
|
389
|
+
sendToCurrentWorker(instanceId, workerId, {
|
|
390
|
+
type: "worker.turn_start_accepted",
|
|
391
|
+
payload: { startRecordId: replay.startRecordId, turnRecordId: replay.turnRecordId },
|
|
392
|
+
});
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
|
|
380
396
|
function routeEnvelope(envelope: IpcEnvelope, instanceId: string): void {
|
|
381
397
|
const currentHandle = workers.get(instanceId);
|
|
382
398
|
if (
|
|
@@ -434,6 +450,15 @@ export function createWorkerSupervisor(deps: SupervisorDeps): WorkerSupervisor {
|
|
|
434
450
|
}
|
|
435
451
|
if (envelope.type === "worker.heartbeat") {
|
|
436
452
|
adoptionCoordinator.onHeartbeat(instanceId, envelope.workerId, envelope.payload);
|
|
453
|
+
const reportedState =
|
|
454
|
+
typeof envelope.payload === "object" &&
|
|
455
|
+
envelope.payload !== null &&
|
|
456
|
+
"state" in envelope.payload
|
|
457
|
+
? envelope.payload.state
|
|
458
|
+
: null;
|
|
459
|
+
if (reportedState === "idle") {
|
|
460
|
+
reconcileAcceptedTurnStart(instanceId, envelope.workerId);
|
|
461
|
+
}
|
|
437
462
|
}
|
|
438
463
|
if (envelope.type === "worker.ready") {
|
|
439
464
|
adoptionCoordinator.onWorkerReady(instanceId);
|
|
@@ -860,6 +885,20 @@ export function createWorkerSupervisor(deps: SupervisorDeps): WorkerSupervisor {
|
|
|
860
885
|
payload: { startRecordId, turnRecordId },
|
|
861
886
|
});
|
|
862
887
|
},
|
|
888
|
+
reconcileAcceptedTurnStart,
|
|
889
|
+
acknowledgeTurnTerminal(instanceId, workerId, payload) {
|
|
890
|
+
runnerRuntime.webSocketIpc.send(
|
|
891
|
+
instanceId,
|
|
892
|
+
workerId,
|
|
893
|
+
createIpcMessage<ServerToWorkerMessage>({
|
|
894
|
+
type: "worker.turn_terminal_recorded",
|
|
895
|
+
payload,
|
|
896
|
+
messageId: randomUUID(),
|
|
897
|
+
instanceId,
|
|
898
|
+
workerId,
|
|
899
|
+
}),
|
|
900
|
+
);
|
|
901
|
+
},
|
|
863
902
|
questionResponse(instanceId, workerId, payload) {
|
|
864
903
|
sendToCurrentWorker(instanceId, workerId, { type: "worker.question_response", payload });
|
|
865
904
|
},
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createGenericFailedTurnRecoveryContext,
|
|
3
|
+
type FailedTurnRecoveryContext,
|
|
4
|
+
isTurnFailureCode,
|
|
5
|
+
isWorkerErrorClass,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
2
7
|
import type {
|
|
3
8
|
WorkerTurnFailedPayload,
|
|
4
9
|
WorkerTurnOutcomePayload,
|
|
@@ -7,7 +12,7 @@ import type { RepositoryBundle } from "../db/repositories.js";
|
|
|
7
12
|
import type { ProcessEngine } from "../process-engine/types.js";
|
|
8
13
|
import type { createWorkerEventIngestor } from "./worker-event-ingestor.js";
|
|
9
14
|
|
|
10
|
-
export interface WorkerTurnIpcRecorderDeps extends Pick<RepositoryBundle, "
|
|
15
|
+
export interface WorkerTurnIpcRecorderDeps extends Pick<RepositoryBundle, "turnRecords"> {
|
|
11
16
|
commands: ProcessEngine;
|
|
12
17
|
eventIngestor: ReturnType<typeof createWorkerEventIngestor>;
|
|
13
18
|
}
|
|
@@ -19,77 +24,211 @@ export interface WorkerTurnIpcRecorderCallbacks {
|
|
|
19
24
|
outcome: string,
|
|
20
25
|
params: Record<string, unknown>,
|
|
21
26
|
) => void;
|
|
27
|
+
onTurnTerminalRecorded?: (instanceId: string, workerId: string, turnRecordId: string) => void;
|
|
28
|
+
onTurnTerminalRecordingFailed?: (input: {
|
|
29
|
+
instanceId: string;
|
|
30
|
+
workerId: string;
|
|
31
|
+
turnRecordId: string;
|
|
32
|
+
terminalType: "outcome" | "failure";
|
|
33
|
+
code: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}) => void;
|
|
22
36
|
}
|
|
23
37
|
|
|
24
|
-
type
|
|
38
|
+
type TerminalType = "outcome" | "failure";
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
type TerminalRecordingFailureInput = {
|
|
41
|
+
instanceId: string;
|
|
42
|
+
workerId: string;
|
|
43
|
+
turnRecordId: string;
|
|
44
|
+
terminalType: TerminalType;
|
|
45
|
+
failure: unknown;
|
|
46
|
+
resultPiEntryId?: string | null;
|
|
47
|
+
recoveryContext?: FailedTurnRecoveryContext | null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function terminalWasAlreadyRecorded(
|
|
51
|
+
deps: Pick<WorkerTurnIpcRecorderDeps, "turnRecords">,
|
|
52
|
+
turnRecordId: string,
|
|
53
|
+
terminalType: TerminalType,
|
|
54
|
+
): boolean {
|
|
55
|
+
const record = deps.turnRecords.getById(turnRecordId);
|
|
56
|
+
return terminalType === "outcome" ? record?.status === "succeeded" : record?.status === "failed";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function failureDetails(result: unknown): {
|
|
60
|
+
code: string;
|
|
61
|
+
message: string;
|
|
62
|
+
} {
|
|
63
|
+
if (result instanceof Error) {
|
|
64
|
+
return { code: "turn_terminal_recording_threw", message: result.message };
|
|
34
65
|
}
|
|
35
|
-
if (result
|
|
36
|
-
|
|
66
|
+
if (typeof result === "object" && result !== null && "ok" in result && result.ok === false) {
|
|
67
|
+
const rejected = result as { code?: unknown; message?: unknown };
|
|
68
|
+
return {
|
|
69
|
+
code: typeof rejected.code === "string" ? rejected.code : "turn_terminal_recording_rejected",
|
|
70
|
+
message:
|
|
71
|
+
typeof rejected.message === "string"
|
|
72
|
+
? rejected.message
|
|
73
|
+
: "Turn terminal recording was rejected",
|
|
74
|
+
};
|
|
37
75
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
errorClass: "infrastructure",
|
|
43
|
-
})
|
|
44
|
-
.catch(() => {});
|
|
76
|
+
return {
|
|
77
|
+
code: "turn_terminal_recording_failed",
|
|
78
|
+
message: "Turn terminal recording failed",
|
|
79
|
+
};
|
|
45
80
|
}
|
|
46
81
|
|
|
47
82
|
export function createWorkerTurnIpcRecorder(
|
|
48
83
|
deps: WorkerTurnIpcRecorderDeps,
|
|
49
84
|
callbacks: WorkerTurnIpcRecorderCallbacks,
|
|
50
85
|
) {
|
|
86
|
+
const acknowledge = (instanceId: string, workerId: string, turnRecordId: string): void => {
|
|
87
|
+
callbacks.onTurnTerminalRecorded?.(instanceId, workerId, turnRecordId);
|
|
88
|
+
};
|
|
89
|
+
const reportRecordingFailure = (
|
|
90
|
+
input: Parameters<NonNullable<typeof callbacks.onTurnTerminalRecordingFailed>>[0],
|
|
91
|
+
): void => {
|
|
92
|
+
try {
|
|
93
|
+
callbacks.onTurnTerminalRecordingFailed?.(input);
|
|
94
|
+
} catch {
|
|
95
|
+
// Observability must not prevent durable failure recovery or terminal replay.
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const recoverRecordingFailure = async (input: TerminalRecordingFailureInput): Promise<void> => {
|
|
100
|
+
if (terminalWasAlreadyRecorded(deps, input.turnRecordId, input.terminalType)) {
|
|
101
|
+
acknowledge(input.instanceId, input.workerId, input.turnRecordId);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const details = failureDetails(input.failure);
|
|
105
|
+
reportRecordingFailure({
|
|
106
|
+
instanceId: input.instanceId,
|
|
107
|
+
workerId: input.workerId,
|
|
108
|
+
turnRecordId: input.turnRecordId,
|
|
109
|
+
terminalType: input.terminalType,
|
|
110
|
+
...details,
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
const fallback = await deps.commands.recordWorkerFailure(input.instanceId, {
|
|
114
|
+
errorCode: details.code,
|
|
115
|
+
message: `Server could not durably record worker turn ${input.terminalType}: ${details.message}`,
|
|
116
|
+
errorClass: "infrastructure",
|
|
117
|
+
resultPiEntryId: input.resultPiEntryId,
|
|
118
|
+
recoveryContext: input.recoveryContext,
|
|
119
|
+
});
|
|
120
|
+
if (fallback.ok || terminalWasAlreadyRecorded(deps, input.turnRecordId, "failure")) {
|
|
121
|
+
acknowledge(input.instanceId, input.workerId, input.turnRecordId);
|
|
122
|
+
} else {
|
|
123
|
+
reportRecordingFailure({
|
|
124
|
+
instanceId: input.instanceId,
|
|
125
|
+
workerId: input.workerId,
|
|
126
|
+
turnRecordId: input.turnRecordId,
|
|
127
|
+
terminalType: input.terminalType,
|
|
128
|
+
code: "worker_failure_fallback_rejected",
|
|
129
|
+
message: fallback.message,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
} catch (fallbackError: unknown) {
|
|
133
|
+
const fallbackDetails = failureDetails(fallbackError);
|
|
134
|
+
reportRecordingFailure({
|
|
135
|
+
instanceId: input.instanceId,
|
|
136
|
+
workerId: input.workerId,
|
|
137
|
+
turnRecordId: input.turnRecordId,
|
|
138
|
+
terminalType: input.terminalType,
|
|
139
|
+
code: "worker_failure_fallback_failed",
|
|
140
|
+
message: fallbackDetails.message,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const recover =
|
|
145
|
+
(input: Omit<TerminalRecordingFailureInput, "failure">) =>
|
|
146
|
+
(failure: unknown): Promise<void> =>
|
|
147
|
+
recoverRecordingFailure({ ...input, failure });
|
|
148
|
+
const clearLiveTurn = (instanceId: string, turnRecordId: string): void => {
|
|
149
|
+
if (deps.eventIngestor.getLiveTurnRecordId(instanceId) === turnRecordId) {
|
|
150
|
+
deps.eventIngestor.clearLiveTurnState(instanceId);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
51
154
|
return {
|
|
52
|
-
recordTurnOutcome(
|
|
155
|
+
recordTurnOutcome(
|
|
156
|
+
instanceId: string,
|
|
157
|
+
workerId: string,
|
|
158
|
+
payload: WorkerTurnOutcomePayload,
|
|
159
|
+
): void {
|
|
53
160
|
const { turnId, ...rest } = payload;
|
|
54
|
-
if (deps
|
|
55
|
-
|
|
161
|
+
if (terminalWasAlreadyRecorded(deps, rest.turnRecordId, "outcome")) {
|
|
162
|
+
acknowledge(instanceId, workerId, rest.turnRecordId);
|
|
163
|
+
return;
|
|
56
164
|
}
|
|
165
|
+
clearLiveTurn(instanceId, rest.turnRecordId);
|
|
166
|
+
const recoverOutcome = recover({
|
|
167
|
+
instanceId,
|
|
168
|
+
workerId,
|
|
169
|
+
turnRecordId: rest.turnRecordId,
|
|
170
|
+
terminalType: "outcome",
|
|
171
|
+
resultPiEntryId: rest.resultPiEntryId,
|
|
172
|
+
recoveryContext: createGenericFailedTurnRecoveryContext(),
|
|
173
|
+
});
|
|
57
174
|
void deps.commands
|
|
58
|
-
.recordTurnOutcome(
|
|
175
|
+
.recordTurnOutcome(
|
|
59
176
|
instanceId,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
177
|
+
{
|
|
178
|
+
instanceId,
|
|
179
|
+
turnId,
|
|
180
|
+
...rest,
|
|
181
|
+
},
|
|
182
|
+
{ onRecorded: () => acknowledge(instanceId, workerId, rest.turnRecordId) },
|
|
183
|
+
)
|
|
63
184
|
.then((result) => {
|
|
64
|
-
if (!result.ok)
|
|
65
|
-
maybeNormalizeTurnCorrelationFailure(deps, instanceId, result, "worker.turn_outcome");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
185
|
+
if (!result.ok) return recoverOutcome(result);
|
|
68
186
|
callbacks.onTurnOutcomeRecorded?.(instanceId, turnId, rest.outcome, rest.params);
|
|
69
187
|
})
|
|
70
|
-
.catch(
|
|
188
|
+
.catch(recoverOutcome);
|
|
71
189
|
},
|
|
72
|
-
recordTurnFailed(instanceId: string, payload: WorkerTurnFailedPayload): void {
|
|
73
|
-
const { errorClass, failureCode, failureDetails, ...rest } = payload;
|
|
190
|
+
recordTurnFailed(instanceId: string, workerId: string, payload: WorkerTurnFailedPayload): void {
|
|
191
|
+
const { errorClass, failureCode, failureDetails: details, ...rest } = payload;
|
|
74
192
|
if (errorClass !== undefined && !isWorkerErrorClass(errorClass)) {
|
|
193
|
+
void recoverRecordingFailure({
|
|
194
|
+
instanceId,
|
|
195
|
+
workerId,
|
|
196
|
+
turnRecordId: rest.turnRecordId,
|
|
197
|
+
terminalType: "failure",
|
|
198
|
+
failure: new Error(`Invalid worker error class '${errorClass}'`),
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (terminalWasAlreadyRecorded(deps, rest.turnRecordId, "failure")) {
|
|
203
|
+
acknowledge(instanceId, workerId, rest.turnRecordId);
|
|
75
204
|
return;
|
|
76
205
|
}
|
|
77
206
|
const normalizedFailureCode =
|
|
78
207
|
failureCode && isTurnFailureCode(failureCode) ? failureCode : undefined;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
208
|
+
clearLiveTurn(instanceId, rest.turnRecordId);
|
|
209
|
+
const recoverFailure = recover({
|
|
210
|
+
instanceId,
|
|
211
|
+
workerId,
|
|
212
|
+
turnRecordId: rest.turnRecordId,
|
|
213
|
+
terminalType: "failure",
|
|
214
|
+
resultPiEntryId: rest.resultPiEntryId,
|
|
215
|
+
recoveryContext: rest.recoveryContext,
|
|
216
|
+
});
|
|
82
217
|
void deps.commands
|
|
83
|
-
.recordTurnFailed(
|
|
218
|
+
.recordTurnFailed(
|
|
84
219
|
instanceId,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
220
|
+
{
|
|
221
|
+
instanceId,
|
|
222
|
+
errorClass,
|
|
223
|
+
...(normalizedFailureCode
|
|
224
|
+
? { failureCode: normalizedFailureCode, failureDetails: details }
|
|
225
|
+
: {}),
|
|
226
|
+
...rest,
|
|
227
|
+
},
|
|
228
|
+
{ onRecorded: () => acknowledge(instanceId, workerId, rest.turnRecordId) },
|
|
229
|
+
)
|
|
230
|
+
.then((result) => (result.ok ? undefined : recoverFailure(result)))
|
|
231
|
+
.catch(recoverFailure);
|
|
93
232
|
},
|
|
94
233
|
};
|
|
95
234
|
}
|
|
@@ -121,6 +121,25 @@ export function createWorkerWebSocketIpcManager(
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
function queueOutbound(entry: PendingWorkerConnection, data: string): void {
|
|
125
|
+
if (entry.outbound.length >= maxBufferedMessages) {
|
|
126
|
+
entry.outbound = [];
|
|
127
|
+
reportRuntimeError(
|
|
128
|
+
entry,
|
|
129
|
+
new WorkerOutboundBufferOverflowError(
|
|
130
|
+
entry.instanceId,
|
|
131
|
+
entry.workerId,
|
|
132
|
+
maxBufferedMessages,
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
if (entry.socket) {
|
|
136
|
+
closeSocket(entry, entry.socket, 1011, "worker websocket outbound buffer overflow");
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
entry.outbound.push(data);
|
|
141
|
+
}
|
|
142
|
+
|
|
124
143
|
function flushOutbound(entry: PendingWorkerConnection, socket: WorkerWebSocketLike): void {
|
|
125
144
|
while (entry.outbound.length > 0) {
|
|
126
145
|
const data = entry.outbound[0];
|
|
@@ -269,21 +288,17 @@ export function createWorkerWebSocketIpcManager(
|
|
|
269
288
|
}
|
|
270
289
|
const data = serializeMessage(message);
|
|
271
290
|
if (!entry.socket || !entry.socketAuthenticated) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
);
|
|
278
|
-
if (entry.socket) {
|
|
279
|
-
closeSocket(entry, entry.socket, 1011, "worker websocket outbound buffer overflow");
|
|
280
|
-
}
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
entry.outbound.push(data);
|
|
291
|
+
queueOutbound(entry, data);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const socket = entry.socket;
|
|
295
|
+
if (sendNow(entry, socket, data)) {
|
|
284
296
|
return;
|
|
285
297
|
}
|
|
286
|
-
|
|
298
|
+
if (entry.socket === socket) {
|
|
299
|
+
closeSocket(entry, socket, 1011, "worker websocket unavailable during send");
|
|
300
|
+
}
|
|
301
|
+
queueOutbound(entry, data);
|
|
287
302
|
},
|
|
288
303
|
unregister(instanceId: string, workerId: string, reason: string) {
|
|
289
304
|
const key = connectionKey(instanceId, workerId);
|
|
@@ -54,6 +54,10 @@ export function createFakeWorkerSupervisor(
|
|
|
54
54
|
abortTurn() {},
|
|
55
55
|
deliverInputs() {},
|
|
56
56
|
acceptTurnStart() {},
|
|
57
|
+
reconcileAcceptedTurnStart() {
|
|
58
|
+
return false;
|
|
59
|
+
},
|
|
60
|
+
acknowledgeTurnTerminal() {},
|
|
57
61
|
questionResponse() {},
|
|
58
62
|
integrationToolResult() {},
|
|
59
63
|
credentialUpdateResult() {},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createReviewSubject, type ReviewSubject } from "@leitwerk-dev/domain";
|
|
2
1
|
import {
|
|
3
2
|
type ExtensionProcessDefinition,
|
|
4
3
|
humanTurn,
|
|
@@ -54,23 +53,12 @@ export interface TestIpcHandlerDeps
|
|
|
54
53
|
|
|
55
54
|
interface TestProcessState {
|
|
56
55
|
readyForHumanReview: boolean;
|
|
57
|
-
reviewSubject: ReviewSubject | null;
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
const testProcessGraphRegistry = createDefaultTestProcessGraphRegistry();
|
|
61
59
|
const ticketTurnGraph = getProcessGraph(testProcessGraphRegistry, "ticket_issue_process");
|
|
62
60
|
const mrPolishGraph = getProcessGraph(testProcessGraphRegistry, "mr_polish_process");
|
|
63
61
|
|
|
64
|
-
function parseReviewSubject(value: unknown): ReviewSubject | null {
|
|
65
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const kind = (value as { kind?: unknown }).kind;
|
|
69
|
-
return typeof kind === "string" && ["plan", "implementation"].includes(kind)
|
|
70
|
-
? { kind: kind as ReviewSubject["kind"] }
|
|
71
|
-
: null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
62
|
function buildTestProcessTurnDefinitions(
|
|
75
63
|
graph: ProcessGraphView,
|
|
76
64
|
): ReadonlyMap<string, TurnDefinition<Record<string, never>, TestProcessState>> {
|
|
@@ -127,7 +115,6 @@ function createTestProcess(
|
|
|
127
115
|
typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
|
|
128
116
|
return {
|
|
129
117
|
readyForHumanReview: record.readyForHumanReview === true,
|
|
130
|
-
reviewSubject: parseReviewSubject(record.reviewSubject),
|
|
131
118
|
};
|
|
132
119
|
},
|
|
133
120
|
serialize(value: TestProcessState) {
|
|
@@ -135,7 +122,7 @@ function createTestProcess(
|
|
|
135
122
|
},
|
|
136
123
|
},
|
|
137
124
|
initialState() {
|
|
138
|
-
return { readyForHumanReview: false
|
|
125
|
+
return { readyForHumanReview: false };
|
|
139
126
|
},
|
|
140
127
|
server,
|
|
141
128
|
});
|
|
@@ -146,7 +133,6 @@ const testTurns = new Map<string, TurnDefinition<Record<string, never>, TestProc
|
|
|
146
133
|
"plan_review",
|
|
147
134
|
humanTurn({
|
|
148
135
|
description: "Plan review",
|
|
149
|
-
reviewSubject: createReviewSubject("plan"),
|
|
150
136
|
reviewSemanticRef: "plan",
|
|
151
137
|
actions: {
|
|
152
138
|
request_revision: {
|
|
@@ -161,7 +147,6 @@ const testTurns = new Map<string, TurnDefinition<Record<string, never>, TestProc
|
|
|
161
147
|
"implementation_review",
|
|
162
148
|
humanTurn({
|
|
163
149
|
description: "Implementation review",
|
|
164
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
165
150
|
reviewSemanticRef: "review",
|
|
166
151
|
actions: {
|
|
167
152
|
request_changes: {
|
|
@@ -176,7 +161,6 @@ const testTurns = new Map<string, TurnDefinition<Record<string, never>, TestProc
|
|
|
176
161
|
"mr_polish_review",
|
|
177
162
|
humanTurn({
|
|
178
163
|
description: "MR polish review",
|
|
179
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
180
164
|
reviewSemanticRef: "review",
|
|
181
165
|
actions: {
|
|
182
166
|
request_changes: {
|
|
@@ -259,7 +243,6 @@ const ticketTurnProcess = createTestProcess("ticket_issue_process", ticketTurnGr
|
|
|
259
243
|
await ctx.transition({
|
|
260
244
|
turnId: "plan_review",
|
|
261
245
|
lifecycleStatus: "waiting",
|
|
262
|
-
state: { ...ctx.state, reviewSubject: createReviewSubject("plan") },
|
|
263
246
|
});
|
|
264
247
|
ctx.applyLifecycleEffects?.({
|
|
265
248
|
processPatch: { planRevision },
|
|
@@ -291,7 +274,6 @@ const ticketTurnProcess = createTestProcess("ticket_issue_process", ticketTurnGr
|
|
|
291
274
|
await ctx.transition({
|
|
292
275
|
turnId: "address_review",
|
|
293
276
|
lifecycleStatus: "active",
|
|
294
|
-
state: { ...ctx.state, readyForHumanReview: false, reviewSubject: null },
|
|
295
277
|
});
|
|
296
278
|
ctx.applyLifecycleEffects?.({
|
|
297
279
|
broadcasts: [
|
|
@@ -310,7 +292,6 @@ const ticketTurnProcess = createTestProcess("ticket_issue_process", ticketTurnGr
|
|
|
310
292
|
await ctx.transition({
|
|
311
293
|
turnId: "implementation_review",
|
|
312
294
|
lifecycleStatus: "waiting",
|
|
313
|
-
state: { ...ctx.state, reviewSubject: createReviewSubject("implementation") },
|
|
314
295
|
});
|
|
315
296
|
ctx.applyLifecycleEffects?.({
|
|
316
297
|
broadcasts: [
|
|
@@ -329,7 +310,6 @@ const ticketTurnProcess = createTestProcess("ticket_issue_process", ticketTurnGr
|
|
|
329
310
|
state: {
|
|
330
311
|
...ctx.state,
|
|
331
312
|
readyForHumanReview: true,
|
|
332
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
333
313
|
},
|
|
334
314
|
});
|
|
335
315
|
});
|
|
@@ -341,7 +321,6 @@ const mrPolishProcess = createTestProcess("mr_polish_process", mrPolishGraph, (a
|
|
|
341
321
|
state: {
|
|
342
322
|
...ctx.state,
|
|
343
323
|
readyForHumanReview: true,
|
|
344
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
345
324
|
},
|
|
346
325
|
});
|
|
347
326
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TurnId } from "@leitwerk-dev/domain";
|
|
2
2
|
import {
|
|
3
3
|
type AutomaticTurnDefinition,
|
|
4
4
|
automaticTurn,
|
|
@@ -38,7 +38,6 @@ export function createFixtureHumanTurn(
|
|
|
38
38
|
): HumanTurnDefinition<Record<string, never>, Record<string, never>> {
|
|
39
39
|
return humanTurn({
|
|
40
40
|
description: "Review",
|
|
41
|
-
reviewSubject: createReviewSubject("plan"),
|
|
42
41
|
reviewSemanticRef: "plan",
|
|
43
42
|
actions: {
|
|
44
43
|
mark_done: {
|
|
@@ -176,7 +175,6 @@ export function createDefaultTestProcessGraphRegistry(): ReadonlyMap<
|
|
|
176
175
|
outcomes: { plan_saved: { description: "plan_saved", parameters: {}, to: "plan_review" } },
|
|
177
176
|
}),
|
|
178
177
|
plan_review: createFixtureHumanTurn({
|
|
179
|
-
reviewSubject: createReviewSubject("plan"),
|
|
180
178
|
reviewSemanticRef: "plan",
|
|
181
179
|
actions: {
|
|
182
180
|
revision_requested: {
|
|
@@ -198,7 +196,6 @@ export function createDefaultTestProcessGraphRegistry(): ReadonlyMap<
|
|
|
198
196
|
turnEnd: { outcome: "created", params: {}, to: "run_llm_review" },
|
|
199
197
|
}),
|
|
200
198
|
run_llm_review: createFixtureLlmTurn("run_llm_review", {
|
|
201
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
202
199
|
resultSemanticRef: "review",
|
|
203
200
|
turnEnd: undefined,
|
|
204
201
|
outcomes: {
|
|
@@ -227,7 +224,6 @@ export function createDefaultTestProcessGraphRegistry(): ReadonlyMap<
|
|
|
227
224
|
turnEnd: { outcome: "committed", params: {}, to: "implementation_review" },
|
|
228
225
|
}),
|
|
229
226
|
implementation_review: createFixtureHumanTurn({
|
|
230
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
231
227
|
reviewSemanticRef: "review",
|
|
232
228
|
}),
|
|
233
229
|
},
|
|
@@ -257,7 +253,6 @@ export function createDefaultTestProcessGraphRegistry(): ReadonlyMap<
|
|
|
257
253
|
turnEnd: { outcome: "committed", params: {}, to: "mr_polish_review" },
|
|
258
254
|
}),
|
|
259
255
|
mr_polish_review: createFixtureHumanTurn({
|
|
260
|
-
reviewSubject: createReviewSubject("implementation"),
|
|
261
256
|
reviewSemanticRef: "review",
|
|
262
257
|
}),
|
|
263
258
|
},
|