@lostgradient/weft 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli/conformance.js +14 -18
- package/dist/cli/generated/operation-catalog.snapshot.json +258 -16
- package/dist/cli/generated/operation-client.generated.d.ts +30 -6
- package/dist/cli/generated/operation-client.generated.js +4 -0
- package/dist/core/context/child-workflow-pipe.d.ts +1 -1
- package/dist/core/context/child-workflow-pipe.js +1 -1
- package/dist/core/engine/construction.d.ts +2 -0
- package/dist/core/engine/construction.js +3 -0
- package/dist/core/engine/index.js +1 -0
- package/dist/core/engine/listing.d.ts +1 -0
- package/dist/core/engine/listing.js +6 -4
- package/dist/core/weft-error.d.ts +1 -1
- package/dist/core/weft-error.js +2 -1
- package/dist/core/worker-execution-dispatcher.d.ts +8 -0
- package/dist/core/worker-execution-dispatcher.js +4 -0
- package/dist/core/worker-execution-strategy-options.d.ts +16 -0
- package/dist/core/worker-execution-strategy.js +71 -89
- package/dist/core/worker-fault-handling.d.ts +45 -0
- package/dist/core/worker-fault-handling.js +88 -0
- package/dist/core/worker-protocol.d.ts +18 -1
- package/dist/core/worker-protocol.js +1 -1
- package/dist/core/worker-realm-readiness.d.ts +78 -0
- package/dist/core/worker-realm-readiness.js +127 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +28 -1
- package/dist/json-schema.js +1 -1
- package/dist/runtime/portable.d.ts +14 -0
- package/dist/runtime/portable.js +10 -0
- package/dist/server/index.d.ts +71 -8
- package/dist/server/index.js +7 -3
- package/dist/server/operations/get-task-diagnostics.d.ts +43 -18
- package/dist/server/operations/get-task-diagnostics.js +87 -126
- package/dist/server/operations/get-worker-diagnostics.d.ts +177 -0
- package/dist/server/operations/get-worker-diagnostics.js +117 -0
- package/dist/server/operations/list-worker-registration-rejections.d.ts +79 -0
- package/dist/server/operations/list-worker-registration-rejections.js +60 -0
- package/dist/server/operations/list-workers.js +1 -3
- package/dist/server/operations/static-registrations.js +5 -20
- package/dist/server/rest-bindings.js +31 -2
- package/dist/server/runtime/authentication-bridge.js +6 -14
- package/dist/server/runtime/context.d.ts +23 -0
- package/dist/server/runtime/task-dispatch.d.ts +7 -1
- package/dist/server/runtime/task-dispatch.js +126 -55
- package/dist/server/runtime/task-ledger-completion.d.ts +68 -0
- package/dist/server/runtime/task-ledger-completion.js +72 -0
- package/dist/server/runtime/task-ledger-recovery.d.ts +55 -0
- package/dist/server/runtime/task-ledger-recovery.js +73 -0
- package/dist/server/runtime/task-ledger-runtime.d.ts +64 -0
- package/dist/server/runtime/task-ledger-runtime.js +34 -0
- package/dist/server/runtime/task-metrics.d.ts +6 -4
- package/dist/server/runtime/task-polling.d.ts +14 -12
- package/dist/server/runtime/task-polling.js +106 -82
- package/dist/server/runtime/task-reconciliation.d.ts +35 -8
- package/dist/server/runtime/task-reconciliation.js +75 -74
- package/dist/server/runtime/task-result-resolution.d.ts +2 -10
- package/dist/server/runtime/task-result-resolution.js +0 -67
- package/dist/server/runtime/task-result-view.d.ts +82 -0
- package/dist/server/runtime/task-result-view.js +48 -0
- package/dist/server/runtime/websocket-worker-messaging.d.ts +16 -0
- package/dist/server/runtime/websocket-worker-messaging.js +32 -0
- package/dist/server/runtime/websocket-worker-registration.d.ts +41 -0
- package/dist/server/runtime/websocket-worker-registration.js +134 -0
- package/dist/server/runtime/websocket-worker.d.ts +0 -1
- package/dist/server/runtime/websocket-worker.js +64 -116
- package/dist/server/serve-internals.d.ts +9 -6
- package/dist/server/serve-internals.js +14 -40
- package/dist/server/task-ledger-codec.d.ts +40 -0
- package/dist/server/task-ledger-codec.js +195 -0
- package/dist/server/task-ledger-keys.d.ts +13 -0
- package/dist/server/task-ledger-keys.js +5 -0
- package/dist/server/task-ledger-limits.d.ts +34 -0
- package/dist/server/task-ledger-limits.js +5 -0
- package/dist/server/task-ledger-transition-helpers.d.ts +38 -0
- package/dist/server/task-ledger-transition-helpers.js +42 -0
- package/dist/server/task-ledger-transitions-cancellation.d.ts +31 -0
- package/dist/server/task-ledger-transitions-cancellation.js +73 -0
- package/dist/server/task-ledger-transitions.d.ts +129 -0
- package/dist/server/task-ledger-transitions.js +162 -0
- package/dist/server/task-ledger-types.d.ts +220 -0
- package/dist/server/task-ledger-types.js +1 -0
- package/dist/server/task-ledger.d.ts +17 -0
- package/dist/server/task-ledger.js +24 -0
- package/dist/server/task-state.d.ts +25 -152
- package/dist/server/task-state.js +0 -188
- package/dist/server/worker-admission-policy.d.ts +70 -0
- package/dist/server/worker-admission-policy.js +0 -0
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/interface.d.ts +0 -2
- package/dist/storage/interface.js +1 -1
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon.js +1 -1
- package/dist/storage/postgres.js +1 -1
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/testing.js +1 -1
- package/dist/storage/turso.js +1 -1
- package/dist/storage/web-extension.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/web-extension.js +1 -1
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/index.js +30 -4
- package/dist/worker/manifest/canonical-json.d.ts +20 -0
- package/dist/worker/manifest/canonical-json.js +13 -0
- package/dist/worker/manifest/capabilities.d.ts +24 -0
- package/dist/worker/manifest/capabilities.js +74 -0
- package/dist/worker/manifest/content-digest.d.ts +20 -0
- package/dist/worker/manifest/content-digest.js +13 -0
- package/dist/worker/manifest/declared-shape-digest.d.ts +14 -0
- package/dist/worker/manifest/declared-shape-digest.js +4 -0
- package/dist/worker/manifest/digest.d.ts +82 -0
- package/dist/worker/manifest/digest.js +9 -0
- package/dist/worker/manifest/execution-identity.d.ts +92 -0
- package/dist/worker/manifest/execution-identity.js +36 -0
- package/dist/worker/manifest/failure.d.ts +59 -0
- package/dist/worker/manifest/failure.js +4 -0
- package/dist/worker/manifest/index.d.ts +22 -0
- package/dist/worker/manifest/index.js +23 -0
- package/dist/worker/manifest/internal-realm.d.ts +50 -0
- package/dist/worker/manifest/internal-realm.js +39 -0
- package/dist/worker/manifest/is-record.d.ts +12 -0
- package/dist/worker/manifest/is-record.js +6 -0
- package/dist/worker/manifest/json-scan.d.ts +26 -0
- package/dist/worker/manifest/json-scan.js +88 -0
- package/dist/worker/manifest/limits.d.ts +138 -0
- package/dist/worker/manifest/limits.js +1 -0
- package/dist/worker/manifest/normalize.d.ts +63 -0
- package/dist/worker/manifest/normalize.js +73 -0
- package/dist/worker/manifest/parse-json.d.ts +24 -0
- package/dist/worker/manifest/parse-json.js +15 -0
- package/dist/worker/manifest/parse.d.ts +86 -0
- package/dist/worker/manifest/parse.js +188 -0
- package/dist/worker/manifest/registry-contract-builder.d.ts +120 -0
- package/dist/worker/manifest/registry-contract-builder.js +65 -0
- package/dist/worker/manifest/types.d.ts +263 -0
- package/dist/worker/manifest/types.js +1 -0
- package/dist/worker/manifest/utf8.d.ts +13 -0
- package/dist/worker/manifest/utf8.js +7 -0
- package/dist/worker/options.d.ts +55 -8
- package/dist/worker/options.js +65 -9
- package/dist/worker/protocol-internals.d.ts +1 -2
- package/dist/worker/protocol-internals.js +0 -5
- package/dist/worker/protocol-messages.d.ts +33 -17
- package/dist/worker/protocol-schemas.d.ts +36 -74
- package/dist/worker/protocol-schemas.js +25 -18
- package/dist/worker/protocol-version.d.ts +18 -14
- package/dist/worker/protocol-version.js +1 -1
- package/dist/worker/protocol.js +1 -1
- package/dist/worker/registry/deployment-consistency.d.ts +78 -0
- package/dist/worker/registry/deployment-consistency.js +27 -0
- package/dist/worker/registry/drain.d.ts +14 -0
- package/dist/worker/registry/drain.js +24 -0
- package/dist/worker/registry/rejections.d.ts +31 -0
- package/dist/worker/registry/rejections.js +10 -0
- package/dist/worker/registry/summary.d.ts +0 -3
- package/dist/worker/registry/summary.js +2 -5
- package/dist/worker/registry/types.d.ts +10 -3
- package/dist/worker/registry.d.ts +47 -2
- package/dist/worker/registry.js +45 -32
- package/dist/workers/workflow-worker-entry.d.ts +12 -7
- package/dist/workers/workflow-worker-entry.js +9 -2
- package/package.json +3 -3
- package/dist/server/task-resolved-record.d.ts +0 -12
- package/dist/server/task-resolved-record.js +0 -35
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { computeWorkerManifestDigest, parseWorkerManifest } from "../worker/manifest/index.js";
|
|
2
|
+
import {
|
|
3
|
+
buildDeclaredWorkflowContract,
|
|
4
|
+
declaredWorkflowContractsMatch
|
|
5
|
+
} from "../worker/manifest/internal-realm.js";
|
|
6
|
+
import {
|
|
7
|
+
assertWorkerProtocolMessageWithinLimit,
|
|
8
|
+
WORKER_PROTOCOL_VERSION
|
|
9
|
+
} from "./worker-protocol.js";
|
|
10
|
+
export function isWorkerRealmReadyMessage(message) {
|
|
11
|
+
return typeof message === "object" && message !== null && message.type === "ready";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class WorkerRealmReadiness {
|
|
15
|
+
#dependencies;
|
|
16
|
+
#readyByWorker = new Map;
|
|
17
|
+
#pendingByWorker = new Map;
|
|
18
|
+
constructor(dependencies) {
|
|
19
|
+
this.#dependencies = dependencies;
|
|
20
|
+
}
|
|
21
|
+
isReady(worker) {
|
|
22
|
+
return this.#readyByWorker.has(worker);
|
|
23
|
+
}
|
|
24
|
+
async waitForReady(worker) {
|
|
25
|
+
const known = this.#readyByWorker.get(worker);
|
|
26
|
+
if (known)
|
|
27
|
+
return { ok: !0, ...known };
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
let settled = !1;
|
|
30
|
+
const settleOnce = (outcome) => {
|
|
31
|
+
if (settled)
|
|
32
|
+
return;
|
|
33
|
+
settled = !0;
|
|
34
|
+
resolve(outcome);
|
|
35
|
+
}, timeout = setTimeout(() => {
|
|
36
|
+
this.#pendingByWorker.delete(worker);
|
|
37
|
+
settleOnce({
|
|
38
|
+
ok: !1,
|
|
39
|
+
error: `Worker realm did not send a ready message within ${this.#dependencies.timeoutMs}ms`,
|
|
40
|
+
failureCategory: "timeout"
|
|
41
|
+
});
|
|
42
|
+
}, this.#dependencies.timeoutMs);
|
|
43
|
+
this.#pendingByWorker.set(worker, (outcome) => {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
settleOnce(outcome);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async noteReadyMessage(worker, message) {
|
|
50
|
+
const outcome = await this.#validate(message);
|
|
51
|
+
if (outcome.ok)
|
|
52
|
+
this.#readyByWorker.set(worker, {
|
|
53
|
+
realmGeneration: outcome.realmGeneration,
|
|
54
|
+
manifestDigest: outcome.manifestDigest
|
|
55
|
+
});
|
|
56
|
+
const pending = this.#pendingByWorker.get(worker);
|
|
57
|
+
if (pending) {
|
|
58
|
+
this.#pendingByWorker.delete(worker);
|
|
59
|
+
pending(outcome);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
forget(worker) {
|
|
63
|
+
this.#readyByWorker.delete(worker);
|
|
64
|
+
const pending = this.#pendingByWorker.get(worker);
|
|
65
|
+
if (pending) {
|
|
66
|
+
this.#pendingByWorker.delete(worker);
|
|
67
|
+
pending({
|
|
68
|
+
ok: !1,
|
|
69
|
+
error: "Worker was discarded before its ready handshake completed",
|
|
70
|
+
failureCategory: "system"
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
clear() {
|
|
75
|
+
for (const resolve of this.#pendingByWorker.values())
|
|
76
|
+
resolve({
|
|
77
|
+
ok: !1,
|
|
78
|
+
error: "Worker execution strategy was disposed before the ready handshake completed",
|
|
79
|
+
failureCategory: "system"
|
|
80
|
+
});
|
|
81
|
+
this.#pendingByWorker.clear();
|
|
82
|
+
this.#readyByWorker.clear();
|
|
83
|
+
}
|
|
84
|
+
async#validate(message) {
|
|
85
|
+
try {
|
|
86
|
+
assertWorkerProtocolMessageWithinLimit(message, this.#dependencies.maxProtocolMessageBytes);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return {
|
|
89
|
+
ok: !1,
|
|
90
|
+
error: error instanceof Error ? error.message : String(error),
|
|
91
|
+
failureCategory: "resource"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const record = message;
|
|
95
|
+
if (record.protocolVersion !== WORKER_PROTOCOL_VERSION)
|
|
96
|
+
return {
|
|
97
|
+
ok: !1,
|
|
98
|
+
error: `Worker realm ready message protocol version mismatch: expected ${WORKER_PROTOCOL_VERSION}, got ${String(record.protocolVersion)}`,
|
|
99
|
+
failureCategory: "system"
|
|
100
|
+
};
|
|
101
|
+
if (typeof record.realmGeneration !== "string" || record.realmGeneration.length === 0)
|
|
102
|
+
return {
|
|
103
|
+
ok: !1,
|
|
104
|
+
error: "Worker realm ready message must include a non-empty realmGeneration string",
|
|
105
|
+
failureCategory: "system"
|
|
106
|
+
};
|
|
107
|
+
const parsed = parseWorkerManifest(record.manifest);
|
|
108
|
+
if (!parsed.ok)
|
|
109
|
+
return {
|
|
110
|
+
ok: !1,
|
|
111
|
+
error: `Worker realm manifest rejected: ${parsed.message}`,
|
|
112
|
+
failureCategory: "system"
|
|
113
|
+
};
|
|
114
|
+
const missing = this.#dependencies.getExpectedWorkflowTypes().filter((workflowType) => {
|
|
115
|
+
const reported = parsed.manifest.workflows[workflowType];
|
|
116
|
+
return !reported || !declaredWorkflowContractsMatch(reported, buildDeclaredWorkflowContract(workflowType));
|
|
117
|
+
}).toSorted();
|
|
118
|
+
if (missing.length > 0)
|
|
119
|
+
return {
|
|
120
|
+
ok: !1,
|
|
121
|
+
error: `Worker realm manifest is missing or disagrees on workflow type(s) the host expects: ${missing.join(", ")}`,
|
|
122
|
+
failureCategory: "system"
|
|
123
|
+
};
|
|
124
|
+
const manifestDigest = await computeWorkerManifestDigest(parsed.manifest);
|
|
125
|
+
return { ok: !0, realmGeneration: record.realmGeneration, manifestDigest };
|
|
126
|
+
}
|
|
127
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { AlertManager } from './alerting/index';
|
|
|
29
29
|
export type { AlertAction, AlertMetric, AlertRule, AlertStateSnapshot, AlertStatus, AlertingOptions, WebhookTarget, } from './alerting/types';
|
|
30
30
|
export { ActivityAsyncPendingEvent, ActivityCompletedEvent, ActivityFailedEvent, ActivityStartedEvent, AlertFiredEvent, AlertResolvedEvent, AttributesChangedEvent, CheckpointSizeWarningEvent, ConstraintViolatedEvent, DevelopmentWarningEvent, ScheduleFiredEvent, ScheduleMissedFireEvent, SignalDeliveredEvent, SignalReceivedEvent, StorageSizeReportedEvent, TaskResultDeadLetteredEvent, UpdateCompletedEvent, UpdateReceivedEvent, WorkflowCancelledEvent, WorkflowCompletedEvent, WorkflowDefinitionRegisteredEvent, WorkflowFailedEvent, WorkflowRecoverySkippedEvent, WorkflowResumedEvent, WorkflowStartedEvent, WorkflowSuspendedEvent, WorkflowTeardownEvent, WorkflowTimedOutEvent, } from './core/events';
|
|
31
31
|
export type { TypedEventTarget, WeftEventMap, WorkflowRecoverySkippedReason, WorkflowTeardownStatus, } from './core/events';
|
|
32
|
-
export { detectRuntime, hashBytes, hashString, sleep } from './runtime/portable';
|
|
32
|
+
export { detectRuntime, detectRuntimeVersion, hashBytes, hashString, sleep, } from './runtime/portable';
|
|
33
33
|
export type { RuntimeKind } from './runtime/portable';
|
|
34
34
|
export { createBunCompressor, createCompressor } from './core/compression';
|
|
35
35
|
export type { CompressionAlgorithm, CompressionOptions, Compressor } from './core/compression';
|
|
@@ -102,6 +102,8 @@ export type { WorkerPoolOptions } from './workers/pool';
|
|
|
102
102
|
export { HeartbeatManager } from './worker/heartbeat';
|
|
103
103
|
export { RemoteWorker } from './worker/index';
|
|
104
104
|
export { LongPollWorker } from './worker/long-poll';
|
|
105
|
+
export { MAX_MANIFEST_ACTIVITY_COUNT, MAX_MANIFEST_CAPABILITY_COUNT, MAX_MANIFEST_CAPABILITY_DEPTH, MAX_MANIFEST_CAPABILITY_STRING_BYTES, MAX_MANIFEST_IDENTIFIER_BYTES, MAX_MANIFEST_WORKFLOW_COUNT, MAX_NORMALIZED_MANIFEST_BYTES, WORKER_MANIFEST_DIGEST_ALGORITHM, WORKER_MANIFEST_VERSION, WorkerManifestBuildError, buildWorkerExecutionIdentity, buildWorkerManifestFromRegistry, canonicalWorkerManifestJson, computeWorkerManifestDigest, digestCanonicalWorkerManifest, executionIdentitySatisfies, normalizeWorkerManifest, parseWorkerManifest, parseWorkerManifestJson, } from './worker/manifest/index.ts';
|
|
106
|
+
export type { ManifestValidationFailure, WorkerActivityContract, WorkerDeploymentIdentity, WorkerExecutionIdentity, WorkerExecutionRequirement, WorkerManifest, WorkerManifestFromRegistryOptions, WorkerManifestParseResult, WorkerManifestParseSuccess, WorkerManifestRejectionReason, WorkerRuntimeIdentity, WorkerWorkflowContract, } from './worker/manifest/index.ts';
|
|
105
107
|
export { WorkerRegistry } from './worker/registry';
|
|
106
108
|
export { WorkerProtocolIncompatibleError, workerProtocolIncompatibleMessage, } from './worker/worker-protocol-incompatible-error';
|
|
107
109
|
export { buildQualifiedActivityTable } from './worker/workflow-activity-binding';
|
package/dist/index.js
CHANGED
|
@@ -91,7 +91,13 @@ export {
|
|
|
91
91
|
WorkflowTeardownEvent,
|
|
92
92
|
WorkflowTimedOutEvent
|
|
93
93
|
} from "./core/events.js";
|
|
94
|
-
export {
|
|
94
|
+
export {
|
|
95
|
+
detectRuntime,
|
|
96
|
+
detectRuntimeVersion,
|
|
97
|
+
hashBytes,
|
|
98
|
+
hashString,
|
|
99
|
+
sleep
|
|
100
|
+
} from "./runtime/portable.js";
|
|
95
101
|
export { createBunCompressor, createCompressor } from "./core/compression.js";
|
|
96
102
|
export { CompressedStorage } from "./storage/compressed-storage.js";
|
|
97
103
|
export { storageDeleteRange } from "./storage/delete-range.js";
|
|
@@ -209,6 +215,27 @@ export { WorkerPool } from "./workers/pool.js";
|
|
|
209
215
|
export { HeartbeatManager } from "./worker/heartbeat.js";
|
|
210
216
|
export { RemoteWorker } from "./worker/index.js";
|
|
211
217
|
export { LongPollWorker } from "./worker/long-poll.js";
|
|
218
|
+
export {
|
|
219
|
+
MAX_MANIFEST_ACTIVITY_COUNT,
|
|
220
|
+
MAX_MANIFEST_CAPABILITY_COUNT,
|
|
221
|
+
MAX_MANIFEST_CAPABILITY_DEPTH,
|
|
222
|
+
MAX_MANIFEST_CAPABILITY_STRING_BYTES,
|
|
223
|
+
MAX_MANIFEST_IDENTIFIER_BYTES,
|
|
224
|
+
MAX_MANIFEST_WORKFLOW_COUNT,
|
|
225
|
+
MAX_NORMALIZED_MANIFEST_BYTES,
|
|
226
|
+
WORKER_MANIFEST_DIGEST_ALGORITHM,
|
|
227
|
+
WORKER_MANIFEST_VERSION,
|
|
228
|
+
WorkerManifestBuildError,
|
|
229
|
+
buildWorkerExecutionIdentity,
|
|
230
|
+
buildWorkerManifestFromRegistry,
|
|
231
|
+
canonicalWorkerManifestJson,
|
|
232
|
+
computeWorkerManifestDigest,
|
|
233
|
+
digestCanonicalWorkerManifest,
|
|
234
|
+
executionIdentitySatisfies,
|
|
235
|
+
normalizeWorkerManifest,
|
|
236
|
+
parseWorkerManifest,
|
|
237
|
+
parseWorkerManifestJson
|
|
238
|
+
} from "./worker/manifest/index.js";
|
|
212
239
|
export { WorkerRegistry } from "./worker/registry.js";
|
|
213
240
|
export {
|
|
214
241
|
WorkerProtocolIncompatibleError,
|
package/dist/json-schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var O=import.meta.require,T=(j,q,z)=>{if(q!=null){if(typeof q!=="object"&&typeof q!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let A;if(z)A=q[Symbol.asyncDispose];if(A===void 0)A=q[Symbol.dispose];if(typeof A!=="function")throw TypeError("Object not disposable");j.push([z,A,q])}else if(z)j.push([z]);return q},y=(j,q,z)=>{let A=(G)=>q=z?new SuppressedError(G,q,"An error was suppressed during disposal"):(z=!0,G),H=(G)=>{while(G=j.pop())try{var $=G[1]&&G[1].call(G[2]);if(G[0])return Promise.resolve($).then(H,(Q)=>(A(Q),H()))}catch(Q){A(Q)}if(z)throw q};return H()};class X extends Error{code;constructor(j,q,z){super(q,z);this.code=j,this.name=j}}var B={WorkflowAlreadyExistsError:!0,BulkDeleteRequiresTerminalWorkflowsError:!0,BulkOperationConfirmationError:!0,WorkflowTypeNotRegisteredForRecoveryError:!0,EngineCreateNameMismatchError:!0,EngineDisposedError:!0,EngineDisposalError:!0,WorkflowNotFoundError:!0,WorkflowNotRegisteredError:!0,WorkflowConcurrencyLimitExceededError:!0,WorkflowSuspendNotSupportedError:!0,ActivityResolutionError:!0,BranchTopologyChangedError:!0,PersistedDataIncompatibleError:!0,WorkflowTimeoutError:!0,HttpClientError:!0,WorkerProtocolIncompatibleError:!0,UpdateTimeoutError:!0,UpdateValidationError:!0,WorkflowTerminalError:!0,WorkflowBuilderError:!0,VersionMismatchError:!0,EffectReplayConflictError:!0,ReviewTimeoutError:!0,AtomicStateConflictError:!0,StandardSchemaValidationError:!0,ActivityReconciliationCapabilityError:!0,ActivityReconciliationConflictError:!0,ActivityReconciliationIndeterminateError:!0,DurableActivityScopeError:!0,DurableActivityUnsupportedError:!0,AsyncActivityTokenNotFoundError:!0,ActivityScheduleToCloseTimeoutError:!0,ActivityPerAttemptTimeoutError:!0,PayloadSizeExceededError:!0,StartOrSignalConflictError:!0,WorkflowTeardownPendingError:!0,IdempotencyKeyPurgedError:!0},R=new Set(Object.keys(B));class K extends X{fieldName;operation;issues;constructor(j){super("StandardSchemaValidationError",M(j.fieldName,j.operation,j.issues));this.fieldName=j.fieldName,this.operation=j.operation,this.issues=j.issues}}async function Z(j,q,z){let A=j["~standard"];if(!D(A))throw TypeError(`Schema for ${z.fieldName} does not provide runtime validation. Attach a Standard Schema validator (Zod, Valibot, or another vendor) or supply a runtime-validating schema at this boundary.`);let H=await A.validate(q);if(H.issues===void 0)return H.value;throw new K({fieldName:z.fieldName,operation:z.operation,issues:H.issues.map(U)})}function Y(j){return j.map((q)=>q.path===""?q.message:`${q.path}: ${q.message}`).join(`
|
|
2
|
+
var O=import.meta.require,T=(j,q,z)=>{if(q!=null){if(typeof q!=="object"&&typeof q!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let A;if(z)A=q[Symbol.asyncDispose];if(A===void 0)A=q[Symbol.dispose];if(typeof A!=="function")throw TypeError("Object not disposable");j.push([z,A,q])}else if(z)j.push([z]);return q},y=(j,q,z)=>{let A=(G)=>q=z?new SuppressedError(G,q,"An error was suppressed during disposal"):(z=!0,G),H=(G)=>{while(G=j.pop())try{var $=G[1]&&G[1].call(G[2]);if(G[0])return Promise.resolve($).then(H,(Q)=>(A(Q),H()))}catch(Q){A(Q)}if(z)throw q};return H()};class X extends Error{code;constructor(j,q,z){super(q,z);this.code=j,this.name=j}}var B={WorkflowAlreadyExistsError:!0,BulkDeleteRequiresTerminalWorkflowsError:!0,BulkOperationConfirmationError:!0,WorkflowTypeNotRegisteredForRecoveryError:!0,EngineCreateNameMismatchError:!0,EngineDisposedError:!0,EngineDisposalError:!0,WorkflowNotFoundError:!0,WorkflowNotRegisteredError:!0,WorkflowConcurrencyLimitExceededError:!0,WorkflowSuspendNotSupportedError:!0,ActivityResolutionError:!0,BranchTopologyChangedError:!0,PersistedDataIncompatibleError:!0,WorkflowTimeoutError:!0,HttpClientError:!0,WorkerProtocolIncompatibleError:!0,UpdateTimeoutError:!0,UpdateValidationError:!0,WorkflowTerminalError:!0,WorkflowBuilderError:!0,VersionMismatchError:!0,EffectReplayConflictError:!0,ReviewTimeoutError:!0,AtomicStateConflictError:!0,StandardSchemaValidationError:!0,ActivityReconciliationCapabilityError:!0,ActivityReconciliationConflictError:!0,ActivityReconciliationIndeterminateError:!0,DurableActivityScopeError:!0,DurableActivityUnsupportedError:!0,AsyncActivityTokenNotFoundError:!0,ActivityScheduleToCloseTimeoutError:!0,ActivityPerAttemptTimeoutError:!0,PayloadSizeExceededError:!0,StartOrSignalConflictError:!0,WorkflowTeardownPendingError:!0,IdempotencyKeyPurgedError:!0,WorkerManifestBuildError:!0},R=new Set(Object.keys(B));class K extends X{fieldName;operation;issues;constructor(j){super("StandardSchemaValidationError",M(j.fieldName,j.operation,j.issues));this.fieldName=j.fieldName,this.operation=j.operation,this.issues=j.issues}}async function Z(j,q,z){let A=j["~standard"];if(!D(A))throw TypeError(`Schema for ${z.fieldName} does not provide runtime validation. Attach a Standard Schema validator (Zod, Valibot, or another vendor) or supply a runtime-validating schema at this boundary.`);let H=await A.validate(q);if(H.issues===void 0)return H.value;throw new K({fieldName:z.fieldName,operation:z.operation,issues:H.issues.map(U)})}function Y(j){return j.map((q)=>q.path===""?q.message:`${q.path}: ${q.message}`).join(`
|
|
3
3
|
`)}function D(j){return typeof j.validate==="function"}function U(j){return{message:j.message,path:b(j.path)}}function b(j){if(j===void 0||j.length===0)return"";let q="";for(let z of j)q+="/",q+=w(z);return q}function w(j){let q=F(j)?j.key:j;return J(String(q))}function F(j){return j!==null&&typeof j==="object"&&"key"in j}function J(j){return j.replace(/~/g,"~0").replace(/\//g,"~1")}function M(j,q,z){return`Validation failed for ${q===void 0?j:`${q} ${j}`}:
|
|
4
4
|
${Y(z)}`}var V=Y,k=K,P=Z;export{P as validateStandardSchema,V as formatStandardSchemaIssues,k as StandardSchemaValidationError};
|
|
@@ -40,6 +40,20 @@ export declare function isBunRuntime(): boolean;
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export declare function detectRuntime(): RuntimeKind;
|
|
43
|
+
/**
|
|
44
|
+
* Detect the current runtime's version string, matching {@link detectRuntime}'s
|
|
45
|
+
* detection precedence. A browser or edge runtime exposes no version, so an
|
|
46
|
+
* empty string is a truthful answer rather than a missing field.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { detectRuntimeVersion } from '@lostgradient/weft';
|
|
51
|
+
*
|
|
52
|
+
* const version = detectRuntimeVersion();
|
|
53
|
+
* console.log(typeof version); // 'string'
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function detectRuntimeVersion(): string;
|
|
43
57
|
/**
|
|
44
58
|
* Read an environment variable without assuming a runtime.
|
|
45
59
|
*
|
package/dist/runtime/portable.js
CHANGED
|
@@ -33,6 +33,16 @@ export function detectRuntime() {
|
|
|
33
33
|
return detector.kind;
|
|
34
34
|
return "edge";
|
|
35
35
|
}
|
|
36
|
+
export function detectRuntimeVersion() {
|
|
37
|
+
switch (detectRuntime()) {
|
|
38
|
+
case "bun":
|
|
39
|
+
return getBunGlobal()?.version ?? "";
|
|
40
|
+
case "node":
|
|
41
|
+
return getProcess()?.versions?.node ?? "";
|
|
42
|
+
default:
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
36
46
|
export function readEnvironmentVariable(name) {
|
|
37
47
|
const bun = getBunGlobal();
|
|
38
48
|
if (bun !== void 0)
|
package/dist/server/index.d.ts
CHANGED
|
@@ -13,11 +13,14 @@ import type { AuthConfig, RateLimitConfig } from './authentication.ts';
|
|
|
13
13
|
import { type DashboardAssets } from './dashboard-assets.ts';
|
|
14
14
|
import type { DiscoveryInfo } from './discovery-info.ts';
|
|
15
15
|
import type { CorsOptions } from './runtime/cors.ts';
|
|
16
|
+
import type { TaskResultView } from './runtime/task-result-view.ts';
|
|
16
17
|
import type { SchedulingPolicy } from './task-queue-types.ts';
|
|
17
18
|
import { TaskQueue } from './task-queue.ts';
|
|
19
|
+
import type { WorkerAdmissionPolicy } from './worker-admission-policy.ts';
|
|
18
20
|
export { wireEventBroadcasting, type EventBroadcastingHandle, } from './runtime/event-broadcasting.ts';
|
|
19
21
|
export type { DashboardAssets } from './dashboard-assets.ts';
|
|
20
22
|
export type { CorsOptions } from './runtime/cors.ts';
|
|
23
|
+
export type { WorkerAdmissionDecision, WorkerAdmissionPolicy, WorkerAdmissionRequest, } from './worker-admission-policy.ts';
|
|
21
24
|
export { AUTHORIZATION_SCOPES, isAuthorizationScope, type AuthorizationScope, } from './authorization-scope.ts';
|
|
22
25
|
export type { GetPrincipalOutput } from './operations/get-principal.ts';
|
|
23
26
|
export { createRateLimiter, createRotatingApiKeyStore, defaultAuthAuditSink, isSensitiveHeader, redactCredential, redactHeaders, validateRateLimitConfig, type ApiKeyRegistration, type AuthAuditEvent, type AuthAuditSink, type AuthConfig, type RateLimitConfig, type RateLimitDecision, type RateLimiter, type RotatingApiKeyStore, } from './authentication.ts';
|
|
@@ -26,6 +29,7 @@ export type { PrometheusExporter } from '../observability/metrics.ts';
|
|
|
26
29
|
export { WorkerRegistry } from '../worker/registry.ts';
|
|
27
30
|
export type { RoutingPolicy } from '../worker/registry.ts';
|
|
28
31
|
export type { DiscoveryInfo } from './discovery-info.ts';
|
|
32
|
+
export type { TaskResultView } from './runtime/task-result-view.ts';
|
|
29
33
|
export type { SchedulingPolicy } from './task-queue-types.ts';
|
|
30
34
|
export { TaskQueue } from './task-queue.ts';
|
|
31
35
|
/**
|
|
@@ -190,7 +194,7 @@ export interface ServeOptions {
|
|
|
190
194
|
* workflow SSE requests return `429`.
|
|
191
195
|
*/
|
|
192
196
|
maxStreamConnectionsPerWorkflow?: number;
|
|
193
|
-
/** How often (in ms) the server scans
|
|
197
|
+
/** How often (in ms) the server scans the task ledger for expired visibility deadlines. Defaults to 5 000. */
|
|
194
198
|
visibilityPollIntervalMs?: number;
|
|
195
199
|
/**
|
|
196
200
|
* Grace period (in ms) between a worker WebSocket close and the requeue of
|
|
@@ -204,6 +208,19 @@ export interface ServeOptions {
|
|
|
204
208
|
* `[0, 5_000]`.
|
|
205
209
|
*/
|
|
206
210
|
workerReconnectGracePeriodMs?: number;
|
|
211
|
+
/**
|
|
212
|
+
* How long (in ms) an adopted terminal task-ledger record is retained
|
|
213
|
+
* before the periodic reconciliation scan reaps it. Defaults to `undefined`
|
|
214
|
+
* — retention is opt-in, and unset means terminal records are kept forever
|
|
215
|
+
* regardless of adoption, matching the durable ledger's default posture of
|
|
216
|
+
* never discarding a task's authoritative record without an explicit
|
|
217
|
+
* policy. Only adopted records are ever eligible; a terminal record whose
|
|
218
|
+
* result no caller has adopted via {@link WeftServer.adoptTaskResult} is
|
|
219
|
+
* retained indefinitely no matter how old it is. Unlike workflow history's
|
|
220
|
+
* count-based `history.retentionWindow`, this is time-based — a terminal
|
|
221
|
+
* task record has no natural sequence axis to bound by count.
|
|
222
|
+
*/
|
|
223
|
+
taskRetentionWindowMs?: number;
|
|
207
224
|
/**
|
|
208
225
|
* Maximum time (in ms) `server.stop()` waits for connected remote workers to
|
|
209
226
|
* drain in-flight task results after receiving a shutdown frame before the
|
|
@@ -223,6 +240,14 @@ export interface ServeOptions {
|
|
|
223
240
|
* least-loaded for that single call.
|
|
224
241
|
*/
|
|
225
242
|
routingPolicy?: RoutingPolicy;
|
|
243
|
+
/**
|
|
244
|
+
* Gate on which workers may become routing-eligible, evaluated after the
|
|
245
|
+
* manifest is validated and checked for deployment consistency and before
|
|
246
|
+
* registry insertion. Defaults to `undefined`, which accepts every worker
|
|
247
|
+
* that already passed authentication — the behavior before this option
|
|
248
|
+
* existed.
|
|
249
|
+
*/
|
|
250
|
+
workerAdmissionPolicy?: WorkerAdmissionPolicy;
|
|
226
251
|
/**
|
|
227
252
|
* Scheduling policy used by the {@link TaskQueue} when ordering pending tasks
|
|
228
253
|
* within a queue. Defaults to `'priority'`.
|
|
@@ -263,10 +288,10 @@ export interface ServeOptions {
|
|
|
263
288
|
* Descriptor for a task dispatched to a remote worker via
|
|
264
289
|
* {@link WeftServer.dispatchTask}.
|
|
265
290
|
*
|
|
266
|
-
* `operationId` and `
|
|
267
|
-
* routing, retry behaviour, and priority. Set `sticky: true`
|
|
268
|
-
* `workflowId` to route the task to the worker that last
|
|
269
|
-
* that workflow.
|
|
291
|
+
* `operationId`, `activityName`, and `workflowType` are required; all other
|
|
292
|
+
* fields refine routing, retry behaviour, and priority. Set `sticky: true`
|
|
293
|
+
* together with `workflowId` to route the task to the worker that last
|
|
294
|
+
* handled tasks for that workflow.
|
|
270
295
|
*
|
|
271
296
|
* @example
|
|
272
297
|
* ```ts
|
|
@@ -275,6 +300,7 @@ export interface ServeOptions {
|
|
|
275
300
|
* const task: TaskDispatch = {
|
|
276
301
|
* operationId: crypto.randomUUID(),
|
|
277
302
|
* activityName: 'sendEmail',
|
|
303
|
+
* workflowType: 'notifications',
|
|
278
304
|
* input: { to: 'user@example.com', subject: 'Hello' },
|
|
279
305
|
* queue: 'email',
|
|
280
306
|
* retryPolicy: { maxAttempts: 3, initialBackoff: '1s', backoffMultiplier: 2, maxBackoff: '30s' },
|
|
@@ -286,9 +312,17 @@ export interface TaskDispatch {
|
|
|
286
312
|
operationId: string;
|
|
287
313
|
activityName: string;
|
|
288
314
|
input: unknown;
|
|
289
|
-
attempt?: number;
|
|
290
315
|
/** Queue to dispatch the task to. Defaults to `'default'`. */
|
|
291
316
|
queue?: string;
|
|
317
|
+
/**
|
|
318
|
+
* The dispatching workflow's registered type. Required — the durable task
|
|
319
|
+
* ledger's envelope (`RemoteTaskBase.workflowType`) is required, and
|
|
320
|
+
* `buildWorkerExecutionIdentity` needs it to look up the claiming worker's
|
|
321
|
+
* manifest entry (`manifest.workflows[workflowType].activities[activityName]`).
|
|
322
|
+
* `dispatchTaskImpl` rejects a call missing this field with an actionable
|
|
323
|
+
* error rather than defaulting it — there is no safe placeholder value.
|
|
324
|
+
*/
|
|
325
|
+
workflowType: string;
|
|
292
326
|
/** Workflow ID. Required for sticky routing to track worker affinity. */
|
|
293
327
|
workflowId?: string | undefined;
|
|
294
328
|
/** Durable token for the workflow run that launched this task, when known. */
|
|
@@ -345,6 +379,16 @@ export interface WeftServer extends AsyncDisposable {
|
|
|
345
379
|
readonly url: string;
|
|
346
380
|
readonly registry: WorkerRegistry;
|
|
347
381
|
readonly taskQueue: TaskQueue;
|
|
382
|
+
/**
|
|
383
|
+
* Resolves once startup task-ledger recovery (WFT-23) has reconstructed
|
|
384
|
+
* every non-terminal task's in-memory indexes from durable storage;
|
|
385
|
+
* rejects if the recovery scan itself failed. `dispatchTask`, long-poll
|
|
386
|
+
* claim/result handling, and worker registration all await this
|
|
387
|
+
* internally before touching the ledger, so awaiting it explicitly is
|
|
388
|
+
* optional — it exists for callers (health checks, orchestration) that
|
|
389
|
+
* want to observe readiness without dispatching a probe task.
|
|
390
|
+
*/
|
|
391
|
+
readonly ready: Promise<void>;
|
|
348
392
|
/**
|
|
349
393
|
* Drain connected remote workers, then stop the underlying Bun server.
|
|
350
394
|
*
|
|
@@ -356,6 +400,22 @@ export interface WeftServer extends AsyncDisposable {
|
|
|
356
400
|
stop(): Promise<void>;
|
|
357
401
|
/** Dispatch a task to the best available worker. Returns true if dispatched. */
|
|
358
402
|
dispatchTask(task: TaskDispatch): Promise<boolean>;
|
|
403
|
+
/**
|
|
404
|
+
* Read the current public view of a dispatched task's ledger record.
|
|
405
|
+
* Returns `null` if no record exists — never dispatched, or a retained
|
|
406
|
+
* terminal record was already reaped. See {@link TaskResultView}.
|
|
407
|
+
*/
|
|
408
|
+
getTaskResult(operationId: string): Promise<TaskResultView | null>;
|
|
409
|
+
/**
|
|
410
|
+
* Mark a terminal task's result as adopted — the durable assertion that
|
|
411
|
+
* whatever consumed the result (a workflow's own checkpoint, or other
|
|
412
|
+
* application logic) has durably incorporated it. `resultDigest` must
|
|
413
|
+
* match the terminal record's `resultDigest` from {@link getTaskResult}.
|
|
414
|
+
* Returns `true` once adopted; `false` if the record is not currently
|
|
415
|
+
* terminal or the digest does not match. Only adopted terminal records
|
|
416
|
+
* become eligible for {@link ServeOptions.taskRetentionWindowMs} reaping.
|
|
417
|
+
*/
|
|
418
|
+
adoptTaskResult(operationId: string, resultDigest: string): Promise<boolean>;
|
|
359
419
|
/** Send a shutdown message to a specific worker and wait for it to disconnect. Returns true if the worker was found. */
|
|
360
420
|
shutdownWorker(workerId: string, options?: {
|
|
361
421
|
timeoutMs?: number;
|
|
@@ -372,8 +432,11 @@ export interface WeftServer extends AsyncDisposable {
|
|
|
372
432
|
*
|
|
373
433
|
* `serve()` validates the supplied `auth` configuration synchronously and
|
|
374
434
|
* throws `Error` before binding the port if any auth setting is invalid.
|
|
375
|
-
*
|
|
376
|
-
* on startup so no
|
|
435
|
+
* Every non-terminal task record from previous server runs is recovered from
|
|
436
|
+
* durable storage on startup so no task is silently lost across restarts —
|
|
437
|
+
* see `WeftServer.ready`. Task dispatch, claim, completion, and worker
|
|
438
|
+
* registration all wait for that recovery to finish (or fail loudly if it
|
|
439
|
+
* doesn't) before touching the ledger.
|
|
377
440
|
*
|
|
378
441
|
* The returned `WeftServer.taskQueue` is exposed for inspection, not as a stable
|
|
379
442
|
* mutation surface — prefer `WeftServer` methods (`dispatchTask`,
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requireStorageCapability } from "../storage/interface.js";
|
|
1
2
|
import { WorkerRegistry } from "../worker/registry.js";
|
|
2
3
|
import {
|
|
3
4
|
createDashboardAssetRoute,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
} from "./runtime/shutdown.js";
|
|
14
15
|
import { stopBunServerForShutdown } from "./runtime/stop-server.js";
|
|
15
16
|
import { cancelTask, dispatchTaskImpl } from "./runtime/task-dispatch.js";
|
|
17
|
+
import { adoptTaskResultImpl, getTaskResultViewImpl } from "./runtime/task-result-view.js";
|
|
16
18
|
import { publishTokenMessage, publishWatchMessage } from "./runtime/websocket-stream.js";
|
|
17
19
|
import {
|
|
18
20
|
buildBunServeConfig,
|
|
@@ -20,8 +22,7 @@ import {
|
|
|
20
22
|
buildServerContext,
|
|
21
23
|
cleanupWorkflowIndex,
|
|
22
24
|
registerStackDisposers,
|
|
23
|
-
resolveNetworkConfig
|
|
24
|
-
restoreInflightTasks
|
|
25
|
+
resolveNetworkConfig
|
|
25
26
|
} from "./serve-internals.js";
|
|
26
27
|
import { TaskQueue } from "./task-queue.js";
|
|
27
28
|
export {
|
|
@@ -53,6 +54,7 @@ export const DASHBOARD_PAGE_ROUTES = [
|
|
|
53
54
|
"/system"
|
|
54
55
|
];
|
|
55
56
|
export function serve(options) {
|
|
57
|
+
requireStorageCapability(options.engine.storage, "conditionalBatch", "Remote task ledger (durable dispatch, claim, heartbeat, completion, and requeue)");
|
|
56
58
|
const dashboardAssets = options.dashboardAssets === void 0 ? void 0 : resolveDashboardAssets(options.dashboardAssets, DASHBOARD_PAGE_ROUTES), { port, hostname, development, tlsOptions, serverOptions, serverMetricsCollector } = resolveNetworkConfig(options), context = buildServerContext(serverOptions, serverMetricsCollector), boundCleanup = (operationId) => cleanupWorkflowIndex(context, operationId), routes = {};
|
|
57
59
|
if (options.dashboard != null)
|
|
58
60
|
for (const path of DASHBOARD_PAGE_ROUTES)
|
|
@@ -79,7 +81,6 @@ export function serve(options) {
|
|
|
79
81
|
throw error;
|
|
80
82
|
}
|
|
81
83
|
registerStackDisposers(stack, context, options, broadcastingHandle, boundCleanup);
|
|
82
|
-
restoreInflightTasks(context, options);
|
|
83
84
|
const resolvedPort = server.port ?? port, resolvedHostname = server.hostname ?? hostname;
|
|
84
85
|
return {
|
|
85
86
|
port: resolvedPort,
|
|
@@ -87,10 +88,13 @@ export function serve(options) {
|
|
|
87
88
|
url: `${tlsOptions ? "https" : "http"}://${resolvedHostname}:${resolvedPort}`,
|
|
88
89
|
registry: context.registry,
|
|
89
90
|
taskQueue: context.taskQueue,
|
|
91
|
+
ready: context.taskLedgerRecovery.ready,
|
|
90
92
|
async stop() {
|
|
91
93
|
await stack[Symbol.asyncDispose]();
|
|
92
94
|
},
|
|
93
95
|
dispatchTask: (task) => dispatchTaskImpl(context, options, task),
|
|
96
|
+
getTaskResult: (operationId) => getTaskResultViewImpl(options.engine.storage, operationId),
|
|
97
|
+
adoptTaskResult: (operationId, resultDigest) => adoptTaskResultImpl(options.engine.storage, operationId, resultDigest),
|
|
94
98
|
shutdownWorker: (workerId, shutdownOptions) => shutdownWorkerImpl(context, workerId, shutdownOptions),
|
|
95
99
|
shutdownAllWorkers: (shutdownOptions) => shutdownAllWorkersImpl(context, shutdownOptions),
|
|
96
100
|
cancelTask: (operationId) => cancelTask(context, operationId),
|
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `weft.tasks.diagnostics` operation + REST binding.
|
|
3
3
|
*
|
|
4
|
-
* Scans durable task
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Scans the durable task ledger (WFT-24 — previously the retired
|
|
5
|
+
* `op:queued:`/`op:inflight:`/`op:resolved:`/`op:dead-letter:` keys, which
|
|
6
|
+
* nothing has written since the WFT-22 ledger cutover) and live worker state
|
|
7
|
+
* to identify queue pressure, stale in-flight work, retry storms, dead
|
|
8
|
+
* letters, and worker capacity saturation. Results are intentionally bounded
|
|
9
|
+
* and low-cardinality so operators can use them in a dashboard without
|
|
10
|
+
* turning workflow or worker identifiers into metrics labels.
|
|
11
|
+
*
|
|
12
|
+
* The output schema's field names and `kind`/`state` vocabulary are
|
|
13
|
+
* unchanged from the pre-ledger version — only the internal scan and
|
|
14
|
+
* classification logic changed — so existing dashboards built against this
|
|
15
|
+
* endpoint's shape keep working. `leased`, `completing`, and `cancelling`
|
|
16
|
+
* ledger states are all reported as diagnostic `state: 'inflight'`: they
|
|
17
|
+
* share the same lease-holder/heartbeat shape and the same operator
|
|
18
|
+
* question ("is a worker still making progress on this attempt?"), so
|
|
19
|
+
* exposing the ledger's more granular internal states here would add
|
|
20
|
+
* distinctions operators cannot act on differently.
|
|
21
|
+
*
|
|
22
|
+
* Retry-storm detection (`kind: 'retry-storm'`) no longer covers `terminal`
|
|
23
|
+
* records: `RemoteTaskTerminal` carries no `retryCount`/`requeueCount` (WFT-25
|
|
24
|
+
* deliberately dropped attempt-count history once a task resolves), so
|
|
25
|
+
* there is nothing left to detect a storm from once an attempt reaches a
|
|
26
|
+
* disposition. The `resolved` value in the `state` enum is kept in the
|
|
27
|
+
* output schema for backward compatibility but nothing produces it anymore.
|
|
28
|
+
* `dead-lettered` diagnostics are unaffected — that is a distinct, separate
|
|
29
|
+
* `kind`.
|
|
30
|
+
*
|
|
31
|
+
* Unlike the pre-ledger scan, the full ledger scan this operation performs
|
|
32
|
+
* is one combined keyspace across every state (queued through terminal),
|
|
33
|
+
* not separate per-state prefixes — there is no time-bounded history index
|
|
34
|
+
* to limit how many terminal records get walked past on the way to
|
|
35
|
+
* classifying the ones that still matter. Operators who dispatch high
|
|
36
|
+
* volumes of tasks and want this scan to stay cheap should set
|
|
37
|
+
* {@link ServeOptions.taskRetentionWindowMs} so adopted terminal records
|
|
38
|
+
* are reaped rather than accumulating indefinitely.
|
|
8
39
|
*
|
|
9
40
|
* @module server/operations/get-task-diagnostics
|
|
10
41
|
*/
|
|
@@ -30,8 +61,8 @@ declare const taskDiagnosticItemSchema: z.ZodObject<{
|
|
|
30
61
|
state: z.ZodEnum<{
|
|
31
62
|
"dead-lettered": "dead-lettered";
|
|
32
63
|
queued: "queued";
|
|
33
|
-
inflight: "inflight";
|
|
34
64
|
resolved: "resolved";
|
|
65
|
+
inflight: "inflight";
|
|
35
66
|
capacity: "capacity";
|
|
36
67
|
}>;
|
|
37
68
|
operationId: z.ZodOptional<z.ZodString>;
|
|
@@ -44,10 +75,7 @@ declare const taskDiagnosticItemSchema: z.ZodObject<{
|
|
|
44
75
|
queueLatencyMs: z.ZodOptional<z.ZodNumber>;
|
|
45
76
|
executionLatencyMs: z.ZodOptional<z.ZodNumber>;
|
|
46
77
|
heartbeatAgeMs: z.ZodOptional<z.ZodNumber>;
|
|
47
|
-
lastRequeueReason: z.ZodOptional<z.
|
|
48
|
-
"visibility-timeout": "visibility-timeout";
|
|
49
|
-
"worker-disconnect": "worker-disconnect";
|
|
50
|
-
}>>;
|
|
78
|
+
lastRequeueReason: z.ZodOptional<z.ZodString>;
|
|
51
79
|
resolutionReason: z.ZodOptional<z.ZodString>;
|
|
52
80
|
deadLetteredAt: z.ZodOptional<z.ZodNumber>;
|
|
53
81
|
deadLetterReason: z.ZodOptional<z.ZodLiteral<"result-resolution-storage-exhausted">>;
|
|
@@ -74,8 +102,8 @@ declare const getTaskDiagnosticsOutput: z.ZodObject<{
|
|
|
74
102
|
state: z.ZodEnum<{
|
|
75
103
|
"dead-lettered": "dead-lettered";
|
|
76
104
|
queued: "queued";
|
|
77
|
-
inflight: "inflight";
|
|
78
105
|
resolved: "resolved";
|
|
106
|
+
inflight: "inflight";
|
|
79
107
|
capacity: "capacity";
|
|
80
108
|
}>;
|
|
81
109
|
operationId: z.ZodOptional<z.ZodString>;
|
|
@@ -88,10 +116,7 @@ declare const getTaskDiagnosticsOutput: z.ZodObject<{
|
|
|
88
116
|
queueLatencyMs: z.ZodOptional<z.ZodNumber>;
|
|
89
117
|
executionLatencyMs: z.ZodOptional<z.ZodNumber>;
|
|
90
118
|
heartbeatAgeMs: z.ZodOptional<z.ZodNumber>;
|
|
91
|
-
lastRequeueReason: z.ZodOptional<z.
|
|
92
|
-
"visibility-timeout": "visibility-timeout";
|
|
93
|
-
"worker-disconnect": "worker-disconnect";
|
|
94
|
-
}>>;
|
|
119
|
+
lastRequeueReason: z.ZodOptional<z.ZodString>;
|
|
95
120
|
resolutionReason: z.ZodOptional<z.ZodString>;
|
|
96
121
|
deadLetteredAt: z.ZodOptional<z.ZodNumber>;
|
|
97
122
|
deadLetterReason: z.ZodOptional<z.ZodLiteral<"result-resolution-storage-exhausted">>;
|
|
@@ -146,7 +171,7 @@ export declare function createGetTaskDiagnosticsOperation(options?: GetTaskDiagn
|
|
|
146
171
|
}, {
|
|
147
172
|
items: {
|
|
148
173
|
kind: "dead-lettered" | "stuck-queued" | "stale-inflight" | "retry-storm" | "all-workers-at-capacity";
|
|
149
|
-
state: "dead-lettered" | "queued" | "
|
|
174
|
+
state: "dead-lettered" | "queued" | "resolved" | "inflight" | "capacity";
|
|
150
175
|
retryCount: number;
|
|
151
176
|
requeueCount: number;
|
|
152
177
|
evidence: string[];
|
|
@@ -158,7 +183,7 @@ export declare function createGetTaskDiagnosticsOperation(options?: GetTaskDiagn
|
|
|
158
183
|
queueLatencyMs?: number | undefined;
|
|
159
184
|
executionLatencyMs?: number | undefined;
|
|
160
185
|
heartbeatAgeMs?: number | undefined;
|
|
161
|
-
lastRequeueReason?:
|
|
186
|
+
lastRequeueReason?: string | undefined;
|
|
162
187
|
resolutionReason?: string | undefined;
|
|
163
188
|
deadLetteredAt?: number | undefined;
|
|
164
189
|
deadLetterReason?: "result-resolution-storage-exhausted" | undefined;
|
|
@@ -185,7 +210,7 @@ export declare const getTaskDiagnosticsOperation: import("../operation-catalog.t
|
|
|
185
210
|
}, {
|
|
186
211
|
items: {
|
|
187
212
|
kind: "dead-lettered" | "stuck-queued" | "stale-inflight" | "retry-storm" | "all-workers-at-capacity";
|
|
188
|
-
state: "dead-lettered" | "queued" | "
|
|
213
|
+
state: "dead-lettered" | "queued" | "resolved" | "inflight" | "capacity";
|
|
189
214
|
retryCount: number;
|
|
190
215
|
requeueCount: number;
|
|
191
216
|
evidence: string[];
|
|
@@ -197,7 +222,7 @@ export declare const getTaskDiagnosticsOperation: import("../operation-catalog.t
|
|
|
197
222
|
queueLatencyMs?: number | undefined;
|
|
198
223
|
executionLatencyMs?: number | undefined;
|
|
199
224
|
heartbeatAgeMs?: number | undefined;
|
|
200
|
-
lastRequeueReason?:
|
|
225
|
+
lastRequeueReason?: string | undefined;
|
|
201
226
|
resolutionReason?: string | undefined;
|
|
202
227
|
deadLetteredAt?: number | undefined;
|
|
203
228
|
deadLetterReason?: "result-resolution-storage-exhausted" | undefined;
|