@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.mjs
CHANGED
|
@@ -2,8 +2,46 @@
|
|
|
2
2
|
import Cadenza from "@cadenza.io/core";
|
|
3
3
|
|
|
4
4
|
// src/graph/definition/DeputyTask.ts
|
|
5
|
-
import { v4 as
|
|
5
|
+
import { v4 as uuid2 } from "uuid";
|
|
6
6
|
import { Task } from "@cadenza.io/core";
|
|
7
|
+
|
|
8
|
+
// src/utils/delegation.ts
|
|
9
|
+
import { v4 as uuid } from "uuid";
|
|
10
|
+
var ROOT_METADATA_PASSTHROUGH_KEYS = [
|
|
11
|
+
"__executionTraceId",
|
|
12
|
+
"__inquiryId",
|
|
13
|
+
"__inquirySourceTaskName",
|
|
14
|
+
"__inquirySourceTaskVersion",
|
|
15
|
+
"__inquirySourceTaskExecutionId",
|
|
16
|
+
"__inquirySourceRoutineExecutionId"
|
|
17
|
+
];
|
|
18
|
+
function hoistDelegationMetadataFields(input, metadataInput) {
|
|
19
|
+
const context = input && typeof input === "object" ? { ...input } : {};
|
|
20
|
+
const mutableContext = context;
|
|
21
|
+
const metadata = metadataInput && typeof metadataInput === "object" ? metadataInput : context.__metadata && typeof context.__metadata === "object" ? context.__metadata : {};
|
|
22
|
+
for (const key of ROOT_METADATA_PASSTHROUGH_KEYS) {
|
|
23
|
+
if ((mutableContext[key] === void 0 || mutableContext[key] === null) && metadata[key] !== void 0 && metadata[key] !== null) {
|
|
24
|
+
mutableContext[key] = metadata[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
29
|
+
function ensureDelegationContextMetadata(input) {
|
|
30
|
+
const rawContext = input && typeof input === "object" ? { ...input } : {};
|
|
31
|
+
const metadata = rawContext.__metadata && typeof rawContext.__metadata === "object" ? { ...rawContext.__metadata } : {};
|
|
32
|
+
const context = hoistDelegationMetadataFields(rawContext, metadata);
|
|
33
|
+
const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof rawContext.__deputyExecId === "string" && rawContext.__deputyExecId.length > 0 ? context.__deputyExecId : uuid();
|
|
34
|
+
return {
|
|
35
|
+
...context,
|
|
36
|
+
__deputyExecId: deputyExecId,
|
|
37
|
+
__metadata: {
|
|
38
|
+
...metadata,
|
|
39
|
+
__deputyExecId: deputyExecId
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/graph/definition/DeputyTask.ts
|
|
7
45
|
var DeputyTask = class extends Task {
|
|
8
46
|
/**
|
|
9
47
|
* Constructs a new instance of the class with the specified parameters.
|
|
@@ -41,7 +79,7 @@ var DeputyTask = class extends Task {
|
|
|
41
79
|
resolve(context);
|
|
42
80
|
return;
|
|
43
81
|
}
|
|
44
|
-
const processId =
|
|
82
|
+
const processId = uuid2();
|
|
45
83
|
context.__metadata.__deputyExecId = processId;
|
|
46
84
|
emit("meta.deputy.delegation_requested", {
|
|
47
85
|
...context
|
|
@@ -129,7 +167,7 @@ var DeputyTask = class extends Task {
|
|
|
129
167
|
execute(context, emit, inquire, progressCallback, nodeData) {
|
|
130
168
|
const ctx = context.getContext();
|
|
131
169
|
const metadata = context.getMetadata();
|
|
132
|
-
const deputyContext = {
|
|
170
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
133
171
|
__timeout: this.timeout,
|
|
134
172
|
__localTaskName: this.name,
|
|
135
173
|
__localTaskVersion: this.version,
|
|
@@ -146,7 +184,7 @@ var DeputyTask = class extends Task {
|
|
|
146
184
|
__deputyTaskName: this.name
|
|
147
185
|
},
|
|
148
186
|
...ctx
|
|
149
|
-
};
|
|
187
|
+
});
|
|
150
188
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
151
189
|
}
|
|
152
190
|
};
|
|
@@ -227,7 +265,7 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
227
265
|
},
|
|
228
266
|
...dynamicQueryData
|
|
229
267
|
};
|
|
230
|
-
const deputyContext = {
|
|
268
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
231
269
|
...ctx,
|
|
232
270
|
__localTaskName: this.name,
|
|
233
271
|
__localTaskVersion: this.version,
|
|
@@ -250,7 +288,7 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
250
288
|
filter: nextQueryData.filter ?? ctx.filter,
|
|
251
289
|
fields: nextQueryData.fields ?? ctx.fields,
|
|
252
290
|
queryData: nextQueryData
|
|
253
|
-
};
|
|
291
|
+
});
|
|
254
292
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
255
293
|
}
|
|
256
294
|
};
|
|
@@ -501,22 +539,6 @@ function getRouteableTransport(instance, role, protocol) {
|
|
|
501
539
|
return selectTransportForRole(instance.transports ?? [], role, protocol);
|
|
502
540
|
}
|
|
503
541
|
|
|
504
|
-
// src/utils/delegation.ts
|
|
505
|
-
import { v4 as uuid2 } from "uuid";
|
|
506
|
-
function ensureDelegationContextMetadata(input) {
|
|
507
|
-
const context = input && typeof input === "object" ? { ...input } : {};
|
|
508
|
-
const metadata = context.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
|
|
509
|
-
const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof context.__deputyExecId === "string" && context.__deputyExecId.length > 0 ? context.__deputyExecId : uuid2();
|
|
510
|
-
return {
|
|
511
|
-
...context,
|
|
512
|
-
__deputyExecId: deputyExecId,
|
|
513
|
-
__metadata: {
|
|
514
|
-
...metadata,
|
|
515
|
-
__deputyExecId: deputyExecId
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
542
|
// src/utils/readiness.ts
|
|
521
543
|
function evaluateDependencyReadiness(input) {
|
|
522
544
|
const missedHeartbeats = Math.max(
|
|
@@ -686,6 +708,21 @@ var CADENZA_DB_GATHERED_SYNC_SIGNAL = "global.meta.cadenza_db.gathered_sync_data
|
|
|
686
708
|
var META_GATHERED_SYNC_TRANSMISSION_RECONCILE_SIGNAL = "meta.service_registry.gathered_sync_transmission_reconcile_requested";
|
|
687
709
|
var META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL = "meta.service_registry.runtime_status.heartbeat_tick";
|
|
688
710
|
var META_RUNTIME_STATUS_MONITOR_TICK_SIGNAL = "meta.service_registry.runtime_status.monitor_tick";
|
|
711
|
+
var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
712
|
+
100,
|
|
713
|
+
1500,
|
|
714
|
+
5e3,
|
|
715
|
+
12e3,
|
|
716
|
+
25e3,
|
|
717
|
+
45e3,
|
|
718
|
+
7e4
|
|
719
|
+
];
|
|
720
|
+
var BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS = [
|
|
721
|
+
"Query service_instance",
|
|
722
|
+
"Query service_instance_transport",
|
|
723
|
+
"Query signal_to_task_map",
|
|
724
|
+
"Query intent_to_task_map"
|
|
725
|
+
];
|
|
689
726
|
var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
690
727
|
"Track local routine start",
|
|
691
728
|
"Track local routine end",
|
|
@@ -698,6 +735,10 @@ var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
|
698
735
|
"Collect distributed readiness",
|
|
699
736
|
"Get status"
|
|
700
737
|
]);
|
|
738
|
+
var SERVICE_REGISTRY_TRACE_SERVICE = (process.env.CADENZA_SERVICE_REGISTRY_TRACE_SERVICE ?? "").trim();
|
|
739
|
+
function shouldTraceServiceRegistry(serviceName) {
|
|
740
|
+
return SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && serviceName === SERVICE_REGISTRY_TRACE_SERVICE;
|
|
741
|
+
}
|
|
701
742
|
function buildServiceRegistryInsertQueryData(ctx, queryData) {
|
|
702
743
|
const joinedContexts = Array.isArray(ctx.joinedContexts) ? ctx.joinedContexts : [];
|
|
703
744
|
const getJoinedValue = (key) => {
|
|
@@ -771,6 +812,45 @@ function normalizeServiceRegistryInsertResult(tableName, ctx, queryData, rawResu
|
|
|
771
812
|
}
|
|
772
813
|
return result;
|
|
773
814
|
}
|
|
815
|
+
function resolveServiceInstanceRegistrationPayload(ctx, fallbackServiceName, fallbackServiceInstanceId) {
|
|
816
|
+
const candidateSources = [
|
|
817
|
+
ctx.__registrationData,
|
|
818
|
+
ctx.queryData?.data,
|
|
819
|
+
ctx.__resolverQueryData?.data,
|
|
820
|
+
ctx.__resolverOriginalContext?.__registrationData,
|
|
821
|
+
ctx.__resolverOriginalContext?.queryData?.data,
|
|
822
|
+
ctx.data,
|
|
823
|
+
ctx.__resolverOriginalContext?.data
|
|
824
|
+
];
|
|
825
|
+
let resolvedData = null;
|
|
826
|
+
for (const candidate of candidateSources) {
|
|
827
|
+
if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) {
|
|
828
|
+
resolvedData = {
|
|
829
|
+
...candidate
|
|
830
|
+
};
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (!resolvedData) {
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
const resolvedUuid = String(
|
|
838
|
+
resolvedData.uuid ?? ctx.__serviceInstanceId ?? ctx.__resolverOriginalContext?.__serviceInstanceId ?? fallbackServiceInstanceId ?? ""
|
|
839
|
+
).trim();
|
|
840
|
+
const resolvedServiceName = String(
|
|
841
|
+
resolvedData.service_name ?? ctx.__serviceName ?? ctx.__resolverOriginalContext?.__serviceName ?? fallbackServiceName ?? ""
|
|
842
|
+
).trim();
|
|
843
|
+
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;
|
|
844
|
+
if (!resolvedUuid || !resolvedServiceName || resolvedProcessPid === null) {
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
...resolvedData,
|
|
849
|
+
uuid: resolvedUuid,
|
|
850
|
+
service_name: resolvedServiceName,
|
|
851
|
+
process_pid: resolvedProcessPid
|
|
852
|
+
};
|
|
853
|
+
}
|
|
774
854
|
function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {}) {
|
|
775
855
|
const remoteInsertTask = CadenzaService.createCadenzaDBInsertTask(
|
|
776
856
|
tableName,
|
|
@@ -795,13 +875,24 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
795
875
|
});
|
|
796
876
|
delegationContext.__metadata.__skipRemoteExecution = delegationContext.__metadata.__skipRemoteExecution ?? delegationContext.__skipRemoteExecution ?? false;
|
|
797
877
|
delegationContext.__metadata.__blockRemoteExecution = delegationContext.__metadata.__blockRemoteExecution ?? delegationContext.__blockRemoteExecution ?? false;
|
|
798
|
-
|
|
878
|
+
const nextContext = {
|
|
799
879
|
...delegationContext,
|
|
800
880
|
__resolverOriginalContext: {
|
|
801
881
|
...ctx
|
|
802
882
|
},
|
|
803
883
|
__resolverQueryData: nextQueryData
|
|
804
884
|
};
|
|
885
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
886
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_registry_insert_execution", {
|
|
887
|
+
tableName,
|
|
888
|
+
signalName,
|
|
889
|
+
resolverRequestId: ctx.__resolverRequestId ?? null,
|
|
890
|
+
hasData: nextQueryData.data !== void 0,
|
|
891
|
+
queryDataKeys: Object.keys(nextQueryData),
|
|
892
|
+
dataKeys: nextQueryData.data && typeof nextQueryData.data === "object" ? Object.keys(nextQueryData.data) : []
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
return nextContext;
|
|
805
896
|
},
|
|
806
897
|
`Prepares ${tableName} service-registry insert payloads for runner execution.`,
|
|
807
898
|
{
|
|
@@ -827,6 +918,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
827
918
|
ctx.__resolverQueryData ?? ctx.queryData ?? {},
|
|
828
919
|
ctx
|
|
829
920
|
);
|
|
921
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
922
|
+
console.log("[CADENZA_INSTANCE_DEBUG] finalize_service_registry_insert", {
|
|
923
|
+
tableName,
|
|
924
|
+
hasNormalized: !!normalized,
|
|
925
|
+
normalizedKeys: normalized && typeof normalized === "object" ? Object.keys(normalized) : [],
|
|
926
|
+
uuid: normalized && typeof normalized === "object" ? normalized.uuid ?? normalized.data?.uuid ?? normalized.queryData?.data?.uuid ?? null : null,
|
|
927
|
+
serviceName: normalized && typeof normalized === "object" ? normalized.__serviceName ?? normalized.data?.service_name ?? normalized.queryData?.data?.service_name ?? null : null,
|
|
928
|
+
errored: normalized && typeof normalized === "object" ? normalized.errored === true : false,
|
|
929
|
+
error: normalized && typeof normalized === "object" ? normalized.__error ?? null : null,
|
|
930
|
+
inquiryMeta: normalized && typeof normalized === "object" ? normalized.__inquiryMeta ?? null : null
|
|
931
|
+
});
|
|
932
|
+
}
|
|
830
933
|
if (!normalized || typeof normalized !== "object") {
|
|
831
934
|
return normalized;
|
|
832
935
|
}
|
|
@@ -852,6 +955,16 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
852
955
|
CadenzaService.createEphemeralMetaTask(
|
|
853
956
|
`Resolve service registry insert execution for ${tableName} (${resolverRequestId})`,
|
|
854
957
|
(resultCtx) => {
|
|
958
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
959
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert_signal", {
|
|
960
|
+
tableName,
|
|
961
|
+
resolverRequestId,
|
|
962
|
+
incomingResolverRequestId: resultCtx.__resolverRequestId ?? null,
|
|
963
|
+
errored: resultCtx.errored === true,
|
|
964
|
+
error: resultCtx.__error ?? null,
|
|
965
|
+
keys: resultCtx && typeof resultCtx === "object" ? Object.keys(resultCtx) : []
|
|
966
|
+
});
|
|
967
|
+
}
|
|
855
968
|
if (resultCtx.__resolverRequestId !== resolverRequestId) {
|
|
856
969
|
return false;
|
|
857
970
|
}
|
|
@@ -871,6 +984,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
871
984
|
).doOn(executionResolvedSignal, executionFailedSignal);
|
|
872
985
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
873
986
|
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
987
|
+
if ((tableName === "service_instance" || tableName === "service") && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
988
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
989
|
+
tableName,
|
|
990
|
+
executionSignal,
|
|
991
|
+
hasLocalInsertTask: !!localInsertTask,
|
|
992
|
+
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
993
|
+
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
994
|
+
hasData: !!ctx.data,
|
|
995
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
996
|
+
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
997
|
+
});
|
|
998
|
+
}
|
|
874
999
|
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
875
1000
|
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
876
1001
|
wiredLocalTaskNames.add(localInsertTask.name);
|
|
@@ -953,6 +1078,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
953
1078
|
this.useSocket = false;
|
|
954
1079
|
this.retryCount = 3;
|
|
955
1080
|
this.isFrontend = false;
|
|
1081
|
+
this.connectsToCadenzaDB = false;
|
|
956
1082
|
CadenzaService.defineIntent({
|
|
957
1083
|
name: META_RUNTIME_TRANSPORT_DIAGNOSTICS_INTENT,
|
|
958
1084
|
description: "Gather transport diagnostics across all services and communication clients.",
|
|
@@ -1311,6 +1437,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1311
1437
|
)?.destroy();
|
|
1312
1438
|
continue;
|
|
1313
1439
|
}
|
|
1440
|
+
if (map.serviceName === this.serviceName) {
|
|
1441
|
+
continue;
|
|
1442
|
+
}
|
|
1314
1443
|
if (locallyEmittedSignals.includes(map.signalName)) {
|
|
1315
1444
|
if (!this.remoteSignals.get(map.serviceName)) {
|
|
1316
1445
|
this.remoteSignals.set(map.serviceName, /* @__PURE__ */ new Set());
|
|
@@ -1327,7 +1456,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1327
1456
|
return true;
|
|
1328
1457
|
},
|
|
1329
1458
|
"Handles registration of remote signals"
|
|
1330
|
-
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1459
|
+
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1460
|
+
"global.meta.cadenza_db.gathered_sync_data",
|
|
1461
|
+
"global.meta.graph_metadata.task_signal_observed"
|
|
1462
|
+
);
|
|
1331
1463
|
this.reconcileGatheredSyncTransmissionsTask = CadenzaService.createMetaTask(
|
|
1332
1464
|
"Reconcile gathered sync signal transmissions",
|
|
1333
1465
|
(ctx, emit) => this.reconcileGatheredSyncTransmissions(ctx, emit),
|
|
@@ -1341,6 +1473,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1341
1473
|
"Handle global intent registration",
|
|
1342
1474
|
(ctx, emit) => {
|
|
1343
1475
|
const intentToTaskMaps = this.normalizeIntentMaps(ctx);
|
|
1476
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1477
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] handle_global_intents", {
|
|
1478
|
+
localServiceName: this.serviceName,
|
|
1479
|
+
intentCount: intentToTaskMaps.length,
|
|
1480
|
+
sample: intentToTaskMaps.slice(0, 5)
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1344
1483
|
const sorted = intentToTaskMaps.sort((a, b) => {
|
|
1345
1484
|
if (a.deleted && !b.deleted) return -1;
|
|
1346
1485
|
if (!a.deleted && b.deleted) return 1;
|
|
@@ -1352,6 +1491,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1352
1491
|
this.unregisterRemoteIntentDeputy(map);
|
|
1353
1492
|
continue;
|
|
1354
1493
|
}
|
|
1494
|
+
if (map.serviceName === this.serviceName) {
|
|
1495
|
+
continue;
|
|
1496
|
+
}
|
|
1355
1497
|
CadenzaService.inquiryBroker.addIntent({
|
|
1356
1498
|
name: map.intentName
|
|
1357
1499
|
});
|
|
@@ -1481,7 +1623,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1481
1623
|
);
|
|
1482
1624
|
this.handleSocketStatusUpdateTask = CadenzaService.createMetaTask(
|
|
1483
1625
|
"Handle Socket Status Update",
|
|
1484
|
-
(ctx) => {
|
|
1626
|
+
(ctx, emit) => {
|
|
1485
1627
|
const report = this.normalizeRuntimeStatusReport(ctx);
|
|
1486
1628
|
if (!report) {
|
|
1487
1629
|
return false;
|
|
@@ -1524,6 +1666,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1524
1666
|
if (!applied) {
|
|
1525
1667
|
return false;
|
|
1526
1668
|
}
|
|
1669
|
+
const updatedInstance = this.getInstance(
|
|
1670
|
+
report.serviceName,
|
|
1671
|
+
report.serviceInstanceId
|
|
1672
|
+
);
|
|
1673
|
+
if (updatedInstance && !updatedInstance.isFrontend && (this.deputies.has(report.serviceName) || this.remoteIntents.has(report.serviceName) || this.remoteSignals.has(report.serviceName))) {
|
|
1674
|
+
this.ensureDependeeClientForInstance(updatedInstance, emit, ctx);
|
|
1675
|
+
}
|
|
1527
1676
|
this.registerDependee(report.serviceName, report.serviceInstanceId);
|
|
1528
1677
|
this.lastHeartbeatAtByInstance.set(report.serviceInstanceId, Date.now());
|
|
1529
1678
|
this.missedHeartbeatsByInstance.set(report.serviceInstanceId, 0);
|
|
@@ -1534,9 +1683,28 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1534
1683
|
},
|
|
1535
1684
|
"Handles status update from socket broadcast"
|
|
1536
1685
|
).doOn("meta.socket_client.status_received");
|
|
1686
|
+
CadenzaService.createMetaTask(
|
|
1687
|
+
"Request full sync after CadenzaDB fetch handshake",
|
|
1688
|
+
(ctx) => {
|
|
1689
|
+
const serviceName = typeof ctx.serviceName === "string" ? ctx.serviceName.trim() : typeof ctx.__serviceName === "string" ? ctx.__serviceName.trim() : "";
|
|
1690
|
+
if (serviceName !== "CadenzaDB") {
|
|
1691
|
+
return false;
|
|
1692
|
+
}
|
|
1693
|
+
return this.scheduleEarlyFullSyncRequests("cadenza_db_fetch_handshake");
|
|
1694
|
+
},
|
|
1695
|
+
"Schedules a few early service-registry full-sync retries after the authority fetch transport comes up."
|
|
1696
|
+
).doOn("meta.fetch.handshake_complete");
|
|
1537
1697
|
this.fullSyncTask = CadenzaService.createMetaTask(
|
|
1538
1698
|
"Full sync",
|
|
1539
1699
|
async (ctx) => {
|
|
1700
|
+
if (this.connectsToCadenzaDB && this.serviceName !== "CadenzaDB" && !this.hasBootstrapFullSyncDeputies()) {
|
|
1701
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1702
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] full_sync_skipped_missing_bootstrap_deputies", {
|
|
1703
|
+
localServiceName: this.serviceName
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
return false;
|
|
1707
|
+
}
|
|
1540
1708
|
const inquiryResult = await CadenzaService.inquire(
|
|
1541
1709
|
META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
1542
1710
|
{
|
|
@@ -1553,6 +1721,15 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1553
1721
|
const serviceInstances = this.normalizeServiceInstancesFromSync(
|
|
1554
1722
|
inquiryResult
|
|
1555
1723
|
);
|
|
1724
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
1725
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] full_sync_result", {
|
|
1726
|
+
localServiceName: this.serviceName,
|
|
1727
|
+
inquiryMeta: inquiryResult.__inquiryMeta,
|
|
1728
|
+
signalToTaskMaps: signalToTaskMaps.length,
|
|
1729
|
+
intentToTaskMaps: intentToTaskMaps.length,
|
|
1730
|
+
serviceInstances: serviceInstances.length
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1556
1733
|
return {
|
|
1557
1734
|
...ctx,
|
|
1558
1735
|
signalToTaskMaps,
|
|
@@ -1593,8 +1770,11 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1593
1770
|
);
|
|
1594
1771
|
this.handleDeputyRegistrationTask = CadenzaService.createMetaTask(
|
|
1595
1772
|
"Handle Deputy Registration",
|
|
1596
|
-
(ctx) => {
|
|
1773
|
+
(ctx, emit) => {
|
|
1597
1774
|
const { serviceName } = ctx;
|
|
1775
|
+
if (!serviceName || serviceName === this.serviceName) {
|
|
1776
|
+
return false;
|
|
1777
|
+
}
|
|
1598
1778
|
if (!this.deputies.has(serviceName)) this.deputies.set(serviceName, []);
|
|
1599
1779
|
this.deputies.get(serviceName).push({
|
|
1600
1780
|
serviceName,
|
|
@@ -1603,6 +1783,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1603
1783
|
localTaskName: ctx.localTaskName,
|
|
1604
1784
|
communicationType: ctx.communicationType
|
|
1605
1785
|
});
|
|
1786
|
+
this.ensureDependeeClientsForService(serviceName, emit, ctx);
|
|
1606
1787
|
}
|
|
1607
1788
|
).doOn("meta.deputy.created");
|
|
1608
1789
|
this.getAllInstances = CadenzaService.createMetaTask(
|
|
@@ -2155,9 +2336,29 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2155
2336
|
retryDelayFactor: 1.3
|
|
2156
2337
|
}
|
|
2157
2338
|
).emits("meta.service_registry.service_inserted").emitsOnFail("meta.service_registry.service_insertion_failed");
|
|
2158
|
-
|
|
2339
|
+
const insertServiceInstanceResolverTask = resolveServiceRegistryInsertTask(
|
|
2159
2340
|
"service_instance",
|
|
2160
|
-
{
|
|
2341
|
+
{
|
|
2342
|
+
onConflict: {
|
|
2343
|
+
target: ["uuid"],
|
|
2344
|
+
action: {
|
|
2345
|
+
do: "update",
|
|
2346
|
+
set: {
|
|
2347
|
+
process_pid: "excluded",
|
|
2348
|
+
is_primary: "excluded",
|
|
2349
|
+
service_name: "excluded",
|
|
2350
|
+
is_database: "excluded",
|
|
2351
|
+
is_frontend: "excluded",
|
|
2352
|
+
is_blocked: "excluded",
|
|
2353
|
+
is_non_responsive: "excluded",
|
|
2354
|
+
is_active: "excluded",
|
|
2355
|
+
last_active: "excluded",
|
|
2356
|
+
health: "excluded",
|
|
2357
|
+
deleted: "false"
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
},
|
|
2161
2362
|
{
|
|
2162
2363
|
inputSchema: {
|
|
2163
2364
|
type: "object",
|
|
@@ -2213,7 +2414,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2213
2414
|
retryCount: 5,
|
|
2214
2415
|
retryDelay: 1e3
|
|
2215
2416
|
}
|
|
2216
|
-
).
|
|
2417
|
+
).emitsOnFail("meta.service_registry.instance_insertion_failed");
|
|
2418
|
+
this.insertServiceInstanceTask = insertServiceInstanceResolverTask.then(
|
|
2217
2419
|
CadenzaService.createMetaTask(
|
|
2218
2420
|
"Setup service",
|
|
2219
2421
|
(ctx) => {
|
|
@@ -2230,6 +2432,21 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2230
2432
|
transports: ctx.__transportData ?? ctx.transportData ?? []
|
|
2231
2433
|
});
|
|
2232
2434
|
if (!normalizedLocalInstance?.uuid || !normalizedLocalInstance.serviceName) {
|
|
2435
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2436
|
+
console.log("[CADENZA_INSTANCE_DEBUG] setup_service_rejected_instance", {
|
|
2437
|
+
hasServiceInstance: !!serviceInstance,
|
|
2438
|
+
hasData: !!data,
|
|
2439
|
+
hasQueryDataData: !!queryData?.data,
|
|
2440
|
+
serviceInstanceKeys: serviceInstance && typeof serviceInstance === "object" ? Object.keys(serviceInstance) : [],
|
|
2441
|
+
dataKeys: data && typeof data === "object" ? Object.keys(data) : [],
|
|
2442
|
+
queryDataDataKeys: queryData?.data && typeof queryData.data === "object" ? Object.keys(queryData.data) : [],
|
|
2443
|
+
normalizedLocalInstance,
|
|
2444
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2445
|
+
errored: ctx.errored === true,
|
|
2446
|
+
error: ctx.__error ?? null,
|
|
2447
|
+
inquiryMeta: ctx.__inquiryMeta ?? null
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2233
2450
|
return false;
|
|
2234
2451
|
}
|
|
2235
2452
|
this.serviceInstanceId = normalizedLocalInstance.uuid;
|
|
@@ -2281,11 +2498,65 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2281
2498
|
).attachSignal("meta.service_registry.transport_registration_requested")
|
|
2282
2499
|
)
|
|
2283
2500
|
);
|
|
2501
|
+
CadenzaService.createMetaTask(
|
|
2502
|
+
"Retry local service instance registration after failed insert",
|
|
2503
|
+
(ctx) => {
|
|
2504
|
+
const registrationPayload = resolveServiceInstanceRegistrationPayload(
|
|
2505
|
+
ctx,
|
|
2506
|
+
this.serviceName,
|
|
2507
|
+
this.serviceInstanceId
|
|
2508
|
+
);
|
|
2509
|
+
if (!registrationPayload) {
|
|
2510
|
+
return false;
|
|
2511
|
+
}
|
|
2512
|
+
const serviceName = String(
|
|
2513
|
+
registrationPayload.service_name ?? this.serviceName ?? ""
|
|
2514
|
+
).trim();
|
|
2515
|
+
if (!serviceName || serviceName !== this.serviceName) {
|
|
2516
|
+
return false;
|
|
2517
|
+
}
|
|
2518
|
+
CadenzaService.schedule(
|
|
2519
|
+
"meta.service_registry.instance_registration_requested",
|
|
2520
|
+
{
|
|
2521
|
+
...ctx,
|
|
2522
|
+
data: registrationPayload,
|
|
2523
|
+
__registrationData: registrationPayload,
|
|
2524
|
+
__serviceName: serviceName,
|
|
2525
|
+
__serviceInstanceId: registrationPayload.uuid
|
|
2526
|
+
},
|
|
2527
|
+
5e3
|
|
2528
|
+
);
|
|
2529
|
+
return true;
|
|
2530
|
+
},
|
|
2531
|
+
"Retries local service instance registration only after the previous insert attempt has failed.",
|
|
2532
|
+
{
|
|
2533
|
+
register: false,
|
|
2534
|
+
isHidden: true
|
|
2535
|
+
}
|
|
2536
|
+
).doOn("meta.service_registry.instance_insertion_failed");
|
|
2284
2537
|
CadenzaService.createMetaTask(
|
|
2285
2538
|
"Prepare service instance registration",
|
|
2286
2539
|
(ctx) => {
|
|
2540
|
+
const registrationPayload = resolveServiceInstanceRegistrationPayload(
|
|
2541
|
+
ctx,
|
|
2542
|
+
this.serviceName,
|
|
2543
|
+
this.serviceInstanceId
|
|
2544
|
+
);
|
|
2545
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2546
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_instance_registration", {
|
|
2547
|
+
serviceName: registrationPayload?.service_name ?? ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? null,
|
|
2548
|
+
serviceInstanceId: registrationPayload?.uuid ?? ctx.data?.uuid ?? ctx.__serviceInstanceId ?? this.serviceInstanceId ?? null,
|
|
2549
|
+
hasData: !!registrationPayload,
|
|
2550
|
+
dataKeys: registrationPayload && typeof registrationPayload === "object" ? Object.keys(registrationPayload) : [],
|
|
2551
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2552
|
+
skipRemoteExecution: ctx.__skipRemoteExecution === true
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
if (!registrationPayload) {
|
|
2556
|
+
return false;
|
|
2557
|
+
}
|
|
2287
2558
|
const serviceName = String(
|
|
2288
|
-
|
|
2559
|
+
registrationPayload.service_name ?? ctx.__serviceName ?? this.serviceName ?? ""
|
|
2289
2560
|
).trim();
|
|
2290
2561
|
if (serviceName === "CadenzaDB" && !CadenzaService.getLocalCadenzaDBInsertTask("service_instance")) {
|
|
2291
2562
|
CadenzaService.schedule(
|
|
@@ -2295,7 +2566,16 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2295
2566
|
);
|
|
2296
2567
|
return false;
|
|
2297
2568
|
}
|
|
2298
|
-
return
|
|
2569
|
+
return {
|
|
2570
|
+
...ctx,
|
|
2571
|
+
data: registrationPayload,
|
|
2572
|
+
__registrationData: {
|
|
2573
|
+
...ctx.__registrationData ?? {},
|
|
2574
|
+
...registrationPayload
|
|
2575
|
+
},
|
|
2576
|
+
__serviceName: serviceName,
|
|
2577
|
+
__serviceInstanceId: registrationPayload.uuid
|
|
2578
|
+
};
|
|
2299
2579
|
},
|
|
2300
2580
|
"Waits for the exact local CadenzaDB service instance insert task during self-bootstrap."
|
|
2301
2581
|
).doOn("meta.service_registry.instance_registration_requested").then(this.insertServiceInstanceTask);
|
|
@@ -2476,21 +2756,40 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2476
2756
|
return [];
|
|
2477
2757
|
}
|
|
2478
2758
|
normalizeSignalMaps(ctx) {
|
|
2479
|
-
|
|
2759
|
+
const arrayPayload = this.readArrayPayload(ctx, [
|
|
2480
2760
|
"signalToTaskMaps",
|
|
2481
2761
|
"signal_to_task_maps",
|
|
2482
2762
|
"signalToTaskMap",
|
|
2483
2763
|
"signal_to_task_map"
|
|
2484
|
-
])
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2764
|
+
]);
|
|
2765
|
+
if (arrayPayload.length > 0) {
|
|
2766
|
+
return arrayPayload.map((map) => ({
|
|
2767
|
+
signalName: String(
|
|
2768
|
+
map.signalName ?? map.signal_name ?? ""
|
|
2769
|
+
).trim(),
|
|
2770
|
+
serviceName: String(
|
|
2771
|
+
map.serviceName ?? map.service_name ?? ""
|
|
2772
|
+
).trim(),
|
|
2773
|
+
isGlobal: Boolean(map.isGlobal ?? map.is_global ?? false),
|
|
2774
|
+
deleted: Boolean(map.deleted)
|
|
2775
|
+
})).filter((map) => map.signalName && map.serviceName);
|
|
2776
|
+
}
|
|
2777
|
+
const single = ctx.signalToTaskMap ?? ctx.signal_to_task_map ?? ctx.data ?? (ctx.signalName ?? ctx.signal_name ? ctx : void 0);
|
|
2778
|
+
if (!single || typeof single !== "object") {
|
|
2779
|
+
return [];
|
|
2780
|
+
}
|
|
2781
|
+
return [
|
|
2782
|
+
{
|
|
2783
|
+
signalName: String(
|
|
2784
|
+
single.signalName ?? single.signal_name ?? ""
|
|
2785
|
+
).trim(),
|
|
2786
|
+
serviceName: String(
|
|
2787
|
+
single.serviceName ?? single.service_name ?? ""
|
|
2788
|
+
).trim(),
|
|
2789
|
+
isGlobal: Boolean(single.isGlobal ?? single.is_global ?? false),
|
|
2790
|
+
deleted: Boolean(single.deleted)
|
|
2791
|
+
}
|
|
2792
|
+
].filter((map) => map.signalName && map.serviceName);
|
|
2494
2793
|
}
|
|
2495
2794
|
normalizeIntentMaps(ctx) {
|
|
2496
2795
|
const arrayPayload = this.readArrayPayload(ctx, [
|
|
@@ -2605,7 +2904,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2605
2904
|
)?.destroy();
|
|
2606
2905
|
this.gatheredSyncTransmissionServices.delete(serviceName);
|
|
2607
2906
|
}
|
|
2608
|
-
if (createdRecipients.length > 0
|
|
2907
|
+
if (createdRecipients.length > 0) {
|
|
2609
2908
|
emit("meta.cadenza_db.sync_tick", {
|
|
2610
2909
|
__syncing: true,
|
|
2611
2910
|
__reason: "gathered_sync_transmissions_reconciled"
|
|
@@ -2651,6 +2950,15 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2651
2950
|
};
|
|
2652
2951
|
this.remoteIntentDeputiesByKey.set(key, descriptor);
|
|
2653
2952
|
this.remoteIntentDeputiesByTask.set(deputyTask, descriptor);
|
|
2953
|
+
if (shouldTraceServiceRegistry(this.serviceName)) {
|
|
2954
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] register_remote_intent_deputy", {
|
|
2955
|
+
localServiceName: this.serviceName,
|
|
2956
|
+
intentName: map.intentName,
|
|
2957
|
+
remoteServiceName: map.serviceName,
|
|
2958
|
+
remoteTaskName: map.taskName,
|
|
2959
|
+
remoteTaskVersion: map.taskVersion
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
2654
2962
|
}
|
|
2655
2963
|
unregisterRemoteIntentDeputy(map) {
|
|
2656
2964
|
const key = this.buildRemoteIntentDeputyKey(map);
|
|
@@ -2680,6 +2988,56 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2680
2988
|
}
|
|
2681
2989
|
}
|
|
2682
2990
|
}
|
|
2991
|
+
registerBootstrapFullSyncDeputies(emit, ctx) {
|
|
2992
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
2993
|
+
return false;
|
|
2994
|
+
}
|
|
2995
|
+
CadenzaService.inquiryBroker.addIntent({
|
|
2996
|
+
name: META_SERVICE_REGISTRY_FULL_SYNC_INTENT
|
|
2997
|
+
});
|
|
2998
|
+
for (const taskName of BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS) {
|
|
2999
|
+
this.registerRemoteIntentDeputy({
|
|
3000
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
3001
|
+
serviceName: "CadenzaDB",
|
|
3002
|
+
taskName,
|
|
3003
|
+
taskVersion: 1
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
this.ensureDependeeClientsForService("CadenzaDB", emit, ctx);
|
|
3007
|
+
return true;
|
|
3008
|
+
}
|
|
3009
|
+
hasBootstrapFullSyncDeputies() {
|
|
3010
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
3011
|
+
return true;
|
|
3012
|
+
}
|
|
3013
|
+
return BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS.every(
|
|
3014
|
+
(taskName) => this.remoteIntentDeputiesByKey.has(
|
|
3015
|
+
this.buildRemoteIntentDeputyKey({
|
|
3016
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
3017
|
+
serviceName: "CadenzaDB",
|
|
3018
|
+
taskName,
|
|
3019
|
+
taskVersion: 1
|
|
3020
|
+
})
|
|
3021
|
+
)
|
|
3022
|
+
);
|
|
3023
|
+
}
|
|
3024
|
+
scheduleEarlyFullSyncRequests(reason) {
|
|
3025
|
+
for (const delayMs of EARLY_FULL_SYNC_DELAYS_MS) {
|
|
3026
|
+
CadenzaService.schedule(
|
|
3027
|
+
"meta.sync_requested",
|
|
3028
|
+
{
|
|
3029
|
+
__syncing: false,
|
|
3030
|
+
__reason: reason
|
|
3031
|
+
},
|
|
3032
|
+
delayMs
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3035
|
+
return true;
|
|
3036
|
+
}
|
|
3037
|
+
bootstrapFullSync(emit, ctx, reason = "local_instance_inserted") {
|
|
3038
|
+
this.registerBootstrapFullSyncDeputies(emit, ctx);
|
|
3039
|
+
return this.scheduleEarlyFullSyncRequests(reason);
|
|
3040
|
+
}
|
|
2683
3041
|
getInquiryResponderDescriptor(task) {
|
|
2684
3042
|
const remote = this.remoteIntentDeputiesByTask.get(task);
|
|
2685
3043
|
if (remote) {
|
|
@@ -2708,6 +3066,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2708
3066
|
}
|
|
2709
3067
|
return this.getInstance(this.serviceName, this.serviceInstanceId);
|
|
2710
3068
|
}
|
|
3069
|
+
hasLocalInstanceRegistered() {
|
|
3070
|
+
return Boolean(this.getLocalInstance());
|
|
3071
|
+
}
|
|
2711
3072
|
summarizeTransportForDebug(transport) {
|
|
2712
3073
|
if (!transport) {
|
|
2713
3074
|
return void 0;
|
|
@@ -2856,7 +3217,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2856
3217
|
return communicationTypes;
|
|
2857
3218
|
}
|
|
2858
3219
|
ensureDependeeClientForInstance(instance, emit, ctx) {
|
|
2859
|
-
if (!instance || instance.uuid === this.serviceInstanceId || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
3220
|
+
if (!instance || instance.uuid === this.serviceInstanceId || instance.serviceName === this.serviceName || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
2860
3221
|
return false;
|
|
2861
3222
|
}
|
|
2862
3223
|
if (!this.deputies.has(instance.serviceName) && !this.remoteIntents.has(instance.serviceName) && !this.remoteSignals.has(instance.serviceName)) {
|
|
@@ -2884,6 +3245,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2884
3245
|
return true;
|
|
2885
3246
|
}
|
|
2886
3247
|
ensureDependeeClientsForService(serviceName, emit, ctx) {
|
|
3248
|
+
if (!serviceName || serviceName === this.serviceName) {
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
2887
3251
|
for (const instance of this.instances.get(serviceName) ?? []) {
|
|
2888
3252
|
this.ensureDependeeClientForInstance(instance, emit, ctx);
|
|
2889
3253
|
}
|
|
@@ -3676,7 +4040,7 @@ var SignalTransmissionTask = class extends Task2 {
|
|
|
3676
4040
|
execute(context, emit, inquire, progressCallback) {
|
|
3677
4041
|
const ctx = context.getContext();
|
|
3678
4042
|
const metadata = context.getMetadata();
|
|
3679
|
-
const deputyContext = {
|
|
4043
|
+
const deputyContext = hoistDelegationMetadataFields({
|
|
3680
4044
|
__localTaskName: this.name,
|
|
3681
4045
|
__localServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
3682
4046
|
__serviceName: this.serviceName,
|
|
@@ -3689,12 +4053,13 @@ var SignalTransmissionTask = class extends Task2 {
|
|
|
3689
4053
|
__signalName: this.signalName,
|
|
3690
4054
|
__signalEmissionId: metadata.__signalEmission?.uuid,
|
|
3691
4055
|
...ctx
|
|
3692
|
-
};
|
|
4056
|
+
});
|
|
3693
4057
|
return this.taskFunction(deputyContext, emit, inquire, progressCallback);
|
|
3694
4058
|
}
|
|
3695
4059
|
};
|
|
3696
4060
|
|
|
3697
4061
|
// src/network/RestController.browser.ts
|
|
4062
|
+
var FETCH_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3698
4063
|
var RestController = class _RestController {
|
|
3699
4064
|
constructor() {
|
|
3700
4065
|
this.fetchClientDiagnostics = /* @__PURE__ */ new Map();
|
|
@@ -3740,7 +4105,15 @@ var RestController = class _RestController {
|
|
|
3740
4105
|
is_blocked: false,
|
|
3741
4106
|
health: {}
|
|
3742
4107
|
},
|
|
3743
|
-
__transportData:
|
|
4108
|
+
__transportData: Array.isArray(ctx.__declaredTransports) ? ctx.__declaredTransports.map((transport) => ({
|
|
4109
|
+
uuid: transport.uuid,
|
|
4110
|
+
service_instance_id: ctx.__serviceInstanceId,
|
|
4111
|
+
role: transport.role,
|
|
4112
|
+
origin: transport.origin,
|
|
4113
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
4114
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
4115
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
4116
|
+
})) : []
|
|
3744
4117
|
});
|
|
3745
4118
|
return true;
|
|
3746
4119
|
},
|
|
@@ -3755,6 +4128,7 @@ var RestController = class _RestController {
|
|
|
3755
4128
|
if (!serviceName || !URL2 || !fetchId) {
|
|
3756
4129
|
return false;
|
|
3757
4130
|
}
|
|
4131
|
+
const clientTaskSuffix = `${URL2} (${fetchId})`;
|
|
3758
4132
|
const fetchDiagnostics = this.ensureFetchClientDiagnostics(
|
|
3759
4133
|
fetchId,
|
|
3760
4134
|
serviceName,
|
|
@@ -3762,11 +4136,11 @@ var RestController = class _RestController {
|
|
|
3762
4136
|
);
|
|
3763
4137
|
fetchDiagnostics.destroyed = false;
|
|
3764
4138
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3765
|
-
if (CadenzaService.get(`Send Handshake to ${
|
|
4139
|
+
if (CadenzaService.get(`Send Handshake to ${clientTaskSuffix}`)) {
|
|
3766
4140
|
return;
|
|
3767
4141
|
}
|
|
3768
4142
|
const handshakeTask = CadenzaService.createMetaTask(
|
|
3769
|
-
`Send Handshake to ${
|
|
4143
|
+
`Send Handshake to ${clientTaskSuffix}`,
|
|
3770
4144
|
async (handshakeCtx, emit) => {
|
|
3771
4145
|
try {
|
|
3772
4146
|
const response = await this.fetchDataWithTimeout(
|
|
@@ -3778,7 +4152,7 @@ var RestController = class _RestController {
|
|
|
3778
4152
|
method: "POST",
|
|
3779
4153
|
body: JSON.stringify(handshakeCtx.handshakeData)
|
|
3780
4154
|
},
|
|
3781
|
-
|
|
4155
|
+
FETCH_HANDSHAKE_TIMEOUT_MS
|
|
3782
4156
|
);
|
|
3783
4157
|
if (response.__status !== "success") {
|
|
3784
4158
|
const error = response.__error ?? `Failed to connect to service ${serviceName} ${handshakeCtx.serviceInstanceId}`;
|
|
@@ -3814,13 +4188,19 @@ var RestController = class _RestController {
|
|
|
3814
4188
|
return handshakeCtx;
|
|
3815
4189
|
},
|
|
3816
4190
|
"Sends handshake request",
|
|
3817
|
-
{
|
|
4191
|
+
{
|
|
4192
|
+
retryCount: 5,
|
|
4193
|
+
retryDelay: 1e3,
|
|
4194
|
+
retryDelayFactor: 1.5,
|
|
4195
|
+
register: false,
|
|
4196
|
+
isHidden: true
|
|
4197
|
+
}
|
|
3818
4198
|
).doOn(`meta.fetch.handshake_requested:${fetchId}`).emits("meta.fetch.handshake_complete").attachSignal(
|
|
3819
4199
|
"meta.fetch.handshake_failed",
|
|
3820
4200
|
"global.meta.fetch.service_communication_established"
|
|
3821
4201
|
);
|
|
3822
4202
|
const delegateTask = CadenzaService.createMetaTask(
|
|
3823
|
-
`Delegate flow to REST server ${
|
|
4203
|
+
`Delegate flow to REST server ${clientTaskSuffix}`,
|
|
3824
4204
|
async (delegateCtx, emit) => {
|
|
3825
4205
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
3826
4206
|
return;
|
|
@@ -3857,13 +4237,17 @@ var RestController = class _RestController {
|
|
|
3857
4237
|
}
|
|
3858
4238
|
return resultContext;
|
|
3859
4239
|
},
|
|
3860
|
-
"Sends delegation request"
|
|
4240
|
+
"Sends delegation request",
|
|
4241
|
+
{
|
|
4242
|
+
register: false,
|
|
4243
|
+
isHidden: true
|
|
4244
|
+
}
|
|
3861
4245
|
).doOn(
|
|
3862
4246
|
`meta.service_registry.selected_instance_for_fetch:${fetchId}`,
|
|
3863
4247
|
`meta.service_registry.socket_failed:${fetchId}`
|
|
3864
4248
|
).emitsOnFail("meta.fetch.delegate_failed").attachSignal("meta.fetch.delegated");
|
|
3865
4249
|
const transmitTask = CadenzaService.createMetaTask(
|
|
3866
|
-
`Transmit signal to server ${
|
|
4250
|
+
`Transmit signal to server ${clientTaskSuffix}`,
|
|
3867
4251
|
async (signalCtx, emit) => {
|
|
3868
4252
|
if (signalCtx.__signalName === void 0) {
|
|
3869
4253
|
return;
|
|
@@ -3898,10 +4282,14 @@ var RestController = class _RestController {
|
|
|
3898
4282
|
}
|
|
3899
4283
|
return response;
|
|
3900
4284
|
},
|
|
3901
|
-
"Sends signal request"
|
|
4285
|
+
"Sends signal request",
|
|
4286
|
+
{
|
|
4287
|
+
register: false,
|
|
4288
|
+
isHidden: true
|
|
4289
|
+
}
|
|
3902
4290
|
).doOn(`meta.service_registry.selected_instance_for_fetch:${fetchId}`).emitsOnFail("meta.fetch.signal_transmission_failed").attachSignal("meta.fetch.transmitted");
|
|
3903
4291
|
const statusTask = CadenzaService.createMetaTask(
|
|
3904
|
-
`Request status from ${
|
|
4292
|
+
`Request status from ${clientTaskSuffix}`,
|
|
3905
4293
|
async (statusCtx) => {
|
|
3906
4294
|
fetchDiagnostics.statusChecks++;
|
|
3907
4295
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -3924,17 +4312,29 @@ var RestController = class _RestController {
|
|
|
3924
4312
|
};
|
|
3925
4313
|
}
|
|
3926
4314
|
},
|
|
3927
|
-
"Requests status"
|
|
4315
|
+
"Requests status",
|
|
4316
|
+
{
|
|
4317
|
+
register: false,
|
|
4318
|
+
isHidden: true
|
|
4319
|
+
}
|
|
3928
4320
|
).doOn("meta.fetch.status_check_requested").emits("meta.fetch.status_checked").emitsOnFail("meta.fetch.status_check_failed");
|
|
3929
|
-
CadenzaService.createEphemeralMetaTask(
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
4321
|
+
CadenzaService.createEphemeralMetaTask(
|
|
4322
|
+
`Destroy fetch client ${fetchId}`,
|
|
4323
|
+
() => {
|
|
4324
|
+
fetchDiagnostics.connected = false;
|
|
4325
|
+
fetchDiagnostics.destroyed = true;
|
|
4326
|
+
fetchDiagnostics.updatedAt = Date.now();
|
|
4327
|
+
handshakeTask.destroy();
|
|
4328
|
+
delegateTask.destroy();
|
|
4329
|
+
transmitTask.destroy();
|
|
4330
|
+
statusTask.destroy();
|
|
4331
|
+
},
|
|
4332
|
+
"",
|
|
4333
|
+
{
|
|
4334
|
+
register: false,
|
|
4335
|
+
isHidden: true
|
|
4336
|
+
}
|
|
4337
|
+
).doOn(
|
|
3938
4338
|
`meta.fetch.destroy_requested:${fetchId}`,
|
|
3939
4339
|
`meta.socket_client.disconnected:${fetchId}`,
|
|
3940
4340
|
`meta.fetch.handshake_failed:${fetchId}`
|
|
@@ -5341,7 +5741,11 @@ var SocketController = class _SocketController {
|
|
|
5341
5741
|
}
|
|
5342
5742
|
);
|
|
5343
5743
|
},
|
|
5344
|
-
"Handshakes with socket server"
|
|
5744
|
+
"Handshakes with socket server",
|
|
5745
|
+
{
|
|
5746
|
+
register: false,
|
|
5747
|
+
isHidden: true
|
|
5748
|
+
}
|
|
5345
5749
|
).doOn(`meta.socket_client.connected:${fetchId}`);
|
|
5346
5750
|
runtimeHandle.delegateTask = CadenzaService.createMetaTask(
|
|
5347
5751
|
`Delegate flow to Socket service ${url}`,
|
|
@@ -5419,7 +5823,11 @@ var SocketController = class _SocketController {
|
|
|
5419
5823
|
}
|
|
5420
5824
|
}
|
|
5421
5825
|
},
|
|
5422
|
-
`Delegate flow to service ${serviceName} with address ${url}
|
|
5826
|
+
`Delegate flow to service ${serviceName} with address ${url}`,
|
|
5827
|
+
{
|
|
5828
|
+
register: false,
|
|
5829
|
+
isHidden: true
|
|
5830
|
+
}
|
|
5423
5831
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal(
|
|
5424
5832
|
"meta.socket_client.delegated",
|
|
5425
5833
|
"meta.socket_shutdown_requested"
|
|
@@ -5443,7 +5851,11 @@ var SocketController = class _SocketController {
|
|
|
5443
5851
|
}
|
|
5444
5852
|
return response;
|
|
5445
5853
|
},
|
|
5446
|
-
`Transmits signal to service ${serviceName} with address ${url}
|
|
5854
|
+
`Transmits signal to service ${serviceName} with address ${url}`,
|
|
5855
|
+
{
|
|
5856
|
+
register: false,
|
|
5857
|
+
isHidden: true
|
|
5858
|
+
}
|
|
5447
5859
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal("meta.socket_client.transmitted");
|
|
5448
5860
|
CadenzaService.createEphemeralMetaTask(
|
|
5449
5861
|
`Shutdown SocketClient ${url}`,
|
|
@@ -5487,7 +5899,11 @@ var SocketController = class _SocketController {
|
|
|
5487
5899
|
fetchId
|
|
5488
5900
|
});
|
|
5489
5901
|
},
|
|
5490
|
-
"Shuts down the socket client"
|
|
5902
|
+
"Shuts down the socket client",
|
|
5903
|
+
{
|
|
5904
|
+
register: false,
|
|
5905
|
+
isHidden: true
|
|
5906
|
+
}
|
|
5491
5907
|
).doOn(
|
|
5492
5908
|
`meta.socket_shutdown_requested:${fetchId}`,
|
|
5493
5909
|
`meta.socket_client.disconnected:${fetchId}`,
|
|
@@ -5751,10 +6167,18 @@ function decomposeSignalName(signalName) {
|
|
|
5751
6167
|
|
|
5752
6168
|
// src/signals/SignalController.ts
|
|
5753
6169
|
function buildSignalDatabaseTriggerContext(data) {
|
|
6170
|
+
const onConflict = {
|
|
6171
|
+
target: ["name"],
|
|
6172
|
+
action: {
|
|
6173
|
+
do: "nothing"
|
|
6174
|
+
}
|
|
6175
|
+
};
|
|
5754
6176
|
return {
|
|
5755
6177
|
data: { ...data },
|
|
6178
|
+
onConflict,
|
|
5756
6179
|
queryData: {
|
|
5757
|
-
data: { ...data }
|
|
6180
|
+
data: { ...data },
|
|
6181
|
+
onConflict
|
|
5758
6182
|
}
|
|
5759
6183
|
};
|
|
5760
6184
|
}
|
|
@@ -5781,16 +6205,28 @@ var SignalController = class _SignalController {
|
|
|
5781
6205
|
CadenzaService.createMetaTask(
|
|
5782
6206
|
"Handle Signal Registration",
|
|
5783
6207
|
(ctx, emit) => {
|
|
6208
|
+
if (!CadenzaService.hasCompletedBootstrapSync()) {
|
|
6209
|
+
return false;
|
|
6210
|
+
}
|
|
5784
6211
|
const { signalName } = ctx;
|
|
6212
|
+
const signalObserver = CadenzaService.signalBroker.signalObservers?.get(
|
|
6213
|
+
signalName
|
|
6214
|
+
);
|
|
6215
|
+
if (signalObserver?.registered || signalObserver?.registrationRequested) {
|
|
6216
|
+
return false;
|
|
6217
|
+
}
|
|
6218
|
+
if (signalObserver) {
|
|
6219
|
+
signalObserver.registrationRequested = true;
|
|
6220
|
+
}
|
|
5785
6221
|
const { isMeta, isGlobal, domain, action } = decomposeSignalName(signalName);
|
|
5786
6222
|
emit(
|
|
5787
6223
|
"global.meta.signal_controller.signal_added",
|
|
5788
6224
|
buildSignalDatabaseTriggerContext({
|
|
5789
6225
|
name: signalName,
|
|
5790
|
-
isGlobal,
|
|
6226
|
+
is_global: isGlobal,
|
|
5791
6227
|
domain,
|
|
5792
6228
|
action,
|
|
5793
|
-
isMeta
|
|
6229
|
+
is_meta: isMeta
|
|
5794
6230
|
})
|
|
5795
6231
|
);
|
|
5796
6232
|
return ctx;
|
|
@@ -5799,12 +6235,35 @@ var SignalController = class _SignalController {
|
|
|
5799
6235
|
).doOn("meta.signal_broker.added").attachSignal("global.meta.signal_controller.signal_added");
|
|
5800
6236
|
CadenzaService.createMetaTask(
|
|
5801
6237
|
"Add data to signal emission",
|
|
5802
|
-
(ctx) => {
|
|
6238
|
+
(ctx, emit) => {
|
|
5803
6239
|
const signalEmission = ctx.__signalEmission;
|
|
5804
6240
|
delete ctx.__signalEmission;
|
|
5805
6241
|
if (!signalEmission) {
|
|
5806
6242
|
return false;
|
|
5807
6243
|
}
|
|
6244
|
+
if (typeof signalEmission.signalName === "string" && signalEmission.signalName.trim().length > 0 && !CadenzaService.signalBroker.signalObservers?.has(signalEmission.signalName)) {
|
|
6245
|
+
CadenzaService.signalBroker.addSignal(signalEmission.signalName);
|
|
6246
|
+
} else {
|
|
6247
|
+
const signalObserver = CadenzaService.signalBroker.signalObservers?.get(
|
|
6248
|
+
signalEmission.signalName
|
|
6249
|
+
);
|
|
6250
|
+
if (signalObserver && signalObserver.registered !== true && signalObserver.registrationRequested !== true && CadenzaService.hasCompletedBootstrapSync()) {
|
|
6251
|
+
signalObserver.registrationRequested = true;
|
|
6252
|
+
const { isMeta, isGlobal, domain, action } = decomposeSignalName(
|
|
6253
|
+
signalEmission.signalName
|
|
6254
|
+
);
|
|
6255
|
+
emit(
|
|
6256
|
+
"global.meta.signal_controller.signal_added",
|
|
6257
|
+
buildSignalDatabaseTriggerContext({
|
|
6258
|
+
name: signalEmission.signalName,
|
|
6259
|
+
is_global: isGlobal,
|
|
6260
|
+
domain,
|
|
6261
|
+
action,
|
|
6262
|
+
is_meta: isMeta
|
|
6263
|
+
})
|
|
6264
|
+
);
|
|
6265
|
+
}
|
|
6266
|
+
}
|
|
5808
6267
|
return {
|
|
5809
6268
|
data: {
|
|
5810
6269
|
uuid: signalEmission.uuid,
|
|
@@ -6159,10 +6618,10 @@ function registerActorSessionPersistenceTasks() {
|
|
|
6159
6618
|
}
|
|
6160
6619
|
|
|
6161
6620
|
// src/graph/controllers/GraphMetadataController.ts
|
|
6162
|
-
function buildDatabaseTriggerContext(data, filter, extra = {}) {
|
|
6621
|
+
function buildDatabaseTriggerContext(data, filter, extra = {}, queryExtra = {}) {
|
|
6163
6622
|
const nextData = data && typeof data === "object" ? { ...data } : void 0;
|
|
6164
6623
|
const nextFilter = filter && typeof filter === "object" ? { ...filter } : void 0;
|
|
6165
|
-
const queryData = {};
|
|
6624
|
+
const queryData = { ...queryExtra };
|
|
6166
6625
|
if (nextData !== void 0) {
|
|
6167
6626
|
queryData.data = nextData;
|
|
6168
6627
|
}
|
|
@@ -6176,33 +6635,125 @@ function buildDatabaseTriggerContext(data, filter, extra = {}) {
|
|
|
6176
6635
|
...Object.keys(queryData).length > 0 ? { queryData } : {}
|
|
6177
6636
|
};
|
|
6178
6637
|
}
|
|
6638
|
+
function resolveTaskFromMetadataContext(ctx) {
|
|
6639
|
+
const taskName = String(
|
|
6640
|
+
ctx?.taskName ?? ctx?.data?.taskName ?? ctx?.data?.task_name ?? ctx?.filter?.taskName ?? ctx?.filter?.task_name ?? ""
|
|
6641
|
+
);
|
|
6642
|
+
return taskName ? CadenzaService.get(taskName) : void 0;
|
|
6643
|
+
}
|
|
6644
|
+
function resolveTaskByName(name) {
|
|
6645
|
+
const taskName = String(name ?? "");
|
|
6646
|
+
return taskName ? CadenzaService.get(taskName) : void 0;
|
|
6647
|
+
}
|
|
6648
|
+
function resolvePredecessorTaskFromMetadataContext(ctx) {
|
|
6649
|
+
return resolveTaskByName(
|
|
6650
|
+
ctx?.predecessorTaskName ?? ctx?.data?.predecessorTaskName ?? ctx?.data?.predecessor_task_name ?? ctx?.filter?.predecessorTaskName ?? ctx?.filter?.predecessor_task_name
|
|
6651
|
+
);
|
|
6652
|
+
}
|
|
6653
|
+
function shouldSkipDirectTaskMetadata(task) {
|
|
6654
|
+
return !task || !task.register || task.isHidden || task.isDeputy;
|
|
6655
|
+
}
|
|
6656
|
+
function shouldPersistBusinessTaskExecution(task) {
|
|
6657
|
+
return !!task && task.register && !task.isHidden && !task.isMeta && !task.isSubMeta && !task.isDeputy;
|
|
6658
|
+
}
|
|
6659
|
+
function shouldEmitDirectPrimitiveMetadata() {
|
|
6660
|
+
return CadenzaService.hasCompletedBootstrapSync();
|
|
6661
|
+
}
|
|
6662
|
+
function shouldPersistBusinessInquiry(ctx) {
|
|
6663
|
+
const inquiryName = String(
|
|
6664
|
+
ctx?.data?.name ?? ctx?.inquiry ?? ctx?.data?.metadata?.inquiryMeta?.inquiry ?? ""
|
|
6665
|
+
);
|
|
6666
|
+
if (!inquiryName) {
|
|
6667
|
+
return false;
|
|
6668
|
+
}
|
|
6669
|
+
return !isMetaIntentName(inquiryName) && ctx?.data?.isMeta !== true && ctx?.data?.is_meta !== true;
|
|
6670
|
+
}
|
|
6671
|
+
function shouldPersistRoutineExecution(ctx) {
|
|
6672
|
+
if (ctx?.data?.isMeta === true || ctx?.data?.is_meta === true) {
|
|
6673
|
+
return false;
|
|
6674
|
+
}
|
|
6675
|
+
const routineTask = resolveTaskByName(ctx?.data?.name);
|
|
6676
|
+
if (routineTask) {
|
|
6677
|
+
return shouldPersistBusinessTaskExecution(routineTask);
|
|
6678
|
+
}
|
|
6679
|
+
return true;
|
|
6680
|
+
}
|
|
6681
|
+
function shouldPersistTaskExecutionMetadata(ctx) {
|
|
6682
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6683
|
+
return shouldPersistBusinessTaskExecution(task);
|
|
6684
|
+
}
|
|
6685
|
+
function shouldPersistTaskExecutionMap(ctx) {
|
|
6686
|
+
return shouldPersistBusinessTaskExecution(resolveTaskFromMetadataContext(ctx)) && shouldPersistBusinessTaskExecution(resolvePredecessorTaskFromMetadataContext(ctx));
|
|
6687
|
+
}
|
|
6688
|
+
function hasInquiryLink(data) {
|
|
6689
|
+
const metaContext = data?.metaContext ?? data?.meta_context;
|
|
6690
|
+
const directInquiryId = metaContext?.__inquiryId ?? metaContext?.__metadata?.__inquiryId;
|
|
6691
|
+
return typeof directInquiryId === "string" && directInquiryId.length > 0;
|
|
6692
|
+
}
|
|
6179
6693
|
var GraphMetadataController = class _GraphMetadataController {
|
|
6180
6694
|
static get instance() {
|
|
6181
6695
|
if (!this._instance) this._instance = new _GraphMetadataController();
|
|
6182
6696
|
return this._instance;
|
|
6183
6697
|
}
|
|
6184
6698
|
constructor() {
|
|
6699
|
+
const buildOnConflictDoNothing = (target) => ({
|
|
6700
|
+
target,
|
|
6701
|
+
action: {
|
|
6702
|
+
do: "nothing"
|
|
6703
|
+
}
|
|
6704
|
+
});
|
|
6185
6705
|
CadenzaService.createMetaTask("Handle task creation", (ctx) => {
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6706
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6707
|
+
return false;
|
|
6708
|
+
}
|
|
6709
|
+
const taskName = String(ctx.data?.name ?? ctx.data?.taskName ?? "");
|
|
6710
|
+
const task = taskName ? CadenzaService.get(taskName) : void 0;
|
|
6711
|
+
const onConflict = buildOnConflictDoNothing([
|
|
6712
|
+
"name",
|
|
6713
|
+
"service_name",
|
|
6714
|
+
"version"
|
|
6715
|
+
]);
|
|
6716
|
+
if (shouldSkipDirectTaskMetadata(task) || task?.registered || task?.registrationRequested) {
|
|
6717
|
+
return false;
|
|
6718
|
+
}
|
|
6719
|
+
if (task) {
|
|
6720
|
+
task.registrationRequested = true;
|
|
6721
|
+
}
|
|
6192
6722
|
return buildDatabaseTriggerContext(
|
|
6193
|
-
ctx.data ?? void 0,
|
|
6194
6723
|
{
|
|
6195
|
-
...ctx.
|
|
6724
|
+
...ctx.data,
|
|
6196
6725
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6197
|
-
}
|
|
6726
|
+
},
|
|
6727
|
+
void 0,
|
|
6728
|
+
{ onConflict },
|
|
6729
|
+
{ onConflict }
|
|
6730
|
+
);
|
|
6731
|
+
}).doOn("meta.task.created").emits("global.meta.graph_metadata.task_created");
|
|
6732
|
+
CadenzaService.createMetaTask("Handle task update", (ctx) => {
|
|
6733
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6734
|
+
return false;
|
|
6735
|
+
}
|
|
6736
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6737
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6738
|
+
return false;
|
|
6739
|
+
}
|
|
6740
|
+
return buildDatabaseTriggerContext(
|
|
6741
|
+
ctx.data ?? void 0,
|
|
6742
|
+
{
|
|
6743
|
+
...ctx.filter,
|
|
6744
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6745
|
+
}
|
|
6198
6746
|
);
|
|
6199
6747
|
}).doOn("meta.task.layer_index_changed", "meta.task.destroyed").emits("global.meta.graph_metadata.task_updated");
|
|
6200
6748
|
CadenzaService.createMetaTask("Handle task relationship creation", (ctx) => {
|
|
6749
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6750
|
+
return false;
|
|
6751
|
+
}
|
|
6201
6752
|
const taskName = ctx.data?.taskName ?? ctx.data?.task_name;
|
|
6202
6753
|
const predecessorTaskName = ctx.data?.predecessorTaskName ?? ctx.data?.predecessor_task_name;
|
|
6203
6754
|
const task = taskName ? CadenzaService.get(taskName) : void 0;
|
|
6204
6755
|
const predecessorTask = predecessorTaskName ? CadenzaService.get(predecessorTaskName) : void 0;
|
|
6205
|
-
if (!task?.registered || !predecessorTask?.registered) {
|
|
6756
|
+
if (shouldSkipDirectTaskMetadata(task) || shouldSkipDirectTaskMetadata(predecessorTask) || !task?.registered || !predecessorTask?.registered) {
|
|
6206
6757
|
return false;
|
|
6207
6758
|
}
|
|
6208
6759
|
return buildDatabaseTriggerContext({
|
|
@@ -6215,14 +6766,35 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6215
6766
|
CadenzaService.log(`Error in task ${ctx.data.taskName}`, ctx.data, "error");
|
|
6216
6767
|
}).doOn("meta.node.errored");
|
|
6217
6768
|
CadenzaService.createMetaTask("Handle task signal observation", (ctx) => {
|
|
6218
|
-
|
|
6769
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6770
|
+
return false;
|
|
6771
|
+
}
|
|
6772
|
+
const signalName = String(
|
|
6773
|
+
ctx.signalName ?? ctx.data?.signalName ?? ""
|
|
6774
|
+
).split(":")[0];
|
|
6775
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6776
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6777
|
+
return false;
|
|
6778
|
+
}
|
|
6779
|
+
if (task?.registered && task.registeredSignals.has(signalName)) {
|
|
6780
|
+
return false;
|
|
6781
|
+
}
|
|
6782
|
+
const isGlobal = signalName.startsWith("global.");
|
|
6219
6783
|
return buildDatabaseTriggerContext({
|
|
6220
6784
|
...ctx.data,
|
|
6785
|
+
signalName,
|
|
6221
6786
|
isGlobal,
|
|
6222
6787
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6223
6788
|
});
|
|
6224
6789
|
}).doOn("meta.task.observed_signal").emits("global.meta.graph_metadata.task_signal_observed");
|
|
6225
6790
|
CadenzaService.createMetaTask("Handle task signal attachment", (ctx) => {
|
|
6791
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6792
|
+
return false;
|
|
6793
|
+
}
|
|
6794
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6795
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6796
|
+
return false;
|
|
6797
|
+
}
|
|
6226
6798
|
return buildDatabaseTriggerContext(
|
|
6227
6799
|
ctx.data ?? void 0,
|
|
6228
6800
|
{
|
|
@@ -6231,7 +6803,34 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6231
6803
|
}
|
|
6232
6804
|
);
|
|
6233
6805
|
}).doOn("meta.task.attached_signal").emits("global.meta.graph_metadata.task_attached_signal");
|
|
6806
|
+
CadenzaService.createMetaTask("Handle task intent association", (ctx) => {
|
|
6807
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6808
|
+
return false;
|
|
6809
|
+
}
|
|
6810
|
+
const intentName = String(ctx.data?.intentName ?? "");
|
|
6811
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6812
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6813
|
+
return false;
|
|
6814
|
+
}
|
|
6815
|
+
if (task?.registered && task.__registeredIntents?.has(
|
|
6816
|
+
intentName
|
|
6817
|
+
)) {
|
|
6818
|
+
return false;
|
|
6819
|
+
}
|
|
6820
|
+
return buildDatabaseTriggerContext({
|
|
6821
|
+
...ctx.data,
|
|
6822
|
+
intentName,
|
|
6823
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6824
|
+
});
|
|
6825
|
+
}).doOn("meta.task.intent_associated").emits("global.meta.graph_metadata.task_intent_associated");
|
|
6234
6826
|
CadenzaService.createMetaTask("Handle task unsubscribing signal", (ctx) => {
|
|
6827
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6828
|
+
return false;
|
|
6829
|
+
}
|
|
6830
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6831
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6832
|
+
return false;
|
|
6833
|
+
}
|
|
6235
6834
|
return buildDatabaseTriggerContext(
|
|
6236
6835
|
{
|
|
6237
6836
|
deleted: true
|
|
@@ -6243,6 +6842,13 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6243
6842
|
);
|
|
6244
6843
|
}).doOn("meta.task.unsubscribed_signal").emits("meta.graph_metadata.task_unsubscribed_signal");
|
|
6245
6844
|
CadenzaService.createMetaTask("Handle task detaching signal", (ctx) => {
|
|
6845
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6846
|
+
return false;
|
|
6847
|
+
}
|
|
6848
|
+
const task = resolveTaskFromMetadataContext(ctx);
|
|
6849
|
+
if (shouldSkipDirectTaskMetadata(task)) {
|
|
6850
|
+
return false;
|
|
6851
|
+
}
|
|
6246
6852
|
return buildDatabaseTriggerContext(
|
|
6247
6853
|
{
|
|
6248
6854
|
deleted: true
|
|
@@ -6254,12 +6860,18 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6254
6860
|
);
|
|
6255
6861
|
}).doOn("meta.task.detached_signal").emits("global.meta.graph_metadata.task_detached_signal");
|
|
6256
6862
|
CadenzaService.createMetaTask("Handle routine creation", (ctx) => {
|
|
6863
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6864
|
+
return false;
|
|
6865
|
+
}
|
|
6257
6866
|
return buildDatabaseTriggerContext({
|
|
6258
6867
|
...ctx.data,
|
|
6259
6868
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6260
6869
|
});
|
|
6261
6870
|
}).doAfter(CadenzaService.registry.registerRoutine).emits("global.meta.graph_metadata.routine_created");
|
|
6262
6871
|
CadenzaService.createMetaTask("Handle routine update", (ctx) => {
|
|
6872
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6873
|
+
return false;
|
|
6874
|
+
}
|
|
6263
6875
|
return buildDatabaseTriggerContext(
|
|
6264
6876
|
ctx.data ?? void 0,
|
|
6265
6877
|
{
|
|
@@ -6269,6 +6881,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6269
6881
|
);
|
|
6270
6882
|
}).doOn("meta.routine.destroyed").emits("global.meta.graph_metadata.routine_updated");
|
|
6271
6883
|
CadenzaService.createMetaTask("Handle adding task to routine", (ctx) => {
|
|
6884
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
6885
|
+
return false;
|
|
6886
|
+
}
|
|
6272
6887
|
return buildDatabaseTriggerContext({
|
|
6273
6888
|
...ctx.data,
|
|
6274
6889
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
@@ -6284,8 +6899,12 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6284
6899
|
CadenzaService.createMetaTask(
|
|
6285
6900
|
"Handle routine execution creation",
|
|
6286
6901
|
(ctx) => {
|
|
6902
|
+
if (!shouldPersistRoutineExecution(ctx)) {
|
|
6903
|
+
return false;
|
|
6904
|
+
}
|
|
6287
6905
|
return buildDatabaseTriggerContext({
|
|
6288
6906
|
...ctx.data,
|
|
6907
|
+
previousRoutineExecution: hasInquiryLink(ctx.data) ? null : ctx.data?.previousRoutineExecution ?? ctx.data?.previous_routine_execution ?? null,
|
|
6289
6908
|
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
6290
6909
|
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId
|
|
6291
6910
|
});
|
|
@@ -6322,6 +6941,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6322
6941
|
CadenzaService.createMetaTask(
|
|
6323
6942
|
"Handle task execution creation",
|
|
6324
6943
|
(ctx) => {
|
|
6944
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
6945
|
+
return false;
|
|
6946
|
+
}
|
|
6325
6947
|
return buildDatabaseTriggerContext({
|
|
6326
6948
|
...ctx.data,
|
|
6327
6949
|
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
@@ -6334,6 +6956,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6334
6956
|
CadenzaService.createMetaTask(
|
|
6335
6957
|
"Handle task execution mapped",
|
|
6336
6958
|
(ctx) => {
|
|
6959
|
+
if (!shouldPersistTaskExecutionMap(ctx)) {
|
|
6960
|
+
return false;
|
|
6961
|
+
}
|
|
6337
6962
|
return buildDatabaseTriggerContext(
|
|
6338
6963
|
ctx.data ?? void 0,
|
|
6339
6964
|
ctx.filter ?? void 0
|
|
@@ -6345,6 +6970,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6345
6970
|
CadenzaService.createMetaTask(
|
|
6346
6971
|
"Handle task execution started",
|
|
6347
6972
|
(ctx) => {
|
|
6973
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
6974
|
+
return false;
|
|
6975
|
+
}
|
|
6348
6976
|
return buildDatabaseTriggerContext(
|
|
6349
6977
|
ctx.data ?? void 0,
|
|
6350
6978
|
ctx.filter ?? void 0
|
|
@@ -6356,6 +6984,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6356
6984
|
CadenzaService.createMetaTask(
|
|
6357
6985
|
"Handle task execution ended",
|
|
6358
6986
|
(ctx) => {
|
|
6987
|
+
if (!shouldPersistTaskExecutionMetadata(ctx)) {
|
|
6988
|
+
return false;
|
|
6989
|
+
}
|
|
6359
6990
|
return buildDatabaseTriggerContext(
|
|
6360
6991
|
{
|
|
6361
6992
|
...ctx.data,
|
|
@@ -6368,9 +6999,39 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6368
6999
|
"Handles task execution ended",
|
|
6369
7000
|
{ concurrency: 100, isSubMeta: true }
|
|
6370
7001
|
).doOn("meta.node.ended").emits("global.meta.graph_metadata.task_execution_ended");
|
|
7002
|
+
CadenzaService.createMetaTask(
|
|
7003
|
+
"Handle inquiry creation",
|
|
7004
|
+
(ctx) => {
|
|
7005
|
+
if (!shouldPersistBusinessInquiry(ctx)) {
|
|
7006
|
+
return false;
|
|
7007
|
+
}
|
|
7008
|
+
return buildDatabaseTriggerContext({
|
|
7009
|
+
...ctx.data,
|
|
7010
|
+
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
7011
|
+
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
7012
|
+
isMeta: false
|
|
7013
|
+
});
|
|
7014
|
+
},
|
|
7015
|
+
"Handles inquiry creation",
|
|
7016
|
+
{ concurrency: 100, isSubMeta: true }
|
|
7017
|
+
).doOn("meta.inquiry_broker.inquiry_started").emits("global.meta.graph_metadata.inquiry_created");
|
|
7018
|
+
CadenzaService.createMetaTask(
|
|
7019
|
+
"Handle inquiry update",
|
|
7020
|
+
(ctx) => {
|
|
7021
|
+
return buildDatabaseTriggerContext(
|
|
7022
|
+
ctx.data ?? void 0,
|
|
7023
|
+
ctx.filter ?? void 0
|
|
7024
|
+
);
|
|
7025
|
+
},
|
|
7026
|
+
"Handles inquiry completion updates",
|
|
7027
|
+
{ concurrency: 100, isSubMeta: true }
|
|
7028
|
+
).doOn("meta.inquiry_broker.inquiry_completed").emits("global.meta.graph_metadata.inquiry_updated");
|
|
6371
7029
|
CadenzaService.createMetaTask(
|
|
6372
7030
|
"Handle task execution relationship creation",
|
|
6373
7031
|
(ctx) => {
|
|
7032
|
+
if (!shouldPersistTaskExecutionMap(ctx)) {
|
|
7033
|
+
return false;
|
|
7034
|
+
}
|
|
6374
7035
|
return buildDatabaseTriggerContext(
|
|
6375
7036
|
{
|
|
6376
7037
|
executionCount: "increment",
|
|
@@ -6386,12 +7047,18 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6386
7047
|
{ concurrency: 100, isSubMeta: true }
|
|
6387
7048
|
).doOn("meta.node.mapped", "meta.node.detected_previous_task_execution").emits("global.meta.graph_metadata.relationship_executed");
|
|
6388
7049
|
CadenzaService.createMetaTask("Handle actor creation", (ctx) => {
|
|
7050
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7051
|
+
return false;
|
|
7052
|
+
}
|
|
6389
7053
|
return buildDatabaseTriggerContext({
|
|
6390
7054
|
...ctx.data,
|
|
6391
7055
|
service_name: CadenzaService.serviceRegistry.serviceName
|
|
6392
7056
|
});
|
|
6393
7057
|
}).doOn("meta.actor.created").emits("global.meta.graph_metadata.actor_created");
|
|
6394
7058
|
CadenzaService.createMetaTask("Handle actor task association", (ctx) => {
|
|
7059
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7060
|
+
return false;
|
|
7061
|
+
}
|
|
6395
7062
|
return buildDatabaseTriggerContext({
|
|
6396
7063
|
...ctx.data,
|
|
6397
7064
|
service_name: CadenzaService.serviceRegistry.serviceName
|
|
@@ -6399,6 +7066,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6399
7066
|
}).doOn("meta.actor.task_associated").emits("global.meta.graph_metadata.actor_task_associated");
|
|
6400
7067
|
registerActorSessionPersistenceTasks();
|
|
6401
7068
|
CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
|
|
7069
|
+
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
7070
|
+
return false;
|
|
7071
|
+
}
|
|
6402
7072
|
const intentName = ctx.data?.name;
|
|
6403
7073
|
return buildDatabaseTriggerContext({
|
|
6404
7074
|
...ctx.data,
|
|
@@ -6522,7 +7192,7 @@ function buildIntentRegistryData(intent) {
|
|
|
6522
7192
|
description: typeof intent?.description === "string" ? intent.description : "",
|
|
6523
7193
|
input: intent?.input && typeof intent.input === "object" ? intent.input : { type: "object" },
|
|
6524
7194
|
output: intent?.output && typeof intent.output === "object" ? intent.output : { type: "object" },
|
|
6525
|
-
|
|
7195
|
+
is_meta: isMetaIntentName(name)
|
|
6526
7196
|
};
|
|
6527
7197
|
}
|
|
6528
7198
|
function getJoinedContextValue(ctx, key) {
|
|
@@ -6595,34 +7265,7 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
|
|
|
6595
7265
|
}
|
|
6596
7266
|
return nextQueryData;
|
|
6597
7267
|
}
|
|
6598
|
-
function buildSyncQueryQueryData(ctx, queryData = {}) {
|
|
6599
|
-
const joinedQueryData = getJoinedContextValue(ctx, "queryData");
|
|
6600
|
-
const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : joinedQueryData && typeof joinedQueryData === "object" ? joinedQueryData : {};
|
|
6601
|
-
const nextQueryData = {};
|
|
6602
|
-
const allowedKeys = [
|
|
6603
|
-
"transaction",
|
|
6604
|
-
"filter",
|
|
6605
|
-
"fields",
|
|
6606
|
-
"joins",
|
|
6607
|
-
"sort",
|
|
6608
|
-
"limit",
|
|
6609
|
-
"offset",
|
|
6610
|
-
"queryMode",
|
|
6611
|
-
"aggregates",
|
|
6612
|
-
"groupBy"
|
|
6613
|
-
];
|
|
6614
|
-
for (const key of allowedKeys) {
|
|
6615
|
-
if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
|
|
6616
|
-
nextQueryData[key] = existingQueryData[key];
|
|
6617
|
-
}
|
|
6618
|
-
}
|
|
6619
|
-
return {
|
|
6620
|
-
...nextQueryData,
|
|
6621
|
-
...queryData
|
|
6622
|
-
};
|
|
6623
|
-
}
|
|
6624
7268
|
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 5;
|
|
6625
|
-
var REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY = 3;
|
|
6626
7269
|
function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
6627
7270
|
if (!graph) {
|
|
6628
7271
|
return void 0;
|
|
@@ -6635,11 +7278,27 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
|
6635
7278
|
}
|
|
6636
7279
|
function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
6637
7280
|
const originalContext = { ...ctx };
|
|
7281
|
+
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();
|
|
7282
|
+
const rootDbOperationFields = {};
|
|
7283
|
+
for (const key of [
|
|
7284
|
+
"data",
|
|
7285
|
+
"batch",
|
|
7286
|
+
"transaction",
|
|
7287
|
+
"onConflict",
|
|
7288
|
+
"filter",
|
|
7289
|
+
"fields"
|
|
7290
|
+
]) {
|
|
7291
|
+
if (Object.prototype.hasOwnProperty.call(queryData, key)) {
|
|
7292
|
+
rootDbOperationFields[key] = queryData[key];
|
|
7293
|
+
}
|
|
7294
|
+
}
|
|
6638
7295
|
const nextContext = {
|
|
6639
7296
|
__syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
|
|
7297
|
+
__syncSourceServiceName: syncSourceServiceName,
|
|
6640
7298
|
__preferredTransportProtocol: "rest",
|
|
6641
7299
|
__resolverOriginalContext: originalContext,
|
|
6642
7300
|
__resolverQueryData: queryData,
|
|
7301
|
+
...rootDbOperationFields,
|
|
6643
7302
|
queryData
|
|
6644
7303
|
};
|
|
6645
7304
|
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
@@ -6647,9 +7306,26 @@ function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
|
6647
7306
|
}
|
|
6648
7307
|
return nextContext;
|
|
6649
7308
|
}
|
|
7309
|
+
function markCompletedSyncCycle(completedCycles, cycleId, limit = 32) {
|
|
7310
|
+
if (!cycleId) {
|
|
7311
|
+
return false;
|
|
7312
|
+
}
|
|
7313
|
+
if (completedCycles.has(cycleId)) {
|
|
7314
|
+
return false;
|
|
7315
|
+
}
|
|
7316
|
+
completedCycles.add(cycleId);
|
|
7317
|
+
while (completedCycles.size > limit) {
|
|
7318
|
+
const oldestCycleId = completedCycles.values().next().value;
|
|
7319
|
+
if (!oldestCycleId) {
|
|
7320
|
+
break;
|
|
7321
|
+
}
|
|
7322
|
+
completedCycles.delete(oldestCycleId);
|
|
7323
|
+
}
|
|
7324
|
+
return true;
|
|
7325
|
+
}
|
|
6650
7326
|
function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6651
7327
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
6652
|
-
if (
|
|
7328
|
+
if (isCadenzaDBReady && !localInsertTask) {
|
|
6653
7329
|
return void 0;
|
|
6654
7330
|
}
|
|
6655
7331
|
const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
|
|
@@ -6700,6 +7376,11 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
6700
7376
|
...ctx,
|
|
6701
7377
|
queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
|
|
6702
7378
|
};
|
|
7379
|
+
if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
|
|
7380
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
7381
|
+
delayMs: 1e3
|
|
7382
|
+
});
|
|
7383
|
+
}
|
|
6703
7384
|
return normalizedContext;
|
|
6704
7385
|
},
|
|
6705
7386
|
`Finalizes ${tableName} graph-sync insert execution after the authority task finishes.`,
|
|
@@ -6727,86 +7408,82 @@ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
|
|
|
6727
7408
|
"intent_to_task_map",
|
|
6728
7409
|
"directional_task_graph_map"
|
|
6729
7410
|
];
|
|
6730
|
-
var
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
function
|
|
6738
|
-
const
|
|
6739
|
-
|
|
6740
|
-
|
|
7411
|
+
var BOOTSTRAP_SYNC_STALE_CYCLE_MS = 15e3;
|
|
7412
|
+
var EARLY_SYNC_TICK_DELAYS_MS = [
|
|
7413
|
+
400,
|
|
7414
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS + 1e3,
|
|
7415
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 2 + 2e3,
|
|
7416
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 3 + 3e3
|
|
7417
|
+
];
|
|
7418
|
+
function shouldTraceSyncPhase(serviceName) {
|
|
7419
|
+
const configured = process.env.CADENZA_SYNC_PHASE_TRACE_SERVICE;
|
|
7420
|
+
if (!configured || !serviceName) {
|
|
7421
|
+
return false;
|
|
7422
|
+
}
|
|
7423
|
+
return configured === serviceName;
|
|
6741
7424
|
}
|
|
6742
|
-
function
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
return void 0;
|
|
7425
|
+
function canonicalizeSignalName(signalName) {
|
|
7426
|
+
if (typeof signalName !== "string") {
|
|
7427
|
+
return "";
|
|
6746
7428
|
}
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY
|
|
6752
|
-
) : REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY,
|
|
6753
|
-
register: false,
|
|
6754
|
-
isHidden: true
|
|
6755
|
-
});
|
|
6756
|
-
const prepareQueryTask = CadenzaService.createMetaTask(
|
|
6757
|
-
`Prepare graph sync query for ${tableName}`,
|
|
6758
|
-
(ctx) => buildSyncExecutionEnvelope(
|
|
6759
|
-
ctx,
|
|
6760
|
-
buildSyncQueryQueryData(ctx, queryData)
|
|
6761
|
-
),
|
|
6762
|
-
`Prepares ${tableName} graph-sync query payloads.`,
|
|
6763
|
-
{
|
|
6764
|
-
register: false,
|
|
6765
|
-
isHidden: true
|
|
6766
|
-
}
|
|
6767
|
-
);
|
|
6768
|
-
const finalizeQueryTask = CadenzaService.createMetaTask(
|
|
6769
|
-
`Finalize graph sync query for ${tableName}`,
|
|
6770
|
-
(ctx) => ctx,
|
|
6771
|
-
`Finalizes ${tableName} graph-sync query payloads after authority lookup.`,
|
|
6772
|
-
{
|
|
6773
|
-
register: false,
|
|
6774
|
-
isHidden: true
|
|
6775
|
-
}
|
|
6776
|
-
);
|
|
6777
|
-
prepareQueryTask.then(targetTask);
|
|
6778
|
-
targetTask.then(finalizeQueryTask);
|
|
6779
|
-
return {
|
|
6780
|
-
entryTask: prepareQueryTask,
|
|
6781
|
-
completionTask: finalizeQueryTask
|
|
6782
|
-
};
|
|
7429
|
+
return signalName.split(":")[0]?.trim() ?? "";
|
|
7430
|
+
}
|
|
7431
|
+
function isBootstrapLocalOnlySignal(signalName) {
|
|
7432
|
+
return signalName === "meta.service_registry.insert_execution_requested" || signalName.startsWith("meta.sync_controller.");
|
|
6783
7433
|
}
|
|
6784
7434
|
function getRegistrableTasks() {
|
|
6785
7435
|
return Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
6786
|
-
(task) => task.register && !task.isHidden
|
|
7436
|
+
(task) => task.register && !task.isHidden && !task.isDeputy
|
|
6787
7437
|
);
|
|
6788
7438
|
}
|
|
6789
7439
|
function getRegistrableRoutines() {
|
|
6790
7440
|
return Array.from(CadenzaService.registry.routines.values());
|
|
6791
7441
|
}
|
|
6792
|
-
function isAuthoritySyncSignal(signalName) {
|
|
6793
|
-
return decomposeSignalName(signalName).isGlobal;
|
|
6794
|
-
}
|
|
6795
7442
|
function getRegistrableSignalObservers() {
|
|
6796
7443
|
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
6797
7444
|
if (!signalObservers) {
|
|
6798
7445
|
return [];
|
|
6799
7446
|
}
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
7447
|
+
const canonicalObservers = /* @__PURE__ */ new Map();
|
|
7448
|
+
for (const [rawSignalName, observer] of signalObservers.entries()) {
|
|
7449
|
+
const signalName = canonicalizeSignalName(rawSignalName);
|
|
7450
|
+
if (!signalName || isBootstrapLocalOnlySignal(signalName)) {
|
|
7451
|
+
continue;
|
|
7452
|
+
}
|
|
7453
|
+
const existing = canonicalObservers.get(signalName);
|
|
7454
|
+
canonicalObservers.set(signalName, {
|
|
7455
|
+
signalName,
|
|
7456
|
+
registered: existing?.registered === true || observer?.registered === true
|
|
7457
|
+
});
|
|
7458
|
+
}
|
|
7459
|
+
return Array.from(canonicalObservers.values());
|
|
7460
|
+
}
|
|
7461
|
+
function isLocallyHandledIntentName(intentName) {
|
|
7462
|
+
const observer = CadenzaService.inquiryBroker.inquiryObservers.get(intentName);
|
|
7463
|
+
if (!observer) {
|
|
7464
|
+
return false;
|
|
7465
|
+
}
|
|
7466
|
+
for (const task of observer.tasks) {
|
|
7467
|
+
if (task.register && !task.isHidden && !task.isDeputy) {
|
|
7468
|
+
return true;
|
|
7469
|
+
}
|
|
7470
|
+
}
|
|
7471
|
+
return false;
|
|
6804
7472
|
}
|
|
6805
7473
|
function getRegistrableIntentNames() {
|
|
6806
7474
|
return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
|
|
6807
7475
|
(intentDefinition) => intentDefinition !== null
|
|
7476
|
+
).filter(
|
|
7477
|
+
(intentDefinition) => isLocallyHandledIntentName(String(intentDefinition.name))
|
|
6808
7478
|
).map((intentDefinition) => String(intentDefinition.name));
|
|
6809
7479
|
}
|
|
7480
|
+
function isRegistrableLocalIntentDefinition(intent) {
|
|
7481
|
+
const intentData = buildIntentRegistryData(intent);
|
|
7482
|
+
if (!intentData) {
|
|
7483
|
+
return false;
|
|
7484
|
+
}
|
|
7485
|
+
return isLocallyHandledIntentName(String(intentData.name));
|
|
7486
|
+
}
|
|
6810
7487
|
function buildActorRegistrationKey(actor, serviceName) {
|
|
6811
7488
|
const data = buildActorRegistrationData(actor);
|
|
6812
7489
|
const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
|
|
@@ -6848,10 +7525,23 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6848
7525
|
this.signalsSynced = false;
|
|
6849
7526
|
this.intentsSynced = false;
|
|
6850
7527
|
this.routinesSynced = false;
|
|
7528
|
+
this.directionalTaskMapsSynced = false;
|
|
7529
|
+
this.signalTaskMapsSynced = false;
|
|
7530
|
+
this.intentTaskMapsSynced = false;
|
|
7531
|
+
this.actorTaskMapsSynced = false;
|
|
7532
|
+
this.routineTaskMapsSynced = false;
|
|
6851
7533
|
this.isCadenzaDBReady = false;
|
|
6852
7534
|
this.initialized = false;
|
|
6853
7535
|
this.initRetryScheduled = false;
|
|
6854
7536
|
this.lastMissingLocalCadenzaDBInsertTablesKey = "";
|
|
7537
|
+
this.syncCycleCounter = 0;
|
|
7538
|
+
this.primitivePhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7539
|
+
this.mapPhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7540
|
+
this.activeSyncCycleId = null;
|
|
7541
|
+
this.activeSyncCycleStartedAt = 0;
|
|
7542
|
+
this.pendingBootstrapSyncRerun = false;
|
|
7543
|
+
this.localServiceInserted = false;
|
|
7544
|
+
this.localServiceInstanceInserted = false;
|
|
6855
7545
|
}
|
|
6856
7546
|
static get instance() {
|
|
6857
7547
|
if (!this._instance) this._instance = new _GraphSyncController();
|
|
@@ -6925,45 +7615,16 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6925
7615
|
},
|
|
6926
7616
|
{ concurrency: 30 }
|
|
6927
7617
|
);
|
|
6928
|
-
const ensureIntentRegistryBeforeIntentMapTask = resolveSyncInsertTask(
|
|
6929
|
-
this.isCadenzaDBReady,
|
|
6930
|
-
"intent_registry",
|
|
6931
|
-
{
|
|
6932
|
-
onConflict: {
|
|
6933
|
-
target: ["name"],
|
|
6934
|
-
action: {
|
|
6935
|
-
do: "nothing"
|
|
6936
|
-
}
|
|
6937
|
-
}
|
|
6938
|
-
},
|
|
6939
|
-
{ concurrency: 30 }
|
|
6940
|
-
);
|
|
6941
|
-
const authoritativeTaskQueryGraph = resolveSyncQueryTask(
|
|
6942
|
-
this.isCadenzaDBReady,
|
|
6943
|
-
"task",
|
|
6944
|
-
{},
|
|
6945
|
-
{ concurrency: 10 }
|
|
6946
|
-
);
|
|
6947
|
-
const authoritativeRoutineQueryGraph = resolveSyncQueryTask(
|
|
6948
|
-
this.isCadenzaDBReady,
|
|
6949
|
-
"routine",
|
|
6950
|
-
{},
|
|
6951
|
-
{ concurrency: 10 }
|
|
6952
|
-
);
|
|
6953
|
-
const authoritativeSignalQueryGraph = resolveSyncQueryTask(
|
|
6954
|
-
this.isCadenzaDBReady,
|
|
6955
|
-
"signal_registry",
|
|
6956
|
-
{},
|
|
6957
|
-
{ concurrency: 10 }
|
|
6958
|
-
);
|
|
6959
|
-
const authoritativeIntentQueryGraph = resolveSyncQueryTask(
|
|
6960
|
-
this.isCadenzaDBReady,
|
|
6961
|
-
"intent_registry",
|
|
6962
|
-
{},
|
|
6963
|
-
{ concurrency: 10 }
|
|
6964
|
-
);
|
|
6965
7618
|
const finalizeTaskSync = (emit, ctx) => {
|
|
6966
7619
|
const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
|
|
7620
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7621
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7622
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_tasks", {
|
|
7623
|
+
serviceName: serviceName2,
|
|
7624
|
+
pendingCount: pendingTasks.length,
|
|
7625
|
+
sample: pendingTasks.slice(0, 5).map((task) => task.name)
|
|
7626
|
+
});
|
|
7627
|
+
}
|
|
6967
7628
|
if (pendingTasks.length > 0) {
|
|
6968
7629
|
this.tasksSynced = false;
|
|
6969
7630
|
return false;
|
|
@@ -6982,6 +7643,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6982
7643
|
const pendingRoutines = getRegistrableRoutines().filter(
|
|
6983
7644
|
(routine) => !routine.registered
|
|
6984
7645
|
);
|
|
7646
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7647
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7648
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_routines", {
|
|
7649
|
+
serviceName: serviceName2,
|
|
7650
|
+
pendingCount: pendingRoutines.length,
|
|
7651
|
+
sample: pendingRoutines.slice(0, 5).map((routine) => routine.name)
|
|
7652
|
+
});
|
|
7653
|
+
}
|
|
6985
7654
|
if (pendingRoutines.length > 0) {
|
|
6986
7655
|
this.routinesSynced = false;
|
|
6987
7656
|
return false;
|
|
@@ -7000,6 +7669,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7000
7669
|
const pendingSignals = getRegistrableSignalObservers().filter(
|
|
7001
7670
|
(observer) => observer.registered !== true
|
|
7002
7671
|
);
|
|
7672
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7673
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7674
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_signals", {
|
|
7675
|
+
serviceName: serviceName2,
|
|
7676
|
+
pendingCount: pendingSignals.length,
|
|
7677
|
+
sample: pendingSignals.slice(0, 5).map((observer) => observer.signalName)
|
|
7678
|
+
});
|
|
7679
|
+
}
|
|
7003
7680
|
if (pendingSignals.length > 0) {
|
|
7004
7681
|
this.signalsSynced = false;
|
|
7005
7682
|
return false;
|
|
@@ -7018,6 +7695,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7018
7695
|
const pendingIntentNames = getRegistrableIntentNames().filter(
|
|
7019
7696
|
(intentName) => !this.registeredIntentDefinitions.has(intentName)
|
|
7020
7697
|
);
|
|
7698
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7699
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
7700
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_intents", {
|
|
7701
|
+
serviceName: serviceName2,
|
|
7702
|
+
pendingCount: pendingIntentNames.length,
|
|
7703
|
+
sample: pendingIntentNames.slice(0, 5)
|
|
7704
|
+
});
|
|
7705
|
+
}
|
|
7021
7706
|
if (pendingIntentNames.length > 0) {
|
|
7022
7707
|
this.intentsSynced = false;
|
|
7023
7708
|
return false;
|
|
@@ -7039,6 +7724,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7039
7724
|
return false;
|
|
7040
7725
|
}
|
|
7041
7726
|
const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
|
|
7727
|
+
if (shouldTraceSyncPhase(syncServiceName)) {
|
|
7728
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] finalize_actors", {
|
|
7729
|
+
serviceName: syncServiceName,
|
|
7730
|
+
pendingCount: pendingActorKeys.length,
|
|
7731
|
+
sample: pendingActorKeys.slice(0, 5)
|
|
7732
|
+
});
|
|
7733
|
+
}
|
|
7042
7734
|
if (pendingActorKeys.length > 0) {
|
|
7043
7735
|
this.actorsSynced = false;
|
|
7044
7736
|
return false;
|
|
@@ -7119,8 +7811,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7119
7811
|
name: routine.name,
|
|
7120
7812
|
version: routine.version,
|
|
7121
7813
|
description: routine.description,
|
|
7122
|
-
|
|
7123
|
-
|
|
7814
|
+
service_name: serviceName2,
|
|
7815
|
+
is_meta: routine.isMeta
|
|
7124
7816
|
},
|
|
7125
7817
|
__routineName: routine.name
|
|
7126
7818
|
};
|
|
@@ -7183,11 +7875,11 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7183
7875
|
yield {
|
|
7184
7876
|
__syncing: ctx.__syncing,
|
|
7185
7877
|
data: {
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7878
|
+
task_name: nextTask.name,
|
|
7879
|
+
task_version: nextTask.version,
|
|
7880
|
+
routine_name: routine.name,
|
|
7881
|
+
routine_version: routine.version,
|
|
7882
|
+
service_name: serviceName2
|
|
7191
7883
|
},
|
|
7192
7884
|
__routineName: routine.name,
|
|
7193
7885
|
__taskName: nextTask.name
|
|
@@ -7245,12 +7937,20 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7245
7937
|
});
|
|
7246
7938
|
const { signals } = ctx;
|
|
7247
7939
|
if (!signals) return;
|
|
7248
|
-
const
|
|
7249
|
-
|
|
7940
|
+
const seenSignals = /* @__PURE__ */ new Set();
|
|
7941
|
+
const filteredSignals = signals.map((signal) => ({
|
|
7942
|
+
signalName: canonicalizeSignalName(signal.signal),
|
|
7943
|
+
data: signal.data
|
|
7944
|
+
})).filter((signal) => {
|
|
7945
|
+
if (!signal.signalName || signal.data?.registered || isBootstrapLocalOnlySignal(signal.signalName)) {
|
|
7946
|
+
return false;
|
|
7947
|
+
}
|
|
7948
|
+
if (seenSignals.has(signal.signalName)) {
|
|
7250
7949
|
return false;
|
|
7251
7950
|
}
|
|
7252
|
-
|
|
7253
|
-
|
|
7951
|
+
seenSignals.add(signal.signalName);
|
|
7952
|
+
return true;
|
|
7953
|
+
}).map((signal) => signal.signalName);
|
|
7254
7954
|
for (const signal of filteredSignals) {
|
|
7255
7955
|
const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
|
|
7256
7956
|
this.signalsSynced = false;
|
|
@@ -7258,10 +7958,10 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7258
7958
|
__syncing: ctx.__syncing,
|
|
7259
7959
|
data: {
|
|
7260
7960
|
name: signal,
|
|
7261
|
-
isGlobal,
|
|
7961
|
+
is_global: isGlobal,
|
|
7262
7962
|
domain,
|
|
7263
7963
|
action,
|
|
7264
|
-
isMeta
|
|
7964
|
+
is_meta: isMeta
|
|
7265
7965
|
},
|
|
7266
7966
|
__signal: signal
|
|
7267
7967
|
};
|
|
@@ -7283,14 +7983,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7283
7983
|
);
|
|
7284
7984
|
const processSignalRegistrationTask = CadenzaService.createMetaTask(
|
|
7285
7985
|
"Process signal registration",
|
|
7286
|
-
(ctx) => {
|
|
7287
|
-
|
|
7986
|
+
(ctx, emit) => {
|
|
7987
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
7988
|
+
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7989
|
+
if (!insertSucceeded) {
|
|
7288
7990
|
return;
|
|
7289
7991
|
}
|
|
7290
7992
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7291
7993
|
delayMs: 3e3
|
|
7292
7994
|
});
|
|
7293
|
-
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7294
7995
|
if (!signalName) {
|
|
7295
7996
|
return false;
|
|
7296
7997
|
}
|
|
@@ -7301,7 +8002,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7301
8002
|
const observer = signalObservers?.get(signalName);
|
|
7302
8003
|
if (observer) {
|
|
7303
8004
|
observer.registered = true;
|
|
8005
|
+
observer.registrationRequested = false;
|
|
7304
8006
|
}
|
|
8007
|
+
emit(
|
|
8008
|
+
"meta.sync_controller.signal_registered",
|
|
8009
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
8010
|
+
__signal: signalName
|
|
8011
|
+
})
|
|
8012
|
+
);
|
|
7305
8013
|
return { signalName };
|
|
7306
8014
|
}
|
|
7307
8015
|
).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask);
|
|
@@ -7322,6 +8030,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7322
8030
|
return;
|
|
7323
8031
|
}
|
|
7324
8032
|
for (const task of tasks) {
|
|
8033
|
+
if (task.hidden || !task.register || task.isDeputy) continue;
|
|
7325
8034
|
if (task.registered) continue;
|
|
7326
8035
|
const { __functionString, __getTagCallback } = task.export();
|
|
7327
8036
|
this.tasksSynced = false;
|
|
@@ -7331,32 +8040,33 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7331
8040
|
name: task.name,
|
|
7332
8041
|
version: task.version,
|
|
7333
8042
|
description: task.description,
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
8043
|
+
function_string: __functionString,
|
|
8044
|
+
tag_id_getter: __getTagCallback,
|
|
8045
|
+
layer_index: task.layerIndex,
|
|
7337
8046
|
concurrency: task.concurrency,
|
|
7338
8047
|
timeout: task.timeout,
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
8048
|
+
is_unique: task.isUnique,
|
|
8049
|
+
is_signal: task.isSignal,
|
|
8050
|
+
is_throttled: task.isThrottled,
|
|
8051
|
+
is_debounce: task.isDebounce,
|
|
8052
|
+
is_ephemeral: task.isEphemeral,
|
|
8053
|
+
is_meta: task.isMeta,
|
|
8054
|
+
is_sub_meta: task.isSubMeta,
|
|
8055
|
+
is_hidden: task.isHidden,
|
|
8056
|
+
validate_input_context: task.validateInputContext,
|
|
8057
|
+
validate_output_context: task.validateOutputContext,
|
|
8058
|
+
retry_count: task.retryCount,
|
|
8059
|
+
retry_delay: task.retryDelay,
|
|
8060
|
+
retry_delay_max: task.retryDelayMax,
|
|
8061
|
+
retry_delay_factor: task.retryDelayFactor,
|
|
7353
8062
|
service_name: serviceName2,
|
|
7354
8063
|
signals: {
|
|
7355
8064
|
emits: Array.from(task.emitsSignals),
|
|
7356
8065
|
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
7357
8066
|
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
7358
8067
|
observed: Array.from(task.observedSignals)
|
|
7359
|
-
}
|
|
8068
|
+
},
|
|
8069
|
+
intents: Array.from(task.handlesIntents)
|
|
7360
8070
|
},
|
|
7361
8071
|
__taskName: task.name
|
|
7362
8072
|
};
|
|
@@ -7379,17 +8089,20 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7379
8089
|
const registerTaskTask = CadenzaService.createMetaTask(
|
|
7380
8090
|
"Record registration",
|
|
7381
8091
|
(ctx, emit) => {
|
|
7382
|
-
|
|
8092
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
8093
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8094
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
8095
|
+
if (!insertSucceeded) {
|
|
7383
8096
|
return;
|
|
7384
8097
|
}
|
|
7385
8098
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7386
8099
|
delayMs: 3e3
|
|
7387
8100
|
});
|
|
7388
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7389
8101
|
if (!task) {
|
|
7390
8102
|
return true;
|
|
7391
8103
|
}
|
|
7392
8104
|
task.registered = true;
|
|
8105
|
+
task.registrationRequested = false;
|
|
7393
8106
|
emit(
|
|
7394
8107
|
"meta.sync_controller.task_registered",
|
|
7395
8108
|
buildMinimalSyncSignalContext(ctx, {
|
|
@@ -7400,24 +8113,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7400
8113
|
}
|
|
7401
8114
|
).then(gatherTaskRegistrationTask);
|
|
7402
8115
|
wireSyncTaskGraph(this.splitTasksForRegistration, registerTaskGraph, registerTaskTask);
|
|
7403
|
-
CadenzaService.createMetaTask(
|
|
7404
|
-
"Prepare created task for immediate sync",
|
|
7405
|
-
(ctx) => {
|
|
7406
|
-
const task = ctx.taskInstance ?? (ctx.data?.name ? CadenzaService.get(String(ctx.data.name)) : void 0);
|
|
7407
|
-
if (!task || task.hidden || !task.register || task.registered) {
|
|
7408
|
-
return false;
|
|
7409
|
-
}
|
|
7410
|
-
return {
|
|
7411
|
-
__syncing: true,
|
|
7412
|
-
tasks: [task]
|
|
7413
|
-
};
|
|
7414
|
-
},
|
|
7415
|
-
"Schedules newly created tasks into the graph sync registration flow without waiting for the next periodic tick.",
|
|
7416
|
-
{
|
|
7417
|
-
register: false,
|
|
7418
|
-
isHidden: true
|
|
7419
|
-
}
|
|
7420
|
-
).doOn("meta.task.created").then(this.splitTasksForRegistration);
|
|
7421
8116
|
this.splitActorsForRegistration = CadenzaService.createMetaTask(
|
|
7422
8117
|
"Split actors for registration",
|
|
7423
8118
|
function* (ctx) {
|
|
@@ -7556,13 +8251,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7556
8251
|
const registerSignalTask = CadenzaService.createMetaTask(
|
|
7557
8252
|
"Record signal registration",
|
|
7558
8253
|
(ctx) => {
|
|
8254
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
8255
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7559
8256
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7560
8257
|
return;
|
|
7561
8258
|
}
|
|
7562
8259
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7563
8260
|
delayMs: 3e3
|
|
7564
8261
|
});
|
|
7565
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7566
8262
|
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7567
8263
|
if (!task || !signalName) {
|
|
7568
8264
|
return true;
|
|
@@ -7574,7 +8270,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7574
8270
|
"Split observed signals of task",
|
|
7575
8271
|
function* (ctx) {
|
|
7576
8272
|
const task = ctx.task;
|
|
7577
|
-
if (task.hidden || !task.register || !task.registered)
|
|
8273
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
8274
|
+
return false;
|
|
7578
8275
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7579
8276
|
if (!serviceName2) {
|
|
7580
8277
|
return false;
|
|
@@ -7593,11 +8290,11 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7593
8290
|
yield {
|
|
7594
8291
|
__syncing: ctx.__syncing,
|
|
7595
8292
|
data: {
|
|
7596
|
-
|
|
7597
|
-
isGlobal,
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
8293
|
+
signal_name: _signal,
|
|
8294
|
+
is_global: isGlobal,
|
|
8295
|
+
task_name: task.name,
|
|
8296
|
+
task_version: task.version,
|
|
8297
|
+
service_name: serviceName2
|
|
7601
8298
|
},
|
|
7602
8299
|
__taskName: task.name,
|
|
7603
8300
|
__signal: signal
|
|
@@ -7638,6 +8335,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7638
8335
|
});
|
|
7639
8336
|
const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
|
|
7640
8337
|
for (const intent of intents) {
|
|
8338
|
+
if (!isRegistrableLocalIntentDefinition(intent)) {
|
|
8339
|
+
continue;
|
|
8340
|
+
}
|
|
7641
8341
|
const intentData = buildIntentRegistryData(intent);
|
|
7642
8342
|
if (!intentData) {
|
|
7643
8343
|
continue;
|
|
@@ -7656,7 +8356,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7656
8356
|
);
|
|
7657
8357
|
const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
|
|
7658
8358
|
"Record intent definition registration",
|
|
7659
|
-
(ctx) => {
|
|
8359
|
+
(ctx, emit) => {
|
|
7660
8360
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7661
8361
|
return;
|
|
7662
8362
|
}
|
|
@@ -7664,6 +8364,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7664
8364
|
delayMs: 3e3
|
|
7665
8365
|
});
|
|
7666
8366
|
this.registeredIntentDefinitions.add(ctx.__intentName);
|
|
8367
|
+
emit(
|
|
8368
|
+
"meta.sync_controller.intent_registered",
|
|
8369
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
8370
|
+
__intentName: ctx.__intentName
|
|
8371
|
+
})
|
|
8372
|
+
);
|
|
7667
8373
|
return true;
|
|
7668
8374
|
}
|
|
7669
8375
|
).then(gatherIntentRegistrationTask);
|
|
@@ -7675,13 +8381,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7675
8381
|
const registerIntentTask = CadenzaService.createMetaTask(
|
|
7676
8382
|
"Record intent registration",
|
|
7677
8383
|
(ctx) => {
|
|
8384
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7678
8385
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7679
8386
|
return;
|
|
7680
8387
|
}
|
|
7681
8388
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7682
8389
|
delayMs: 3e3
|
|
7683
8390
|
});
|
|
7684
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7685
8391
|
if (!task) {
|
|
7686
8392
|
return true;
|
|
7687
8393
|
}
|
|
@@ -7693,7 +8399,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7693
8399
|
"Split intents of task",
|
|
7694
8400
|
function* (ctx) {
|
|
7695
8401
|
const task = ctx.task;
|
|
7696
|
-
if (task.hidden || !task.register || !task.registered)
|
|
8402
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
8403
|
+
return false;
|
|
7697
8404
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7698
8405
|
if (!serviceName2) {
|
|
7699
8406
|
return false;
|
|
@@ -7728,19 +8435,19 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7728
8435
|
yield {
|
|
7729
8436
|
__syncing: ctx.__syncing,
|
|
7730
8437
|
data: {
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
8438
|
+
intent_name: intent,
|
|
8439
|
+
task_name: task.name,
|
|
8440
|
+
task_version: task.version,
|
|
8441
|
+
service_name: serviceName2
|
|
7735
8442
|
},
|
|
7736
8443
|
__taskName: task.name,
|
|
7737
8444
|
__intent: intent,
|
|
7738
8445
|
__intentDefinition: intentDefinition,
|
|
7739
8446
|
__intentMapData: {
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
8447
|
+
intent_name: intent,
|
|
8448
|
+
task_name: task.name,
|
|
8449
|
+
task_version: task.version,
|
|
8450
|
+
service_name: serviceName2
|
|
7744
8451
|
}
|
|
7745
8452
|
};
|
|
7746
8453
|
emittedCount += 1;
|
|
@@ -7748,30 +8455,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7748
8455
|
return emittedCount > 0;
|
|
7749
8456
|
}.bind(this)
|
|
7750
8457
|
);
|
|
7751
|
-
const prepareIntentDefinitionForIntentMapTask = CadenzaService.createMetaTask(
|
|
7752
|
-
"Prepare intent definition for intent-to-task map",
|
|
7753
|
-
(ctx) => {
|
|
7754
|
-
if (!ctx.__intentDefinition || !ctx.__intentMapData) {
|
|
7755
|
-
return false;
|
|
7756
|
-
}
|
|
7757
|
-
return {
|
|
7758
|
-
...ctx,
|
|
7759
|
-
data: ctx.__intentDefinition
|
|
7760
|
-
};
|
|
7761
|
-
}
|
|
7762
|
-
);
|
|
7763
|
-
const restoreIntentToTaskMapPayloadTask = CadenzaService.createMetaTask(
|
|
7764
|
-
"Restore intent-to-task map payload",
|
|
7765
|
-
(ctx) => {
|
|
7766
|
-
if (!ctx.__intentMapData) {
|
|
7767
|
-
return false;
|
|
7768
|
-
}
|
|
7769
|
-
return {
|
|
7770
|
-
...ctx,
|
|
7771
|
-
data: ctx.__intentMapData
|
|
7772
|
-
};
|
|
7773
|
-
}
|
|
7774
|
-
);
|
|
7775
8458
|
const intentToTaskMapGraph = resolveSyncInsertTask(
|
|
7776
8459
|
this.isCadenzaDBReady,
|
|
7777
8460
|
"intent_to_task_map",
|
|
@@ -7790,20 +8473,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7790
8473
|
},
|
|
7791
8474
|
{ concurrency: 30 }
|
|
7792
8475
|
);
|
|
7793
|
-
this.registerIntentToTaskMapTask.then(prepareIntentDefinitionForIntentMapTask);
|
|
7794
|
-
if (ensureIntentRegistryBeforeIntentMapTask) {
|
|
7795
|
-
wireSyncTaskGraph(
|
|
7796
|
-
prepareIntentDefinitionForIntentMapTask,
|
|
7797
|
-
ensureIntentRegistryBeforeIntentMapTask,
|
|
7798
|
-
restoreIntentToTaskMapPayloadTask
|
|
7799
|
-
);
|
|
7800
|
-
} else {
|
|
7801
|
-
prepareIntentDefinitionForIntentMapTask.then(
|
|
7802
|
-
restoreIntentToTaskMapPayloadTask
|
|
7803
|
-
);
|
|
7804
|
-
}
|
|
7805
8476
|
wireSyncTaskGraph(
|
|
7806
|
-
|
|
8477
|
+
this.registerIntentToTaskMapTask,
|
|
7807
8478
|
intentToTaskMapGraph,
|
|
7808
8479
|
registerIntentTask
|
|
7809
8480
|
);
|
|
@@ -7814,7 +8485,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7814
8485
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7815
8486
|
delayMs: 3e3
|
|
7816
8487
|
});
|
|
7817
|
-
if (task.hidden || !task.register)
|
|
8488
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered) {
|
|
8489
|
+
return;
|
|
8490
|
+
}
|
|
7818
8491
|
const predecessorServiceName = resolveSyncServiceName(task);
|
|
7819
8492
|
if (!predecessorServiceName) {
|
|
7820
8493
|
return;
|
|
@@ -7829,12 +8502,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7829
8502
|
}
|
|
7830
8503
|
yield {
|
|
7831
8504
|
data: {
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
predecessorServiceName
|
|
8505
|
+
task_name: t.name,
|
|
8506
|
+
task_version: t.version,
|
|
8507
|
+
predecessor_task_name: task.name,
|
|
8508
|
+
predecessor_task_version: task.version,
|
|
8509
|
+
service_name: serviceName2,
|
|
8510
|
+
predecessor_service_name: predecessorServiceName
|
|
7838
8511
|
},
|
|
7839
8512
|
__taskName: task.name,
|
|
7840
8513
|
__nextTaskName: t.name
|
|
@@ -7881,519 +8554,598 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7881
8554
|
taskMapRegistrationGraph,
|
|
7882
8555
|
recordTaskMapRegistrationTask
|
|
7883
8556
|
);
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
task_name: task.remoteRoutineName,
|
|
7899
|
-
task_version: 1,
|
|
7900
|
-
service_name: serviceName2,
|
|
7901
|
-
predecessor_task_name: task.name,
|
|
7902
|
-
predecessor_task_version: task.version,
|
|
7903
|
-
predecessor_service_name: predecessorServiceName
|
|
7904
|
-
},
|
|
7905
|
-
__taskName: task.name
|
|
7906
|
-
};
|
|
8557
|
+
const hasPendingDirectionalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8558
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8559
|
+
return false;
|
|
8560
|
+
}
|
|
8561
|
+
const predecessorServiceName = resolveSyncServiceName(task);
|
|
8562
|
+
if (!predecessorServiceName) {
|
|
8563
|
+
return false;
|
|
8564
|
+
}
|
|
8565
|
+
for (const nextTask of task.nextTasks) {
|
|
8566
|
+
if (task.taskMapRegistration.has(nextTask.name) || nextTask.isHidden || !nextTask.register || !nextTask.registered) {
|
|
8567
|
+
continue;
|
|
8568
|
+
}
|
|
8569
|
+
if (resolveSyncServiceName(nextTask)) {
|
|
8570
|
+
return true;
|
|
7907
8571
|
}
|
|
7908
8572
|
}
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
"task_version",
|
|
7919
|
-
"predecessor_task_version",
|
|
7920
|
-
"service_name",
|
|
7921
|
-
"predecessor_service_name"
|
|
7922
|
-
],
|
|
7923
|
-
action: {
|
|
7924
|
-
do: "nothing"
|
|
7925
|
-
}
|
|
8573
|
+
return false;
|
|
8574
|
+
});
|
|
8575
|
+
const hasPendingSignalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8576
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8577
|
+
return false;
|
|
8578
|
+
}
|
|
8579
|
+
for (const signal of task.observedSignals) {
|
|
8580
|
+
if (task.registeredSignals.has(signal)) {
|
|
8581
|
+
continue;
|
|
7926
8582
|
}
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
const recordDeputyRelationshipRegistrationTask = CadenzaService.createMetaTask(
|
|
7931
|
-
"Record deputy relationship registration",
|
|
7932
|
-
(ctx) => {
|
|
7933
|
-
if (!didSyncInsertSucceed(ctx)) {
|
|
7934
|
-
return;
|
|
8583
|
+
const signalName = signal.split(":")[0];
|
|
8584
|
+
if (!decomposeSignalName(signalName).isGlobal) {
|
|
8585
|
+
continue;
|
|
7935
8586
|
}
|
|
7936
|
-
CadenzaService.
|
|
7937
|
-
|
|
7938
|
-
});
|
|
7939
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7940
|
-
if (!task) {
|
|
7941
|
-
return true;
|
|
8587
|
+
if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
|
|
8588
|
+
continue;
|
|
7942
8589
|
}
|
|
7943
|
-
|
|
8590
|
+
return true;
|
|
7944
8591
|
}
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
8592
|
+
return false;
|
|
8593
|
+
});
|
|
8594
|
+
const hasPendingIntentTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8595
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8596
|
+
return false;
|
|
8597
|
+
}
|
|
8598
|
+
const registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
|
|
8599
|
+
for (const intent of task.handlesIntents) {
|
|
8600
|
+
if (registeredIntents.has(intent) || isLocalOnlySyncIntent(intent)) {
|
|
8601
|
+
continue;
|
|
8602
|
+
}
|
|
8603
|
+
if (isMetaIntentName(intent) && !task.isMeta) {
|
|
8604
|
+
continue;
|
|
8605
|
+
}
|
|
8606
|
+
const intentDefinition = buildIntentRegistryData(CadenzaService.inquiryBroker.intents.get(intent)) ?? buildIntentRegistryData({ name: intent });
|
|
8607
|
+
if (!intentDefinition) {
|
|
8608
|
+
continue;
|
|
8609
|
+
}
|
|
8610
|
+
return true;
|
|
8611
|
+
}
|
|
8612
|
+
return false;
|
|
8613
|
+
});
|
|
8614
|
+
const hasPendingActorTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8615
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8616
|
+
return false;
|
|
8617
|
+
}
|
|
8618
|
+
const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
|
|
8619
|
+
if (!metadata?.actorName) {
|
|
8620
|
+
return false;
|
|
8621
|
+
}
|
|
8622
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8623
|
+
if (!serviceName2) {
|
|
8624
|
+
return false;
|
|
8625
|
+
}
|
|
8626
|
+
const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
|
|
8627
|
+
return !this.registeredActorTaskMaps.has(registrationKey);
|
|
8628
|
+
});
|
|
8629
|
+
const hasPendingRoutineTaskMaps = () => getRegistrableRoutines().some((routine) => {
|
|
8630
|
+
if (!routine.registered) {
|
|
8631
|
+
return false;
|
|
8632
|
+
}
|
|
8633
|
+
for (const task of routine.tasks) {
|
|
8634
|
+
if (!task) {
|
|
8635
|
+
continue;
|
|
8636
|
+
}
|
|
8637
|
+
const tasks = task.getIterator();
|
|
8638
|
+
while (tasks.hasNext()) {
|
|
8639
|
+
const nextTask = tasks.next();
|
|
8640
|
+
if (!nextTask?.registered) {
|
|
7959
8641
|
continue;
|
|
7960
8642
|
}
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
continue;
|
|
8643
|
+
if (!routine.registeredTasks.has(nextTask.name)) {
|
|
8644
|
+
return true;
|
|
7964
8645
|
}
|
|
7965
|
-
task.registered = true;
|
|
7966
|
-
changed = true;
|
|
7967
|
-
emit("meta.sync_controller.task_registered", {
|
|
7968
|
-
...ctx,
|
|
7969
|
-
__taskName: task.name,
|
|
7970
|
-
task,
|
|
7971
|
-
__authoritativeReconciliation: true
|
|
7972
|
-
});
|
|
7973
8646
|
}
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
8647
|
+
}
|
|
8648
|
+
return false;
|
|
8649
|
+
});
|
|
8650
|
+
const gatherDirectionalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8651
|
+
"Gather directional task map registration",
|
|
8652
|
+
(ctx) => {
|
|
8653
|
+
if (hasPendingDirectionalTaskMaps()) {
|
|
8654
|
+
this.directionalTaskMapsSynced = false;
|
|
8655
|
+
return false;
|
|
7979
8656
|
}
|
|
7980
|
-
|
|
8657
|
+
this.directionalTaskMapsSynced = true;
|
|
8658
|
+
return ctx;
|
|
7981
8659
|
},
|
|
7982
|
-
"
|
|
8660
|
+
"Completes directional task graph registration when task edges and deputy edges are registered.",
|
|
7983
8661
|
{
|
|
7984
8662
|
register: false,
|
|
7985
8663
|
isHidden: true
|
|
7986
8664
|
}
|
|
7987
8665
|
);
|
|
7988
|
-
const
|
|
7989
|
-
"
|
|
7990
|
-
(ctx
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
const routineName = typeof row.name === "string" ? row.name : "";
|
|
7995
|
-
if (!routineName) {
|
|
7996
|
-
continue;
|
|
7997
|
-
}
|
|
7998
|
-
const routine = CadenzaService.getRoutine(routineName);
|
|
7999
|
-
if (!routine || routine.registered) {
|
|
8000
|
-
continue;
|
|
8001
|
-
}
|
|
8002
|
-
routine.registered = true;
|
|
8003
|
-
changed = true;
|
|
8666
|
+
const gatherSignalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8667
|
+
"Gather signal task map registration",
|
|
8668
|
+
(ctx) => {
|
|
8669
|
+
if (hasPendingSignalTaskMaps()) {
|
|
8670
|
+
this.signalTaskMapsSynced = false;
|
|
8671
|
+
return false;
|
|
8004
8672
|
}
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8673
|
+
this.signalTaskMapsSynced = true;
|
|
8674
|
+
return ctx;
|
|
8675
|
+
},
|
|
8676
|
+
"Completes signal-to-task map registration when all global observed signal edges are registered.",
|
|
8677
|
+
{
|
|
8678
|
+
register: false,
|
|
8679
|
+
isHidden: true
|
|
8680
|
+
}
|
|
8681
|
+
);
|
|
8682
|
+
const gatherIntentTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8683
|
+
"Gather intent task map registration",
|
|
8684
|
+
(ctx) => {
|
|
8685
|
+
if (hasPendingIntentTaskMaps()) {
|
|
8686
|
+
this.intentTaskMapsSynced = false;
|
|
8687
|
+
return false;
|
|
8010
8688
|
}
|
|
8011
|
-
|
|
8689
|
+
this.intentTaskMapsSynced = true;
|
|
8690
|
+
return ctx;
|
|
8012
8691
|
},
|
|
8013
|
-
"
|
|
8692
|
+
"Completes intent-to-task map registration when all task responders are registered.",
|
|
8014
8693
|
{
|
|
8015
8694
|
register: false,
|
|
8016
8695
|
isHidden: true
|
|
8017
8696
|
}
|
|
8018
8697
|
);
|
|
8019
|
-
const
|
|
8020
|
-
"
|
|
8021
|
-
(ctx
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
for (const row of authoritativeSignals) {
|
|
8026
|
-
const signalName = typeof row.name === "string" ? row.name : "";
|
|
8027
|
-
if (!signalName) {
|
|
8028
|
-
continue;
|
|
8029
|
-
}
|
|
8030
|
-
const observer = signalObservers?.get(signalName);
|
|
8031
|
-
if (!observer || observer.registered) {
|
|
8032
|
-
continue;
|
|
8033
|
-
}
|
|
8034
|
-
observer.registered = true;
|
|
8035
|
-
changed = true;
|
|
8698
|
+
const gatherActorTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8699
|
+
"Gather actor task map registration",
|
|
8700
|
+
(ctx) => {
|
|
8701
|
+
if (hasPendingActorTaskMaps()) {
|
|
8702
|
+
this.actorTaskMapsSynced = false;
|
|
8703
|
+
return false;
|
|
8036
8704
|
}
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8705
|
+
this.actorTaskMapsSynced = true;
|
|
8706
|
+
return ctx;
|
|
8707
|
+
},
|
|
8708
|
+
"Completes actor-to-task map registration when all actor-backed tasks are registered.",
|
|
8709
|
+
{
|
|
8710
|
+
register: false,
|
|
8711
|
+
isHidden: true
|
|
8712
|
+
}
|
|
8713
|
+
);
|
|
8714
|
+
const gatherRoutineTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8715
|
+
"Gather routine task map registration",
|
|
8716
|
+
(ctx) => {
|
|
8717
|
+
if (hasPendingRoutineTaskMaps()) {
|
|
8718
|
+
this.routineTaskMapsSynced = false;
|
|
8719
|
+
return false;
|
|
8042
8720
|
}
|
|
8043
|
-
|
|
8721
|
+
this.routineTaskMapsSynced = true;
|
|
8722
|
+
return ctx;
|
|
8044
8723
|
},
|
|
8045
|
-
"
|
|
8724
|
+
"Completes task-to-routine map registration when all routine task memberships are registered.",
|
|
8046
8725
|
{
|
|
8047
8726
|
register: false,
|
|
8048
8727
|
isHidden: true
|
|
8049
8728
|
}
|
|
8050
8729
|
);
|
|
8051
|
-
const
|
|
8052
|
-
"
|
|
8730
|
+
const finishSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8731
|
+
"Finish sync",
|
|
8053
8732
|
(ctx, emit) => {
|
|
8054
|
-
const
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8733
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8734
|
+
if (syncCycleId && this.activeSyncCycleId === syncCycleId) {
|
|
8735
|
+
this.activeSyncCycleId = null;
|
|
8736
|
+
this.activeSyncCycleStartedAt = 0;
|
|
8737
|
+
}
|
|
8738
|
+
if (this.pendingBootstrapSyncRerun) {
|
|
8739
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8740
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
8741
|
+
delayMs: 100
|
|
8742
|
+
});
|
|
8743
|
+
}
|
|
8744
|
+
emit("global.meta.sync_controller.synced", {
|
|
8745
|
+
data: {
|
|
8746
|
+
is_active: true,
|
|
8747
|
+
is_non_responsive: false,
|
|
8748
|
+
is_blocked: false,
|
|
8749
|
+
last_active: formatTimestamp(Date.now())
|
|
8750
|
+
},
|
|
8751
|
+
filter: {
|
|
8752
|
+
uuid: CadenzaService.serviceRegistry.serviceInstanceId
|
|
8063
8753
|
}
|
|
8064
|
-
|
|
8065
|
-
|
|
8754
|
+
});
|
|
8755
|
+
return true;
|
|
8756
|
+
},
|
|
8757
|
+
"Marks the current bootstrap sync cycle as complete.",
|
|
8758
|
+
{
|
|
8759
|
+
register: false,
|
|
8760
|
+
isHidden: true
|
|
8761
|
+
}
|
|
8762
|
+
).attachSignal("global.meta.sync_controller.synced");
|
|
8763
|
+
const mapPhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8764
|
+
"Complete map sync phase",
|
|
8765
|
+
(ctx) => {
|
|
8766
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8767
|
+
if (!syncCycleId) {
|
|
8768
|
+
return false;
|
|
8066
8769
|
}
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8770
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8771
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
8772
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] map_barrier_check", {
|
|
8773
|
+
serviceName: serviceName2,
|
|
8774
|
+
syncCycleId,
|
|
8775
|
+
directionalTaskMapsSynced: this.directionalTaskMapsSynced,
|
|
8776
|
+
signalTaskMapsSynced: this.signalTaskMapsSynced,
|
|
8777
|
+
intentTaskMapsSynced: this.intentTaskMapsSynced,
|
|
8778
|
+
actorTaskMapsSynced: this.actorTaskMapsSynced,
|
|
8779
|
+
routineTaskMapsSynced: this.routineTaskMapsSynced
|
|
8071
8780
|
});
|
|
8072
8781
|
}
|
|
8073
|
-
|
|
8782
|
+
if (!this.directionalTaskMapsSynced || !this.signalTaskMapsSynced || !this.intentTaskMapsSynced || !this.actorTaskMapsSynced || !this.routineTaskMapsSynced) {
|
|
8783
|
+
return false;
|
|
8784
|
+
}
|
|
8785
|
+
if (!markCompletedSyncCycle(this.mapPhaseCompletedCycles, syncCycleId)) {
|
|
8786
|
+
return false;
|
|
8787
|
+
}
|
|
8788
|
+
return ctx;
|
|
8074
8789
|
},
|
|
8075
|
-
"
|
|
8790
|
+
"Fans in map branch completion and ends the current sync cycle once every map branch is complete.",
|
|
8791
|
+
{
|
|
8792
|
+
register: false,
|
|
8793
|
+
isHidden: true
|
|
8794
|
+
}
|
|
8795
|
+
).then(finishSyncTask);
|
|
8796
|
+
const startDirectionalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8797
|
+
"Start directional task map sync",
|
|
8798
|
+
(ctx) => ctx,
|
|
8799
|
+
"Starts the directional task graph map branch for the current sync cycle.",
|
|
8076
8800
|
{
|
|
8077
8801
|
register: false,
|
|
8078
8802
|
isHidden: true
|
|
8079
8803
|
}
|
|
8080
8804
|
);
|
|
8081
|
-
const
|
|
8082
|
-
"
|
|
8083
|
-
() =>
|
|
8084
|
-
"
|
|
8805
|
+
const startSignalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8806
|
+
"Start signal task map sync",
|
|
8807
|
+
(ctx) => ctx,
|
|
8808
|
+
"Starts the signal-to-task map branch for the current sync cycle.",
|
|
8085
8809
|
{
|
|
8086
8810
|
register: false,
|
|
8087
8811
|
isHidden: true
|
|
8088
8812
|
}
|
|
8089
8813
|
);
|
|
8090
|
-
const
|
|
8091
|
-
"
|
|
8092
|
-
() =>
|
|
8093
|
-
"
|
|
8814
|
+
const startIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8815
|
+
"Start intent task map sync",
|
|
8816
|
+
(ctx) => ctx,
|
|
8817
|
+
"Starts the intent-to-task map branch for the current sync cycle.",
|
|
8094
8818
|
{
|
|
8095
8819
|
register: false,
|
|
8096
8820
|
isHidden: true
|
|
8097
8821
|
}
|
|
8098
8822
|
);
|
|
8099
|
-
const
|
|
8100
|
-
"
|
|
8101
|
-
() =>
|
|
8102
|
-
"
|
|
8823
|
+
const startActorTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8824
|
+
"Start actor task map sync",
|
|
8825
|
+
(ctx) => ctx,
|
|
8826
|
+
"Starts the actor-to-task map branch for the current sync cycle.",
|
|
8103
8827
|
{
|
|
8104
8828
|
register: false,
|
|
8105
8829
|
isHidden: true
|
|
8106
8830
|
}
|
|
8107
8831
|
);
|
|
8108
|
-
const
|
|
8109
|
-
"
|
|
8110
|
-
() =>
|
|
8111
|
-
"
|
|
8832
|
+
const startRoutineTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8833
|
+
"Start routine task map sync",
|
|
8834
|
+
(ctx) => ctx,
|
|
8835
|
+
"Starts the task-to-routine map branch for the current sync cycle.",
|
|
8112
8836
|
{
|
|
8113
8837
|
register: false,
|
|
8114
8838
|
isHidden: true
|
|
8115
8839
|
}
|
|
8116
8840
|
);
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
reconcileTaskRegistrationFromAuthorityTask
|
|
8120
|
-
);
|
|
8121
|
-
}
|
|
8122
|
-
if (authoritativeRoutineQueryGraph) {
|
|
8123
|
-
authoritativeRoutineQueryGraph.completionTask.then(
|
|
8124
|
-
reconcileRoutineRegistrationFromAuthorityTask
|
|
8125
|
-
);
|
|
8126
|
-
}
|
|
8127
|
-
if (authoritativeSignalQueryGraph) {
|
|
8128
|
-
authoritativeSignalQueryGraph.completionTask.then(
|
|
8129
|
-
reconcileSignalRegistrationFromAuthorityTask
|
|
8130
|
-
);
|
|
8131
|
-
}
|
|
8132
|
-
if (authoritativeIntentQueryGraph) {
|
|
8133
|
-
authoritativeIntentQueryGraph.completionTask.then(
|
|
8134
|
-
reconcileIntentRegistrationFromAuthorityTask
|
|
8135
|
-
);
|
|
8136
|
-
}
|
|
8137
|
-
const authoritativeRegistrationTriggers = [
|
|
8138
|
-
"meta.service_registry.initial_sync_complete",
|
|
8139
|
-
"meta.sync_requested",
|
|
8140
|
-
"meta.sync_controller.synced_resource",
|
|
8141
|
-
"meta.sync_controller.authority_registration_reconciliation_requested"
|
|
8142
|
-
];
|
|
8143
|
-
CadenzaService.createMetaTask(
|
|
8144
|
-
"Prepare authoritative task registration query",
|
|
8841
|
+
const primitivePhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8842
|
+
"Complete primitive sync phase",
|
|
8145
8843
|
(ctx) => {
|
|
8146
|
-
|
|
8844
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8845
|
+
if (!syncCycleId) {
|
|
8147
8846
|
return false;
|
|
8148
8847
|
}
|
|
8149
|
-
const serviceName2 = resolveSyncServiceName();
|
|
8150
|
-
if (
|
|
8848
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8849
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
8850
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] primitive_barrier_check", {
|
|
8851
|
+
serviceName: serviceName2,
|
|
8852
|
+
syncCycleId,
|
|
8853
|
+
tasksSynced: this.tasksSynced,
|
|
8854
|
+
signalsSynced: this.signalsSynced,
|
|
8855
|
+
intentsSynced: this.intentsSynced,
|
|
8856
|
+
actorsSynced: this.actorsSynced,
|
|
8857
|
+
routinesSynced: this.routinesSynced
|
|
8858
|
+
});
|
|
8859
|
+
}
|
|
8860
|
+
if (!this.tasksSynced || !this.signalsSynced || !this.intentsSynced || !this.actorsSynced || !this.routinesSynced) {
|
|
8151
8861
|
return false;
|
|
8152
8862
|
}
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
};
|
|
8863
|
+
if (!markCompletedSyncCycle(this.primitivePhaseCompletedCycles, syncCycleId)) {
|
|
8864
|
+
return false;
|
|
8865
|
+
}
|
|
8866
|
+
this.directionalTaskMapsSynced = false;
|
|
8867
|
+
this.signalTaskMapsSynced = false;
|
|
8868
|
+
this.intentTaskMapsSynced = false;
|
|
8869
|
+
this.actorTaskMapsSynced = false;
|
|
8870
|
+
this.routineTaskMapsSynced = false;
|
|
8871
|
+
return ctx;
|
|
8163
8872
|
},
|
|
8164
|
-
"
|
|
8873
|
+
"Fans in primitive registration and opens the map registration phase once every primitive branch is complete.",
|
|
8165
8874
|
{
|
|
8166
8875
|
register: false,
|
|
8167
8876
|
isHidden: true
|
|
8168
8877
|
}
|
|
8169
|
-
).
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8878
|
+
).then(
|
|
8879
|
+
startDirectionalTaskMapSyncTask,
|
|
8880
|
+
startSignalTaskMapSyncTask,
|
|
8881
|
+
startIntentTaskMapSyncTask,
|
|
8882
|
+
startActorTaskMapSyncTask,
|
|
8883
|
+
startRoutineTaskMapSyncTask
|
|
8884
|
+
);
|
|
8885
|
+
gatherTaskRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8886
|
+
gatherSignalRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8887
|
+
gatherIntentRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8888
|
+
gatherActorRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8889
|
+
gatherRoutineRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8890
|
+
const markLocalServiceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8891
|
+
"Mark local service inserted for bootstrap sync",
|
|
8174
8892
|
(ctx) => {
|
|
8175
|
-
if (!this.isCadenzaDBReady) {
|
|
8176
|
-
return false;
|
|
8177
|
-
}
|
|
8178
8893
|
const serviceName2 = resolveSyncServiceName();
|
|
8179
|
-
|
|
8894
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8895
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8180
8896
|
return false;
|
|
8181
8897
|
}
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
__syncServiceName: serviceName2,
|
|
8185
|
-
queryData: {
|
|
8186
|
-
filter: {
|
|
8187
|
-
service_name: serviceName2
|
|
8188
|
-
},
|
|
8189
|
-
fields: ["name", "version", "service_name"]
|
|
8190
|
-
}
|
|
8191
|
-
};
|
|
8898
|
+
this.localServiceInserted = true;
|
|
8899
|
+
return true;
|
|
8192
8900
|
},
|
|
8193
|
-
"
|
|
8901
|
+
"Marks that the local service row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8194
8902
|
{
|
|
8195
8903
|
register: false,
|
|
8196
8904
|
isHidden: true
|
|
8197
8905
|
}
|
|
8198
|
-
).doOn(
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
CadenzaService.createMetaTask(
|
|
8202
|
-
"Prepare authoritative signal registration query",
|
|
8906
|
+
).doOn("meta.service_registry.service_inserted");
|
|
8907
|
+
const markLocalServiceInstanceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8908
|
+
"Mark local service instance inserted for bootstrap sync",
|
|
8203
8909
|
(ctx) => {
|
|
8204
|
-
|
|
8910
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8911
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8912
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8205
8913
|
return false;
|
|
8206
8914
|
}
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
queryData: {
|
|
8210
|
-
fields: ["name"]
|
|
8211
|
-
}
|
|
8212
|
-
};
|
|
8915
|
+
this.localServiceInstanceInserted = true;
|
|
8916
|
+
return true;
|
|
8213
8917
|
},
|
|
8214
|
-
"
|
|
8918
|
+
"Marks that the local service instance row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8215
8919
|
{
|
|
8216
8920
|
register: false,
|
|
8217
8921
|
isHidden: true
|
|
8218
8922
|
}
|
|
8219
|
-
).doOn(
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
CadenzaService.createMetaTask(
|
|
8223
|
-
"Prepare authoritative intent registration query",
|
|
8923
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8924
|
+
const startBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8925
|
+
"Start bootstrap graph sync",
|
|
8224
8926
|
(ctx) => {
|
|
8225
|
-
|
|
8927
|
+
const now = Date.now();
|
|
8928
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8929
|
+
const serviceInstanceId = CadenzaService.serviceRegistry.serviceInstanceId;
|
|
8930
|
+
if (!serviceName2 || !serviceInstanceId) {
|
|
8931
|
+
return false;
|
|
8932
|
+
}
|
|
8933
|
+
if (!this.localServiceInserted) {
|
|
8934
|
+
return false;
|
|
8935
|
+
}
|
|
8936
|
+
if (!this.localServiceInstanceInserted) {
|
|
8937
|
+
return false;
|
|
8938
|
+
}
|
|
8939
|
+
if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
|
|
8226
8940
|
return false;
|
|
8227
8941
|
}
|
|
8942
|
+
if (this.activeSyncCycleId) {
|
|
8943
|
+
const activeCycleAgeMs = now - this.activeSyncCycleStartedAt;
|
|
8944
|
+
if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
|
|
8945
|
+
this.pendingBootstrapSyncRerun = true;
|
|
8946
|
+
return false;
|
|
8947
|
+
}
|
|
8948
|
+
}
|
|
8949
|
+
const syncCycleId = `${now}-${++this.syncCycleCounter}`;
|
|
8950
|
+
this.activeSyncCycleId = syncCycleId;
|
|
8951
|
+
this.activeSyncCycleStartedAt = now;
|
|
8952
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8953
|
+
this.tasksSynced = false;
|
|
8954
|
+
this.signalsSynced = false;
|
|
8955
|
+
this.intentsSynced = false;
|
|
8956
|
+
this.actorsSynced = false;
|
|
8957
|
+
this.routinesSynced = false;
|
|
8228
8958
|
return {
|
|
8229
8959
|
...ctx,
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8960
|
+
__syncing: true,
|
|
8961
|
+
__syncCycleId: syncCycleId,
|
|
8962
|
+
__serviceName: serviceName2,
|
|
8963
|
+
__serviceInstanceId: serviceInstanceId
|
|
8233
8964
|
};
|
|
8234
8965
|
},
|
|
8235
|
-
"
|
|
8966
|
+
"Starts a deterministic bootstrap sync cycle once the local service instance exists.",
|
|
8236
8967
|
{
|
|
8237
8968
|
register: false,
|
|
8238
8969
|
isHidden: true
|
|
8239
8970
|
}
|
|
8240
|
-
).doOn(
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
CadenzaService.signalBroker.getSignalsTask.clone().doOn(
|
|
8244
|
-
"meta.sync_controller.sync_tick",
|
|
8245
|
-
"meta.service_registry.initial_sync_complete",
|
|
8246
|
-
"meta.sync_requested"
|
|
8247
|
-
).then(this.splitSignalsTask);
|
|
8248
|
-
CadenzaService.registry.getAllTasks.clone().doOn(
|
|
8249
|
-
"meta.sync_controller.sync_tick",
|
|
8250
|
-
"meta.sync_controller.synced_signals",
|
|
8251
|
-
"meta.sync_requested"
|
|
8252
|
-
).then(this.splitTasksForRegistration);
|
|
8253
|
-
CadenzaService.createMetaTask("Get all intents", (ctx) => {
|
|
8254
|
-
return {
|
|
8255
|
-
...ctx,
|
|
8256
|
-
intents: Array.from(CadenzaService.inquiryBroker.intents.values())
|
|
8257
|
-
};
|
|
8258
|
-
}).doOn(
|
|
8259
|
-
"meta.sync_controller.sync_tick",
|
|
8260
|
-
"meta.service_registry.initial_sync_complete",
|
|
8261
|
-
"meta.sync_requested"
|
|
8262
|
-
).then(this.splitIntentsTask);
|
|
8263
|
-
CadenzaService.registry.getAllRoutines.clone().doOn(
|
|
8264
|
-
"meta.sync_controller.sync_tick",
|
|
8265
|
-
"meta.service_registry.initial_sync_complete",
|
|
8266
|
-
"meta.sync_requested"
|
|
8267
|
-
).then(this.splitRoutinesTask);
|
|
8268
|
-
CadenzaService.createMetaTask("Get all actors", (ctx) => {
|
|
8269
|
-
return {
|
|
8270
|
-
...ctx,
|
|
8271
|
-
actors: CadenzaService.getAllActors()
|
|
8272
|
-
};
|
|
8273
|
-
}).doOn(
|
|
8971
|
+
).doOn(
|
|
8972
|
+
"meta.service_registry.service_inserted",
|
|
8973
|
+
"meta.service_registry.instance_inserted",
|
|
8274
8974
|
"meta.sync_controller.sync_tick",
|
|
8275
|
-
"meta.service_registry.initial_sync_complete",
|
|
8276
8975
|
"meta.sync_requested"
|
|
8277
|
-
)
|
|
8278
|
-
CadenzaService.createMetaTask(
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8976
|
+
);
|
|
8977
|
+
const startTaskPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8978
|
+
"Start task primitive sync",
|
|
8979
|
+
(ctx) => ctx,
|
|
8980
|
+
"Starts the task registration branch for the current sync cycle.",
|
|
8981
|
+
{
|
|
8982
|
+
register: false,
|
|
8983
|
+
isHidden: true
|
|
8282
8984
|
}
|
|
8283
|
-
return {
|
|
8284
|
-
...ctx,
|
|
8285
|
-
task
|
|
8286
|
-
};
|
|
8287
|
-
}).doOn("meta.sync_controller.task_registered").then(
|
|
8288
|
-
this.registerTaskMapTask,
|
|
8289
|
-
this.registerDeputyRelationshipTask
|
|
8290
8985
|
);
|
|
8291
|
-
CadenzaService.
|
|
8292
|
-
"
|
|
8293
|
-
|
|
8294
|
-
"
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
if (!task) {
|
|
8299
|
-
return false;
|
|
8986
|
+
const startSignalPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8987
|
+
"Start signal primitive sync",
|
|
8988
|
+
(ctx) => ctx,
|
|
8989
|
+
"Starts the signal registration branch for the current sync cycle.",
|
|
8990
|
+
{
|
|
8991
|
+
register: false,
|
|
8992
|
+
isHidden: true
|
|
8300
8993
|
}
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
"meta.sync_requested"
|
|
8310
|
-
).then(this.registerIntentToTaskMapTask);
|
|
8311
|
-
CadenzaService.createMetaTask("Get registered task for intent sync", (ctx) => {
|
|
8312
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8313
|
-
if (!task) {
|
|
8314
|
-
return false;
|
|
8994
|
+
);
|
|
8995
|
+
const startIntentPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8996
|
+
"Start intent primitive sync",
|
|
8997
|
+
(ctx) => ctx,
|
|
8998
|
+
"Starts the intent registration branch for the current sync cycle.",
|
|
8999
|
+
{
|
|
9000
|
+
register: false,
|
|
9001
|
+
isHidden: true
|
|
8315
9002
|
}
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
"meta.sync_requested"
|
|
8325
|
-
).then(this.registerActorTaskMapTask);
|
|
8326
|
-
CadenzaService.createMetaTask("Get registered task for actor sync", (ctx) => {
|
|
8327
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8328
|
-
if (!task) {
|
|
8329
|
-
return false;
|
|
9003
|
+
);
|
|
9004
|
+
const startActorPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9005
|
+
"Start actor primitive sync",
|
|
9006
|
+
(ctx) => ctx,
|
|
9007
|
+
"Starts the actor registration branch for the current sync cycle.",
|
|
9008
|
+
{
|
|
9009
|
+
register: false,
|
|
9010
|
+
isHidden: true
|
|
8330
9011
|
}
|
|
8331
|
-
|
|
9012
|
+
);
|
|
9013
|
+
const startRoutinePrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
9014
|
+
"Start routine primitive sync",
|
|
9015
|
+
(ctx) => ctx,
|
|
9016
|
+
"Starts the routine registration branch for the current sync cycle.",
|
|
9017
|
+
{
|
|
9018
|
+
register: false,
|
|
9019
|
+
isHidden: true
|
|
9020
|
+
}
|
|
9021
|
+
);
|
|
9022
|
+
startBootstrapSyncTask.then(
|
|
9023
|
+
startTaskPrimitiveSyncTask,
|
|
9024
|
+
startSignalPrimitiveSyncTask,
|
|
9025
|
+
startIntentPrimitiveSyncTask,
|
|
9026
|
+
startActorPrimitiveSyncTask,
|
|
9027
|
+
startRoutinePrimitiveSyncTask
|
|
9028
|
+
);
|
|
9029
|
+
const getAllTasksForSyncTask = CadenzaService.registry.getAllTasks.clone();
|
|
9030
|
+
startTaskPrimitiveSyncTask.then(
|
|
9031
|
+
getAllTasksForSyncTask,
|
|
9032
|
+
gatherTaskRegistrationTask
|
|
9033
|
+
);
|
|
9034
|
+
getAllTasksForSyncTask.then(this.splitTasksForRegistration);
|
|
9035
|
+
const getSignalsForSyncTask = CadenzaService.signalBroker.getSignalsTask.clone();
|
|
9036
|
+
startSignalPrimitiveSyncTask.then(
|
|
9037
|
+
getSignalsForSyncTask,
|
|
9038
|
+
gatherSignalRegistrationTask
|
|
9039
|
+
);
|
|
9040
|
+
getSignalsForSyncTask.then(this.splitSignalsTask);
|
|
9041
|
+
const getAllIntentsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
9042
|
+
"Get all intents for sync",
|
|
9043
|
+
(ctx) => ({
|
|
8332
9044
|
...ctx,
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
return ctx;
|
|
8343
|
-
}
|
|
8344
|
-
).then(this.registerActorTaskMapTask)
|
|
9045
|
+
intents: Array.from(CadenzaService.inquiryBroker.intents.values()).filter(
|
|
9046
|
+
(intent) => isRegistrableLocalIntentDefinition(intent)
|
|
9047
|
+
)
|
|
9048
|
+
}),
|
|
9049
|
+
"Collects local intents for the primitive sync phase.",
|
|
9050
|
+
{
|
|
9051
|
+
register: false,
|
|
9052
|
+
isHidden: true
|
|
9053
|
+
}
|
|
8345
9054
|
);
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
"meta.sync_requested"
|
|
8350
|
-
).then(
|
|
8351
|
-
CadenzaService.createMetaTask(
|
|
8352
|
-
"Ensure routine and task sync ready",
|
|
8353
|
-
(ctx) => {
|
|
8354
|
-
if (!this.tasksSynced || !this.routinesSynced) {
|
|
8355
|
-
return false;
|
|
8356
|
-
}
|
|
8357
|
-
return ctx;
|
|
8358
|
-
}
|
|
8359
|
-
).then(this.splitTasksInRoutines)
|
|
9055
|
+
startIntentPrimitiveSyncTask.then(
|
|
9056
|
+
getAllIntentsForSyncTask,
|
|
9057
|
+
gatherIntentRegistrationTask
|
|
8360
9058
|
);
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
9059
|
+
getAllIntentsForSyncTask.then(this.splitIntentsTask);
|
|
9060
|
+
const getAllActorsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
9061
|
+
"Get all actors for sync",
|
|
9062
|
+
(ctx) => ({
|
|
9063
|
+
...ctx,
|
|
9064
|
+
actors: CadenzaService.getAllActors()
|
|
9065
|
+
}),
|
|
9066
|
+
"Collects local actors for the primitive sync phase.",
|
|
9067
|
+
{
|
|
9068
|
+
register: false,
|
|
9069
|
+
isHidden: true
|
|
9070
|
+
}
|
|
9071
|
+
);
|
|
9072
|
+
startActorPrimitiveSyncTask.then(
|
|
9073
|
+
getAllActorsForSyncTask,
|
|
9074
|
+
gatherActorRegistrationTask
|
|
9075
|
+
);
|
|
9076
|
+
getAllActorsForSyncTask.then(this.splitActorsForRegistration);
|
|
9077
|
+
const getAllRoutinesForSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
9078
|
+
startRoutinePrimitiveSyncTask.then(
|
|
9079
|
+
getAllRoutinesForSyncTask,
|
|
9080
|
+
gatherRoutineRegistrationTask
|
|
9081
|
+
);
|
|
9082
|
+
getAllRoutinesForSyncTask.then(this.splitRoutinesTask);
|
|
9083
|
+
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9084
|
+
startDirectionalTaskMapSyncTask.then(
|
|
9085
|
+
iterateTasksForDirectionalTaskMapSyncTask,
|
|
9086
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
9087
|
+
);
|
|
9088
|
+
iterateTasksForDirectionalTaskMapSyncTask.then(this.registerTaskMapTask);
|
|
9089
|
+
recordTaskMapRegistrationTask.then(gatherDirectionalTaskMapRegistrationTask);
|
|
9090
|
+
gatherDirectionalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9091
|
+
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9092
|
+
startSignalTaskMapSyncTask.then(
|
|
9093
|
+
iterateTasksForSignalTaskMapSyncTask,
|
|
9094
|
+
gatherSignalTaskMapRegistrationTask
|
|
9095
|
+
);
|
|
9096
|
+
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
9097
|
+
registerSignalTask.then(gatherSignalTaskMapRegistrationTask);
|
|
9098
|
+
gatherSignalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9099
|
+
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9100
|
+
startIntentTaskMapSyncTask.then(
|
|
9101
|
+
iterateTasksForIntentTaskMapSyncTask,
|
|
9102
|
+
gatherIntentTaskMapRegistrationTask
|
|
9103
|
+
);
|
|
9104
|
+
iterateTasksForIntentTaskMapSyncTask.then(this.registerIntentToTaskMapTask);
|
|
9105
|
+
registerIntentTask.then(gatherIntentTaskMapRegistrationTask);
|
|
9106
|
+
gatherIntentTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9107
|
+
const iterateTasksForActorTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
9108
|
+
startActorTaskMapSyncTask.then(
|
|
9109
|
+
iterateTasksForActorTaskMapSyncTask,
|
|
9110
|
+
gatherActorTaskMapRegistrationTask
|
|
9111
|
+
);
|
|
9112
|
+
iterateTasksForActorTaskMapSyncTask.then(this.registerActorTaskMapTask);
|
|
9113
|
+
recordActorTaskMapRegistrationTask.then(gatherActorTaskMapRegistrationTask);
|
|
9114
|
+
gatherActorTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9115
|
+
const getAllRoutinesForTaskMapSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
9116
|
+
startRoutineTaskMapSyncTask.then(
|
|
9117
|
+
getAllRoutinesForTaskMapSyncTask,
|
|
9118
|
+
gatherRoutineTaskMapRegistrationTask
|
|
9119
|
+
);
|
|
9120
|
+
getAllRoutinesForTaskMapSyncTask.then(this.splitTasksInRoutines);
|
|
9121
|
+
registerTaskToRoutineMapTask.then(gatherRoutineTaskMapRegistrationTask);
|
|
9122
|
+
gatherRoutineTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
9123
|
+
CadenzaService.createMetaTask(
|
|
9124
|
+
"Request sync after local service instance registration",
|
|
9125
|
+
(ctx) => {
|
|
9126
|
+
for (const delayMs of EARLY_SYNC_TICK_DELAYS_MS) {
|
|
9127
|
+
CadenzaService.schedule(
|
|
9128
|
+
"meta.sync_controller.sync_tick",
|
|
9129
|
+
{
|
|
9130
|
+
...buildMinimalSyncSignalContext(ctx),
|
|
9131
|
+
__syncing: true
|
|
9132
|
+
},
|
|
9133
|
+
delayMs
|
|
9134
|
+
);
|
|
8371
9135
|
}
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8378
|
-
{ __syncing: true },
|
|
8379
|
-
3e5,
|
|
8380
|
-
true
|
|
8381
|
-
);
|
|
8382
|
-
} else {
|
|
8383
|
-
CadenzaService.interval(
|
|
8384
|
-
"meta.sync_controller.sync_tick",
|
|
8385
|
-
{ __syncing: true },
|
|
8386
|
-
18e4
|
|
8387
|
-
);
|
|
8388
|
-
CadenzaService.schedule(
|
|
8389
|
-
"meta.sync_controller.sync_tick",
|
|
8390
|
-
{ __syncing: true },
|
|
8391
|
-
250
|
|
8392
|
-
);
|
|
8393
|
-
for (const delayMs of EARLY_SYNC_REQUEST_DELAYS_MS) {
|
|
8394
|
-
CadenzaService.schedule("meta.sync_requested", { __syncing: true }, delayMs);
|
|
9136
|
+
return true;
|
|
9137
|
+
},
|
|
9138
|
+
"Schedules the early bootstrap sync burst after local instance registration so startup-defined primitives can converge deterministically.",
|
|
9139
|
+
{
|
|
9140
|
+
register: false,
|
|
9141
|
+
isHidden: true
|
|
8395
9142
|
}
|
|
8396
|
-
|
|
9143
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
9144
|
+
CadenzaService.interval(
|
|
9145
|
+
"meta.sync_controller.sync_tick",
|
|
9146
|
+
{ __syncing: true },
|
|
9147
|
+
this.isCadenzaDBReady ? 18e4 : 3e5
|
|
9148
|
+
);
|
|
8397
9149
|
}
|
|
8398
9150
|
};
|
|
8399
9151
|
|
|
@@ -8567,7 +9319,53 @@ function resolveBootstrapEndpoint(options) {
|
|
|
8567
9319
|
}
|
|
8568
9320
|
|
|
8569
9321
|
// src/Cadenza.ts
|
|
9322
|
+
var POSTGRES_SETUP_DEBUG_ENABLED = process.env.CADENZA_POSTGRES_SETUP_DEBUG === "1" || process.env.CADENZA_POSTGRES_SETUP_DEBUG === "true";
|
|
9323
|
+
var DEFAULT_DEPUTY_TASK_CONCURRENCY = 50;
|
|
9324
|
+
var DEFAULT_DEPUTY_TASK_TIMEOUT_MS = 12e4;
|
|
9325
|
+
var DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY = 50;
|
|
9326
|
+
var DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS = 12e4;
|
|
8570
9327
|
var CadenzaService = class {
|
|
9328
|
+
static replayRegisteredTaskIntentAssociations() {
|
|
9329
|
+
for (const task of this.registry.tasks.values()) {
|
|
9330
|
+
if (!task.register || task.isHidden || task.handlesIntents.size === 0) {
|
|
9331
|
+
continue;
|
|
9332
|
+
}
|
|
9333
|
+
for (const intentName of task.handlesIntents) {
|
|
9334
|
+
task.emitWithMetadata("meta.task.intent_associated", {
|
|
9335
|
+
data: {
|
|
9336
|
+
intentName,
|
|
9337
|
+
taskName: task.name,
|
|
9338
|
+
taskVersion: task.version
|
|
9339
|
+
},
|
|
9340
|
+
taskInstance: task,
|
|
9341
|
+
__isSubMeta: task.isSubMeta
|
|
9342
|
+
});
|
|
9343
|
+
}
|
|
9344
|
+
}
|
|
9345
|
+
}
|
|
9346
|
+
static replayRegisteredTaskSignalObservations() {
|
|
9347
|
+
for (const task of this.registry.tasks.values()) {
|
|
9348
|
+
if (!task.register || task.isHidden || task.observedSignals.size === 0) {
|
|
9349
|
+
continue;
|
|
9350
|
+
}
|
|
9351
|
+
for (const signalName of task.observedSignals) {
|
|
9352
|
+
task.emitWithMetadata("meta.task.observed_signal", {
|
|
9353
|
+
data: {
|
|
9354
|
+
signalName,
|
|
9355
|
+
taskName: task.name,
|
|
9356
|
+
taskVersion: task.version
|
|
9357
|
+
},
|
|
9358
|
+
taskInstance: task,
|
|
9359
|
+
signalName,
|
|
9360
|
+
__isSubMeta: task.isSubMeta
|
|
9361
|
+
});
|
|
9362
|
+
}
|
|
9363
|
+
}
|
|
9364
|
+
}
|
|
9365
|
+
static replayRegisteredTaskGraphMetadata() {
|
|
9366
|
+
this.replayRegisteredTaskSignalObservations();
|
|
9367
|
+
this.replayRegisteredTaskIntentAssociations();
|
|
9368
|
+
}
|
|
8571
9369
|
static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
|
|
8572
9370
|
const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
8573
9371
|
const helperSuffix = camelCase(String(tableName ?? "").trim());
|
|
@@ -8710,6 +9508,12 @@ var CadenzaService = class {
|
|
|
8710
9508
|
static setMode(mode) {
|
|
8711
9509
|
Cadenza.setMode(mode);
|
|
8712
9510
|
}
|
|
9511
|
+
static hasCompletedBootstrapSync() {
|
|
9512
|
+
return !this.serviceCreated || this.bootstrapSyncCompleted;
|
|
9513
|
+
}
|
|
9514
|
+
static markBootstrapSyncCompleted() {
|
|
9515
|
+
this.bootstrapSyncCompleted = true;
|
|
9516
|
+
}
|
|
8713
9517
|
/**
|
|
8714
9518
|
* Emits a signal with the specified data using the associated broker.
|
|
8715
9519
|
*
|
|
@@ -8797,6 +9601,46 @@ var CadenzaService = class {
|
|
|
8797
9601
|
responders: statuses
|
|
8798
9602
|
};
|
|
8799
9603
|
}
|
|
9604
|
+
static shouldPersistInquiry(inquiry, _context) {
|
|
9605
|
+
return !isMetaIntentName(inquiry);
|
|
9606
|
+
}
|
|
9607
|
+
static splitInquiryPersistenceContext(context) {
|
|
9608
|
+
const businessContext = {};
|
|
9609
|
+
const metadata = context?.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
|
|
9610
|
+
for (const [key, value] of Object.entries(context ?? {})) {
|
|
9611
|
+
if (key === "__metadata") {
|
|
9612
|
+
continue;
|
|
9613
|
+
}
|
|
9614
|
+
if (key.startsWith("__")) {
|
|
9615
|
+
metadata[key] = value;
|
|
9616
|
+
continue;
|
|
9617
|
+
}
|
|
9618
|
+
businessContext[key] = value;
|
|
9619
|
+
}
|
|
9620
|
+
return {
|
|
9621
|
+
context: businessContext,
|
|
9622
|
+
metadata
|
|
9623
|
+
};
|
|
9624
|
+
}
|
|
9625
|
+
static buildInquiryPersistenceStartData(inquiryId, inquiry, context, startedAt) {
|
|
9626
|
+
const normalizedTaskVersion = Number(context?.__inquirySourceTaskVersion);
|
|
9627
|
+
const { context: inquiryContext, metadata } = this.splitInquiryPersistenceContext(context);
|
|
9628
|
+
return {
|
|
9629
|
+
uuid: inquiryId,
|
|
9630
|
+
name: inquiry,
|
|
9631
|
+
taskName: typeof context?.__inquirySourceTaskName === "string" ? context.__inquirySourceTaskName : null,
|
|
9632
|
+
taskVersion: Number.isFinite(normalizedTaskVersion) && normalizedTaskVersion > 0 ? normalizedTaskVersion : null,
|
|
9633
|
+
taskExecutionId: typeof context?.__inquirySourceTaskExecutionId === "string" ? context.__inquirySourceTaskExecutionId : null,
|
|
9634
|
+
serviceName: this.serviceRegistry.serviceName,
|
|
9635
|
+
serviceInstanceId: this.serviceRegistry.serviceInstanceId,
|
|
9636
|
+
executionTraceId: typeof (context?.__metadata?.__executionTraceId ?? context?.__executionTraceId) === "string" ? context.__metadata?.__executionTraceId ?? context.__executionTraceId : null,
|
|
9637
|
+
routineExecutionId: typeof context?.__inquirySourceRoutineExecutionId === "string" ? context.__inquirySourceRoutineExecutionId : null,
|
|
9638
|
+
context: inquiryContext,
|
|
9639
|
+
metadata,
|
|
9640
|
+
isMeta: false,
|
|
9641
|
+
sentAt: formatTimestamp(startedAt)
|
|
9642
|
+
};
|
|
9643
|
+
}
|
|
8800
9644
|
static async inquire(inquiry, context, options = {}) {
|
|
8801
9645
|
this.bootstrap();
|
|
8802
9646
|
const hydratedResult = this.consumeHydratedInquiryResult(
|
|
@@ -8811,6 +9655,20 @@ var CadenzaService = class {
|
|
|
8811
9655
|
descriptor: this.getInquiryResponderDescriptor(task)
|
|
8812
9656
|
})) : [];
|
|
8813
9657
|
const isMetaInquiry = isMetaIntentName(inquiry);
|
|
9658
|
+
const startedAt = Date.now();
|
|
9659
|
+
const persistInquiry = this.shouldPersistInquiry(inquiry, context);
|
|
9660
|
+
const logicalInquiryId = persistInquiry ? uuid5() : null;
|
|
9661
|
+
const inquiryStartData = logicalInquiryId ? this.buildInquiryPersistenceStartData(
|
|
9662
|
+
logicalInquiryId,
|
|
9663
|
+
inquiry,
|
|
9664
|
+
context,
|
|
9665
|
+
startedAt
|
|
9666
|
+
) : null;
|
|
9667
|
+
if (inquiryStartData) {
|
|
9668
|
+
this.emit("meta.inquiry_broker.inquiry_started", {
|
|
9669
|
+
data: inquiryStartData
|
|
9670
|
+
});
|
|
9671
|
+
}
|
|
8814
9672
|
const responders = allResponders.filter(({ task, descriptor }) => {
|
|
8815
9673
|
const shouldExecute = shouldExecuteInquiryResponder(inquiry, task.isMeta);
|
|
8816
9674
|
if (shouldExecute) {
|
|
@@ -8845,6 +9703,21 @@ var CadenzaService = class {
|
|
|
8845
9703
|
durationMs: 0,
|
|
8846
9704
|
responders: []
|
|
8847
9705
|
};
|
|
9706
|
+
if (logicalInquiryId) {
|
|
9707
|
+
this.emit("meta.inquiry_broker.inquiry_completed", {
|
|
9708
|
+
data: {
|
|
9709
|
+
fulfilledAt: formatTimestamp(startedAt),
|
|
9710
|
+
duration: 0,
|
|
9711
|
+
metadata: {
|
|
9712
|
+
...inquiryStartData?.metadata ?? {},
|
|
9713
|
+
inquiryMeta
|
|
9714
|
+
}
|
|
9715
|
+
},
|
|
9716
|
+
filter: {
|
|
9717
|
+
uuid: logicalInquiryId
|
|
9718
|
+
}
|
|
9719
|
+
});
|
|
9720
|
+
}
|
|
8848
9721
|
if (options.requireComplete) {
|
|
8849
9722
|
throw {
|
|
8850
9723
|
__inquiryMeta: inquiryMeta,
|
|
@@ -8860,7 +9733,6 @@ var CadenzaService = class {
|
|
|
8860
9733
|
const overallTimeoutMs = options.overallTimeoutMs ?? options.timeout ?? 0;
|
|
8861
9734
|
const requireComplete = options.requireComplete ?? false;
|
|
8862
9735
|
const perResponderTimeoutMs = options.perResponderTimeoutMs;
|
|
8863
|
-
const startedAt = Date.now();
|
|
8864
9736
|
const statuses = [];
|
|
8865
9737
|
const statusByTask = /* @__PURE__ */ new Map();
|
|
8866
9738
|
for (const responder of responders) {
|
|
@@ -8906,10 +9778,26 @@ var CadenzaService = class {
|
|
|
8906
9778
|
statuses,
|
|
8907
9779
|
allResponders.length
|
|
8908
9780
|
);
|
|
9781
|
+
const finishedAt = Date.now();
|
|
8909
9782
|
const responseContext = {
|
|
8910
9783
|
...mergedContext,
|
|
8911
9784
|
__inquiryMeta: inquiryMeta
|
|
8912
9785
|
};
|
|
9786
|
+
if (logicalInquiryId) {
|
|
9787
|
+
this.emit("meta.inquiry_broker.inquiry_completed", {
|
|
9788
|
+
data: {
|
|
9789
|
+
fulfilledAt: formatTimestamp(finishedAt),
|
|
9790
|
+
duration: finishedAt - startedAt,
|
|
9791
|
+
metadata: {
|
|
9792
|
+
...inquiryStartData?.metadata ?? {},
|
|
9793
|
+
inquiryMeta
|
|
9794
|
+
}
|
|
9795
|
+
},
|
|
9796
|
+
filter: {
|
|
9797
|
+
uuid: logicalInquiryId
|
|
9798
|
+
}
|
|
9799
|
+
});
|
|
9800
|
+
}
|
|
8913
9801
|
if (requireComplete && (timedOut || inquiryMeta.failed > 0 || inquiryMeta.timedOut > 0 || inquiryMeta.pending > 0)) {
|
|
8914
9802
|
reject({
|
|
8915
9803
|
...responseContext,
|
|
@@ -8925,7 +9813,7 @@ var CadenzaService = class {
|
|
|
8925
9813
|
}
|
|
8926
9814
|
for (const responder of responders) {
|
|
8927
9815
|
const { task, descriptor } = responder;
|
|
8928
|
-
const
|
|
9816
|
+
const responderInquiryId = uuid5();
|
|
8929
9817
|
startTimeByTask.set(task, Date.now());
|
|
8930
9818
|
const resolverTask = this.createEphemeralMetaTask(
|
|
8931
9819
|
`Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
|
|
@@ -8953,11 +9841,12 @@ var CadenzaService = class {
|
|
|
8953
9841
|
},
|
|
8954
9842
|
"Resolves distributed inquiry responder result",
|
|
8955
9843
|
{ register: false }
|
|
8956
|
-
).doOn(`meta.node.graph_completed:${
|
|
9844
|
+
).doOn(`meta.node.graph_completed:${responderInquiryId}`);
|
|
8957
9845
|
resolverTasks.push(resolverTask);
|
|
8958
9846
|
const executionContext = {
|
|
8959
9847
|
...context,
|
|
8960
|
-
|
|
9848
|
+
...logicalInquiryId ? { __inquiryId: logicalInquiryId } : {},
|
|
9849
|
+
__routineExecId: responderInquiryId,
|
|
8961
9850
|
__isInquiry: true
|
|
8962
9851
|
};
|
|
8963
9852
|
if (perResponderTimeoutMs !== void 0) {
|
|
@@ -9119,8 +10008,8 @@ var CadenzaService = class {
|
|
|
9119
10008
|
this.validateName(routineName);
|
|
9120
10009
|
const name = `${routineName} (Proxy)`;
|
|
9121
10010
|
options = {
|
|
9122
|
-
concurrency:
|
|
9123
|
-
timeout:
|
|
10011
|
+
concurrency: DEFAULT_DEPUTY_TASK_CONCURRENCY,
|
|
10012
|
+
timeout: DEFAULT_DEPUTY_TASK_TIMEOUT_MS,
|
|
9124
10013
|
register: true,
|
|
9125
10014
|
isUnique: false,
|
|
9126
10015
|
isMeta: false,
|
|
@@ -9227,8 +10116,8 @@ var CadenzaService = class {
|
|
|
9227
10116
|
return;
|
|
9228
10117
|
}
|
|
9229
10118
|
options = {
|
|
9230
|
-
concurrency:
|
|
9231
|
-
timeout:
|
|
10119
|
+
concurrency: DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY,
|
|
10120
|
+
timeout: DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS,
|
|
9232
10121
|
register: true,
|
|
9233
10122
|
isUnique: false,
|
|
9234
10123
|
isMeta: true,
|
|
@@ -9289,8 +10178,8 @@ var CadenzaService = class {
|
|
|
9289
10178
|
const description = `Executes a ${operation} on table ${tableName} in ${targetDatabaseServiceName}`;
|
|
9290
10179
|
const taskName = `${operation.charAt(0).toUpperCase() + operation.slice(1)} ${tableName}`;
|
|
9291
10180
|
options = {
|
|
9292
|
-
concurrency:
|
|
9293
|
-
timeout:
|
|
10181
|
+
concurrency: DEFAULT_DATABASE_PROXY_TASK_CONCURRENCY,
|
|
10182
|
+
timeout: DEFAULT_DATABASE_PROXY_TASK_TIMEOUT_MS,
|
|
9294
10183
|
register: true,
|
|
9295
10184
|
isUnique: false,
|
|
9296
10185
|
isMeta: false,
|
|
@@ -9434,8 +10323,10 @@ var CadenzaService = class {
|
|
|
9434
10323
|
this.validateName(serviceName);
|
|
9435
10324
|
this.validateServiceName(serviceName);
|
|
9436
10325
|
const serviceId = options.customServiceId ?? uuid5();
|
|
10326
|
+
this.bootstrapSyncCompleted = false;
|
|
9437
10327
|
this.serviceRegistry.serviceName = serviceName;
|
|
9438
10328
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
10329
|
+
this.serviceRegistry.connectsToCadenzaDB = !!options.cadenzaDB?.connect;
|
|
9439
10330
|
this.setHydrationResults(options.hydration);
|
|
9440
10331
|
const explicitFrontendMode = options.isFrontend;
|
|
9441
10332
|
options = {
|
|
@@ -9464,6 +10355,23 @@ var CadenzaService = class {
|
|
|
9464
10355
|
this.serviceRegistry.useSocket = !!options.useSocket;
|
|
9465
10356
|
this.serviceRegistry.retryCount = options.retryCount ?? 3;
|
|
9466
10357
|
this.ensureTransportControllers(isFrontend);
|
|
10358
|
+
if (!isFrontend) {
|
|
10359
|
+
this.createMetaTask(
|
|
10360
|
+
"Initialize graph metadata controller after initial sync",
|
|
10361
|
+
() => {
|
|
10362
|
+
this.markBootstrapSyncCompleted();
|
|
10363
|
+
GraphMetadataController.instance;
|
|
10364
|
+
return true;
|
|
10365
|
+
},
|
|
10366
|
+
"Delays direct graph-metadata registration until the bootstrap sync has completed.",
|
|
10367
|
+
{
|
|
10368
|
+
register: false,
|
|
10369
|
+
isHidden: true
|
|
10370
|
+
}
|
|
10371
|
+
).doOn("meta.service_registry.initial_sync_complete");
|
|
10372
|
+
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB";
|
|
10373
|
+
GraphSyncController.instance.init();
|
|
10374
|
+
}
|
|
9467
10375
|
const resolvedBootstrapEndpoint = options.cadenzaDB?.connect ? resolveBootstrapEndpoint({
|
|
9468
10376
|
runtime: isFrontend ? "browser" : "server",
|
|
9469
10377
|
bootstrap: options.bootstrap,
|
|
@@ -9537,14 +10445,14 @@ var CadenzaService = class {
|
|
|
9537
10445
|
data: {
|
|
9538
10446
|
name: serviceName,
|
|
9539
10447
|
description,
|
|
9540
|
-
|
|
9541
|
-
|
|
10448
|
+
display_name: options.displayName ?? "",
|
|
10449
|
+
is_meta: options.isMeta
|
|
9542
10450
|
},
|
|
9543
10451
|
__registrationData: {
|
|
9544
10452
|
name: serviceName,
|
|
9545
10453
|
description,
|
|
9546
|
-
|
|
9547
|
-
|
|
10454
|
+
display_name: options.displayName ?? "",
|
|
10455
|
+
is_meta: options.isMeta
|
|
9548
10456
|
},
|
|
9549
10457
|
__serviceName: serviceName,
|
|
9550
10458
|
__serviceInstanceId: serviceId,
|
|
@@ -9575,14 +10483,13 @@ var CadenzaService = class {
|
|
|
9575
10483
|
);
|
|
9576
10484
|
}).doOn("meta.rest.handshake", "meta.socket.handshake");
|
|
9577
10485
|
}
|
|
9578
|
-
this.createMetaTask("Handle service setup completion", () => {
|
|
10486
|
+
this.createMetaTask("Handle service setup completion", (ctx, emit) => {
|
|
10487
|
+
if (options.cadenzaDB?.connect) {
|
|
10488
|
+
this.serviceRegistry.bootstrapFullSync(emit, ctx, "service_setup_completed");
|
|
10489
|
+
}
|
|
9579
10490
|
if (isFrontend) {
|
|
9580
10491
|
registerActorSessionPersistenceTasks();
|
|
9581
10492
|
this.ensureFrontendSyncLoop();
|
|
9582
|
-
} else {
|
|
9583
|
-
GraphMetadataController.instance;
|
|
9584
|
-
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB" || !!options.cadenzaDB?.connect;
|
|
9585
|
-
GraphSyncController.instance.init();
|
|
9586
10493
|
}
|
|
9587
10494
|
this.log("Service created.");
|
|
9588
10495
|
return true;
|
|
@@ -9611,7 +10518,15 @@ var CadenzaService = class {
|
|
|
9611
10518
|
is_blocked: false,
|
|
9612
10519
|
health: {}
|
|
9613
10520
|
},
|
|
9614
|
-
__transportData:
|
|
10521
|
+
__transportData: declaredTransports.map((transport) => ({
|
|
10522
|
+
uuid: transport.uuid,
|
|
10523
|
+
service_instance_id: serviceId,
|
|
10524
|
+
role: transport.role,
|
|
10525
|
+
origin: transport.origin,
|
|
10526
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
10527
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
10528
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
10529
|
+
})),
|
|
9615
10530
|
__serviceName: serviceName,
|
|
9616
10531
|
__serviceInstanceId: serviceId,
|
|
9617
10532
|
__useSocket: options.useSocket,
|
|
@@ -9728,10 +10643,35 @@ var CadenzaService = class {
|
|
|
9728
10643
|
registration.actorName
|
|
9729
10644
|
);
|
|
9730
10645
|
const createServiceTaskName = `Create database service ${name} after ${registration.actorName} setup`;
|
|
10646
|
+
const traceSetupDoneTaskName = `Trace database service ${name} setup done`;
|
|
10647
|
+
if (POSTGRES_SETUP_DEBUG_ENABLED && !this.get(traceSetupDoneTaskName)) {
|
|
10648
|
+
this.createMetaTask(
|
|
10649
|
+
traceSetupDoneTaskName,
|
|
10650
|
+
(ctx) => {
|
|
10651
|
+
console.log("[CADENZA_POSTGRES_SETUP_DEBUG] setup_done_signal_observed", {
|
|
10652
|
+
serviceName: name,
|
|
10653
|
+
actorName: registration.actorName,
|
|
10654
|
+
payloadKeys: Object.keys(ctx ?? {})
|
|
10655
|
+
});
|
|
10656
|
+
return true;
|
|
10657
|
+
},
|
|
10658
|
+
"Debug trace for PostgresActor setup-done signal delivery.",
|
|
10659
|
+
{ isHidden: true, register: false }
|
|
10660
|
+
).doOn(registration.setupDoneSignal);
|
|
10661
|
+
}
|
|
9731
10662
|
if (!this.get(createServiceTaskName)) {
|
|
9732
10663
|
this.createMetaTask(
|
|
9733
10664
|
createServiceTaskName,
|
|
9734
10665
|
() => {
|
|
10666
|
+
if (POSTGRES_SETUP_DEBUG_ENABLED) {
|
|
10667
|
+
console.log(
|
|
10668
|
+
"[CADENZA_POSTGRES_SETUP_DEBUG] create_database_service_task_fired",
|
|
10669
|
+
{
|
|
10670
|
+
serviceName: name,
|
|
10671
|
+
actorName: registration.actorName
|
|
10672
|
+
}
|
|
10673
|
+
);
|
|
10674
|
+
}
|
|
9735
10675
|
this.createCadenzaService(name, description, serviceOptions);
|
|
9736
10676
|
return true;
|
|
9737
10677
|
},
|
|
@@ -10263,6 +11203,7 @@ var CadenzaService = class {
|
|
|
10263
11203
|
this.serviceRegistry?.reset();
|
|
10264
11204
|
this.isBootstrapped = false;
|
|
10265
11205
|
this.serviceCreated = false;
|
|
11206
|
+
this.bootstrapSyncCompleted = false;
|
|
10266
11207
|
this.defaultDatabaseServiceName = null;
|
|
10267
11208
|
this.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
|
|
10268
11209
|
this.hydratedInquiryResults = /* @__PURE__ */ new Map();
|
|
@@ -10271,6 +11212,7 @@ var CadenzaService = class {
|
|
|
10271
11212
|
};
|
|
10272
11213
|
CadenzaService.isBootstrapped = false;
|
|
10273
11214
|
CadenzaService.serviceCreated = false;
|
|
11215
|
+
CadenzaService.bootstrapSyncCompleted = false;
|
|
10274
11216
|
CadenzaService.defaultDatabaseServiceName = null;
|
|
10275
11217
|
CadenzaService.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
|
|
10276
11218
|
CadenzaService.hydratedInquiryResults = /* @__PURE__ */ new Map();
|