@cadenza.io/service 2.18.1 → 2.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +1689 -747
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1689 -747
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1878 -765
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1878 -765
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/browser/index.js
CHANGED
|
@@ -55,8 +55,46 @@ module.exports = __toCommonJS(index_exports);
|
|
|
55
55
|
var import_core5 = __toESM(require("@cadenza.io/core"));
|
|
56
56
|
|
|
57
57
|
// src/graph/definition/DeputyTask.ts
|
|
58
|
-
var
|
|
58
|
+
var import_uuid2 = require("uuid");
|
|
59
59
|
var import_core = require("@cadenza.io/core");
|
|
60
|
+
|
|
61
|
+
// src/utils/delegation.ts
|
|
62
|
+
var import_uuid = require("uuid");
|
|
63
|
+
var ROOT_METADATA_PASSTHROUGH_KEYS = [
|
|
64
|
+
"__executionTraceId",
|
|
65
|
+
"__inquiryId",
|
|
66
|
+
"__inquirySourceTaskName",
|
|
67
|
+
"__inquirySourceTaskVersion",
|
|
68
|
+
"__inquirySourceTaskExecutionId",
|
|
69
|
+
"__inquirySourceRoutineExecutionId"
|
|
70
|
+
];
|
|
71
|
+
function hoistDelegationMetadataFields(input, metadataInput) {
|
|
72
|
+
const context = input && typeof input === "object" ? { ...input } : {};
|
|
73
|
+
const mutableContext = context;
|
|
74
|
+
const metadata = metadataInput && typeof metadataInput === "object" ? metadataInput : context.__metadata && typeof context.__metadata === "object" ? context.__metadata : {};
|
|
75
|
+
for (const key of ROOT_METADATA_PASSTHROUGH_KEYS) {
|
|
76
|
+
if ((mutableContext[key] === void 0 || mutableContext[key] === null) && metadata[key] !== void 0 && metadata[key] !== null) {
|
|
77
|
+
mutableContext[key] = metadata[key];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return context;
|
|
81
|
+
}
|
|
82
|
+
function ensureDelegationContextMetadata(input) {
|
|
83
|
+
const rawContext = input && typeof input === "object" ? { ...input } : {};
|
|
84
|
+
const metadata = rawContext.__metadata && typeof rawContext.__metadata === "object" ? { ...rawContext.__metadata } : {};
|
|
85
|
+
const context = hoistDelegationMetadataFields(rawContext, metadata);
|
|
86
|
+
const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof rawContext.__deputyExecId === "string" && rawContext.__deputyExecId.length > 0 ? context.__deputyExecId : (0, import_uuid.v4)();
|
|
87
|
+
return {
|
|
88
|
+
...context,
|
|
89
|
+
__deputyExecId: deputyExecId,
|
|
90
|
+
__metadata: {
|
|
91
|
+
...metadata,
|
|
92
|
+
__deputyExecId: deputyExecId
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/graph/definition/DeputyTask.ts
|
|
60
98
|
var DeputyTask = class extends import_core.Task {
|
|
61
99
|
/**
|
|
62
100
|
* Constructs a new instance of the class with the specified parameters.
|
|
@@ -94,7 +132,7 @@ var DeputyTask = class extends import_core.Task {
|
|
|
94
132
|
resolve(context);
|
|
95
133
|
return;
|
|
96
134
|
}
|
|
97
|
-
const processId = (0,
|
|
135
|
+
const processId = (0, import_uuid2.v4)();
|
|
98
136
|
context.__metadata.__deputyExecId = processId;
|
|
99
137
|
emit("meta.deputy.delegation_requested", {
|
|
100
138
|
...context
|
|
@@ -182,7 +220,7 @@ var DeputyTask = class extends import_core.Task {
|
|
|
182
220
|
execute(context, emit, inquire, progressCallback, nodeData) {
|
|
183
221
|
const ctx = context.getContext();
|
|
184
222
|
const metadata = context.getMetadata();
|
|
185
|
-
const deputyContext = {
|
|
223
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
186
224
|
__timeout: this.timeout,
|
|
187
225
|
__localTaskName: this.name,
|
|
188
226
|
__localTaskVersion: this.version,
|
|
@@ -199,7 +237,7 @@ var DeputyTask = class extends import_core.Task {
|
|
|
199
237
|
__deputyTaskName: this.name
|
|
200
238
|
},
|
|
201
239
|
...ctx
|
|
202
|
-
};
|
|
240
|
+
});
|
|
203
241
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
204
242
|
}
|
|
205
243
|
};
|
|
@@ -280,7 +318,7 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
280
318
|
},
|
|
281
319
|
...dynamicQueryData
|
|
282
320
|
};
|
|
283
|
-
const deputyContext = {
|
|
321
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
284
322
|
...ctx,
|
|
285
323
|
__localTaskName: this.name,
|
|
286
324
|
__localTaskVersion: this.version,
|
|
@@ -303,7 +341,7 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
303
341
|
filter: nextQueryData.filter ?? ctx.filter,
|
|
304
342
|
fields: nextQueryData.fields ?? ctx.fields,
|
|
305
343
|
queryData: nextQueryData
|
|
306
|
-
};
|
|
344
|
+
});
|
|
307
345
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
308
346
|
}
|
|
309
347
|
};
|
|
@@ -554,22 +592,6 @@ function getRouteableTransport(instance, role, protocol) {
|
|
|
554
592
|
return selectTransportForRole(instance.transports ?? [], role, protocol);
|
|
555
593
|
}
|
|
556
594
|
|
|
557
|
-
// src/utils/delegation.ts
|
|
558
|
-
var import_uuid2 = require("uuid");
|
|
559
|
-
function ensureDelegationContextMetadata(input) {
|
|
560
|
-
const context = input && typeof input === "object" ? { ...input } : {};
|
|
561
|
-
const metadata = context.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
|
|
562
|
-
const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof context.__deputyExecId === "string" && context.__deputyExecId.length > 0 ? context.__deputyExecId : (0, import_uuid2.v4)();
|
|
563
|
-
return {
|
|
564
|
-
...context,
|
|
565
|
-
__deputyExecId: deputyExecId,
|
|
566
|
-
__metadata: {
|
|
567
|
-
...metadata,
|
|
568
|
-
__deputyExecId: deputyExecId
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
|
|
573
595
|
// src/utils/readiness.ts
|
|
574
596
|
function evaluateDependencyReadiness(input) {
|
|
575
597
|
const missedHeartbeats = Math.max(
|
|
@@ -739,6 +761,21 @@ var CADENZA_DB_GATHERED_SYNC_SIGNAL = "global.meta.cadenza_db.gathered_sync_data
|
|
|
739
761
|
var META_GATHERED_SYNC_TRANSMISSION_RECONCILE_SIGNAL = "meta.service_registry.gathered_sync_transmission_reconcile_requested";
|
|
740
762
|
var META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL = "meta.service_registry.runtime_status.heartbeat_tick";
|
|
741
763
|
var META_RUNTIME_STATUS_MONITOR_TICK_SIGNAL = "meta.service_registry.runtime_status.monitor_tick";
|
|
764
|
+
var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
765
|
+
100,
|
|
766
|
+
1500,
|
|
767
|
+
5e3,
|
|
768
|
+
12e3,
|
|
769
|
+
25e3,
|
|
770
|
+
45e3,
|
|
771
|
+
7e4
|
|
772
|
+
];
|
|
773
|
+
var BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS = [
|
|
774
|
+
"Query service_instance",
|
|
775
|
+
"Query service_instance_transport",
|
|
776
|
+
"Query signal_to_task_map",
|
|
777
|
+
"Query intent_to_task_map"
|
|
778
|
+
];
|
|
742
779
|
var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
743
780
|
"Track local routine start",
|
|
744
781
|
"Track local routine end",
|
|
@@ -751,6 +788,10 @@ var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
|
751
788
|
"Collect distributed readiness",
|
|
752
789
|
"Get status"
|
|
753
790
|
]);
|
|
791
|
+
var SERVICE_REGISTRY_TRACE_SERVICE = (process.env.CADENZA_SERVICE_REGISTRY_TRACE_SERVICE ?? "").trim();
|
|
792
|
+
function shouldTraceServiceRegistry(serviceName) {
|
|
793
|
+
return SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && serviceName === SERVICE_REGISTRY_TRACE_SERVICE;
|
|
794
|
+
}
|
|
754
795
|
function buildServiceRegistryInsertQueryData(ctx, queryData) {
|
|
755
796
|
const joinedContexts = Array.isArray(ctx.joinedContexts) ? ctx.joinedContexts : [];
|
|
756
797
|
const getJoinedValue = (key) => {
|
|
@@ -824,6 +865,45 @@ function normalizeServiceRegistryInsertResult(tableName, ctx, queryData, rawResu
|
|
|
824
865
|
}
|
|
825
866
|
return result;
|
|
826
867
|
}
|
|
868
|
+
function resolveServiceInstanceRegistrationPayload(ctx, fallbackServiceName, fallbackServiceInstanceId) {
|
|
869
|
+
const candidateSources = [
|
|
870
|
+
ctx.__registrationData,
|
|
871
|
+
ctx.queryData?.data,
|
|
872
|
+
ctx.__resolverQueryData?.data,
|
|
873
|
+
ctx.__resolverOriginalContext?.__registrationData,
|
|
874
|
+
ctx.__resolverOriginalContext?.queryData?.data,
|
|
875
|
+
ctx.data,
|
|
876
|
+
ctx.__resolverOriginalContext?.data
|
|
877
|
+
];
|
|
878
|
+
let resolvedData = null;
|
|
879
|
+
for (const candidate of candidateSources) {
|
|
880
|
+
if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) {
|
|
881
|
+
resolvedData = {
|
|
882
|
+
...candidate
|
|
883
|
+
};
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (!resolvedData) {
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
const resolvedUuid = String(
|
|
891
|
+
resolvedData.uuid ?? ctx.__serviceInstanceId ?? ctx.__resolverOriginalContext?.__serviceInstanceId ?? fallbackServiceInstanceId ?? ""
|
|
892
|
+
).trim();
|
|
893
|
+
const resolvedServiceName = String(
|
|
894
|
+
resolvedData.service_name ?? ctx.__serviceName ?? ctx.__resolverOriginalContext?.__serviceName ?? fallbackServiceName ?? ""
|
|
895
|
+
).trim();
|
|
896
|
+
const resolvedProcessPid = typeof resolvedData.process_pid === "number" ? resolvedData.process_pid : typeof ctx.__resolverOriginalContext?.data?.process_pid === "number" ? ctx.__resolverOriginalContext.data.process_pid : typeof ctx.__resolverOriginalContext?.__registrationData?.process_pid === "number" ? ctx.__resolverOriginalContext.__registrationData.process_pid : typeof ctx.queryData?.data?.process_pid === "number" ? ctx.queryData.data.process_pid : typeof ctx.__registrationData?.process_pid === "number" ? ctx.__registrationData.process_pid : null;
|
|
897
|
+
if (!resolvedUuid || !resolvedServiceName || resolvedProcessPid === null) {
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
...resolvedData,
|
|
902
|
+
uuid: resolvedUuid,
|
|
903
|
+
service_name: resolvedServiceName,
|
|
904
|
+
process_pid: resolvedProcessPid
|
|
905
|
+
};
|
|
906
|
+
}
|
|
827
907
|
function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {}) {
|
|
828
908
|
const remoteInsertTask = CadenzaService.createCadenzaDBInsertTask(
|
|
829
909
|
tableName,
|
|
@@ -848,13 +928,24 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
848
928
|
});
|
|
849
929
|
delegationContext.__metadata.__skipRemoteExecution = delegationContext.__metadata.__skipRemoteExecution ?? delegationContext.__skipRemoteExecution ?? false;
|
|
850
930
|
delegationContext.__metadata.__blockRemoteExecution = delegationContext.__metadata.__blockRemoteExecution ?? delegationContext.__blockRemoteExecution ?? false;
|
|
851
|
-
|
|
931
|
+
const nextContext = {
|
|
852
932
|
...delegationContext,
|
|
853
933
|
__resolverOriginalContext: {
|
|
854
934
|
...ctx
|
|
855
935
|
},
|
|
856
936
|
__resolverQueryData: nextQueryData
|
|
857
937
|
};
|
|
938
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
939
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_registry_insert_execution", {
|
|
940
|
+
tableName,
|
|
941
|
+
signalName,
|
|
942
|
+
resolverRequestId: ctx.__resolverRequestId ?? null,
|
|
943
|
+
hasData: nextQueryData.data !== void 0,
|
|
944
|
+
queryDataKeys: Object.keys(nextQueryData),
|
|
945
|
+
dataKeys: nextQueryData.data && typeof nextQueryData.data === "object" ? Object.keys(nextQueryData.data) : []
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
return nextContext;
|
|
858
949
|
},
|
|
859
950
|
`Prepares ${tableName} service-registry insert payloads for runner execution.`,
|
|
860
951
|
{
|
|
@@ -880,6 +971,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
880
971
|
ctx.__resolverQueryData ?? ctx.queryData ?? {},
|
|
881
972
|
ctx
|
|
882
973
|
);
|
|
974
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
975
|
+
console.log("[CADENZA_INSTANCE_DEBUG] finalize_service_registry_insert", {
|
|
976
|
+
tableName,
|
|
977
|
+
hasNormalized: !!normalized,
|
|
978
|
+
normalizedKeys: normalized && typeof normalized === "object" ? Object.keys(normalized) : [],
|
|
979
|
+
uuid: normalized && typeof normalized === "object" ? normalized.uuid ?? normalized.data?.uuid ?? normalized.queryData?.data?.uuid ?? null : null,
|
|
980
|
+
serviceName: normalized && typeof normalized === "object" ? normalized.__serviceName ?? normalized.data?.service_name ?? normalized.queryData?.data?.service_name ?? null : null,
|
|
981
|
+
errored: normalized && typeof normalized === "object" ? normalized.errored === true : false,
|
|
982
|
+
error: normalized && typeof normalized === "object" ? normalized.__error ?? null : null,
|
|
983
|
+
inquiryMeta: normalized && typeof normalized === "object" ? normalized.__inquiryMeta ?? null : null
|
|
984
|
+
});
|
|
985
|
+
}
|
|
883
986
|
if (!normalized || typeof normalized !== "object") {
|
|
884
987
|
return normalized;
|
|
885
988
|
}
|
|
@@ -905,6 +1008,16 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
905
1008
|
CadenzaService.createEphemeralMetaTask(
|
|
906
1009
|
`Resolve service registry insert execution for ${tableName} (${resolverRequestId})`,
|
|
907
1010
|
(resultCtx) => {
|
|
1011
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
1012
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert_signal", {
|
|
1013
|
+
tableName,
|
|
1014
|
+
resolverRequestId,
|
|
1015
|
+
incomingResolverRequestId: resultCtx.__resolverRequestId ?? null,
|
|
1016
|
+
errored: resultCtx.errored === true,
|
|
1017
|
+
error: resultCtx.__error ?? null,
|
|
1018
|
+
keys: resultCtx && typeof resultCtx === "object" ? Object.keys(resultCtx) : []
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
908
1021
|
if (resultCtx.__resolverRequestId !== resolverRequestId) {
|
|
909
1022
|
return false;
|
|
910
1023
|
}
|
|
@@ -924,6 +1037,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
924
1037
|
).doOn(executionResolvedSignal, executionFailedSignal);
|
|
925
1038
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
926
1039
|
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
1040
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
1041
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
1042
|
+
tableName,
|
|
1043
|
+
executionSignal,
|
|
1044
|
+
hasLocalInsertTask: !!localInsertTask,
|
|
1045
|
+
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
1046
|
+
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
1047
|
+
hasData: !!ctx.data,
|
|
1048
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
1049
|
+
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
927
1052
|
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
928
1053
|
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
929
1054
|
wiredLocalTaskNames.add(localInsertTask.name);
|
|
@@ -1006,6 +1131,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1006
1131
|
this.useSocket = false;
|
|
1007
1132
|
this.retryCount = 3;
|
|
1008
1133
|
this.isFrontend = false;
|
|
1134
|
+
this.connectsToCadenzaDB = false;
|
|
1009
1135
|
CadenzaService.defineIntent({
|
|
1010
1136
|
name: META_RUNTIME_TRANSPORT_DIAGNOSTICS_INTENT,
|
|
1011
1137
|
description: "Gather transport diagnostics across all services and communication clients.",
|
|
@@ -1364,6 +1490,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1364
1490
|
)?.destroy();
|
|
1365
1491
|
continue;
|
|
1366
1492
|
}
|
|
1493
|
+
if (map.serviceName === this.serviceName) {
|
|
1494
|
+
continue;
|
|
1495
|
+
}
|
|
1367
1496
|
if (locallyEmittedSignals.includes(map.signalName)) {
|
|
1368
1497
|
if (!this.remoteSignals.get(map.serviceName)) {
|
|
1369
1498
|
this.remoteSignals.set(map.serviceName, /* @__PURE__ */ new Set());
|
|
@@ -1380,7 +1509,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1380
1509
|
return true;
|
|
1381
1510
|
},
|
|
1382
1511
|
"Handles registration of remote signals"
|
|
1383
|
-
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1512
|
+
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1513
|
+
"global.meta.cadenza_db.gathered_sync_data",
|
|
1514
|
+
"global.meta.graph_metadata.task_signal_observed"
|
|
1515
|
+
);
|
|
1384
1516
|
this.reconcileGatheredSyncTransmissionsTask = CadenzaService.createMetaTask(
|
|
1385
1517
|
"Reconcile gathered sync signal transmissions",
|
|
1386
1518
|
(ctx, emit) => this.reconcileGatheredSyncTransmissions(ctx, emit),
|
|
@@ -1394,6 +1526,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1394
1526
|
"Handle global intent registration",
|
|
1395
1527
|
(ctx, emit) => {
|
|
1396
1528
|
const intentToTaskMaps = this.normalizeIntentMaps(ctx);
|
|
1529
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1530
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] handle_global_intents", {
|
|
1531
|
+
localServiceName: this.serviceName,
|
|
1532
|
+
intentCount: intentToTaskMaps.length,
|
|
1533
|
+
sample: intentToTaskMaps.slice(0, 5)
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1397
1536
|
const sorted = intentToTaskMaps.sort((a, b) => {
|
|
1398
1537
|
if (a.deleted && !b.deleted) return -1;
|
|
1399
1538
|
if (!a.deleted && b.deleted) return 1;
|
|
@@ -1405,6 +1544,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1405
1544
|
this.unregisterRemoteIntentDeputy(map);
|
|
1406
1545
|
continue;
|
|
1407
1546
|
}
|
|
1547
|
+
if (map.serviceName === this.serviceName) {
|
|
1548
|
+
continue;
|
|
1549
|
+
}
|
|
1408
1550
|
CadenzaService.inquiryBroker.addIntent({
|
|
1409
1551
|
name: map.intentName
|
|
1410
1552
|
});
|
|
@@ -1534,7 +1676,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1534
1676
|
);
|
|
1535
1677
|
this.handleSocketStatusUpdateTask = CadenzaService.createMetaTask(
|
|
1536
1678
|
"Handle Socket Status Update",
|
|
1537
|
-
(ctx) => {
|
|
1679
|
+
(ctx, emit) => {
|
|
1538
1680
|
const report = this.normalizeRuntimeStatusReport(ctx);
|
|
1539
1681
|
if (!report) {
|
|
1540
1682
|
return false;
|
|
@@ -1577,6 +1719,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1577
1719
|
if (!applied) {
|
|
1578
1720
|
return false;
|
|
1579
1721
|
}
|
|
1722
|
+
const updatedInstance = this.getInstance(
|
|
1723
|
+
report.serviceName,
|
|
1724
|
+
report.serviceInstanceId
|
|
1725
|
+
);
|
|
1726
|
+
if (updatedInstance && !updatedInstance.isFrontend && (this.deputies.has(report.serviceName) || this.remoteIntents.has(report.serviceName) || this.remoteSignals.has(report.serviceName))) {
|
|
1727
|
+
this.ensureDependeeClientForInstance(updatedInstance, emit, ctx);
|
|
1728
|
+
}
|
|
1580
1729
|
this.registerDependee(report.serviceName, report.serviceInstanceId);
|
|
1581
1730
|
this.lastHeartbeatAtByInstance.set(report.serviceInstanceId, Date.now());
|
|
1582
1731
|
this.missedHeartbeatsByInstance.set(report.serviceInstanceId, 0);
|
|
@@ -1587,9 +1736,28 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1587
1736
|
},
|
|
1588
1737
|
"Handles status update from socket broadcast"
|
|
1589
1738
|
).doOn("meta.socket_client.status_received");
|
|
1739
|
+
CadenzaService.createMetaTask(
|
|
1740
|
+
"Request full sync after CadenzaDB fetch handshake",
|
|
1741
|
+
(ctx) => {
|
|
1742
|
+
const serviceName = typeof ctx.serviceName === "string" ? ctx.serviceName.trim() : typeof ctx.__serviceName === "string" ? ctx.__serviceName.trim() : "";
|
|
1743
|
+
if (serviceName !== "CadenzaDB") {
|
|
1744
|
+
return false;
|
|
1745
|
+
}
|
|
1746
|
+
return this.scheduleEarlyFullSyncRequests("cadenza_db_fetch_handshake");
|
|
1747
|
+
},
|
|
1748
|
+
"Schedules a few early service-registry full-sync retries after the authority fetch transport comes up."
|
|
1749
|
+
).doOn("meta.fetch.handshake_complete");
|
|
1590
1750
|
this.fullSyncTask = CadenzaService.createMetaTask(
|
|
1591
1751
|
"Full sync",
|
|
1592
1752
|
async (ctx) => {
|
|
1753
|
+
if (this.connectsToCadenzaDB && this.serviceName !== "CadenzaDB" && !this.hasBootstrapFullSyncDeputies()) {
|
|
1754
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1755
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] full_sync_skipped_missing_bootstrap_deputies", {
|
|
1756
|
+
localServiceName: this.serviceName
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
return false;
|
|
1760
|
+
}
|
|
1593
1761
|
const inquiryResult = await CadenzaService.inquire(
|
|
1594
1762
|
META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
1595
1763
|
{
|
|
@@ -1606,6 +1774,15 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1606
1774
|
const serviceInstances = this.normalizeServiceInstancesFromSync(
|
|
1607
1775
|
inquiryResult
|
|
1608
1776
|
);
|
|
1777
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1778
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] full_sync_result", {
|
|
1779
|
+
localServiceName: this.serviceName,
|
|
1780
|
+
inquiryMeta: inquiryResult.__inquiryMeta,
|
|
1781
|
+
signalToTaskMaps: signalToTaskMaps.length,
|
|
1782
|
+
intentToTaskMaps: intentToTaskMaps.length,
|
|
1783
|
+
serviceInstances: serviceInstances.length
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1609
1786
|
return {
|
|
1610
1787
|
...ctx,
|
|
1611
1788
|
signalToTaskMaps,
|
|
@@ -1646,8 +1823,11 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1646
1823
|
);
|
|
1647
1824
|
this.handleDeputyRegistrationTask = CadenzaService.createMetaTask(
|
|
1648
1825
|
"Handle Deputy Registration",
|
|
1649
|
-
(ctx) => {
|
|
1826
|
+
(ctx, emit) => {
|
|
1650
1827
|
const { serviceName } = ctx;
|
|
1828
|
+
if (!serviceName || serviceName === this.serviceName) {
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1651
1831
|
if (!this.deputies.has(serviceName)) this.deputies.set(serviceName, []);
|
|
1652
1832
|
this.deputies.get(serviceName).push({
|
|
1653
1833
|
serviceName,
|
|
@@ -1656,6 +1836,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1656
1836
|
localTaskName: ctx.localTaskName,
|
|
1657
1837
|
communicationType: ctx.communicationType
|
|
1658
1838
|
});
|
|
1839
|
+
this.ensureDependeeClientsForService(serviceName, emit, ctx);
|
|
1659
1840
|
}
|
|
1660
1841
|
).doOn("meta.deputy.created");
|
|
1661
1842
|
this.getAllInstances = CadenzaService.createMetaTask(
|
|
@@ -2208,9 +2389,29 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2208
2389
|
retryDelayFactor: 1.3
|
|
2209
2390
|
}
|
|
2210
2391
|
).emits("meta.service_registry.service_inserted").emitsOnFail("meta.service_registry.service_insertion_failed");
|
|
2211
|
-
|
|
2392
|
+
const insertServiceInstanceResolverTask = resolveServiceRegistryInsertTask(
|
|
2212
2393
|
"service_instance",
|
|
2213
|
-
{
|
|
2394
|
+
{
|
|
2395
|
+
onConflict: {
|
|
2396
|
+
target: ["uuid"],
|
|
2397
|
+
action: {
|
|
2398
|
+
do: "update",
|
|
2399
|
+
set: {
|
|
2400
|
+
process_pid: "excluded",
|
|
2401
|
+
is_primary: "excluded",
|
|
2402
|
+
service_name: "excluded",
|
|
2403
|
+
is_database: "excluded",
|
|
2404
|
+
is_frontend: "excluded",
|
|
2405
|
+
is_blocked: "excluded",
|
|
2406
|
+
is_non_responsive: "excluded",
|
|
2407
|
+
is_active: "excluded",
|
|
2408
|
+
last_active: "excluded",
|
|
2409
|
+
health: "excluded",
|
|
2410
|
+
deleted: "false"
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
},
|
|
2214
2415
|
{
|
|
2215
2416
|
inputSchema: {
|
|
2216
2417
|
type: "object",
|
|
@@ -2266,7 +2467,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2266
2467
|
retryCount: 5,
|
|
2267
2468
|
retryDelay: 1e3
|
|
2268
2469
|
}
|
|
2269
|
-
).
|
|
2470
|
+
).emitsOnFail("meta.service_registry.instance_insertion_failed");
|
|
2471
|
+
this.insertServiceInstanceTask = insertServiceInstanceResolverTask.then(
|
|
2270
2472
|
CadenzaService.createMetaTask(
|
|
2271
2473
|
"Setup service",
|
|
2272
2474
|
(ctx) => {
|
|
@@ -2283,6 +2485,21 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2283
2485
|
transports: ctx.__transportData ?? ctx.transportData ?? []
|
|
2284
2486
|
});
|
|
2285
2487
|
if (!normalizedLocalInstance?.uuid || !normalizedLocalInstance.serviceName) {
|
|
2488
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2489
|
+
console.log("[CADENZA_INSTANCE_DEBUG] setup_service_rejected_instance", {
|
|
2490
|
+
hasServiceInstance: !!serviceInstance,
|
|
2491
|
+
hasData: !!data,
|
|
2492
|
+
hasQueryDataData: !!queryData?.data,
|
|
2493
|
+
serviceInstanceKeys: serviceInstance && typeof serviceInstance === "object" ? Object.keys(serviceInstance) : [],
|
|
2494
|
+
dataKeys: data && typeof data === "object" ? Object.keys(data) : [],
|
|
2495
|
+
queryDataDataKeys: queryData?.data && typeof queryData.data === "object" ? Object.keys(queryData.data) : [],
|
|
2496
|
+
normalizedLocalInstance,
|
|
2497
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2498
|
+
errored: ctx.errored === true,
|
|
2499
|
+
error: ctx.__error ?? null,
|
|
2500
|
+
inquiryMeta: ctx.__inquiryMeta ?? null
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2286
2503
|
return false;
|
|
2287
2504
|
}
|
|
2288
2505
|
this.serviceInstanceId = normalizedLocalInstance.uuid;
|
|
@@ -2334,11 +2551,65 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2334
2551
|
).attachSignal("meta.service_registry.transport_registration_requested")
|
|
2335
2552
|
)
|
|
2336
2553
|
);
|
|
2554
|
+
CadenzaService.createMetaTask(
|
|
2555
|
+
"Retry local service instance registration after failed insert",
|
|
2556
|
+
(ctx) => {
|
|
2557
|
+
const registrationPayload = resolveServiceInstanceRegistrationPayload(
|
|
2558
|
+
ctx,
|
|
2559
|
+
this.serviceName,
|
|
2560
|
+
this.serviceInstanceId
|
|
2561
|
+
);
|
|
2562
|
+
if (!registrationPayload) {
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
const serviceName = String(
|
|
2566
|
+
registrationPayload.service_name ?? this.serviceName ?? ""
|
|
2567
|
+
).trim();
|
|
2568
|
+
if (!serviceName || serviceName !== this.serviceName) {
|
|
2569
|
+
return false;
|
|
2570
|
+
}
|
|
2571
|
+
CadenzaService.schedule(
|
|
2572
|
+
"meta.service_registry.instance_registration_requested",
|
|
2573
|
+
{
|
|
2574
|
+
...ctx,
|
|
2575
|
+
data: registrationPayload,
|
|
2576
|
+
__registrationData: registrationPayload,
|
|
2577
|
+
__serviceName: serviceName,
|
|
2578
|
+
__serviceInstanceId: registrationPayload.uuid
|
|
2579
|
+
},
|
|
2580
|
+
5e3
|
|
2581
|
+
);
|
|
2582
|
+
return true;
|
|
2583
|
+
},
|
|
2584
|
+
"Retries local service instance registration only after the previous insert attempt has failed.",
|
|
2585
|
+
{
|
|
2586
|
+
register: false,
|
|
2587
|
+
isHidden: true
|
|
2588
|
+
}
|
|
2589
|
+
).doOn("meta.service_registry.instance_insertion_failed");
|
|
2337
2590
|
CadenzaService.createMetaTask(
|
|
2338
2591
|
"Prepare service instance registration",
|
|
2339
2592
|
(ctx) => {
|
|
2593
|
+
const registrationPayload = resolveServiceInstanceRegistrationPayload(
|
|
2594
|
+
ctx,
|
|
2595
|
+
this.serviceName,
|
|
2596
|
+
this.serviceInstanceId
|
|
2597
|
+
);
|
|
2598
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2599
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_instance_registration", {
|
|
2600
|
+
serviceName: registrationPayload?.service_name ?? ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? null,
|
|
2601
|
+
serviceInstanceId: registrationPayload?.uuid ?? ctx.data?.uuid ?? ctx.__serviceInstanceId ?? this.serviceInstanceId ?? null,
|
|
2602
|
+
hasData: !!registrationPayload,
|
|
2603
|
+
dataKeys: registrationPayload && typeof registrationPayload === "object" ? Object.keys(registrationPayload) : [],
|
|
2604
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2605
|
+
skipRemoteExecution: ctx.__skipRemoteExecution === true
|
|
2606
|
+
});
|
|
2607
|
+
}
|
|
2608
|
+
if (!registrationPayload) {
|
|
2609
|
+
return false;
|
|
2610
|
+
}
|
|
2340
2611
|
const serviceName = String(
|
|
2341
|
-
|
|
2612
|
+
registrationPayload.service_name ?? ctx.__serviceName ?? this.serviceName ?? ""
|
|
2342
2613
|
).trim();
|
|
2343
2614
|
if (serviceName === "CadenzaDB" && !CadenzaService.getLocalCadenzaDBInsertTask("service_instance")) {
|
|
2344
2615
|
CadenzaService.schedule(
|
|
@@ -2348,7 +2619,16 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2348
2619
|
);
|
|
2349
2620
|
return false;
|
|
2350
2621
|
}
|
|
2351
|
-
return
|
|
2622
|
+
return {
|
|
2623
|
+
...ctx,
|
|
2624
|
+
data: registrationPayload,
|
|
2625
|
+
__registrationData: {
|
|
2626
|
+
...ctx.__registrationData ?? {},
|
|
2627
|
+
...registrationPayload
|
|
2628
|
+
},
|
|
2629
|
+
__serviceName: serviceName,
|
|
2630
|
+
__serviceInstanceId: registrationPayload.uuid
|
|
2631
|
+
};
|
|
2352
2632
|
},
|
|
2353
2633
|
"Waits for the exact local CadenzaDB service instance insert task during self-bootstrap."
|
|
2354
2634
|
).doOn("meta.service_registry.instance_registration_requested").then(this.insertServiceInstanceTask);
|
|
@@ -2529,21 +2809,40 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2529
2809
|
return [];
|
|
2530
2810
|
}
|
|
2531
2811
|
normalizeSignalMaps(ctx) {
|
|
2532
|
-
|
|
2812
|
+
const arrayPayload = this.readArrayPayload(ctx, [
|
|
2533
2813
|
"signalToTaskMaps",
|
|
2534
2814
|
"signal_to_task_maps",
|
|
2535
2815
|
"signalToTaskMap",
|
|
2536
2816
|
"signal_to_task_map"
|
|
2537
|
-
])
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2817
|
+
]);
|
|
2818
|
+
if (arrayPayload.length > 0) {
|
|
2819
|
+
return arrayPayload.map((map) => ({
|
|
2820
|
+
signalName: String(
|
|
2821
|
+
map.signalName ?? map.signal_name ?? ""
|
|
2822
|
+
).trim(),
|
|
2823
|
+
serviceName: String(
|
|
2824
|
+
map.serviceName ?? map.service_name ?? ""
|
|
2825
|
+
).trim(),
|
|
2826
|
+
isGlobal: Boolean(map.isGlobal ?? map.is_global ?? false),
|
|
2827
|
+
deleted: Boolean(map.deleted)
|
|
2828
|
+
})).filter((map) => map.signalName && map.serviceName);
|
|
2829
|
+
}
|
|
2830
|
+
const single = ctx.signalToTaskMap ?? ctx.signal_to_task_map ?? ctx.data ?? (ctx.signalName ?? ctx.signal_name ? ctx : void 0);
|
|
2831
|
+
if (!single || typeof single !== "object") {
|
|
2832
|
+
return [];
|
|
2833
|
+
}
|
|
2834
|
+
return [
|
|
2835
|
+
{
|
|
2836
|
+
signalName: String(
|
|
2837
|
+
single.signalName ?? single.signal_name ?? ""
|
|
2838
|
+
).trim(),
|
|
2839
|
+
serviceName: String(
|
|
2840
|
+
single.serviceName ?? single.service_name ?? ""
|
|
2841
|
+
).trim(),
|
|
2842
|
+
isGlobal: Boolean(single.isGlobal ?? single.is_global ?? false),
|
|
2843
|
+
deleted: Boolean(single.deleted)
|
|
2844
|
+
}
|
|
2845
|
+
].filter((map) => map.signalName && map.serviceName);
|
|
2547
2846
|
}
|
|
2548
2847
|
normalizeIntentMaps(ctx) {
|
|
2549
2848
|
const arrayPayload = this.readArrayPayload(ctx, [
|
|
@@ -2658,7 +2957,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2658
2957
|
)?.destroy();
|
|
2659
2958
|
this.gatheredSyncTransmissionServices.delete(serviceName);
|
|
2660
2959
|
}
|
|
2661
|
-
if (createdRecipients.length > 0
|
|
2960
|
+
if (createdRecipients.length > 0) {
|
|
2662
2961
|
emit("meta.cadenza_db.sync_tick", {
|
|
2663
2962
|
__syncing: true,
|
|
2664
2963
|
__reason: "gathered_sync_transmissions_reconciled"
|
|
@@ -2704,6 +3003,15 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2704
3003
|
};
|
|
2705
3004
|
this.remoteIntentDeputiesByKey.set(key, descriptor);
|
|
2706
3005
|
this.remoteIntentDeputiesByTask.set(deputyTask, descriptor);
|
|
3006
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
3007
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] register_remote_intent_deputy", {
|
|
3008
|
+
localServiceName: this.serviceName,
|
|
3009
|
+
intentName: map.intentName,
|
|
3010
|
+
remoteServiceName: map.serviceName,
|
|
3011
|
+
remoteTaskName: map.taskName,
|
|
3012
|
+
remoteTaskVersion: map.taskVersion
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
2707
3015
|
}
|
|
2708
3016
|
unregisterRemoteIntentDeputy(map) {
|
|
2709
3017
|
const key = this.buildRemoteIntentDeputyKey(map);
|
|
@@ -2733,6 +3041,56 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2733
3041
|
}
|
|
2734
3042
|
}
|
|
2735
3043
|
}
|
|
3044
|
+
registerBootstrapFullSyncDeputies(emit, ctx) {
|
|
3045
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
3046
|
+
return false;
|
|
3047
|
+
}
|
|
3048
|
+
CadenzaService.inquiryBroker.addIntent({
|
|
3049
|
+
name: META_SERVICE_REGISTRY_FULL_SYNC_INTENT
|
|
3050
|
+
});
|
|
3051
|
+
for (const taskName of BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS) {
|
|
3052
|
+
this.registerRemoteIntentDeputy({
|
|
3053
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
3054
|
+
serviceName: "CadenzaDB",
|
|
3055
|
+
taskName,
|
|
3056
|
+
taskVersion: 1
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
this.ensureDependeeClientsForService("CadenzaDB", emit, ctx);
|
|
3060
|
+
return true;
|
|
3061
|
+
}
|
|
3062
|
+
hasBootstrapFullSyncDeputies() {
|
|
3063
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
3064
|
+
return true;
|
|
3065
|
+
}
|
|
3066
|
+
return BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS.every(
|
|
3067
|
+
(taskName) => this.remoteIntentDeputiesByKey.has(
|
|
3068
|
+
this.buildRemoteIntentDeputyKey({
|
|
3069
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
3070
|
+
serviceName: "CadenzaDB",
|
|
3071
|
+
taskName,
|
|
3072
|
+
taskVersion: 1
|
|
3073
|
+
})
|
|
3074
|
+
)
|
|
3075
|
+
);
|
|
3076
|
+
}
|
|
3077
|
+
scheduleEarlyFullSyncRequests(reason) {
|
|
3078
|
+
for (const delayMs of EARLY_FULL_SYNC_DELAYS_MS) {
|
|
3079
|
+
CadenzaService.schedule(
|
|
3080
|
+
"meta.sync_requested",
|
|
3081
|
+
{
|
|
3082
|
+
__syncing: false,
|
|
3083
|
+
__reason: reason
|
|
3084
|
+
},
|
|
3085
|
+
delayMs
|
|
3086
|
+
);
|
|
3087
|
+
}
|
|
3088
|
+
return true;
|
|
3089
|
+
}
|
|
3090
|
+
bootstrapFullSync(emit, ctx, reason = "local_instance_inserted") {
|
|
3091
|
+
this.registerBootstrapFullSyncDeputies(emit, ctx);
|
|
3092
|
+
return this.scheduleEarlyFullSyncRequests(reason);
|
|
3093
|
+
}
|
|
2736
3094
|
getInquiryResponderDescriptor(task) {
|
|
2737
3095
|
const remote = this.remoteIntentDeputiesByTask.get(task);
|
|
2738
3096
|
if (remote) {
|
|
@@ -2761,6 +3119,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2761
3119
|
}
|
|
2762
3120
|
return this.getInstance(this.serviceName, this.serviceInstanceId);
|
|
2763
3121
|
}
|
|
3122
|
+
hasLocalInstanceRegistered() {
|
|
3123
|
+
return Boolean(this.getLocalInstance());
|
|
3124
|
+
}
|
|
2764
3125
|
summarizeTransportForDebug(transport) {
|
|
2765
3126
|
if (!transport) {
|
|
2766
3127
|
return void 0;
|
|
@@ -2909,7 +3270,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2909
3270
|
return communicationTypes;
|
|
2910
3271
|
}
|
|
2911
3272
|
ensureDependeeClientForInstance(instance, emit, ctx) {
|
|
2912
|
-
if (!instance || instance.uuid === this.serviceInstanceId || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
3273
|
+
if (!instance || instance.uuid === this.serviceInstanceId || instance.serviceName === this.serviceName || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
2913
3274
|
return false;
|
|
2914
3275
|
}
|
|
2915
3276
|
if (!this.deputies.has(instance.serviceName) && !this.remoteIntents.has(instance.serviceName) && !this.remoteSignals.has(instance.serviceName)) {
|
|
@@ -2937,6 +3298,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2937
3298
|
return true;
|
|
2938
3299
|
}
|
|
2939
3300
|
ensureDependeeClientsForService(serviceName, emit, ctx) {
|
|
3301
|
+
if (!serviceName || serviceName === this.serviceName) {
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
2940
3304
|
for (const instance of this.instances.get(serviceName) ?? []) {
|
|
2941
3305
|
this.ensureDependeeClientForInstance(instance, emit, ctx);
|
|
2942
3306
|
}
|
|
@@ -3729,7 +4093,7 @@ var SignalTransmissionTask = class extends import_core2.Task {
|
|
|
3729
4093
|
execute(context, emit, inquire, progressCallback) {
|
|
3730
4094
|
const ctx = context.getContext();
|
|
3731
4095
|
const metadata = context.getMetadata();
|
|
3732
|
-
const deputyContext = {
|
|
4096
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
3733
4097
|
__localTaskName: this.name,
|
|
3734
4098
|
__localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
3735
4099
|
__serviceName: this.serviceName,
|
|
@@ -3742,12 +4106,13 @@ var SignalTransmissionTask = class extends import_core2.Task {
|
|
|
3742
4106
|
__signalName: this.signalName,
|
|
3743
4107
|
__signalEmissionId: metadata.__signalEmission?.uuid,
|
|
3744
4108
|
...ctx
|
|
3745
|
-
};
|
|
4109
|
+
});
|
|
3746
4110
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
3747
4111
|
}
|
|
3748
4112
|
};
|
|
3749
4113
|
|
|
3750
4114
|
// src/network/RestController.browser.ts
|
|
4115
|
+
var FETCH_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3751
4116
|
var RestController = class _RestController {
|
|
3752
4117
|
constructor() {
|
|
3753
4118
|
this.fetchClientDiagnostics = /* @__PURE__ */ new Map();
|
|
@@ -3793,7 +4158,15 @@ var RestController = class _RestController {
|
|
|
3793
4158
|
is_blocked: false,
|
|
3794
4159
|
health: {}
|
|
3795
4160
|
},
|
|
3796
|
-
__transportData:
|
|
4161
|
+
__transportData: Array.isArray(ctx.__declaredTransports) ? ctx.__declaredTransports.map((transport) => ({
|
|
4162
|
+
uuid: transport.uuid,
|
|
4163
|
+
service_instance_id: ctx.__serviceInstanceId,
|
|
4164
|
+
role: transport.role,
|
|
4165
|
+
origin: transport.origin,
|
|
4166
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
4167
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
4168
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
4169
|
+
})) : []
|
|
3797
4170
|
});
|
|
3798
4171
|
return true;
|
|
3799
4172
|
},
|
|
@@ -3808,6 +4181,7 @@ var RestController = class _RestController {
|
|
|
3808
4181
|
if (!serviceName || !URL2 || !fetchId) {
|
|
3809
4182
|
return false;
|
|
3810
4183
|
}
|
|
4184
|
+
const clientTaskSuffix = `${URL2} (${fetchId})`;
|
|
3811
4185
|
const fetchDiagnostics = this.ensureFetchClientDiagnostics(
|
|
3812
4186
|
fetchId,
|
|
3813
4187
|
serviceName,
|
|
@@ -3815,11 +4189,11 @@ var RestController = class _RestController {
|
|
|
3815
4189
|
);
|
|
3816
4190
|
fetchDiagnostics.destroyed = false;
|
|
3817
4191
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3818
|
-
if (CadenzaService.get(`Send Handshake to ${
|
|
4192
|
+
if (CadenzaService.get(`Send Handshake to ${clientTaskSuffix}`)) {
|
|
3819
4193
|
return;
|
|
3820
4194
|
}
|
|
3821
4195
|
const handshakeTask = CadenzaService.createMetaTask(
|
|
3822
|
-
`Send Handshake to ${
|
|
4196
|
+
`Send Handshake to ${clientTaskSuffix}`,
|
|
3823
4197
|
async (handshakeCtx, emit) => {
|
|
3824
4198
|
try {
|
|
3825
4199
|
const response = await this.fetchDataWithTimeout(
|
|
@@ -3831,7 +4205,7 @@ var RestController = class _RestController {
|
|
|
3831
4205
|
method: "POST",
|
|
3832
4206
|
body: JSON.stringify(handshakeCtx.handshakeData)
|
|
3833
4207
|
},
|
|
3834
|
-
|
|
4208
|
+
FETCH_HANDSHAKE_TIMEOUT_MS
|
|
3835
4209
|
);
|
|
3836
4210
|
if (response.__status !== "success") {
|
|
3837
4211
|
const error = response.__error ?? `Failed to connect to service ${serviceName} ${handshakeCtx.serviceInstanceId}`;
|
|
@@ -3867,13 +4241,19 @@ var RestController = class _RestController {
|
|
|
3867
4241
|
return handshakeCtx;
|
|
3868
4242
|
},
|
|
3869
4243
|
"Sends handshake request",
|
|
3870
|
-
{
|
|
4244
|
+
{
|
|
4245
|
+
retryCount: 5,
|
|
4246
|
+
retryDelay: 1e3,
|
|
4247
|
+
retryDelayFactor: 1.5,
|
|
4248
|
+
register: false,
|
|
4249
|
+
isHidden: true
|
|
4250
|
+
}
|
|
3871
4251
|
).doOn(`meta.fetch.handshake_requested:${fetchId}`).emits("meta.fetch.handshake_complete").attachSignal(
|
|
3872
4252
|
"meta.fetch.handshake_failed",
|
|
3873
4253
|
"global.meta.fetch.service_communication_established"
|
|
3874
4254
|
);
|
|
3875
4255
|
const delegateTask = CadenzaService.createMetaTask(
|
|
3876
|
-
`Delegate flow to REST server ${
|
|
4256
|
+
`Delegate flow to REST server ${clientTaskSuffix}`,
|
|
3877
4257
|
async (delegateCtx, emit) => {
|
|
3878
4258
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
3879
4259
|
return;
|
|
@@ -3910,13 +4290,17 @@ var RestController = class _RestController {
|
|
|
3910
4290
|
}
|
|
3911
4291
|
return resultContext;
|
|
3912
4292
|
},
|
|
3913
|
-
"Sends delegation request"
|
|
4293
|
+
"Sends delegation request",
|
|
4294
|
+
{
|
|
4295
|
+
register: false,
|
|
4296
|
+
isHidden: true
|
|
4297
|
+
}
|
|
3914
4298
|
).doOn(
|
|
3915
4299
|
`meta.service_registry.selected_instance_for_fetch:${fetchId}`,
|
|
3916
4300
|
`meta.service_registry.socket_failed:${fetchId}`
|
|
3917
4301
|
).emitsOnFail("meta.fetch.delegate_failed").attachSignal("meta.fetch.delegated");
|
|
3918
4302
|
const transmitTask = CadenzaService.createMetaTask(
|
|
3919
|
-
`Transmit signal to server ${
|
|
4303
|
+
`Transmit signal to server ${clientTaskSuffix}`,
|
|
3920
4304
|
async (signalCtx, emit) => {
|
|
3921
4305
|
if (signalCtx.__signalName === void 0) {
|
|
3922
4306
|
return;
|
|
@@ -3951,10 +4335,14 @@ var RestController = class _RestController {
|
|
|
3951
4335
|
}
|
|
3952
4336
|
return response;
|
|
3953
4337
|
},
|
|
3954
|
-
"Sends signal request"
|
|
4338
|
+
"Sends signal request",
|
|
4339
|
+
{
|
|
4340
|
+
register: false,
|
|
4341
|
+
isHidden: true
|
|
4342
|
+
}
|
|
3955
4343
|
).doOn(`meta.service_registry.selected_instance_for_fetch:${fetchId}`).emitsOnFail("meta.fetch.signal_transmission_failed").attachSignal("meta.fetch.transmitted");
|
|
3956
4344
|
const statusTask = CadenzaService.createMetaTask(
|
|
3957
|
-
`Request status from ${
|
|
4345
|
+
`Request status from ${clientTaskSuffix}`,
|
|
3958
4346
|
async (statusCtx) => {
|
|
3959
4347
|
fetchDiagnostics.statusChecks++;
|
|
3960
4348
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -3977,17 +4365,29 @@ var RestController = class _RestController {
|
|
|
3977
4365
|
};
|
|
3978
4366
|
}
|
|
3979
4367
|
},
|
|
3980
|
-
"Requests status"
|
|
4368
|
+
"Requests status",
|
|
4369
|
+
{
|
|
4370
|
+
register: false,
|
|
4371
|
+
isHidden: true
|
|
4372
|
+
}
|
|
3981
4373
|
).doOn("meta.fetch.status_check_requested").emits("meta.fetch.status_checked").emitsOnFail("meta.fetch.status_check_failed");
|
|
3982
|
-
CadenzaService.createEphemeralMetaTask(
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
4374
|
+
CadenzaService.createEphemeralMetaTask(
|
|
4375
|
+
`Destroy fetch client ${fetchId}`,
|
|
4376
|
+
() => {
|
|
4377
|
+
fetchDiagnostics.connected = false;
|
|
4378
|
+
fetchDiagnostics.destroyed = true;
|
|
4379
|
+
fetchDiagnostics.updatedAt = Date.now();
|
|
4380
|
+
handshakeTask.destroy();
|
|
4381
|
+
delegateTask.destroy();
|
|
4382
|
+
transmitTask.destroy();
|
|
4383
|
+
statusTask.destroy();
|
|
4384
|
+
},
|
|
4385
|
+
"",
|
|
4386
|
+
{
|
|
4387
|
+
register: false,
|
|
4388
|
+
isHidden: true
|
|
4389
|
+
}
|
|
4390
|
+
).doOn(
|
|
3991
4391
|
`meta.fetch.destroy_requested:${fetchId}`,
|
|
3992
4392
|
`meta.socket_client.disconnected:${fetchId}`,
|
|
3993
4393
|
`meta.fetch.handshake_failed:${fetchId}`
|
|
@@ -5394,7 +5794,11 @@ var SocketController = class _SocketController {
|
|
|
5394
5794
|
}
|
|
5395
5795
|
);
|
|
5396
5796
|
},
|
|
5397
|
-
"Handshakes with socket server"
|
|
5797
|
+
"Handshakes with socket server",
|
|
5798
|
+
{
|
|
5799
|
+
register: false,
|
|
5800
|
+
isHidden: true
|
|
5801
|
+
}
|
|
5398
5802
|
).doOn(`meta.socket_client.connected:${fetchId}`);
|
|
5399
5803
|
runtimeHandle.delegateTask = CadenzaService.createMetaTask(
|
|
5400
5804
|
`Delegate flow to Socket service ${url}`,
|
|
@@ -5472,7 +5876,11 @@ var SocketController = class _SocketController {
|
|
|
5472
5876
|
}
|
|
5473
5877
|
}
|
|
5474
5878
|
},
|
|
5475
|
-
`Delegate flow to service ${serviceName} with address ${url}
|
|
5879
|
+
`Delegate flow to service ${serviceName} with address ${url}`,
|
|
5880
|
+
{
|
|
5881
|
+
register: false,
|
|
5882
|
+
isHidden: true
|
|
5883
|
+
}
|
|
5476
5884
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal(
|
|
5477
5885
|
"meta.socket_client.delegated",
|
|
5478
5886
|
"meta.socket_shutdown_requested"
|
|
@@ -5496,7 +5904,11 @@ var SocketController = class _SocketController {
|
|
|
5496
5904
|
}
|
|
5497
5905
|
return response;
|
|
5498
5906
|
},
|
|
5499
|
-
`Transmits signal to service ${serviceName} with address ${url}
|
|
5907
|
+
`Transmits signal to service ${serviceName} with address ${url}`,
|
|
5908
|
+
{
|
|
5909
|
+
register: false,
|
|
5910
|
+
isHidden: true
|
|
5911
|
+
}
|
|
5500
5912
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal("meta.socket_client.transmitted");
|
|
5501
5913
|
CadenzaService.createEphemeralMetaTask(
|
|
5502
5914
|
`Shutdown SocketClient ${url}`,
|
|
@@ -5540,7 +5952,11 @@ var SocketController = class _SocketController {
|
|
|
5540
5952
|
fetchId
|
|
5541
5953
|
});
|
|
5542
5954
|
},
|
|
5543
|
-
"Shuts down the socket client"
|
|
5955
|
+
"Shuts down the socket client",
|
|
5956
|
+
{
|
|
5957
|
+
register: false,
|
|
5958
|
+
isHidden: true
|
|
5959
|
+
}
|
|
5544
5960
|
).doOn(
|
|
5545
5961
|
`meta.socket_shutdown_requested:${fetchId}`,
|
|
5546
5962
|
`meta.socket_client.disconnected:${fetchId}`,
|
|
@@ -5804,10 +6220,18 @@ function decomposeSignalName(signalName) {
|
|
|
5804
6220
|
|
|
5805
6221
|
// src/signals/SignalController.ts
|
|
5806
6222
|
function buildSignalDatabaseTriggerContext(data) {
|
|
6223
|
+
const onConflict = {
|
|
6224
|
+
target: ["name"],
|
|
6225
|
+
action: {
|
|
6226
|
+
do: "nothing"
|
|
6227
|
+
}
|
|
6228
|
+
};
|
|
5807
6229
|
return {
|
|
5808
6230
|
data: { ...data },
|
|
6231
|
+
onConflict,
|
|
5809
6232
|
queryData: {
|
|
5810
|
-
data: { ...data }
|
|
6233
|
+
data: { ...data },
|
|
6234
|
+
onConflict
|
|
5811
6235
|
}
|
|
5812
6236
|
};
|
|
5813
6237
|
}
|
|
@@ -5834,16 +6258,28 @@ var SignalController = class _SignalController {
|
|
|
5834
6258
|
CadenzaService.createMetaTask(
|
|
5835
6259
|
"Handle Signal Registration",
|
|
5836
6260
|
(ctx, emit) => {
|
|
6261
|
+
if (!CadenzaService.hasCompletedBootstrapSync()) {
|
|
6262
|
+
return false;
|
|
6263
|
+
}
|
|
5837
6264
|
const { signalName } = ctx;
|
|
6265
|
+
const signalObserver = CadenzaService.signalBroker.signalObservers?.get(
|
|
6266
|
+
signalName
|
|
6267
|
+
);
|
|
6268
|
+
if (signalObserver?.registered || signalObserver?.registrationRequested) {
|
|
6269
|
+
return false;
|
|
6270
|
+
}
|
|
6271
|
+
if (signalObserver) {
|
|
6272
|
+
signalObserver.registrationRequested = true;
|
|
6273
|
+
}
|
|
5838
6274
|
const { isMeta, isGlobal, domain, action } = decomposeSignalName(signalName);
|
|
5839
6275
|
emit(
|
|
5840
6276
|
"global.meta.signal_controller.signal_added",
|
|
5841
6277
|
buildSignalDatabaseTriggerContext({
|
|
5842
6278
|
name: signalName,
|
|
5843
|
-
isGlobal,
|
|
6279
|
+
is_global: isGlobal,
|
|
5844
6280
|
domain,
|
|
5845
6281
|
action,
|
|
5846
|
-
isMeta
|
|
6282
|
+
is_meta: isMeta
|
|
5847
6283
|
})
|
|
5848
6284
|
);
|
|
5849
6285
|
return ctx;
|
|
@@ -5852,12 +6288,35 @@ var SignalController = class _SignalController {
|
|
|
5852
6288
|
).doOn("meta.signal_broker.added").attachSignal("global.meta.signal_controller.signal_added");
|
|
5853
6289
|
CadenzaService.createMetaTask(
|
|
5854
6290
|
"Add data to signal emission",
|
|
5855
|
-
(ctx) => {
|
|
6291
|
+
(ctx, emit) => {
|
|
5856
6292
|
const signalEmission = ctx.__signalEmission;
|
|
5857
6293
|
delete ctx.__signalEmission;
|
|
5858
6294
|
if (!signalEmission) {
|
|
5859
6295
|
return false;
|
|
5860
6296
|
}
|
|
6297
|
+
if (typeof signalEmission.signalName === "string" && signalEmission.signalName.trim().length > 0 && !CadenzaService.signalBroker.signalObservers?.has(signalEmission.signalName)) {
|
|
6298
|
+
CadenzaService.signalBroker.addSignal(signalEmission.signalName);
|
|
6299
|
+
} else {
|
|
6300
|
+
const signalObserver = CadenzaService.signalBroker.signalObservers?.get(
|
|
6301
|
+
signalEmission.signalName
|
|
6302
|
+
);
|
|
6303
|
+
if (signalObserver && signalObserver.registered !== true && signalObserver.registrationRequested !== true && CadenzaService.hasCompletedBootstrapSync()) {
|
|
6304
|
+
signalObserver.registrationRequested = true;
|
|
6305
|
+
const { isMeta, isGlobal, domain, action } = decomposeSignalName(
|
|
6306
|
+
signalEmission.signalName
|
|
6307
|
+
);
|
|
6308
|
+
emit(
|
|
6309
|
+
"global.meta.signal_controller.signal_added",
|
|
6310
|
+
buildSignalDatabaseTriggerContext({
|
|
6311
|
+
name: signalEmission.signalName,
|
|
6312
|
+
is_global: isGlobal,
|
|
6313
|
+
domain,
|
|
6314
|
+
action,
|
|
6315
|
+
is_meta: isMeta
|
|
6316
|
+
})
|
|
6317
|
+
);
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
5861
6320
|
return {
|
|
5862
6321
|
data: {
|
|
5863
6322
|
uuid: signalEmission.uuid,
|
|
@@ -6212,10 +6671,10 @@ function registerActorSessionPersistenceTasks() {
|
|
|
6212
6671
|
}
|
|
6213
6672
|
|
|
6214
6673
|
// src/graph/controllers/GraphMetadataController.ts
|
|
6215
|
-
function buildDatabaseTriggerContext(data, filter, extra = {}) {
|
|
6674
|
+
function buildDatabaseTriggerContext(data, filter, extra = {}, queryExtra = {}) {
|
|
6216
6675
|
const nextData = data && typeof data === "object" ? { ...data } : void 0;
|
|
6217
6676
|
const nextFilter = filter && typeof filter === "object" ? { ...filter } : void 0;
|
|
6218
|
-
const queryData = {};
|
|
6677
|
+
const queryData = { ...queryExtra };
|
|
6219
6678
|
if (nextData !== void 0) {
|
|
6220
6679
|
queryData.data = nextData;
|
|
6221
6680
|
}
|
|
@@ -6229,33 +6688,125 @@ function buildDatabaseTriggerContext(data, filter, extra = {}) {
|
|
|
6229
6688
|
...Object.keys(queryData).length > 0 ? { queryData } : {}
|
|
6230
6689
|
};
|
|
6231
6690
|
}
|
|
6691
|
+
function resolveTaskFromMetadataContext(ctx) {
|
|
6692
|
+
const taskName = String(
|
|
6693
|
+
ctx?.taskName ?? ctx?.data?.taskName ?? ctx?.data?.task_name ?? ctx?.filter?.taskName ?? ctx?.filter?.task_name ?? ""
|
|
6694
|
+
);
|
|
6695
|
+
return taskName ? CadenzaService.get(taskName) : void 0;
|
|
6696
|
+
}
|
|
6697
|
+
function resolveTaskByName(name) {
|
|
6698
|
+
const taskName = String(name ?? "");
|
|
6699
|
+
return taskName ? CadenzaService.get(taskName) : void 0;
|
|
6700
|
+
}
|
|
6701
|
+
function resolvePredecessorTaskFromMetadataContext(ctx) {
|
|
6702
|
+
return resolveTaskByName(
|
|
6703
|
+
ctx?.predecessorTaskName ?? ctx?.data?.predecessorTaskName ?? ctx?.data?.predecessor_task_name ?? ctx?.filter?.predecessorTaskName ?? ctx?.filter?.predecessor_task_name
|
|
6704
|
+
);
|
|
6705
|
+
}
|
|
6706
|
+
function shouldSkipDirectTaskMetadata(task) {
|
|
6707
|
+
return !task || !task.register || task.isHidden || task.isDeputy;
|
|
6708
|
+
}
|
|
6709
|
+
function shouldPersistBusinessTaskExecution(task) {
|
|
6710
|
+
return !!task && task.register && !task.isHidden && !task.isMeta && !task.isSubMeta && !task.isDeputy;
|
|
6711
|
+
}
|
|
6712
|
+
function shouldEmitDirectPrimitiveMetadata() {
|
|
6713
|
+
return CadenzaService.hasCompletedBootstrapSync();
|
|
6714
|
+
}
|
|
6715
|
+
function shouldPersistBusinessInquiry(ctx) {
|
|
6716
|
+
const inquiryName = String(
|
|
6717
|
+
ctx?.data?.name ?? ctx?.inquiry ?? ctx?.data?.metadata?.inquiryMeta?.inquiry ?? ""
|
|
6718
|
+
);
|
|
6719
|
+
if (!inquiryName) {
|
|
6720
|
+
return false;
|
|
6721
|
+
}
|
|
6722
|
+
return !isMetaIntentName(inquiryName) && ctx?.data?.isMeta !== true && ctx?.data?.is_meta !== true;
|
|
6723
|
+
}
|
|
6724
|
+
function shouldPersistRoutineExecution(ctx) {
|
|
6725
|
+
if (ctx?.data?.isMeta === true || ctx?.data?.is_meta === true) {
|
|
6726
|
+
return false;
|
|
6727
|
+
}
|
|
6728
|
+
const routineTask = resolveTaskByName(ctx?.data?.name);
|
|
6729
|
+
if (routineTask) {
|
|
6730
|
+
return shouldPersistBusinessTaskExecution(routineTask);
|
|
6731
|
+
}
|
|
6732
|
+
return true;
|
|
6733
|
+
}
|
|
6734
|
+
function shouldPersistTaskExecutionMetadata(ctx) {
|
|
6735
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6736
|
+
return shouldPersistBusinessTaskExecution(task);
|
|
6737
|
+
}
|
|
6738
|
+
function shouldPersistTaskExecutionMap(ctx) {
|
|
6739
|
+
return shouldPersistBusinessTaskExecution(resolveTaskFromMetadataContext(ctx)) && shouldPersistBusinessTaskExecution(resolvePredecessorTaskFromMetadataContext(ctx));
|
|
6740
|
+
}
|
|
6741
|
+
function hasInquiryLink(data) {
|
|
6742
|
+
const metaContext = data?.metaContext ?? data?.meta_context;
|
|
6743
|
+
const directInquiryId = metaContext?.__inquiryId ?? metaContext?.__metadata?.__inquiryId;
|
|
6744
|
+
return typeof directInquiryId === "string" && directInquiryId.length > 0;
|
|
6745
|
+
}
|
|
6232
6746
|
var GraphMetadataController = class _GraphMetadataController {
|
|
6233
6747
|
static get instance() {
|
|
6234
6748
|
if (!this._instance) this._instance = new _GraphMetadataController();
|
|
6235
6749
|
return this._instance;
|
|
6236
6750
|
}
|
|
6237
6751
|
constructor() {
|
|
6752
|
+
const buildOnConflictDoNothing = (target) => ({
|
|
6753
|
+
target,
|
|
6754
|
+
action: {
|
|
6755
|
+
do: "nothing"
|
|
6756
|
+
}
|
|
6757
|
+
});
|
|
6238
6758
|
CadenzaService.createMetaTask("Handle task creation", (ctx) => {
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6759
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6760
|
+
return false;
|
|
6761
|
+
}
|
|
6762
|
+
const taskName = String(ctx.data?.name ?? ctx.data?.taskName ?? "");
|
|
6763
|
+
const task = taskName ? CadenzaService.get(taskName) : void 0;
|
|
6764
|
+
const onConflict = buildOnConflictDoNothing([
|
|
6765
|
+
"name",
|
|
6766
|
+
"service_name",
|
|
6767
|
+
"version"
|
|
6768
|
+
]);
|
|
6769
|
+
if (shouldSkipDirectTaskMetadata(task) || task?.registered || task?.registrationRequested) {
|
|
6770
|
+
return false;
|
|
6771
|
+
}
|
|
6772
|
+
if (task) {
|
|
6773
|
+
task.registrationRequested = true;
|
|
6774
|
+
}
|
|
6245
6775
|
return buildDatabaseTriggerContext(
|
|
6246
|
-
ctx.data ?? void 0,
|
|
6247
6776
|
{
|
|
6248
|
-
...ctx.
|
|
6777
|
+
...ctx.data,
|
|
6249
6778
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6250
|
-
}
|
|
6779
|
+
},
|
|
6780
|
+
void 0,
|
|
6781
|
+
{ onConflict },
|
|
6782
|
+
{ onConflict }
|
|
6783
|
+
);
|
|
6784
|
+
}).doOn("meta.task.created").emits("global.meta.graph_metadata.task_created");
|
|
6785
|
+
CadenzaService.createMetaTask("Handle task update", (ctx) => {
|
|
6786
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6787
|
+
return false;
|
|
6788
|
+
}
|
|
6789
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6790
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6791
|
+
return false;
|
|
6792
|
+
}
|
|
6793
|
+
return buildDatabaseTriggerContext(
|
|
6794
|
+
ctx.data ?? void 0,
|
|
6795
|
+
{
|
|
6796
|
+
...ctx.filter,
|
|
6797
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6798
|
+
}
|
|
6251
6799
|
);
|
|
6252
6800
|
}).doOn("meta.task.layer_index_changed", "meta.task.destroyed").emits("global.meta.graph_metadata.task_updated");
|
|
6253
6801
|
CadenzaService.createMetaTask("Handle task relationship creation", (ctx) => {
|
|
6802
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6803
|
+
return false;
|
|
6804
|
+
}
|
|
6254
6805
|
const taskName = ctx.data?.taskName ?? ctx.data?.task_name;
|
|
6255
6806
|
const predecessorTaskName = ctx.data?.predecessorTaskName ?? ctx.data?.predecessor_task_name;
|
|
6256
6807
|
const task = taskName ? CadenzaService.get(taskName) : void 0;
|
|
6257
6808
|
const predecessorTask = predecessorTaskName ? CadenzaService.get(predecessorTaskName) : void 0;
|
|
6258
|
-
if (!task?.registered || !predecessorTask?.registered) {
|
|
6809
|
+
if (shouldSkipDirectTaskMetadata(task) || shouldSkipDirectTaskMetadata(predecessorTask) || !task?.registered || !predecessorTask?.registered) {
|
|
6259
6810
|
return false;
|
|
6260
6811
|
}
|
|
6261
6812
|
return buildDatabaseTriggerContext({
|
|
@@ -6268,14 +6819,35 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6268
6819
|
CadenzaService.log(`Error in task ${ctx.data.taskName}`, ctx.data, "error");
|
|
6269
6820
|
}).doOn("meta.node.errored");
|
|
6270
6821
|
CadenzaService.createMetaTask("Handle task signal observation", (ctx) => {
|
|
6271
|
-
|
|
6822
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6823
|
+
return false;
|
|
6824
|
+
}
|
|
6825
|
+
const signalName = String(
|
|
6826
|
+
ctx.signalName ?? ctx.data?.signalName ?? ""
|
|
6827
|
+
).split(":")[0];
|
|
6828
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6829
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6830
|
+
return false;
|
|
6831
|
+
}
|
|
6832
|
+
if (task?.registered && task.registeredSignals.has(signalName)) {
|
|
6833
|
+
return false;
|
|
6834
|
+
}
|
|
6835
|
+
const isGlobal = signalName.startsWith("global.");
|
|
6272
6836
|
return buildDatabaseTriggerContext({
|
|
6273
6837
|
...ctx.data,
|
|
6838
|
+
signalName,
|
|
6274
6839
|
isGlobal,
|
|
6275
6840
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6276
6841
|
});
|
|
6277
6842
|
}).doOn("meta.task.observed_signal").emits("global.meta.graph_metadata.task_signal_observed");
|
|
6278
6843
|
CadenzaService.createMetaTask("Handle task signal attachment", (ctx) => {
|
|
6844
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6845
|
+
return false;
|
|
6846
|
+
}
|
|
6847
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6848
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6849
|
+
return false;
|
|
6850
|
+
}
|
|
6279
6851
|
return buildDatabaseTriggerContext(
|
|
6280
6852
|
ctx.data ?? void 0,
|
|
6281
6853
|
{
|
|
@@ -6284,7 +6856,34 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6284
6856
|
}
|
|
6285
6857
|
);
|
|
6286
6858
|
}).doOn("meta.task.attached_signal").emits("global.meta.graph_metadata.task_attached_signal");
|
|
6859
|
+
CadenzaService.createMetaTask("Handle task intent association", (ctx) => {
|
|
6860
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6861
|
+
return false;
|
|
6862
|
+
}
|
|
6863
|
+
const intentName = String(ctx.data?.intentName ?? "");
|
|
6864
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6865
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6866
|
+
return false;
|
|
6867
|
+
}
|
|
6868
|
+
if (task?.registered && task.__registeredIntents?.has(
|
|
6869
|
+
intentName
|
|
6870
|
+
)) {
|
|
6871
|
+
return false;
|
|
6872
|
+
}
|
|
6873
|
+
return buildDatabaseTriggerContext({
|
|
6874
|
+
...ctx.data,
|
|
6875
|
+
intentName,
|
|
6876
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6877
|
+
});
|
|
6878
|
+
}).doOn("meta.task.intent_associated").emits("global.meta.graph_metadata.task_intent_associated");
|
|
6287
6879
|
CadenzaService.createMetaTask("Handle task unsubscribing signal", (ctx) => {
|
|
6880
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6881
|
+
return false;
|
|
6882
|
+
}
|
|
6883
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6884
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6885
|
+
return false;
|
|
6886
|
+
}
|
|
6288
6887
|
return buildDatabaseTriggerContext(
|
|
6289
6888
|
{
|
|
6290
6889
|
deleted: true
|
|
@@ -6296,6 +6895,13 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6296
6895
|
);
|
|
6297
6896
|
}).doOn("meta.task.unsubscribed_signal").emits("meta.graph_metadata.task_unsubscribed_signal");
|
|
6298
6897
|
CadenzaService.createMetaTask("Handle task detaching signal", (ctx) => {
|
|
6898
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6899
|
+
return false;
|
|
6900
|
+
}
|
|
6901
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6902
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6903
|
+
return false;
|
|
6904
|
+
}
|
|
6299
6905
|
return buildDatabaseTriggerContext(
|
|
6300
6906
|
{
|
|
6301
6907
|
deleted: true
|
|
@@ -6307,12 +6913,18 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6307
6913
|
);
|
|
6308
6914
|
}).doOn("meta.task.detached_signal").emits("global.meta.graph_metadata.task_detached_signal");
|
|
6309
6915
|
CadenzaService.createMetaTask("Handle routine creation", (ctx) => {
|
|
6916
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6917
|
+
return false;
|
|
6918
|
+
}
|
|
6310
6919
|
return buildDatabaseTriggerContext({
|
|
6311
6920
|
...ctx.data,
|
|
6312
6921
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6313
6922
|
});
|
|
6314
6923
|
}).doAfter(CadenzaService.registry.registerRoutine).emits("global.meta.graph_metadata.routine_created");
|
|
6315
6924
|
CadenzaService.createMetaTask("Handle routine update", (ctx) => {
|
|
6925
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6926
|
+
return false;
|
|
6927
|
+
}
|
|
6316
6928
|
return buildDatabaseTriggerContext(
|
|
6317
6929
|
ctx.data ?? void 0,
|
|
6318
6930
|
{
|
|
@@ -6322,6 +6934,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6322
6934
|
);
|
|
6323
6935
|
}).doOn("meta.routine.destroyed").emits("global.meta.graph_metadata.routine_updated");
|
|
6324
6936
|
CadenzaService.createMetaTask("Handle adding task to routine", (ctx) => {
|
|
6937
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6938
|
+
return false;
|
|
6939
|
+
}
|
|
6325
6940
|
return buildDatabaseTriggerContext({
|
|
6326
6941
|
...ctx.data,
|
|
6327
6942
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
@@ -6337,8 +6952,12 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6337
6952
|
CadenzaService.createMetaTask(
|
|
6338
6953
|
"Handle routine execution creation",
|
|
6339
6954
|
(ctx) => {
|
|
6955
|
+
if (!shouldPersistRoutineExecution(ctx)) {
|
|
6956
|
+
return false;
|
|
6957
|
+
}
|
|
6340
6958
|
return buildDatabaseTriggerContext({
|
|
6341
6959
|
...ctx.data,
|
|
6960
|
+
previousRoutineExecution: hasInquiryLink(ctx.data) ? null : ctx.data?.previousRoutineExecution ?? ctx.data?.previous_routine_execution ?? null,
|
|
6342
6961
|
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
6343
6962
|
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId
|
|
6344
6963
|
});
|
|
@@ -6375,6 +6994,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6375
6994
|
CadenzaService.createMetaTask(
|
|
6376
6995
|
"Handle task execution creation",
|
|
6377
6996
|
(ctx) => {
|
|
6997
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
6998
|
+
return false;
|
|
6999
|
+
}
|
|
6378
7000
|
return buildDatabaseTriggerContext({
|
|
6379
7001
|
...ctx.data,
|
|
6380
7002
|
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
@@ -6387,6 +7009,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6387
7009
|
CadenzaService.createMetaTask(
|
|
6388
7010
|
"Handle task execution mapped",
|
|
6389
7011
|
(ctx) => {
|
|
7012
|
+
if (!shouldPersistTaskExecutionMap(ctx)) {
|
|
7013
|
+
return false;
|
|
7014
|
+
}
|
|
6390
7015
|
return buildDatabaseTriggerContext(
|
|
6391
7016
|
ctx.data ?? void 0,
|
|
6392
7017
|
ctx.filter ?? void 0
|
|
@@ -6398,6 +7023,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6398
7023
|
CadenzaService.createMetaTask(
|
|
6399
7024
|
"Handle task execution started",
|
|
6400
7025
|
(ctx) => {
|
|
7026
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
7027
|
+
return false;
|
|
7028
|
+
}
|
|
6401
7029
|
return buildDatabaseTriggerContext(
|
|
6402
7030
|
ctx.data ?? void 0,
|
|
6403
7031
|
ctx.filter ?? void 0
|
|
@@ -6409,6 +7037,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6409
7037
|
CadenzaService.createMetaTask(
|
|
6410
7038
|
"Handle task execution ended",
|
|
6411
7039
|
(ctx) => {
|
|
7040
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
7041
|
+
return false;
|
|
7042
|
+
}
|
|
6412
7043
|
return buildDatabaseTriggerContext(
|
|
6413
7044
|
{
|
|
6414
7045
|
...ctx.data,
|
|
@@ -6421,9 +7052,39 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6421
7052
|
"Handles task execution ended",
|
|
6422
7053
|
{ concurrency: 100, isSubMeta: true }
|
|
6423
7054
|
).doOn("meta.node.ended").emits("global.meta.graph_metadata.task_execution_ended");
|
|
7055
|
+
CadenzaService.createMetaTask(
|
|
7056
|
+
"Handle inquiry creation",
|
|
7057
|
+
(ctx) => {
|
|
7058
|
+
if (!shouldPersistBusinessInquiry(ctx)) {
|
|
7059
|
+
return false;
|
|
7060
|
+
}
|
|
7061
|
+
return buildDatabaseTriggerContext({
|
|
7062
|
+
...ctx.data,
|
|
7063
|
+
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
7064
|
+
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
7065
|
+
isMeta: false
|
|
7066
|
+
});
|
|
7067
|
+
},
|
|
7068
|
+
"Handles inquiry creation",
|
|
7069
|
+
{ concurrency: 100, isSubMeta: true }
|
|
7070
|
+
).doOn("meta.inquiry_broker.inquiry_started").emits("global.meta.graph_metadata.inquiry_created");
|
|
7071
|
+
CadenzaService.createMetaTask(
|
|
7072
|
+
"Handle inquiry update",
|
|
7073
|
+
(ctx) => {
|
|
7074
|
+
return buildDatabaseTriggerContext(
|
|
7075
|
+
ctx.data ?? void 0,
|
|
7076
|
+
ctx.filter ?? void 0
|
|
7077
|
+
);
|
|
7078
|
+
},
|
|
7079
|
+
"Handles inquiry completion updates",
|
|
7080
|
+
{ concurrency: 100, isSubMeta: true }
|
|
7081
|
+
).doOn("meta.inquiry_broker.inquiry_completed").emits("global.meta.graph_metadata.inquiry_updated");
|
|
6424
7082
|
CadenzaService.createMetaTask(
|
|
6425
7083
|
"Handle task execution relationship creation",
|
|
6426
7084
|
(ctx) => {
|
|
7085
|
+
if (!shouldPersistTaskExecutionMap(ctx)) {
|
|
7086
|
+
return false;
|
|
7087
|
+
}
|
|
6427
7088
|
return buildDatabaseTriggerContext(
|
|
6428
7089
|
{
|
|
6429
7090
|
executionCount: "increment",
|
|
@@ -6439,12 +7100,18 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6439
7100
|
{ concurrency: 100, isSubMeta: true }
|
|
6440
7101
|
).doOn("meta.node.mapped", "meta.node.detected_previous_task_execution").emits("global.meta.graph_metadata.relationship_executed");
|
|
6441
7102
|
CadenzaService.createMetaTask("Handle actor creation", (ctx) => {
|
|
7103
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7104
|
+
return false;
|
|
7105
|
+
}
|
|
6442
7106
|
return buildDatabaseTriggerContext({
|
|
6443
7107
|
...ctx.data,
|
|
6444
7108
|
service_name: CadenzaService.serviceRegistry.serviceName
|
|
6445
7109
|
});
|
|
6446
7110
|
}).doOn("meta.actor.created").emits("global.meta.graph_metadata.actor_created");
|
|
6447
7111
|
CadenzaService.createMetaTask("Handle actor task association", (ctx) => {
|
|
7112
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7113
|
+
return false;
|
|
7114
|
+
}
|
|
6448
7115
|
return buildDatabaseTriggerContext({
|
|
6449
7116
|
...ctx.data,
|
|
6450
7117
|
service_name: CadenzaService.serviceRegistry.serviceName
|
|
@@ -6452,6 +7119,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6452
7119
|
}).doOn("meta.actor.task_associated").emits("global.meta.graph_metadata.actor_task_associated");
|
|
6453
7120
|
registerActorSessionPersistenceTasks();
|
|
6454
7121
|
CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
|
|
7122
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7123
|
+
return false;
|
|
7124
|
+
}
|
|
6455
7125
|
const intentName = ctx.data?.name;
|
|
6456
7126
|
return buildDatabaseTriggerContext({
|
|
6457
7127
|
...ctx.data,
|
|
@@ -6573,7 +7243,7 @@ function buildIntentRegistryData(intent) {
|
|
|
6573
7243
|
description: typeof intent?.description === "string" ? intent.description : "",
|
|
6574
7244
|
input: intent?.input && typeof intent.input === "object" ? intent.input : { type: "object" },
|
|
6575
7245
|
output: intent?.output && typeof intent.output === "object" ? intent.output : { type: "object" },
|
|
6576
|
-
|
|
7246
|
+
is_meta: isMetaIntentName(name)
|
|
6577
7247
|
};
|
|
6578
7248
|
}
|
|
6579
7249
|
function getJoinedContextValue(ctx, key) {
|
|
@@ -6646,34 +7316,7 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
|
|
|
6646
7316
|
}
|
|
6647
7317
|
return nextQueryData;
|
|
6648
7318
|
}
|
|
6649
|
-
function buildSyncQueryQueryData(ctx, queryData = {}) {
|
|
6650
|
-
const joinedQueryData = getJoinedContextValue(ctx, "queryData");
|
|
6651
|
-
const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : joinedQueryData && typeof joinedQueryData === "object" ? joinedQueryData : {};
|
|
6652
|
-
const nextQueryData = {};
|
|
6653
|
-
const allowedKeys = [
|
|
6654
|
-
"transaction",
|
|
6655
|
-
"filter",
|
|
6656
|
-
"fields",
|
|
6657
|
-
"joins",
|
|
6658
|
-
"sort",
|
|
6659
|
-
"limit",
|
|
6660
|
-
"offset",
|
|
6661
|
-
"queryMode",
|
|
6662
|
-
"aggregates",
|
|
6663
|
-
"groupBy"
|
|
6664
|
-
];
|
|
6665
|
-
for (const key of allowedKeys) {
|
|
6666
|
-
if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
|
|
6667
|
-
nextQueryData[key] = existingQueryData[key];
|
|
6668
|
-
}
|
|
6669
|
-
}
|
|
6670
|
-
return {
|
|
6671
|
-
...nextQueryData,
|
|
6672
|
-
...queryData
|
|
6673
|
-
};
|
|
6674
|
-
}
|
|
6675
7319
|
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 5;
|
|
6676
|
-
var REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY = 3;
|
|
6677
7320
|
function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
6678
7321
|
if (!graph) {
|
|
6679
7322
|
return void 0;
|
|
@@ -6686,11 +7329,27 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
|
6686
7329
|
}
|
|
6687
7330
|
function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
6688
7331
|
const originalContext = { ...ctx };
|
|
7332
|
+
const syncSourceServiceName = typeof ctx.__syncSourceServiceName === "string" && ctx.__syncSourceServiceName.trim().length > 0 ? ctx.__syncSourceServiceName : typeof ctx.__serviceName === "string" && ctx.__serviceName.trim().length > 0 ? ctx.__serviceName : resolveSyncServiceName();
|
|
7333
|
+
const rootDbOperationFields = {};
|
|
7334
|
+
for (const key of [
|
|
7335
|
+
"data",
|
|
7336
|
+
"batch",
|
|
7337
|
+
"transaction",
|
|
7338
|
+
"onConflict",
|
|
7339
|
+
"filter",
|
|
7340
|
+
"fields"
|
|
7341
|
+
]) {
|
|
7342
|
+
if (Object.prototype.hasOwnProperty.call(queryData, key)) {
|
|
7343
|
+
rootDbOperationFields[key] = queryData[key];
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
6689
7346
|
const nextContext = {
|
|
6690
7347
|
__syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
|
|
7348
|
+
__syncSourceServiceName: syncSourceServiceName,
|
|
6691
7349
|
__preferredTransportProtocol: "rest",
|
|
6692
7350
|
__resolverOriginalContext: originalContext,
|
|
6693
7351
|
__resolverQueryData: queryData,
|
|
7352
|
+
...rootDbOperationFields,
|
|
6694
7353
|
queryData
|
|
6695
7354
|
};
|
|
6696
7355
|
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
@@ -6698,9 +7357,26 @@ function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
|
6698
7357
|
}
|
|
6699
7358
|
return nextContext;
|
|
6700
7359
|
}
|
|
7360
|
+
function markCompletedSyncCycle(completedCycles, cycleId, limit = 32) {
|
|
7361
|
+
if (!cycleId) {
|
|
7362
|
+
return false;
|
|
7363
|
+
}
|
|
7364
|
+
if (completedCycles.has(cycleId)) {
|
|
7365
|
+
return false;
|
|
7366
|
+
}
|
|
7367
|
+
completedCycles.add(cycleId);
|
|
7368
|
+
while (completedCycles.size > limit) {
|
|
7369
|
+
const oldestCycleId = completedCycles.values().next().value;
|
|
7370
|
+
if (!oldestCycleId) {
|
|
7371
|
+
break;
|
|
7372
|
+
}
|
|
7373
|
+
completedCycles.delete(oldestCycleId);
|
|
7374
|
+
}
|
|
7375
|
+
return true;
|
|
7376
|
+
}
|
|
6701
7377
|
function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6702
7378
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
6703
|
-
if (
|
|
7379
|
+
if (isCadenzaDBReady && !localInsertTask) {
|
|
6704
7380
|
return void 0;
|
|
6705
7381
|
}
|
|
6706
7382
|
const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
|
|
@@ -6751,6 +7427,11 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
6751
7427
|
...ctx,
|
|
6752
7428
|
queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
|
|
6753
7429
|
};
|
|
7430
|
+
if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
|
|
7431
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
7432
|
+
delayMs: 1e3
|
|
7433
|
+
});
|
|
7434
|
+
}
|
|
6754
7435
|
return normalizedContext;
|
|
6755
7436
|
},
|
|
6756
7437
|
`Finalizes ${tableName} graph-sync insert execution after the authority task finishes.`,
|
|
@@ -6778,86 +7459,82 @@ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
|
|
|
6778
7459
|
"intent_to_task_map",
|
|
6779
7460
|
"directional_task_graph_map"
|
|
6780
7461
|
];
|
|
6781
|
-
var
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
function
|
|
6789
|
-
const
|
|
6790
|
-
|
|
6791
|
-
|
|
7462
|
+
var BOOTSTRAP_SYNC_STALE_CYCLE_MS = 15e3;
|
|
7463
|
+
var EARLY_SYNC_TICK_DELAYS_MS = [
|
|
7464
|
+
400,
|
|
7465
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS + 1e3,
|
|
7466
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 2 + 2e3,
|
|
7467
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 3 + 3e3
|
|
7468
|
+
];
|
|
7469
|
+
function shouldTraceSyncPhase(serviceName) {
|
|
7470
|
+
const configured = process.env.CADENZA_SYNC_PHASE_TRACE_SERVICE;
|
|
7471
|
+
if (!configured || !serviceName) {
|
|
7472
|
+
return false;
|
|
7473
|
+
}
|
|
7474
|
+
return configured === serviceName;
|
|
6792
7475
|
}
|
|
6793
|
-
function
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
return void 0;
|
|
7476
|
+
function canonicalizeSignalName(signalName) {
|
|
7477
|
+
if (typeof signalName !== "string") {
|
|
7478
|
+
return "";
|
|
6797
7479
|
}
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY
|
|
6803
|
-
) : REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY,
|
|
6804
|
-
register: false,
|
|
6805
|
-
isHidden: true
|
|
6806
|
-
});
|
|
6807
|
-
const prepareQueryTask = CadenzaService.createMetaTask(
|
|
6808
|
-
`Prepare graph sync query for ${tableName}`,
|
|
6809
|
-
(ctx) => buildSyncExecutionEnvelope(
|
|
6810
|
-
ctx,
|
|
6811
|
-
buildSyncQueryQueryData(ctx, queryData)
|
|
6812
|
-
),
|
|
6813
|
-
`Prepares ${tableName} graph-sync query payloads.`,
|
|
6814
|
-
{
|
|
6815
|
-
register: false,
|
|
6816
|
-
isHidden: true
|
|
6817
|
-
}
|
|
6818
|
-
);
|
|
6819
|
-
const finalizeQueryTask = CadenzaService.createMetaTask(
|
|
6820
|
-
`Finalize graph sync query for ${tableName}`,
|
|
6821
|
-
(ctx) => ctx,
|
|
6822
|
-
`Finalizes ${tableName} graph-sync query payloads after authority lookup.`,
|
|
6823
|
-
{
|
|
6824
|
-
register: false,
|
|
6825
|
-
isHidden: true
|
|
6826
|
-
}
|
|
6827
|
-
);
|
|
6828
|
-
prepareQueryTask.then(targetTask);
|
|
6829
|
-
targetTask.then(finalizeQueryTask);
|
|
6830
|
-
return {
|
|
6831
|
-
entryTask: prepareQueryTask,
|
|
6832
|
-
completionTask: finalizeQueryTask
|
|
6833
|
-
};
|
|
7480
|
+
return signalName.split(":")[0]?.trim() ?? "";
|
|
7481
|
+
}
|
|
7482
|
+
function isBootstrapLocalOnlySignal(signalName) {
|
|
7483
|
+
return signalName === "meta.service_registry.insert_execution_requested" || signalName.startsWith("meta.sync_controller.");
|
|
6834
7484
|
}
|
|
6835
7485
|
function getRegistrableTasks() {
|
|
6836
7486
|
return Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
6837
|
-
(task) => task.register && !task.isHidden
|
|
7487
|
+
(task) => task.register && !task.isHidden && !task.isDeputy
|
|
6838
7488
|
);
|
|
6839
7489
|
}
|
|
6840
7490
|
function getRegistrableRoutines() {
|
|
6841
7491
|
return Array.from(CadenzaService.registry.routines.values());
|
|
6842
7492
|
}
|
|
6843
|
-
function isAuthoritySyncSignal(signalName) {
|
|
6844
|
-
return decomposeSignalName(signalName).isGlobal;
|
|
6845
|
-
}
|
|
6846
7493
|
function getRegistrableSignalObservers() {
|
|
6847
7494
|
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
6848
7495
|
if (!signalObservers) {
|
|
6849
7496
|
return [];
|
|
6850
7497
|
}
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
7498
|
+
const canonicalObservers = /* @__PURE__ */ new Map();
|
|
7499
|
+
for (const [rawSignalName, observer] of signalObservers.entries()) {
|
|
7500
|
+
const signalName = canonicalizeSignalName(rawSignalName);
|
|
7501
|
+
if (!signalName || isBootstrapLocalOnlySignal(signalName)) {
|
|
7502
|
+
continue;
|
|
7503
|
+
}
|
|
7504
|
+
const existing = canonicalObservers.get(signalName);
|
|
7505
|
+
canonicalObservers.set(signalName, {
|
|
7506
|
+
signalName,
|
|
7507
|
+
registered: existing?.registered === true || observer?.registered === true
|
|
7508
|
+
});
|
|
7509
|
+
}
|
|
7510
|
+
return Array.from(canonicalObservers.values());
|
|
7511
|
+
}
|
|
7512
|
+
function isLocallyHandledIntentName(intentName) {
|
|
7513
|
+
const observer = CadenzaService.inquiryBroker.inquiryObservers.get(intentName);
|
|
7514
|
+
if (!observer) {
|
|
7515
|
+
return false;
|
|
7516
|
+
}
|
|
7517
|
+
for (const task of observer.tasks) {
|
|
7518
|
+
if (task.register && !task.isHidden && !task.isDeputy) {
|
|
7519
|
+
return true;
|
|
7520
|
+
}
|
|
7521
|
+
}
|
|
7522
|
+
return false;
|
|
6855
7523
|
}
|
|
6856
7524
|
function getRegistrableIntentNames() {
|
|
6857
7525
|
return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
|
|
6858
7526
|
(intentDefinition) => intentDefinition !== null
|
|
7527
|
+
).filter(
|
|
7528
|
+
(intentDefinition) => isLocallyHandledIntentName(String(intentDefinition.name))
|
|
6859
7529
|
).map((intentDefinition) => String(intentDefinition.name));
|
|
6860
7530
|
}
|
|
7531
|
+
function isRegistrableLocalIntentDefinition(intent) {
|
|
7532
|
+
const intentData = buildIntentRegistryData(intent);
|
|
7533
|
+
if (!intentData) {
|
|
7534
|
+
return false;
|
|
7535
|
+
}
|
|
7536
|
+
return isLocallyHandledIntentName(String(intentData.name));
|
|
7537
|
+
}
|
|
6861
7538
|
function buildActorRegistrationKey(actor, serviceName) {
|
|
6862
7539
|
const data = buildActorRegistrationData(actor);
|
|
6863
7540
|
const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
|
|
@@ -6899,10 +7576,23 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6899
7576
|
this.signalsSynced = false;
|
|
6900
7577
|
this.intentsSynced = false;
|
|
6901
7578
|
this.routinesSynced = false;
|
|
7579
|
+
this.directionalTaskMapsSynced = false;
|
|
7580
|
+
this.signalTaskMapsSynced = false;
|
|
7581
|
+
this.intentTaskMapsSynced = false;
|
|
7582
|
+
this.actorTaskMapsSynced = false;
|
|
7583
|
+
this.routineTaskMapsSynced = false;
|
|
6902
7584
|
this.isCadenzaDBReady = false;
|
|
6903
7585
|
this.initialized = false;
|
|
6904
7586
|
this.initRetryScheduled = false;
|
|
6905
7587
|
this.lastMissingLocalCadenzaDBInsertTablesKey = "";
|
|
7588
|
+
this.syncCycleCounter = 0;
|
|
7589
|
+
this.primitivePhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7590
|
+
this.mapPhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7591
|
+
this.activeSyncCycleId = null;
|
|
7592
|
+
this.activeSyncCycleStartedAt = 0;
|
|
7593
|
+
this.pendingBootstrapSyncRerun = false;
|
|
7594
|
+
this.localServiceInserted = false;
|
|
7595
|
+
this.localServiceInstanceInserted = false;
|
|
6906
7596
|
}
|
|
6907
7597
|
static get instance() {
|
|
6908
7598
|
if (!this._instance) this._instance = new _GraphSyncController();
|
|
@@ -6976,45 +7666,16 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6976
7666
|
},
|
|
6977
7667
|
{ concurrency: 30 }
|
|
6978
7668
|
);
|
|
6979
|
-
const ensureIntentRegistryBeforeIntentMapTask = resolveSyncInsertTask(
|
|
6980
|
-
this.isCadenzaDBReady,
|
|
6981
|
-
"intent_registry",
|
|
6982
|
-
{
|
|
6983
|
-
onConflict: {
|
|
6984
|
-
target: ["name"],
|
|
6985
|
-
action: {
|
|
6986
|
-
do: "nothing"
|
|
6987
|
-
}
|
|
6988
|
-
}
|
|
6989
|
-
},
|
|
6990
|
-
{ concurrency: 30 }
|
|
6991
|
-
);
|
|
6992
|
-
const authoritativeTaskQueryGraph = resolveSyncQueryTask(
|
|
6993
|
-
this.isCadenzaDBReady,
|
|
6994
|
-
"task",
|
|
6995
|
-
{},
|
|
6996
|
-
{ concurrency: 10 }
|
|
6997
|
-
);
|
|
6998
|
-
const authoritativeRoutineQueryGraph = resolveSyncQueryTask(
|
|
6999
|
-
this.isCadenzaDBReady,
|
|
7000
|
-
"routine",
|
|
7001
|
-
{},
|
|
7002
|
-
{ concurrency: 10 }
|
|
7003
|
-
);
|
|
7004
|
-
const authoritativeSignalQueryGraph = resolveSyncQueryTask(
|
|
7005
|
-
this.isCadenzaDBReady,
|
|
7006
|
-
"signal_registry",
|
|
7007
|
-
{},
|
|
7008
|
-
{ concurrency: 10 }
|
|
7009
|
-
);
|
|
7010
|
-
const authoritativeIntentQueryGraph = resolveSyncQueryTask(
|
|
7011
|
-
this.isCadenzaDBReady,
|
|
7012
|
-
"intent_registry",
|
|
7013
|
-
{},
|
|
7014
|
-
{ concurrency: 10 }
|
|
7015
|
-
);
|
|
7016
7669
|
const finalizeTaskSync = (emit, ctx) => {
|
|
7017
7670
|
const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
|
|
7671
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7672
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7673
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_tasks", {
|
|
7674
|
+
serviceName: serviceName2,
|
|
7675
|
+
pendingCount: pendingTasks.length,
|
|
7676
|
+
sample: pendingTasks.slice(0, 5).map((task) => task.name)
|
|
7677
|
+
});
|
|
7678
|
+
}
|
|
7018
7679
|
if (pendingTasks.length > 0) {
|
|
7019
7680
|
this.tasksSynced = false;
|
|
7020
7681
|
return false;
|
|
@@ -7033,6 +7694,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7033
7694
|
const pendingRoutines = getRegistrableRoutines().filter(
|
|
7034
7695
|
(routine) => !routine.registered
|
|
7035
7696
|
);
|
|
7697
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7698
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7699
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_routines", {
|
|
7700
|
+
serviceName: serviceName2,
|
|
7701
|
+
pendingCount: pendingRoutines.length,
|
|
7702
|
+
sample: pendingRoutines.slice(0, 5).map((routine) => routine.name)
|
|
7703
|
+
});
|
|
7704
|
+
}
|
|
7036
7705
|
if (pendingRoutines.length > 0) {
|
|
7037
7706
|
this.routinesSynced = false;
|
|
7038
7707
|
return false;
|
|
@@ -7051,6 +7720,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7051
7720
|
const pendingSignals = getRegistrableSignalObservers().filter(
|
|
7052
7721
|
(observer) => observer.registered !== true
|
|
7053
7722
|
);
|
|
7723
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7724
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7725
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_signals", {
|
|
7726
|
+
serviceName: serviceName2,
|
|
7727
|
+
pendingCount: pendingSignals.length,
|
|
7728
|
+
sample: pendingSignals.slice(0, 5).map((observer) => observer.signalName)
|
|
7729
|
+
});
|
|
7730
|
+
}
|
|
7054
7731
|
if (pendingSignals.length > 0) {
|
|
7055
7732
|
this.signalsSynced = false;
|
|
7056
7733
|
return false;
|
|
@@ -7069,6 +7746,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7069
7746
|
const pendingIntentNames = getRegistrableIntentNames().filter(
|
|
7070
7747
|
(intentName) => !this.registeredIntentDefinitions.has(intentName)
|
|
7071
7748
|
);
|
|
7749
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7750
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7751
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_intents", {
|
|
7752
|
+
serviceName: serviceName2,
|
|
7753
|
+
pendingCount: pendingIntentNames.length,
|
|
7754
|
+
sample: pendingIntentNames.slice(0, 5)
|
|
7755
|
+
});
|
|
7756
|
+
}
|
|
7072
7757
|
if (pendingIntentNames.length > 0) {
|
|
7073
7758
|
this.intentsSynced = false;
|
|
7074
7759
|
return false;
|
|
@@ -7090,6 +7775,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7090
7775
|
return false;
|
|
7091
7776
|
}
|
|
7092
7777
|
const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
|
|
7778
|
+
if (shouldTraceSyncPhase(syncServiceName)) {
|
|
7779
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_actors", {
|
|
7780
|
+
serviceName: syncServiceName,
|
|
7781
|
+
pendingCount: pendingActorKeys.length,
|
|
7782
|
+
sample: pendingActorKeys.slice(0, 5)
|
|
7783
|
+
});
|
|
7784
|
+
}
|
|
7093
7785
|
if (pendingActorKeys.length > 0) {
|
|
7094
7786
|
this.actorsSynced = false;
|
|
7095
7787
|
return false;
|
|
@@ -7170,8 +7862,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7170
7862
|
name: routine.name,
|
|
7171
7863
|
version: routine.version,
|
|
7172
7864
|
description: routine.description,
|
|
7173
|
-
|
|
7174
|
-
|
|
7865
|
+
service_name: serviceName2,
|
|
7866
|
+
is_meta: routine.isMeta
|
|
7175
7867
|
},
|
|
7176
7868
|
__routineName: routine.name
|
|
7177
7869
|
};
|
|
@@ -7234,11 +7926,11 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7234
7926
|
yield {
|
|
7235
7927
|
__syncing: ctx.__syncing,
|
|
7236
7928
|
data: {
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7929
|
+
task_name: nextTask.name,
|
|
7930
|
+
task_version: nextTask.version,
|
|
7931
|
+
routine_name: routine.name,
|
|
7932
|
+
routine_version: routine.version,
|
|
7933
|
+
service_name: serviceName2
|
|
7242
7934
|
},
|
|
7243
7935
|
__routineName: routine.name,
|
|
7244
7936
|
__taskName: nextTask.name
|
|
@@ -7296,12 +7988,20 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7296
7988
|
});
|
|
7297
7989
|
const { signals } = ctx;
|
|
7298
7990
|
if (!signals) return;
|
|
7299
|
-
const
|
|
7300
|
-
|
|
7991
|
+
const seenSignals = /* @__PURE__ */ new Set();
|
|
7992
|
+
const filteredSignals = signals.map((signal) => ({
|
|
7993
|
+
signalName: canonicalizeSignalName(signal.signal),
|
|
7994
|
+
data: signal.data
|
|
7995
|
+
})).filter((signal) => {
|
|
7996
|
+
if (!signal.signalName || signal.data?.registered || isBootstrapLocalOnlySignal(signal.signalName)) {
|
|
7997
|
+
return false;
|
|
7998
|
+
}
|
|
7999
|
+
if (seenSignals.has(signal.signalName)) {
|
|
7301
8000
|
return false;
|
|
7302
8001
|
}
|
|
7303
|
-
|
|
7304
|
-
|
|
8002
|
+
seenSignals.add(signal.signalName);
|
|
8003
|
+
return true;
|
|
8004
|
+
}).map((signal) => signal.signalName);
|
|
7305
8005
|
for (const signal of filteredSignals) {
|
|
7306
8006
|
const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
|
|
7307
8007
|
this.signalsSynced = false;
|
|
@@ -7309,10 +8009,10 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7309
8009
|
__syncing: ctx.__syncing,
|
|
7310
8010
|
data: {
|
|
7311
8011
|
name: signal,
|
|
7312
|
-
isGlobal,
|
|
8012
|
+
is_global: isGlobal,
|
|
7313
8013
|
domain,
|
|
7314
8014
|
action,
|
|
7315
|
-
isMeta
|
|
8015
|
+
is_meta: isMeta
|
|
7316
8016
|
},
|
|
7317
8017
|
__signal: signal
|
|
7318
8018
|
};
|
|
@@ -7334,14 +8034,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7334
8034
|
);
|
|
7335
8035
|
const processSignalRegistrationTask = CadenzaService.createMetaTask(
|
|
7336
8036
|
"Process signal registration",
|
|
7337
|
-
(ctx) => {
|
|
7338
|
-
|
|
8037
|
+
(ctx, emit) => {
|
|
8038
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
8039
|
+
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
8040
|
+
if (!insertSucceeded) {
|
|
7339
8041
|
return;
|
|
7340
8042
|
}
|
|
7341
8043
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7342
8044
|
delayMs: 3e3
|
|
7343
8045
|
});
|
|
7344
|
-
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7345
8046
|
if (!signalName) {
|
|
7346
8047
|
return false;
|
|
7347
8048
|
}
|
|
@@ -7352,7 +8053,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7352
8053
|
const observer = signalObservers?.get(signalName);
|
|
7353
8054
|
if (observer) {
|
|
7354
8055
|
observer.registered = true;
|
|
8056
|
+
observer.registrationRequested = false;
|
|
7355
8057
|
}
|
|
8058
|
+
emit(
|
|
8059
|
+
"meta.sync_controller.signal_registered",
|
|
8060
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
8061
|
+
__signal: signalName
|
|
8062
|
+
})
|
|
8063
|
+
);
|
|
7356
8064
|
return { signalName };
|
|
7357
8065
|
}
|
|
7358
8066
|
).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask);
|
|
@@ -7373,6 +8081,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7373
8081
|
return;
|
|
7374
8082
|
}
|
|
7375
8083
|
for (const task of tasks) {
|
|
8084
|
+
if (task.hidden || !task.register || task.isDeputy) continue;
|
|
7376
8085
|
if (task.registered) continue;
|
|
7377
8086
|
const { __functionString, __getTagCallback } = task.export();
|
|
7378
8087
|
this.tasksSynced = false;
|
|
@@ -7382,32 +8091,33 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7382
8091
|
name: task.name,
|
|
7383
8092
|
version: task.version,
|
|
7384
8093
|
description: task.description,
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
8094
|
+
function_string: __functionString,
|
|
8095
|
+
tag_id_getter: __getTagCallback,
|
|
8096
|
+
layer_index: task.layerIndex,
|
|
7388
8097
|
concurrency: task.concurrency,
|
|
7389
8098
|
timeout: task.timeout,
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
8099
|
+
is_unique: task.isUnique,
|
|
8100
|
+
is_signal: task.isSignal,
|
|
8101
|
+
is_throttled: task.isThrottled,
|
|
8102
|
+
is_debounce: task.isDebounce,
|
|
8103
|
+
is_ephemeral: task.isEphemeral,
|
|
8104
|
+
is_meta: task.isMeta,
|
|
8105
|
+
is_sub_meta: task.isSubMeta,
|
|
8106
|
+
is_hidden: task.isHidden,
|
|
8107
|
+
validate_input_context: task.validateInputContext,
|
|
8108
|
+
validate_output_context: task.validateOutputContext,
|
|
8109
|
+
retry_count: task.retryCount,
|
|
8110
|
+
retry_delay: task.retryDelay,
|
|
8111
|
+
retry_delay_max: task.retryDelayMax,
|
|
8112
|
+
retry_delay_factor: task.retryDelayFactor,
|
|
7404
8113
|
service_name: serviceName2,
|
|
7405
8114
|
signals: {
|
|
7406
8115
|
emits: Array.from(task.emitsSignals),
|
|
7407
8116
|
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
7408
8117
|
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
7409
8118
|
observed: Array.from(task.observedSignals)
|
|
7410
|
-
}
|
|
8119
|
+
},
|
|
8120
|
+
intents: Array.from(task.handlesIntents)
|
|
7411
8121
|
},
|
|
7412
8122
|
__taskName: task.name
|
|
7413
8123
|
};
|
|
@@ -7430,17 +8140,20 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7430
8140
|
const registerTaskTask = CadenzaService.createMetaTask(
|
|
7431
8141
|
"Record registration",
|
|
7432
8142
|
(ctx, emit) => {
|
|
7433
|
-
|
|
8143
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
8144
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8145
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
8146
|
+
if (!insertSucceeded) {
|
|
7434
8147
|
return;
|
|
7435
8148
|
}
|
|
7436
8149
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7437
8150
|
delayMs: 3e3
|
|
7438
8151
|
});
|
|
7439
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7440
8152
|
if (!task) {
|
|
7441
8153
|
return true;
|
|
7442
8154
|
}
|
|
7443
8155
|
task.registered = true;
|
|
8156
|
+
task.registrationRequested = false;
|
|
7444
8157
|
emit(
|
|
7445
8158
|
"meta.sync_controller.task_registered",
|
|
7446
8159
|
buildMinimalSyncSignalContext(ctx, {
|
|
@@ -7451,24 +8164,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7451
8164
|
}
|
|
7452
8165
|
).then(gatherTaskRegistrationTask);
|
|
7453
8166
|
wireSyncTaskGraph(this.splitTasksForRegistration, registerTaskGraph, registerTaskTask);
|
|
7454
|
-
CadenzaService.createMetaTask(
|
|
7455
|
-
"Prepare created task for immediate sync",
|
|
7456
|
-
(ctx) => {
|
|
7457
|
-
const task = ctx.taskInstance ?? (ctx.data?.name ? CadenzaService.get(String(ctx.data.name)) : void 0);
|
|
7458
|
-
if (!task || task.hidden || !task.register || task.registered) {
|
|
7459
|
-
return false;
|
|
7460
|
-
}
|
|
7461
|
-
return {
|
|
7462
|
-
__syncing: true,
|
|
7463
|
-
tasks: [task]
|
|
7464
|
-
};
|
|
7465
|
-
},
|
|
7466
|
-
"Schedules newly created tasks into the graph sync registration flow without waiting for the next periodic tick.",
|
|
7467
|
-
{
|
|
7468
|
-
register: false,
|
|
7469
|
-
isHidden: true
|
|
7470
|
-
}
|
|
7471
|
-
).doOn("meta.task.created").then(this.splitTasksForRegistration);
|
|
7472
8167
|
this.splitActorsForRegistration = CadenzaService.createMetaTask(
|
|
7473
8168
|
"Split actors for registration",
|
|
7474
8169
|
function* (ctx) {
|
|
@@ -7607,13 +8302,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7607
8302
|
const registerSignalTask = CadenzaService.createMetaTask(
|
|
7608
8303
|
"Record signal registration",
|
|
7609
8304
|
(ctx) => {
|
|
8305
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
8306
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7610
8307
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7611
8308
|
return;
|
|
7612
8309
|
}
|
|
7613
8310
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7614
8311
|
delayMs: 3e3
|
|
7615
8312
|
});
|
|
7616
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7617
8313
|
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7618
8314
|
if (!task || !signalName) {
|
|
7619
8315
|
return true;
|
|
@@ -7625,7 +8321,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7625
8321
|
"Split observed signals of task",
|
|
7626
8322
|
function* (ctx) {
|
|
7627
8323
|
const task = ctx.task;
|
|
7628
|
-
if (task.hidden || !task.register || !task.registered)
|
|
8324
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
8325
|
+
return false;
|
|
7629
8326
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7630
8327
|
if (!serviceName2) {
|
|
7631
8328
|
return false;
|
|
@@ -7644,11 +8341,11 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7644
8341
|
yield {
|
|
7645
8342
|
__syncing: ctx.__syncing,
|
|
7646
8343
|
data: {
|
|
7647
|
-
|
|
7648
|
-
isGlobal,
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
8344
|
+
signal_name: _signal,
|
|
8345
|
+
is_global: isGlobal,
|
|
8346
|
+
task_name: task.name,
|
|
8347
|
+
task_version: task.version,
|
|
8348
|
+
service_name: serviceName2
|
|
7652
8349
|
},
|
|
7653
8350
|
__taskName: task.name,
|
|
7654
8351
|
__signal: signal
|
|
@@ -7689,6 +8386,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7689
8386
|
});
|
|
7690
8387
|
const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
|
|
7691
8388
|
for (const intent of intents) {
|
|
8389
|
+
if (!isRegistrableLocalIntentDefinition(intent)) {
|
|
8390
|
+
continue;
|
|
8391
|
+
}
|
|
7692
8392
|
const intentData = buildIntentRegistryData(intent);
|
|
7693
8393
|
if (!intentData) {
|
|
7694
8394
|
continue;
|
|
@@ -7707,7 +8407,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7707
8407
|
);
|
|
7708
8408
|
const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
|
|
7709
8409
|
"Record intent definition registration",
|
|
7710
|
-
(ctx) => {
|
|
8410
|
+
(ctx, emit) => {
|
|
7711
8411
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7712
8412
|
return;
|
|
7713
8413
|
}
|
|
@@ -7715,6 +8415,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7715
8415
|
delayMs: 3e3
|
|
7716
8416
|
});
|
|
7717
8417
|
this.registeredIntentDefinitions.add(ctx.__intentName);
|
|
8418
|
+
emit(
|
|
8419
|
+
"meta.sync_controller.intent_registered",
|
|
8420
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
8421
|
+
__intentName: ctx.__intentName
|
|
8422
|
+
})
|
|
8423
|
+
);
|
|
7718
8424
|
return true;
|
|
7719
8425
|
}
|
|
7720
8426
|
).then(gatherIntentRegistrationTask);
|
|
@@ -7726,13 +8432,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7726
8432
|
const registerIntentTask = CadenzaService.createMetaTask(
|
|
7727
8433
|
"Record intent registration",
|
|
7728
8434
|
(ctx) => {
|
|
8435
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7729
8436
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7730
8437
|
return;
|
|
7731
8438
|
}
|
|
7732
8439
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7733
8440
|
delayMs: 3e3
|
|
7734
8441
|
});
|
|
7735
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7736
8442
|
if (!task) {
|
|
7737
8443
|
return true;
|
|
7738
8444
|
}
|
|
@@ -7744,7 +8450,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7744
8450
|
"Split intents of task",
|
|
7745
8451
|
function* (ctx) {
|
|
7746
8452
|
const task = ctx.task;
|
|
7747
|
-
if (task.hidden || !task.register || !task.registered)
|
|
8453
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
8454
|
+
return false;
|
|
7748
8455
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7749
8456
|
if (!serviceName2) {
|
|
7750
8457
|
return false;
|
|
@@ -7779,19 +8486,19 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7779
8486
|
yield {
|
|
7780
8487
|
__syncing: ctx.__syncing,
|
|
7781
8488
|
data: {
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
8489
|
+
intent_name: intent,
|
|
8490
|
+
task_name: task.name,
|
|
8491
|
+
task_version: task.version,
|
|
8492
|
+
service_name: serviceName2
|
|
7786
8493
|
},
|
|
7787
8494
|
__taskName: task.name,
|
|
7788
8495
|
__intent: intent,
|
|
7789
8496
|
__intentDefinition: intentDefinition,
|
|
7790
8497
|
__intentMapData: {
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
8498
|
+
intent_name: intent,
|
|
8499
|
+
task_name: task.name,
|
|
8500
|
+
task_version: task.version,
|
|
8501
|
+
service_name: serviceName2
|
|
7795
8502
|
}
|
|
7796
8503
|
};
|
|
7797
8504
|
emittedCount += 1;
|
|
@@ -7799,30 +8506,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7799
8506
|
return emittedCount > 0;
|
|
7800
8507
|
}.bind(this)
|
|
7801
8508
|
);
|
|
7802
|
-
const prepareIntentDefinitionForIntentMapTask = CadenzaService.createMetaTask(
|
|
7803
|
-
"Prepare intent definition for intent-to-task map",
|
|
7804
|
-
(ctx) => {
|
|
7805
|
-
if (!ctx.__intentDefinition || !ctx.__intentMapData) {
|
|
7806
|
-
return false;
|
|
7807
|
-
}
|
|
7808
|
-
return {
|
|
7809
|
-
...ctx,
|
|
7810
|
-
data: ctx.__intentDefinition
|
|
7811
|
-
};
|
|
7812
|
-
}
|
|
7813
|
-
);
|
|
7814
|
-
const restoreIntentToTaskMapPayloadTask = CadenzaService.createMetaTask(
|
|
7815
|
-
"Restore intent-to-task map payload",
|
|
7816
|
-
(ctx) => {
|
|
7817
|
-
if (!ctx.__intentMapData) {
|
|
7818
|
-
return false;
|
|
7819
|
-
}
|
|
7820
|
-
return {
|
|
7821
|
-
...ctx,
|
|
7822
|
-
data: ctx.__intentMapData
|
|
7823
|
-
};
|
|
7824
|
-
}
|
|
7825
|
-
);
|
|
7826
8509
|
const intentToTaskMapGraph = resolveSyncInsertTask(
|
|
7827
8510
|
this.isCadenzaDBReady,
|
|
7828
8511
|
"intent_to_task_map",
|
|
@@ -7841,20 +8524,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7841
8524
|
},
|
|
7842
8525
|
{ concurrency: 30 }
|
|
7843
8526
|
);
|
|
7844
|
-
this.registerIntentToTaskMapTask.then(prepareIntentDefinitionForIntentMapTask);
|
|
7845
|
-
if (ensureIntentRegistryBeforeIntentMapTask) {
|
|
7846
|
-
wireSyncTaskGraph(
|
|
7847
|
-
prepareIntentDefinitionForIntentMapTask,
|
|
7848
|
-
ensureIntentRegistryBeforeIntentMapTask,
|
|
7849
|
-
restoreIntentToTaskMapPayloadTask
|
|
7850
|
-
);
|
|
7851
|
-
} else {
|
|
7852
|
-
prepareIntentDefinitionForIntentMapTask.then(
|
|
7853
|
-
restoreIntentToTaskMapPayloadTask
|
|
7854
|
-
);
|
|
7855
|
-
}
|
|
7856
8527
|
wireSyncTaskGraph(
|
|
7857
|
-
|
|
8528
|
+
this.registerIntentToTaskMapTask,
|
|
7858
8529
|
intentToTaskMapGraph,
|
|
7859
8530
|
registerIntentTask
|
|
7860
8531
|
);
|
|
@@ -7865,7 +8536,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7865
8536
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7866
8537
|
delayMs: 3e3
|
|
7867
8538
|
});
|
|
7868
|
-
if (task.hidden || !task.register)
|
|
8539
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered) {
|
|
8540
|
+
return;
|
|
8541
|
+
}
|
|
7869
8542
|
const predecessorServiceName = resolveSyncServiceName(task);
|
|
7870
8543
|
if (!predecessorServiceName) {
|
|
7871
8544
|
return;
|
|
@@ -7880,12 +8553,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7880
8553
|
}
|
|
7881
8554
|
yield {
|
|
7882
8555
|
data: {
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
predecessorServiceName
|
|
8556
|
+
task_name: t.name,
|
|
8557
|
+
task_version: t.version,
|
|
8558
|
+
predecessor_task_name: task.name,
|
|
8559
|
+
predecessor_task_version: task.version,
|
|
8560
|
+
service_name: serviceName2,
|
|
8561
|
+
predecessor_service_name: predecessorServiceName
|
|
7889
8562
|
},
|
|
7890
8563
|
__taskName: task.name,
|
|
7891
8564
|
__nextTaskName: t.name
|
|
@@ -7932,519 +8605,598 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7932
8605
|
taskMapRegistrationGraph,
|
|
7933
8606
|
recordTaskMapRegistrationTask
|
|
7934
8607
|
);
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
task_name: task.remoteRoutineName,
|
|
7950
|
-
task_version: 1,
|
|
7951
|
-
service_name: serviceName2,
|
|
7952
|
-
predecessor_task_name: task.name,
|
|
7953
|
-
predecessor_task_version: task.version,
|
|
7954
|
-
predecessor_service_name: predecessorServiceName
|
|
7955
|
-
},
|
|
7956
|
-
__taskName: task.name
|
|
7957
|
-
};
|
|
8608
|
+
const hasPendingDirectionalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8609
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8610
|
+
return false;
|
|
8611
|
+
}
|
|
8612
|
+
const predecessorServiceName = resolveSyncServiceName(task);
|
|
8613
|
+
if (!predecessorServiceName) {
|
|
8614
|
+
return false;
|
|
8615
|
+
}
|
|
8616
|
+
for (const nextTask of task.nextTasks) {
|
|
8617
|
+
if (task.taskMapRegistration.has(nextTask.name) || nextTask.isHidden || !nextTask.register || !nextTask.registered) {
|
|
8618
|
+
continue;
|
|
8619
|
+
}
|
|
8620
|
+
if (resolveSyncServiceName(nextTask)) {
|
|
8621
|
+
return true;
|
|
7958
8622
|
}
|
|
7959
8623
|
}
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
"task_version",
|
|
7970
|
-
"predecessor_task_version",
|
|
7971
|
-
"service_name",
|
|
7972
|
-
"predecessor_service_name"
|
|
7973
|
-
],
|
|
7974
|
-
action: {
|
|
7975
|
-
do: "nothing"
|
|
7976
|
-
}
|
|
8624
|
+
return false;
|
|
8625
|
+
});
|
|
8626
|
+
const hasPendingSignalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8627
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8628
|
+
return false;
|
|
8629
|
+
}
|
|
8630
|
+
for (const signal of task.observedSignals) {
|
|
8631
|
+
if (task.registeredSignals.has(signal)) {
|
|
8632
|
+
continue;
|
|
7977
8633
|
}
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
const recordDeputyRelationshipRegistrationTask = CadenzaService.createMetaTask(
|
|
7982
|
-
"Record deputy relationship registration",
|
|
7983
|
-
(ctx) => {
|
|
7984
|
-
if (!didSyncInsertSucceed(ctx)) {
|
|
7985
|
-
return;
|
|
8634
|
+
const signalName = signal.split(":")[0];
|
|
8635
|
+
if (!decomposeSignalName(signalName).isGlobal) {
|
|
8636
|
+
continue;
|
|
7986
8637
|
}
|
|
7987
|
-
CadenzaService.
|
|
7988
|
-
|
|
7989
|
-
});
|
|
7990
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7991
|
-
if (!task) {
|
|
7992
|
-
return true;
|
|
8638
|
+
if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
|
|
8639
|
+
continue;
|
|
7993
8640
|
}
|
|
7994
|
-
|
|
8641
|
+
return true;
|
|
7995
8642
|
}
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8643
|
+
return false;
|
|
8644
|
+
});
|
|
8645
|
+
const hasPendingIntentTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8646
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8647
|
+
return false;
|
|
8648
|
+
}
|
|
8649
|
+
const registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
|
|
8650
|
+
for (const intent of task.handlesIntents) {
|
|
8651
|
+
if (registeredIntents.has(intent) || isLocalOnlySyncIntent(intent)) {
|
|
8652
|
+
continue;
|
|
8653
|
+
}
|
|
8654
|
+
if (isMetaIntentName(intent) && !task.isMeta) {
|
|
8655
|
+
continue;
|
|
8656
|
+
}
|
|
8657
|
+
const intentDefinition = buildIntentRegistryData(CadenzaService.inquiryBroker.intents.get(intent)) ?? buildIntentRegistryData({ name: intent });
|
|
8658
|
+
if (!intentDefinition) {
|
|
8659
|
+
continue;
|
|
8660
|
+
}
|
|
8661
|
+
return true;
|
|
8662
|
+
}
|
|
8663
|
+
return false;
|
|
8664
|
+
});
|
|
8665
|
+
const hasPendingActorTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8666
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8667
|
+
return false;
|
|
8668
|
+
}
|
|
8669
|
+
const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
|
|
8670
|
+
if (!metadata?.actorName) {
|
|
8671
|
+
return false;
|
|
8672
|
+
}
|
|
8673
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8674
|
+
if (!serviceName2) {
|
|
8675
|
+
return false;
|
|
8676
|
+
}
|
|
8677
|
+
const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
|
|
8678
|
+
return !this.registeredActorTaskMaps.has(registrationKey);
|
|
8679
|
+
});
|
|
8680
|
+
const hasPendingRoutineTaskMaps = () => getRegistrableRoutines().some((routine) => {
|
|
8681
|
+
if (!routine.registered) {
|
|
8682
|
+
return false;
|
|
8683
|
+
}
|
|
8684
|
+
for (const task of routine.tasks) {
|
|
8685
|
+
if (!task) {
|
|
8686
|
+
continue;
|
|
8687
|
+
}
|
|
8688
|
+
const tasks = task.getIterator();
|
|
8689
|
+
while (tasks.hasNext()) {
|
|
8690
|
+
const nextTask = tasks.next();
|
|
8691
|
+
if (!nextTask?.registered) {
|
|
8010
8692
|
continue;
|
|
8011
8693
|
}
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
continue;
|
|
8694
|
+
if (!routine.registeredTasks.has(nextTask.name)) {
|
|
8695
|
+
return true;
|
|
8015
8696
|
}
|
|
8016
|
-
task.registered = true;
|
|
8017
|
-
changed = true;
|
|
8018
|
-
emit("meta.sync_controller.task_registered", {
|
|
8019
|
-
...ctx,
|
|
8020
|
-
__taskName: task.name,
|
|
8021
|
-
task,
|
|
8022
|
-
__authoritativeReconciliation: true
|
|
8023
|
-
});
|
|
8024
8697
|
}
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8698
|
+
}
|
|
8699
|
+
return false;
|
|
8700
|
+
});
|
|
8701
|
+
const gatherDirectionalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8702
|
+
"Gather directional task map registration",
|
|
8703
|
+
(ctx) => {
|
|
8704
|
+
if (hasPendingDirectionalTaskMaps()) {
|
|
8705
|
+
this.directionalTaskMapsSynced = false;
|
|
8706
|
+
return false;
|
|
8030
8707
|
}
|
|
8031
|
-
|
|
8708
|
+
this.directionalTaskMapsSynced = true;
|
|
8709
|
+
return ctx;
|
|
8032
8710
|
},
|
|
8033
|
-
"
|
|
8711
|
+
"Completes directional task graph registration when task edges and deputy edges are registered.",
|
|
8034
8712
|
{
|
|
8035
8713
|
register: false,
|
|
8036
8714
|
isHidden: true
|
|
8037
8715
|
}
|
|
8038
8716
|
);
|
|
8039
|
-
const
|
|
8040
|
-
"
|
|
8041
|
-
(ctx
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
const routineName = typeof row.name === "string" ? row.name : "";
|
|
8046
|
-
if (!routineName) {
|
|
8047
|
-
continue;
|
|
8048
|
-
}
|
|
8049
|
-
const routine = CadenzaService.getRoutine(routineName);
|
|
8050
|
-
if (!routine || routine.registered) {
|
|
8051
|
-
continue;
|
|
8052
|
-
}
|
|
8053
|
-
routine.registered = true;
|
|
8054
|
-
changed = true;
|
|
8717
|
+
const gatherSignalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8718
|
+
"Gather signal task map registration",
|
|
8719
|
+
(ctx) => {
|
|
8720
|
+
if (hasPendingSignalTaskMaps()) {
|
|
8721
|
+
this.signalTaskMapsSynced = false;
|
|
8722
|
+
return false;
|
|
8055
8723
|
}
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8724
|
+
this.signalTaskMapsSynced = true;
|
|
8725
|
+
return ctx;
|
|
8726
|
+
},
|
|
8727
|
+
"Completes signal-to-task map registration when all global observed signal edges are registered.",
|
|
8728
|
+
{
|
|
8729
|
+
register: false,
|
|
8730
|
+
isHidden: true
|
|
8731
|
+
}
|
|
8732
|
+
);
|
|
8733
|
+
const gatherIntentTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8734
|
+
"Gather intent task map registration",
|
|
8735
|
+
(ctx) => {
|
|
8736
|
+
if (hasPendingIntentTaskMaps()) {
|
|
8737
|
+
this.intentTaskMapsSynced = false;
|
|
8738
|
+
return false;
|
|
8061
8739
|
}
|
|
8062
|
-
|
|
8740
|
+
this.intentTaskMapsSynced = true;
|
|
8741
|
+
return ctx;
|
|
8063
8742
|
},
|
|
8064
|
-
"
|
|
8743
|
+
"Completes intent-to-task map registration when all task responders are registered.",
|
|
8065
8744
|
{
|
|
8066
8745
|
register: false,
|
|
8067
8746
|
isHidden: true
|
|
8068
8747
|
}
|
|
8069
8748
|
);
|
|
8070
|
-
const
|
|
8071
|
-
"
|
|
8072
|
-
(ctx
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
for (const row of authoritativeSignals) {
|
|
8077
|
-
const signalName = typeof row.name === "string" ? row.name : "";
|
|
8078
|
-
if (!signalName) {
|
|
8079
|
-
continue;
|
|
8080
|
-
}
|
|
8081
|
-
const observer = signalObservers?.get(signalName);
|
|
8082
|
-
if (!observer || observer.registered) {
|
|
8083
|
-
continue;
|
|
8084
|
-
}
|
|
8085
|
-
observer.registered = true;
|
|
8086
|
-
changed = true;
|
|
8749
|
+
const gatherActorTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8750
|
+
"Gather actor task map registration",
|
|
8751
|
+
(ctx) => {
|
|
8752
|
+
if (hasPendingActorTaskMaps()) {
|
|
8753
|
+
this.actorTaskMapsSynced = false;
|
|
8754
|
+
return false;
|
|
8087
8755
|
}
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8756
|
+
this.actorTaskMapsSynced = true;
|
|
8757
|
+
return ctx;
|
|
8758
|
+
},
|
|
8759
|
+
"Completes actor-to-task map registration when all actor-backed tasks are registered.",
|
|
8760
|
+
{
|
|
8761
|
+
register: false,
|
|
8762
|
+
isHidden: true
|
|
8763
|
+
}
|
|
8764
|
+
);
|
|
8765
|
+
const gatherRoutineTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8766
|
+
"Gather routine task map registration",
|
|
8767
|
+
(ctx) => {
|
|
8768
|
+
if (hasPendingRoutineTaskMaps()) {
|
|
8769
|
+
this.routineTaskMapsSynced = false;
|
|
8770
|
+
return false;
|
|
8093
8771
|
}
|
|
8094
|
-
|
|
8772
|
+
this.routineTaskMapsSynced = true;
|
|
8773
|
+
return ctx;
|
|
8095
8774
|
},
|
|
8096
|
-
"
|
|
8775
|
+
"Completes task-to-routine map registration when all routine task memberships are registered.",
|
|
8097
8776
|
{
|
|
8098
8777
|
register: false,
|
|
8099
8778
|
isHidden: true
|
|
8100
8779
|
}
|
|
8101
8780
|
);
|
|
8102
|
-
const
|
|
8103
|
-
"
|
|
8781
|
+
const finishSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8782
|
+
"Finish sync",
|
|
8104
8783
|
(ctx, emit) => {
|
|
8105
|
-
const
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8784
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8785
|
+
if (syncCycleId && this.activeSyncCycleId === syncCycleId) {
|
|
8786
|
+
this.activeSyncCycleId = null;
|
|
8787
|
+
this.activeSyncCycleStartedAt = 0;
|
|
8788
|
+
}
|
|
8789
|
+
if (this.pendingBootstrapSyncRerun) {
|
|
8790
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8791
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
8792
|
+
delayMs: 100
|
|
8793
|
+
});
|
|
8794
|
+
}
|
|
8795
|
+
emit("global.meta.sync_controller.synced", {
|
|
8796
|
+
data: {
|
|
8797
|
+
is_active: true,
|
|
8798
|
+
is_non_responsive: false,
|
|
8799
|
+
is_blocked: false,
|
|
8800
|
+
last_active: formatTimestamp(Date.now())
|
|
8801
|
+
},
|
|
8802
|
+
filter: {
|
|
8803
|
+
uuid: CadenzaService.serviceRegistry.serviceInstanceId
|
|
8114
8804
|
}
|
|
8115
|
-
|
|
8116
|
-
|
|
8805
|
+
});
|
|
8806
|
+
return true;
|
|
8807
|
+
},
|
|
8808
|
+
"Marks the current bootstrap sync cycle as complete.",
|
|
8809
|
+
{
|
|
8810
|
+
register: false,
|
|
8811
|
+
isHidden: true
|
|
8812
|
+
}
|
|
8813
|
+
).attachSignal("global.meta.sync_controller.synced");
|
|
8814
|
+
const mapPhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8815
|
+
"Complete map sync phase",
|
|
8816
|
+
(ctx) => {
|
|
8817
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8818
|
+
if (!syncCycleId) {
|
|
8819
|
+
return false;
|
|
8117
8820
|
}
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8821
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8822
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
8823
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] map_barrier_check", {
|
|
8824
|
+
serviceName: serviceName2,
|
|
8825
|
+
syncCycleId,
|
|
8826
|
+
directionalTaskMapsSynced: this.directionalTaskMapsSynced,
|
|
8827
|
+
signalTaskMapsSynced: this.signalTaskMapsSynced,
|
|
8828
|
+
intentTaskMapsSynced: this.intentTaskMapsSynced,
|
|
8829
|
+
actorTaskMapsSynced: this.actorTaskMapsSynced,
|
|
8830
|
+
routineTaskMapsSynced: this.routineTaskMapsSynced
|
|
8122
8831
|
});
|
|
8123
8832
|
}
|
|
8124
|
-
|
|
8833
|
+
if (!this.directionalTaskMapsSynced || !this.signalTaskMapsSynced || !this.intentTaskMapsSynced || !this.actorTaskMapsSynced || !this.routineTaskMapsSynced) {
|
|
8834
|
+
return false;
|
|
8835
|
+
}
|
|
8836
|
+
if (!markCompletedSyncCycle(this.mapPhaseCompletedCycles, syncCycleId)) {
|
|
8837
|
+
return false;
|
|
8838
|
+
}
|
|
8839
|
+
return ctx;
|
|
8125
8840
|
},
|
|
8126
|
-
"
|
|
8841
|
+
"Fans in map branch completion and ends the current sync cycle once every map branch is complete.",
|
|
8842
|
+
{
|
|
8843
|
+
register: false,
|
|
8844
|
+
isHidden: true
|
|
8845
|
+
}
|
|
8846
|
+
).then(finishSyncTask);
|
|
8847
|
+
const startDirectionalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8848
|
+
"Start directional task map sync",
|
|
8849
|
+
(ctx) => ctx,
|
|
8850
|
+
"Starts the directional task graph map branch for the current sync cycle.",
|
|
8127
8851
|
{
|
|
8128
8852
|
register: false,
|
|
8129
8853
|
isHidden: true
|
|
8130
8854
|
}
|
|
8131
8855
|
);
|
|
8132
|
-
const
|
|
8133
|
-
"
|
|
8134
|
-
() =>
|
|
8135
|
-
"
|
|
8856
|
+
const startSignalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8857
|
+
"Start signal task map sync",
|
|
8858
|
+
(ctx) => ctx,
|
|
8859
|
+
"Starts the signal-to-task map branch for the current sync cycle.",
|
|
8136
8860
|
{
|
|
8137
8861
|
register: false,
|
|
8138
8862
|
isHidden: true
|
|
8139
8863
|
}
|
|
8140
8864
|
);
|
|
8141
|
-
const
|
|
8142
|
-
"
|
|
8143
|
-
() =>
|
|
8144
|
-
"
|
|
8865
|
+
const startIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8866
|
+
"Start intent task map sync",
|
|
8867
|
+
(ctx) => ctx,
|
|
8868
|
+
"Starts the intent-to-task map branch for the current sync cycle.",
|
|
8145
8869
|
{
|
|
8146
8870
|
register: false,
|
|
8147
8871
|
isHidden: true
|
|
8148
8872
|
}
|
|
8149
8873
|
);
|
|
8150
|
-
const
|
|
8151
|
-
"
|
|
8152
|
-
() =>
|
|
8153
|
-
"
|
|
8874
|
+
const startActorTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8875
|
+
"Start actor task map sync",
|
|
8876
|
+
(ctx) => ctx,
|
|
8877
|
+
"Starts the actor-to-task map branch for the current sync cycle.",
|
|
8154
8878
|
{
|
|
8155
8879
|
register: false,
|
|
8156
8880
|
isHidden: true
|
|
8157
8881
|
}
|
|
8158
8882
|
);
|
|
8159
|
-
const
|
|
8160
|
-
"
|
|
8161
|
-
() =>
|
|
8162
|
-
"
|
|
8883
|
+
const startRoutineTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8884
|
+
"Start routine task map sync",
|
|
8885
|
+
(ctx) => ctx,
|
|
8886
|
+
"Starts the task-to-routine map branch for the current sync cycle.",
|
|
8163
8887
|
{
|
|
8164
8888
|
register: false,
|
|
8165
8889
|
isHidden: true
|
|
8166
8890
|
}
|
|
8167
8891
|
);
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
reconcileTaskRegistrationFromAuthorityTask
|
|
8171
|
-
);
|
|
8172
|
-
}
|
|
8173
|
-
if (authoritativeRoutineQueryGraph) {
|
|
8174
|
-
authoritativeRoutineQueryGraph.completionTask.then(
|
|
8175
|
-
reconcileRoutineRegistrationFromAuthorityTask
|
|
8176
|
-
);
|
|
8177
|
-
}
|
|
8178
|
-
if (authoritativeSignalQueryGraph) {
|
|
8179
|
-
authoritativeSignalQueryGraph.completionTask.then(
|
|
8180
|
-
reconcileSignalRegistrationFromAuthorityTask
|
|
8181
|
-
);
|
|
8182
|
-
}
|
|
8183
|
-
if (authoritativeIntentQueryGraph) {
|
|
8184
|
-
authoritativeIntentQueryGraph.completionTask.then(
|
|
8185
|
-
reconcileIntentRegistrationFromAuthorityTask
|
|
8186
|
-
);
|
|
8187
|
-
}
|
|
8188
|
-
const authoritativeRegistrationTriggers = [
|
|
8189
|
-
"meta.service_registry.initial_sync_complete",
|
|
8190
|
-
"meta.sync_requested",
|
|
8191
|
-
"meta.sync_controller.synced_resource",
|
|
8192
|
-
"meta.sync_controller.authority_registration_reconciliation_requested"
|
|
8193
|
-
];
|
|
8194
|
-
CadenzaService.createMetaTask(
|
|
8195
|
-
"Prepare authoritative task registration query",
|
|
8892
|
+
const primitivePhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8893
|
+
"Complete primitive sync phase",
|
|
8196
8894
|
(ctx) => {
|
|
8197
|
-
|
|
8895
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8896
|
+
if (!syncCycleId) {
|
|
8198
8897
|
return false;
|
|
8199
8898
|
}
|
|
8200
|
-
const serviceName2 = resolveSyncServiceName();
|
|
8201
|
-
if (
|
|
8899
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8900
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
8901
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] primitive_barrier_check", {
|
|
8902
|
+
serviceName: serviceName2,
|
|
8903
|
+
syncCycleId,
|
|
8904
|
+
tasksSynced: this.tasksSynced,
|
|
8905
|
+
signalsSynced: this.signalsSynced,
|
|
8906
|
+
intentsSynced: this.intentsSynced,
|
|
8907
|
+
actorsSynced: this.actorsSynced,
|
|
8908
|
+
routinesSynced: this.routinesSynced
|
|
8909
|
+
});
|
|
8910
|
+
}
|
|
8911
|
+
if (!this.tasksSynced || !this.signalsSynced || !this.intentsSynced || !this.actorsSynced || !this.routinesSynced) {
|
|
8202
8912
|
return false;
|
|
8203
8913
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
};
|
|
8914
|
+
if (!markCompletedSyncCycle(this.primitivePhaseCompletedCycles, syncCycleId)) {
|
|
8915
|
+
return false;
|
|
8916
|
+
}
|
|
8917
|
+
this.directionalTaskMapsSynced = false;
|
|
8918
|
+
this.signalTaskMapsSynced = false;
|
|
8919
|
+
this.intentTaskMapsSynced = false;
|
|
8920
|
+
this.actorTaskMapsSynced = false;
|
|
8921
|
+
this.routineTaskMapsSynced = false;
|
|
8922
|
+
return ctx;
|
|
8214
8923
|
},
|
|
8215
|
-
"
|
|
8924
|
+
"Fans in primitive registration and opens the map registration phase once every primitive branch is complete.",
|
|
8216
8925
|
{
|
|
8217
8926
|
register: false,
|
|
8218
8927
|
isHidden: true
|
|
8219
8928
|
}
|
|
8220
|
-
).
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8929
|
+
).then(
|
|
8930
|
+
startDirectionalTaskMapSyncTask,
|
|
8931
|
+
startSignalTaskMapSyncTask,
|
|
8932
|
+
startIntentTaskMapSyncTask,
|
|
8933
|
+
startActorTaskMapSyncTask,
|
|
8934
|
+
startRoutineTaskMapSyncTask
|
|
8935
|
+
);
|
|
8936
|
+
gatherTaskRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8937
|
+
gatherSignalRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8938
|
+
gatherIntentRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8939
|
+
gatherActorRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8940
|
+
gatherRoutineRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8941
|
+
const markLocalServiceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8942
|
+
"Mark local service inserted for bootstrap sync",
|
|
8225
8943
|
(ctx) => {
|
|
8226
|
-
if (!this.isCadenzaDBReady) {
|
|
8227
|
-
return false;
|
|
8228
|
-
}
|
|
8229
8944
|
const serviceName2 = resolveSyncServiceName();
|
|
8230
|
-
|
|
8945
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8946
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8231
8947
|
return false;
|
|
8232
8948
|
}
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
__syncServiceName: serviceName2,
|
|
8236
|
-
queryData: {
|
|
8237
|
-
filter: {
|
|
8238
|
-
service_name: serviceName2
|
|
8239
|
-
},
|
|
8240
|
-
fields: ["name", "version", "service_name"]
|
|
8241
|
-
}
|
|
8242
|
-
};
|
|
8949
|
+
this.localServiceInserted = true;
|
|
8950
|
+
return true;
|
|
8243
8951
|
},
|
|
8244
|
-
"
|
|
8952
|
+
"Marks that the local service row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8245
8953
|
{
|
|
8246
8954
|
register: false,
|
|
8247
8955
|
isHidden: true
|
|
8248
8956
|
}
|
|
8249
|
-
).doOn(
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
CadenzaService.createMetaTask(
|
|
8253
|
-
"Prepare authoritative signal registration query",
|
|
8957
|
+
).doOn("meta.service_registry.service_inserted");
|
|
8958
|
+
const markLocalServiceInstanceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8959
|
+
"Mark local service instance inserted for bootstrap sync",
|
|
8254
8960
|
(ctx) => {
|
|
8255
|
-
|
|
8961
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8962
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8963
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8256
8964
|
return false;
|
|
8257
8965
|
}
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
queryData: {
|
|
8261
|
-
fields: ["name"]
|
|
8262
|
-
}
|
|
8263
|
-
};
|
|
8966
|
+
this.localServiceInstanceInserted = true;
|
|
8967
|
+
return true;
|
|
8264
8968
|
},
|
|
8265
|
-
"
|
|
8969
|
+
"Marks that the local service instance row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8266
8970
|
{
|
|
8267
8971
|
register: false,
|
|
8268
8972
|
isHidden: true
|
|
8269
8973
|
}
|
|
8270
|
-
).doOn(
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
CadenzaService.createMetaTask(
|
|
8274
|
-
"Prepare authoritative intent registration query",
|
|
8974
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8975
|
+
const startBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8976
|
+
"Start bootstrap graph sync",
|
|
8275
8977
|
(ctx) => {
|
|
8276
|
-
|
|
8978
|
+
const now = Date.now();
|
|
8979
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8980
|
+
const serviceInstanceId = CadenzaService.serviceRegistry.serviceInstanceId;
|
|
8981
|
+
if (!serviceName2 || !serviceInstanceId) {
|
|
8982
|
+
return false;
|
|
8983
|
+
}
|
|
8984
|
+
if (!this.localServiceInserted) {
|
|
8985
|
+
return false;
|
|
8986
|
+
}
|
|
8987
|
+
if (!this.localServiceInstanceInserted) {
|
|
8988
|
+
return false;
|
|
8989
|
+
}
|
|
8990
|
+
if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
|
|
8277
8991
|
return false;
|
|
8278
8992
|
}
|
|
8993
|
+
if (this.activeSyncCycleId) {
|
|
8994
|
+
const activeCycleAgeMs = now - this.activeSyncCycleStartedAt;
|
|
8995
|
+
if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
|
|
8996
|
+
this.pendingBootstrapSyncRerun = true;
|
|
8997
|
+
return false;
|
|
8998
|
+
}
|
|
8999
|
+
}
|
|
9000
|
+
const syncCycleId = `${now}-${++this.syncCycleCounter}`;
|
|
9001
|
+
this.activeSyncCycleId = syncCycleId;
|
|
9002
|
+
this.activeSyncCycleStartedAt = now;
|
|
9003
|
+
this.pendingBootstrapSyncRerun = false;
|
|
9004
|
+
this.tasksSynced = false;
|
|
9005
|
+
this.signalsSynced = false;
|
|
9006
|
+
this.intentsSynced = false;
|
|
9007
|
+
this.actorsSynced = false;
|
|
9008
|
+
this.routinesSynced = false;
|
|
8279
9009
|
return {
|
|
8280
9010
|
...ctx,
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
9011
|
+
__syncing: true,
|
|
9012
|
+
__syncCycleId: syncCycleId,
|
|
9013
|
+
__serviceName: serviceName2,
|
|
9014
|
+
__serviceInstanceId: serviceInstanceId
|
|
8284
9015
|
};
|
|
8285
9016
|
},
|
|
8286
|
-
"
|
|
9017
|
+
"Starts a deterministic bootstrap sync cycle once the local service instance exists.",
|
|
8287
9018
|
{
|
|
8288
9019
|
register: false,
|
|
8289
9020
|
isHidden: true
|
|
8290
9021
|
}
|
|
8291
|
-
).doOn(
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
CadenzaService.signalBroker.getSignalsTask.clone().doOn(
|
|
8295
|
-
"meta.sync_controller.sync_tick",
|
|
8296
|
-
"meta.service_registry.initial_sync_complete",
|
|
8297
|
-
"meta.sync_requested"
|
|
8298
|
-
).then(this.splitSignalsTask);
|
|
8299
|
-
CadenzaService.registry.getAllTasks.clone().doOn(
|
|
8300
|
-
"meta.sync_controller.sync_tick",
|
|
8301
|
-
"meta.sync_controller.synced_signals",
|
|
8302
|
-
"meta.sync_requested"
|
|
8303
|
-
).then(this.splitTasksForRegistration);
|
|
8304
|
-
CadenzaService.createMetaTask("Get all intents", (ctx) => {
|
|
8305
|
-
return {
|
|
8306
|
-
...ctx,
|
|
8307
|
-
intents: Array.from(CadenzaService.inquiryBroker.intents.values())
|
|
8308
|
-
};
|
|
8309
|
-
}).doOn(
|
|
8310
|
-
"meta.sync_controller.sync_tick",
|
|
8311
|
-
"meta.service_registry.initial_sync_complete",
|
|
8312
|
-
"meta.sync_requested"
|
|
8313
|
-
).then(this.splitIntentsTask);
|
|
8314
|
-
CadenzaService.registry.getAllRoutines.clone().doOn(
|
|
8315
|
-
"meta.sync_controller.sync_tick",
|
|
8316
|
-
"meta.service_registry.initial_sync_complete",
|
|
8317
|
-
"meta.sync_requested"
|
|
8318
|
-
).then(this.splitRoutinesTask);
|
|
8319
|
-
CadenzaService.createMetaTask("Get all actors", (ctx) => {
|
|
8320
|
-
return {
|
|
8321
|
-
...ctx,
|
|
8322
|
-
actors: CadenzaService.getAllActors()
|
|
8323
|
-
};
|
|
8324
|
-
}).doOn(
|
|
9022
|
+
).doOn(
|
|
9023
|
+
"meta.service_registry.service_inserted",
|
|
9024
|
+
"meta.service_registry.instance_inserted",
|
|
8325
9025
|
"meta.sync_controller.sync_tick",
|
|
8326
|
-
"meta.service_registry.initial_sync_complete",
|
|
8327
9026
|
"meta.sync_requested"
|
|
8328
|
-
)
|
|
8329
|
-
CadenzaService.createMetaTask(
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
9027
|
+
);
|
|
9028
|
+
const startTaskPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9029
|
+
"Start task primitive sync",
|
|
9030
|
+
(ctx) => ctx,
|
|
9031
|
+
"Starts the task registration branch for the current sync cycle.",
|
|
9032
|
+
{
|
|
9033
|
+
register: false,
|
|
9034
|
+
isHidden: true
|
|
8333
9035
|
}
|
|
8334
|
-
return {
|
|
8335
|
-
...ctx,
|
|
8336
|
-
task
|
|
8337
|
-
};
|
|
8338
|
-
}).doOn("meta.sync_controller.task_registered").then(
|
|
8339
|
-
this.registerTaskMapTask,
|
|
8340
|
-
this.registerDeputyRelationshipTask
|
|
8341
9036
|
);
|
|
8342
|
-
CadenzaService.
|
|
8343
|
-
"
|
|
8344
|
-
|
|
8345
|
-
"
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
if (!task) {
|
|
8350
|
-
return false;
|
|
9037
|
+
const startSignalPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9038
|
+
"Start signal primitive sync",
|
|
9039
|
+
(ctx) => ctx,
|
|
9040
|
+
"Starts the signal registration branch for the current sync cycle.",
|
|
9041
|
+
{
|
|
9042
|
+
register: false,
|
|
9043
|
+
isHidden: true
|
|
8351
9044
|
}
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
"meta.sync_requested"
|
|
8361
|
-
).then(this.registerIntentToTaskMapTask);
|
|
8362
|
-
CadenzaService.createMetaTask("Get registered task for intent sync", (ctx) => {
|
|
8363
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8364
|
-
if (!task) {
|
|
8365
|
-
return false;
|
|
9045
|
+
);
|
|
9046
|
+
const startIntentPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9047
|
+
"Start intent primitive sync",
|
|
9048
|
+
(ctx) => ctx,
|
|
9049
|
+
"Starts the intent registration branch for the current sync cycle.",
|
|
9050
|
+
{
|
|
9051
|
+
register: false,
|
|
9052
|
+
isHidden: true
|
|
8366
9053
|
}
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
"meta.sync_requested"
|
|
8376
|
-
).then(this.registerActorTaskMapTask);
|
|
8377
|
-
CadenzaService.createMetaTask("Get registered task for actor sync", (ctx) => {
|
|
8378
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8379
|
-
if (!task) {
|
|
8380
|
-
return false;
|
|
9054
|
+
);
|
|
9055
|
+
const startActorPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9056
|
+
"Start actor primitive sync",
|
|
9057
|
+
(ctx) => ctx,
|
|
9058
|
+
"Starts the actor registration branch for the current sync cycle.",
|
|
9059
|
+
{
|
|
9060
|
+
register: false,
|
|
9061
|
+
isHidden: true
|
|
8381
9062
|
}
|
|
8382
|
-
|
|
9063
|
+
);
|
|
9064
|
+
const startRoutinePrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9065
|
+
"Start routine primitive sync",
|
|
9066
|
+
(ctx) => ctx,
|
|
9067
|
+
"Starts the routine registration branch for the current sync cycle.",
|
|
9068
|
+
{
|
|
9069
|
+
register: false,
|
|
9070
|
+
isHidden: true
|
|
9071
|
+
}
|
|
9072
|
+
);
|
|
9073
|
+
startBootstrapSyncTask.then(
|
|
9074
|
+
startTaskPrimitiveSyncTask,
|
|
9075
|
+
startSignalPrimitiveSyncTask,
|
|
9076
|
+
startIntentPrimitiveSyncTask,
|
|
9077
|
+
startActorPrimitiveSyncTask,
|
|
9078
|
+
startRoutinePrimitiveSyncTask
|
|
9079
|
+
);
|
|
9080
|
+
const getAllTasksForSyncTask = CadenzaService.registry.getAllTasks.clone();
|
|
9081
|
+
startTaskPrimitiveSyncTask.then(
|
|
9082
|
+
getAllTasksForSyncTask,
|
|
9083
|
+
gatherTaskRegistrationTask
|
|
9084
|
+
);
|
|
9085
|
+
getAllTasksForSyncTask.then(this.splitTasksForRegistration);
|
|
9086
|
+
const getSignalsForSyncTask = CadenzaService.signalBroker.getSignalsTask.clone();
|
|
9087
|
+
startSignalPrimitiveSyncTask.then(
|
|
9088
|
+
getSignalsForSyncTask,
|
|
9089
|
+
gatherSignalRegistrationTask
|
|
9090
|
+
);
|
|
9091
|
+
getSignalsForSyncTask.then(this.splitSignalsTask);
|
|
9092
|
+
const getAllIntentsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
9093
|
+
"Get all intents for sync",
|
|
9094
|
+
(ctx) => ({
|
|
8383
9095
|
...ctx,
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
return ctx;
|
|
8394
|
-
}
|
|
8395
|
-
).then(this.registerActorTaskMapTask)
|
|
9096
|
+
intents: Array.from(CadenzaService.inquiryBroker.intents.values()).filter(
|
|
9097
|
+
(intent) => isRegistrableLocalIntentDefinition(intent)
|
|
9098
|
+
)
|
|
9099
|
+
}),
|
|
9100
|
+
"Collects local intents for the primitive sync phase.",
|
|
9101
|
+
{
|
|
9102
|
+
register: false,
|
|
9103
|
+
isHidden: true
|
|
9104
|
+
}
|
|
8396
9105
|
);
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
"meta.sync_requested"
|
|
8401
|
-
).then(
|
|
8402
|
-
CadenzaService.createMetaTask(
|
|
8403
|
-
"Ensure routine and task sync ready",
|
|
8404
|
-
(ctx) => {
|
|
8405
|
-
if (!this.tasksSynced || !this.routinesSynced) {
|
|
8406
|
-
return false;
|
|
8407
|
-
}
|
|
8408
|
-
return ctx;
|
|
8409
|
-
}
|
|
8410
|
-
).then(this.splitTasksInRoutines)
|
|
9106
|
+
startIntentPrimitiveSyncTask.then(
|
|
9107
|
+
getAllIntentsForSyncTask,
|
|
9108
|
+
gatherIntentRegistrationTask
|
|
8411
9109
|
);
|
|
8412
|
-
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
9110
|
+
getAllIntentsForSyncTask.then(this.splitIntentsTask);
|
|
9111
|
+
const getAllActorsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
9112
|
+
"Get all actors for sync",
|
|
9113
|
+
(ctx) => ({
|
|
9114
|
+
...ctx,
|
|
9115
|
+
actors: CadenzaService.getAllActors()
|
|
9116
|
+
}),
|
|
9117
|
+
"Collects local actors for the primitive sync phase.",
|
|
9118
|
+
{
|
|
9119
|
+
register: false,
|
|
9120
|
+
isHidden: true
|
|
9121
|
+
}
|
|
9122
|
+
);
|
|
9123
|
+
startActorPrimitiveSyncTask.then(
|
|
9124
|
+
getAllActorsForSyncTask,
|
|
9125
|
+
gatherActorRegistrationTask
|
|
9126
|
+
);
|
|
9127
|
+
getAllActorsForSyncTask.then(this.splitActorsForRegistration);
|
|
9128
|
+
const getAllRoutinesForSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
9129
|
+
startRoutinePrimitiveSyncTask.then(
|
|
9130
|
+
getAllRoutinesForSyncTask,
|
|
9131
|
+
gatherRoutineRegistrationTask
|
|
9132
|
+
);
|
|
9133
|
+
getAllRoutinesForSyncTask.then(this.splitRoutinesTask);
|
|
9134
|
+
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9135
|
+
startDirectionalTaskMapSyncTask.then(
|
|
9136
|
+
iterateTasksForDirectionalTaskMapSyncTask,
|
|
9137
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
9138
|
+
);
|
|
9139
|
+
iterateTasksForDirectionalTaskMapSyncTask.then(this.registerTaskMapTask);
|
|
9140
|
+
recordTaskMapRegistrationTask.then(gatherDirectionalTaskMapRegistrationTask);
|
|
9141
|
+
gatherDirectionalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9142
|
+
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9143
|
+
startSignalTaskMapSyncTask.then(
|
|
9144
|
+
iterateTasksForSignalTaskMapSyncTask,
|
|
9145
|
+
gatherSignalTaskMapRegistrationTask
|
|
9146
|
+
);
|
|
9147
|
+
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
9148
|
+
registerSignalTask.then(gatherSignalTaskMapRegistrationTask);
|
|
9149
|
+
gatherSignalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9150
|
+
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9151
|
+
startIntentTaskMapSyncTask.then(
|
|
9152
|
+
iterateTasksForIntentTaskMapSyncTask,
|
|
9153
|
+
gatherIntentTaskMapRegistrationTask
|
|
9154
|
+
);
|
|
9155
|
+
iterateTasksForIntentTaskMapSyncTask.then(this.registerIntentToTaskMapTask);
|
|
9156
|
+
registerIntentTask.then(gatherIntentTaskMapRegistrationTask);
|
|
9157
|
+
gatherIntentTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9158
|
+
const iterateTasksForActorTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9159
|
+
startActorTaskMapSyncTask.then(
|
|
9160
|
+
iterateTasksForActorTaskMapSyncTask,
|
|
9161
|
+
gatherActorTaskMapRegistrationTask
|
|
9162
|
+
);
|
|
9163
|
+
iterateTasksForActorTaskMapSyncTask.then(this.registerActorTaskMapTask);
|
|
9164
|
+
recordActorTaskMapRegistrationTask.then(gatherActorTaskMapRegistrationTask);
|
|
9165
|
+
gatherActorTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9166
|
+
const getAllRoutinesForTaskMapSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
9167
|
+
startRoutineTaskMapSyncTask.then(
|
|
9168
|
+
getAllRoutinesForTaskMapSyncTask,
|
|
9169
|
+
gatherRoutineTaskMapRegistrationTask
|
|
9170
|
+
);
|
|
9171
|
+
getAllRoutinesForTaskMapSyncTask.then(this.splitTasksInRoutines);
|
|
9172
|
+
registerTaskToRoutineMapTask.then(gatherRoutineTaskMapRegistrationTask);
|
|
9173
|
+
gatherRoutineTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9174
|
+
CadenzaService.createMetaTask(
|
|
9175
|
+
"Request sync after local service instance registration",
|
|
9176
|
+
(ctx) => {
|
|
9177
|
+
for (const delayMs of EARLY_SYNC_TICK_DELAYS_MS) {
|
|
9178
|
+
CadenzaService.schedule(
|
|
9179
|
+
"meta.sync_controller.sync_tick",
|
|
9180
|
+
{
|
|
9181
|
+
...buildMinimalSyncSignalContext(ctx),
|
|
9182
|
+
__syncing: true
|
|
9183
|
+
},
|
|
9184
|
+
delayMs
|
|
9185
|
+
);
|
|
8422
9186
|
}
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
{ __syncing: true },
|
|
8430
|
-
3e5,
|
|
8431
|
-
true
|
|
8432
|
-
);
|
|
8433
|
-
} else {
|
|
8434
|
-
CadenzaService.interval(
|
|
8435
|
-
"meta.sync_controller.sync_tick",
|
|
8436
|
-
{ __syncing: true },
|
|
8437
|
-
18e4
|
|
8438
|
-
);
|
|
8439
|
-
CadenzaService.schedule(
|
|
8440
|
-
"meta.sync_controller.sync_tick",
|
|
8441
|
-
{ __syncing: true },
|
|
8442
|
-
250
|
|
8443
|
-
);
|
|
8444
|
-
for (const delayMs of EARLY_SYNC_REQUEST_DELAYS_MS) {
|
|
8445
|
-
CadenzaService.schedule("meta.sync_requested", { __syncing: true }, delayMs);
|
|
9187
|
+
return true;
|
|
9188
|
+
},
|
|
9189
|
+
"Schedules the early bootstrap sync burst after local instance registration so startup-defined primitives can converge deterministically.",
|
|
9190
|
+
{
|
|
9191
|
+
register: false,
|
|
9192
|
+
isHidden: true
|
|
8446
9193
|
}
|
|
8447
|
-
|
|
9194
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
9195
|
+
CadenzaService.interval(
|
|
9196
|
+
"meta.sync_controller.sync_tick",
|
|
9197
|
+
{ __syncing: true },
|
|
9198
|
+
this.isCadenzaDBReady ? 18e4 : 3e5
|
|
9199
|
+
);
|
|
8448
9200
|
}
|
|
8449
9201
|
};
|
|
8450
9202
|
|
|
@@ -8618,7 +9370,53 @@ function resolveBootstrapEndpoint(options) {
|
|
|
8618
9370
|
}
|
|
8619
9371
|
|
|
8620
9372
|
// src/Cadenza.ts
|
|
9373
|
+
var POSTGRES_SETUP_DEBUG_ENABLED = process.env.CADENZA_POSTGRES_SETUP_DEBUG === "1" || process.env.CADENZA_POSTGRES_SETUP_DEBUG === "true";
|
|
9374
|
+
var DEFAULT_DEPUTY_TASK_CONCURRENCY = 50;
|
|
9375
|
+
var DEFAULT_DEPUTY_TASK_TIMEOUT_MS = 12e4;
|
|
9376
|
+
var DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY = 50;
|
|
9377
|
+
var DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS = 12e4;
|
|
8621
9378
|
var CadenzaService = class {
|
|
9379
|
+
static replayRegisteredTaskIntentAssociations() {
|
|
9380
|
+
for (const task of this.registry.tasks.values()) {
|
|
9381
|
+
if (!task.register || task.isHidden || task.handlesIntents.size === 0) {
|
|
9382
|
+
continue;
|
|
9383
|
+
}
|
|
9384
|
+
for (const intentName of task.handlesIntents) {
|
|
9385
|
+
task.emitWithMetadata("meta.task.intent_associated", {
|
|
9386
|
+
data: {
|
|
9387
|
+
intentName,
|
|
9388
|
+
taskName: task.name,
|
|
9389
|
+
taskVersion: task.version
|
|
9390
|
+
},
|
|
9391
|
+
taskInstance: task,
|
|
9392
|
+
__isSubMeta: task.isSubMeta
|
|
9393
|
+
});
|
|
9394
|
+
}
|
|
9395
|
+
}
|
|
9396
|
+
}
|
|
9397
|
+
static replayRegisteredTaskSignalObservations() {
|
|
9398
|
+
for (const task of this.registry.tasks.values()) {
|
|
9399
|
+
if (!task.register || task.isHidden || task.observedSignals.size === 0) {
|
|
9400
|
+
continue;
|
|
9401
|
+
}
|
|
9402
|
+
for (const signalName of task.observedSignals) {
|
|
9403
|
+
task.emitWithMetadata("meta.task.observed_signal", {
|
|
9404
|
+
data: {
|
|
9405
|
+
signalName,
|
|
9406
|
+
taskName: task.name,
|
|
9407
|
+
taskVersion: task.version
|
|
9408
|
+
},
|
|
9409
|
+
taskInstance: task,
|
|
9410
|
+
signalName,
|
|
9411
|
+
__isSubMeta: task.isSubMeta
|
|
9412
|
+
});
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
}
|
|
9416
|
+
static replayRegisteredTaskGraphMetadata() {
|
|
9417
|
+
this.replayRegisteredTaskSignalObservations();
|
|
9418
|
+
this.replayRegisteredTaskIntentAssociations();
|
|
9419
|
+
}
|
|
8622
9420
|
static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
|
|
8623
9421
|
const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
8624
9422
|
const helperSuffix = (0, import_lodash_es.camelCase)(String(tableName ?? "").trim());
|
|
@@ -8761,6 +9559,12 @@ var CadenzaService = class {
|
|
|
8761
9559
|
static setMode(mode) {
|
|
8762
9560
|
import_core5.default.setMode(mode);
|
|
8763
9561
|
}
|
|
9562
|
+
static hasCompletedBootstrapSync() {
|
|
9563
|
+
return !this.serviceCreated || this.bootstrapSyncCompleted;
|
|
9564
|
+
}
|
|
9565
|
+
static markBootstrapSyncCompleted() {
|
|
9566
|
+
this.bootstrapSyncCompleted = true;
|
|
9567
|
+
}
|
|
8764
9568
|
/**
|
|
8765
9569
|
* Emits a signal with the specified data using the associated broker.
|
|
8766
9570
|
*
|
|
@@ -8848,6 +9652,46 @@ var CadenzaService = class {
|
|
|
8848
9652
|
responders: statuses
|
|
8849
9653
|
};
|
|
8850
9654
|
}
|
|
9655
|
+
static shouldPersistInquiry(inquiry, _context) {
|
|
9656
|
+
return !isMetaIntentName(inquiry);
|
|
9657
|
+
}
|
|
9658
|
+
static splitInquiryPersistenceContext(context) {
|
|
9659
|
+
const businessContext = {};
|
|
9660
|
+
const metadata = context?.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
|
|
9661
|
+
for (const [key, value] of Object.entries(context ?? {})) {
|
|
9662
|
+
if (key === "__metadata") {
|
|
9663
|
+
continue;
|
|
9664
|
+
}
|
|
9665
|
+
if (key.startsWith("__")) {
|
|
9666
|
+
metadata[key] = value;
|
|
9667
|
+
continue;
|
|
9668
|
+
}
|
|
9669
|
+
businessContext[key] = value;
|
|
9670
|
+
}
|
|
9671
|
+
return {
|
|
9672
|
+
context: businessContext,
|
|
9673
|
+
metadata
|
|
9674
|
+
};
|
|
9675
|
+
}
|
|
9676
|
+
static buildInquiryPersistenceStartData(inquiryId, inquiry, context, startedAt) {
|
|
9677
|
+
const normalizedTaskVersion = Number(context?.__inquirySourceTaskVersion);
|
|
9678
|
+
const { context: inquiryContext, metadata } = this.splitInquiryPersistenceContext(context);
|
|
9679
|
+
return {
|
|
9680
|
+
uuid: inquiryId,
|
|
9681
|
+
name: inquiry,
|
|
9682
|
+
taskName: typeof context?.__inquirySourceTaskName === "string" ? context.__inquirySourceTaskName : null,
|
|
9683
|
+
taskVersion: Number.isFinite(normalizedTaskVersion) && normalizedTaskVersion > 0 ? normalizedTaskVersion : null,
|
|
9684
|
+
taskExecutionId: typeof context?.__inquirySourceTaskExecutionId === "string" ? context.__inquirySourceTaskExecutionId : null,
|
|
9685
|
+
serviceName: this.serviceRegistry.serviceName,
|
|
9686
|
+
serviceInstanceId: this.serviceRegistry.serviceInstanceId,
|
|
9687
|
+
executionTraceId: typeof (context?.__metadata?.__executionTraceId ?? context?.__executionTraceId) === "string" ? context.__metadata?.__executionTraceId ?? context.__executionTraceId : null,
|
|
9688
|
+
routineExecutionId: typeof context?.__inquirySourceRoutineExecutionId === "string" ? context.__inquirySourceRoutineExecutionId : null,
|
|
9689
|
+
context: inquiryContext,
|
|
9690
|
+
metadata,
|
|
9691
|
+
isMeta: false,
|
|
9692
|
+
sentAt: formatTimestamp(startedAt)
|
|
9693
|
+
};
|
|
9694
|
+
}
|
|
8851
9695
|
static async inquire(inquiry, context, options = {}) {
|
|
8852
9696
|
this.bootstrap();
|
|
8853
9697
|
const hydratedResult = this.consumeHydratedInquiryResult(
|
|
@@ -8862,6 +9706,20 @@ var CadenzaService = class {
|
|
|
8862
9706
|
descriptor: this.getInquiryResponderDescriptor(task)
|
|
8863
9707
|
})) : [];
|
|
8864
9708
|
const isMetaInquiry = isMetaIntentName(inquiry);
|
|
9709
|
+
const startedAt = Date.now();
|
|
9710
|
+
const persistInquiry = this.shouldPersistInquiry(inquiry, context);
|
|
9711
|
+
const logicalInquiryId = persistInquiry ? (0, import_uuid5.v4)() : null;
|
|
9712
|
+
const inquiryStartData = logicalInquiryId ? this.buildInquiryPersistenceStartData(
|
|
9713
|
+
logicalInquiryId,
|
|
9714
|
+
inquiry,
|
|
9715
|
+
context,
|
|
9716
|
+
startedAt
|
|
9717
|
+
) : null;
|
|
9718
|
+
if (inquiryStartData) {
|
|
9719
|
+
this.emit("meta.inquiry_broker.inquiry_started", {
|
|
9720
|
+
data: inquiryStartData
|
|
9721
|
+
});
|
|
9722
|
+
}
|
|
8865
9723
|
const responders = allResponders.filter(({ task, descriptor }) => {
|
|
8866
9724
|
const shouldExecute = shouldExecuteInquiryResponder(inquiry, task.isMeta);
|
|
8867
9725
|
if (shouldExecute) {
|
|
@@ -8896,6 +9754,21 @@ var CadenzaService = class {
|
|
|
8896
9754
|
durationMs: 0,
|
|
8897
9755
|
responders: []
|
|
8898
9756
|
};
|
|
9757
|
+
if (logicalInquiryId) {
|
|
9758
|
+
this.emit("meta.inquiry_broker.inquiry_completed", {
|
|
9759
|
+
data: {
|
|
9760
|
+
fulfilledAt: formatTimestamp(startedAt),
|
|
9761
|
+
duration: 0,
|
|
9762
|
+
metadata: {
|
|
9763
|
+
...inquiryStartData?.metadata ?? {},
|
|
9764
|
+
inquiryMeta
|
|
9765
|
+
}
|
|
9766
|
+
},
|
|
9767
|
+
filter: {
|
|
9768
|
+
uuid: logicalInquiryId
|
|
9769
|
+
}
|
|
9770
|
+
});
|
|
9771
|
+
}
|
|
8899
9772
|
if (options.requireComplete) {
|
|
8900
9773
|
throw {
|
|
8901
9774
|
__inquiryMeta: inquiryMeta,
|
|
@@ -8911,7 +9784,6 @@ var CadenzaService = class {
|
|
|
8911
9784
|
const overallTimeoutMs = options.overallTimeoutMs ?? options.timeout ?? 0;
|
|
8912
9785
|
const requireComplete = options.requireComplete ?? false;
|
|
8913
9786
|
const perResponderTimeoutMs = options.perResponderTimeoutMs;
|
|
8914
|
-
const startedAt = Date.now();
|
|
8915
9787
|
const statuses = [];
|
|
8916
9788
|
const statusByTask = /* @__PURE__ */ new Map();
|
|
8917
9789
|
for (const responder of responders) {
|
|
@@ -8957,10 +9829,26 @@ var CadenzaService = class {
|
|
|
8957
9829
|
statuses,
|
|
8958
9830
|
allResponders.length
|
|
8959
9831
|
);
|
|
9832
|
+
const finishedAt = Date.now();
|
|
8960
9833
|
const responseContext = {
|
|
8961
9834
|
...mergedContext,
|
|
8962
9835
|
__inquiryMeta: inquiryMeta
|
|
8963
9836
|
};
|
|
9837
|
+
if (logicalInquiryId) {
|
|
9838
|
+
this.emit("meta.inquiry_broker.inquiry_completed", {
|
|
9839
|
+
data: {
|
|
9840
|
+
fulfilledAt: formatTimestamp(finishedAt),
|
|
9841
|
+
duration: finishedAt - startedAt,
|
|
9842
|
+
metadata: {
|
|
9843
|
+
...inquiryStartData?.metadata ?? {},
|
|
9844
|
+
inquiryMeta
|
|
9845
|
+
}
|
|
9846
|
+
},
|
|
9847
|
+
filter: {
|
|
9848
|
+
uuid: logicalInquiryId
|
|
9849
|
+
}
|
|
9850
|
+
});
|
|
9851
|
+
}
|
|
8964
9852
|
if (requireComplete && (timedOut || inquiryMeta.failed > 0 || inquiryMeta.timedOut > 0 || inquiryMeta.pending > 0)) {
|
|
8965
9853
|
reject({
|
|
8966
9854
|
...responseContext,
|
|
@@ -8976,7 +9864,7 @@ var CadenzaService = class {
|
|
|
8976
9864
|
}
|
|
8977
9865
|
for (const responder of responders) {
|
|
8978
9866
|
const { task, descriptor } = responder;
|
|
8979
|
-
const
|
|
9867
|
+
const responderInquiryId = (0, import_uuid5.v4)();
|
|
8980
9868
|
startTimeByTask.set(task, Date.now());
|
|
8981
9869
|
const resolverTask = this.createEphemeralMetaTask(
|
|
8982
9870
|
`Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
|
|
@@ -9004,11 +9892,12 @@ var CadenzaService = class {
|
|
|
9004
9892
|
},
|
|
9005
9893
|
"Resolves distributed inquiry responder result",
|
|
9006
9894
|
{ register: false }
|
|
9007
|
-
).doOn(`meta.node.graph_completed:${
|
|
9895
|
+
).doOn(`meta.node.graph_completed:${responderInquiryId}`);
|
|
9008
9896
|
resolverTasks.push(resolverTask);
|
|
9009
9897
|
const executionContext = {
|
|
9010
9898
|
...context,
|
|
9011
|
-
|
|
9899
|
+
...logicalInquiryId ? { __inquiryId: logicalInquiryId } : {},
|
|
9900
|
+
__routineExecId: responderInquiryId,
|
|
9012
9901
|
__isInquiry: true
|
|
9013
9902
|
};
|
|
9014
9903
|
if (perResponderTimeoutMs !== void 0) {
|
|
@@ -9170,8 +10059,8 @@ var CadenzaService = class {
|
|
|
9170
10059
|
this.validateName(routineName);
|
|
9171
10060
|
const name = `${routineName} (Proxy)`;
|
|
9172
10061
|
options = {
|
|
9173
|
-
concurrency:
|
|
9174
|
-
timeout:
|
|
10062
|
+
concurrency: DEFAULT_DEPUTY_TASK_CONCURRENCY,
|
|
10063
|
+
timeout: DEFAULT_DEPUTY_TASK_TIMEOUT_MS,
|
|
9175
10064
|
register: true,
|
|
9176
10065
|
isUnique: false,
|
|
9177
10066
|
isMeta: false,
|
|
@@ -9278,8 +10167,8 @@ var CadenzaService = class {
|
|
|
9278
10167
|
return;
|
|
9279
10168
|
}
|
|
9280
10169
|
options = {
|
|
9281
|
-
concurrency:
|
|
9282
|
-
timeout:
|
|
10170
|
+
concurrency: DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY,
|
|
10171
|
+
timeout: DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS,
|
|
9283
10172
|
register: true,
|
|
9284
10173
|
isUnique: false,
|
|
9285
10174
|
isMeta: true,
|
|
@@ -9340,8 +10229,8 @@ var CadenzaService = class {
|
|
|
9340
10229
|
const description = `Executes a ${operation} on table ${tableName} in ${targetDatabaseServiceName}`;
|
|
9341
10230
|
const taskName = `${operation.charAt(0).toUpperCase() + operation.slice(1)} ${tableName}`;
|
|
9342
10231
|
options = {
|
|
9343
|
-
concurrency:
|
|
9344
|
-
timeout:
|
|
10232
|
+
concurrency: DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY,
|
|
10233
|
+
timeout: DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS,
|
|
9345
10234
|
register: true,
|
|
9346
10235
|
isUnique: false,
|
|
9347
10236
|
isMeta: false,
|
|
@@ -9485,8 +10374,10 @@ var CadenzaService = class {
|
|
|
9485
10374
|
this.validateName(serviceName);
|
|
9486
10375
|
this.validateServiceName(serviceName);
|
|
9487
10376
|
const serviceId = options.customServiceId ?? (0, import_uuid5.v4)();
|
|
10377
|
+
this.bootstrapSyncCompleted = false;
|
|
9488
10378
|
this.serviceRegistry.serviceName = serviceName;
|
|
9489
10379
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
10380
|
+
this.serviceRegistry.connectsToCadenzaDB = !!options.cadenzaDB?.connect;
|
|
9490
10381
|
this.setHydrationResults(options.hydration);
|
|
9491
10382
|
const explicitFrontendMode = options.isFrontend;
|
|
9492
10383
|
options = {
|
|
@@ -9515,6 +10406,23 @@ var CadenzaService = class {
|
|
|
9515
10406
|
this.serviceRegistry.useSocket = !!options.useSocket;
|
|
9516
10407
|
this.serviceRegistry.retryCount = options.retryCount ?? 3;
|
|
9517
10408
|
this.ensureTransportControllers(isFrontend);
|
|
10409
|
+
if (!isFrontend) {
|
|
10410
|
+
this.createMetaTask(
|
|
10411
|
+
"Initialize graph metadata controller after initial sync",
|
|
10412
|
+
() => {
|
|
10413
|
+
this.markBootstrapSyncCompleted();
|
|
10414
|
+
GraphMetadataController.instance;
|
|
10415
|
+
return true;
|
|
10416
|
+
},
|
|
10417
|
+
"Delays direct graph-metadata registration until the bootstrap sync has completed.",
|
|
10418
|
+
{
|
|
10419
|
+
register: false,
|
|
10420
|
+
isHidden: true
|
|
10421
|
+
}
|
|
10422
|
+
).doOn("meta.service_registry.initial_sync_complete");
|
|
10423
|
+
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB";
|
|
10424
|
+
GraphSyncController.instance.init();
|
|
10425
|
+
}
|
|
9518
10426
|
const resolvedBootstrapEndpoint = options.cadenzaDB?.connect ? resolveBootstrapEndpoint({
|
|
9519
10427
|
runtime: isFrontend ? "browser" : "server",
|
|
9520
10428
|
bootstrap: options.bootstrap,
|
|
@@ -9588,14 +10496,14 @@ var CadenzaService = class {
|
|
|
9588
10496
|
data: {
|
|
9589
10497
|
name: serviceName,
|
|
9590
10498
|
description,
|
|
9591
|
-
|
|
9592
|
-
|
|
10499
|
+
display_name: options.displayName ?? "",
|
|
10500
|
+
is_meta: options.isMeta
|
|
9593
10501
|
},
|
|
9594
10502
|
__registrationData: {
|
|
9595
10503
|
name: serviceName,
|
|
9596
10504
|
description,
|
|
9597
|
-
|
|
9598
|
-
|
|
10505
|
+
display_name: options.displayName ?? "",
|
|
10506
|
+
is_meta: options.isMeta
|
|
9599
10507
|
},
|
|
9600
10508
|
__serviceName: serviceName,
|
|
9601
10509
|
__serviceInstanceId: serviceId,
|
|
@@ -9626,14 +10534,13 @@ var CadenzaService = class {
|
|
|
9626
10534
|
);
|
|
9627
10535
|
}).doOn("meta.rest.handshake", "meta.socket.handshake");
|
|
9628
10536
|
}
|
|
9629
|
-
this.createMetaTask("Handle service setup completion", () => {
|
|
10537
|
+
this.createMetaTask("Handle service setup completion", (ctx, emit) => {
|
|
10538
|
+
if (options.cadenzaDB?.connect) {
|
|
10539
|
+
this.serviceRegistry.bootstrapFullSync(emit, ctx, "service_setup_completed");
|
|
10540
|
+
}
|
|
9630
10541
|
if (isFrontend) {
|
|
9631
10542
|
registerActorSessionPersistenceTasks();
|
|
9632
10543
|
this.ensureFrontendSyncLoop();
|
|
9633
|
-
} else {
|
|
9634
|
-
GraphMetadataController.instance;
|
|
9635
|
-
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB" || !!options.cadenzaDB?.connect;
|
|
9636
|
-
GraphSyncController.instance.init();
|
|
9637
10544
|
}
|
|
9638
10545
|
this.log("Service created.");
|
|
9639
10546
|
return true;
|
|
@@ -9662,7 +10569,15 @@ var CadenzaService = class {
|
|
|
9662
10569
|
is_blocked: false,
|
|
9663
10570
|
health: {}
|
|
9664
10571
|
},
|
|
9665
|
-
__transportData:
|
|
10572
|
+
__transportData: declaredTransports.map((transport) => ({
|
|
10573
|
+
uuid: transport.uuid,
|
|
10574
|
+
service_instance_id: serviceId,
|
|
10575
|
+
role: transport.role,
|
|
10576
|
+
origin: transport.origin,
|
|
10577
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
10578
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
10579
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
10580
|
+
})),
|
|
9666
10581
|
__serviceName: serviceName,
|
|
9667
10582
|
__serviceInstanceId: serviceId,
|
|
9668
10583
|
__useSocket: options.useSocket,
|
|
@@ -9779,10 +10694,35 @@ var CadenzaService = class {
|
|
|
9779
10694
|
registration.actorName
|
|
9780
10695
|
);
|
|
9781
10696
|
const createServiceTaskName = `Create database service ${name} after ${registration.actorName} setup`;
|
|
10697
|
+
const traceSetupDoneTaskName = `Trace database service ${name} setup done`;
|
|
10698
|
+
if (POSTGRES_SETUP_DEBUG_ENABLED && !this.get(traceSetupDoneTaskName)) {
|
|
10699
|
+
this.createMetaTask(
|
|
10700
|
+
traceSetupDoneTaskName,
|
|
10701
|
+
(ctx) => {
|
|
10702
|
+
console.log("[CADENZA_POSTGRES_SETUP_DEBUG] setup_done_signal_observed", {
|
|
10703
|
+
serviceName: name,
|
|
10704
|
+
actorName: registration.actorName,
|
|
10705
|
+
payloadKeys: Object.keys(ctx ?? {})
|
|
10706
|
+
});
|
|
10707
|
+
return true;
|
|
10708
|
+
},
|
|
10709
|
+
"Debug trace for PostgresActor setup-done signal delivery.",
|
|
10710
|
+
{ isHidden: true, register: false }
|
|
10711
|
+
).doOn(registration.setupDoneSignal);
|
|
10712
|
+
}
|
|
9782
10713
|
if (!this.get(createServiceTaskName)) {
|
|
9783
10714
|
this.createMetaTask(
|
|
9784
10715
|
createServiceTaskName,
|
|
9785
10716
|
() => {
|
|
10717
|
+
if (POSTGRES_SETUP_DEBUG_ENABLED) {
|
|
10718
|
+
console.log(
|
|
10719
|
+
"[CADENZA_POSTGRES_SETUP_DEBUG] create_database_service_task_fired",
|
|
10720
|
+
{
|
|
10721
|
+
serviceName: name,
|
|
10722
|
+
actorName: registration.actorName
|
|
10723
|
+
}
|
|
10724
|
+
);
|
|
10725
|
+
}
|
|
9786
10726
|
this.createCadenzaService(name, description, serviceOptions);
|
|
9787
10727
|
return true;
|
|
9788
10728
|
},
|
|
@@ -10314,6 +11254,7 @@ var CadenzaService = class {
|
|
|
10314
11254
|
this.serviceRegistry?.reset();
|
|
10315
11255
|
this.isBootstrapped = false;
|
|
10316
11256
|
this.serviceCreated = false;
|
|
11257
|
+
this.bootstrapSyncCompleted = false;
|
|
10317
11258
|
this.defaultDatabaseServiceName = null;
|
|
10318
11259
|
this.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
|
|
10319
11260
|
this.hydratedInquiryResults = /* @__PURE__ */ new Map();
|
|
@@ -10322,6 +11263,7 @@ var CadenzaService = class {
|
|
|
10322
11263
|
};
|
|
10323
11264
|
CadenzaService.isBootstrapped = false;
|
|
10324
11265
|
CadenzaService.serviceCreated = false;
|
|
11266
|
+
CadenzaService.bootstrapSyncCompleted = false;
|
|
10325
11267
|
CadenzaService.defaultDatabaseServiceName = null;
|
|
10326
11268
|
CadenzaService.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
|
|
10327
11269
|
CadenzaService.hydratedInquiryResults = /* @__PURE__ */ new Map();
|