@leitwerk-dev/server 0.4.0 → 0.4.2
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-CsuxFZT5.d.ts → app-CtlotzYm.d.ts} +51 -1
- package/dist/app-KR3N2JAE.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-FPMDWQF7.js → chunk-OUA5EZS2.js} +518 -135
- package/dist/chunk-OUA5EZS2.js.map +1 -0
- package/dist/{chunk-MBHRCQFE.js → chunk-YLWY4UTT.js} +174 -57
- package/dist/chunk-YLWY4UTT.js.map +1 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +2 -0
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/dashboard-model-issues.d.ts +10 -0
- package/dist/dashboard-model-issues.d.ts.map +1 -0
- package/dist/db/process-instance-repo.d.ts +17 -0
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +9 -0
- package/dist/db/turn-summary-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/index.js +2 -2
- package/dist/main.js +3 -3
- package/dist/process-engine/engine.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/retry-startup.d.ts +2 -0
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +8 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.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/routes/dashboard.d.ts +17 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- package/dist/scoped-settings-service.d.ts +15 -0
- package/dist/scoped-settings-service.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts.map +1 -1
- package/dist/skills/skill-frontmatter.d.ts +2 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +1 -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/worker-supervisor.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/package.json +12 -12
- package/src/app.ts +62 -20
- package/src/config/config-loader.ts +2 -0
- package/src/config/config-types.ts +2 -0
- package/src/dashboard-model-issues.ts +199 -0
- package/src/db/process-instance-repo.ts +24 -0
- package/src/db/turn-start-record-repo.ts +5 -1
- package/src/db/turn-summary-repo.ts +25 -2
- package/src/domain-logic/outcome-tools.ts +14 -23
- package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
- package/src/process-engine/engine.ts +14 -0
- package/src/process-engine/ops/automatic-retry-startup.ts +93 -0
- package/src/process-engine/ops/retry-startup.ts +11 -3
- package/src/process-engine/recorder.ts +13 -0
- package/src/process-engine/types.ts +12 -0
- package/src/process-engine/writes/commit-writes.ts +1 -2
- package/src/process-model-availability-recovery.ts +6 -4
- package/src/routes/dashboard.ts +106 -0
- package/src/routes/process-actions.ts +1 -1
- package/src/scoped-settings-service.ts +61 -0
- package/src/server-bootstrap/register-http.ts +5 -0
- package/src/skills/extension-importer.ts +3 -6
- package/src/skills/skill-frontmatter.ts +7 -7
- package/src/skills/source-importer.ts +4 -13
- package/src/startup-evidence.ts +9 -8
- package/src/startup-retry-policy.ts +106 -0
- package/src/supervisor/worker-supervisor.ts +23 -1
- package/dist/app-JM4CBTND.js +0 -8
- package/dist/chunk-FPMDWQF7.js.map +0 -1
- package/dist/chunk-MBHRCQFE.js.map +0 -1
- /package/dist/{app-JM4CBTND.js.map → app-KR3N2JAE.js.map} +0 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
applySubmittedProcessTitleToLaunchPlan,
|
|
14
14
|
authenticateBrowserRequest,
|
|
15
15
|
authenticateRequest,
|
|
16
|
+
automaticStartupRecovery,
|
|
16
17
|
broadcastProcessAttentionToast,
|
|
17
18
|
buildFutureExecutionListView,
|
|
18
19
|
buildFutureExecutionSummaries,
|
|
@@ -114,9 +115,11 @@ import {
|
|
|
114
115
|
sendLauncherRequestNormalizationError,
|
|
115
116
|
sendScheduledActionMutationResponse,
|
|
116
117
|
serializeProcessGraph,
|
|
118
|
+
skillFrontmatter,
|
|
117
119
|
skillMetadata,
|
|
118
120
|
stampActorOnEvents,
|
|
119
121
|
stampActorOnQueuedInputs,
|
|
122
|
+
startupRetryState,
|
|
120
123
|
tokenExpiry,
|
|
121
124
|
truncateTextAtWordBoundary,
|
|
122
125
|
turnWaitPredicate,
|
|
@@ -127,7 +130,7 @@ import {
|
|
|
127
130
|
verifyOpaqueToken,
|
|
128
131
|
withTimeout,
|
|
129
132
|
writeTurnWait
|
|
130
|
-
} from "./chunk-
|
|
133
|
+
} from "./chunk-YLWY4UTT.js";
|
|
131
134
|
|
|
132
135
|
// src/app.ts
|
|
133
136
|
import path10 from "node:path";
|
|
@@ -7412,6 +7415,151 @@ function maybeBroadcastErrorAttentionToast(deps, result, input = {}) {
|
|
|
7412
7415
|
return result;
|
|
7413
7416
|
}
|
|
7414
7417
|
|
|
7418
|
+
// src/process-engine/ops/retry-startup.ts
|
|
7419
|
+
var RetryStartup = defineOperation({
|
|
7420
|
+
kind: "retry_startup",
|
|
7421
|
+
label: "Retry startup",
|
|
7422
|
+
admission: "new_turn",
|
|
7423
|
+
decide(ctx, input) {
|
|
7424
|
+
if (ctx.process.lifecycleStatus !== "error" || ctx.process.currentExecution?.kind !== "worker_start" || ctx.process.currentExecution.id !== input.startRecordId) {
|
|
7425
|
+
return reject("stale_turn_start", "Startup retry target is no longer current");
|
|
7426
|
+
}
|
|
7427
|
+
const failed = ctx.deps.turnStarts.getById(input.startRecordId);
|
|
7428
|
+
if (!failed || failed.state.kind !== "preparation_failed" && failed.state.kind !== "bootstrap_failed") {
|
|
7429
|
+
return reject("retry_target_missing", "Startup retry requires a failed current start");
|
|
7430
|
+
}
|
|
7431
|
+
const id = generateId("tsr");
|
|
7432
|
+
const state = failed.state.kind === "preparation_failed" ? {
|
|
7433
|
+
...failed.state,
|
|
7434
|
+
// A new operator retry must validate current inputs; the previous
|
|
7435
|
+
// failure remains on its original start record.
|
|
7436
|
+
code: "model_required",
|
|
7437
|
+
safeSummary: "LLM start requires retry preparation"
|
|
7438
|
+
} : failed.state.start.kind === "automatic" ? { kind: "starting", start: failed.state.start } : {
|
|
7439
|
+
kind: "preparation_failed",
|
|
7440
|
+
requestedModelProfileId: failed.state.start.model.profileId,
|
|
7441
|
+
providerOptions: { ...failed.state.start.providerOptions },
|
|
7442
|
+
code: "model_required",
|
|
7443
|
+
safeSummary: "LLM start requires retry preparation",
|
|
7444
|
+
...failed.state.start.modelSelectionProvenance ? { modelSelectionProvenance: failed.state.start.modelSelectionProvenance } : {}
|
|
7445
|
+
};
|
|
7446
|
+
state.automaticRetry = input.automaticRetry;
|
|
7447
|
+
const writes = createWrites({
|
|
7448
|
+
workerIntent: state.kind === "starting" ? { kind: "restart_worker" } : void 0
|
|
7449
|
+
});
|
|
7450
|
+
writes.turnStartWrites.push({
|
|
7451
|
+
kind: "create",
|
|
7452
|
+
input: {
|
|
7453
|
+
id,
|
|
7454
|
+
instanceId: failed.instanceId,
|
|
7455
|
+
turnId: failed.turnId,
|
|
7456
|
+
turnType: failed.turnType,
|
|
7457
|
+
proposedTurnRecordId: generateId("trn"),
|
|
7458
|
+
startKind: "startup_retry",
|
|
7459
|
+
recoveryTurnRecordId: failed.recoveryTurnRecordId,
|
|
7460
|
+
continuation: failed.continuation,
|
|
7461
|
+
state,
|
|
7462
|
+
iteration: failed.iteration ?? null
|
|
7463
|
+
}
|
|
7464
|
+
});
|
|
7465
|
+
applyProcessPatchField(writes, ctx.process, "currentExecution", { kind: "worker_start", id });
|
|
7466
|
+
applyProcessPatchField(
|
|
7467
|
+
writes,
|
|
7468
|
+
ctx.process,
|
|
7469
|
+
"lifecycleStatus",
|
|
7470
|
+
state.kind === "starting" ? "active" : "error"
|
|
7471
|
+
);
|
|
7472
|
+
appendProcessEvent(writes, ctx.process, {
|
|
7473
|
+
eventType: "startup_retry_scheduled",
|
|
7474
|
+
level: "info",
|
|
7475
|
+
message: "Startup retry scheduled",
|
|
7476
|
+
data: {
|
|
7477
|
+
previousStartRecordId: failed.id,
|
|
7478
|
+
startRecordId: id,
|
|
7479
|
+
state: state.kind,
|
|
7480
|
+
retrySource: input.automaticRetry ? "automatic" : "manual"
|
|
7481
|
+
}
|
|
7482
|
+
});
|
|
7483
|
+
stampActorOnEvents(writes, input.actor, "startup_retry_scheduled");
|
|
7484
|
+
return accept({
|
|
7485
|
+
writes,
|
|
7486
|
+
data: { startRecordId: id },
|
|
7487
|
+
metadata: modelOverrideMetadata(input)
|
|
7488
|
+
});
|
|
7489
|
+
}
|
|
7490
|
+
});
|
|
7491
|
+
|
|
7492
|
+
// src/process-engine/ops/automatic-retry-startup.ts
|
|
7493
|
+
var AutomaticRetryStartup = defineOperation({
|
|
7494
|
+
kind: "automatic_retry_startup",
|
|
7495
|
+
label: "Automatic startup recovery",
|
|
7496
|
+
admission: "new_turn",
|
|
7497
|
+
async decide(ctx, input) {
|
|
7498
|
+
if (ctx.process.lifecycleStatus !== "error" || ctx.process.currentExecution?.kind !== "worker_start" || ctx.process.currentExecution.id !== input.startRecordId)
|
|
7499
|
+
return reject("stale_turn_start", "Startup recovery target is no longer current");
|
|
7500
|
+
const start = ctx.deps.turnStarts.getById(input.startRecordId);
|
|
7501
|
+
if (!start || start.state.kind !== "preparation_failed" && start.state.kind !== "bootstrap_failed")
|
|
7502
|
+
return reject(
|
|
7503
|
+
"retry_target_missing",
|
|
7504
|
+
"Automatic recovery requires an unaccepted failed start"
|
|
7505
|
+
);
|
|
7506
|
+
const retry = start.state.automaticRetry ?? startupRetryState(
|
|
7507
|
+
start,
|
|
7508
|
+
ctx.deps.turnStarts.listByInstance(ctx.process.id),
|
|
7509
|
+
ctx.deps.events.listByInstanceEventTypes(ctx.process.id, ["startup_retry_scheduled"], -1)
|
|
7510
|
+
);
|
|
7511
|
+
let modelRestored = false;
|
|
7512
|
+
if (input.availabilityCause && start.state.kind === "preparation_failed") {
|
|
7513
|
+
const evaluation = ctx.deps.processModelPolicy.evaluate({
|
|
7514
|
+
kind: "preparation_recovery",
|
|
7515
|
+
cause: input.availabilityCause,
|
|
7516
|
+
process: ctx.process,
|
|
7517
|
+
currentStart: start,
|
|
7518
|
+
availability: ctx.deps.getModelAvailabilitySnapshot()
|
|
7519
|
+
});
|
|
7520
|
+
modelRestored = evaluation.ok && evaluation.selection !== null;
|
|
7521
|
+
}
|
|
7522
|
+
const summary = automaticStartupRecovery(start, retry, Date.now(), modelRestored);
|
|
7523
|
+
if (summary.status !== "ready") {
|
|
7524
|
+
if (start.state.automaticRetry && retry.nextRetryAt === summary.nextRetryAt)
|
|
7525
|
+
return accept({ data: summary });
|
|
7526
|
+
const metadata = { ...retry, nextRetryAt: summary.nextRetryAt };
|
|
7527
|
+
return accept({
|
|
7528
|
+
data: summary,
|
|
7529
|
+
writes: {
|
|
7530
|
+
turnStartWrites: [
|
|
7531
|
+
{
|
|
7532
|
+
kind: "cas_state",
|
|
7533
|
+
id: start.id,
|
|
7534
|
+
expectedKind: start.state.kind,
|
|
7535
|
+
state: { ...start.state, automaticRetry: metadata }
|
|
7536
|
+
}
|
|
7537
|
+
],
|
|
7538
|
+
// Refresh the recovery projection only when retained metadata changes.
|
|
7539
|
+
processPatch: { currentExecution: ctx.process.currentExecution },
|
|
7540
|
+
changedFields: ["currentExecution"]
|
|
7541
|
+
}
|
|
7542
|
+
});
|
|
7543
|
+
}
|
|
7544
|
+
const decision = await RetryStartup.decide(ctx, {
|
|
7545
|
+
...input,
|
|
7546
|
+
automaticRetry: { ...retry, starts: retry.starts + 1, nextRetryAt: null }
|
|
7547
|
+
});
|
|
7548
|
+
if (!decision.ok) return reject(decision.code, decision.message);
|
|
7549
|
+
return accept({
|
|
7550
|
+
writes: decision.writes,
|
|
7551
|
+
metadata: decision.metadata,
|
|
7552
|
+
data: {
|
|
7553
|
+
...summary,
|
|
7554
|
+
starts: retry.starts + 1,
|
|
7555
|
+
status: "retried",
|
|
7556
|
+
nextRetryAt: null,
|
|
7557
|
+
reason: "Worker startup retry requested."
|
|
7558
|
+
}
|
|
7559
|
+
});
|
|
7560
|
+
}
|
|
7561
|
+
});
|
|
7562
|
+
|
|
7415
7563
|
// src/process-engine/writes/build-process-abort-writes.ts
|
|
7416
7564
|
function supersedeExecution(writes, record4, start, recordedAt) {
|
|
7417
7565
|
writes.mappedRunWrites.push({ kind: "abort_active" });
|
|
@@ -8479,74 +8627,6 @@ var RetryFailedTurn = defineOperation({
|
|
|
8479
8627
|
}
|
|
8480
8628
|
});
|
|
8481
8629
|
|
|
8482
|
-
// src/process-engine/ops/retry-startup.ts
|
|
8483
|
-
var RetryStartup = defineOperation({
|
|
8484
|
-
kind: "retry_startup",
|
|
8485
|
-
label: "Retry startup",
|
|
8486
|
-
admission: "new_turn",
|
|
8487
|
-
decide(ctx, input) {
|
|
8488
|
-
if (ctx.process.lifecycleStatus !== "error" || ctx.process.currentExecution?.kind !== "worker_start" || ctx.process.currentExecution.id !== input.startRecordId) {
|
|
8489
|
-
return reject("stale_turn_start", "Startup retry target is no longer current");
|
|
8490
|
-
}
|
|
8491
|
-
const failed = ctx.deps.turnStarts.getById(input.startRecordId);
|
|
8492
|
-
if (!failed || failed.state.kind !== "preparation_failed" && failed.state.kind !== "bootstrap_failed") {
|
|
8493
|
-
return reject("retry_target_missing", "Startup retry requires a failed current start");
|
|
8494
|
-
}
|
|
8495
|
-
const id = generateId("tsr");
|
|
8496
|
-
const state = failed.state.kind === "preparation_failed" ? {
|
|
8497
|
-
...failed.state,
|
|
8498
|
-
// A new operator retry must validate current inputs; the previous
|
|
8499
|
-
// failure remains on its original start record.
|
|
8500
|
-
code: "model_required",
|
|
8501
|
-
safeSummary: "LLM start requires retry preparation"
|
|
8502
|
-
} : failed.state.start.kind === "automatic" ? { kind: "starting", start: failed.state.start } : {
|
|
8503
|
-
kind: "preparation_failed",
|
|
8504
|
-
requestedModelProfileId: failed.state.start.model.profileId,
|
|
8505
|
-
providerOptions: { ...failed.state.start.providerOptions },
|
|
8506
|
-
code: "model_required",
|
|
8507
|
-
safeSummary: "LLM start requires retry preparation",
|
|
8508
|
-
...failed.state.start.modelSelectionProvenance ? { modelSelectionProvenance: failed.state.start.modelSelectionProvenance } : {}
|
|
8509
|
-
};
|
|
8510
|
-
const writes = createWrites({
|
|
8511
|
-
workerIntent: state.kind === "starting" ? { kind: "restart_worker" } : void 0
|
|
8512
|
-
});
|
|
8513
|
-
writes.turnStartWrites.push({
|
|
8514
|
-
kind: "create",
|
|
8515
|
-
input: {
|
|
8516
|
-
id,
|
|
8517
|
-
instanceId: failed.instanceId,
|
|
8518
|
-
turnId: failed.turnId,
|
|
8519
|
-
turnType: failed.turnType,
|
|
8520
|
-
proposedTurnRecordId: generateId("trn"),
|
|
8521
|
-
startKind: "startup_retry",
|
|
8522
|
-
recoveryTurnRecordId: failed.recoveryTurnRecordId,
|
|
8523
|
-
continuation: failed.continuation,
|
|
8524
|
-
state,
|
|
8525
|
-
iteration: failed.iteration ?? null
|
|
8526
|
-
}
|
|
8527
|
-
});
|
|
8528
|
-
applyProcessPatchField(writes, ctx.process, "currentExecution", { kind: "worker_start", id });
|
|
8529
|
-
applyProcessPatchField(
|
|
8530
|
-
writes,
|
|
8531
|
-
ctx.process,
|
|
8532
|
-
"lifecycleStatus",
|
|
8533
|
-
state.kind === "starting" ? "active" : "error"
|
|
8534
|
-
);
|
|
8535
|
-
appendProcessEvent(writes, ctx.process, {
|
|
8536
|
-
eventType: "startup_retry_scheduled",
|
|
8537
|
-
level: "info",
|
|
8538
|
-
message: "Startup retry scheduled",
|
|
8539
|
-
data: { previousStartRecordId: failed.id, startRecordId: id, state: state.kind }
|
|
8540
|
-
});
|
|
8541
|
-
stampActorOnEvents(writes, input.actor, "startup_retry_scheduled");
|
|
8542
|
-
return accept({
|
|
8543
|
-
writes,
|
|
8544
|
-
data: { startRecordId: id },
|
|
8545
|
-
metadata: modelOverrideMetadata(input)
|
|
8546
|
-
});
|
|
8547
|
-
}
|
|
8548
|
-
});
|
|
8549
|
-
|
|
8550
8630
|
// src/domain-logic/turn-record-guards.ts
|
|
8551
8631
|
function validationFailure(code, message) {
|
|
8552
8632
|
return { ok: false, code, message };
|
|
@@ -8798,29 +8878,12 @@ function validationFailure2(code, message) {
|
|
|
8798
8878
|
return { ok: false, code, message };
|
|
8799
8879
|
}
|
|
8800
8880
|
function jsonValuesEqual(left, right) {
|
|
8801
|
-
if (left === right)
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
}
|
|
8808
|
-
return left.every((entry, index) => jsonValuesEqual(entry, right[index]));
|
|
8809
|
-
}
|
|
8810
|
-
if (isJsonObject(left) && isJsonObject(right)) {
|
|
8811
|
-
const leftKeys = Object.keys(left).sort();
|
|
8812
|
-
const rightKeys = Object.keys(right).sort();
|
|
8813
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
8814
|
-
return false;
|
|
8815
|
-
}
|
|
8816
|
-
for (let index = 0; index < leftKeys.length; index += 1) {
|
|
8817
|
-
if (leftKeys[index] !== rightKeys[index]) {
|
|
8818
|
-
return false;
|
|
8819
|
-
}
|
|
8820
|
-
}
|
|
8821
|
-
return leftKeys.every((key) => jsonValuesEqual(left[key], right[key]));
|
|
8822
|
-
}
|
|
8823
|
-
return false;
|
|
8881
|
+
if (left === right) return true;
|
|
8882
|
+
if (Array.isArray(left) && Array.isArray(right))
|
|
8883
|
+
return left.length === right.length && left.every((value, index) => jsonValuesEqual(value, right[index]));
|
|
8884
|
+
return isJsonObject(left) && isJsonObject(right) && Object.keys(left).length === Object.keys(right).length && Object.keys(left).every(
|
|
8885
|
+
(key) => Object.hasOwn(right, key) && jsonValuesEqual(left[key], right[key])
|
|
8886
|
+
);
|
|
8824
8887
|
}
|
|
8825
8888
|
function resolveOutcomeValidationContract(turnDefinition, turnId, outcome) {
|
|
8826
8889
|
if (!turnDefinition) {
|
|
@@ -10246,9 +10309,8 @@ function commitWrites(deps, instanceId, writes) {
|
|
|
10246
10309
|
}
|
|
10247
10310
|
for (const write of writes.turnStartWrites) {
|
|
10248
10311
|
if (write.kind === "create") repos.turnStarts.create(write.input);
|
|
10249
|
-
else if (!repos.turnStarts.compareAndSetState(write))
|
|
10312
|
+
else if (!repos.turnStarts.compareAndSetState(write))
|
|
10250
10313
|
throw new Error(`Turn start '${write.id}' changed before acceptance`);
|
|
10251
|
-
}
|
|
10252
10314
|
}
|
|
10253
10315
|
const committedLeafOutcomeSnapshots = [];
|
|
10254
10316
|
const committedAnnotationChanges = [];
|
|
@@ -10622,6 +10684,14 @@ async function record2(deps, operation, input, initialProcess, decision) {
|
|
|
10622
10684
|
message: preparation.message
|
|
10623
10685
|
};
|
|
10624
10686
|
}
|
|
10687
|
+
for (const write of decision.writes.turnStartWrites) {
|
|
10688
|
+
if (write.kind !== "create") continue;
|
|
10689
|
+
write.input.id ??= generateId("tsr");
|
|
10690
|
+
const original = baselineWrites.turnStartWrites.find(
|
|
10691
|
+
(entry) => entry.kind === "create" && entry.input.id === write.input.id
|
|
10692
|
+
);
|
|
10693
|
+
write.input.state.automaticRetry = original?.kind === "create" && original.input.state.automaticRetry ? original.input.state.automaticRetry : { episodeStartRecordId: write.input.id, starts: 1, nextRetryAt: null };
|
|
10694
|
+
}
|
|
10625
10695
|
let commit;
|
|
10626
10696
|
try {
|
|
10627
10697
|
commit = commitWrites(getRecordDeps(deps), input.instanceId, decision.writes);
|
|
@@ -11001,6 +11071,15 @@ function createProcessEngine(deps) {
|
|
|
11001
11071
|
retryStartup(instanceId, startRecordId, opts) {
|
|
11002
11072
|
return run(RetryStartup, { instanceId, startRecordId, ...opts ?? {} });
|
|
11003
11073
|
},
|
|
11074
|
+
async retryStartupAutomatically(instanceId, startRecordId, opts) {
|
|
11075
|
+
const result = await run(AutomaticRetryStartup, { instanceId, startRecordId, ...opts });
|
|
11076
|
+
if (!result.ok || result.data.status !== "retried") return result;
|
|
11077
|
+
const current = deps.processes.getById(instanceId)?.currentExecution;
|
|
11078
|
+
const start = current?.kind === "worker_start" ? deps.turnStarts.getById(current.id) : null;
|
|
11079
|
+
if (start && (start.state.kind === "preparation_failed" || start.state.kind === "bootstrap_failed"))
|
|
11080
|
+
return { ...result, data: automaticStartupRecovery(start, startupRetryState(start, [])) };
|
|
11081
|
+
return result;
|
|
11082
|
+
},
|
|
11004
11083
|
continueFailedTurn(instanceId, turnRecordId, options) {
|
|
11005
11084
|
return run(ContinueFailedTurn, { instanceId, turnRecordId, options });
|
|
11006
11085
|
},
|
|
@@ -11080,6 +11159,7 @@ var WORKER_LEASE_TRANSITIONS = [
|
|
|
11080
11159
|
{ from: "idle", to: "failed", observation: "failure_reported" },
|
|
11081
11160
|
{ from: "busy", to: "failed", observation: "failure_reported" },
|
|
11082
11161
|
{ from: "draining", to: "failed", observation: "failure_reported" },
|
|
11162
|
+
{ from: "cleanup", to: "failed", observation: "failure_reported" },
|
|
11083
11163
|
{ from: "draining", to: "cleanup", observation: "cleanup_completed" },
|
|
11084
11164
|
{ from: "failed", to: "cleanup", observation: "cleanup_completed" },
|
|
11085
11165
|
{ from: "spawning", to: "exited", observation: "process_exited" },
|
|
@@ -11106,7 +11186,7 @@ var WORKER_LEASE_NOOPS = {
|
|
|
11106
11186
|
busy_reported: /* @__PURE__ */ new Set(["busy", "draining", "failed", "cleanup", "exited"]),
|
|
11107
11187
|
idle_reported: /* @__PURE__ */ new Set(["idle", "draining", "failed", "cleanup", "exited"]),
|
|
11108
11188
|
stop_requested: /* @__PURE__ */ new Set(["absent", "draining", "failed", "cleanup", "exited"]),
|
|
11109
|
-
failure_reported: /* @__PURE__ */ new Set(["failed", "
|
|
11189
|
+
failure_reported: /* @__PURE__ */ new Set(["failed", "exited"]),
|
|
11110
11190
|
cleanup_completed: /* @__PURE__ */ new Set(["cleanup", "exited"]),
|
|
11111
11191
|
process_exited: /* @__PURE__ */ new Set(["absent", "exited"]),
|
|
11112
11192
|
reclaimed: /* @__PURE__ */ new Set(["absent"])
|
|
@@ -11561,9 +11641,11 @@ async function recoverModelAvailabilityFailures(input) {
|
|
|
11561
11641
|
availability: input.availability
|
|
11562
11642
|
});
|
|
11563
11643
|
if (!evaluation.ok || !evaluation.selection) continue;
|
|
11564
|
-
const result = await input.commands.
|
|
11565
|
-
|
|
11566
|
-
|
|
11644
|
+
const result = await input.commands.retryStartupAutomatically(process2.id, start.id, {
|
|
11645
|
+
availabilityCause: input.cause
|
|
11646
|
+
});
|
|
11647
|
+
if (result.ok && result.data.status === "retried") recovered += 1;
|
|
11648
|
+
else if (!result.ok && result.code !== "stale_turn_start") {
|
|
11567
11649
|
input.logger?.warn(
|
|
11568
11650
|
{ instanceId: process2.id, startRecordId: start.id, code: result.code },
|
|
11569
11651
|
"Model availability recovery was rejected"
|
|
@@ -13439,6 +13521,46 @@ function createScopedSettingsService(input) {
|
|
|
13439
13521
|
}
|
|
13440
13522
|
discoverLocal();
|
|
13441
13523
|
return {
|
|
13524
|
+
modelReferences() {
|
|
13525
|
+
const references = [];
|
|
13526
|
+
const append = (definition, value, subjectId, label, invalid = false) => {
|
|
13527
|
+
let modelProfileId = null;
|
|
13528
|
+
try {
|
|
13529
|
+
const parsed = definition.schema.parse(value);
|
|
13530
|
+
if (parsed !== null && (typeof parsed !== "string" || !parsed.trim())) invalid = true;
|
|
13531
|
+
else modelProfileId = typeof parsed === "string" ? parsed.trim() : null;
|
|
13532
|
+
} catch {
|
|
13533
|
+
invalid = true;
|
|
13534
|
+
}
|
|
13535
|
+
if (invalid || modelProfileId !== null)
|
|
13536
|
+
references.push({ key: definition.key, label, subjectId, modelProfileId, invalid });
|
|
13537
|
+
};
|
|
13538
|
+
for (const { definition } of definitions.values()) {
|
|
13539
|
+
if (definition.form.control === "model")
|
|
13540
|
+
append(
|
|
13541
|
+
definition,
|
|
13542
|
+
definition.defaultValue,
|
|
13543
|
+
null,
|
|
13544
|
+
`${definition.form.label} (code default)`
|
|
13545
|
+
);
|
|
13546
|
+
}
|
|
13547
|
+
const subjects = new Map(
|
|
13548
|
+
repos.scopedSettings.listSubjects().map((subject) => [subject.id, subject])
|
|
13549
|
+
);
|
|
13550
|
+
for (const override of repos.scopedSettings.listOverrides()) {
|
|
13551
|
+
const definition = definitions.get(override.key)?.definition;
|
|
13552
|
+
const subject = subjects.get(override.subjectId);
|
|
13553
|
+
if (override.reset || !subject || definition?.form.control !== "model") continue;
|
|
13554
|
+
append(
|
|
13555
|
+
definition,
|
|
13556
|
+
override.value,
|
|
13557
|
+
subject.id,
|
|
13558
|
+
`${subject.label}: ${definition.form.label}`,
|
|
13559
|
+
override.schemaVersion !== definition.schemaVersion || override.mode !== "replace"
|
|
13560
|
+
);
|
|
13561
|
+
}
|
|
13562
|
+
return references;
|
|
13563
|
+
},
|
|
13442
13564
|
async overview(scopeType) {
|
|
13443
13565
|
const subjects = listScopes().subjects.filter(
|
|
13444
13566
|
(subject) => subject.scopeType === scopeType && subject.hasSettings
|
|
@@ -13986,6 +14108,234 @@ function registerAuthRoutes(app, auth) {
|
|
|
13986
14108
|
});
|
|
13987
14109
|
}
|
|
13988
14110
|
|
|
14111
|
+
// src/dashboard-model-issues.ts
|
|
14112
|
+
import { parseStrictInstanceTurnConfigsJson, trimToNull as trimToNull3 } from "@leitwerk-dev/domain";
|
|
14113
|
+
import { parseFutureActionPayloadJson as parseFutureActionPayloadJson4, parseFutureLaunchPayloadJson as parseFutureLaunchPayloadJson5 } from "@leitwerk-dev/protocol";
|
|
14114
|
+
function buildDashboardModelIssues(deps) {
|
|
14115
|
+
const issues = /* @__PURE__ */ new Map();
|
|
14116
|
+
const availability = deps.modelStatusCache.snapshot();
|
|
14117
|
+
function add(code, key, message, source) {
|
|
14118
|
+
const id = JSON.stringify([code, key]);
|
|
14119
|
+
const issue = issues.get(id) ?? {
|
|
14120
|
+
id,
|
|
14121
|
+
code,
|
|
14122
|
+
severity: code === "model_stale" ? "warning" : "error",
|
|
14123
|
+
message,
|
|
14124
|
+
sources: []
|
|
14125
|
+
};
|
|
14126
|
+
if (!issue.sources.some((item) => item.label === source.label && item.href === source.href))
|
|
14127
|
+
issue.sources.push(source);
|
|
14128
|
+
issues.set(id, issue);
|
|
14129
|
+
}
|
|
14130
|
+
function check(profileId, source, processId = "") {
|
|
14131
|
+
const id = trimToNull3(profileId);
|
|
14132
|
+
if (!id) return;
|
|
14133
|
+
const result = deps.processModelPolicy.evaluate({
|
|
14134
|
+
kind: "runtime_selection",
|
|
14135
|
+
processId,
|
|
14136
|
+
selection: {
|
|
14137
|
+
modelProfileId: id,
|
|
14138
|
+
provenance: { kind: "explicit", source: "instance_default" }
|
|
14139
|
+
},
|
|
14140
|
+
availability
|
|
14141
|
+
});
|
|
14142
|
+
if (result.ok) return;
|
|
14143
|
+
const key = result.code === "model_profile_not_allowed" ? JSON.stringify([id, processId]) : id;
|
|
14144
|
+
const message = presentProcessModelPolicyFailure(result);
|
|
14145
|
+
add(
|
|
14146
|
+
result.code,
|
|
14147
|
+
key,
|
|
14148
|
+
result.code === "model_stale" || result.code === "model_unavailable" ? `${id}: ${message}` : message,
|
|
14149
|
+
source
|
|
14150
|
+
);
|
|
14151
|
+
}
|
|
14152
|
+
function checkPersisted(input, source) {
|
|
14153
|
+
check(
|
|
14154
|
+
input.defaultModelProfileId,
|
|
14155
|
+
{ ...source, label: `${source.label}: default model` },
|
|
14156
|
+
input.processId
|
|
14157
|
+
);
|
|
14158
|
+
check(
|
|
14159
|
+
input.selectedTurnModelProfileId,
|
|
14160
|
+
{ ...source, label: `${source.label}: selected step` },
|
|
14161
|
+
input.processId
|
|
14162
|
+
);
|
|
14163
|
+
const parsed = parseStrictInstanceTurnConfigsJson(
|
|
14164
|
+
input.processId,
|
|
14165
|
+
input.turnConfigsJson ?? null
|
|
14166
|
+
);
|
|
14167
|
+
if (!parsed.ok) {
|
|
14168
|
+
add(
|
|
14169
|
+
"invalid_model_configuration",
|
|
14170
|
+
source.href ?? source.label,
|
|
14171
|
+
"Saved step model configuration is invalid.",
|
|
14172
|
+
source
|
|
14173
|
+
);
|
|
14174
|
+
return;
|
|
14175
|
+
}
|
|
14176
|
+
for (const [turnId, config2] of Object.entries(parsed.value))
|
|
14177
|
+
check(
|
|
14178
|
+
config2.modelProfileId,
|
|
14179
|
+
{ ...source, label: `${source.label}: ${turnId}` },
|
|
14180
|
+
input.processId
|
|
14181
|
+
);
|
|
14182
|
+
}
|
|
14183
|
+
const config = deps.config;
|
|
14184
|
+
if (config) {
|
|
14185
|
+
for (const profile2 of config.pi.model_profiles)
|
|
14186
|
+
check(profile2.id, { label: `pi.model_profiles (${profile2.id})`, href: null });
|
|
14187
|
+
check(config.pi.default_model_profile, { label: "pi.default_model_profile", href: null });
|
|
14188
|
+
check(config.pi.process_title_generation.model_profile, {
|
|
14189
|
+
label: "pi.process_title_generation.model_profile",
|
|
14190
|
+
href: null
|
|
14191
|
+
});
|
|
14192
|
+
for (const [processId, processConfig] of Object.entries(config.process_configs ?? {})) {
|
|
14193
|
+
const prefix = `process_configs.${processId}`;
|
|
14194
|
+
check(
|
|
14195
|
+
processConfig.default_model_profile,
|
|
14196
|
+
{ label: `${prefix}.default_model_profile`, href: null },
|
|
14197
|
+
processId
|
|
14198
|
+
);
|
|
14199
|
+
for (const [turnId, turnConfig] of Object.entries(processConfig.turn_configs ?? {}))
|
|
14200
|
+
check(
|
|
14201
|
+
turnConfig.model_profile,
|
|
14202
|
+
{ label: `${prefix}.turn_configs.${turnId}.model_profile`, href: null },
|
|
14203
|
+
processId
|
|
14204
|
+
);
|
|
14205
|
+
}
|
|
14206
|
+
}
|
|
14207
|
+
for (const reference of deps.scopedSettingsService?.modelReferences() ?? []) {
|
|
14208
|
+
const source = {
|
|
14209
|
+
label: `${reference.label} (${reference.key})`,
|
|
14210
|
+
href: reference.subjectId ? `/settings?scope=${encodeURIComponent(reference.subjectId)}` : null
|
|
14211
|
+
};
|
|
14212
|
+
if (reference.invalid)
|
|
14213
|
+
add(
|
|
14214
|
+
"invalid_model_configuration",
|
|
14215
|
+
`${reference.subjectId}:${reference.key}`,
|
|
14216
|
+
"Saved model setting is invalid. Correct it in Settings.",
|
|
14217
|
+
source
|
|
14218
|
+
);
|
|
14219
|
+
else check(reference.modelProfileId, source);
|
|
14220
|
+
}
|
|
14221
|
+
for (const watcher of deps.processWatchers?.listAll() ?? []) {
|
|
14222
|
+
const source = { label: watcher.configPath, href: "/watchers" };
|
|
14223
|
+
check(watcher.launchModelConfig.defaultModelProfileId, source, watcher.processId);
|
|
14224
|
+
for (const [turnId, turnConfig] of Object.entries(watcher.launchModelConfig.turnConfigs ?? {}))
|
|
14225
|
+
check(
|
|
14226
|
+
turnConfig.modelProfileId,
|
|
14227
|
+
{ ...source, label: `${source.label}: ${turnId}` },
|
|
14228
|
+
watcher.processId
|
|
14229
|
+
);
|
|
14230
|
+
}
|
|
14231
|
+
for (const process2 of deps.processes.listModelConfigurations()) {
|
|
14232
|
+
checkPersisted(
|
|
14233
|
+
{
|
|
14234
|
+
...process2,
|
|
14235
|
+
selectedTurnModelProfileId: process2.selectedTurnId ? process2.selectedTurnModelProfileId : null
|
|
14236
|
+
},
|
|
14237
|
+
{
|
|
14238
|
+
label: process2.title ?? process2.id,
|
|
14239
|
+
href: `/processes/${encodeURIComponent(process2.id)}?inspect=process§ion=inputs`
|
|
14240
|
+
}
|
|
14241
|
+
);
|
|
14242
|
+
}
|
|
14243
|
+
for (const execution of deps.futureExecutions.listAll()) {
|
|
14244
|
+
const source = {
|
|
14245
|
+
label: `Scheduled ${execution.kind}: ${execution.id}`,
|
|
14246
|
+
href: execution.kind === "launch" ? `/future-launches/${encodeURIComponent(execution.id)}` : `/processes/${encodeURIComponent(execution.instanceId ?? "")}`
|
|
14247
|
+
};
|
|
14248
|
+
check(execution.modelSelection?.modelProfileId, source, execution.processId);
|
|
14249
|
+
const parsed = execution.kind === "launch" ? parseFutureLaunchPayloadJson5(execution.payloadJson) : parseFutureActionPayloadJson4(execution.payloadJson);
|
|
14250
|
+
if (!parsed.ok)
|
|
14251
|
+
add(
|
|
14252
|
+
"invalid_model_configuration",
|
|
14253
|
+
execution.id,
|
|
14254
|
+
`Scheduled ${execution.kind} configuration is invalid.`,
|
|
14255
|
+
source
|
|
14256
|
+
);
|
|
14257
|
+
else if ("launchPlan" in parsed.value)
|
|
14258
|
+
checkPersisted(parsed.value.launchPlan.processInput, source);
|
|
14259
|
+
else check(parsed.value.nextTurnModelProfileId, source, execution.processId);
|
|
14260
|
+
}
|
|
14261
|
+
for (const issue of issues.values()) issue.sources.sort((a, b) => a.label.localeCompare(b.label));
|
|
14262
|
+
return [...issues.values()].sort(
|
|
14263
|
+
(a, b) => (a.severity === b.severity ? 0 : a.severity === "error" ? -1 : 1) || a.message.localeCompare(b.message) || a.id.localeCompare(b.id)
|
|
14264
|
+
);
|
|
14265
|
+
}
|
|
14266
|
+
|
|
14267
|
+
// src/routes/dashboard.ts
|
|
14268
|
+
function aggregateDashboardCosts(rows) {
|
|
14269
|
+
const groups = /* @__PURE__ */ new Map();
|
|
14270
|
+
let totalUsd = 0;
|
|
14271
|
+
let pricedTurnCount = 0;
|
|
14272
|
+
for (const row of rows) {
|
|
14273
|
+
if (typeof row.costUsd !== "number" || !Number.isFinite(row.costUsd)) continue;
|
|
14274
|
+
const providerId = row.providerId && row.modelId ? row.providerId : null;
|
|
14275
|
+
const modelId = providerId ? row.modelId : null;
|
|
14276
|
+
const key = JSON.stringify([providerId, modelId]);
|
|
14277
|
+
const group = groups.get(key) ?? { providerId, modelId, costUsd: 0, turnCount: 0 };
|
|
14278
|
+
group.turnCount += 1;
|
|
14279
|
+
group.costUsd += row.costUsd;
|
|
14280
|
+
totalUsd += row.costUsd;
|
|
14281
|
+
pricedTurnCount += 1;
|
|
14282
|
+
groups.set(key, group);
|
|
14283
|
+
}
|
|
14284
|
+
const missingCostTurnCount = rows.length - pricedTurnCount;
|
|
14285
|
+
return {
|
|
14286
|
+
totalUsd: rows.length > 0 && pricedTurnCount === 0 ? null : totalUsd,
|
|
14287
|
+
totalLlmTurnCount: rows.length,
|
|
14288
|
+
pricedTurnCount,
|
|
14289
|
+
missingCostTurnCount,
|
|
14290
|
+
isPartial: missingCostTurnCount > 0,
|
|
14291
|
+
byModel: [...groups.values()].sort(
|
|
14292
|
+
(a, b) => b.costUsd - a.costUsd || (a.providerId ?? "").localeCompare(b.providerId ?? "") || (a.modelId ?? "").localeCompare(b.modelId ?? "")
|
|
14293
|
+
)
|
|
14294
|
+
};
|
|
14295
|
+
}
|
|
14296
|
+
function buildDashboard(deps) {
|
|
14297
|
+
const items = [...deps.processGraphs.values()].map((process2) => ({ id: process2.id, name: process2.displayName })).sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
14298
|
+
const watchers = (deps.processWatchers?.listAll() ?? []).map((watcher) => ({
|
|
14299
|
+
id: `${watcher.processId}.${watcher.watcherId}`,
|
|
14300
|
+
name: watcher.watcherLabel,
|
|
14301
|
+
enabled: watcher.enabled
|
|
14302
|
+
})).sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
14303
|
+
const skills = deps.skillCatalog?.list().installedSkills ?? [];
|
|
14304
|
+
const bundled = skills.filter((skill) => skill.registrationKind === "bundled").length;
|
|
14305
|
+
const lifecycle = Object.fromEntries(
|
|
14306
|
+
deps.processes.countOverviewByLifecycle({}).map((row) => [row.lifecycleStatus, row.value])
|
|
14307
|
+
);
|
|
14308
|
+
const processTotal = Object.values(lifecycle).reduce((sum, count) => sum + count, 0);
|
|
14309
|
+
lifecycle.running = (lifecycle.active ?? 0) + (lifecycle.discovered ?? 0);
|
|
14310
|
+
const statuses = ["running", "waiting", "error", "completed", "aborted"];
|
|
14311
|
+
return {
|
|
14312
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14313
|
+
definitions: { total: items.length, items },
|
|
14314
|
+
watchers: {
|
|
14315
|
+
total: watchers.length,
|
|
14316
|
+
enabled: watchers.filter((watcher) => watcher.enabled).length,
|
|
14317
|
+
items: watchers
|
|
14318
|
+
},
|
|
14319
|
+
skills: { total: skills.length, installed: skills.length - bundled, bundled },
|
|
14320
|
+
processes: {
|
|
14321
|
+
total: processTotal,
|
|
14322
|
+
byStatus: statuses.map((status) => ({ status, count: lifecycle[status] ?? 0 })),
|
|
14323
|
+
byDefinition: deps.processes.listOverviewProcessTypes({ status: "all" }).map((row) => ({
|
|
14324
|
+
processId: row.processId,
|
|
14325
|
+
name: deps.processGraphs.get(row.processId)?.displayName ?? row.processId,
|
|
14326
|
+
count: row.value
|
|
14327
|
+
})).sort(
|
|
14328
|
+
(a, b) => b.count - a.count || a.name.localeCompare(b.name) || a.processId.localeCompare(b.processId)
|
|
14329
|
+
)
|
|
14330
|
+
},
|
|
14331
|
+
costs: aggregateDashboardCosts(deps.turnSummaries.listDashboardCosts()),
|
|
14332
|
+
configuration: { issues: buildDashboardModelIssues(deps) }
|
|
14333
|
+
};
|
|
14334
|
+
}
|
|
14335
|
+
function registerDashboardRoutes(app, deps) {
|
|
14336
|
+
app.get("/api/dashboard", async () => buildDashboard(deps));
|
|
14337
|
+
}
|
|
14338
|
+
|
|
13989
14339
|
// src/routes/internal-session-transfer-exports.ts
|
|
13990
14340
|
import { finished } from "node:stream/promises";
|
|
13991
14341
|
import { SESSION_TRANSFER_CONTENT_TYPE } from "@leitwerk-dev/session-transfer";
|
|
@@ -14826,7 +15176,7 @@ function registerProcessActionRoutes(app, deps, futureExecutionLifecycle) {
|
|
|
14826
15176
|
const result = await deps.processEngine.retryStartup(
|
|
14827
15177
|
req.params.instanceId,
|
|
14828
15178
|
req.params.startRecordId,
|
|
14829
|
-
|
|
15179
|
+
{ ...options, actor: actorForRequest(req) }
|
|
14830
15180
|
);
|
|
14831
15181
|
deps.launchCoordinator.refresh(req.params.instanceId);
|
|
14832
15182
|
if (!result.ok) {
|
|
@@ -15751,7 +16101,7 @@ function registerProcessDetailRoutes(app, deps) {
|
|
|
15751
16101
|
}
|
|
15752
16102
|
|
|
15753
16103
|
// src/process-model-config.ts
|
|
15754
|
-
import { parseStrictInstanceTurnConfigsJson } from "@leitwerk-dev/domain";
|
|
16104
|
+
import { parseStrictInstanceTurnConfigsJson as parseStrictInstanceTurnConfigsJson2 } from "@leitwerk-dev/domain";
|
|
15755
16105
|
function record3(value) {
|
|
15756
16106
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15757
16107
|
}
|
|
@@ -15784,7 +16134,7 @@ function prepareProcessModelConfig(input) {
|
|
|
15784
16134
|
const patch = parseProcessModelConfigPatch(input.patch);
|
|
15785
16135
|
if (process2.lifecycleStatus === "completed" || process2.lifecycleStatus === "aborted")
|
|
15786
16136
|
throw new Error("Completed and aborted processes have read-only model settings");
|
|
15787
|
-
const parsed =
|
|
16137
|
+
const parsed = parseStrictInstanceTurnConfigsJson2(process2.processId, process2.turnConfigsJson);
|
|
15788
16138
|
if (!parsed.ok)
|
|
15789
16139
|
throw new Error("Saved model configuration is malformed and must be repaired before editing");
|
|
15790
16140
|
const current = policy.project({ kind: "process_configuration", process: process2, availability });
|
|
@@ -16840,6 +17190,10 @@ function registerHttp(input) {
|
|
|
16840
17190
|
store: input.resultImages
|
|
16841
17191
|
});
|
|
16842
17192
|
registerProcessRoutes(input.app, input.deps);
|
|
17193
|
+
registerDashboardRoutes(input.app, {
|
|
17194
|
+
...input.deps,
|
|
17195
|
+
processWatchers: input.processWatcherService
|
|
17196
|
+
});
|
|
16843
17197
|
if (input.deps.topicWiki)
|
|
16844
17198
|
registerTopicWikiRoutes(input.app, input.deps.topicWiki, actorForRequest);
|
|
16845
17199
|
if (input.deps.scopedSettingsService)
|
|
@@ -17130,13 +17484,6 @@ async function checkoutGitSource(source, root) {
|
|
|
17130
17484
|
const { stdout } = await execFileAsync("git", ["-C", root, "rev-parse", "HEAD"]);
|
|
17131
17485
|
return { root, commit: stdout.trim() };
|
|
17132
17486
|
}
|
|
17133
|
-
function metadataValue(markdown, key) {
|
|
17134
|
-
if (!markdown.startsWith("---")) return null;
|
|
17135
|
-
const end = markdown.indexOf("\n---", 3);
|
|
17136
|
-
if (end < 0) return null;
|
|
17137
|
-
const match = markdown.slice(3, end).match(new RegExp(`^${key}:\\s*["']?([^\\n"']+)["']?\\s*$`, "m"));
|
|
17138
|
-
return match?.[1]?.trim() || null;
|
|
17139
|
-
}
|
|
17140
17487
|
function fallbackLabel(id) {
|
|
17141
17488
|
return id.split(/[-_.]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
17142
17489
|
}
|
|
@@ -17186,13 +17533,13 @@ async function importSkillRepository(repository) {
|
|
|
17186
17533
|
const skills = [];
|
|
17187
17534
|
for (const skillRoot of skillRoots) {
|
|
17188
17535
|
const skillId = path6.basename(skillRoot);
|
|
17189
|
-
const
|
|
17536
|
+
const metadata = skillMetadata(await readFile4(path6.join(skillRoot, "SKILL.md"), "utf8"));
|
|
17190
17537
|
const imported = await importSkillDirectory(
|
|
17191
17538
|
skillRoot,
|
|
17192
17539
|
{
|
|
17193
17540
|
id: skillId,
|
|
17194
|
-
label:
|
|
17195
|
-
description:
|
|
17541
|
+
label: metadata.name ?? fallbackLabel(skillId),
|
|
17542
|
+
description: metadata.description ?? void 0
|
|
17196
17543
|
},
|
|
17197
17544
|
checkout.commit
|
|
17198
17545
|
);
|
|
@@ -17308,7 +17655,6 @@ import { lstat, readFile as readFile5, realpath } from "node:fs/promises";
|
|
|
17308
17655
|
import path7 from "node:path";
|
|
17309
17656
|
import { parseSkillPackManifest } from "@leitwerk-dev/protocol";
|
|
17310
17657
|
import { createCanonicalPiResourceBundle as createCanonicalPiResourceBundle3 } from "@leitwerk-dev/worker-protocol";
|
|
17311
|
-
import { parse as parseYaml } from "yaml";
|
|
17312
17658
|
async function packagePath(packageRoot, target) {
|
|
17313
17659
|
const relative = path7.relative(packageRoot, target);
|
|
17314
17660
|
if (!relative || relative === ".." || relative.startsWith(`..${path7.sep}`) || path7.isAbsolute(relative)) {
|
|
@@ -17358,9 +17704,8 @@ async function importExtensionSkills(modules) {
|
|
|
17358
17704
|
{ forbiddenNames: /* @__PURE__ */ new Set([".git", ".leitwerk-skill.json"]) }
|
|
17359
17705
|
);
|
|
17360
17706
|
const markdown = collector.files.get(`skills/${skill.id}/SKILL.md`);
|
|
17361
|
-
const
|
|
17362
|
-
|
|
17363
|
-
if (metadata?.name !== skill.id || metadata.description !== skill.description) {
|
|
17707
|
+
const metadata = markdown ? skillFrontmatter(Buffer.from(markdown).toString("utf8")) : null;
|
|
17708
|
+
if (metadata?.name !== skill.id || metadata?.description !== skill.description) {
|
|
17364
17709
|
throw new Error(`Skill '${skill.id}' frontmatter does not match its pack manifest`);
|
|
17365
17710
|
}
|
|
17366
17711
|
collector.addBytes(
|
|
@@ -19857,7 +20202,11 @@ function createWorkerSupervisor(deps) {
|
|
|
19857
20202
|
pendingCleanup.delete(instanceId);
|
|
19858
20203
|
const leaseBeforeExit = safeGetLeaseByInstance(instanceId);
|
|
19859
20204
|
const startupTimedOut = startupTimedOutWorkers.delete(timedOutWorkerKey(instanceId, workerId));
|
|
19860
|
-
|
|
20205
|
+
const processBeforeExit = safeGetProcessById(instanceId);
|
|
20206
|
+
const startBeforeExit = processBeforeExit?.currentExecution?.kind === "worker_start" ? deps.turnStarts.getById(processBeforeExit.currentExecution.id) : null;
|
|
20207
|
+
const acceptedTurnBeforeExit = startBeforeExit?.state.kind === "accepted" ? deps.turnRecords.getById(startBeforeExit.state.turnRecordId) : null;
|
|
20208
|
+
const unfinishedOwningTurn = leaseBeforeExit?.workerId === workerId && ["draining", "cleanup"].includes(leaseBeforeExit.state) && processBeforeExit?.lifecycleStatus === "active" && startBeforeExit?.state.kind === "accepted" && startBeforeExit.state.acceptedWorkerLeaseId === leaseBeforeExit.id && startBeforeExit.instanceId === instanceId && acceptedTurnBeforeExit?.instanceId === instanceId && acceptedTurnBeforeExit.turnStartRecordId === startBeforeExit.id && acceptedTurnBeforeExit.acceptedWorkerLeaseId === leaseBeforeExit.id && acceptedTurnBeforeExit.status === "running";
|
|
20209
|
+
if (isLiveWorkerLease(leaseBeforeExit, workerId) || unfinishedOwningTurn) {
|
|
19861
20210
|
const diagnostics = formatWorkerExitDiagnostics(info);
|
|
19862
20211
|
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
19863
20212
|
errorCode: startupTimedOut ? "startup_timeout" : info?.oomKilled ? "process_oom_killed" : "process_exited",
|
|
@@ -20568,6 +20917,7 @@ async function createConfiguredWorkerRunnerRuntime(input) {
|
|
|
20568
20917
|
});
|
|
20569
20918
|
const created2 = createKubernetesWorkerRunner({
|
|
20570
20919
|
client: kubernetesClient,
|
|
20920
|
+
reclaimOnClose: processVolume?.reclaim_on_close === true,
|
|
20571
20921
|
preProvision: processVolume?.pre_provision ? { ...processVolume.pre_provision, onError: input.onVolumePoolError } : void 0,
|
|
20572
20922
|
imagePreload: input.config.kubernetes?.image_preload?.enabled ? {
|
|
20573
20923
|
images: Object.values(input.config.worker_runtime_profiles ?? {}).map(
|
|
@@ -20669,6 +21019,23 @@ ${configErrors.join("\n")}`);
|
|
|
20669
21019
|
let closeOwnedDatabase;
|
|
20670
21020
|
const preCloseCleanup = [];
|
|
20671
21021
|
try {
|
|
21022
|
+
let releaseRetainedVolume2 = function(instanceId) {
|
|
21023
|
+
const work = processOperations.runExclusive(instanceId, async () => {
|
|
21024
|
+
const process2 = baseDeps.processes.getById(instanceId);
|
|
21025
|
+
const lease = baseDeps.leases.getByInstance(instanceId);
|
|
21026
|
+
if (!process2 || lease && !lease.exitedAt) return;
|
|
21027
|
+
await cleanupRetainedProcessVolumes({
|
|
21028
|
+
volume: runnerRuntime.volume,
|
|
21029
|
+
processes: [process2],
|
|
21030
|
+
now: /* @__PURE__ */ new Date(),
|
|
21031
|
+
policy: volumeRetentionPolicy,
|
|
21032
|
+
reclaimTerminalBackingStorage: reclaimTerminalStorage
|
|
21033
|
+
});
|
|
21034
|
+
});
|
|
21035
|
+
pendingVolumeReleases.add(work);
|
|
21036
|
+
return work.finally(() => pendingVolumeReleases.delete(work));
|
|
21037
|
+
};
|
|
21038
|
+
var releaseRetainedVolume = releaseRetainedVolume2;
|
|
20672
21039
|
await app.register(cookie);
|
|
20673
21040
|
markStartup("fastify_plugins");
|
|
20674
21041
|
const ownsDb = !opts.db;
|
|
@@ -21164,7 +21531,10 @@ ${configErrors.join("\n")}`);
|
|
|
21164
21531
|
webSocketIpc: workerWebSocketIpc,
|
|
21165
21532
|
provided: opts.workerRunnerRuntime,
|
|
21166
21533
|
helperRelays: sessionTransferHelperRelays,
|
|
21167
|
-
onVolumePoolError: () => app.log.warn(
|
|
21534
|
+
onVolumePoolError: (error) => app.log.warn(
|
|
21535
|
+
{ err: error },
|
|
21536
|
+
"Volume pool degraded; inspect preparation Pods and CSI storage scheduling"
|
|
21537
|
+
),
|
|
21168
21538
|
onImagePreparationEvent: (event) => {
|
|
21169
21539
|
if (event.outcome === "succeeded") app.log.info(event, "Worker image prepared");
|
|
21170
21540
|
else app.log.warn(event, "Worker image preparation failed; retrying in the background");
|
|
@@ -21217,30 +21587,42 @@ ${configErrors.join("\n")}`);
|
|
|
21217
21587
|
let retentionWork;
|
|
21218
21588
|
let retainedVolumeCleanupTimer = null;
|
|
21219
21589
|
let retainedVolumeCleanupRunning = false;
|
|
21220
|
-
const
|
|
21590
|
+
const retentionPolicy = {
|
|
21591
|
+
completedProcessRetention: config.workers.cleanup.completed_process_retention,
|
|
21592
|
+
errorProcessRetention: config.workers.cleanup.error_process_retention
|
|
21593
|
+
};
|
|
21594
|
+
const reclaimTerminalStorage = config.workers.runner === "kubernetes" && config.kubernetes?.process_volume.reclaim_on_close === true;
|
|
21595
|
+
const volumeRetentionPolicy = reclaimTerminalStorage ? { ...retentionPolicy, completedProcessRetention: "0s", abortedProcessRetention: "0s" } : retentionPolicy;
|
|
21596
|
+
const pendingVolumeReleases = /* @__PURE__ */ new Set();
|
|
21597
|
+
afterSuccessHooks.add(async (instanceId) => {
|
|
21598
|
+
const process2 = baseDeps.processes.getById(instanceId);
|
|
21599
|
+
if (!reclaimTerminalStorage || !process2 || !["completed", "aborted"].includes(process2.lifecycleStatus))
|
|
21600
|
+
return;
|
|
21601
|
+
try {
|
|
21602
|
+
await releaseRetainedVolume2(instanceId);
|
|
21603
|
+
} catch (err) {
|
|
21604
|
+
app.log.warn({ err, instanceId }, "process PVC release failed; retention sweep will retry");
|
|
21605
|
+
}
|
|
21606
|
+
});
|
|
21221
21607
|
async function runRetainedVolumeCleanup() {
|
|
21222
21608
|
if (retainedVolumeCleanupRunning) return;
|
|
21223
21609
|
retainedVolumeCleanupRunning = true;
|
|
21224
21610
|
const processes = baseDeps.processes.listAll();
|
|
21225
21611
|
const now2 = /* @__PURE__ */ new Date();
|
|
21226
|
-
const policy = {
|
|
21227
|
-
completedProcessRetention: config.workers.cleanup.completed_process_retention,
|
|
21228
|
-
errorProcessRetention: config.workers.cleanup.error_process_retention
|
|
21229
|
-
};
|
|
21230
21612
|
const expiredImageProcesses = new Set(
|
|
21231
|
-
planProcessVolumeRetentionCleanup({ processes, now: now2, policy })
|
|
21613
|
+
planProcessVolumeRetentionCleanup({ processes, now: now2, policy: retentionPolicy })
|
|
21232
21614
|
);
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21236
|
-
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21615
|
+
const expiredVolumes = planProcessVolumeRetentionCleanup({
|
|
21616
|
+
processes,
|
|
21617
|
+
now: now2,
|
|
21618
|
+
policy: volumeRetentionPolicy
|
|
21619
|
+
});
|
|
21620
|
+
for (const instanceId of expiredVolumes) {
|
|
21621
|
+
try {
|
|
21622
|
+
await releaseRetainedVolume2(instanceId);
|
|
21623
|
+
} catch (err) {
|
|
21624
|
+
app.log.warn({ err, instanceId }, "retained process volume cleanup failed");
|
|
21625
|
+
}
|
|
21244
21626
|
}
|
|
21245
21627
|
try {
|
|
21246
21628
|
await resultImages.cleanupProcesses({
|
|
@@ -21285,6 +21667,7 @@ ${configErrors.join("\n")}`);
|
|
|
21285
21667
|
retainedVolumeCleanupTimer = null;
|
|
21286
21668
|
}
|
|
21287
21669
|
await retentionWork;
|
|
21670
|
+
await Promise.allSettled([...pendingVolumeReleases]);
|
|
21288
21671
|
});
|
|
21289
21672
|
if (processTitles?.start) {
|
|
21290
21673
|
startHooks.push(() => processTitles.start?.());
|
|
@@ -21632,4 +22015,4 @@ ${configErrors.join("\n")}`);
|
|
|
21632
22015
|
export {
|
|
21633
22016
|
createAppContext
|
|
21634
22017
|
};
|
|
21635
|
-
//# sourceMappingURL=chunk-
|
|
22018
|
+
//# sourceMappingURL=chunk-OUA5EZS2.js.map
|