@leitwerk-dev/worker 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/{chunk-ZTJ7UAOC.js → chunk-O6332GRG.js} +100 -11
- package/dist/chunk-O6332GRG.js.map +1 -0
- package/dist/diagnostics.d.ts +5 -1
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/lifecycle-reducer.d.ts +4 -1
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reducer.js +52 -10
- package/dist/runtime/lifecycle-reducer.js.map +1 -1
- package/dist/runtime/turn-execution.d.ts +1 -1
- package/dist/runtime/turn-execution.d.ts.map +1 -1
- package/dist/runtime/turn-execution.js +30 -0
- package/dist/runtime/turn-execution.js.map +1 -1
- package/package.json +7 -7
- package/src/diagnostics.ts +2 -1
- package/src/runtime/index.ts +6 -0
- package/src/runtime/lifecycle-reducer.ts +79 -10
- package/src/runtime/turn-execution.ts +36 -1
- package/dist/chunk-ZTJ7UAOC.js.map +0 -1
|
@@ -4124,12 +4124,17 @@ function createInitialWorkerRuntimeState() {
|
|
|
4124
4124
|
publication: { kind: "none" }
|
|
4125
4125
|
},
|
|
4126
4126
|
credential: null,
|
|
4127
|
-
timers: {
|
|
4127
|
+
timers: {
|
|
4128
|
+
heartbeat: null,
|
|
4129
|
+
acceptance_retry: null,
|
|
4130
|
+
credential_poll: null,
|
|
4131
|
+
terminal_ack: null
|
|
4132
|
+
}
|
|
4128
4133
|
};
|
|
4129
4134
|
}
|
|
4130
4135
|
function deriveReportedWorkerState(state) {
|
|
4131
4136
|
if (state.phase.kind === "draining" || state.phase.kind === "cleaning") return "draining";
|
|
4132
|
-
if (state.phase.kind === "active" && (state.phase.turnStatus === "executing" || state.work.publication.kind === "terminal_snapshot") || state.work.deliveryHeadSequence !== null)
|
|
4137
|
+
if (state.phase.kind === "active" && (state.phase.turnStatus === "executing" || state.work.publication.kind === "terminal_snapshot" || state.work.publication.kind === "terminal_pending_ack") || state.work.deliveryHeadSequence !== null)
|
|
4133
4138
|
return "busy";
|
|
4134
4139
|
return "idle";
|
|
4135
4140
|
}
|
|
@@ -4224,6 +4229,24 @@ function beginTerminalSnapshot(state, point, turnRecordId, terminal, source, out
|
|
|
4224
4229
|
}
|
|
4225
4230
|
};
|
|
4226
4231
|
}
|
|
4232
|
+
var TERMINAL_ACK_RETRY_MS = 5e3;
|
|
4233
|
+
function publishTerminalAndAwaitAcknowledgement(state, terminal, outputs) {
|
|
4234
|
+
outputs.push(terminal.fact);
|
|
4235
|
+
if (terminal.park) outputs.push(protocol("worker.lifecycle_parked", terminal.park));
|
|
4236
|
+
return armTimer(
|
|
4237
|
+
{
|
|
4238
|
+
...state,
|
|
4239
|
+
work: {
|
|
4240
|
+
...state.work,
|
|
4241
|
+
publication: { kind: "terminal_pending_ack", terminal }
|
|
4242
|
+
}
|
|
4243
|
+
},
|
|
4244
|
+
outputs,
|
|
4245
|
+
"terminal_ack",
|
|
4246
|
+
TERMINAL_ACK_RETRY_MS,
|
|
4247
|
+
terminal.correlation.turnRecordId
|
|
4248
|
+
);
|
|
4249
|
+
}
|
|
4227
4250
|
function beginCleanupSnapshot(state, source, outputs) {
|
|
4228
4251
|
requireNoPublication(state);
|
|
4229
4252
|
const snapshot = {
|
|
@@ -4502,6 +4525,13 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4502
4525
|
})
|
|
4503
4526
|
);
|
|
4504
4527
|
}
|
|
4528
|
+
if (state.work.publication.kind === "terminal_pending_ack") {
|
|
4529
|
+
next = publishTerminalAndAwaitAcknowledgement(
|
|
4530
|
+
state,
|
|
4531
|
+
state.work.publication.terminal,
|
|
4532
|
+
outputs
|
|
4533
|
+
);
|
|
4534
|
+
}
|
|
4505
4535
|
break;
|
|
4506
4536
|
case "transport_failed": {
|
|
4507
4537
|
const failed = failureOutputs(state, { kind: "transport", error: event.error });
|
|
@@ -4535,7 +4565,12 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4535
4565
|
outputs.push({ kind: "cancel_timer", name });
|
|
4536
4566
|
next = {
|
|
4537
4567
|
...next,
|
|
4538
|
-
timers: {
|
|
4568
|
+
timers: {
|
|
4569
|
+
heartbeat: null,
|
|
4570
|
+
acceptance_retry: null,
|
|
4571
|
+
credential_poll: null,
|
|
4572
|
+
terminal_ack: null
|
|
4573
|
+
},
|
|
4539
4574
|
credential: null
|
|
4540
4575
|
};
|
|
4541
4576
|
break;
|
|
@@ -4603,6 +4638,18 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4603
4638
|
);
|
|
4604
4639
|
break;
|
|
4605
4640
|
}
|
|
4641
|
+
if (message.type === "worker.turn_terminal_recorded") {
|
|
4642
|
+
const publication = state.work.publication;
|
|
4643
|
+
if (publication.kind !== "terminal_pending_ack" || publication.terminal.correlation.turnRecordId !== message.payload.turnRecordId)
|
|
4644
|
+
break;
|
|
4645
|
+
outputs.push({ kind: "cancel_timer", name: "terminal_ack" });
|
|
4646
|
+
next = {
|
|
4647
|
+
...state,
|
|
4648
|
+
work: { ...state.work, publication: { kind: "none" } },
|
|
4649
|
+
timers: { ...state.timers, terminal_ack: null }
|
|
4650
|
+
};
|
|
4651
|
+
break;
|
|
4652
|
+
}
|
|
4606
4653
|
if (message.type === "worker.credential_update_accepted") {
|
|
4607
4654
|
const credential = state.credential;
|
|
4608
4655
|
if (!credential?.enabled || !credential.updatePending || message.payload.providerId !== credential.descriptor.providerId)
|
|
@@ -4863,8 +4910,7 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4863
4910
|
phase: state.phase.kind === "active" ? { ...state.phase, turnStatus: "completed" } : next.phase
|
|
4864
4911
|
};
|
|
4865
4912
|
if (state.session?.kind === "automatic") {
|
|
4866
|
-
|
|
4867
|
-
if (pending.park) outputs.push(protocol("worker.lifecycle_parked", pending.park));
|
|
4913
|
+
next = publishTerminalAndAwaitAcknowledgement(next, pending, outputs);
|
|
4868
4914
|
} else if (state.session) {
|
|
4869
4915
|
const point = event.result.kind === "outcome" ? "before_turn_outcome" : "before_turn_failed";
|
|
4870
4916
|
const snapshotPolicy = resolveWorkerSnapshotPolicy(
|
|
@@ -4904,6 +4950,7 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4904
4950
|
const publication = state.work.publication;
|
|
4905
4951
|
switch (publication.kind) {
|
|
4906
4952
|
case "none":
|
|
4953
|
+
case "terminal_pending_ack":
|
|
4907
4954
|
case "fatal_pending_cleanup":
|
|
4908
4955
|
break;
|
|
4909
4956
|
case "ready_snapshot":
|
|
@@ -4912,10 +4959,7 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4912
4959
|
break;
|
|
4913
4960
|
case "terminal_snapshot":
|
|
4914
4961
|
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
4915
|
-
|
|
4916
|
-
if (publication.terminal.park)
|
|
4917
|
-
outputs.push(protocol("worker.lifecycle_parked", publication.terminal.park));
|
|
4918
|
-
next = { ...state, work: { ...state.work, publication: { kind: "none" } } };
|
|
4962
|
+
next = publishTerminalAndAwaitAcknowledgement(state, publication.terminal, outputs);
|
|
4919
4963
|
break;
|
|
4920
4964
|
case "cleanup_snapshot":
|
|
4921
4965
|
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
@@ -4958,6 +5002,7 @@ function reduceWorkerRuntime(state, event) {
|
|
|
4958
5002
|
const publication = state.work.publication;
|
|
4959
5003
|
switch (publication.kind) {
|
|
4960
5004
|
case "none":
|
|
5005
|
+
case "terminal_pending_ack":
|
|
4961
5006
|
case "fatal_pending_cleanup":
|
|
4962
5007
|
break;
|
|
4963
5008
|
case "ready_snapshot":
|
|
@@ -5050,6 +5095,12 @@ function reduceWorkerRuntime(state, event) {
|
|
|
5050
5095
|
})
|
|
5051
5096
|
);
|
|
5052
5097
|
next = armTimer(next, outputs, "acceptance_retry", 1e3, event.correlation);
|
|
5098
|
+
} else if (event.name === "terminal_ack" && state.work.publication.kind === "terminal_pending_ack" && state.work.publication.terminal.correlation.turnRecordId === event.correlation) {
|
|
5099
|
+
next = publishTerminalAndAwaitAcknowledgement(
|
|
5100
|
+
next,
|
|
5101
|
+
state.work.publication.terminal,
|
|
5102
|
+
outputs
|
|
5103
|
+
);
|
|
5053
5104
|
} else if (event.name === "credential_poll" && state.credential?.enabled && !state.credential.sampling && !state.credential.updatePending) {
|
|
5054
5105
|
outputs.push({
|
|
5055
5106
|
kind: "sample_credentials",
|
|
@@ -5178,6 +5229,9 @@ function resolveWorkerRuntimeSettings(config, payload) {
|
|
|
5178
5229
|
}
|
|
5179
5230
|
|
|
5180
5231
|
// src/runtime/turn-execution.ts
|
|
5232
|
+
import {
|
|
5233
|
+
failActiveTurnProgress
|
|
5234
|
+
} from "@leitwerk-dev/domain";
|
|
5181
5235
|
import { assertValidLlmTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
5182
5236
|
|
|
5183
5237
|
// src/turn-execution-result.ts
|
|
@@ -6986,6 +7040,8 @@ async function executeSelectedTurn(input) {
|
|
|
6986
7040
|
}
|
|
6987
7041
|
const handler = resolvedWorkerProcess.definition.turns.get(currentTurnId);
|
|
6988
7042
|
if (!handler) throw new Error(`Validated turn handler '${currentTurnId}' is unavailable`);
|
|
7043
|
+
let automaticIntegrationCallIndex = 0;
|
|
7044
|
+
let latestProgressReport = null;
|
|
6989
7045
|
const ctx = {
|
|
6990
7046
|
process: processSnapshot,
|
|
6991
7047
|
projects: projectSnapshots,
|
|
@@ -6993,7 +7049,26 @@ async function executeSelectedTurn(input) {
|
|
|
6993
7049
|
state: resolvedWorkerProcess.state,
|
|
6994
7050
|
turnResultMarkdownBySemanticRef: input.session.turnResultMarkdownBySemanticRef,
|
|
6995
7051
|
turnResultMarkdownByProduct: input.session.turnResultMarkdownByProduct,
|
|
6996
|
-
workspaceRoot: input.session.workspaceRoot
|
|
7052
|
+
workspaceRoot: input.session.workspaceRoot,
|
|
7053
|
+
...selectedTurnType === "automatic" ? {
|
|
7054
|
+
reportProgress(report) {
|
|
7055
|
+
latestProgressReport = report;
|
|
7056
|
+
input.emit({ kind: "progress", turnRecordId: input.turnRecordId, report });
|
|
7057
|
+
},
|
|
7058
|
+
async callIntegrationTool(name, args) {
|
|
7059
|
+
const tool = input.integrationTools?.find((candidate) => candidate.name === name);
|
|
7060
|
+
if (!tool) {
|
|
7061
|
+
throw new Error(
|
|
7062
|
+
`Integration tool '${name}' is not authorized for turn '${currentTurnId}'`
|
|
7063
|
+
);
|
|
7064
|
+
}
|
|
7065
|
+
automaticIntegrationCallIndex += 1;
|
|
7066
|
+
return tool.execute(args, {
|
|
7067
|
+
toolCallId: `${input.turnRecordId}:${automaticIntegrationCallIndex}:${name}`,
|
|
7068
|
+
signal: input.signal
|
|
7069
|
+
});
|
|
7070
|
+
}
|
|
7071
|
+
} : {}
|
|
6997
7072
|
};
|
|
6998
7073
|
let terminal = null;
|
|
6999
7074
|
const appliedTargetedInputs = [];
|
|
@@ -7091,6 +7166,14 @@ async function executeSelectedTurn(input) {
|
|
|
7091
7166
|
}
|
|
7092
7167
|
return terminal;
|
|
7093
7168
|
} catch (error) {
|
|
7169
|
+
const failedProgressReport = latestProgressReport;
|
|
7170
|
+
if (failedProgressReport) {
|
|
7171
|
+
input.emit({
|
|
7172
|
+
kind: "progress",
|
|
7173
|
+
turnRecordId: input.turnRecordId,
|
|
7174
|
+
report: failActiveTurnProgress(failedProgressReport)
|
|
7175
|
+
});
|
|
7176
|
+
}
|
|
7094
7177
|
if (error instanceof TurnExecutionFailure) return failedResult(error, appliedTargetedInputs);
|
|
7095
7178
|
if (automaticExecutor)
|
|
7096
7179
|
return failedResult(automaticExecutor.failure(error), appliedTargetedInputs);
|
|
@@ -7259,6 +7342,12 @@ function createWorkerRuntime(options) {
|
|
|
7259
7342
|
complete({ kind: "session_tainted", reason: emission.reason });
|
|
7260
7343
|
} else if (emission.kind === "trace") {
|
|
7261
7344
|
reporter.workerTrace(emission.payload, command.session.selectedTurnId);
|
|
7345
|
+
} else if (emission.kind === "progress") {
|
|
7346
|
+
reporter.workerEvent(
|
|
7347
|
+
"turn.progress",
|
|
7348
|
+
{ turnRecordId: emission.turnRecordId, report: emission.report },
|
|
7349
|
+
command.session.selectedTurnId
|
|
7350
|
+
);
|
|
7262
7351
|
} else reporter.workerError(emission.payload, command.session.selectedTurnId);
|
|
7263
7352
|
}
|
|
7264
7353
|
})
|
|
@@ -8255,4 +8344,4 @@ export {
|
|
|
8255
8344
|
createWorkerRuntime,
|
|
8256
8345
|
createWorkerEntryRuntime
|
|
8257
8346
|
};
|
|
8258
|
-
//# sourceMappingURL=chunk-
|
|
8347
|
+
//# sourceMappingURL=chunk-O6332GRG.js.map
|