@cadenza.io/service 2.20.1 → 2.21.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 +17 -0
- package/dist/{Cadenza-Duj65Skt.d.mts → Cadenza-Cq1mscQf.d.mts} +72 -1
- package/dist/{Cadenza-Duj65Skt.d.ts → Cadenza-Cq1mscQf.d.ts} +72 -1
- package/dist/browser/index.js +1485 -313
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1485 -313
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +1504 -332
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1504 -332
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +2 -2
- package/dist/nuxt/index.d.ts +2 -2
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/vue/index.d.mts +2 -2
- package/dist/vue/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -21,6 +21,30 @@ var LOCAL_ROUTINE_PERSISTENCE_KEYS = [
|
|
|
21
21
|
"__routineCreatedAt",
|
|
22
22
|
"__routineIsMeta"
|
|
23
23
|
];
|
|
24
|
+
var BULKY_EXECUTION_PERSISTENCE_KEYS = [
|
|
25
|
+
"rows",
|
|
26
|
+
"joinedContexts",
|
|
27
|
+
"serviceInstances",
|
|
28
|
+
"serviceInstanceLeases",
|
|
29
|
+
"serviceInstanceTransports",
|
|
30
|
+
"serviceManifests",
|
|
31
|
+
"tasks",
|
|
32
|
+
"helpers",
|
|
33
|
+
"globals",
|
|
34
|
+
"signals",
|
|
35
|
+
"intents",
|
|
36
|
+
"actors",
|
|
37
|
+
"routines",
|
|
38
|
+
"directionalTaskMaps",
|
|
39
|
+
"actorTaskMaps",
|
|
40
|
+
"taskToRoutineMaps",
|
|
41
|
+
"taskToHelperMaps",
|
|
42
|
+
"helperToHelperMaps",
|
|
43
|
+
"taskToGlobalMaps",
|
|
44
|
+
"helperToGlobalMaps",
|
|
45
|
+
"signalToTaskMaps",
|
|
46
|
+
"intentToTaskMaps"
|
|
47
|
+
];
|
|
24
48
|
function readHintValue(source, key) {
|
|
25
49
|
if (!source || typeof source !== "object") {
|
|
26
50
|
return void 0;
|
|
@@ -47,8 +71,80 @@ function stripLocalRoutinePersistenceHints(input) {
|
|
|
47
71
|
}
|
|
48
72
|
return context;
|
|
49
73
|
}
|
|
74
|
+
function summarizeQueryData(queryData) {
|
|
75
|
+
if (!queryData || typeof queryData !== "object") {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
const summary = {};
|
|
79
|
+
if (queryData.data && typeof queryData.data === "object") {
|
|
80
|
+
summary.dataKeys = Object.keys(queryData.data).sort();
|
|
81
|
+
}
|
|
82
|
+
if (queryData.filter && typeof queryData.filter === "object") {
|
|
83
|
+
summary.filterKeys = Object.keys(queryData.filter).sort();
|
|
84
|
+
}
|
|
85
|
+
if (queryData.onConflict && typeof queryData.onConflict === "object") {
|
|
86
|
+
const onConflict = queryData.onConflict;
|
|
87
|
+
summary.onConflictTarget = Array.isArray(onConflict.target) ? [...onConflict.target] : onConflict.target ?? null;
|
|
88
|
+
}
|
|
89
|
+
return Object.keys(summary).length > 0 ? summary : void 0;
|
|
90
|
+
}
|
|
91
|
+
function sanitizeExecutionPersistenceContext(input) {
|
|
92
|
+
const context = stripLocalRoutinePersistenceHints(input);
|
|
93
|
+
for (const key of BULKY_EXECUTION_PERSISTENCE_KEYS) {
|
|
94
|
+
const value = context[key];
|
|
95
|
+
if (value === void 0) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const countKey = `${key}Count`;
|
|
99
|
+
if (context[countKey] === void 0) {
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
context[countKey] = value.length;
|
|
102
|
+
} else if (value && typeof value === "object") {
|
|
103
|
+
context[countKey] = Object.keys(value).length;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
delete context[key];
|
|
107
|
+
}
|
|
108
|
+
if (context.queryData && typeof context.queryData === "object") {
|
|
109
|
+
const queryDataSummary = summarizeQueryData(context.queryData);
|
|
110
|
+
if (queryDataSummary) {
|
|
111
|
+
context.queryData = queryDataSummary;
|
|
112
|
+
} else {
|
|
113
|
+
delete context.queryData;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return context;
|
|
117
|
+
}
|
|
118
|
+
function sanitizeExecutionPersistenceResultPayload(input) {
|
|
119
|
+
const payload = input && typeof input === "object" ? { ...input } : {};
|
|
120
|
+
const resultContext = payload.resultContext && typeof payload.resultContext === "object" ? sanitizeExecutionPersistenceContext(
|
|
121
|
+
payload.resultContext
|
|
122
|
+
) : payload.resultContext;
|
|
123
|
+
const metaResultContext = payload.metaResultContext && typeof payload.metaResultContext === "object" ? sanitizeExecutionPersistenceContext(
|
|
124
|
+
payload.metaResultContext
|
|
125
|
+
) : payload.metaResultContext;
|
|
126
|
+
const snakeResultContext = payload.result_context && typeof payload.result_context === "object" ? sanitizeExecutionPersistenceContext(
|
|
127
|
+
payload.result_context
|
|
128
|
+
) : payload.result_context;
|
|
129
|
+
const snakeMetaResultContext = payload.meta_result_context && typeof payload.meta_result_context === "object" ? sanitizeExecutionPersistenceContext(
|
|
130
|
+
payload.meta_result_context
|
|
131
|
+
) : payload.meta_result_context;
|
|
132
|
+
if (resultContext !== void 0) {
|
|
133
|
+
payload.resultContext = resultContext;
|
|
134
|
+
}
|
|
135
|
+
if (metaResultContext !== void 0) {
|
|
136
|
+
payload.metaResultContext = metaResultContext;
|
|
137
|
+
}
|
|
138
|
+
if (snakeResultContext !== void 0) {
|
|
139
|
+
payload.result_context = snakeResultContext;
|
|
140
|
+
}
|
|
141
|
+
if (snakeMetaResultContext !== void 0) {
|
|
142
|
+
payload.meta_result_context = snakeMetaResultContext;
|
|
143
|
+
}
|
|
144
|
+
return payload;
|
|
145
|
+
}
|
|
50
146
|
function splitRoutinePersistenceContext(input) {
|
|
51
|
-
const sanitized =
|
|
147
|
+
const sanitized = sanitizeExecutionPersistenceContext(input);
|
|
52
148
|
return {
|
|
53
149
|
context: Object.fromEntries(
|
|
54
150
|
Object.entries(sanitized).filter(([key]) => !key.startsWith("__"))
|
|
@@ -237,6 +333,90 @@ function ensureDelegationContextMetadata(input) {
|
|
|
237
333
|
|
|
238
334
|
// src/graph/definition/DeputyTask.ts
|
|
239
335
|
var SERVICE_REGISTRY_TRACE_SERVICE = (process.env.CADENZA_SERVICE_REGISTRY_TRACE_SERVICE ?? "").trim();
|
|
336
|
+
function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
337
|
+
const task = this;
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
if (context.__metadata.__blockRemoteExecution) {
|
|
340
|
+
reject(new Error("Blocked remote execution"));
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (context.__metadata.__skipRemoteExecution) {
|
|
344
|
+
resolve(context);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const processId = uuid2();
|
|
348
|
+
context.__metadata.__deputyExecId = processId;
|
|
349
|
+
if ((process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") && context.__remoteRoutineName === "Insert service_instance") {
|
|
350
|
+
console.log("[CADENZA_INSTANCE_DEBUG] deputy_delegation_requested", {
|
|
351
|
+
localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
352
|
+
localTaskName: context.__localTaskName ?? null,
|
|
353
|
+
remoteRoutineName: context.__remoteRoutineName ?? null,
|
|
354
|
+
targetServiceName: context.__serviceName ?? null,
|
|
355
|
+
deputyExecId: processId,
|
|
356
|
+
dataKeys: context.data && typeof context.data === "object" ? Object.keys(context.data) : [],
|
|
357
|
+
queryDataKeys: context.queryData && typeof context.queryData === "object" ? Object.keys(context.queryData) : [],
|
|
358
|
+
queryDataDataKeys: context.queryData?.data && typeof context.queryData.data === "object" ? Object.keys(context.queryData.data) : []
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
emit2("meta.deputy.delegation_requested", {
|
|
362
|
+
...context
|
|
363
|
+
});
|
|
364
|
+
CadenzaService.createEphemeralMetaTask(
|
|
365
|
+
`On progress deputy ${task.remoteRoutineName}`,
|
|
366
|
+
(ctx) => {
|
|
367
|
+
if (typeof progressCallback === "function" && ctx.progress) {
|
|
368
|
+
progressCallback(ctx.progress * ctx.weight);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
`Ephemeral task for deputy process ${processId}`,
|
|
372
|
+
{
|
|
373
|
+
once: false,
|
|
374
|
+
destroyCondition: (ctx) => ctx.progress === 1 || ctx.progress === void 0,
|
|
375
|
+
register: false
|
|
376
|
+
}
|
|
377
|
+
).doOn(
|
|
378
|
+
`meta.socket_client.delegation_progress:${processId}`,
|
|
379
|
+
`meta.socket_client.delegated:${processId}`,
|
|
380
|
+
`meta.fetch.delegated:${processId}`,
|
|
381
|
+
`meta.service_registry.load_balance_failed:${processId}`
|
|
382
|
+
);
|
|
383
|
+
CadenzaService.createEphemeralMetaTask(
|
|
384
|
+
`Resolve deputy ${task.remoteRoutineName}`,
|
|
385
|
+
(responseCtx) => {
|
|
386
|
+
const mergedResponseCtx = responseCtx && typeof responseCtx === "object" ? {
|
|
387
|
+
...context,
|
|
388
|
+
...responseCtx
|
|
389
|
+
} : responseCtx;
|
|
390
|
+
if (responseCtx?.errored) {
|
|
391
|
+
reject(new Error(responseCtx.__error));
|
|
392
|
+
} else {
|
|
393
|
+
if (SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && CadenzaService.serviceRegistry.serviceName === SERVICE_REGISTRY_TRACE_SERVICE && context.__remoteRoutineName === "Insert service_instance") {
|
|
394
|
+
console.log(
|
|
395
|
+
"[CADENZA_SERVICE_REGISTRY_TRACE] deputy_insert_service_instance_resolved",
|
|
396
|
+
{
|
|
397
|
+
localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
398
|
+
targetServiceName: context.__serviceName ?? null,
|
|
399
|
+
resolverRequestId: context.__resolverRequestId ?? null,
|
|
400
|
+
serviceInstanceId: mergedResponseCtx && typeof mergedResponseCtx === "object" ? mergedResponseCtx.__serviceInstanceId ?? mergedResponseCtx.uuid ?? mergedResponseCtx.data?.uuid ?? null : null,
|
|
401
|
+
hasResolverQueryData: mergedResponseCtx && typeof mergedResponseCtx === "object" && mergedResponseCtx.__resolverQueryData !== void 0
|
|
402
|
+
}
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
if (mergedResponseCtx && typeof mergedResponseCtx === "object") {
|
|
406
|
+
delete mergedResponseCtx.__isDeputy;
|
|
407
|
+
}
|
|
408
|
+
resolve(mergedResponseCtx);
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
`Ephemeral resolver for deputy process ${processId}`,
|
|
412
|
+
{ register: false }
|
|
413
|
+
).doOn(
|
|
414
|
+
`meta.socket_client.delegated:${processId}`,
|
|
415
|
+
`meta.fetch.delegated:${processId}`,
|
|
416
|
+
`meta.service_registry.load_balance_failed:${processId}`
|
|
417
|
+
);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
240
420
|
var DeputyTask = class extends Task {
|
|
241
421
|
/**
|
|
242
422
|
* Constructs a new instance of the class with the specified parameters.
|
|
@@ -264,87 +444,9 @@ var DeputyTask = class extends Task {
|
|
|
264
444
|
* @return {void} This constructor does not return a value.
|
|
265
445
|
*/
|
|
266
446
|
constructor(name, remoteRoutineName, serviceName = void 0, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
267
|
-
const taskFunction = (context, emit2, inquire, progressCallback) => {
|
|
268
|
-
return new Promise((resolve, reject) => {
|
|
269
|
-
if (context.__metadata.__blockRemoteExecution) {
|
|
270
|
-
reject(new Error("Blocked remote execution"));
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (context.__metadata.__skipRemoteExecution) {
|
|
274
|
-
resolve(context);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const processId = uuid2();
|
|
278
|
-
context.__metadata.__deputyExecId = processId;
|
|
279
|
-
if ((process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") && context.__remoteRoutineName === "Insert service_instance") {
|
|
280
|
-
console.log("[CADENZA_INSTANCE_DEBUG] deputy_delegation_requested", {
|
|
281
|
-
localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
282
|
-
localTaskName: context.__localTaskName ?? null,
|
|
283
|
-
remoteRoutineName: context.__remoteRoutineName ?? null,
|
|
284
|
-
targetServiceName: context.__serviceName ?? null,
|
|
285
|
-
deputyExecId: processId,
|
|
286
|
-
dataKeys: context.data && typeof context.data === "object" ? Object.keys(context.data) : [],
|
|
287
|
-
queryDataKeys: context.queryData && typeof context.queryData === "object" ? Object.keys(context.queryData) : [],
|
|
288
|
-
queryDataDataKeys: context.queryData?.data && typeof context.queryData.data === "object" ? Object.keys(context.queryData.data) : []
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
emit2("meta.deputy.delegation_requested", {
|
|
292
|
-
...context
|
|
293
|
-
});
|
|
294
|
-
CadenzaService.createEphemeralMetaTask(
|
|
295
|
-
`On progress deputy ${this.remoteRoutineName}`,
|
|
296
|
-
(ctx) => {
|
|
297
|
-
if (ctx.progress) progressCallback(ctx.progress * ctx.weight);
|
|
298
|
-
},
|
|
299
|
-
`Ephemeral task for deputy process ${processId}`,
|
|
300
|
-
{
|
|
301
|
-
once: false,
|
|
302
|
-
destroyCondition: (ctx) => ctx.progress === 1 || ctx.progress === void 0,
|
|
303
|
-
register: false
|
|
304
|
-
}
|
|
305
|
-
).doOn(
|
|
306
|
-
`meta.socket_client.delegation_progress:${processId}`,
|
|
307
|
-
`meta.socket_client.delegated:${processId}`,
|
|
308
|
-
`meta.fetch.delegated:${processId}`,
|
|
309
|
-
`meta.service_registry.load_balance_failed:${processId}`
|
|
310
|
-
);
|
|
311
|
-
CadenzaService.createEphemeralMetaTask(
|
|
312
|
-
`Resolve deputy ${this.remoteRoutineName}`,
|
|
313
|
-
(responseCtx) => {
|
|
314
|
-
const mergedResponseCtx = responseCtx && typeof responseCtx === "object" ? {
|
|
315
|
-
...context,
|
|
316
|
-
...responseCtx
|
|
317
|
-
} : responseCtx;
|
|
318
|
-
if (responseCtx?.errored) {
|
|
319
|
-
reject(new Error(responseCtx.__error));
|
|
320
|
-
} else {
|
|
321
|
-
if (SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && CadenzaService.serviceRegistry.serviceName === SERVICE_REGISTRY_TRACE_SERVICE && context.__remoteRoutineName === "Insert service_instance") {
|
|
322
|
-
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] deputy_insert_service_instance_resolved", {
|
|
323
|
-
localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
324
|
-
targetServiceName: context.__serviceName ?? null,
|
|
325
|
-
resolverRequestId: context.__resolverRequestId ?? null,
|
|
326
|
-
serviceInstanceId: mergedResponseCtx && typeof mergedResponseCtx === "object" ? mergedResponseCtx.__serviceInstanceId ?? mergedResponseCtx.uuid ?? mergedResponseCtx.data?.uuid ?? null : null,
|
|
327
|
-
hasResolverQueryData: mergedResponseCtx && typeof mergedResponseCtx === "object" && mergedResponseCtx.__resolverQueryData !== void 0
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
if (mergedResponseCtx && typeof mergedResponseCtx === "object") {
|
|
331
|
-
delete mergedResponseCtx.__isDeputy;
|
|
332
|
-
}
|
|
333
|
-
resolve(mergedResponseCtx);
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
`Ephemeral resolver for deputy process ${processId}`,
|
|
337
|
-
{ register: false }
|
|
338
|
-
).doOn(
|
|
339
|
-
`meta.socket_client.delegated:${processId}`,
|
|
340
|
-
`meta.fetch.delegated:${processId}`,
|
|
341
|
-
`meta.service_registry.load_balance_failed:${processId}`
|
|
342
|
-
);
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
447
|
super(
|
|
346
448
|
name,
|
|
347
|
-
|
|
449
|
+
deputyTaskExecutor,
|
|
348
450
|
description,
|
|
349
451
|
concurrency,
|
|
350
452
|
timeout,
|
|
@@ -376,6 +478,11 @@ var DeputyTask = class extends Task {
|
|
|
376
478
|
communicationType: "delegation"
|
|
377
479
|
});
|
|
378
480
|
}
|
|
481
|
+
clone() {
|
|
482
|
+
throw new Error(
|
|
483
|
+
`DeputyTask '${this.name}' does not support clone(). Create a new named deputy task or use a flow-specific meta task that performs an inquiry instead.`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
379
486
|
/**
|
|
380
487
|
* Executes the specified task function within the provided execution context.
|
|
381
488
|
*
|
|
@@ -419,7 +526,25 @@ var DeputyTask = class extends Task {
|
|
|
419
526
|
})
|
|
420
527
|
)
|
|
421
528
|
);
|
|
422
|
-
|
|
529
|
+
const resolvedTools = typeof CadenzaService.resolveToolsForOwner === "function" ? CadenzaService.resolveToolsForOwner(
|
|
530
|
+
this,
|
|
531
|
+
deputyContext,
|
|
532
|
+
emit2,
|
|
533
|
+
inquire,
|
|
534
|
+
progressCallback
|
|
535
|
+
) : {
|
|
536
|
+
helpers: {},
|
|
537
|
+
globals: {}
|
|
538
|
+
};
|
|
539
|
+
const resolvedProgressCallback = typeof progressCallback === "function" ? progressCallback : () => {
|
|
540
|
+
};
|
|
541
|
+
return this.taskFunction(
|
|
542
|
+
deputyContext,
|
|
543
|
+
emit2,
|
|
544
|
+
inquire,
|
|
545
|
+
resolvedTools,
|
|
546
|
+
resolvedProgressCallback
|
|
547
|
+
);
|
|
423
548
|
}
|
|
424
549
|
};
|
|
425
550
|
|
|
@@ -488,6 +613,11 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
488
613
|
);
|
|
489
614
|
this.queryData = queryData;
|
|
490
615
|
}
|
|
616
|
+
clone() {
|
|
617
|
+
throw new Error(
|
|
618
|
+
`DatabaseTask '${this.name}' does not support clone(). Create a new named database task or use a flow-specific meta task that performs the default database inquiry instead.`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
491
621
|
/**
|
|
492
622
|
* Executes the specified task within the given context.
|
|
493
623
|
*
|
|
@@ -613,7 +743,25 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
613
743
|
sourceTaskName: rawContext.__localTaskName ?? rawContext.__metadata?.__localTaskName ?? null
|
|
614
744
|
});
|
|
615
745
|
}
|
|
616
|
-
|
|
746
|
+
const resolvedTools = typeof CadenzaService.resolveToolsForOwner === "function" ? CadenzaService.resolveToolsForOwner(
|
|
747
|
+
this,
|
|
748
|
+
deputyContext,
|
|
749
|
+
emit2,
|
|
750
|
+
inquire,
|
|
751
|
+
progressCallback
|
|
752
|
+
) : {
|
|
753
|
+
helpers: {},
|
|
754
|
+
globals: {}
|
|
755
|
+
};
|
|
756
|
+
const resolvedProgressCallback = typeof progressCallback === "function" ? progressCallback : () => {
|
|
757
|
+
};
|
|
758
|
+
return this.taskFunction(
|
|
759
|
+
deputyContext,
|
|
760
|
+
emit2,
|
|
761
|
+
inquire,
|
|
762
|
+
resolvedTools,
|
|
763
|
+
resolvedProgressCallback
|
|
764
|
+
);
|
|
617
765
|
}
|
|
618
766
|
};
|
|
619
767
|
|
|
@@ -903,6 +1051,10 @@ function normalizeServiceInstanceDescriptor(value) {
|
|
|
903
1051
|
return null;
|
|
904
1052
|
}
|
|
905
1053
|
const transports = normalizeTransportArray(raw.transports, uuid9);
|
|
1054
|
+
const leaseStatusRaw = normalizeString2(raw.leaseStatus ?? raw.lease_status);
|
|
1055
|
+
const leaseStatus = leaseStatusRaw === "active" || leaseStatusRaw === "non_responsive" || leaseStatusRaw === "inactive" || leaseStatusRaw === "deleted" ? leaseStatusRaw : void 0;
|
|
1056
|
+
const isActive = leaseStatus === "active" ? true : leaseStatus === "non_responsive" || leaseStatus === "inactive" || leaseStatus === "deleted" ? false : Boolean(raw.isActive ?? raw.is_active ?? true);
|
|
1057
|
+
const isNonResponsive = leaseStatus === "non_responsive" ? true : leaseStatus === "active" || leaseStatus === "inactive" || leaseStatus === "deleted" ? false : Boolean(raw.isNonResponsive ?? raw.is_non_responsive ?? false);
|
|
906
1058
|
return {
|
|
907
1059
|
uuid: uuid9,
|
|
908
1060
|
serviceName,
|
|
@@ -913,10 +1065,16 @@ function normalizeServiceInstanceDescriptor(value) {
|
|
|
913
1065
|
)
|
|
914
1066
|
),
|
|
915
1067
|
isPrimary: Boolean(raw.isPrimary ?? raw.is_primary ?? false),
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1068
|
+
leaseStatus,
|
|
1069
|
+
leaseExpiresAt: typeof raw.leaseExpiresAt === "string" ? raw.leaseExpiresAt : typeof raw.lease_expires_at === "string" ? raw.lease_expires_at : void 0,
|
|
1070
|
+
lastLeaseRenewedAt: typeof raw.lastLeaseRenewedAt === "string" ? raw.lastLeaseRenewedAt : typeof raw.last_lease_renewed_at === "string" ? raw.last_lease_renewed_at : void 0,
|
|
1071
|
+
isReady: typeof raw.isReady === "boolean" ? raw.isReady : typeof raw.is_ready === "boolean" ? raw.is_ready : void 0,
|
|
1072
|
+
readinessReason: typeof raw.readinessReason === "string" ? raw.readinessReason : typeof raw.readiness_reason === "string" ? raw.readiness_reason : null,
|
|
1073
|
+
lastReadyAt: typeof raw.lastReadyAt === "string" ? raw.lastReadyAt : typeof raw.last_ready_at === "string" ? raw.last_ready_at : null,
|
|
1074
|
+
lastObservedTransportAt: typeof raw.lastObservedTransportAt === "string" ? raw.lastObservedTransportAt : typeof raw.last_observed_transport_at === "string" ? raw.last_observed_transport_at : null,
|
|
1075
|
+
shutdownRequestedAt: typeof raw.shutdownRequestedAt === "string" ? raw.shutdownRequestedAt : typeof raw.shutdown_requested_at === "string" ? raw.shutdown_requested_at : null,
|
|
1076
|
+
isActive,
|
|
1077
|
+
isNonResponsive,
|
|
920
1078
|
isBlocked: Boolean(raw.isBlocked ?? raw.is_blocked ?? false),
|
|
921
1079
|
runtimeState: raw.runtimeState === "healthy" || raw.runtimeState === "degraded" || raw.runtimeState === "overloaded" || raw.runtimeState === "unavailable" ? raw.runtimeState : void 0,
|
|
922
1080
|
acceptingWork: typeof raw.acceptingWork === "boolean" ? raw.acceptingWork : void 0,
|
|
@@ -1369,6 +1527,61 @@ function resolveHealthMetric(input, keys) {
|
|
|
1369
1527
|
}
|
|
1370
1528
|
return void 0;
|
|
1371
1529
|
}
|
|
1530
|
+
function sanitizeRuntimeMetricsHealthDetail(value) {
|
|
1531
|
+
if (!value || typeof value !== "object") {
|
|
1532
|
+
return void 0;
|
|
1533
|
+
}
|
|
1534
|
+
const input = value;
|
|
1535
|
+
const sampledAt = typeof input.sampledAt === "string" && input.sampledAt.trim().length > 0 ? input.sampledAt : void 0;
|
|
1536
|
+
const cpuUsage = normalizeOptionalMetric(input.cpuUsage ?? input.cpu ?? input.cpuLoad);
|
|
1537
|
+
const memoryUsage = normalizeOptionalMetric(
|
|
1538
|
+
input.memoryUsage ?? input.memory ?? input.memoryPressure
|
|
1539
|
+
);
|
|
1540
|
+
const eventLoopLag = normalizeOptionalMetric(
|
|
1541
|
+
input.eventLoopLag ?? input.eventLoopLagMs
|
|
1542
|
+
);
|
|
1543
|
+
const rssBytes = normalizeOptionalMetric(input.rssBytes);
|
|
1544
|
+
const heapUsedBytes = normalizeOptionalMetric(input.heapUsedBytes);
|
|
1545
|
+
const heapTotalBytes = normalizeOptionalMetric(input.heapTotalBytes);
|
|
1546
|
+
const memoryLimitBytes = normalizeOptionalMetric(input.memoryLimitBytes);
|
|
1547
|
+
if (sampledAt === void 0 && cpuUsage === void 0 && memoryUsage === void 0 && eventLoopLag === void 0 && rssBytes === void 0 && heapUsedBytes === void 0 && heapTotalBytes === void 0 && memoryLimitBytes === void 0) {
|
|
1548
|
+
return void 0;
|
|
1549
|
+
}
|
|
1550
|
+
return {
|
|
1551
|
+
...sampledAt !== void 0 ? { sampledAt } : {},
|
|
1552
|
+
...cpuUsage !== void 0 ? { cpuUsage } : {},
|
|
1553
|
+
...memoryUsage !== void 0 ? { memoryUsage } : {},
|
|
1554
|
+
...eventLoopLag !== void 0 ? { eventLoopLag } : {},
|
|
1555
|
+
...rssBytes !== void 0 ? { rssBytes } : {},
|
|
1556
|
+
...heapUsedBytes !== void 0 ? { heapUsedBytes } : {},
|
|
1557
|
+
...heapTotalBytes !== void 0 ? { heapTotalBytes } : {},
|
|
1558
|
+
...memoryLimitBytes !== void 0 ? { memoryLimitBytes } : {}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
function sanitizeAuthorityRuntimeStatusHealth(health, options) {
|
|
1562
|
+
const input = health && typeof health === "object" ? health : {};
|
|
1563
|
+
const cpuUsage = options?.cpuUsage !== void 0 ? options.cpuUsage : normalizeOptionalMetric(input.cpuUsage ?? input.cpu ?? input.cpuLoad);
|
|
1564
|
+
const memoryUsage = options?.memoryUsage !== void 0 ? options.memoryUsage : normalizeOptionalMetric(
|
|
1565
|
+
input.memoryUsage ?? input.memory ?? input.memoryPressure
|
|
1566
|
+
);
|
|
1567
|
+
const eventLoopLag = options?.eventLoopLag !== void 0 ? options.eventLoopLag : normalizeOptionalMetric(input.eventLoopLag ?? input.eventLoopLagMs);
|
|
1568
|
+
const runtimeMetrics = sanitizeRuntimeMetricsHealthDetail(input.runtimeMetrics);
|
|
1569
|
+
const runtimeStatus = options?.state || options?.reportedAt || typeof options?.acceptingWork === "boolean" ? {
|
|
1570
|
+
...options?.state ? { state: options.state } : {},
|
|
1571
|
+
...typeof options?.acceptingWork === "boolean" ? { acceptingWork: options.acceptingWork } : {},
|
|
1572
|
+
...options?.reportedAt ? { reportedAt: options.reportedAt } : {}
|
|
1573
|
+
} : void 0;
|
|
1574
|
+
if (cpuUsage === void 0 && memoryUsage === void 0 && eventLoopLag === void 0 && !runtimeMetrics && !runtimeStatus) {
|
|
1575
|
+
return void 0;
|
|
1576
|
+
}
|
|
1577
|
+
return {
|
|
1578
|
+
...cpuUsage !== void 0 ? { cpuUsage } : {},
|
|
1579
|
+
...memoryUsage !== void 0 ? { memoryUsage } : {},
|
|
1580
|
+
...eventLoopLag !== void 0 ? { eventLoopLag } : {},
|
|
1581
|
+
...runtimeMetrics ? { runtimeMetrics } : {},
|
|
1582
|
+
...runtimeStatus ? { runtimeStatus } : {}
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1372
1585
|
function normalizeAuthorityRuntimeStatusReport(input) {
|
|
1373
1586
|
if (!input || typeof input !== "object") {
|
|
1374
1587
|
return null;
|
|
@@ -1397,6 +1610,17 @@ function normalizeAuthorityRuntimeStatusReport(input) {
|
|
|
1397
1610
|
(protocol) => protocol === "rest" || protocol === "socket"
|
|
1398
1611
|
) : [];
|
|
1399
1612
|
const transportProtocols = transportProtocolList.length > 0 ? Array.from(new Set(transportProtocolList)) : void 0;
|
|
1613
|
+
const acceptingWork = Boolean(input.acceptingWork ?? input.accepting_work);
|
|
1614
|
+
const cpuUsage = resolveHealthMetric(input, ["cpuUsage", "cpu", "cpuLoad"]);
|
|
1615
|
+
const memoryUsage = resolveHealthMetric(input, [
|
|
1616
|
+
"memoryUsage",
|
|
1617
|
+
"memory",
|
|
1618
|
+
"memoryPressure"
|
|
1619
|
+
]);
|
|
1620
|
+
const eventLoopLag = resolveHealthMetric(input, [
|
|
1621
|
+
"eventLoopLag",
|
|
1622
|
+
"eventLoopLagMs"
|
|
1623
|
+
]);
|
|
1400
1624
|
return {
|
|
1401
1625
|
serviceName,
|
|
1402
1626
|
serviceInstanceId,
|
|
@@ -1407,7 +1631,7 @@ function normalizeAuthorityRuntimeStatusReport(input) {
|
|
|
1407
1631
|
isFrontend: typeof input.isFrontend === "boolean" ? input.isFrontend : typeof input.is_frontend === "boolean" ? input.is_frontend : void 0,
|
|
1408
1632
|
reportedAt,
|
|
1409
1633
|
state,
|
|
1410
|
-
acceptingWork
|
|
1634
|
+
acceptingWork,
|
|
1411
1635
|
numberOfRunningGraphs: Math.max(
|
|
1412
1636
|
0,
|
|
1413
1637
|
Math.trunc(
|
|
@@ -1416,22 +1640,22 @@ function normalizeAuthorityRuntimeStatusReport(input) {
|
|
|
1416
1640
|
) || 0
|
|
1417
1641
|
)
|
|
1418
1642
|
),
|
|
1419
|
-
cpuUsage
|
|
1420
|
-
memoryUsage
|
|
1421
|
-
|
|
1422
|
-
"memory",
|
|
1423
|
-
"memoryPressure"
|
|
1424
|
-
]),
|
|
1425
|
-
eventLoopLag: resolveHealthMetric(input, [
|
|
1426
|
-
"eventLoopLag",
|
|
1427
|
-
"eventLoopLagMs"
|
|
1428
|
-
]),
|
|
1643
|
+
cpuUsage,
|
|
1644
|
+
memoryUsage,
|
|
1645
|
+
eventLoopLag,
|
|
1429
1646
|
isActive: Boolean(input.isActive ?? input.is_active ?? true),
|
|
1430
1647
|
isNonResponsive: Boolean(
|
|
1431
1648
|
input.isNonResponsive ?? input.is_non_responsive ?? false
|
|
1432
1649
|
),
|
|
1433
1650
|
isBlocked: Boolean(input.isBlocked ?? input.is_blocked ?? false),
|
|
1434
|
-
health: input.health
|
|
1651
|
+
health: sanitizeAuthorityRuntimeStatusHealth(input.health, {
|
|
1652
|
+
state,
|
|
1653
|
+
acceptingWork,
|
|
1654
|
+
reportedAt,
|
|
1655
|
+
cpuUsage,
|
|
1656
|
+
memoryUsage,
|
|
1657
|
+
eventLoopLag
|
|
1658
|
+
})
|
|
1435
1659
|
};
|
|
1436
1660
|
}
|
|
1437
1661
|
function buildAuthorityRuntimeStatusSignature(report) {
|
|
@@ -1444,18 +1668,53 @@ function buildAuthorityRuntimeStatusSignature(report) {
|
|
|
1444
1668
|
transportProtocols: report.transportProtocols ?? [],
|
|
1445
1669
|
state: report.state,
|
|
1446
1670
|
acceptingWork: report.acceptingWork,
|
|
1447
|
-
numberOfRunningGraphs: report.numberOfRunningGraphs,
|
|
1448
|
-
cpuUsage: report.cpuUsage ?? null,
|
|
1449
|
-
memoryUsage: report.memoryUsage ?? null,
|
|
1450
|
-
eventLoopLag: report.eventLoopLag ?? null,
|
|
1451
1671
|
isActive: report.isActive,
|
|
1452
1672
|
isNonResponsive: report.isNonResponsive,
|
|
1453
1673
|
isBlocked: report.isBlocked,
|
|
1454
|
-
isFrontend: report.isFrontend ?? null
|
|
1455
|
-
health: report.health ?? {}
|
|
1674
|
+
isFrontend: report.isFrontend ?? null
|
|
1456
1675
|
});
|
|
1457
1676
|
}
|
|
1458
1677
|
|
|
1678
|
+
// src/registry/runtimeJitter.ts
|
|
1679
|
+
function normalizeKey(key) {
|
|
1680
|
+
return key.trim() || "default";
|
|
1681
|
+
}
|
|
1682
|
+
function hashKeyToUnitInterval(key) {
|
|
1683
|
+
const normalizedKey = normalizeKey(key);
|
|
1684
|
+
let hash = 2166136261;
|
|
1685
|
+
for (let index = 0; index < normalizedKey.length; index += 1) {
|
|
1686
|
+
hash ^= normalizedKey.charCodeAt(index);
|
|
1687
|
+
hash = Math.imul(hash, 16777619);
|
|
1688
|
+
}
|
|
1689
|
+
return (hash >>> 0) / 4294967295;
|
|
1690
|
+
}
|
|
1691
|
+
function normalizeJitterRatio(value) {
|
|
1692
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
1693
|
+
return 0;
|
|
1694
|
+
}
|
|
1695
|
+
return Math.min(value, 1);
|
|
1696
|
+
}
|
|
1697
|
+
function buildDeterministicJitterOffsetMs(baseMs, ratio, key) {
|
|
1698
|
+
if (!Number.isFinite(baseMs) || baseMs <= 0) {
|
|
1699
|
+
return 0;
|
|
1700
|
+
}
|
|
1701
|
+
const normalizedRatio = normalizeJitterRatio(ratio);
|
|
1702
|
+
if (normalizedRatio <= 0) {
|
|
1703
|
+
return 0;
|
|
1704
|
+
}
|
|
1705
|
+
const maxOffsetMs = Math.round(baseMs * normalizedRatio);
|
|
1706
|
+
if (maxOffsetMs <= 0) {
|
|
1707
|
+
return 0;
|
|
1708
|
+
}
|
|
1709
|
+
return Math.round(hashKeyToUnitInterval(key) * maxOffsetMs);
|
|
1710
|
+
}
|
|
1711
|
+
function buildDeterministicJitteredDelayMs(baseMs, ratio, key) {
|
|
1712
|
+
return Math.max(
|
|
1713
|
+
0,
|
|
1714
|
+
Math.round(baseMs) + buildDeterministicJitterOffsetMs(baseMs, ratio, key)
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1459
1718
|
// src/registry/serviceManifestContract.ts
|
|
1460
1719
|
var AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT = "meta-service-registry-authority-service-manifest-report";
|
|
1461
1720
|
var AUTHORITY_SERVICE_MANIFEST_UPDATED_SIGNAL = "global.meta.cadenza_db.service_manifest_updated";
|
|
@@ -1487,11 +1746,17 @@ function normalizeServiceManifestSnapshot(input) {
|
|
|
1487
1746
|
intents: normalizeArray(record.intents),
|
|
1488
1747
|
actors: normalizeArray(record.actors),
|
|
1489
1748
|
routines: normalizeArray(record.routines),
|
|
1749
|
+
helpers: normalizeArray(record.helpers),
|
|
1750
|
+
globals: normalizeArray(record.globals),
|
|
1490
1751
|
directionalTaskMaps: normalizeArray(record.directionalTaskMaps),
|
|
1491
1752
|
signalToTaskMaps: normalizeArray(record.signalToTaskMaps),
|
|
1492
1753
|
intentToTaskMaps: normalizeArray(record.intentToTaskMaps),
|
|
1493
1754
|
actorTaskMaps: normalizeArray(record.actorTaskMaps),
|
|
1494
|
-
taskToRoutineMaps: normalizeArray(record.taskToRoutineMaps)
|
|
1755
|
+
taskToRoutineMaps: normalizeArray(record.taskToRoutineMaps),
|
|
1756
|
+
taskToHelperMaps: normalizeArray(record.taskToHelperMaps),
|
|
1757
|
+
helperToHelperMaps: normalizeArray(record.helperToHelperMaps),
|
|
1758
|
+
taskToGlobalMaps: normalizeArray(record.taskToGlobalMaps),
|
|
1759
|
+
helperToGlobalMaps: normalizeArray(record.helperToGlobalMaps)
|
|
1495
1760
|
};
|
|
1496
1761
|
}
|
|
1497
1762
|
function selectLatestServiceManifestSnapshots(snapshots) {
|
|
@@ -1755,6 +2020,27 @@ function buildRoutineDefinition(routine, serviceName) {
|
|
|
1755
2020
|
is_meta: routine.isMeta === true
|
|
1756
2021
|
};
|
|
1757
2022
|
}
|
|
2023
|
+
function buildHelperDefinition(helper, serviceName) {
|
|
2024
|
+
return {
|
|
2025
|
+
name: helper.name,
|
|
2026
|
+
version: helper.version,
|
|
2027
|
+
description: helper.description,
|
|
2028
|
+
service_name: serviceName,
|
|
2029
|
+
is_meta: helper.isMeta === true,
|
|
2030
|
+
handler_source: helper.helperFunction.toString(),
|
|
2031
|
+
language: "js"
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
function buildGlobalDefinition(globalDefinition, serviceName) {
|
|
2035
|
+
return {
|
|
2036
|
+
name: globalDefinition.name,
|
|
2037
|
+
version: globalDefinition.version,
|
|
2038
|
+
description: globalDefinition.description,
|
|
2039
|
+
service_name: serviceName,
|
|
2040
|
+
is_meta: globalDefinition.isMeta === true,
|
|
2041
|
+
value: sanitizeManifestValue(globalDefinition.value)
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
1758
2044
|
function shouldExportTask(task) {
|
|
1759
2045
|
return task.register !== false && task.isHidden !== true && !task.isDeputy && !task.isEphemeral;
|
|
1760
2046
|
}
|
|
@@ -1770,6 +2056,12 @@ function buildActorKey(actor) {
|
|
|
1770
2056
|
function buildRoutineKey(routine) {
|
|
1771
2057
|
return `${routine.service_name}|${routine.name}|${routine.version}`;
|
|
1772
2058
|
}
|
|
2059
|
+
function buildHelperKey(helper) {
|
|
2060
|
+
return `${helper.service_name}|${helper.name}|${helper.version}`;
|
|
2061
|
+
}
|
|
2062
|
+
function buildGlobalKey(globalDefinition) {
|
|
2063
|
+
return `${globalDefinition.service_name}|${globalDefinition.name}|${globalDefinition.version}`;
|
|
2064
|
+
}
|
|
1773
2065
|
function listManifestTasks() {
|
|
1774
2066
|
const registryTasks = Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
1775
2067
|
(task) => Boolean(task)
|
|
@@ -1783,6 +2075,18 @@ function listManifestTasks() {
|
|
|
1783
2075
|
).values()
|
|
1784
2076
|
);
|
|
1785
2077
|
}
|
|
2078
|
+
function listManifestHelpers() {
|
|
2079
|
+
const toolRuntime = CadenzaService;
|
|
2080
|
+
return (toolRuntime.getAllHelpers?.() ?? []).filter(
|
|
2081
|
+
(helper) => Boolean(helper && !helper.destroyed)
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
function listManifestGlobals() {
|
|
2085
|
+
const toolRuntime = CadenzaService;
|
|
2086
|
+
return (toolRuntime.getAllGlobals?.() ?? []).filter(
|
|
2087
|
+
(globalDefinition) => Boolean(globalDefinition && !globalDefinition.destroyed)
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
1786
2090
|
function isRoutingCriticalMetaSignal(_signal) {
|
|
1787
2091
|
return false;
|
|
1788
2092
|
}
|
|
@@ -1798,6 +2102,8 @@ function buildServiceManifestSnapshot(params) {
|
|
|
1798
2102
|
publicationLayer = "business_structural"
|
|
1799
2103
|
} = params;
|
|
1800
2104
|
const tasks = listManifestTasks().filter(shouldExportTask);
|
|
2105
|
+
const helpers = listManifestHelpers();
|
|
2106
|
+
const globals = listManifestGlobals();
|
|
1801
2107
|
const routines = Array.from(CadenzaService.registry.routines.values()).filter((routine) => Boolean(routine)).filter(shouldExportRoutine);
|
|
1802
2108
|
const actors = CadenzaService.getAllActors();
|
|
1803
2109
|
const taskDefinitions = tasks.map((task) => buildTaskDefinition(task, serviceName)).sort(
|
|
@@ -1809,6 +2115,10 @@ function buildServiceManifestSnapshot(params) {
|
|
|
1809
2115
|
const directionalTaskMaps = /* @__PURE__ */ new Map();
|
|
1810
2116
|
const actorTaskMaps = /* @__PURE__ */ new Map();
|
|
1811
2117
|
const taskToRoutineMaps = /* @__PURE__ */ new Map();
|
|
2118
|
+
const helperTaskMaps = /* @__PURE__ */ new Map();
|
|
2119
|
+
const helperHelperMaps = /* @__PURE__ */ new Map();
|
|
2120
|
+
const taskGlobalMaps = /* @__PURE__ */ new Map();
|
|
2121
|
+
const helperGlobalMaps = /* @__PURE__ */ new Map();
|
|
1812
2122
|
const registerSignal = (signalName) => {
|
|
1813
2123
|
const normalizedSignalName = canonicalizeSignalName(signalName);
|
|
1814
2124
|
if (!normalizedSignalName || signalDefinitions.has(normalizedSignalName)) {
|
|
@@ -1892,6 +2202,37 @@ function buildServiceManifestSnapshot(params) {
|
|
|
1892
2202
|
is_meta: actorTaskMetadata.actorKind === "meta" || task.isMeta === true
|
|
1893
2203
|
});
|
|
1894
2204
|
}
|
|
2205
|
+
const taskTools = task;
|
|
2206
|
+
for (const [alias, helperName] of taskTools.helperAliases?.entries?.() ?? []) {
|
|
2207
|
+
const helper = CadenzaService.getHelper?.(helperName);
|
|
2208
|
+
if (!helper) {
|
|
2209
|
+
continue;
|
|
2210
|
+
}
|
|
2211
|
+
const key = `${task.name}|${task.version}|${alias}|${helper.name}|${helper.version}|${serviceName}`;
|
|
2212
|
+
helperTaskMaps.set(key, {
|
|
2213
|
+
task_name: task.name,
|
|
2214
|
+
task_version: task.version,
|
|
2215
|
+
service_name: serviceName,
|
|
2216
|
+
alias,
|
|
2217
|
+
helper_name: helper.name,
|
|
2218
|
+
helper_version: helper.version
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
for (const [alias, globalName] of taskTools.globalAliases?.entries?.() ?? []) {
|
|
2222
|
+
const globalDefinition = CadenzaService.getGlobal?.(globalName);
|
|
2223
|
+
if (!globalDefinition) {
|
|
2224
|
+
continue;
|
|
2225
|
+
}
|
|
2226
|
+
const key = `${task.name}|${task.version}|${alias}|${globalDefinition.name}|${globalDefinition.version}|${serviceName}`;
|
|
2227
|
+
taskGlobalMaps.set(key, {
|
|
2228
|
+
task_name: task.name,
|
|
2229
|
+
task_version: task.version,
|
|
2230
|
+
service_name: serviceName,
|
|
2231
|
+
alias,
|
|
2232
|
+
global_name: globalDefinition.name,
|
|
2233
|
+
global_version: globalDefinition.version
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
1895
2236
|
}
|
|
1896
2237
|
const intentDefinitions = Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => {
|
|
1897
2238
|
const intentRecord = intent;
|
|
@@ -1923,6 +2264,44 @@ function buildServiceManifestSnapshot(params) {
|
|
|
1923
2264
|
).sort(
|
|
1924
2265
|
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
1925
2266
|
);
|
|
2267
|
+
const helperDefinitions = helpers.map((helper) => buildHelperDefinition(helper, serviceName)).sort(
|
|
2268
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2269
|
+
);
|
|
2270
|
+
const globalDefinitions = globals.map((globalDefinition) => buildGlobalDefinition(globalDefinition, serviceName)).sort(
|
|
2271
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2272
|
+
);
|
|
2273
|
+
for (const helper of helpers) {
|
|
2274
|
+
for (const [alias, dependencyHelperName] of helper.helperAliases.entries()) {
|
|
2275
|
+
const dependencyHelper = CadenzaService.getHelper?.(dependencyHelperName);
|
|
2276
|
+
if (!dependencyHelper) {
|
|
2277
|
+
continue;
|
|
2278
|
+
}
|
|
2279
|
+
const key = `${helper.name}|${helper.version}|${alias}|${dependencyHelper.name}|${dependencyHelper.version}|${serviceName}`;
|
|
2280
|
+
helperHelperMaps.set(key, {
|
|
2281
|
+
helper_name: helper.name,
|
|
2282
|
+
helper_version: helper.version,
|
|
2283
|
+
service_name: serviceName,
|
|
2284
|
+
alias,
|
|
2285
|
+
dependency_helper_name: dependencyHelper.name,
|
|
2286
|
+
dependency_helper_version: dependencyHelper.version
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
for (const [alias, globalName] of helper.globalAliases.entries()) {
|
|
2290
|
+
const globalDefinition = CadenzaService.getGlobal?.(globalName);
|
|
2291
|
+
if (!globalDefinition) {
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
const key = `${helper.name}|${helper.version}|${alias}|${globalDefinition.name}|${globalDefinition.version}|${serviceName}`;
|
|
2295
|
+
helperGlobalMaps.set(key, {
|
|
2296
|
+
helper_name: helper.name,
|
|
2297
|
+
helper_version: helper.version,
|
|
2298
|
+
service_name: serviceName,
|
|
2299
|
+
alias,
|
|
2300
|
+
global_name: globalDefinition.name,
|
|
2301
|
+
global_version: globalDefinition.version
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
1926
2305
|
for (const routine of routines) {
|
|
1927
2306
|
for (const task of routine.tasks) {
|
|
1928
2307
|
if (!task) {
|
|
@@ -1960,6 +2339,15 @@ function buildServiceManifestSnapshot(params) {
|
|
|
1960
2339
|
const routineDefinitionsByKey = new Map(
|
|
1961
2340
|
routineDefinitions.map((routine) => [buildRoutineKey(routine), routine])
|
|
1962
2341
|
);
|
|
2342
|
+
const helperDefinitionsByKey = new Map(
|
|
2343
|
+
helperDefinitions.map((helper) => [buildHelperKey(helper), helper])
|
|
2344
|
+
);
|
|
2345
|
+
const globalDefinitionsByKey = new Map(
|
|
2346
|
+
globalDefinitions.map((globalDefinition) => [
|
|
2347
|
+
buildGlobalKey(globalDefinition),
|
|
2348
|
+
globalDefinition
|
|
2349
|
+
])
|
|
2350
|
+
);
|
|
1963
2351
|
const routingTaskKeys = /* @__PURE__ */ new Set();
|
|
1964
2352
|
const routingSignalNames = /* @__PURE__ */ new Set();
|
|
1965
2353
|
const routingIntentNames = /* @__PURE__ */ new Set();
|
|
@@ -2277,6 +2665,112 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2277
2665
|
).sort(
|
|
2278
2666
|
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2279
2667
|
);
|
|
2668
|
+
const businessHelpers = helperDefinitions.filter((helper) => helper.is_meta !== true).sort(
|
|
2669
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2670
|
+
);
|
|
2671
|
+
const localMetaHelpers = helperDefinitions.filter((helper) => helper.is_meta === true).sort(
|
|
2672
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2673
|
+
);
|
|
2674
|
+
const businessGlobals = globalDefinitions.filter((globalDefinition) => globalDefinition.is_meta !== true).sort(
|
|
2675
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2676
|
+
);
|
|
2677
|
+
const localMetaGlobals = globalDefinitions.filter((globalDefinition) => globalDefinition.is_meta === true).sort(
|
|
2678
|
+
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2679
|
+
);
|
|
2680
|
+
const businessTaskToHelperMaps = Array.from(helperTaskMaps.values()).filter((map) => {
|
|
2681
|
+
const task = taskDefinitionsByKey.get(
|
|
2682
|
+
buildTaskKey({
|
|
2683
|
+
service_name: map.service_name,
|
|
2684
|
+
name: map.task_name,
|
|
2685
|
+
version: map.task_version
|
|
2686
|
+
})
|
|
2687
|
+
);
|
|
2688
|
+
const helper = helperDefinitionsByKey.get(
|
|
2689
|
+
buildHelperKey({
|
|
2690
|
+
service_name: map.service_name,
|
|
2691
|
+
name: map.helper_name,
|
|
2692
|
+
version: map.helper_version
|
|
2693
|
+
})
|
|
2694
|
+
);
|
|
2695
|
+
return task?.is_meta !== true && task?.is_sub_meta !== true && helper?.is_meta !== true;
|
|
2696
|
+
}).sort(
|
|
2697
|
+
(left, right) => `${left.task_name}:${left.alias}`.localeCompare(`${right.task_name}:${right.alias}`)
|
|
2698
|
+
);
|
|
2699
|
+
const localMetaTaskToHelperMaps = Array.from(helperTaskMaps.values()).filter((map) => !businessTaskToHelperMaps.includes(map)).sort(
|
|
2700
|
+
(left, right) => `${left.task_name}:${left.alias}`.localeCompare(`${right.task_name}:${right.alias}`)
|
|
2701
|
+
);
|
|
2702
|
+
const businessHelperToHelperMaps = Array.from(helperHelperMaps.values()).filter((map) => {
|
|
2703
|
+
const helper = helperDefinitionsByKey.get(
|
|
2704
|
+
buildHelperKey({
|
|
2705
|
+
service_name: map.service_name,
|
|
2706
|
+
name: map.helper_name,
|
|
2707
|
+
version: map.helper_version
|
|
2708
|
+
})
|
|
2709
|
+
);
|
|
2710
|
+
const dependencyHelper = helperDefinitionsByKey.get(
|
|
2711
|
+
buildHelperKey({
|
|
2712
|
+
service_name: map.service_name,
|
|
2713
|
+
name: map.dependency_helper_name,
|
|
2714
|
+
version: map.dependency_helper_version
|
|
2715
|
+
})
|
|
2716
|
+
);
|
|
2717
|
+
return helper?.is_meta !== true && dependencyHelper?.is_meta !== true;
|
|
2718
|
+
}).sort(
|
|
2719
|
+
(left, right) => `${left.helper_name}:${left.alias}`.localeCompare(`${right.helper_name}:${right.alias}`)
|
|
2720
|
+
);
|
|
2721
|
+
const localMetaHelperToHelperMaps = Array.from(helperHelperMaps.values()).filter((map) => !businessHelperToHelperMaps.includes(map)).sort(
|
|
2722
|
+
(left, right) => `${left.helper_name}:${left.alias}`.localeCompare(`${right.helper_name}:${right.alias}`)
|
|
2723
|
+
);
|
|
2724
|
+
const businessTaskToGlobalMaps = Array.from(taskGlobalMaps.values()).filter((map) => {
|
|
2725
|
+
const task = taskDefinitionsByKey.get(
|
|
2726
|
+
buildTaskKey({
|
|
2727
|
+
service_name: map.service_name,
|
|
2728
|
+
name: map.task_name,
|
|
2729
|
+
version: map.task_version
|
|
2730
|
+
})
|
|
2731
|
+
);
|
|
2732
|
+
const globalDefinition = globalDefinitionsByKey.get(
|
|
2733
|
+
buildGlobalKey({
|
|
2734
|
+
service_name: map.service_name,
|
|
2735
|
+
name: map.global_name,
|
|
2736
|
+
version: map.global_version
|
|
2737
|
+
})
|
|
2738
|
+
);
|
|
2739
|
+
return task?.is_meta !== true && task?.is_sub_meta !== true && globalDefinition?.is_meta !== true;
|
|
2740
|
+
}).sort(
|
|
2741
|
+
(left, right) => `${left.task_name}:${left.alias}`.localeCompare(`${right.task_name}:${right.alias}`)
|
|
2742
|
+
);
|
|
2743
|
+
const localMetaTaskToGlobalMaps = Array.from(taskGlobalMaps.values()).filter((map) => !businessTaskToGlobalMaps.includes(map)).sort(
|
|
2744
|
+
(left, right) => `${left.task_name}:${left.alias}`.localeCompare(`${right.task_name}:${right.alias}`)
|
|
2745
|
+
);
|
|
2746
|
+
const businessHelperToGlobalMaps = Array.from(helperGlobalMaps.values()).filter((map) => {
|
|
2747
|
+
const helper = helperDefinitionsByKey.get(
|
|
2748
|
+
buildHelperKey({
|
|
2749
|
+
service_name: map.service_name,
|
|
2750
|
+
name: map.helper_name,
|
|
2751
|
+
version: map.helper_version
|
|
2752
|
+
})
|
|
2753
|
+
);
|
|
2754
|
+
const globalDefinition = globalDefinitionsByKey.get(
|
|
2755
|
+
buildGlobalKey({
|
|
2756
|
+
service_name: map.service_name,
|
|
2757
|
+
name: map.global_name,
|
|
2758
|
+
version: map.global_version
|
|
2759
|
+
})
|
|
2760
|
+
);
|
|
2761
|
+
return helper?.is_meta !== true && globalDefinition?.is_meta !== true;
|
|
2762
|
+
}).sort(
|
|
2763
|
+
(left, right) => `${left.helper_name}:${left.alias}`.localeCompare(`${right.helper_name}:${right.alias}`)
|
|
2764
|
+
);
|
|
2765
|
+
const localMetaHelperToGlobalMaps = Array.from(helperGlobalMaps.values()).filter((map) => !businessHelperToGlobalMaps.includes(map)).sort(
|
|
2766
|
+
(left, right) => `${left.helper_name}:${left.alias}`.localeCompare(`${right.helper_name}:${right.alias}`)
|
|
2767
|
+
);
|
|
2768
|
+
const cumulativeHelpers = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessHelpers : [...businessHelpers, ...localMetaHelpers];
|
|
2769
|
+
const cumulativeGlobals = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessGlobals : [...businessGlobals, ...localMetaGlobals];
|
|
2770
|
+
const cumulativeTaskToHelperMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessTaskToHelperMaps : [...businessTaskToHelperMaps, ...localMetaTaskToHelperMaps];
|
|
2771
|
+
const cumulativeHelperToHelperMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessHelperToHelperMaps : [...businessHelperToHelperMaps, ...localMetaHelperToHelperMaps];
|
|
2772
|
+
const cumulativeTaskToGlobalMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessTaskToGlobalMaps : [...businessTaskToGlobalMaps, ...localMetaTaskToGlobalMaps];
|
|
2773
|
+
const cumulativeHelperToGlobalMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessHelperToGlobalMaps : [...businessHelperToGlobalMaps, ...localMetaHelperToGlobalMaps];
|
|
2280
2774
|
const cumulativeDirectionalTaskMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessDirectionalTaskMaps : Array.from(
|
|
2281
2775
|
new Map(
|
|
2282
2776
|
[...businessDirectionalTaskMaps, ...localMetaDirectionalTaskMaps].map(
|
|
@@ -2319,11 +2813,17 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2319
2813
|
intents: cumulativeIntents,
|
|
2320
2814
|
actors: cumulativeActors,
|
|
2321
2815
|
routines: cumulativeRoutines,
|
|
2816
|
+
helpers: cumulativeHelpers,
|
|
2817
|
+
globals: cumulativeGlobals,
|
|
2322
2818
|
directionalTaskMaps: cumulativeDirectionalTaskMaps,
|
|
2323
2819
|
signalToTaskMaps: publicationLayer === "routing_capability" ? publishedSignalTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps] : [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps],
|
|
2324
2820
|
intentToTaskMaps: publicationLayer === "routing_capability" ? publishedIntentTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps] : [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps],
|
|
2325
2821
|
actorTaskMaps: cumulativeActorTaskMaps,
|
|
2326
|
-
taskToRoutineMaps: cumulativeTaskToRoutineMaps
|
|
2822
|
+
taskToRoutineMaps: cumulativeTaskToRoutineMaps,
|
|
2823
|
+
taskToHelperMaps: cumulativeTaskToHelperMaps,
|
|
2824
|
+
helperToHelperMaps: cumulativeHelperToHelperMaps,
|
|
2825
|
+
taskToGlobalMaps: cumulativeTaskToGlobalMaps,
|
|
2826
|
+
helperToGlobalMaps: cumulativeHelperToGlobalMaps
|
|
2327
2827
|
};
|
|
2328
2828
|
return {
|
|
2329
2829
|
...manifestBody,
|
|
@@ -2367,6 +2867,20 @@ function explodeServiceManifestSnapshots(snapshots) {
|
|
|
2367
2867
|
`${right.service_name}|${right.name}|${right.version}`
|
|
2368
2868
|
)
|
|
2369
2869
|
);
|
|
2870
|
+
const helpers = dedupe(
|
|
2871
|
+
snapshots.flatMap((snapshot) => snapshot.helpers),
|
|
2872
|
+
(helper) => `${helper.service_name}|${helper.name}|${helper.version}`,
|
|
2873
|
+
(left, right) => `${left.service_name}|${left.name}|${left.version}`.localeCompare(
|
|
2874
|
+
`${right.service_name}|${right.name}|${right.version}`
|
|
2875
|
+
)
|
|
2876
|
+
);
|
|
2877
|
+
const globals = dedupe(
|
|
2878
|
+
snapshots.flatMap((snapshot) => snapshot.globals),
|
|
2879
|
+
(globalDefinition) => `${globalDefinition.service_name}|${globalDefinition.name}|${globalDefinition.version}`,
|
|
2880
|
+
(left, right) => `${left.service_name}|${left.name}|${left.version}`.localeCompare(
|
|
2881
|
+
`${right.service_name}|${right.name}|${right.version}`
|
|
2882
|
+
)
|
|
2883
|
+
);
|
|
2370
2884
|
const directionalTaskMaps = dedupe(
|
|
2371
2885
|
snapshots.flatMap((snapshot) => snapshot.directionalTaskMaps),
|
|
2372
2886
|
(map) => `${map.predecessor_service_name}|${map.predecessor_task_name}|${map.predecessor_task_version}|${map.service_name}|${map.task_name}|${map.task_version}`,
|
|
@@ -2402,17 +2916,51 @@ function explodeServiceManifestSnapshots(snapshots) {
|
|
|
2402
2916
|
`${right.routine_name}|${right.routine_version}|${right.service_name}|${right.task_name}|${right.task_version}`
|
|
2403
2917
|
)
|
|
2404
2918
|
);
|
|
2919
|
+
const taskToHelperMaps = dedupe(
|
|
2920
|
+
snapshots.flatMap((snapshot) => snapshot.taskToHelperMaps),
|
|
2921
|
+
(map) => `${map.service_name}|${map.task_name}|${map.task_version}|${map.alias}|${map.helper_name}|${map.helper_version}`,
|
|
2922
|
+
(left, right) => `${left.service_name}|${left.task_name}|${left.alias}|${left.helper_name}`.localeCompare(
|
|
2923
|
+
`${right.service_name}|${right.task_name}|${right.alias}|${right.helper_name}`
|
|
2924
|
+
)
|
|
2925
|
+
);
|
|
2926
|
+
const helperToHelperMaps = dedupe(
|
|
2927
|
+
snapshots.flatMap((snapshot) => snapshot.helperToHelperMaps),
|
|
2928
|
+
(map) => `${map.service_name}|${map.helper_name}|${map.helper_version}|${map.alias}|${map.dependency_helper_name}|${map.dependency_helper_version}`,
|
|
2929
|
+
(left, right) => `${left.service_name}|${left.helper_name}|${left.alias}|${left.dependency_helper_name}`.localeCompare(
|
|
2930
|
+
`${right.service_name}|${right.helper_name}|${right.alias}|${right.dependency_helper_name}`
|
|
2931
|
+
)
|
|
2932
|
+
);
|
|
2933
|
+
const taskToGlobalMaps = dedupe(
|
|
2934
|
+
snapshots.flatMap((snapshot) => snapshot.taskToGlobalMaps),
|
|
2935
|
+
(map) => `${map.service_name}|${map.task_name}|${map.task_version}|${map.alias}|${map.global_name}|${map.global_version}`,
|
|
2936
|
+
(left, right) => `${left.service_name}|${left.task_name}|${left.alias}|${left.global_name}`.localeCompare(
|
|
2937
|
+
`${right.service_name}|${right.task_name}|${right.alias}|${right.global_name}`
|
|
2938
|
+
)
|
|
2939
|
+
);
|
|
2940
|
+
const helperToGlobalMaps = dedupe(
|
|
2941
|
+
snapshots.flatMap((snapshot) => snapshot.helperToGlobalMaps),
|
|
2942
|
+
(map) => `${map.service_name}|${map.helper_name}|${map.helper_version}|${map.alias}|${map.global_name}|${map.global_version}`,
|
|
2943
|
+
(left, right) => `${left.service_name}|${left.helper_name}|${left.alias}|${left.global_name}`.localeCompare(
|
|
2944
|
+
`${right.service_name}|${right.helper_name}|${right.alias}|${right.global_name}`
|
|
2945
|
+
)
|
|
2946
|
+
);
|
|
2405
2947
|
return {
|
|
2406
2948
|
tasks,
|
|
2407
2949
|
signals,
|
|
2408
2950
|
intents,
|
|
2409
2951
|
actors,
|
|
2410
2952
|
routines,
|
|
2953
|
+
helpers,
|
|
2954
|
+
globals,
|
|
2411
2955
|
directionalTaskMaps,
|
|
2412
2956
|
signalToTaskMaps,
|
|
2413
2957
|
intentToTaskMaps,
|
|
2414
2958
|
actorTaskMaps,
|
|
2415
|
-
taskToRoutineMaps
|
|
2959
|
+
taskToRoutineMaps,
|
|
2960
|
+
taskToHelperMaps,
|
|
2961
|
+
helperToHelperMaps,
|
|
2962
|
+
taskToGlobalMaps,
|
|
2963
|
+
helperToGlobalMaps
|
|
2416
2964
|
};
|
|
2417
2965
|
}
|
|
2418
2966
|
|
|
@@ -2461,6 +3009,52 @@ var SERVICE_REGISTRY_TRACE_SERVICE2 = (process.env.CADENZA_SERVICE_REGISTRY_TRAC
|
|
|
2461
3009
|
function shouldTraceServiceRegistry(serviceName) {
|
|
2462
3010
|
return SERVICE_REGISTRY_TRACE_SERVICE2.length > 0 && serviceName === SERVICE_REGISTRY_TRACE_SERVICE2;
|
|
2463
3011
|
}
|
|
3012
|
+
function normalizeLeaseStatus(value) {
|
|
3013
|
+
const status = String(value ?? "").trim();
|
|
3014
|
+
if (status === "active" || status === "non_responsive" || status === "inactive" || status === "deleted") {
|
|
3015
|
+
return status;
|
|
3016
|
+
}
|
|
3017
|
+
return null;
|
|
3018
|
+
}
|
|
3019
|
+
function overlayServiceInstancesWithLeases(serviceInstances, serviceInstanceLeases) {
|
|
3020
|
+
if (serviceInstanceLeases.length === 0) {
|
|
3021
|
+
return serviceInstances;
|
|
3022
|
+
}
|
|
3023
|
+
const leasesByInstanceId = /* @__PURE__ */ new Map();
|
|
3024
|
+
for (const row of serviceInstanceLeases) {
|
|
3025
|
+
const serviceInstanceId = String(
|
|
3026
|
+
row.service_instance_id ?? row.serviceInstanceId ?? ""
|
|
3027
|
+
).trim();
|
|
3028
|
+
if (!serviceInstanceId) {
|
|
3029
|
+
continue;
|
|
3030
|
+
}
|
|
3031
|
+
leasesByInstanceId.set(serviceInstanceId, row);
|
|
3032
|
+
}
|
|
3033
|
+
return serviceInstances.map((row) => {
|
|
3034
|
+
const serviceInstanceId = String(row.uuid ?? "").trim();
|
|
3035
|
+
const lease = serviceInstanceId ? leasesByInstanceId.get(serviceInstanceId) : void 0;
|
|
3036
|
+
if (!lease) {
|
|
3037
|
+
return row;
|
|
3038
|
+
}
|
|
3039
|
+
const leaseStatus = normalizeLeaseStatus(
|
|
3040
|
+
lease.status ?? lease.lease_status ?? lease.leaseStatus
|
|
3041
|
+
);
|
|
3042
|
+
return {
|
|
3043
|
+
...row,
|
|
3044
|
+
lease_status: leaseStatus ?? void 0,
|
|
3045
|
+
is_ready: typeof lease.is_ready === "boolean" ? lease.is_ready : typeof lease.isReady === "boolean" ? lease.isReady : void 0,
|
|
3046
|
+
readiness_reason: typeof lease.readiness_reason === "string" ? lease.readiness_reason : typeof lease.readinessReason === "string" ? lease.readinessReason : null,
|
|
3047
|
+
lease_expires_at: typeof lease.lease_expires_at === "string" ? lease.lease_expires_at : typeof lease.leaseExpiresAt === "string" ? lease.leaseExpiresAt : null,
|
|
3048
|
+
last_lease_renewed_at: typeof lease.last_lease_renewed_at === "string" ? lease.last_lease_renewed_at : typeof lease.lastLeaseRenewedAt === "string" ? lease.lastLeaseRenewedAt : null,
|
|
3049
|
+
last_ready_at: typeof lease.last_ready_at === "string" ? lease.last_ready_at : typeof lease.lastReadyAt === "string" ? lease.lastReadyAt : null,
|
|
3050
|
+
last_observed_transport_at: typeof lease.last_observed_transport_at === "string" ? lease.last_observed_transport_at : typeof lease.lastObservedTransportAt === "string" ? lease.lastObservedTransportAt : null,
|
|
3051
|
+
shutdown_requested_at: typeof lease.shutdown_requested_at === "string" ? lease.shutdown_requested_at : typeof lease.shutdownRequestedAt === "string" ? lease.shutdownRequestedAt : null,
|
|
3052
|
+
is_active: leaseStatus === "active" ? true : leaseStatus === "non_responsive" || leaseStatus === "inactive" || leaseStatus === "deleted" ? false : row.is_active,
|
|
3053
|
+
is_non_responsive: leaseStatus === "non_responsive" ? true : leaseStatus === "active" || leaseStatus === "inactive" || leaseStatus === "deleted" ? false : row.is_non_responsive,
|
|
3054
|
+
deleted: leaseStatus === "deleted" ? true : Boolean(row.deleted ?? false)
|
|
3055
|
+
};
|
|
3056
|
+
});
|
|
3057
|
+
}
|
|
2464
3058
|
function buildServiceRegistryInsertQueryData(tableName, ctx, queryData) {
|
|
2465
3059
|
const joinedContexts = Array.isArray(ctx.joinedContexts) ? ctx.joinedContexts : [];
|
|
2466
3060
|
const getJoinedValue = (key) => {
|
|
@@ -2538,6 +3132,43 @@ function sanitizeAuthorityBootstrapDelegationContext(ctx) {
|
|
|
2538
3132
|
}
|
|
2539
3133
|
return sanitized;
|
|
2540
3134
|
}
|
|
3135
|
+
var BOOTSTRAP_DB_OPERATION_CONTEXT_KEYS = [
|
|
3136
|
+
"data",
|
|
3137
|
+
"batch",
|
|
3138
|
+
"transaction",
|
|
3139
|
+
"onConflict",
|
|
3140
|
+
"filter",
|
|
3141
|
+
"fields",
|
|
3142
|
+
"joins",
|
|
3143
|
+
"sort",
|
|
3144
|
+
"limit",
|
|
3145
|
+
"offset",
|
|
3146
|
+
"queryMode",
|
|
3147
|
+
"aggregates",
|
|
3148
|
+
"groupBy"
|
|
3149
|
+
];
|
|
3150
|
+
function isBootstrapDbOperationRoutineName(value) {
|
|
3151
|
+
return /^(Insert|Update|Query|Delete)\s+/.test(String(value ?? "").trim());
|
|
3152
|
+
}
|
|
3153
|
+
function compactAuthorityBootstrapRequestBody(ctx) {
|
|
3154
|
+
if (!isBootstrapDbOperationRoutineName(ctx.__remoteRoutineName)) {
|
|
3155
|
+
return ctx;
|
|
3156
|
+
}
|
|
3157
|
+
const queryData = ctx.queryData && typeof ctx.queryData === "object" ? { ...ctx.queryData } : null;
|
|
3158
|
+
if (!queryData) {
|
|
3159
|
+
return ctx;
|
|
3160
|
+
}
|
|
3161
|
+
const compacted = {
|
|
3162
|
+
...ctx,
|
|
3163
|
+
queryData
|
|
3164
|
+
};
|
|
3165
|
+
for (const key of BOOTSTRAP_DB_OPERATION_CONTEXT_KEYS) {
|
|
3166
|
+
if (Object.prototype.hasOwnProperty.call(queryData, key)) {
|
|
3167
|
+
delete compacted[key];
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
return compacted;
|
|
3171
|
+
}
|
|
2541
3172
|
function cloneServiceRegistryContextValue(value) {
|
|
2542
3173
|
if (value instanceof Date) {
|
|
2543
3174
|
return new Date(value.getTime());
|
|
@@ -2894,6 +3525,92 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
2894
3525
|
`Resolve service registry insert for ${tableName}`,
|
|
2895
3526
|
(ctx, emit2) => new Promise((resolve) => {
|
|
2896
3527
|
const resolverRequestId = uuid3();
|
|
3528
|
+
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
3529
|
+
const bootstrapAuthorityInsertSpec = !localInsertTask && CadenzaService.serviceRegistry.connectsToCadenzaDB ? getAuthorityBootstrapInsertIntentSpecForTable(tableName) : null;
|
|
3530
|
+
const resolvedTargetServiceName = resolveServiceNameFromContext(ctx);
|
|
3531
|
+
const selfBootstrapRetrySignal = CadenzaService.serviceRegistry.serviceName === "CadenzaDB" && resolvedTargetServiceName === "CadenzaDB" && !localInsertTask ? getSelfBootstrapRegistrationRetrySignal(tableName) : null;
|
|
3532
|
+
if (selfBootstrapRetrySignal) {
|
|
3533
|
+
CadenzaService.schedule(
|
|
3534
|
+
selfBootstrapRetrySignal,
|
|
3535
|
+
{
|
|
3536
|
+
...ctx
|
|
3537
|
+
},
|
|
3538
|
+
250
|
|
3539
|
+
);
|
|
3540
|
+
resolve(false);
|
|
3541
|
+
return;
|
|
3542
|
+
}
|
|
3543
|
+
if (bootstrapAuthorityInsertSpec) {
|
|
3544
|
+
const sanitizedContext = sanitizeServiceRegistryInsertExecutionContext(ctx);
|
|
3545
|
+
const nextQueryData = buildServiceRegistryInsertQueryData(
|
|
3546
|
+
tableName,
|
|
3547
|
+
sanitizedContext,
|
|
3548
|
+
queryData
|
|
3549
|
+
);
|
|
3550
|
+
const inquiryContext = ensureDelegationContextMetadata({
|
|
3551
|
+
...sanitizedContext,
|
|
3552
|
+
data: nextQueryData.data !== void 0 ? nextQueryData.data : sanitizedContext.data,
|
|
3553
|
+
batch: nextQueryData.batch !== void 0 ? nextQueryData.batch : sanitizedContext.batch,
|
|
3554
|
+
onConflict: Object.prototype.hasOwnProperty.call(nextQueryData, "onConflict") ? nextQueryData.onConflict : void 0,
|
|
3555
|
+
transaction: nextQueryData.transaction !== void 0 ? nextQueryData.transaction : sanitizedContext.transaction,
|
|
3556
|
+
queryData: nextQueryData
|
|
3557
|
+
});
|
|
3558
|
+
inquiryContext.__metadata = {
|
|
3559
|
+
...inquiryContext.__metadata ?? {},
|
|
3560
|
+
__skipRemoteExecution: inquiryContext.__metadata?.__skipRemoteExecution ?? inquiryContext.__skipRemoteExecution ?? false,
|
|
3561
|
+
__blockRemoteExecution: inquiryContext.__metadata?.__blockRemoteExecution ?? inquiryContext.__blockRemoteExecution ?? false
|
|
3562
|
+
};
|
|
3563
|
+
CadenzaService.serviceRegistry.ensureBootstrapAuthorityControlPlaneForInquiry(
|
|
3564
|
+
bootstrapAuthorityInsertSpec.intentName,
|
|
3565
|
+
inquiryContext
|
|
3566
|
+
);
|
|
3567
|
+
void CadenzaService.inquire(
|
|
3568
|
+
bootstrapAuthorityInsertSpec.intentName,
|
|
3569
|
+
inquiryContext,
|
|
3570
|
+
{
|
|
3571
|
+
requireComplete: true,
|
|
3572
|
+
timeout: bootstrapAuthorityInsertSpec.defaultTimeoutMs
|
|
3573
|
+
}
|
|
3574
|
+
).then(
|
|
3575
|
+
(result) => resolve(
|
|
3576
|
+
resolveBootstrapAuthorityInsertResult(
|
|
3577
|
+
tableName,
|
|
3578
|
+
sanitizedContext,
|
|
3579
|
+
nextQueryData,
|
|
3580
|
+
result,
|
|
3581
|
+
emit2
|
|
3582
|
+
)
|
|
3583
|
+
)
|
|
3584
|
+
).catch(
|
|
3585
|
+
(error) => resolve(
|
|
3586
|
+
resolveBootstrapAuthorityInsertResult(
|
|
3587
|
+
tableName,
|
|
3588
|
+
sanitizedContext,
|
|
3589
|
+
nextQueryData,
|
|
3590
|
+
error,
|
|
3591
|
+
emit2
|
|
3592
|
+
)
|
|
3593
|
+
)
|
|
3594
|
+
);
|
|
3595
|
+
return;
|
|
3596
|
+
}
|
|
3597
|
+
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
3598
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
3599
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
3600
|
+
tableName,
|
|
3601
|
+
executionSignal,
|
|
3602
|
+
hasLocalInsertTask: !!localInsertTask,
|
|
3603
|
+
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
3604
|
+
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
3605
|
+
hasData: !!ctx.data,
|
|
3606
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
3607
|
+
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
3608
|
+
});
|
|
3609
|
+
}
|
|
3610
|
+
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
3611
|
+
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
3612
|
+
wiredLocalTaskNames.add(localInsertTask.name);
|
|
3613
|
+
}
|
|
2897
3614
|
CadenzaService.createEphemeralMetaTask(
|
|
2898
3615
|
`Resolve service registry insert execution for ${tableName} (${resolverRequestId})`,
|
|
2899
3616
|
(resultCtx) => {
|
|
@@ -2993,95 +3710,11 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
2993
3710
|
},
|
|
2994
3711
|
`Resolves signal-driven ${tableName} service-registry insert execution.`,
|
|
2995
3712
|
{
|
|
2996
|
-
register: false
|
|
3713
|
+
register: false,
|
|
3714
|
+
once: false,
|
|
3715
|
+
destroyCondition: (result) => result !== false
|
|
2997
3716
|
}
|
|
2998
3717
|
).doOn(executionResolvedSignal, executionFailedSignal);
|
|
2999
|
-
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
3000
|
-
const bootstrapAuthorityInsertSpec = !localInsertTask && CadenzaService.serviceRegistry.connectsToCadenzaDB ? getAuthorityBootstrapInsertIntentSpecForTable(tableName) : null;
|
|
3001
|
-
const resolvedTargetServiceName = resolveServiceNameFromContext(ctx);
|
|
3002
|
-
const selfBootstrapRetrySignal = CadenzaService.serviceRegistry.serviceName === "CadenzaDB" && resolvedTargetServiceName === "CadenzaDB" && !localInsertTask ? getSelfBootstrapRegistrationRetrySignal(tableName) : null;
|
|
3003
|
-
if (selfBootstrapRetrySignal) {
|
|
3004
|
-
CadenzaService.schedule(
|
|
3005
|
-
selfBootstrapRetrySignal,
|
|
3006
|
-
{
|
|
3007
|
-
...ctx
|
|
3008
|
-
},
|
|
3009
|
-
250
|
|
3010
|
-
);
|
|
3011
|
-
resolve(false);
|
|
3012
|
-
return;
|
|
3013
|
-
}
|
|
3014
|
-
if (bootstrapAuthorityInsertSpec) {
|
|
3015
|
-
const sanitizedContext = sanitizeServiceRegistryInsertExecutionContext(ctx);
|
|
3016
|
-
const nextQueryData = buildServiceRegistryInsertQueryData(
|
|
3017
|
-
tableName,
|
|
3018
|
-
sanitizedContext,
|
|
3019
|
-
queryData
|
|
3020
|
-
);
|
|
3021
|
-
const inquiryContext = ensureDelegationContextMetadata({
|
|
3022
|
-
...sanitizedContext,
|
|
3023
|
-
data: nextQueryData.data !== void 0 ? nextQueryData.data : sanitizedContext.data,
|
|
3024
|
-
batch: nextQueryData.batch !== void 0 ? nextQueryData.batch : sanitizedContext.batch,
|
|
3025
|
-
onConflict: Object.prototype.hasOwnProperty.call(nextQueryData, "onConflict") ? nextQueryData.onConflict : void 0,
|
|
3026
|
-
transaction: nextQueryData.transaction !== void 0 ? nextQueryData.transaction : sanitizedContext.transaction,
|
|
3027
|
-
queryData: nextQueryData
|
|
3028
|
-
});
|
|
3029
|
-
inquiryContext.__metadata = {
|
|
3030
|
-
...inquiryContext.__metadata ?? {},
|
|
3031
|
-
__skipRemoteExecution: inquiryContext.__metadata?.__skipRemoteExecution ?? inquiryContext.__skipRemoteExecution ?? false,
|
|
3032
|
-
__blockRemoteExecution: inquiryContext.__metadata?.__blockRemoteExecution ?? inquiryContext.__blockRemoteExecution ?? false
|
|
3033
|
-
};
|
|
3034
|
-
CadenzaService.serviceRegistry.ensureBootstrapAuthorityControlPlaneForInquiry(
|
|
3035
|
-
bootstrapAuthorityInsertSpec.intentName,
|
|
3036
|
-
inquiryContext
|
|
3037
|
-
);
|
|
3038
|
-
void CadenzaService.inquire(
|
|
3039
|
-
bootstrapAuthorityInsertSpec.intentName,
|
|
3040
|
-
inquiryContext,
|
|
3041
|
-
{
|
|
3042
|
-
requireComplete: true,
|
|
3043
|
-
timeout: bootstrapAuthorityInsertSpec.defaultTimeoutMs
|
|
3044
|
-
}
|
|
3045
|
-
).then(
|
|
3046
|
-
(result) => resolve(
|
|
3047
|
-
resolveBootstrapAuthorityInsertResult(
|
|
3048
|
-
tableName,
|
|
3049
|
-
sanitizedContext,
|
|
3050
|
-
nextQueryData,
|
|
3051
|
-
result,
|
|
3052
|
-
emit2
|
|
3053
|
-
)
|
|
3054
|
-
)
|
|
3055
|
-
).catch(
|
|
3056
|
-
(error) => resolve(
|
|
3057
|
-
resolveBootstrapAuthorityInsertResult(
|
|
3058
|
-
tableName,
|
|
3059
|
-
sanitizedContext,
|
|
3060
|
-
nextQueryData,
|
|
3061
|
-
error,
|
|
3062
|
-
emit2
|
|
3063
|
-
)
|
|
3064
|
-
)
|
|
3065
|
-
);
|
|
3066
|
-
return;
|
|
3067
|
-
}
|
|
3068
|
-
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
3069
|
-
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
3070
|
-
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
3071
|
-
tableName,
|
|
3072
|
-
executionSignal,
|
|
3073
|
-
hasLocalInsertTask: !!localInsertTask,
|
|
3074
|
-
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
3075
|
-
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
3076
|
-
hasData: !!ctx.data,
|
|
3077
|
-
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
3078
|
-
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
3079
|
-
});
|
|
3080
|
-
}
|
|
3081
|
-
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
3082
|
-
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
3083
|
-
wiredLocalTaskNames.add(localInsertTask.name);
|
|
3084
|
-
}
|
|
3085
3718
|
emit2(executionSignal, {
|
|
3086
3719
|
...ctx,
|
|
3087
3720
|
__resolverRequestId: resolverRequestId
|
|
@@ -3106,6 +3739,17 @@ function readPositiveIntegerEnv(name, fallback) {
|
|
|
3106
3739
|
}
|
|
3107
3740
|
return normalized;
|
|
3108
3741
|
}
|
|
3742
|
+
function readNonNegativeFloatEnv(name, fallback) {
|
|
3743
|
+
if (typeof process === "undefined") {
|
|
3744
|
+
return fallback;
|
|
3745
|
+
}
|
|
3746
|
+
const raw = process.env?.[name];
|
|
3747
|
+
const parsed = Number(raw);
|
|
3748
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
3749
|
+
return fallback;
|
|
3750
|
+
}
|
|
3751
|
+
return parsed;
|
|
3752
|
+
}
|
|
3109
3753
|
var ServiceRegistry = class _ServiceRegistry {
|
|
3110
3754
|
/**
|
|
3111
3755
|
* Initializes a private constructor for managing service instances, remote signals,
|
|
@@ -3155,6 +3799,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
3155
3799
|
"CADENZA_RUNTIME_STATUS_REST_REFRESH_MS",
|
|
3156
3800
|
this.runtimeMetricsSampleIntervalMs
|
|
3157
3801
|
);
|
|
3802
|
+
this.runtimeStatusLoopJitterRatio = normalizeJitterRatio(
|
|
3803
|
+
readNonNegativeFloatEnv("CADENZA_RUNTIME_STATUS_JITTER_RATIO", 0.2)
|
|
3804
|
+
);
|
|
3158
3805
|
this.runtimeStatusMissThreshold = readPositiveIntegerEnv(
|
|
3159
3806
|
"CADENZA_RUNTIME_STATUS_MISSED_HEARTBEATS",
|
|
3160
3807
|
3
|
|
@@ -3203,6 +3850,18 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
3203
3850
|
"CADENZA_RUNTIME_STATUS_OVERLOADED_GRAPH_THRESHOLD",
|
|
3204
3851
|
20
|
|
3205
3852
|
);
|
|
3853
|
+
this.bootstrapFullSyncRetryJitterRatio = normalizeJitterRatio(
|
|
3854
|
+
readNonNegativeFloatEnv(
|
|
3855
|
+
"CADENZA_BOOTSTRAP_FULL_SYNC_RETRY_JITTER_RATIO",
|
|
3856
|
+
0.2
|
|
3857
|
+
)
|
|
3858
|
+
);
|
|
3859
|
+
this.serviceCommunicationRetryJitterRatio = normalizeJitterRatio(
|
|
3860
|
+
readNonNegativeFloatEnv(
|
|
3861
|
+
"CADENZA_SERVICE_COMMUNICATION_RETRY_JITTER_RATIO",
|
|
3862
|
+
0.2
|
|
3863
|
+
)
|
|
3864
|
+
);
|
|
3206
3865
|
this.serviceName = null;
|
|
3207
3866
|
this.serviceInstanceId = null;
|
|
3208
3867
|
this.numberOfRunningGraphs = 0;
|
|
@@ -4181,6 +4840,12 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4181
4840
|
const tasks = this.readArrayPayload(inquiryResult, [
|
|
4182
4841
|
"tasks"
|
|
4183
4842
|
]);
|
|
4843
|
+
const helpers = this.readArrayPayload(inquiryResult, [
|
|
4844
|
+
"helpers"
|
|
4845
|
+
]);
|
|
4846
|
+
const globals = this.readArrayPayload(inquiryResult, [
|
|
4847
|
+
"globals"
|
|
4848
|
+
]);
|
|
4184
4849
|
const signals = this.readArrayPayload(inquiryResult, [
|
|
4185
4850
|
"signals"
|
|
4186
4851
|
]);
|
|
@@ -4205,6 +4870,22 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4205
4870
|
inquiryResult,
|
|
4206
4871
|
["taskToRoutineMaps", "task_to_routine_maps"]
|
|
4207
4872
|
);
|
|
4873
|
+
const taskToHelperMaps = this.readArrayPayload(
|
|
4874
|
+
inquiryResult,
|
|
4875
|
+
["taskToHelperMaps", "task_to_helper_maps"]
|
|
4876
|
+
);
|
|
4877
|
+
const helperToHelperMaps = this.readArrayPayload(
|
|
4878
|
+
inquiryResult,
|
|
4879
|
+
["helperToHelperMaps", "helper_to_helper_maps"]
|
|
4880
|
+
);
|
|
4881
|
+
const taskToGlobalMaps = this.readArrayPayload(
|
|
4882
|
+
inquiryResult,
|
|
4883
|
+
["taskToGlobalMaps", "task_to_global_maps"]
|
|
4884
|
+
);
|
|
4885
|
+
const helperToGlobalMaps = this.readArrayPayload(
|
|
4886
|
+
inquiryResult,
|
|
4887
|
+
["helperToGlobalMaps", "helper_to_global_maps"]
|
|
4888
|
+
);
|
|
4208
4889
|
const serviceInstances = this.normalizeServiceInstancesFromSync(
|
|
4209
4890
|
inquiryResult
|
|
4210
4891
|
);
|
|
@@ -4238,6 +4919,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4238
4919
|
serviceInstanceTransports: serviceInstanceTransports.length,
|
|
4239
4920
|
serviceManifests: serviceManifests.length,
|
|
4240
4921
|
tasks: tasks.length,
|
|
4922
|
+
helpers: helpers.length,
|
|
4923
|
+
globals: globals.length,
|
|
4241
4924
|
signals: signals.length,
|
|
4242
4925
|
intents: intents.length,
|
|
4243
4926
|
actors: actors.length,
|
|
@@ -4263,6 +4946,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4263
4946
|
serviceInstanceTransports,
|
|
4264
4947
|
serviceManifests,
|
|
4265
4948
|
tasks,
|
|
4949
|
+
helpers,
|
|
4950
|
+
globals,
|
|
4266
4951
|
signals,
|
|
4267
4952
|
intents,
|
|
4268
4953
|
actors,
|
|
@@ -4270,6 +4955,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4270
4955
|
directionalTaskMaps,
|
|
4271
4956
|
actorTaskMaps,
|
|
4272
4957
|
taskToRoutineMaps,
|
|
4958
|
+
taskToHelperMaps,
|
|
4959
|
+
helperToHelperMaps,
|
|
4960
|
+
taskToGlobalMaps,
|
|
4961
|
+
helperToGlobalMaps,
|
|
4273
4962
|
__inquiryMeta: inquiryResult.__inquiryMeta
|
|
4274
4963
|
};
|
|
4275
4964
|
},
|
|
@@ -4889,29 +5578,51 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4889
5578
|
this.runtimeStatusHeartbeatStarted = true;
|
|
4890
5579
|
if (!this.runtimeMetricsSamplingStarted) {
|
|
4891
5580
|
this.runtimeMetricsSamplingStarted = true;
|
|
5581
|
+
CadenzaService.emit(META_RUNTIME_METRICS_SAMPLE_TICK_SIGNAL, {});
|
|
4892
5582
|
CadenzaService.interval(
|
|
4893
5583
|
META_RUNTIME_METRICS_SAMPLE_TICK_SIGNAL,
|
|
4894
5584
|
{},
|
|
4895
5585
|
this.runtimeMetricsSampleIntervalMs,
|
|
4896
|
-
|
|
5586
|
+
false,
|
|
5587
|
+
this.buildJitteredIntervalStartDate(
|
|
5588
|
+
this.runtimeMetricsSampleIntervalMs,
|
|
5589
|
+
"runtime-metrics-sample"
|
|
5590
|
+
)
|
|
4897
5591
|
);
|
|
4898
5592
|
}
|
|
5593
|
+
CadenzaService.emit(META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL, {
|
|
5594
|
+
reason: "heartbeat"
|
|
5595
|
+
});
|
|
4899
5596
|
CadenzaService.interval(
|
|
4900
5597
|
META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL,
|
|
4901
5598
|
{ reason: "heartbeat" },
|
|
4902
5599
|
this.runtimeStatusHeartbeatIntervalMs,
|
|
4903
|
-
|
|
5600
|
+
false,
|
|
5601
|
+
this.buildJitteredIntervalStartDate(
|
|
5602
|
+
this.runtimeStatusHeartbeatIntervalMs,
|
|
5603
|
+
"runtime-status-heartbeat"
|
|
5604
|
+
)
|
|
4904
5605
|
);
|
|
4905
5606
|
CadenzaService.interval(
|
|
4906
5607
|
META_RUNTIME_STATUS_MONITOR_TICK_SIGNAL,
|
|
4907
5608
|
{},
|
|
4908
|
-
this.runtimeStatusHeartbeatIntervalMs
|
|
5609
|
+
this.runtimeStatusHeartbeatIntervalMs,
|
|
5610
|
+
false,
|
|
5611
|
+
this.buildJitteredIntervalStartDate(
|
|
5612
|
+
this.runtimeStatusHeartbeatIntervalMs,
|
|
5613
|
+
"runtime-status-monitor"
|
|
5614
|
+
)
|
|
4909
5615
|
);
|
|
5616
|
+
CadenzaService.emit(META_RUNTIME_STATUS_REST_REFRESH_TICK_SIGNAL, {});
|
|
4910
5617
|
CadenzaService.interval(
|
|
4911
5618
|
META_RUNTIME_STATUS_REST_REFRESH_TICK_SIGNAL,
|
|
4912
5619
|
{},
|
|
4913
5620
|
this.runtimeStatusRestRefreshIntervalMs,
|
|
4914
|
-
|
|
5621
|
+
false,
|
|
5622
|
+
this.buildJitteredIntervalStartDate(
|
|
5623
|
+
this.runtimeStatusRestRefreshIntervalMs,
|
|
5624
|
+
"runtime-status-rest-refresh"
|
|
5625
|
+
)
|
|
4915
5626
|
);
|
|
4916
5627
|
return true;
|
|
4917
5628
|
},
|
|
@@ -5916,11 +6627,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5916
6627
|
}
|
|
5917
6628
|
collectBootstrapFullSyncPayload(ctx) {
|
|
5918
6629
|
const serviceInstances = [];
|
|
6630
|
+
const serviceInstanceLeases = [];
|
|
5919
6631
|
const serviceInstanceTransports = [];
|
|
5920
6632
|
const manifestSnapshots = [];
|
|
5921
6633
|
const signalToTaskMaps = [];
|
|
5922
6634
|
const intentToTaskMaps = [];
|
|
5923
6635
|
const tasks = [];
|
|
6636
|
+
const helpers = [];
|
|
6637
|
+
const globals = [];
|
|
5924
6638
|
const signals = [];
|
|
5925
6639
|
const intents = [];
|
|
5926
6640
|
const actors = [];
|
|
@@ -5928,11 +6642,18 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5928
6642
|
const directionalTaskMaps = [];
|
|
5929
6643
|
const actorTaskMaps = [];
|
|
5930
6644
|
const taskToRoutineMaps = [];
|
|
6645
|
+
const taskToHelperMaps = [];
|
|
6646
|
+
const helperToHelperMaps = [];
|
|
6647
|
+
const taskToGlobalMaps = [];
|
|
6648
|
+
const helperToGlobalMaps = [];
|
|
5931
6649
|
const seenServiceInstances = /* @__PURE__ */ new Set();
|
|
6650
|
+
const seenServiceInstanceLeases = /* @__PURE__ */ new Set();
|
|
5932
6651
|
const seenServiceInstanceTransports = /* @__PURE__ */ new Set();
|
|
5933
6652
|
const seenSignalMaps = /* @__PURE__ */ new Set();
|
|
5934
6653
|
const seenIntentMaps = /* @__PURE__ */ new Set();
|
|
5935
6654
|
const seenTasks = /* @__PURE__ */ new Set();
|
|
6655
|
+
const seenHelpers = /* @__PURE__ */ new Set();
|
|
6656
|
+
const seenGlobals = /* @__PURE__ */ new Set();
|
|
5936
6657
|
const seenSignals = /* @__PURE__ */ new Set();
|
|
5937
6658
|
const seenIntents = /* @__PURE__ */ new Set();
|
|
5938
6659
|
const seenActors = /* @__PURE__ */ new Set();
|
|
@@ -5940,6 +6661,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5940
6661
|
const seenDirectionalTaskMaps = /* @__PURE__ */ new Set();
|
|
5941
6662
|
const seenActorTaskMaps = /* @__PURE__ */ new Set();
|
|
5942
6663
|
const seenTaskToRoutineMaps = /* @__PURE__ */ new Set();
|
|
6664
|
+
const seenTaskToHelperMaps = /* @__PURE__ */ new Set();
|
|
6665
|
+
const seenHelperToHelperMaps = /* @__PURE__ */ new Set();
|
|
6666
|
+
const seenTaskToGlobalMaps = /* @__PURE__ */ new Set();
|
|
6667
|
+
const seenHelperToGlobalMaps = /* @__PURE__ */ new Set();
|
|
5943
6668
|
const contexts = Array.isArray(ctx.joinedContexts) ? [ctx, ...ctx.joinedContexts] : [ctx];
|
|
5944
6669
|
const pushUnique = (rows, target, seen, keyResolver) => {
|
|
5945
6670
|
for (const row of rows) {
|
|
@@ -5970,6 +6695,12 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5970
6695
|
"serviceInstance",
|
|
5971
6696
|
"service_instance"
|
|
5972
6697
|
]);
|
|
6698
|
+
const serviceInstanceLeaseRows = readDirectArrayPayload(candidate, [
|
|
6699
|
+
"serviceInstanceLeases",
|
|
6700
|
+
"service_instance_leases",
|
|
6701
|
+
"serviceInstanceLease",
|
|
6702
|
+
"service_instance_lease"
|
|
6703
|
+
]);
|
|
5973
6704
|
const serviceInstanceTransportRows = readDirectArrayPayload(candidate, [
|
|
5974
6705
|
"serviceInstanceTransports",
|
|
5975
6706
|
"service_instance_transports",
|
|
@@ -6000,6 +6731,12 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6000
6731
|
seenServiceInstances,
|
|
6001
6732
|
(row) => String(row.uuid ?? "").trim()
|
|
6002
6733
|
);
|
|
6734
|
+
pushUnique(
|
|
6735
|
+
serviceInstanceLeaseRows,
|
|
6736
|
+
serviceInstanceLeases,
|
|
6737
|
+
seenServiceInstanceLeases,
|
|
6738
|
+
(row) => String(row.service_instance_id ?? row.serviceInstanceId ?? "").trim()
|
|
6739
|
+
);
|
|
6003
6740
|
pushUnique(
|
|
6004
6741
|
serviceInstanceTransportRows,
|
|
6005
6742
|
serviceInstanceTransports,
|
|
@@ -6062,6 +6799,17 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6062
6799
|
);
|
|
6063
6800
|
continue;
|
|
6064
6801
|
}
|
|
6802
|
+
if (row.status !== void 0 && (row.service_instance_id !== void 0 || row.serviceInstanceId !== void 0)) {
|
|
6803
|
+
pushUnique(
|
|
6804
|
+
[row],
|
|
6805
|
+
serviceInstanceLeases,
|
|
6806
|
+
seenServiceInstanceLeases,
|
|
6807
|
+
(entry) => String(
|
|
6808
|
+
entry.service_instance_id ?? entry.serviceInstanceId ?? ""
|
|
6809
|
+
).trim()
|
|
6810
|
+
);
|
|
6811
|
+
continue;
|
|
6812
|
+
}
|
|
6065
6813
|
if (row.service_instance_id !== void 0 || row.serviceInstanceId !== void 0) {
|
|
6066
6814
|
pushUnique(
|
|
6067
6815
|
[row],
|
|
@@ -6090,12 +6838,16 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6090
6838
|
}
|
|
6091
6839
|
}
|
|
6092
6840
|
}
|
|
6841
|
+
const mergedServiceInstances = overlayServiceInstancesWithLeases(
|
|
6842
|
+
serviceInstances,
|
|
6843
|
+
serviceInstanceLeases
|
|
6844
|
+
);
|
|
6093
6845
|
const activeServiceInstanceIds = new Set(
|
|
6094
|
-
|
|
6846
|
+
mergedServiceInstances.filter((row) => row.is_active === true || row.isActive === true).map((row) => String(row.uuid ?? "").trim()).filter((uuid9) => uuid9.length > 0)
|
|
6095
6847
|
);
|
|
6096
|
-
const filteredServiceInstances = activeServiceInstanceIds.size > 0 ?
|
|
6848
|
+
const filteredServiceInstances = activeServiceInstanceIds.size > 0 ? mergedServiceInstances.filter(
|
|
6097
6849
|
(row) => activeServiceInstanceIds.has(String(row.uuid ?? "").trim())
|
|
6098
|
-
) :
|
|
6850
|
+
) : mergedServiceInstances;
|
|
6099
6851
|
const filteredServiceInstanceTransports = activeServiceInstanceIds.size > 0 ? serviceInstanceTransports.filter(
|
|
6100
6852
|
(row) => activeServiceInstanceIds.has(
|
|
6101
6853
|
String(row.service_instance_id ?? row.serviceInstanceId ?? "").trim()
|
|
@@ -6139,6 +6891,22 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6139
6891
|
row.version ?? 1
|
|
6140
6892
|
).trim()}`
|
|
6141
6893
|
);
|
|
6894
|
+
pushUnique(
|
|
6895
|
+
explodedManifest.helpers,
|
|
6896
|
+
helpers,
|
|
6897
|
+
seenHelpers,
|
|
6898
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(row.name ?? "").trim()}|${String(
|
|
6899
|
+
row.version ?? 1
|
|
6900
|
+
).trim()}`
|
|
6901
|
+
);
|
|
6902
|
+
pushUnique(
|
|
6903
|
+
explodedManifest.globals,
|
|
6904
|
+
globals,
|
|
6905
|
+
seenGlobals,
|
|
6906
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(row.name ?? "").trim()}|${String(
|
|
6907
|
+
row.version ?? 1
|
|
6908
|
+
).trim()}`
|
|
6909
|
+
);
|
|
6142
6910
|
pushUnique(
|
|
6143
6911
|
explodedManifest.signals,
|
|
6144
6912
|
signals,
|
|
@@ -6199,6 +6967,50 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6199
6967
|
row.task_version ?? 1
|
|
6200
6968
|
).trim()}`
|
|
6201
6969
|
);
|
|
6970
|
+
pushUnique(
|
|
6971
|
+
explodedManifest.taskToHelperMaps,
|
|
6972
|
+
taskToHelperMaps,
|
|
6973
|
+
seenTaskToHelperMaps,
|
|
6974
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(row.task_name ?? "").trim()}|${String(
|
|
6975
|
+
row.task_version ?? 1
|
|
6976
|
+
).trim()}|${String(row.alias ?? "").trim()}|${String(
|
|
6977
|
+
row.helper_name ?? ""
|
|
6978
|
+
).trim()}|${String(row.helper_version ?? 1).trim()}`
|
|
6979
|
+
);
|
|
6980
|
+
pushUnique(
|
|
6981
|
+
explodedManifest.helperToHelperMaps,
|
|
6982
|
+
helperToHelperMaps,
|
|
6983
|
+
seenHelperToHelperMaps,
|
|
6984
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(
|
|
6985
|
+
row.helper_name ?? ""
|
|
6986
|
+
).trim()}|${String(row.helper_version ?? 1).trim()}|${String(
|
|
6987
|
+
row.alias ?? ""
|
|
6988
|
+
).trim()}|${String(row.dependency_helper_name ?? "").trim()}|${String(
|
|
6989
|
+
row.dependency_helper_version ?? 1
|
|
6990
|
+
).trim()}`
|
|
6991
|
+
);
|
|
6992
|
+
pushUnique(
|
|
6993
|
+
explodedManifest.taskToGlobalMaps,
|
|
6994
|
+
taskToGlobalMaps,
|
|
6995
|
+
seenTaskToGlobalMaps,
|
|
6996
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(row.task_name ?? "").trim()}|${String(
|
|
6997
|
+
row.task_version ?? 1
|
|
6998
|
+
).trim()}|${String(row.alias ?? "").trim()}|${String(
|
|
6999
|
+
row.global_name ?? ""
|
|
7000
|
+
).trim()}|${String(row.global_version ?? 1).trim()}`
|
|
7001
|
+
);
|
|
7002
|
+
pushUnique(
|
|
7003
|
+
explodedManifest.helperToGlobalMaps,
|
|
7004
|
+
helperToGlobalMaps,
|
|
7005
|
+
seenHelperToGlobalMaps,
|
|
7006
|
+
(row) => `${String(row.service_name ?? "").trim()}|${String(
|
|
7007
|
+
row.helper_name ?? ""
|
|
7008
|
+
).trim()}|${String(row.helper_version ?? 1).trim()}|${String(
|
|
7009
|
+
row.alias ?? ""
|
|
7010
|
+
).trim()}|${String(row.global_name ?? "").trim()}|${String(
|
|
7011
|
+
row.global_version ?? 1
|
|
7012
|
+
).trim()}`
|
|
7013
|
+
);
|
|
6202
7014
|
if (!hasExplicitSignalRoutingRows) {
|
|
6203
7015
|
pushUnique(
|
|
6204
7016
|
explodedManifest.signalToTaskMaps,
|
|
@@ -6225,9 +7037,12 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6225
7037
|
}
|
|
6226
7038
|
return {
|
|
6227
7039
|
serviceInstances: filteredServiceInstances,
|
|
7040
|
+
serviceInstanceLeases,
|
|
6228
7041
|
serviceInstanceTransports: filteredServiceInstanceTransports,
|
|
6229
7042
|
serviceManifests,
|
|
6230
7043
|
tasks,
|
|
7044
|
+
helpers,
|
|
7045
|
+
globals,
|
|
6231
7046
|
signals,
|
|
6232
7047
|
intents,
|
|
6233
7048
|
actors,
|
|
@@ -6235,6 +7050,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6235
7050
|
directionalTaskMaps,
|
|
6236
7051
|
actorTaskMaps,
|
|
6237
7052
|
taskToRoutineMaps,
|
|
7053
|
+
taskToHelperMaps,
|
|
7054
|
+
helperToHelperMaps,
|
|
7055
|
+
taskToGlobalMaps,
|
|
7056
|
+
helperToGlobalMaps,
|
|
6238
7057
|
signalToTaskMaps: filteredSignalToTaskMaps,
|
|
6239
7058
|
intentToTaskMaps: filteredIntentToTaskMaps
|
|
6240
7059
|
};
|
|
@@ -6666,29 +7485,31 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6666
7485
|
const timeoutId = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
6667
7486
|
try {
|
|
6668
7487
|
const sanitizedContext = sanitizeAuthorityBootstrapDelegationContext(context);
|
|
6669
|
-
const requestBody =
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
__syncing: true,
|
|
6678
|
-
__transportOrigin: target.origin,
|
|
6679
|
-
__transportProtocol: "rest",
|
|
6680
|
-
__transportProtocols: ["rest"],
|
|
6681
|
-
__routeKey: target.routeKey,
|
|
6682
|
-
routeKey: target.routeKey,
|
|
6683
|
-
__fetchId: target.fetchId,
|
|
6684
|
-
fetchId: target.fetchId,
|
|
6685
|
-
__metadata: {
|
|
6686
|
-
...sanitizedContext.__metadata && typeof sanitizedContext.__metadata === "object" ? sanitizedContext.__metadata : {},
|
|
7488
|
+
const requestBody = compactAuthorityBootstrapRequestBody(
|
|
7489
|
+
stripDelegationRequestSnapshot(
|
|
7490
|
+
ensureDelegationContextMetadata(
|
|
7491
|
+
attachDelegationRequestSnapshot({
|
|
7492
|
+
...sanitizedContext,
|
|
7493
|
+
__remoteRoutineName: remoteRoutineName,
|
|
7494
|
+
__serviceName: "CadenzaDB",
|
|
7495
|
+
__localServiceName: this.serviceName,
|
|
6687
7496
|
__timeout: timeoutMs,
|
|
6688
7497
|
__syncing: true,
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
7498
|
+
__transportOrigin: target.origin,
|
|
7499
|
+
__transportProtocol: "rest",
|
|
7500
|
+
__transportProtocols: ["rest"],
|
|
7501
|
+
__routeKey: target.routeKey,
|
|
7502
|
+
routeKey: target.routeKey,
|
|
7503
|
+
__fetchId: target.fetchId,
|
|
7504
|
+
fetchId: target.fetchId,
|
|
7505
|
+
__metadata: {
|
|
7506
|
+
...sanitizedContext.__metadata && typeof sanitizedContext.__metadata === "object" ? sanitizedContext.__metadata : {},
|
|
7507
|
+
__timeout: timeoutMs,
|
|
7508
|
+
__syncing: true,
|
|
7509
|
+
__authorityBootstrapChannel: true
|
|
7510
|
+
}
|
|
7511
|
+
})
|
|
7512
|
+
)
|
|
6692
7513
|
)
|
|
6693
7514
|
);
|
|
6694
7515
|
const response = await globalThis.fetch(`${target.origin}/delegation`, {
|
|
@@ -6843,12 +7664,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6843
7664
|
};
|
|
6844
7665
|
const [
|
|
6845
7666
|
serviceInstances,
|
|
7667
|
+
serviceInstanceLeases,
|
|
6846
7668
|
serviceInstanceTransports,
|
|
6847
7669
|
serviceManifests,
|
|
6848
7670
|
signalToTaskMaps,
|
|
6849
7671
|
intentToTaskMaps
|
|
6850
7672
|
] = await Promise.all([
|
|
6851
7673
|
DatabaseController.instance.queryAuthorityTableRows("service_instance"),
|
|
7674
|
+
queryOptionalAuthorityRoutingRows("service_instance_lease"),
|
|
6852
7675
|
DatabaseController.instance.queryAuthorityTableRows(
|
|
6853
7676
|
"service_instance_transport"
|
|
6854
7677
|
),
|
|
@@ -6861,6 +7684,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6861
7684
|
__syncing: true,
|
|
6862
7685
|
...this.collectBootstrapFullSyncPayload({
|
|
6863
7686
|
serviceInstances,
|
|
7687
|
+
serviceInstanceLeases,
|
|
6864
7688
|
serviceInstanceTransports,
|
|
6865
7689
|
serviceManifests,
|
|
6866
7690
|
signalToTaskMaps,
|
|
@@ -6893,9 +7717,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6893
7717
|
return false;
|
|
6894
7718
|
}
|
|
6895
7719
|
const scheduleRetry = (reason, error) => {
|
|
6896
|
-
const
|
|
7720
|
+
const baseDelayMs = SERVICE_COMMUNICATION_PERSIST_RETRY_DELAYS_MS[descriptor.retryAttempt];
|
|
6897
7721
|
const nextAttempt = descriptor.retryAttempt + 1;
|
|
6898
|
-
if (
|
|
7722
|
+
if (baseDelayMs !== void 0) {
|
|
7723
|
+
const delayMs = buildDeterministicJitteredDelayMs(
|
|
7724
|
+
baseDelayMs,
|
|
7725
|
+
this.serviceCommunicationRetryJitterRatio,
|
|
7726
|
+
`${descriptor.serviceInstanceId}:${descriptor.communicationType}:${descriptor.retryAttempt}`
|
|
7727
|
+
);
|
|
6899
7728
|
CadenzaService.schedule(
|
|
6900
7729
|
retrySignal,
|
|
6901
7730
|
buildServiceCommunicationRetryContext({
|
|
@@ -7043,6 +7872,31 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7043
7872
|
})
|
|
7044
7873
|
);
|
|
7045
7874
|
}
|
|
7875
|
+
buildDeterministicInstanceJitterKey(scope) {
|
|
7876
|
+
const serviceName = String(this.serviceName ?? "").trim() || "unknown-service";
|
|
7877
|
+
const serviceInstanceId = String(this.serviceInstanceId ?? "").trim() || "pending-instance";
|
|
7878
|
+
return `${serviceName}:${serviceInstanceId}:${scope}`;
|
|
7879
|
+
}
|
|
7880
|
+
buildJitteredIntervalStartDate(intervalMs, scope) {
|
|
7881
|
+
const jitterOffsetMs = buildDeterministicJitterOffsetMs(
|
|
7882
|
+
intervalMs,
|
|
7883
|
+
this.runtimeStatusLoopJitterRatio,
|
|
7884
|
+
this.buildDeterministicInstanceJitterKey(scope)
|
|
7885
|
+
);
|
|
7886
|
+
if (jitterOffsetMs <= 0) {
|
|
7887
|
+
return void 0;
|
|
7888
|
+
}
|
|
7889
|
+
return new Date(Date.now() + intervalMs + jitterOffsetMs);
|
|
7890
|
+
}
|
|
7891
|
+
buildJitteredBootstrapRetryDelayMs(baseDelayMs, attempt) {
|
|
7892
|
+
return buildDeterministicJitteredDelayMs(
|
|
7893
|
+
baseDelayMs,
|
|
7894
|
+
this.bootstrapFullSyncRetryJitterRatio,
|
|
7895
|
+
this.buildDeterministicInstanceJitterKey(
|
|
7896
|
+
`bootstrap-full-sync-retry-${attempt}`
|
|
7897
|
+
)
|
|
7898
|
+
);
|
|
7899
|
+
}
|
|
7046
7900
|
ensureAuthorityBootstrapSignalTransmissions() {
|
|
7047
7901
|
if (this.serviceName !== "CadenzaDB") {
|
|
7048
7902
|
return false;
|
|
@@ -7120,8 +7974,11 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7120
7974
|
}
|
|
7121
7975
|
const retryGeneration = this.bootstrapFullSyncRetryGeneration;
|
|
7122
7976
|
const retryReason = this.bootstrapFullSyncRetryReason ?? "service_registry_bootstrap_retry";
|
|
7123
|
-
const delayMs = EARLY_FULL_SYNC_DELAYS_MS[this.bootstrapFullSyncRetryIndex];
|
|
7124
7977
|
const attempt = this.bootstrapFullSyncRetryIndex + 1;
|
|
7978
|
+
const delayMs = this.buildJitteredBootstrapRetryDelayMs(
|
|
7979
|
+
EARLY_FULL_SYNC_DELAYS_MS[this.bootstrapFullSyncRetryIndex],
|
|
7980
|
+
attempt
|
|
7981
|
+
);
|
|
7125
7982
|
this.bootstrapFullSyncRetryIndex += 1;
|
|
7126
7983
|
this.bootstrapFullSyncRetryTimer = setTimeout(() => {
|
|
7127
7984
|
this.bootstrapFullSyncRetryTimer = null;
|
|
@@ -9024,6 +9881,18 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9024
9881
|
isNonResponsive,
|
|
9025
9882
|
isBlocked
|
|
9026
9883
|
);
|
|
9884
|
+
const cpuUsage = this.readRuntimeStatusMetric(ctx, "cpuUsage", "cpu", "cpuLoad");
|
|
9885
|
+
const memoryUsage = this.readRuntimeStatusMetric(
|
|
9886
|
+
ctx,
|
|
9887
|
+
"memoryUsage",
|
|
9888
|
+
"memory",
|
|
9889
|
+
"memoryPressure"
|
|
9890
|
+
);
|
|
9891
|
+
const eventLoopLag = this.readRuntimeStatusMetric(
|
|
9892
|
+
ctx,
|
|
9893
|
+
"eventLoopLag",
|
|
9894
|
+
"eventLoopLagMs"
|
|
9895
|
+
);
|
|
9027
9896
|
return {
|
|
9028
9897
|
serviceName,
|
|
9029
9898
|
serviceInstanceId,
|
|
@@ -9036,22 +9905,20 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9036
9905
|
state: ctx.state === "healthy" || ctx.state === "degraded" || ctx.state === "overloaded" || ctx.state === "unavailable" ? ctx.state : resolved.state,
|
|
9037
9906
|
acceptingWork: typeof ctx.acceptingWork === "boolean" ? ctx.acceptingWork : resolved.acceptingWork,
|
|
9038
9907
|
numberOfRunningGraphs,
|
|
9039
|
-
cpuUsage
|
|
9040
|
-
memoryUsage
|
|
9041
|
-
|
|
9042
|
-
"memoryUsage",
|
|
9043
|
-
"memory",
|
|
9044
|
-
"memoryPressure"
|
|
9045
|
-
),
|
|
9046
|
-
eventLoopLag: this.readRuntimeStatusMetric(
|
|
9047
|
-
ctx,
|
|
9048
|
-
"eventLoopLag",
|
|
9049
|
-
"eventLoopLagMs"
|
|
9050
|
-
),
|
|
9908
|
+
cpuUsage,
|
|
9909
|
+
memoryUsage,
|
|
9910
|
+
eventLoopLag,
|
|
9051
9911
|
isActive,
|
|
9052
9912
|
isNonResponsive,
|
|
9053
9913
|
isBlocked,
|
|
9054
|
-
health: ctx.health ?? ctx.__health
|
|
9914
|
+
health: sanitizeAuthorityRuntimeStatusHealth(ctx.health ?? ctx.__health, {
|
|
9915
|
+
state: ctx.state === "healthy" || ctx.state === "degraded" || ctx.state === "overloaded" || ctx.state === "unavailable" ? ctx.state : resolved.state,
|
|
9916
|
+
acceptingWork: typeof ctx.acceptingWork === "boolean" ? ctx.acceptingWork : resolved.acceptingWork,
|
|
9917
|
+
reportedAt: ctx.reportedAt ?? (typeof ctx.__reportedAt === "string" ? ctx.__reportedAt : void 0) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
9918
|
+
cpuUsage,
|
|
9919
|
+
memoryUsage,
|
|
9920
|
+
eventLoopLag
|
|
9921
|
+
})
|
|
9055
9922
|
};
|
|
9056
9923
|
}
|
|
9057
9924
|
applyRuntimeStatusReport(report) {
|
|
@@ -9092,12 +9959,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9092
9959
|
instance.isFrontend = report.isFrontend;
|
|
9093
9960
|
}
|
|
9094
9961
|
instance.numberOfRunningGraphs = report.numberOfRunningGraphs;
|
|
9095
|
-
const
|
|
9962
|
+
const runtimeStatusHealth = sanitizeAuthorityRuntimeStatusHealth(report.health, {
|
|
9963
|
+
state: report.state,
|
|
9964
|
+
acceptingWork: report.acceptingWork,
|
|
9965
|
+
reportedAt: report.reportedAt,
|
|
9096
9966
|
cpuUsage: report.cpuUsage ?? null,
|
|
9097
9967
|
memoryUsage: report.memoryUsage ?? null,
|
|
9098
|
-
eventLoopLag: report.eventLoopLag ?? null
|
|
9099
|
-
|
|
9100
|
-
};
|
|
9968
|
+
eventLoopLag: report.eventLoopLag ?? null
|
|
9969
|
+
});
|
|
9101
9970
|
instance.isActive = report.isActive;
|
|
9102
9971
|
instance.isNonResponsive = report.isNonResponsive;
|
|
9103
9972
|
instance.isBlocked = report.isBlocked;
|
|
@@ -9106,13 +9975,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9106
9975
|
instance.reportedAt = report.reportedAt;
|
|
9107
9976
|
instance.health = {
|
|
9108
9977
|
...instance.health ?? {},
|
|
9109
|
-
...
|
|
9110
|
-
...runtimeMetricsHealth,
|
|
9111
|
-
runtimeStatus: {
|
|
9112
|
-
state: report.state,
|
|
9113
|
-
acceptingWork: report.acceptingWork,
|
|
9114
|
-
reportedAt: report.reportedAt
|
|
9115
|
-
}
|
|
9978
|
+
...runtimeStatusHealth ?? {}
|
|
9116
9979
|
};
|
|
9117
9980
|
this.lastHeartbeatAtByInstance.set(report.serviceInstanceId, Date.now());
|
|
9118
9981
|
this.missedHeartbeatsByInstance.set(report.serviceInstanceId, 0);
|
|
@@ -9284,15 +10147,20 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9284
10147
|
isActive: snapshot.isActive,
|
|
9285
10148
|
isNonResponsive: snapshot.isNonResponsive,
|
|
9286
10149
|
isBlocked: snapshot.isBlocked,
|
|
9287
|
-
health:
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
10150
|
+
health: sanitizeAuthorityRuntimeStatusHealth(
|
|
10151
|
+
{
|
|
10152
|
+
...localInstance.health ?? {},
|
|
10153
|
+
...this.buildRuntimeMetricsHealthPayload(runtimeMetricsSnapshot) ?? {}
|
|
10154
|
+
},
|
|
10155
|
+
{
|
|
9291
10156
|
state: snapshot.state,
|
|
9292
10157
|
acceptingWork: snapshot.acceptingWork,
|
|
9293
|
-
reportedAt
|
|
10158
|
+
reportedAt,
|
|
10159
|
+
cpuUsage: runtimeMetricsSnapshot?.cpuUsage ?? null,
|
|
10160
|
+
memoryUsage: runtimeMetricsSnapshot?.memoryUsage ?? null,
|
|
10161
|
+
eventLoopLag: runtimeMetricsSnapshot?.eventLoopLag ?? null
|
|
9294
10162
|
}
|
|
9295
|
-
|
|
10163
|
+
)
|
|
9296
10164
|
};
|
|
9297
10165
|
this.applyRuntimeStatusReport(report);
|
|
9298
10166
|
return detailLevel === "full" ? report : this.stripRuntimeStatusReportForPeer(report);
|
|
@@ -9646,6 +10514,32 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9646
10514
|
if (!instancePersisted) {
|
|
9647
10515
|
return false;
|
|
9648
10516
|
}
|
|
10517
|
+
await this.delegateAuthorityLifecycleUpdate(
|
|
10518
|
+
"Update service_instance_lease",
|
|
10519
|
+
{
|
|
10520
|
+
reason,
|
|
10521
|
+
graceful: true,
|
|
10522
|
+
data: {
|
|
10523
|
+
status: "inactive",
|
|
10524
|
+
is_ready: false,
|
|
10525
|
+
readiness_reason: "graceful_shutdown",
|
|
10526
|
+
lease_expires_at: reportedAt,
|
|
10527
|
+
last_lease_renewed_at: reportedAt,
|
|
10528
|
+
last_ready_at: null,
|
|
10529
|
+
last_observed_transport_at: reportedAt,
|
|
10530
|
+
shutdown_requested_at: reportedAt,
|
|
10531
|
+
deleted: false,
|
|
10532
|
+
modified: reportedAt
|
|
10533
|
+
},
|
|
10534
|
+
queryData: {
|
|
10535
|
+
filter: {
|
|
10536
|
+
service_instance_id: localInstance.uuid
|
|
10537
|
+
}
|
|
10538
|
+
},
|
|
10539
|
+
__serviceInstanceId: localInstance.uuid
|
|
10540
|
+
},
|
|
10541
|
+
Math.max(1e3, timeoutMs)
|
|
10542
|
+
);
|
|
9649
10543
|
for (const transport of localInstance.transports) {
|
|
9650
10544
|
if (!isPersistedUuid(transport.uuid)) {
|
|
9651
10545
|
continue;
|
|
@@ -9797,6 +10691,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9797
10691
|
};
|
|
9798
10692
|
}
|
|
9799
10693
|
reset() {
|
|
10694
|
+
this.clearBootstrapFullSyncRetryTimer();
|
|
9800
10695
|
this.instances.clear();
|
|
9801
10696
|
this.deputies.clear();
|
|
9802
10697
|
this.remoteSignals.clear();
|
|
@@ -9820,6 +10715,23 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9820
10715
|
this.lastRuntimeStatusSnapshot = null;
|
|
9821
10716
|
this.isFrontend = false;
|
|
9822
10717
|
this.localInstanceSeed = null;
|
|
10718
|
+
this.bootstrapFullSyncRetryIndex = 0;
|
|
10719
|
+
this.bootstrapFullSyncRetryGeneration = 0;
|
|
10720
|
+
this.bootstrapFullSyncSatisfied = false;
|
|
10721
|
+
this.bootstrapFullSyncRetryReason = null;
|
|
10722
|
+
this.knownGlobalSignalMaps.clear();
|
|
10723
|
+
this.authorityBootstrapRoute = {
|
|
10724
|
+
origin: null,
|
|
10725
|
+
role: "internal",
|
|
10726
|
+
routeKey: null,
|
|
10727
|
+
fetchId: null,
|
|
10728
|
+
serviceInstanceId: null,
|
|
10729
|
+
serviceTransportId: null,
|
|
10730
|
+
handshakeEstablished: false
|
|
10731
|
+
};
|
|
10732
|
+
this.authorityBootstrapHandshakeInFlight = false;
|
|
10733
|
+
this.authorityFullSyncResponderTask = null;
|
|
10734
|
+
this.authorityServiceCommunicationPersistenceTask = null;
|
|
9823
10735
|
}
|
|
9824
10736
|
};
|
|
9825
10737
|
|
|
@@ -9928,7 +10840,25 @@ var SignalTransmissionTask = class extends Task2 {
|
|
|
9928
10840
|
...ctx
|
|
9929
10841
|
})
|
|
9930
10842
|
);
|
|
9931
|
-
|
|
10843
|
+
const resolvedTools = typeof CadenzaService.resolveToolsForOwner === "function" ? CadenzaService.resolveToolsForOwner(
|
|
10844
|
+
this,
|
|
10845
|
+
deputyContext,
|
|
10846
|
+
emit2,
|
|
10847
|
+
inquire,
|
|
10848
|
+
progressCallback
|
|
10849
|
+
) : {
|
|
10850
|
+
helpers: {},
|
|
10851
|
+
globals: {}
|
|
10852
|
+
};
|
|
10853
|
+
const resolvedProgressCallback = typeof progressCallback === "function" ? progressCallback : () => {
|
|
10854
|
+
};
|
|
10855
|
+
return this.taskFunction(
|
|
10856
|
+
deputyContext,
|
|
10857
|
+
emit2,
|
|
10858
|
+
inquire,
|
|
10859
|
+
resolvedTools,
|
|
10860
|
+
resolvedProgressCallback
|
|
10861
|
+
);
|
|
9932
10862
|
}
|
|
9933
10863
|
};
|
|
9934
10864
|
|
|
@@ -12499,7 +13429,7 @@ var SignalController = class _SignalController {
|
|
|
12499
13429
|
}
|
|
12500
13430
|
const traceContext = { ...ctx };
|
|
12501
13431
|
delete traceContext.__traceCreatedBySignalBroker;
|
|
12502
|
-
const sanitizedTraceContext =
|
|
13432
|
+
const sanitizedTraceContext = sanitizeExecutionPersistenceContext(traceContext);
|
|
12503
13433
|
const routineMetadata = resolveRoutinePersistenceMetadata(traceContext);
|
|
12504
13434
|
const { context: routineContext, metaContext: routineMetaContext } = splitRoutinePersistenceContext(traceContext);
|
|
12505
13435
|
const traceCreatedBySignalBroker = ctx.__traceCreatedBySignalBroker === true || signalEmission.__traceCreatedBySignalBroker === true;
|
|
@@ -13183,6 +14113,16 @@ function buildActorRegistrationData(actor) {
|
|
|
13183
14113
|
version: 1
|
|
13184
14114
|
};
|
|
13185
14115
|
}
|
|
14116
|
+
function sanitizePersistedTaskSourceFields(task, data) {
|
|
14117
|
+
if (!task.isMeta && !task.isDeputy) {
|
|
14118
|
+
return data;
|
|
14119
|
+
}
|
|
14120
|
+
return {
|
|
14121
|
+
...data,
|
|
14122
|
+
function_string: "",
|
|
14123
|
+
tag_id_getter: null
|
|
14124
|
+
};
|
|
14125
|
+
}
|
|
13186
14126
|
function resolveSyncServiceName(task) {
|
|
13187
14127
|
const ownerServiceName = typeof task?.ownerServiceName === "string" ? task.ownerServiceName.trim() : "";
|
|
13188
14128
|
const taskServiceName = typeof task?.serviceName === "string" ? task.serviceName.trim() : "";
|
|
@@ -14300,40 +15240,41 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
14300
15240
|
if (task.registered) continue;
|
|
14301
15241
|
const { __functionString, __getTagCallback } = task.export();
|
|
14302
15242
|
this.tasksSynced = false;
|
|
15243
|
+
const taskRegistrationData = sanitizePersistedTaskSourceFields(task, {
|
|
15244
|
+
name: task.name,
|
|
15245
|
+
version: task.version,
|
|
15246
|
+
description: task.description,
|
|
15247
|
+
function_string: __functionString,
|
|
15248
|
+
tag_id_getter: __getTagCallback,
|
|
15249
|
+
layer_index: task.layerIndex,
|
|
15250
|
+
concurrency: task.concurrency,
|
|
15251
|
+
timeout: task.timeout,
|
|
15252
|
+
is_unique: task.isUnique,
|
|
15253
|
+
is_signal: task.isSignal,
|
|
15254
|
+
is_throttled: task.isThrottled,
|
|
15255
|
+
is_debounce: task.isDebounce,
|
|
15256
|
+
is_ephemeral: task.isEphemeral,
|
|
15257
|
+
is_meta: task.isMeta,
|
|
15258
|
+
is_sub_meta: task.isSubMeta,
|
|
15259
|
+
is_hidden: task.isHidden,
|
|
15260
|
+
validate_input_context: task.validateInputContext,
|
|
15261
|
+
validate_output_context: task.validateOutputContext,
|
|
15262
|
+
retry_count: task.retryCount,
|
|
15263
|
+
retry_delay: task.retryDelay,
|
|
15264
|
+
retry_delay_max: task.retryDelayMax,
|
|
15265
|
+
retry_delay_factor: task.retryDelayFactor,
|
|
15266
|
+
service_name: serviceName2,
|
|
15267
|
+
signals: {
|
|
15268
|
+
emits: Array.from(task.emitsSignals),
|
|
15269
|
+
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
15270
|
+
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
15271
|
+
observed: Array.from(task.observedSignals)
|
|
15272
|
+
},
|
|
15273
|
+
intents: Array.from(task.handlesIntents)
|
|
15274
|
+
});
|
|
14303
15275
|
yield {
|
|
14304
15276
|
__syncing: ctx.__syncing,
|
|
14305
|
-
data:
|
|
14306
|
-
name: task.name,
|
|
14307
|
-
version: task.version,
|
|
14308
|
-
description: task.description,
|
|
14309
|
-
function_string: __functionString,
|
|
14310
|
-
tag_id_getter: __getTagCallback,
|
|
14311
|
-
layer_index: task.layerIndex,
|
|
14312
|
-
concurrency: task.concurrency,
|
|
14313
|
-
timeout: task.timeout,
|
|
14314
|
-
is_unique: task.isUnique,
|
|
14315
|
-
is_signal: task.isSignal,
|
|
14316
|
-
is_throttled: task.isThrottled,
|
|
14317
|
-
is_debounce: task.isDebounce,
|
|
14318
|
-
is_ephemeral: task.isEphemeral,
|
|
14319
|
-
is_meta: task.isMeta,
|
|
14320
|
-
is_sub_meta: task.isSubMeta,
|
|
14321
|
-
is_hidden: task.isHidden,
|
|
14322
|
-
validate_input_context: task.validateInputContext,
|
|
14323
|
-
validate_output_context: task.validateOutputContext,
|
|
14324
|
-
retry_count: task.retryCount,
|
|
14325
|
-
retry_delay: task.retryDelay,
|
|
14326
|
-
retry_delay_max: task.retryDelayMax,
|
|
14327
|
-
retry_delay_factor: task.retryDelayFactor,
|
|
14328
|
-
service_name: serviceName2,
|
|
14329
|
-
signals: {
|
|
14330
|
-
emits: Array.from(task.emitsSignals),
|
|
14331
|
-
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
14332
|
-
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
14333
|
-
observed: Array.from(task.observedSignals)
|
|
14334
|
-
},
|
|
14335
|
-
intents: Array.from(task.handlesIntents)
|
|
14336
|
-
},
|
|
15277
|
+
data: taskRegistrationData,
|
|
14337
15278
|
__taskName: task.name
|
|
14338
15279
|
};
|
|
14339
15280
|
}
|
|
@@ -15492,13 +16433,50 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15492
16433
|
startActorPrimitiveSyncTask,
|
|
15493
16434
|
startRoutinePrimitiveSyncTask
|
|
15494
16435
|
);
|
|
15495
|
-
const getAllTasksForSyncTask = CadenzaService.
|
|
16436
|
+
const getAllTasksForSyncTask = CadenzaService.createMetaTask(
|
|
16437
|
+
"Get all tasks for sync",
|
|
16438
|
+
(ctx) => ({
|
|
16439
|
+
...ctx,
|
|
16440
|
+
tasks: Array.from(CadenzaService.registry.tasks.values())
|
|
16441
|
+
}),
|
|
16442
|
+
"Collects local tasks for the primitive sync phase.",
|
|
16443
|
+
{
|
|
16444
|
+
register: false,
|
|
16445
|
+
isHidden: true
|
|
16446
|
+
}
|
|
16447
|
+
);
|
|
15496
16448
|
startTaskPrimitiveSyncTask.then(
|
|
15497
16449
|
getAllTasksForSyncTask,
|
|
15498
16450
|
gatherTaskRegistrationTask
|
|
15499
16451
|
);
|
|
15500
16452
|
getAllTasksForSyncTask.then(this.splitTasksForRegistration);
|
|
15501
|
-
const getSignalsForSyncTask = CadenzaService.
|
|
16453
|
+
const getSignalsForSyncTask = CadenzaService.createMetaTask(
|
|
16454
|
+
"Get signals for sync",
|
|
16455
|
+
(ctx) => {
|
|
16456
|
+
const uniqueSignals = Array.from(
|
|
16457
|
+
/* @__PURE__ */ new Set([
|
|
16458
|
+
...CadenzaService.signalBroker.signalObservers.keys(),
|
|
16459
|
+
...CadenzaService.signalBroker.emittedSignalsRegistry
|
|
16460
|
+
])
|
|
16461
|
+
).filter((signal) => !signal.includes(":"));
|
|
16462
|
+
const processedSignals = uniqueSignals.map((signal) => ({
|
|
16463
|
+
signal,
|
|
16464
|
+
data: {
|
|
16465
|
+
registered: CadenzaService.signalBroker.signalObservers.get(signal)?.registered ?? false,
|
|
16466
|
+
metadata: CadenzaService.signalBroker.getSignalMetadata(signal) ?? null
|
|
16467
|
+
}
|
|
16468
|
+
}));
|
|
16469
|
+
return {
|
|
16470
|
+
...ctx,
|
|
16471
|
+
signals: processedSignals
|
|
16472
|
+
};
|
|
16473
|
+
},
|
|
16474
|
+
"Collects local signals for the primitive sync phase.",
|
|
16475
|
+
{
|
|
16476
|
+
register: false,
|
|
16477
|
+
isHidden: true
|
|
16478
|
+
}
|
|
16479
|
+
);
|
|
15502
16480
|
startSignalPrimitiveSyncTask.then(
|
|
15503
16481
|
getSignalsForSyncTask,
|
|
15504
16482
|
gatherSignalRegistrationTask
|
|
@@ -15540,40 +16518,110 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15540
16518
|
gatherActorRegistrationTask
|
|
15541
16519
|
);
|
|
15542
16520
|
getAllActorsForSyncTask.then(this.splitActorsForRegistration);
|
|
15543
|
-
const getAllRoutinesForSyncTask = CadenzaService.
|
|
16521
|
+
const getAllRoutinesForSyncTask = CadenzaService.createMetaTask(
|
|
16522
|
+
"Get all routines for sync",
|
|
16523
|
+
(ctx) => ({
|
|
16524
|
+
...ctx,
|
|
16525
|
+
routines: Array.from(CadenzaService.registry.routines.values())
|
|
16526
|
+
}),
|
|
16527
|
+
"Collects local routines for the primitive sync phase.",
|
|
16528
|
+
{
|
|
16529
|
+
register: false,
|
|
16530
|
+
isHidden: true
|
|
16531
|
+
}
|
|
16532
|
+
);
|
|
15544
16533
|
startRoutinePrimitiveSyncTask.then(
|
|
15545
16534
|
getAllRoutinesForSyncTask,
|
|
15546
16535
|
gatherRoutineRegistrationTask
|
|
15547
16536
|
);
|
|
15548
16537
|
getAllRoutinesForSyncTask.then(this.splitRoutinesTask);
|
|
15549
|
-
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.
|
|
16538
|
+
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16539
|
+
"Iterate tasks for directional task map sync",
|
|
16540
|
+
function* (ctx) {
|
|
16541
|
+
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16542
|
+
yield { ...ctx, task };
|
|
16543
|
+
}
|
|
16544
|
+
},
|
|
16545
|
+
"Iterates local tasks for directional task-map sync.",
|
|
16546
|
+
{
|
|
16547
|
+
register: false,
|
|
16548
|
+
isHidden: true
|
|
16549
|
+
}
|
|
16550
|
+
);
|
|
15550
16551
|
startDirectionalTaskMapSyncTask.then(
|
|
15551
16552
|
iterateTasksForDirectionalTaskMapSyncTask,
|
|
15552
16553
|
gatherDirectionalTaskMapRegistrationTask
|
|
15553
16554
|
);
|
|
15554
16555
|
iterateTasksForDirectionalTaskMapSyncTask.then(this.registerTaskMapTask);
|
|
15555
16556
|
recordTaskMapRegistrationTask.then(gatherDirectionalTaskMapRegistrationTask);
|
|
15556
|
-
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.
|
|
16557
|
+
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16558
|
+
"Iterate tasks for signal task map sync",
|
|
16559
|
+
function* (ctx) {
|
|
16560
|
+
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16561
|
+
yield { ...ctx, task };
|
|
16562
|
+
}
|
|
16563
|
+
},
|
|
16564
|
+
"Iterates local tasks for signal-to-task map sync.",
|
|
16565
|
+
{
|
|
16566
|
+
register: false,
|
|
16567
|
+
isHidden: true
|
|
16568
|
+
}
|
|
16569
|
+
);
|
|
15557
16570
|
startSignalTaskMapSyncTask.then(
|
|
15558
16571
|
iterateTasksForSignalTaskMapSyncTask,
|
|
15559
16572
|
gatherSignalTaskMapRegistrationTask
|
|
15560
16573
|
);
|
|
15561
16574
|
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
15562
16575
|
this.registerSignalToTaskMapTask.then(gatherSignalTaskMapRegistrationTask);
|
|
15563
|
-
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.
|
|
16576
|
+
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16577
|
+
"Iterate tasks for intent task map sync",
|
|
16578
|
+
function* (ctx) {
|
|
16579
|
+
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16580
|
+
yield { ...ctx, task };
|
|
16581
|
+
}
|
|
16582
|
+
},
|
|
16583
|
+
"Iterates local tasks for intent-to-task map sync.",
|
|
16584
|
+
{
|
|
16585
|
+
register: false,
|
|
16586
|
+
isHidden: true
|
|
16587
|
+
}
|
|
16588
|
+
);
|
|
15564
16589
|
startIntentTaskMapSyncTask.then(
|
|
15565
16590
|
iterateTasksForIntentTaskMapSyncTask,
|
|
15566
16591
|
gatherIntentTaskMapRegistrationTask
|
|
15567
16592
|
);
|
|
15568
16593
|
iterateTasksForIntentTaskMapSyncTask.then(this.registerIntentToTaskMapTask);
|
|
15569
16594
|
this.registerIntentToTaskMapTask.then(gatherIntentTaskMapRegistrationTask);
|
|
15570
|
-
const iterateTasksForActorTaskMapSyncTask = CadenzaService.
|
|
16595
|
+
const iterateTasksForActorTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16596
|
+
"Iterate tasks for actor task map sync",
|
|
16597
|
+
function* (ctx) {
|
|
16598
|
+
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16599
|
+
yield { ...ctx, task };
|
|
16600
|
+
}
|
|
16601
|
+
},
|
|
16602
|
+
"Iterates local tasks for actor-to-task map sync.",
|
|
16603
|
+
{
|
|
16604
|
+
register: false,
|
|
16605
|
+
isHidden: true
|
|
16606
|
+
}
|
|
16607
|
+
);
|
|
15571
16608
|
startActorTaskMapSyncTask.then(
|
|
15572
16609
|
iterateTasksForActorTaskMapSyncTask,
|
|
15573
16610
|
gatherActorTaskMapRegistrationTask
|
|
15574
16611
|
);
|
|
15575
16612
|
iterateTasksForActorTaskMapSyncTask.then(this.registerActorTaskMapTask);
|
|
15576
|
-
const getAllRoutinesForTaskMapSyncTask = CadenzaService.
|
|
16613
|
+
const getAllRoutinesForTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16614
|
+
"Get all routines for task map sync",
|
|
16615
|
+
(ctx) => ({
|
|
16616
|
+
...ctx,
|
|
16617
|
+
routines: Array.from(CadenzaService.registry.routines.values())
|
|
16618
|
+
}),
|
|
16619
|
+
"Collects local routines for routine-to-task map sync.",
|
|
16620
|
+
{
|
|
16621
|
+
register: false,
|
|
16622
|
+
isHidden: true
|
|
16623
|
+
}
|
|
16624
|
+
);
|
|
15577
16625
|
startRoutineTaskMapSyncTask.then(
|
|
15578
16626
|
getAllRoutinesForTaskMapSyncTask,
|
|
15579
16627
|
gatherRoutineTaskMapRegistrationTask
|
|
@@ -15649,11 +16697,37 @@ function resolveTaskByName(name) {
|
|
|
15649
16697
|
const taskName = String(name ?? "");
|
|
15650
16698
|
return taskName ? CadenzaService.get(taskName) : void 0;
|
|
15651
16699
|
}
|
|
16700
|
+
function resolveHelperFromMetadataContext(ctx) {
|
|
16701
|
+
const toolRuntime = CadenzaService;
|
|
16702
|
+
const helperName = String(
|
|
16703
|
+
ctx?.helperName ?? ctx?.data?.helperName ?? ctx?.data?.helper_name ?? ctx?.filter?.helperName ?? ctx?.filter?.helper_name ?? ""
|
|
16704
|
+
);
|
|
16705
|
+
return helperName ? toolRuntime.getHelper?.(helperName) : void 0;
|
|
16706
|
+
}
|
|
16707
|
+
function resolveGlobalFromMetadataContext(ctx) {
|
|
16708
|
+
const toolRuntime = CadenzaService;
|
|
16709
|
+
const globalName = String(
|
|
16710
|
+
ctx?.globalName ?? ctx?.data?.globalName ?? ctx?.data?.global_name ?? ctx?.filter?.globalName ?? ctx?.filter?.global_name ?? ""
|
|
16711
|
+
);
|
|
16712
|
+
return globalName ? toolRuntime.getGlobal?.(globalName) : void 0;
|
|
16713
|
+
}
|
|
15652
16714
|
function resolvePredecessorTaskFromMetadataContext(ctx) {
|
|
15653
16715
|
return resolveTaskByName(
|
|
15654
16716
|
ctx?.predecessorTaskName ?? ctx?.data?.predecessorTaskName ?? ctx?.data?.predecessor_task_name ?? ctx?.filter?.predecessorTaskName ?? ctx?.filter?.predecessor_task_name
|
|
15655
16717
|
);
|
|
15656
16718
|
}
|
|
16719
|
+
function sanitizePersistedTaskSourceFields2(task, data) {
|
|
16720
|
+
if (!task?.isMeta && !task?.isDeputy) {
|
|
16721
|
+
return data;
|
|
16722
|
+
}
|
|
16723
|
+
return {
|
|
16724
|
+
...data,
|
|
16725
|
+
functionString: "",
|
|
16726
|
+
function_string: "",
|
|
16727
|
+
tagIdGetter: null,
|
|
16728
|
+
tag_id_getter: null
|
|
16729
|
+
};
|
|
16730
|
+
}
|
|
15657
16731
|
function shouldSkipDirectTaskMetadata(task) {
|
|
15658
16732
|
return !task || !task.register || task.isHidden || task.isDeputy;
|
|
15659
16733
|
}
|
|
@@ -15731,6 +16805,9 @@ function shouldPersistBusinessInquiryCompletion(ctx) {
|
|
|
15731
16805
|
const inquiryName = String(ctx?.data?.metadata?.inquiryMeta?.inquiry ?? "");
|
|
15732
16806
|
return inquiryName.length > 0 && !isMetaIntentName(inquiryName);
|
|
15733
16807
|
}
|
|
16808
|
+
function shouldPersistExecutionTrace(ctx) {
|
|
16809
|
+
return ctx?.data?.isMeta !== true && ctx?.data?.is_meta !== true;
|
|
16810
|
+
}
|
|
15734
16811
|
function shouldPersistRoutineExecution(ctx) {
|
|
15735
16812
|
if (ctx?.data?.isMeta === true || ctx?.data?.is_meta === true) {
|
|
15736
16813
|
return false;
|
|
@@ -15794,10 +16871,10 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
15794
16871
|
task.registrationRequested = true;
|
|
15795
16872
|
}
|
|
15796
16873
|
return buildDatabaseTriggerContext(
|
|
15797
|
-
{
|
|
16874
|
+
sanitizePersistedTaskSourceFields2(task, {
|
|
15798
16875
|
...ctx.data,
|
|
15799
16876
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
15800
|
-
},
|
|
16877
|
+
}),
|
|
15801
16878
|
void 0,
|
|
15802
16879
|
{ onConflict },
|
|
15803
16880
|
{ onConflict }
|
|
@@ -15900,6 +16977,88 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
15900
16977
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
15901
16978
|
});
|
|
15902
16979
|
}).doOn("meta.task.intent_associated").emits("global.meta.graph_metadata.task_intent_associated");
|
|
16980
|
+
const buildHelperMetadataContext = (ctx) => {
|
|
16981
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
16982
|
+
return false;
|
|
16983
|
+
}
|
|
16984
|
+
const helper = resolveHelperFromMetadataContext(ctx);
|
|
16985
|
+
if (!helper) {
|
|
16986
|
+
return false;
|
|
16987
|
+
}
|
|
16988
|
+
return buildDatabaseTriggerContext({
|
|
16989
|
+
...ctx.data,
|
|
16990
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
16991
|
+
});
|
|
16992
|
+
};
|
|
16993
|
+
createLocalGraphMetadataTask("Handle helper creation", buildHelperMetadataContext).doOn("meta.helper.created").emits("global.meta.graph_metadata.helper_created");
|
|
16994
|
+
createLocalGraphMetadataTask("Handle helper update", buildHelperMetadataContext).doOn("meta.helper.updated").emits("global.meta.graph_metadata.helper_updated");
|
|
16995
|
+
const buildGlobalMetadataContext = (ctx) => {
|
|
16996
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
16997
|
+
return false;
|
|
16998
|
+
}
|
|
16999
|
+
const globalDefinition = resolveGlobalFromMetadataContext(ctx);
|
|
17000
|
+
if (!globalDefinition) {
|
|
17001
|
+
return false;
|
|
17002
|
+
}
|
|
17003
|
+
return buildDatabaseTriggerContext({
|
|
17004
|
+
...ctx.data,
|
|
17005
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
17006
|
+
});
|
|
17007
|
+
};
|
|
17008
|
+
createLocalGraphMetadataTask("Handle global creation", buildGlobalMetadataContext).doOn("meta.global.created").emits("global.meta.graph_metadata.global_created");
|
|
17009
|
+
createLocalGraphMetadataTask("Handle global update", buildGlobalMetadataContext).doOn("meta.global.updated").emits("global.meta.graph_metadata.global_updated");
|
|
17010
|
+
createLocalGraphMetadataTask("Handle task helper association", (ctx) => {
|
|
17011
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17012
|
+
return false;
|
|
17013
|
+
}
|
|
17014
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
17015
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
17016
|
+
return false;
|
|
17017
|
+
}
|
|
17018
|
+
return buildDatabaseTriggerContext({
|
|
17019
|
+
...ctx.data,
|
|
17020
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
17021
|
+
});
|
|
17022
|
+
}).doOn("meta.task.helper_associated").emits("global.meta.graph_metadata.task_helper_associated");
|
|
17023
|
+
createLocalGraphMetadataTask("Handle helper helper association", (ctx) => {
|
|
17024
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17025
|
+
return false;
|
|
17026
|
+
}
|
|
17027
|
+
const helper = resolveHelperFromMetadataContext(ctx);
|
|
17028
|
+
if (!helper) {
|
|
17029
|
+
return false;
|
|
17030
|
+
}
|
|
17031
|
+
return buildDatabaseTriggerContext({
|
|
17032
|
+
...ctx.data,
|
|
17033
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
17034
|
+
});
|
|
17035
|
+
}).doOn("meta.helper.helper_associated").emits("global.meta.graph_metadata.helper_helper_associated");
|
|
17036
|
+
createLocalGraphMetadataTask("Handle task global association", (ctx) => {
|
|
17037
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17038
|
+
return false;
|
|
17039
|
+
}
|
|
17040
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
17041
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
17042
|
+
return false;
|
|
17043
|
+
}
|
|
17044
|
+
return buildDatabaseTriggerContext({
|
|
17045
|
+
...ctx.data,
|
|
17046
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
17047
|
+
});
|
|
17048
|
+
}).doOn("meta.task.global_associated").emits("global.meta.graph_metadata.task_global_associated");
|
|
17049
|
+
createLocalGraphMetadataTask("Handle helper global association", (ctx) => {
|
|
17050
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17051
|
+
return false;
|
|
17052
|
+
}
|
|
17053
|
+
const helper = resolveHelperFromMetadataContext(ctx);
|
|
17054
|
+
if (!helper) {
|
|
17055
|
+
return false;
|
|
17056
|
+
}
|
|
17057
|
+
return buildDatabaseTriggerContext({
|
|
17058
|
+
...ctx.data,
|
|
17059
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
17060
|
+
});
|
|
17061
|
+
}).doOn("meta.helper.global_associated").emits("global.meta.graph_metadata.helper_global_associated");
|
|
15903
17062
|
createLocalGraphMetadataTask("Handle task unsubscribing signal", (ctx) => {
|
|
15904
17063
|
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
15905
17064
|
return false;
|
|
@@ -15967,6 +17126,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
15967
17126
|
});
|
|
15968
17127
|
}).doOn("meta.routine.task_added").emits("global.meta.graph_metadata.task_added_to_routine");
|
|
15969
17128
|
createLocalGraphMetadataTask("Handle new trace", (ctx) => {
|
|
17129
|
+
if (!shouldPersistExecutionTrace(ctx)) {
|
|
17130
|
+
return false;
|
|
17131
|
+
}
|
|
15970
17132
|
return buildDatabaseTriggerContext({
|
|
15971
17133
|
...ctx.data,
|
|
15972
17134
|
service_name: CadenzaService.serviceRegistry.serviceName,
|
|
@@ -15980,10 +17142,10 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
15980
17142
|
return false;
|
|
15981
17143
|
}
|
|
15982
17144
|
const routineData = ctx.data ?? {};
|
|
15983
|
-
const sanitizedRoutineContext =
|
|
17145
|
+
const sanitizedRoutineContext = sanitizeExecutionPersistenceContext(
|
|
15984
17146
|
routineData.context ?? {}
|
|
15985
17147
|
);
|
|
15986
|
-
const sanitizedRoutineMetaContext =
|
|
17148
|
+
const sanitizedRoutineMetaContext = sanitizeExecutionPersistenceContext(
|
|
15987
17149
|
routineData.metaContext ?? {}
|
|
15988
17150
|
);
|
|
15989
17151
|
const routineExecutionRow = {
|
|
@@ -16118,12 +17280,13 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
16118
17280
|
createLocalGraphMetadataTask(
|
|
16119
17281
|
"Handle routine execution ended",
|
|
16120
17282
|
(ctx) => {
|
|
17283
|
+
const sanitizedData = sanitizeExecutionPersistenceResultPayload({
|
|
17284
|
+
...ctx.data,
|
|
17285
|
+
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
17286
|
+
serviceInstanceId: resolveExecutionObservabilityServiceInstanceId2()
|
|
17287
|
+
});
|
|
16121
17288
|
return buildDatabaseTriggerContext(
|
|
16122
|
-
|
|
16123
|
-
...ctx.data,
|
|
16124
|
-
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
16125
|
-
serviceInstanceId: resolveExecutionObservabilityServiceInstanceId2()
|
|
16126
|
-
},
|
|
17289
|
+
sanitizedData,
|
|
16127
17290
|
ctx.filter ?? void 0
|
|
16128
17291
|
);
|
|
16129
17292
|
},
|
|
@@ -16137,10 +17300,10 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
16137
17300
|
return false;
|
|
16138
17301
|
}
|
|
16139
17302
|
const taskExecutionData = ctx.data ?? {};
|
|
16140
|
-
const sanitizedTaskContext =
|
|
17303
|
+
const sanitizedTaskContext = sanitizeExecutionPersistenceContext(
|
|
16141
17304
|
taskExecutionData.context ?? {}
|
|
16142
17305
|
);
|
|
16143
|
-
const sanitizedTaskMetaContext =
|
|
17306
|
+
const sanitizedTaskMetaContext = sanitizeExecutionPersistenceContext(
|
|
16144
17307
|
taskExecutionData.metaContext ?? {}
|
|
16145
17308
|
);
|
|
16146
17309
|
const routineMetadata = resolveRoutinePersistenceMetadata(
|
|
@@ -16373,12 +17536,13 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
16373
17536
|
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
16374
17537
|
return false;
|
|
16375
17538
|
}
|
|
17539
|
+
const sanitizedData = sanitizeExecutionPersistenceResultPayload({
|
|
17540
|
+
...ctx.data,
|
|
17541
|
+
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
17542
|
+
serviceInstanceId: resolveExecutionObservabilityServiceInstanceId2()
|
|
17543
|
+
});
|
|
16376
17544
|
return buildDatabaseTriggerContext(
|
|
16377
|
-
|
|
16378
|
-
...ctx.data,
|
|
16379
|
-
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
16380
|
-
serviceInstanceId: resolveExecutionObservabilityServiceInstanceId2()
|
|
16381
|
-
},
|
|
17545
|
+
sanitizedData,
|
|
16382
17546
|
ctx.filter ?? void 0
|
|
16383
17547
|
);
|
|
16384
17548
|
},
|
|
@@ -17443,9 +18607,17 @@ var CadenzaService = class {
|
|
|
17443
18607
|
"meta.task.relationship_added",
|
|
17444
18608
|
"meta.task.relationship_removed",
|
|
17445
18609
|
"meta.task.intent_associated",
|
|
18610
|
+
"meta.task.helper_associated",
|
|
18611
|
+
"meta.task.global_associated",
|
|
17446
18612
|
"meta.task.observed_signal",
|
|
17447
18613
|
"meta.task.attached_signal",
|
|
17448
18614
|
"meta.task.detached_signal",
|
|
18615
|
+
"meta.helper.created",
|
|
18616
|
+
"meta.helper.updated",
|
|
18617
|
+
"meta.global.created",
|
|
18618
|
+
"meta.global.updated",
|
|
18619
|
+
"meta.helper.helper_associated",
|
|
18620
|
+
"meta.helper.global_associated",
|
|
17449
18621
|
"meta.actor.created",
|
|
17450
18622
|
"meta.actor.task_associated",
|
|
17451
18623
|
"meta.fetch.handshake_complete",
|