@cadenza.io/service 2.18.1 → 2.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +896 -569
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +896 -569
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +920 -561
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +920 -561
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -686,6 +686,21 @@ var CADENZA_DB_GATHERED_SYNC_SIGNAL = "global.meta.cadenza_db.gathered_sync_data
|
|
|
686
686
|
var META_GATHERED_SYNC_TRANSMISSION_RECONCILE_SIGNAL = "meta.service_registry.gathered_sync_transmission_reconcile_requested";
|
|
687
687
|
var META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL = "meta.service_registry.runtime_status.heartbeat_tick";
|
|
688
688
|
var META_RUNTIME_STATUS_MONITOR_TICK_SIGNAL = "meta.service_registry.runtime_status.monitor_tick";
|
|
689
|
+
var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
690
|
+
100,
|
|
691
|
+
1500,
|
|
692
|
+
5e3,
|
|
693
|
+
12e3,
|
|
694
|
+
25e3,
|
|
695
|
+
45e3,
|
|
696
|
+
7e4
|
|
697
|
+
];
|
|
698
|
+
var BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS = [
|
|
699
|
+
"Query service_instance",
|
|
700
|
+
"Query service_instance_transport",
|
|
701
|
+
"Query signal_to_task_map",
|
|
702
|
+
"Query intent_to_task_map"
|
|
703
|
+
];
|
|
689
704
|
var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
690
705
|
"Track local routine start",
|
|
691
706
|
"Track local routine end",
|
|
@@ -827,6 +842,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
827
842
|
ctx.__resolverQueryData ?? ctx.queryData ?? {},
|
|
828
843
|
ctx
|
|
829
844
|
);
|
|
845
|
+
if (tableName === "service_instance" && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
846
|
+
console.log("[CADENZA_INSTANCE_DEBUG] finalize_service_registry_insert", {
|
|
847
|
+
tableName,
|
|
848
|
+
hasNormalized: !!normalized,
|
|
849
|
+
normalizedKeys: normalized && typeof normalized === "object" ? Object.keys(normalized) : [],
|
|
850
|
+
uuid: normalized && typeof normalized === "object" ? normalized.uuid ?? normalized.data?.uuid ?? normalized.queryData?.data?.uuid ?? null : null,
|
|
851
|
+
serviceName: normalized && typeof normalized === "object" ? normalized.__serviceName ?? normalized.data?.service_name ?? normalized.queryData?.data?.service_name ?? null : null,
|
|
852
|
+
errored: normalized && typeof normalized === "object" ? normalized.errored === true : false,
|
|
853
|
+
error: normalized && typeof normalized === "object" ? normalized.__error ?? null : null,
|
|
854
|
+
inquiryMeta: normalized && typeof normalized === "object" ? normalized.__inquiryMeta ?? null : null
|
|
855
|
+
});
|
|
856
|
+
}
|
|
830
857
|
if (!normalized || typeof normalized !== "object") {
|
|
831
858
|
return normalized;
|
|
832
859
|
}
|
|
@@ -871,6 +898,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
871
898
|
).doOn(executionResolvedSignal, executionFailedSignal);
|
|
872
899
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
873
900
|
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
901
|
+
if (tableName === "service_instance" && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
902
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
903
|
+
tableName,
|
|
904
|
+
executionSignal,
|
|
905
|
+
hasLocalInsertTask: !!localInsertTask,
|
|
906
|
+
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
907
|
+
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
908
|
+
hasData: !!ctx.data,
|
|
909
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
910
|
+
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
911
|
+
});
|
|
912
|
+
}
|
|
874
913
|
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
875
914
|
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
876
915
|
wiredLocalTaskNames.add(localInsertTask.name);
|
|
@@ -953,6 +992,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
953
992
|
this.useSocket = false;
|
|
954
993
|
this.retryCount = 3;
|
|
955
994
|
this.isFrontend = false;
|
|
995
|
+
this.connectsToCadenzaDB = false;
|
|
956
996
|
CadenzaService.defineIntent({
|
|
957
997
|
name: META_RUNTIME_TRANSPORT_DIAGNOSTICS_INTENT,
|
|
958
998
|
description: "Gather transport diagnostics across all services and communication clients.",
|
|
@@ -1327,7 +1367,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1327
1367
|
return true;
|
|
1328
1368
|
},
|
|
1329
1369
|
"Handles registration of remote signals"
|
|
1330
|
-
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1370
|
+
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1371
|
+
"global.meta.cadenza_db.gathered_sync_data",
|
|
1372
|
+
"global.meta.graph_metadata.task_signal_observed"
|
|
1373
|
+
);
|
|
1331
1374
|
this.reconcileGatheredSyncTransmissionsTask = CadenzaService.createMetaTask(
|
|
1332
1375
|
"Reconcile gathered sync signal transmissions",
|
|
1333
1376
|
(ctx, emit) => this.reconcileGatheredSyncTransmissions(ctx, emit),
|
|
@@ -1481,7 +1524,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1481
1524
|
);
|
|
1482
1525
|
this.handleSocketStatusUpdateTask = CadenzaService.createMetaTask(
|
|
1483
1526
|
"Handle Socket Status Update",
|
|
1484
|
-
(ctx) => {
|
|
1527
|
+
(ctx, emit) => {
|
|
1485
1528
|
const report = this.normalizeRuntimeStatusReport(ctx);
|
|
1486
1529
|
if (!report) {
|
|
1487
1530
|
return false;
|
|
@@ -1524,6 +1567,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1524
1567
|
if (!applied) {
|
|
1525
1568
|
return false;
|
|
1526
1569
|
}
|
|
1570
|
+
const updatedInstance = this.getInstance(
|
|
1571
|
+
report.serviceName,
|
|
1572
|
+
report.serviceInstanceId
|
|
1573
|
+
);
|
|
1574
|
+
if (updatedInstance && !updatedInstance.isFrontend && (this.deputies.has(report.serviceName) || this.remoteIntents.has(report.serviceName) || this.remoteSignals.has(report.serviceName))) {
|
|
1575
|
+
this.ensureDependeeClientForInstance(updatedInstance, emit, ctx);
|
|
1576
|
+
}
|
|
1527
1577
|
this.registerDependee(report.serviceName, report.serviceInstanceId);
|
|
1528
1578
|
this.lastHeartbeatAtByInstance.set(report.serviceInstanceId, Date.now());
|
|
1529
1579
|
this.missedHeartbeatsByInstance.set(report.serviceInstanceId, 0);
|
|
@@ -1534,9 +1584,23 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1534
1584
|
},
|
|
1535
1585
|
"Handles status update from socket broadcast"
|
|
1536
1586
|
).doOn("meta.socket_client.status_received");
|
|
1587
|
+
CadenzaService.createMetaTask(
|
|
1588
|
+
"Request full sync after CadenzaDB fetch handshake",
|
|
1589
|
+
(ctx) => {
|
|
1590
|
+
const serviceName = typeof ctx.serviceName === "string" ? ctx.serviceName.trim() : typeof ctx.__serviceName === "string" ? ctx.__serviceName.trim() : "";
|
|
1591
|
+
if (serviceName !== "CadenzaDB") {
|
|
1592
|
+
return false;
|
|
1593
|
+
}
|
|
1594
|
+
return this.scheduleEarlyFullSyncRequests("cadenza_db_fetch_handshake");
|
|
1595
|
+
},
|
|
1596
|
+
"Schedules a few early service-registry full-sync retries after the authority fetch transport comes up."
|
|
1597
|
+
).doOn("meta.fetch.handshake_complete");
|
|
1537
1598
|
this.fullSyncTask = CadenzaService.createMetaTask(
|
|
1538
1599
|
"Full sync",
|
|
1539
1600
|
async (ctx) => {
|
|
1601
|
+
if (this.connectsToCadenzaDB && this.serviceName !== "CadenzaDB" && !this.hasBootstrapFullSyncDeputies()) {
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1540
1604
|
const inquiryResult = await CadenzaService.inquire(
|
|
1541
1605
|
META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
1542
1606
|
{
|
|
@@ -1593,7 +1657,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1593
1657
|
);
|
|
1594
1658
|
this.handleDeputyRegistrationTask = CadenzaService.createMetaTask(
|
|
1595
1659
|
"Handle Deputy Registration",
|
|
1596
|
-
(ctx) => {
|
|
1660
|
+
(ctx, emit) => {
|
|
1597
1661
|
const { serviceName } = ctx;
|
|
1598
1662
|
if (!this.deputies.has(serviceName)) this.deputies.set(serviceName, []);
|
|
1599
1663
|
this.deputies.get(serviceName).push({
|
|
@@ -1603,6 +1667,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1603
1667
|
localTaskName: ctx.localTaskName,
|
|
1604
1668
|
communicationType: ctx.communicationType
|
|
1605
1669
|
});
|
|
1670
|
+
this.ensureDependeeClientsForService(serviceName, emit, ctx);
|
|
1606
1671
|
}
|
|
1607
1672
|
).doOn("meta.deputy.created");
|
|
1608
1673
|
this.getAllInstances = CadenzaService.createMetaTask(
|
|
@@ -2155,9 +2220,29 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2155
2220
|
retryDelayFactor: 1.3
|
|
2156
2221
|
}
|
|
2157
2222
|
).emits("meta.service_registry.service_inserted").emitsOnFail("meta.service_registry.service_insertion_failed");
|
|
2158
|
-
|
|
2223
|
+
const insertServiceInstanceResolverTask = resolveServiceRegistryInsertTask(
|
|
2159
2224
|
"service_instance",
|
|
2160
|
-
{
|
|
2225
|
+
{
|
|
2226
|
+
onConflict: {
|
|
2227
|
+
target: ["uuid"],
|
|
2228
|
+
action: {
|
|
2229
|
+
do: "update",
|
|
2230
|
+
set: {
|
|
2231
|
+
process_pid: "excluded",
|
|
2232
|
+
is_primary: "excluded",
|
|
2233
|
+
service_name: "excluded",
|
|
2234
|
+
is_database: "excluded",
|
|
2235
|
+
is_frontend: "excluded",
|
|
2236
|
+
is_blocked: "excluded",
|
|
2237
|
+
is_non_responsive: "excluded",
|
|
2238
|
+
is_active: "excluded",
|
|
2239
|
+
last_active: "excluded",
|
|
2240
|
+
health: "excluded",
|
|
2241
|
+
deleted: "false"
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
},
|
|
2161
2246
|
{
|
|
2162
2247
|
inputSchema: {
|
|
2163
2248
|
type: "object",
|
|
@@ -2213,7 +2298,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2213
2298
|
retryCount: 5,
|
|
2214
2299
|
retryDelay: 1e3
|
|
2215
2300
|
}
|
|
2216
|
-
).
|
|
2301
|
+
).emitsOnFail("meta.service_registry.instance_insertion_failed");
|
|
2302
|
+
this.insertServiceInstanceTask = insertServiceInstanceResolverTask.then(
|
|
2217
2303
|
CadenzaService.createMetaTask(
|
|
2218
2304
|
"Setup service",
|
|
2219
2305
|
(ctx) => {
|
|
@@ -2230,6 +2316,21 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2230
2316
|
transports: ctx.__transportData ?? ctx.transportData ?? []
|
|
2231
2317
|
});
|
|
2232
2318
|
if (!normalizedLocalInstance?.uuid || !normalizedLocalInstance.serviceName) {
|
|
2319
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2320
|
+
console.log("[CADENZA_INSTANCE_DEBUG] setup_service_rejected_instance", {
|
|
2321
|
+
hasServiceInstance: !!serviceInstance,
|
|
2322
|
+
hasData: !!data,
|
|
2323
|
+
hasQueryDataData: !!queryData?.data,
|
|
2324
|
+
serviceInstanceKeys: serviceInstance && typeof serviceInstance === "object" ? Object.keys(serviceInstance) : [],
|
|
2325
|
+
dataKeys: data && typeof data === "object" ? Object.keys(data) : [],
|
|
2326
|
+
queryDataDataKeys: queryData?.data && typeof queryData.data === "object" ? Object.keys(queryData.data) : [],
|
|
2327
|
+
normalizedLocalInstance,
|
|
2328
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2329
|
+
errored: ctx.errored === true,
|
|
2330
|
+
error: ctx.__error ?? null,
|
|
2331
|
+
inquiryMeta: ctx.__inquiryMeta ?? null
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2233
2334
|
return false;
|
|
2234
2335
|
}
|
|
2235
2336
|
this.serviceInstanceId = normalizedLocalInstance.uuid;
|
|
@@ -2281,9 +2382,41 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2281
2382
|
).attachSignal("meta.service_registry.transport_registration_requested")
|
|
2282
2383
|
)
|
|
2283
2384
|
);
|
|
2385
|
+
CadenzaService.createMetaTask(
|
|
2386
|
+
"Retry local service instance registration after failed insert",
|
|
2387
|
+
(ctx) => {
|
|
2388
|
+
const serviceName = String(
|
|
2389
|
+
ctx.__serviceName ?? ctx.data?.service_name ?? this.serviceName ?? ""
|
|
2390
|
+
).trim();
|
|
2391
|
+
if (!serviceName || serviceName !== this.serviceName) {
|
|
2392
|
+
return false;
|
|
2393
|
+
}
|
|
2394
|
+
CadenzaService.schedule(
|
|
2395
|
+
"meta.service_registry.instance_registration_requested",
|
|
2396
|
+
{ ...ctx },
|
|
2397
|
+
5e3
|
|
2398
|
+
);
|
|
2399
|
+
return true;
|
|
2400
|
+
},
|
|
2401
|
+
"Retries local service instance registration only after the previous insert attempt has failed.",
|
|
2402
|
+
{
|
|
2403
|
+
register: false,
|
|
2404
|
+
isHidden: true
|
|
2405
|
+
}
|
|
2406
|
+
).doOn("meta.service_registry.instance_insertion_failed");
|
|
2284
2407
|
CadenzaService.createMetaTask(
|
|
2285
2408
|
"Prepare service instance registration",
|
|
2286
2409
|
(ctx) => {
|
|
2410
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2411
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_instance_registration", {
|
|
2412
|
+
serviceName: ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? null,
|
|
2413
|
+
serviceInstanceId: ctx.data?.uuid ?? ctx.__serviceInstanceId ?? this.serviceInstanceId ?? null,
|
|
2414
|
+
hasData: !!ctx.data,
|
|
2415
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
2416
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2417
|
+
skipRemoteExecution: ctx.__skipRemoteExecution === true
|
|
2418
|
+
});
|
|
2419
|
+
}
|
|
2287
2420
|
const serviceName = String(
|
|
2288
2421
|
ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? ""
|
|
2289
2422
|
).trim();
|
|
@@ -2476,21 +2609,40 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2476
2609
|
return [];
|
|
2477
2610
|
}
|
|
2478
2611
|
normalizeSignalMaps(ctx) {
|
|
2479
|
-
|
|
2612
|
+
const arrayPayload = this.readArrayPayload(ctx, [
|
|
2480
2613
|
"signalToTaskMaps",
|
|
2481
2614
|
"signal_to_task_maps",
|
|
2482
2615
|
"signalToTaskMap",
|
|
2483
2616
|
"signal_to_task_map"
|
|
2484
|
-
])
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2617
|
+
]);
|
|
2618
|
+
if (arrayPayload.length > 0) {
|
|
2619
|
+
return arrayPayload.map((map) => ({
|
|
2620
|
+
signalName: String(
|
|
2621
|
+
map.signalName ?? map.signal_name ?? ""
|
|
2622
|
+
).trim(),
|
|
2623
|
+
serviceName: String(
|
|
2624
|
+
map.serviceName ?? map.service_name ?? ""
|
|
2625
|
+
).trim(),
|
|
2626
|
+
isGlobal: Boolean(map.isGlobal ?? map.is_global ?? false),
|
|
2627
|
+
deleted: Boolean(map.deleted)
|
|
2628
|
+
})).filter((map) => map.signalName && map.serviceName);
|
|
2629
|
+
}
|
|
2630
|
+
const single = ctx.signalToTaskMap ?? ctx.signal_to_task_map ?? ctx.data ?? (ctx.signalName ?? ctx.signal_name ? ctx : void 0);
|
|
2631
|
+
if (!single || typeof single !== "object") {
|
|
2632
|
+
return [];
|
|
2633
|
+
}
|
|
2634
|
+
return [
|
|
2635
|
+
{
|
|
2636
|
+
signalName: String(
|
|
2637
|
+
single.signalName ?? single.signal_name ?? ""
|
|
2638
|
+
).trim(),
|
|
2639
|
+
serviceName: String(
|
|
2640
|
+
single.serviceName ?? single.service_name ?? ""
|
|
2641
|
+
).trim(),
|
|
2642
|
+
isGlobal: Boolean(single.isGlobal ?? single.is_global ?? false),
|
|
2643
|
+
deleted: Boolean(single.deleted)
|
|
2644
|
+
}
|
|
2645
|
+
].filter((map) => map.signalName && map.serviceName);
|
|
2494
2646
|
}
|
|
2495
2647
|
normalizeIntentMaps(ctx) {
|
|
2496
2648
|
const arrayPayload = this.readArrayPayload(ctx, [
|
|
@@ -2605,7 +2757,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2605
2757
|
)?.destroy();
|
|
2606
2758
|
this.gatheredSyncTransmissionServices.delete(serviceName);
|
|
2607
2759
|
}
|
|
2608
|
-
if (createdRecipients.length > 0
|
|
2760
|
+
if (createdRecipients.length > 0) {
|
|
2609
2761
|
emit("meta.cadenza_db.sync_tick", {
|
|
2610
2762
|
__syncing: true,
|
|
2611
2763
|
__reason: "gathered_sync_transmissions_reconciled"
|
|
@@ -2680,6 +2832,56 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2680
2832
|
}
|
|
2681
2833
|
}
|
|
2682
2834
|
}
|
|
2835
|
+
registerBootstrapFullSyncDeputies(emit, ctx) {
|
|
2836
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
2837
|
+
return false;
|
|
2838
|
+
}
|
|
2839
|
+
CadenzaService.inquiryBroker.addIntent({
|
|
2840
|
+
name: META_SERVICE_REGISTRY_FULL_SYNC_INTENT
|
|
2841
|
+
});
|
|
2842
|
+
for (const taskName of BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS) {
|
|
2843
|
+
this.registerRemoteIntentDeputy({
|
|
2844
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
2845
|
+
serviceName: "CadenzaDB",
|
|
2846
|
+
taskName,
|
|
2847
|
+
taskVersion: 1
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
this.ensureDependeeClientsForService("CadenzaDB", emit, ctx);
|
|
2851
|
+
return true;
|
|
2852
|
+
}
|
|
2853
|
+
hasBootstrapFullSyncDeputies() {
|
|
2854
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
2855
|
+
return true;
|
|
2856
|
+
}
|
|
2857
|
+
return BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS.every(
|
|
2858
|
+
(taskName) => this.remoteIntentDeputiesByKey.has(
|
|
2859
|
+
this.buildRemoteIntentDeputyKey({
|
|
2860
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
2861
|
+
serviceName: "CadenzaDB",
|
|
2862
|
+
taskName,
|
|
2863
|
+
taskVersion: 1
|
|
2864
|
+
})
|
|
2865
|
+
)
|
|
2866
|
+
);
|
|
2867
|
+
}
|
|
2868
|
+
scheduleEarlyFullSyncRequests(reason) {
|
|
2869
|
+
for (const delayMs of EARLY_FULL_SYNC_DELAYS_MS) {
|
|
2870
|
+
CadenzaService.schedule(
|
|
2871
|
+
"meta.sync_requested",
|
|
2872
|
+
{
|
|
2873
|
+
__syncing: false,
|
|
2874
|
+
__reason: reason
|
|
2875
|
+
},
|
|
2876
|
+
delayMs
|
|
2877
|
+
);
|
|
2878
|
+
}
|
|
2879
|
+
return true;
|
|
2880
|
+
}
|
|
2881
|
+
bootstrapFullSync(emit, ctx, reason = "local_instance_inserted") {
|
|
2882
|
+
this.registerBootstrapFullSyncDeputies(emit, ctx);
|
|
2883
|
+
return this.scheduleEarlyFullSyncRequests(reason);
|
|
2884
|
+
}
|
|
2683
2885
|
getInquiryResponderDescriptor(task) {
|
|
2684
2886
|
const remote = this.remoteIntentDeputiesByTask.get(task);
|
|
2685
2887
|
if (remote) {
|
|
@@ -2708,6 +2910,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2708
2910
|
}
|
|
2709
2911
|
return this.getInstance(this.serviceName, this.serviceInstanceId);
|
|
2710
2912
|
}
|
|
2913
|
+
hasLocalInstanceRegistered() {
|
|
2914
|
+
return Boolean(this.getLocalInstance());
|
|
2915
|
+
}
|
|
2711
2916
|
summarizeTransportForDebug(transport) {
|
|
2712
2917
|
if (!transport) {
|
|
2713
2918
|
return void 0;
|
|
@@ -3695,6 +3900,7 @@ var SignalTransmissionTask = class extends Task2 {
|
|
|
3695
3900
|
};
|
|
3696
3901
|
|
|
3697
3902
|
// src/network/RestController.browser.ts
|
|
3903
|
+
var FETCH_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3698
3904
|
var RestController = class _RestController {
|
|
3699
3905
|
constructor() {
|
|
3700
3906
|
this.fetchClientDiagnostics = /* @__PURE__ */ new Map();
|
|
@@ -3740,7 +3946,15 @@ var RestController = class _RestController {
|
|
|
3740
3946
|
is_blocked: false,
|
|
3741
3947
|
health: {}
|
|
3742
3948
|
},
|
|
3743
|
-
__transportData:
|
|
3949
|
+
__transportData: Array.isArray(ctx.__declaredTransports) ? ctx.__declaredTransports.map((transport) => ({
|
|
3950
|
+
uuid: transport.uuid,
|
|
3951
|
+
service_instance_id: ctx.__serviceInstanceId,
|
|
3952
|
+
role: transport.role,
|
|
3953
|
+
origin: transport.origin,
|
|
3954
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
3955
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
3956
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
3957
|
+
})) : []
|
|
3744
3958
|
});
|
|
3745
3959
|
return true;
|
|
3746
3960
|
},
|
|
@@ -3755,6 +3969,7 @@ var RestController = class _RestController {
|
|
|
3755
3969
|
if (!serviceName || !URL2 || !fetchId) {
|
|
3756
3970
|
return false;
|
|
3757
3971
|
}
|
|
3972
|
+
const clientTaskSuffix = `${URL2} (${fetchId})`;
|
|
3758
3973
|
const fetchDiagnostics = this.ensureFetchClientDiagnostics(
|
|
3759
3974
|
fetchId,
|
|
3760
3975
|
serviceName,
|
|
@@ -3762,11 +3977,11 @@ var RestController = class _RestController {
|
|
|
3762
3977
|
);
|
|
3763
3978
|
fetchDiagnostics.destroyed = false;
|
|
3764
3979
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3765
|
-
if (CadenzaService.get(`Send Handshake to ${
|
|
3980
|
+
if (CadenzaService.get(`Send Handshake to ${clientTaskSuffix}`)) {
|
|
3766
3981
|
return;
|
|
3767
3982
|
}
|
|
3768
3983
|
const handshakeTask = CadenzaService.createMetaTask(
|
|
3769
|
-
`Send Handshake to ${
|
|
3984
|
+
`Send Handshake to ${clientTaskSuffix}`,
|
|
3770
3985
|
async (handshakeCtx, emit) => {
|
|
3771
3986
|
try {
|
|
3772
3987
|
const response = await this.fetchDataWithTimeout(
|
|
@@ -3778,7 +3993,7 @@ var RestController = class _RestController {
|
|
|
3778
3993
|
method: "POST",
|
|
3779
3994
|
body: JSON.stringify(handshakeCtx.handshakeData)
|
|
3780
3995
|
},
|
|
3781
|
-
|
|
3996
|
+
FETCH_HANDSHAKE_TIMEOUT_MS
|
|
3782
3997
|
);
|
|
3783
3998
|
if (response.__status !== "success") {
|
|
3784
3999
|
const error = response.__error ?? `Failed to connect to service ${serviceName} ${handshakeCtx.serviceInstanceId}`;
|
|
@@ -3820,7 +4035,7 @@ var RestController = class _RestController {
|
|
|
3820
4035
|
"global.meta.fetch.service_communication_established"
|
|
3821
4036
|
);
|
|
3822
4037
|
const delegateTask = CadenzaService.createMetaTask(
|
|
3823
|
-
`Delegate flow to REST server ${
|
|
4038
|
+
`Delegate flow to REST server ${clientTaskSuffix}`,
|
|
3824
4039
|
async (delegateCtx, emit) => {
|
|
3825
4040
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
3826
4041
|
return;
|
|
@@ -3863,7 +4078,7 @@ var RestController = class _RestController {
|
|
|
3863
4078
|
`meta.service_registry.socket_failed:${fetchId}`
|
|
3864
4079
|
).emitsOnFail("meta.fetch.delegate_failed").attachSignal("meta.fetch.delegated");
|
|
3865
4080
|
const transmitTask = CadenzaService.createMetaTask(
|
|
3866
|
-
`Transmit signal to server ${
|
|
4081
|
+
`Transmit signal to server ${clientTaskSuffix}`,
|
|
3867
4082
|
async (signalCtx, emit) => {
|
|
3868
4083
|
if (signalCtx.__signalName === void 0) {
|
|
3869
4084
|
return;
|
|
@@ -3901,7 +4116,7 @@ var RestController = class _RestController {
|
|
|
3901
4116
|
"Sends signal request"
|
|
3902
4117
|
).doOn(`meta.service_registry.selected_instance_for_fetch:${fetchId}`).emitsOnFail("meta.fetch.signal_transmission_failed").attachSignal("meta.fetch.transmitted");
|
|
3903
4118
|
const statusTask = CadenzaService.createMetaTask(
|
|
3904
|
-
`Request status from ${
|
|
4119
|
+
`Request status from ${clientTaskSuffix}`,
|
|
3905
4120
|
async (statusCtx) => {
|
|
3906
4121
|
fetchDiagnostics.statusChecks++;
|
|
3907
4122
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -3926,7 +4141,7 @@ var RestController = class _RestController {
|
|
|
3926
4141
|
},
|
|
3927
4142
|
"Requests status"
|
|
3928
4143
|
).doOn("meta.fetch.status_check_requested").emits("meta.fetch.status_checked").emitsOnFail("meta.fetch.status_check_failed");
|
|
3929
|
-
CadenzaService.createEphemeralMetaTask(
|
|
4144
|
+
CadenzaService.createEphemeralMetaTask(`Destroy fetch client ${fetchId}`, () => {
|
|
3930
4145
|
fetchDiagnostics.connected = false;
|
|
3931
4146
|
fetchDiagnostics.destroyed = true;
|
|
3932
4147
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -6231,6 +6446,12 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6231
6446
|
}
|
|
6232
6447
|
);
|
|
6233
6448
|
}).doOn("meta.task.attached_signal").emits("global.meta.graph_metadata.task_attached_signal");
|
|
6449
|
+
CadenzaService.createMetaTask("Handle task intent association", (ctx) => {
|
|
6450
|
+
return buildDatabaseTriggerContext({
|
|
6451
|
+
...ctx.data,
|
|
6452
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6453
|
+
});
|
|
6454
|
+
}).doOn("meta.task.intent_associated").emits("global.meta.graph_metadata.task_intent_associated");
|
|
6234
6455
|
CadenzaService.createMetaTask("Handle task unsubscribing signal", (ctx) => {
|
|
6235
6456
|
return buildDatabaseTriggerContext(
|
|
6236
6457
|
{
|
|
@@ -6595,34 +6816,7 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
|
|
|
6595
6816
|
}
|
|
6596
6817
|
return nextQueryData;
|
|
6597
6818
|
}
|
|
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
6819
|
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 5;
|
|
6625
|
-
var REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY = 3;
|
|
6626
6820
|
function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
6627
6821
|
if (!graph) {
|
|
6628
6822
|
return void 0;
|
|
@@ -6635,11 +6829,27 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
|
6635
6829
|
}
|
|
6636
6830
|
function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
6637
6831
|
const originalContext = { ...ctx };
|
|
6832
|
+
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();
|
|
6833
|
+
const rootDbOperationFields = {};
|
|
6834
|
+
for (const key of [
|
|
6835
|
+
"data",
|
|
6836
|
+
"batch",
|
|
6837
|
+
"transaction",
|
|
6838
|
+
"onConflict",
|
|
6839
|
+
"filter",
|
|
6840
|
+
"fields"
|
|
6841
|
+
]) {
|
|
6842
|
+
if (Object.prototype.hasOwnProperty.call(queryData, key)) {
|
|
6843
|
+
rootDbOperationFields[key] = queryData[key];
|
|
6844
|
+
}
|
|
6845
|
+
}
|
|
6638
6846
|
const nextContext = {
|
|
6639
6847
|
__syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
|
|
6848
|
+
__syncSourceServiceName: syncSourceServiceName,
|
|
6640
6849
|
__preferredTransportProtocol: "rest",
|
|
6641
6850
|
__resolverOriginalContext: originalContext,
|
|
6642
6851
|
__resolverQueryData: queryData,
|
|
6852
|
+
...rootDbOperationFields,
|
|
6643
6853
|
queryData
|
|
6644
6854
|
};
|
|
6645
6855
|
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
@@ -6647,9 +6857,26 @@ function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
|
6647
6857
|
}
|
|
6648
6858
|
return nextContext;
|
|
6649
6859
|
}
|
|
6860
|
+
function markCompletedSyncCycle(completedCycles, cycleId, limit = 32) {
|
|
6861
|
+
if (!cycleId) {
|
|
6862
|
+
return false;
|
|
6863
|
+
}
|
|
6864
|
+
if (completedCycles.has(cycleId)) {
|
|
6865
|
+
return false;
|
|
6866
|
+
}
|
|
6867
|
+
completedCycles.add(cycleId);
|
|
6868
|
+
while (completedCycles.size > limit) {
|
|
6869
|
+
const oldestCycleId = completedCycles.values().next().value;
|
|
6870
|
+
if (!oldestCycleId) {
|
|
6871
|
+
break;
|
|
6872
|
+
}
|
|
6873
|
+
completedCycles.delete(oldestCycleId);
|
|
6874
|
+
}
|
|
6875
|
+
return true;
|
|
6876
|
+
}
|
|
6650
6877
|
function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6651
6878
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
6652
|
-
if (
|
|
6879
|
+
if (isCadenzaDBReady && !localInsertTask) {
|
|
6653
6880
|
return void 0;
|
|
6654
6881
|
}
|
|
6655
6882
|
const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
|
|
@@ -6700,6 +6927,11 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
6700
6927
|
...ctx,
|
|
6701
6928
|
queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
|
|
6702
6929
|
};
|
|
6930
|
+
if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
|
|
6931
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
6932
|
+
delayMs: 1e3
|
|
6933
|
+
});
|
|
6934
|
+
}
|
|
6703
6935
|
return normalizedContext;
|
|
6704
6936
|
},
|
|
6705
6937
|
`Finalizes ${tableName} graph-sync insert execution after the authority task finishes.`,
|
|
@@ -6727,63 +6959,16 @@ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
|
|
|
6727
6959
|
"intent_to_task_map",
|
|
6728
6960
|
"directional_task_graph_map"
|
|
6729
6961
|
];
|
|
6730
|
-
var
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
function resolveSyncQueryRows(ctx, tableName) {
|
|
6738
|
-
const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
|
|
6739
|
-
const rows = ctx?.[resultKey];
|
|
6740
|
-
return Array.isArray(rows) ? rows : [];
|
|
6741
|
-
}
|
|
6742
|
-
function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6743
|
-
const localQueryTask = CadenzaService.getLocalCadenzaDBQueryTask(tableName);
|
|
6744
|
-
if (!localQueryTask && !isCadenzaDBReady) {
|
|
6745
|
-
return void 0;
|
|
6746
|
-
}
|
|
6747
|
-
const targetTask = localQueryTask ?? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, {
|
|
6748
|
-
...options,
|
|
6749
|
-
concurrency: Number(options.concurrency) > 0 ? Math.min(
|
|
6750
|
-
Number(options.concurrency),
|
|
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
|
-
};
|
|
6783
|
-
}
|
|
6962
|
+
var BOOTSTRAP_SYNC_STALE_CYCLE_MS = 15e3;
|
|
6963
|
+
var EARLY_SYNC_TICK_DELAYS_MS = [
|
|
6964
|
+
400,
|
|
6965
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS + 1e3,
|
|
6966
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 2 + 2e3,
|
|
6967
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 3 + 3e3
|
|
6968
|
+
];
|
|
6784
6969
|
function getRegistrableTasks() {
|
|
6785
6970
|
return Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
6786
|
-
(task) => task.register && !task.isHidden
|
|
6971
|
+
(task) => task.register && !task.isHidden && !task.isDeputy
|
|
6787
6972
|
);
|
|
6788
6973
|
}
|
|
6789
6974
|
function getRegistrableRoutines() {
|
|
@@ -6848,10 +7033,23 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6848
7033
|
this.signalsSynced = false;
|
|
6849
7034
|
this.intentsSynced = false;
|
|
6850
7035
|
this.routinesSynced = false;
|
|
7036
|
+
this.directionalTaskMapsSynced = false;
|
|
7037
|
+
this.signalTaskMapsSynced = false;
|
|
7038
|
+
this.intentTaskMapsSynced = false;
|
|
7039
|
+
this.actorTaskMapsSynced = false;
|
|
7040
|
+
this.routineTaskMapsSynced = false;
|
|
6851
7041
|
this.isCadenzaDBReady = false;
|
|
6852
7042
|
this.initialized = false;
|
|
6853
7043
|
this.initRetryScheduled = false;
|
|
6854
7044
|
this.lastMissingLocalCadenzaDBInsertTablesKey = "";
|
|
7045
|
+
this.syncCycleCounter = 0;
|
|
7046
|
+
this.primitivePhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7047
|
+
this.mapPhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7048
|
+
this.activeSyncCycleId = null;
|
|
7049
|
+
this.activeSyncCycleStartedAt = 0;
|
|
7050
|
+
this.pendingBootstrapSyncRerun = false;
|
|
7051
|
+
this.localServiceInserted = false;
|
|
7052
|
+
this.localServiceInstanceInserted = false;
|
|
6855
7053
|
}
|
|
6856
7054
|
static get instance() {
|
|
6857
7055
|
if (!this._instance) this._instance = new _GraphSyncController();
|
|
@@ -6925,45 +7123,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6925
7123
|
},
|
|
6926
7124
|
{ concurrency: 30 }
|
|
6927
7125
|
);
|
|
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
7126
|
const finalizeTaskSync = (emit, ctx) => {
|
|
6966
7127
|
const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
|
|
7128
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
6967
7129
|
if (pendingTasks.length > 0) {
|
|
6968
7130
|
this.tasksSynced = false;
|
|
6969
7131
|
return false;
|
|
@@ -6982,6 +7144,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6982
7144
|
const pendingRoutines = getRegistrableRoutines().filter(
|
|
6983
7145
|
(routine) => !routine.registered
|
|
6984
7146
|
);
|
|
7147
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
6985
7148
|
if (pendingRoutines.length > 0) {
|
|
6986
7149
|
this.routinesSynced = false;
|
|
6987
7150
|
return false;
|
|
@@ -7000,6 +7163,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7000
7163
|
const pendingSignals = getRegistrableSignalObservers().filter(
|
|
7001
7164
|
(observer) => observer.registered !== true
|
|
7002
7165
|
);
|
|
7166
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7003
7167
|
if (pendingSignals.length > 0) {
|
|
7004
7168
|
this.signalsSynced = false;
|
|
7005
7169
|
return false;
|
|
@@ -7018,6 +7182,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7018
7182
|
const pendingIntentNames = getRegistrableIntentNames().filter(
|
|
7019
7183
|
(intentName) => !this.registeredIntentDefinitions.has(intentName)
|
|
7020
7184
|
);
|
|
7185
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7021
7186
|
if (pendingIntentNames.length > 0) {
|
|
7022
7187
|
this.intentsSynced = false;
|
|
7023
7188
|
return false;
|
|
@@ -7283,14 +7448,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7283
7448
|
);
|
|
7284
7449
|
const processSignalRegistrationTask = CadenzaService.createMetaTask(
|
|
7285
7450
|
"Process signal registration",
|
|
7286
|
-
(ctx) => {
|
|
7287
|
-
|
|
7451
|
+
(ctx, emit) => {
|
|
7452
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
7453
|
+
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7454
|
+
if (!insertSucceeded) {
|
|
7288
7455
|
return;
|
|
7289
7456
|
}
|
|
7290
7457
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7291
7458
|
delayMs: 3e3
|
|
7292
7459
|
});
|
|
7293
|
-
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7294
7460
|
if (!signalName) {
|
|
7295
7461
|
return false;
|
|
7296
7462
|
}
|
|
@@ -7302,6 +7468,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7302
7468
|
if (observer) {
|
|
7303
7469
|
observer.registered = true;
|
|
7304
7470
|
}
|
|
7471
|
+
emit(
|
|
7472
|
+
"meta.sync_controller.signal_registered",
|
|
7473
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
7474
|
+
__signal: signalName
|
|
7475
|
+
})
|
|
7476
|
+
);
|
|
7305
7477
|
return { signalName };
|
|
7306
7478
|
}
|
|
7307
7479
|
).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask);
|
|
@@ -7322,6 +7494,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7322
7494
|
return;
|
|
7323
7495
|
}
|
|
7324
7496
|
for (const task of tasks) {
|
|
7497
|
+
if (task.hidden || !task.register || task.isDeputy) continue;
|
|
7325
7498
|
if (task.registered) continue;
|
|
7326
7499
|
const { __functionString, __getTagCallback } = task.export();
|
|
7327
7500
|
this.tasksSynced = false;
|
|
@@ -7356,7 +7529,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7356
7529
|
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
7357
7530
|
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
7358
7531
|
observed: Array.from(task.observedSignals)
|
|
7359
|
-
}
|
|
7532
|
+
},
|
|
7533
|
+
intents: Array.from(task.handlesIntents)
|
|
7360
7534
|
},
|
|
7361
7535
|
__taskName: task.name
|
|
7362
7536
|
};
|
|
@@ -7379,13 +7553,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7379
7553
|
const registerTaskTask = CadenzaService.createMetaTask(
|
|
7380
7554
|
"Record registration",
|
|
7381
7555
|
(ctx, emit) => {
|
|
7382
|
-
|
|
7556
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7557
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7558
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
7559
|
+
if (!insertSucceeded) {
|
|
7383
7560
|
return;
|
|
7384
7561
|
}
|
|
7385
7562
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7386
7563
|
delayMs: 3e3
|
|
7387
7564
|
});
|
|
7388
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7389
7565
|
if (!task) {
|
|
7390
7566
|
return true;
|
|
7391
7567
|
}
|
|
@@ -7400,24 +7576,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7400
7576
|
}
|
|
7401
7577
|
).then(gatherTaskRegistrationTask);
|
|
7402
7578
|
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
7579
|
this.splitActorsForRegistration = CadenzaService.createMetaTask(
|
|
7422
7580
|
"Split actors for registration",
|
|
7423
7581
|
function* (ctx) {
|
|
@@ -7556,13 +7714,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7556
7714
|
const registerSignalTask = CadenzaService.createMetaTask(
|
|
7557
7715
|
"Record signal registration",
|
|
7558
7716
|
(ctx) => {
|
|
7717
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7718
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7559
7719
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7560
7720
|
return;
|
|
7561
7721
|
}
|
|
7562
7722
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7563
7723
|
delayMs: 3e3
|
|
7564
7724
|
});
|
|
7565
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7566
7725
|
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7567
7726
|
if (!task || !signalName) {
|
|
7568
7727
|
return true;
|
|
@@ -7574,7 +7733,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7574
7733
|
"Split observed signals of task",
|
|
7575
7734
|
function* (ctx) {
|
|
7576
7735
|
const task = ctx.task;
|
|
7577
|
-
if (task.hidden || !task.register || !task.registered)
|
|
7736
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
7737
|
+
return false;
|
|
7578
7738
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7579
7739
|
if (!serviceName2) {
|
|
7580
7740
|
return false;
|
|
@@ -7656,7 +7816,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7656
7816
|
);
|
|
7657
7817
|
const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
|
|
7658
7818
|
"Record intent definition registration",
|
|
7659
|
-
(ctx) => {
|
|
7819
|
+
(ctx, emit) => {
|
|
7660
7820
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7661
7821
|
return;
|
|
7662
7822
|
}
|
|
@@ -7664,6 +7824,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7664
7824
|
delayMs: 3e3
|
|
7665
7825
|
});
|
|
7666
7826
|
this.registeredIntentDefinitions.add(ctx.__intentName);
|
|
7827
|
+
emit(
|
|
7828
|
+
"meta.sync_controller.intent_registered",
|
|
7829
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
7830
|
+
__intentName: ctx.__intentName
|
|
7831
|
+
})
|
|
7832
|
+
);
|
|
7667
7833
|
return true;
|
|
7668
7834
|
}
|
|
7669
7835
|
).then(gatherIntentRegistrationTask);
|
|
@@ -7675,13 +7841,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7675
7841
|
const registerIntentTask = CadenzaService.createMetaTask(
|
|
7676
7842
|
"Record intent registration",
|
|
7677
7843
|
(ctx) => {
|
|
7844
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7678
7845
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7679
7846
|
return;
|
|
7680
7847
|
}
|
|
7681
7848
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7682
7849
|
delayMs: 3e3
|
|
7683
7850
|
});
|
|
7684
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7685
7851
|
if (!task) {
|
|
7686
7852
|
return true;
|
|
7687
7853
|
}
|
|
@@ -7693,7 +7859,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7693
7859
|
"Split intents of task",
|
|
7694
7860
|
function* (ctx) {
|
|
7695
7861
|
const task = ctx.task;
|
|
7696
|
-
if (task.hidden || !task.register || !task.registered)
|
|
7862
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
7863
|
+
return false;
|
|
7697
7864
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7698
7865
|
if (!serviceName2) {
|
|
7699
7866
|
return false;
|
|
@@ -7748,30 +7915,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7748
7915
|
return emittedCount > 0;
|
|
7749
7916
|
}.bind(this)
|
|
7750
7917
|
);
|
|
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
7918
|
const intentToTaskMapGraph = resolveSyncInsertTask(
|
|
7776
7919
|
this.isCadenzaDBReady,
|
|
7777
7920
|
"intent_to_task_map",
|
|
@@ -7790,20 +7933,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7790
7933
|
},
|
|
7791
7934
|
{ concurrency: 30 }
|
|
7792
7935
|
);
|
|
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
7936
|
wireSyncTaskGraph(
|
|
7806
|
-
|
|
7937
|
+
this.registerIntentToTaskMapTask,
|
|
7807
7938
|
intentToTaskMapGraph,
|
|
7808
7939
|
registerIntentTask
|
|
7809
7940
|
);
|
|
@@ -7814,7 +7945,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7814
7945
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7815
7946
|
delayMs: 3e3
|
|
7816
7947
|
});
|
|
7817
|
-
if (task.hidden || !task.register) return;
|
|
7948
|
+
if (task.hidden || !task.register || task.isDeputy) return;
|
|
7818
7949
|
const predecessorServiceName = resolveSyncServiceName(task);
|
|
7819
7950
|
if (!predecessorServiceName) {
|
|
7820
7951
|
return;
|
|
@@ -7948,452 +8079,583 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7948
8079
|
deputyRelationshipRegistrationGraph,
|
|
7949
8080
|
recordDeputyRelationshipRegistrationTask
|
|
7950
8081
|
);
|
|
7951
|
-
const
|
|
7952
|
-
|
|
7953
|
-
(
|
|
7954
|
-
|
|
7955
|
-
let changed = false;
|
|
7956
|
-
for (const row of authoritativeTasks) {
|
|
7957
|
-
const taskName = typeof row.name === "string" ? row.name : "";
|
|
7958
|
-
if (!taskName) {
|
|
7959
|
-
continue;
|
|
7960
|
-
}
|
|
7961
|
-
const task = CadenzaService.get(taskName);
|
|
7962
|
-
if (!task || task.registered) {
|
|
7963
|
-
continue;
|
|
7964
|
-
}
|
|
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
|
-
}
|
|
7974
|
-
if (authoritativeTasks.length > 0 || changed) {
|
|
7975
|
-
finalizeTaskSync(emit, {
|
|
7976
|
-
...ctx,
|
|
7977
|
-
__authoritativeReconciliation: true
|
|
7978
|
-
});
|
|
7979
|
-
}
|
|
7980
|
-
return changed;
|
|
7981
|
-
},
|
|
7982
|
-
"Marks local tasks as registered when authority rows already exist.",
|
|
7983
|
-
{
|
|
7984
|
-
register: false,
|
|
7985
|
-
isHidden: true
|
|
8082
|
+
const hasPendingDirectionalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8083
|
+
const taskWithDeputyState = task;
|
|
8084
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8085
|
+
return false;
|
|
7986
8086
|
}
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
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;
|
|
8087
|
+
const predecessorServiceName = resolveSyncServiceName(task);
|
|
8088
|
+
if (!predecessorServiceName) {
|
|
8089
|
+
return false;
|
|
8090
|
+
}
|
|
8091
|
+
for (const nextTask of task.nextTasks) {
|
|
8092
|
+
if (task.taskMapRegistration.has(nextTask.name) || nextTask.isHidden || !nextTask.register || !nextTask.registered) {
|
|
8093
|
+
continue;
|
|
8004
8094
|
}
|
|
8005
|
-
if (
|
|
8006
|
-
|
|
8007
|
-
...ctx,
|
|
8008
|
-
__authoritativeReconciliation: true
|
|
8009
|
-
});
|
|
8095
|
+
if (resolveSyncServiceName(nextTask)) {
|
|
8096
|
+
return true;
|
|
8010
8097
|
}
|
|
8011
|
-
return changed;
|
|
8012
|
-
},
|
|
8013
|
-
"Marks local routines as registered when authority rows already exist.",
|
|
8014
|
-
{
|
|
8015
|
-
register: false,
|
|
8016
|
-
isHidden: true
|
|
8017
8098
|
}
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8099
|
+
if (task.isDeputy && !taskWithDeputyState.signalName && !taskWithDeputyState.registeredDeputyMap) {
|
|
8100
|
+
return Boolean(resolveSyncServiceName(task) && resolveSyncServiceName());
|
|
8101
|
+
}
|
|
8102
|
+
return false;
|
|
8103
|
+
});
|
|
8104
|
+
const hasPendingSignalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8105
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8106
|
+
return false;
|
|
8107
|
+
}
|
|
8108
|
+
for (const signal of task.observedSignals) {
|
|
8109
|
+
if (task.registeredSignals.has(signal)) {
|
|
8110
|
+
continue;
|
|
8111
|
+
}
|
|
8112
|
+
const signalName = signal.split(":")[0];
|
|
8113
|
+
if (!decomposeSignalName(signalName).isGlobal) {
|
|
8114
|
+
continue;
|
|
8115
|
+
}
|
|
8116
|
+
if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
|
|
8117
|
+
continue;
|
|
8118
|
+
}
|
|
8119
|
+
return true;
|
|
8120
|
+
}
|
|
8121
|
+
return false;
|
|
8122
|
+
});
|
|
8123
|
+
const hasPendingIntentTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8124
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8125
|
+
return false;
|
|
8126
|
+
}
|
|
8127
|
+
const registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
|
|
8128
|
+
for (const intent of task.handlesIntents) {
|
|
8129
|
+
if (registeredIntents.has(intent) || isLocalOnlySyncIntent(intent)) {
|
|
8130
|
+
continue;
|
|
8131
|
+
}
|
|
8132
|
+
if (isMetaIntentName(intent) && !task.isMeta) {
|
|
8133
|
+
continue;
|
|
8134
|
+
}
|
|
8135
|
+
const intentDefinition = buildIntentRegistryData(CadenzaService.inquiryBroker.intents.get(intent)) ?? buildIntentRegistryData({ name: intent });
|
|
8136
|
+
if (!intentDefinition) {
|
|
8137
|
+
continue;
|
|
8138
|
+
}
|
|
8139
|
+
return true;
|
|
8140
|
+
}
|
|
8141
|
+
return false;
|
|
8142
|
+
});
|
|
8143
|
+
const hasPendingActorTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8144
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8145
|
+
return false;
|
|
8146
|
+
}
|
|
8147
|
+
const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
|
|
8148
|
+
if (!metadata?.actorName) {
|
|
8149
|
+
return false;
|
|
8150
|
+
}
|
|
8151
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8152
|
+
if (!serviceName2) {
|
|
8153
|
+
return false;
|
|
8154
|
+
}
|
|
8155
|
+
const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
|
|
8156
|
+
return !this.registeredActorTaskMaps.has(registrationKey);
|
|
8157
|
+
});
|
|
8158
|
+
const hasPendingRoutineTaskMaps = () => getRegistrableRoutines().some((routine) => {
|
|
8159
|
+
if (!routine.registered) {
|
|
8160
|
+
return false;
|
|
8161
|
+
}
|
|
8162
|
+
for (const task of routine.tasks) {
|
|
8163
|
+
if (!task) {
|
|
8164
|
+
continue;
|
|
8165
|
+
}
|
|
8166
|
+
const tasks = task.getIterator();
|
|
8167
|
+
while (tasks.hasNext()) {
|
|
8168
|
+
const nextTask = tasks.next();
|
|
8169
|
+
if (!nextTask?.registered) {
|
|
8028
8170
|
continue;
|
|
8029
8171
|
}
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
continue;
|
|
8172
|
+
if (!routine.registeredTasks.has(nextTask.name)) {
|
|
8173
|
+
return true;
|
|
8033
8174
|
}
|
|
8034
|
-
observer.registered = true;
|
|
8035
|
-
changed = true;
|
|
8036
8175
|
}
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8176
|
+
}
|
|
8177
|
+
return false;
|
|
8178
|
+
});
|
|
8179
|
+
const gatherDirectionalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8180
|
+
"Gather directional task map registration",
|
|
8181
|
+
(ctx) => {
|
|
8182
|
+
if (hasPendingDirectionalTaskMaps()) {
|
|
8183
|
+
this.directionalTaskMapsSynced = false;
|
|
8184
|
+
return false;
|
|
8042
8185
|
}
|
|
8043
|
-
|
|
8186
|
+
this.directionalTaskMapsSynced = true;
|
|
8187
|
+
return ctx;
|
|
8044
8188
|
},
|
|
8045
|
-
"
|
|
8189
|
+
"Completes directional task graph registration when task edges and deputy edges are registered.",
|
|
8046
8190
|
{
|
|
8047
8191
|
register: false,
|
|
8048
8192
|
isHidden: true
|
|
8049
8193
|
}
|
|
8050
8194
|
);
|
|
8051
|
-
const
|
|
8052
|
-
"
|
|
8195
|
+
const gatherSignalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8196
|
+
"Gather signal task map registration",
|
|
8197
|
+
(ctx) => {
|
|
8198
|
+
if (hasPendingSignalTaskMaps()) {
|
|
8199
|
+
this.signalTaskMapsSynced = false;
|
|
8200
|
+
return false;
|
|
8201
|
+
}
|
|
8202
|
+
this.signalTaskMapsSynced = true;
|
|
8203
|
+
return ctx;
|
|
8204
|
+
},
|
|
8205
|
+
"Completes signal-to-task map registration when all global observed signal edges are registered.",
|
|
8206
|
+
{
|
|
8207
|
+
register: false,
|
|
8208
|
+
isHidden: true
|
|
8209
|
+
}
|
|
8210
|
+
);
|
|
8211
|
+
const gatherIntentTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8212
|
+
"Gather intent task map registration",
|
|
8213
|
+
(ctx) => {
|
|
8214
|
+
if (hasPendingIntentTaskMaps()) {
|
|
8215
|
+
this.intentTaskMapsSynced = false;
|
|
8216
|
+
return false;
|
|
8217
|
+
}
|
|
8218
|
+
this.intentTaskMapsSynced = true;
|
|
8219
|
+
return ctx;
|
|
8220
|
+
},
|
|
8221
|
+
"Completes intent-to-task map registration when all task responders are registered.",
|
|
8222
|
+
{
|
|
8223
|
+
register: false,
|
|
8224
|
+
isHidden: true
|
|
8225
|
+
}
|
|
8226
|
+
);
|
|
8227
|
+
const gatherActorTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8228
|
+
"Gather actor task map registration",
|
|
8229
|
+
(ctx) => {
|
|
8230
|
+
if (hasPendingActorTaskMaps()) {
|
|
8231
|
+
this.actorTaskMapsSynced = false;
|
|
8232
|
+
return false;
|
|
8233
|
+
}
|
|
8234
|
+
this.actorTaskMapsSynced = true;
|
|
8235
|
+
return ctx;
|
|
8236
|
+
},
|
|
8237
|
+
"Completes actor-to-task map registration when all actor-backed tasks are registered.",
|
|
8238
|
+
{
|
|
8239
|
+
register: false,
|
|
8240
|
+
isHidden: true
|
|
8241
|
+
}
|
|
8242
|
+
);
|
|
8243
|
+
const gatherRoutineTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8244
|
+
"Gather routine task map registration",
|
|
8245
|
+
(ctx) => {
|
|
8246
|
+
if (hasPendingRoutineTaskMaps()) {
|
|
8247
|
+
this.routineTaskMapsSynced = false;
|
|
8248
|
+
return false;
|
|
8249
|
+
}
|
|
8250
|
+
this.routineTaskMapsSynced = true;
|
|
8251
|
+
return ctx;
|
|
8252
|
+
},
|
|
8253
|
+
"Completes task-to-routine map registration when all routine task memberships are registered.",
|
|
8254
|
+
{
|
|
8255
|
+
register: false,
|
|
8256
|
+
isHidden: true
|
|
8257
|
+
}
|
|
8258
|
+
);
|
|
8259
|
+
const finishSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8260
|
+
"Finish sync",
|
|
8053
8261
|
(ctx, emit) => {
|
|
8054
|
-
const
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8262
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8263
|
+
if (syncCycleId && this.activeSyncCycleId === syncCycleId) {
|
|
8264
|
+
this.activeSyncCycleId = null;
|
|
8265
|
+
this.activeSyncCycleStartedAt = 0;
|
|
8266
|
+
}
|
|
8267
|
+
if (this.pendingBootstrapSyncRerun) {
|
|
8268
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8269
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
8270
|
+
delayMs: 100
|
|
8271
|
+
});
|
|
8272
|
+
}
|
|
8273
|
+
emit("global.meta.sync_controller.synced", {
|
|
8274
|
+
data: {
|
|
8275
|
+
is_active: true,
|
|
8276
|
+
is_non_responsive: false,
|
|
8277
|
+
is_blocked: false,
|
|
8278
|
+
last_active: formatTimestamp(Date.now())
|
|
8279
|
+
},
|
|
8280
|
+
filter: {
|
|
8281
|
+
uuid: CadenzaService.serviceRegistry.serviceInstanceId
|
|
8063
8282
|
}
|
|
8064
|
-
|
|
8065
|
-
|
|
8283
|
+
});
|
|
8284
|
+
return true;
|
|
8285
|
+
},
|
|
8286
|
+
"Marks the current bootstrap sync cycle as complete.",
|
|
8287
|
+
{
|
|
8288
|
+
register: false,
|
|
8289
|
+
isHidden: true
|
|
8290
|
+
}
|
|
8291
|
+
).attachSignal("global.meta.sync_controller.synced");
|
|
8292
|
+
const mapPhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8293
|
+
"Complete map sync phase",
|
|
8294
|
+
(ctx) => {
|
|
8295
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8296
|
+
if (!syncCycleId) {
|
|
8297
|
+
return false;
|
|
8066
8298
|
}
|
|
8067
|
-
if (
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8299
|
+
if (!this.directionalTaskMapsSynced || !this.signalTaskMapsSynced || !this.intentTaskMapsSynced || !this.actorTaskMapsSynced || !this.routineTaskMapsSynced) {
|
|
8300
|
+
return false;
|
|
8301
|
+
}
|
|
8302
|
+
if (!markCompletedSyncCycle(this.mapPhaseCompletedCycles, syncCycleId)) {
|
|
8303
|
+
return false;
|
|
8072
8304
|
}
|
|
8073
|
-
return
|
|
8305
|
+
return ctx;
|
|
8074
8306
|
},
|
|
8075
|
-
"
|
|
8307
|
+
"Fans in map branch completion and ends the current sync cycle once every map branch is complete.",
|
|
8308
|
+
{
|
|
8309
|
+
register: false,
|
|
8310
|
+
isHidden: true
|
|
8311
|
+
}
|
|
8312
|
+
).then(finishSyncTask);
|
|
8313
|
+
const startDirectionalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8314
|
+
"Start directional task map sync",
|
|
8315
|
+
(ctx) => ctx,
|
|
8316
|
+
"Starts the directional task graph map branch for the current sync cycle.",
|
|
8076
8317
|
{
|
|
8077
8318
|
register: false,
|
|
8078
8319
|
isHidden: true
|
|
8079
8320
|
}
|
|
8080
8321
|
);
|
|
8081
|
-
const
|
|
8082
|
-
"
|
|
8083
|
-
() =>
|
|
8084
|
-
"
|
|
8322
|
+
const startSignalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8323
|
+
"Start signal task map sync",
|
|
8324
|
+
(ctx) => ctx,
|
|
8325
|
+
"Starts the signal-to-task map branch for the current sync cycle.",
|
|
8085
8326
|
{
|
|
8086
8327
|
register: false,
|
|
8087
8328
|
isHidden: true
|
|
8088
8329
|
}
|
|
8089
8330
|
);
|
|
8090
|
-
const
|
|
8091
|
-
"
|
|
8092
|
-
() =>
|
|
8093
|
-
"
|
|
8331
|
+
const startIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8332
|
+
"Start intent task map sync",
|
|
8333
|
+
(ctx) => ctx,
|
|
8334
|
+
"Starts the intent-to-task map branch for the current sync cycle.",
|
|
8094
8335
|
{
|
|
8095
8336
|
register: false,
|
|
8096
8337
|
isHidden: true
|
|
8097
8338
|
}
|
|
8098
8339
|
);
|
|
8099
|
-
const
|
|
8100
|
-
"
|
|
8101
|
-
() =>
|
|
8102
|
-
"
|
|
8340
|
+
const startActorTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8341
|
+
"Start actor task map sync",
|
|
8342
|
+
(ctx) => ctx,
|
|
8343
|
+
"Starts the actor-to-task map branch for the current sync cycle.",
|
|
8103
8344
|
{
|
|
8104
8345
|
register: false,
|
|
8105
8346
|
isHidden: true
|
|
8106
8347
|
}
|
|
8107
8348
|
);
|
|
8108
|
-
const
|
|
8109
|
-
"
|
|
8110
|
-
() =>
|
|
8111
|
-
"
|
|
8349
|
+
const startRoutineTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8350
|
+
"Start routine task map sync",
|
|
8351
|
+
(ctx) => ctx,
|
|
8352
|
+
"Starts the task-to-routine map branch for the current sync cycle.",
|
|
8112
8353
|
{
|
|
8113
8354
|
register: false,
|
|
8114
8355
|
isHidden: true
|
|
8115
8356
|
}
|
|
8116
8357
|
);
|
|
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",
|
|
8358
|
+
const primitivePhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8359
|
+
"Complete primitive sync phase",
|
|
8145
8360
|
(ctx) => {
|
|
8146
|
-
|
|
8361
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8362
|
+
if (!syncCycleId) {
|
|
8147
8363
|
return false;
|
|
8148
8364
|
}
|
|
8149
|
-
const serviceName2 = resolveSyncServiceName();
|
|
8150
|
-
if (!
|
|
8365
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8366
|
+
if (!this.tasksSynced || !this.signalsSynced || !this.intentsSynced || !this.actorsSynced || !this.routinesSynced) {
|
|
8151
8367
|
return false;
|
|
8152
8368
|
}
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
};
|
|
8369
|
+
if (!markCompletedSyncCycle(this.primitivePhaseCompletedCycles, syncCycleId)) {
|
|
8370
|
+
return false;
|
|
8371
|
+
}
|
|
8372
|
+
this.directionalTaskMapsSynced = false;
|
|
8373
|
+
this.signalTaskMapsSynced = false;
|
|
8374
|
+
this.intentTaskMapsSynced = false;
|
|
8375
|
+
this.actorTaskMapsSynced = false;
|
|
8376
|
+
this.routineTaskMapsSynced = false;
|
|
8377
|
+
return ctx;
|
|
8163
8378
|
},
|
|
8164
|
-
"
|
|
8379
|
+
"Fans in primitive registration and opens the map registration phase once every primitive branch is complete.",
|
|
8165
8380
|
{
|
|
8166
8381
|
register: false,
|
|
8167
8382
|
isHidden: true
|
|
8168
8383
|
}
|
|
8169
|
-
).
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8384
|
+
).then(
|
|
8385
|
+
startDirectionalTaskMapSyncTask,
|
|
8386
|
+
startSignalTaskMapSyncTask,
|
|
8387
|
+
startIntentTaskMapSyncTask,
|
|
8388
|
+
startActorTaskMapSyncTask,
|
|
8389
|
+
startRoutineTaskMapSyncTask
|
|
8390
|
+
);
|
|
8391
|
+
gatherTaskRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8392
|
+
gatherSignalRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8393
|
+
gatherIntentRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8394
|
+
gatherActorRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8395
|
+
gatherRoutineRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8396
|
+
const markLocalServiceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8397
|
+
"Mark local service inserted for bootstrap sync",
|
|
8174
8398
|
(ctx) => {
|
|
8175
|
-
if (!this.isCadenzaDBReady) {
|
|
8176
|
-
return false;
|
|
8177
|
-
}
|
|
8178
8399
|
const serviceName2 = resolveSyncServiceName();
|
|
8179
|
-
|
|
8400
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8401
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8180
8402
|
return false;
|
|
8181
8403
|
}
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
__syncServiceName: serviceName2,
|
|
8185
|
-
queryData: {
|
|
8186
|
-
filter: {
|
|
8187
|
-
service_name: serviceName2
|
|
8188
|
-
},
|
|
8189
|
-
fields: ["name", "version", "service_name"]
|
|
8190
|
-
}
|
|
8191
|
-
};
|
|
8404
|
+
this.localServiceInserted = true;
|
|
8405
|
+
return true;
|
|
8192
8406
|
},
|
|
8193
|
-
"
|
|
8407
|
+
"Marks that the local service row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8194
8408
|
{
|
|
8195
8409
|
register: false,
|
|
8196
8410
|
isHidden: true
|
|
8197
8411
|
}
|
|
8198
|
-
).doOn(
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
CadenzaService.createMetaTask(
|
|
8202
|
-
"Prepare authoritative signal registration query",
|
|
8412
|
+
).doOn("meta.service_registry.service_inserted");
|
|
8413
|
+
const markLocalServiceInstanceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8414
|
+
"Mark local service instance inserted for bootstrap sync",
|
|
8203
8415
|
(ctx) => {
|
|
8204
|
-
|
|
8416
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8417
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8418
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8205
8419
|
return false;
|
|
8206
8420
|
}
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
queryData: {
|
|
8210
|
-
fields: ["name"]
|
|
8211
|
-
}
|
|
8212
|
-
};
|
|
8421
|
+
this.localServiceInstanceInserted = true;
|
|
8422
|
+
return true;
|
|
8213
8423
|
},
|
|
8214
|
-
"
|
|
8424
|
+
"Marks that the local service instance row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8215
8425
|
{
|
|
8216
8426
|
register: false,
|
|
8217
8427
|
isHidden: true
|
|
8218
8428
|
}
|
|
8219
|
-
).doOn(
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
CadenzaService.createMetaTask(
|
|
8223
|
-
"Prepare authoritative intent registration query",
|
|
8429
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8430
|
+
const startBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8431
|
+
"Start bootstrap graph sync",
|
|
8224
8432
|
(ctx) => {
|
|
8225
|
-
|
|
8433
|
+
const now = Date.now();
|
|
8434
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8435
|
+
const serviceInstanceId = CadenzaService.serviceRegistry.serviceInstanceId;
|
|
8436
|
+
if (!serviceName2 || !serviceInstanceId) {
|
|
8437
|
+
return false;
|
|
8438
|
+
}
|
|
8439
|
+
if (!this.localServiceInserted) {
|
|
8440
|
+
return false;
|
|
8441
|
+
}
|
|
8442
|
+
if (!this.localServiceInstanceInserted) {
|
|
8226
8443
|
return false;
|
|
8227
8444
|
}
|
|
8445
|
+
if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
|
|
8446
|
+
return false;
|
|
8447
|
+
}
|
|
8448
|
+
if (this.activeSyncCycleId) {
|
|
8449
|
+
const activeCycleAgeMs = now - this.activeSyncCycleStartedAt;
|
|
8450
|
+
if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
|
|
8451
|
+
this.pendingBootstrapSyncRerun = true;
|
|
8452
|
+
return false;
|
|
8453
|
+
}
|
|
8454
|
+
}
|
|
8455
|
+
const syncCycleId = `${now}-${++this.syncCycleCounter}`;
|
|
8456
|
+
this.activeSyncCycleId = syncCycleId;
|
|
8457
|
+
this.activeSyncCycleStartedAt = now;
|
|
8458
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8459
|
+
this.tasksSynced = false;
|
|
8460
|
+
this.signalsSynced = false;
|
|
8461
|
+
this.intentsSynced = false;
|
|
8462
|
+
this.actorsSynced = false;
|
|
8463
|
+
this.routinesSynced = false;
|
|
8228
8464
|
return {
|
|
8229
8465
|
...ctx,
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8466
|
+
__syncing: true,
|
|
8467
|
+
__syncCycleId: syncCycleId,
|
|
8468
|
+
__serviceName: serviceName2,
|
|
8469
|
+
__serviceInstanceId: serviceInstanceId
|
|
8233
8470
|
};
|
|
8234
8471
|
},
|
|
8235
|
-
"
|
|
8472
|
+
"Starts a deterministic bootstrap sync cycle once the local service instance exists.",
|
|
8236
8473
|
{
|
|
8237
8474
|
register: false,
|
|
8238
8475
|
isHidden: true
|
|
8239
8476
|
}
|
|
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(
|
|
8477
|
+
).doOn(
|
|
8478
|
+
"meta.service_registry.service_inserted",
|
|
8479
|
+
"meta.service_registry.instance_inserted",
|
|
8274
8480
|
"meta.sync_controller.sync_tick",
|
|
8275
|
-
"meta.service_registry.initial_sync_complete",
|
|
8276
8481
|
"meta.sync_requested"
|
|
8277
|
-
)
|
|
8278
|
-
CadenzaService.createMetaTask(
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8482
|
+
);
|
|
8483
|
+
const startTaskPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8484
|
+
"Start task primitive sync",
|
|
8485
|
+
(ctx) => ctx,
|
|
8486
|
+
"Starts the task registration branch for the current sync cycle.",
|
|
8487
|
+
{
|
|
8488
|
+
register: false,
|
|
8489
|
+
isHidden: true
|
|
8282
8490
|
}
|
|
8283
|
-
return {
|
|
8284
|
-
...ctx,
|
|
8285
|
-
task
|
|
8286
|
-
};
|
|
8287
|
-
}).doOn("meta.sync_controller.task_registered").then(
|
|
8288
|
-
this.registerTaskMapTask,
|
|
8289
|
-
this.registerDeputyRelationshipTask
|
|
8290
8491
|
);
|
|
8291
|
-
CadenzaService.
|
|
8292
|
-
"
|
|
8293
|
-
|
|
8294
|
-
"
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
if (!task) {
|
|
8299
|
-
return false;
|
|
8492
|
+
const startSignalPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8493
|
+
"Start signal primitive sync",
|
|
8494
|
+
(ctx) => ctx,
|
|
8495
|
+
"Starts the signal registration branch for the current sync cycle.",
|
|
8496
|
+
{
|
|
8497
|
+
register: false,
|
|
8498
|
+
isHidden: true
|
|
8300
8499
|
}
|
|
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;
|
|
8500
|
+
);
|
|
8501
|
+
const startIntentPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8502
|
+
"Start intent primitive sync",
|
|
8503
|
+
(ctx) => ctx,
|
|
8504
|
+
"Starts the intent registration branch for the current sync cycle.",
|
|
8505
|
+
{
|
|
8506
|
+
register: false,
|
|
8507
|
+
isHidden: true
|
|
8315
8508
|
}
|
|
8316
|
-
|
|
8509
|
+
);
|
|
8510
|
+
const startActorPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8511
|
+
"Start actor primitive sync",
|
|
8512
|
+
(ctx) => ctx,
|
|
8513
|
+
"Starts the actor registration branch for the current sync cycle.",
|
|
8514
|
+
{
|
|
8515
|
+
register: false,
|
|
8516
|
+
isHidden: true
|
|
8517
|
+
}
|
|
8518
|
+
);
|
|
8519
|
+
const startRoutinePrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8520
|
+
"Start routine primitive sync",
|
|
8521
|
+
(ctx) => ctx,
|
|
8522
|
+
"Starts the routine registration branch for the current sync cycle.",
|
|
8523
|
+
{
|
|
8524
|
+
register: false,
|
|
8525
|
+
isHidden: true
|
|
8526
|
+
}
|
|
8527
|
+
);
|
|
8528
|
+
startBootstrapSyncTask.then(
|
|
8529
|
+
startTaskPrimitiveSyncTask,
|
|
8530
|
+
startSignalPrimitiveSyncTask,
|
|
8531
|
+
startIntentPrimitiveSyncTask,
|
|
8532
|
+
startActorPrimitiveSyncTask,
|
|
8533
|
+
startRoutinePrimitiveSyncTask
|
|
8534
|
+
);
|
|
8535
|
+
const getAllTasksForSyncTask = CadenzaService.registry.getAllTasks.clone();
|
|
8536
|
+
startTaskPrimitiveSyncTask.then(
|
|
8537
|
+
getAllTasksForSyncTask,
|
|
8538
|
+
gatherTaskRegistrationTask
|
|
8539
|
+
);
|
|
8540
|
+
getAllTasksForSyncTask.then(this.splitTasksForRegistration);
|
|
8541
|
+
const getSignalsForSyncTask = CadenzaService.signalBroker.getSignalsTask.clone();
|
|
8542
|
+
startSignalPrimitiveSyncTask.then(
|
|
8543
|
+
getSignalsForSyncTask,
|
|
8544
|
+
gatherSignalRegistrationTask
|
|
8545
|
+
);
|
|
8546
|
+
getSignalsForSyncTask.then(this.splitSignalsTask);
|
|
8547
|
+
const getAllIntentsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8548
|
+
"Get all intents for sync",
|
|
8549
|
+
(ctx) => ({
|
|
8317
8550
|
...ctx,
|
|
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;
|
|
8551
|
+
intents: Array.from(CadenzaService.inquiryBroker.intents.values())
|
|
8552
|
+
}),
|
|
8553
|
+
"Collects local intents for the primitive sync phase.",
|
|
8554
|
+
{
|
|
8555
|
+
register: false,
|
|
8556
|
+
isHidden: true
|
|
8330
8557
|
}
|
|
8331
|
-
|
|
8558
|
+
);
|
|
8559
|
+
startIntentPrimitiveSyncTask.then(
|
|
8560
|
+
getAllIntentsForSyncTask,
|
|
8561
|
+
gatherIntentRegistrationTask
|
|
8562
|
+
);
|
|
8563
|
+
getAllIntentsForSyncTask.then(this.splitIntentsTask);
|
|
8564
|
+
const getAllActorsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8565
|
+
"Get all actors for sync",
|
|
8566
|
+
(ctx) => ({
|
|
8332
8567
|
...ctx,
|
|
8333
|
-
|
|
8334
|
-
}
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
return false;
|
|
8341
|
-
}
|
|
8342
|
-
return ctx;
|
|
8343
|
-
}
|
|
8344
|
-
).then(this.registerActorTaskMapTask)
|
|
8568
|
+
actors: CadenzaService.getAllActors()
|
|
8569
|
+
}),
|
|
8570
|
+
"Collects local actors for the primitive sync phase.",
|
|
8571
|
+
{
|
|
8572
|
+
register: false,
|
|
8573
|
+
isHidden: true
|
|
8574
|
+
}
|
|
8345
8575
|
);
|
|
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)
|
|
8576
|
+
startActorPrimitiveSyncTask.then(
|
|
8577
|
+
getAllActorsForSyncTask,
|
|
8578
|
+
gatherActorRegistrationTask
|
|
8360
8579
|
);
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8580
|
+
getAllActorsForSyncTask.then(this.splitActorsForRegistration);
|
|
8581
|
+
const getAllRoutinesForSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
8582
|
+
startRoutinePrimitiveSyncTask.then(
|
|
8583
|
+
getAllRoutinesForSyncTask,
|
|
8584
|
+
gatherRoutineRegistrationTask
|
|
8585
|
+
);
|
|
8586
|
+
getAllRoutinesForSyncTask.then(this.splitRoutinesTask);
|
|
8587
|
+
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8588
|
+
startDirectionalTaskMapSyncTask.then(
|
|
8589
|
+
iterateTasksForDirectionalTaskMapSyncTask,
|
|
8590
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
8591
|
+
);
|
|
8592
|
+
iterateTasksForDirectionalTaskMapSyncTask.then(
|
|
8593
|
+
this.registerTaskMapTask,
|
|
8594
|
+
this.registerDeputyRelationshipTask
|
|
8595
|
+
);
|
|
8596
|
+
recordTaskMapRegistrationTask.then(gatherDirectionalTaskMapRegistrationTask);
|
|
8597
|
+
recordDeputyRelationshipRegistrationTask.then(
|
|
8598
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
8599
|
+
);
|
|
8600
|
+
gatherDirectionalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8601
|
+
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8602
|
+
startSignalTaskMapSyncTask.then(
|
|
8603
|
+
iterateTasksForSignalTaskMapSyncTask,
|
|
8604
|
+
gatherSignalTaskMapRegistrationTask
|
|
8605
|
+
);
|
|
8606
|
+
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
8607
|
+
registerSignalTask.then(gatherSignalTaskMapRegistrationTask);
|
|
8608
|
+
gatherSignalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8609
|
+
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8610
|
+
startIntentTaskMapSyncTask.then(
|
|
8611
|
+
iterateTasksForIntentTaskMapSyncTask,
|
|
8612
|
+
gatherIntentTaskMapRegistrationTask
|
|
8613
|
+
);
|
|
8614
|
+
iterateTasksForIntentTaskMapSyncTask.then(this.registerIntentToTaskMapTask);
|
|
8615
|
+
registerIntentTask.then(gatherIntentTaskMapRegistrationTask);
|
|
8616
|
+
gatherIntentTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8617
|
+
const iterateTasksForActorTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8618
|
+
startActorTaskMapSyncTask.then(
|
|
8619
|
+
iterateTasksForActorTaskMapSyncTask,
|
|
8620
|
+
gatherActorTaskMapRegistrationTask
|
|
8621
|
+
);
|
|
8622
|
+
iterateTasksForActorTaskMapSyncTask.then(this.registerActorTaskMapTask);
|
|
8623
|
+
recordActorTaskMapRegistrationTask.then(gatherActorTaskMapRegistrationTask);
|
|
8624
|
+
gatherActorTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8625
|
+
const getAllRoutinesForTaskMapSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
8626
|
+
startRoutineTaskMapSyncTask.then(
|
|
8627
|
+
getAllRoutinesForTaskMapSyncTask,
|
|
8628
|
+
gatherRoutineTaskMapRegistrationTask
|
|
8629
|
+
);
|
|
8630
|
+
getAllRoutinesForTaskMapSyncTask.then(this.splitTasksInRoutines);
|
|
8631
|
+
registerTaskToRoutineMapTask.then(gatherRoutineTaskMapRegistrationTask);
|
|
8632
|
+
gatherRoutineTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8633
|
+
CadenzaService.createMetaTask(
|
|
8634
|
+
"Request sync after local service instance registration",
|
|
8635
|
+
(ctx) => {
|
|
8636
|
+
for (const delayMs of EARLY_SYNC_TICK_DELAYS_MS) {
|
|
8637
|
+
CadenzaService.schedule(
|
|
8638
|
+
"meta.sync_controller.sync_tick",
|
|
8639
|
+
{
|
|
8640
|
+
...buildMinimalSyncSignalContext(ctx),
|
|
8641
|
+
__syncing: true
|
|
8642
|
+
},
|
|
8643
|
+
delayMs
|
|
8644
|
+
);
|
|
8371
8645
|
}
|
|
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);
|
|
8646
|
+
return true;
|
|
8647
|
+
},
|
|
8648
|
+
"Schedules the early bootstrap sync burst after local instance registration so startup-defined primitives can converge deterministically.",
|
|
8649
|
+
{
|
|
8650
|
+
register: false,
|
|
8651
|
+
isHidden: true
|
|
8395
8652
|
}
|
|
8396
|
-
|
|
8653
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8654
|
+
CadenzaService.interval(
|
|
8655
|
+
"meta.sync_controller.sync_tick",
|
|
8656
|
+
{ __syncing: true },
|
|
8657
|
+
this.isCadenzaDBReady ? 18e4 : 3e5
|
|
8658
|
+
);
|
|
8397
8659
|
}
|
|
8398
8660
|
};
|
|
8399
8661
|
|
|
@@ -8568,6 +8830,47 @@ function resolveBootstrapEndpoint(options) {
|
|
|
8568
8830
|
|
|
8569
8831
|
// src/Cadenza.ts
|
|
8570
8832
|
var CadenzaService = class {
|
|
8833
|
+
static replayRegisteredTaskIntentAssociations() {
|
|
8834
|
+
for (const task of this.registry.tasks.values()) {
|
|
8835
|
+
if (!task.register || task.isHidden || task.handlesIntents.size === 0) {
|
|
8836
|
+
continue;
|
|
8837
|
+
}
|
|
8838
|
+
for (const intentName of task.handlesIntents) {
|
|
8839
|
+
task.emitWithMetadata("meta.task.intent_associated", {
|
|
8840
|
+
data: {
|
|
8841
|
+
intentName,
|
|
8842
|
+
taskName: task.name,
|
|
8843
|
+
taskVersion: task.version
|
|
8844
|
+
},
|
|
8845
|
+
taskInstance: task,
|
|
8846
|
+
__isSubMeta: task.isSubMeta
|
|
8847
|
+
});
|
|
8848
|
+
}
|
|
8849
|
+
}
|
|
8850
|
+
}
|
|
8851
|
+
static replayRegisteredTaskSignalObservations() {
|
|
8852
|
+
for (const task of this.registry.tasks.values()) {
|
|
8853
|
+
if (!task.register || task.isHidden || task.observedSignals.size === 0) {
|
|
8854
|
+
continue;
|
|
8855
|
+
}
|
|
8856
|
+
for (const signalName of task.observedSignals) {
|
|
8857
|
+
task.emitWithMetadata("meta.task.observed_signal", {
|
|
8858
|
+
data: {
|
|
8859
|
+
signalName,
|
|
8860
|
+
taskName: task.name,
|
|
8861
|
+
taskVersion: task.version
|
|
8862
|
+
},
|
|
8863
|
+
taskInstance: task,
|
|
8864
|
+
signalName,
|
|
8865
|
+
__isSubMeta: task.isSubMeta
|
|
8866
|
+
});
|
|
8867
|
+
}
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8870
|
+
static replayRegisteredTaskGraphMetadata() {
|
|
8871
|
+
this.replayRegisteredTaskSignalObservations();
|
|
8872
|
+
this.replayRegisteredTaskIntentAssociations();
|
|
8873
|
+
}
|
|
8571
8874
|
static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
|
|
8572
8875
|
const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
8573
8876
|
const helperSuffix = camelCase(String(tableName ?? "").trim());
|
|
@@ -9436,6 +9739,7 @@ var CadenzaService = class {
|
|
|
9436
9739
|
const serviceId = options.customServiceId ?? uuid5();
|
|
9437
9740
|
this.serviceRegistry.serviceName = serviceName;
|
|
9438
9741
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
9742
|
+
this.serviceRegistry.connectsToCadenzaDB = !!options.cadenzaDB?.connect;
|
|
9439
9743
|
this.setHydrationResults(options.hydration);
|
|
9440
9744
|
const explicitFrontendMode = options.isFrontend;
|
|
9441
9745
|
options = {
|
|
@@ -9464,6 +9768,22 @@ var CadenzaService = class {
|
|
|
9464
9768
|
this.serviceRegistry.useSocket = !!options.useSocket;
|
|
9465
9769
|
this.serviceRegistry.retryCount = options.retryCount ?? 3;
|
|
9466
9770
|
this.ensureTransportControllers(isFrontend);
|
|
9771
|
+
if (!isFrontend) {
|
|
9772
|
+
this.createMetaTask(
|
|
9773
|
+
"Initialize graph metadata controller after initial sync",
|
|
9774
|
+
() => {
|
|
9775
|
+
GraphMetadataController.instance;
|
|
9776
|
+
return true;
|
|
9777
|
+
},
|
|
9778
|
+
"Delays direct graph-metadata registration until the bootstrap sync has completed.",
|
|
9779
|
+
{
|
|
9780
|
+
register: false,
|
|
9781
|
+
isHidden: true
|
|
9782
|
+
}
|
|
9783
|
+
).doOn("meta.service_registry.initial_sync_complete");
|
|
9784
|
+
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB";
|
|
9785
|
+
GraphSyncController.instance.init();
|
|
9786
|
+
}
|
|
9467
9787
|
const resolvedBootstrapEndpoint = options.cadenzaDB?.connect ? resolveBootstrapEndpoint({
|
|
9468
9788
|
runtime: isFrontend ? "browser" : "server",
|
|
9469
9789
|
bootstrap: options.bootstrap,
|
|
@@ -9575,14 +9895,13 @@ var CadenzaService = class {
|
|
|
9575
9895
|
);
|
|
9576
9896
|
}).doOn("meta.rest.handshake", "meta.socket.handshake");
|
|
9577
9897
|
}
|
|
9578
|
-
this.createMetaTask("Handle service setup completion", () => {
|
|
9898
|
+
this.createMetaTask("Handle service setup completion", (ctx, emit) => {
|
|
9899
|
+
if (options.cadenzaDB?.connect) {
|
|
9900
|
+
this.serviceRegistry.bootstrapFullSync(emit, ctx, "service_setup_completed");
|
|
9901
|
+
}
|
|
9579
9902
|
if (isFrontend) {
|
|
9580
9903
|
registerActorSessionPersistenceTasks();
|
|
9581
9904
|
this.ensureFrontendSyncLoop();
|
|
9582
|
-
} else {
|
|
9583
|
-
GraphMetadataController.instance;
|
|
9584
|
-
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB" || !!options.cadenzaDB?.connect;
|
|
9585
|
-
GraphSyncController.instance.init();
|
|
9586
9905
|
}
|
|
9587
9906
|
this.log("Service created.");
|
|
9588
9907
|
return true;
|
|
@@ -9611,7 +9930,15 @@ var CadenzaService = class {
|
|
|
9611
9930
|
is_blocked: false,
|
|
9612
9931
|
health: {}
|
|
9613
9932
|
},
|
|
9614
|
-
__transportData:
|
|
9933
|
+
__transportData: declaredTransports.map((transport) => ({
|
|
9934
|
+
uuid: transport.uuid,
|
|
9935
|
+
service_instance_id: serviceId,
|
|
9936
|
+
role: transport.role,
|
|
9937
|
+
origin: transport.origin,
|
|
9938
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
9939
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
9940
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
9941
|
+
})),
|
|
9615
9942
|
__serviceName: serviceName,
|
|
9616
9943
|
__serviceInstanceId: serviceId,
|
|
9617
9944
|
__useSocket: options.useSocket,
|