@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.js
CHANGED
|
@@ -739,6 +739,21 @@ var CADENZA_DB_GATHERED_SYNC_SIGNAL = "global.meta.cadenza_db.gathered_sync_data
|
|
|
739
739
|
var META_GATHERED_SYNC_TRANSMISSION_RECONCILE_SIGNAL = "meta.service_registry.gathered_sync_transmission_reconcile_requested";
|
|
740
740
|
var META_RUNTIME_STATUS_HEARTBEAT_TICK_SIGNAL = "meta.service_registry.runtime_status.heartbeat_tick";
|
|
741
741
|
var META_RUNTIME_STATUS_MONITOR_TICK_SIGNAL = "meta.service_registry.runtime_status.monitor_tick";
|
|
742
|
+
var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
743
|
+
100,
|
|
744
|
+
1500,
|
|
745
|
+
5e3,
|
|
746
|
+
12e3,
|
|
747
|
+
25e3,
|
|
748
|
+
45e3,
|
|
749
|
+
7e4
|
|
750
|
+
];
|
|
751
|
+
var BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS = [
|
|
752
|
+
"Query service_instance",
|
|
753
|
+
"Query service_instance_transport",
|
|
754
|
+
"Query signal_to_task_map",
|
|
755
|
+
"Query intent_to_task_map"
|
|
756
|
+
];
|
|
742
757
|
var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
|
|
743
758
|
"Track local routine start",
|
|
744
759
|
"Track local routine end",
|
|
@@ -880,6 +895,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
880
895
|
ctx.__resolverQueryData ?? ctx.queryData ?? {},
|
|
881
896
|
ctx
|
|
882
897
|
);
|
|
898
|
+
if (tableName === "service_instance" && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
899
|
+
console.log("[CADENZA_INSTANCE_DEBUG] finalize_service_registry_insert", {
|
|
900
|
+
tableName,
|
|
901
|
+
hasNormalized: !!normalized,
|
|
902
|
+
normalizedKeys: normalized && typeof normalized === "object" ? Object.keys(normalized) : [],
|
|
903
|
+
uuid: normalized && typeof normalized === "object" ? normalized.uuid ?? normalized.data?.uuid ?? normalized.queryData?.data?.uuid ?? null : null,
|
|
904
|
+
serviceName: normalized && typeof normalized === "object" ? normalized.__serviceName ?? normalized.data?.service_name ?? normalized.queryData?.data?.service_name ?? null : null,
|
|
905
|
+
errored: normalized && typeof normalized === "object" ? normalized.errored === true : false,
|
|
906
|
+
error: normalized && typeof normalized === "object" ? normalized.__error ?? null : null,
|
|
907
|
+
inquiryMeta: normalized && typeof normalized === "object" ? normalized.__inquiryMeta ?? null : null
|
|
908
|
+
});
|
|
909
|
+
}
|
|
883
910
|
if (!normalized || typeof normalized !== "object") {
|
|
884
911
|
return normalized;
|
|
885
912
|
}
|
|
@@ -924,6 +951,18 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
|
|
|
924
951
|
).doOn(executionResolvedSignal, executionFailedSignal);
|
|
925
952
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
926
953
|
const executionSignal = localInsertTask ? localExecutionRequestedSignal : remoteExecutionRequestedSignal;
|
|
954
|
+
if (tableName === "service_instance" && (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true")) {
|
|
955
|
+
console.log("[CADENZA_INSTANCE_DEBUG] resolve_service_registry_insert", {
|
|
956
|
+
tableName,
|
|
957
|
+
executionSignal,
|
|
958
|
+
hasLocalInsertTask: !!localInsertTask,
|
|
959
|
+
serviceName: ctx.__serviceName ?? ctx.data?.service_name ?? null,
|
|
960
|
+
serviceInstanceId: ctx.__serviceInstanceId ?? ctx.data?.uuid ?? null,
|
|
961
|
+
hasData: !!ctx.data,
|
|
962
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
963
|
+
registrationKeys: ctx.__registrationData && typeof ctx.__registrationData === "object" ? Object.keys(ctx.__registrationData) : []
|
|
964
|
+
});
|
|
965
|
+
}
|
|
927
966
|
if (localInsertTask && !wiredLocalTaskNames.has(localInsertTask.name)) {
|
|
928
967
|
wireExecutionTarget(localInsertTask, prepareLocalExecutionTask);
|
|
929
968
|
wiredLocalTaskNames.add(localInsertTask.name);
|
|
@@ -1006,6 +1045,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1006
1045
|
this.useSocket = false;
|
|
1007
1046
|
this.retryCount = 3;
|
|
1008
1047
|
this.isFrontend = false;
|
|
1048
|
+
this.connectsToCadenzaDB = false;
|
|
1009
1049
|
CadenzaService.defineIntent({
|
|
1010
1050
|
name: META_RUNTIME_TRANSPORT_DIAGNOSTICS_INTENT,
|
|
1011
1051
|
description: "Gather transport diagnostics across all services and communication clients.",
|
|
@@ -1380,7 +1420,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1380
1420
|
return true;
|
|
1381
1421
|
},
|
|
1382
1422
|
"Handles registration of remote signals"
|
|
1383
|
-
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1423
|
+
).emits("meta.service_registry.registered_global_signals").doOn(
|
|
1424
|
+
"global.meta.cadenza_db.gathered_sync_data",
|
|
1425
|
+
"global.meta.graph_metadata.task_signal_observed"
|
|
1426
|
+
);
|
|
1384
1427
|
this.reconcileGatheredSyncTransmissionsTask = CadenzaService.createMetaTask(
|
|
1385
1428
|
"Reconcile gathered sync signal transmissions",
|
|
1386
1429
|
(ctx, emit) => this.reconcileGatheredSyncTransmissions(ctx, emit),
|
|
@@ -1534,7 +1577,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1534
1577
|
);
|
|
1535
1578
|
this.handleSocketStatusUpdateTask = CadenzaService.createMetaTask(
|
|
1536
1579
|
"Handle Socket Status Update",
|
|
1537
|
-
(ctx) => {
|
|
1580
|
+
(ctx, emit) => {
|
|
1538
1581
|
const report = this.normalizeRuntimeStatusReport(ctx);
|
|
1539
1582
|
if (!report) {
|
|
1540
1583
|
return false;
|
|
@@ -1577,6 +1620,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1577
1620
|
if (!applied) {
|
|
1578
1621
|
return false;
|
|
1579
1622
|
}
|
|
1623
|
+
const updatedInstance = this.getInstance(
|
|
1624
|
+
report.serviceName,
|
|
1625
|
+
report.serviceInstanceId
|
|
1626
|
+
);
|
|
1627
|
+
if (updatedInstance && !updatedInstance.isFrontend && (this.deputies.has(report.serviceName) || this.remoteIntents.has(report.serviceName) || this.remoteSignals.has(report.serviceName))) {
|
|
1628
|
+
this.ensureDependeeClientForInstance(updatedInstance, emit, ctx);
|
|
1629
|
+
}
|
|
1580
1630
|
this.registerDependee(report.serviceName, report.serviceInstanceId);
|
|
1581
1631
|
this.lastHeartbeatAtByInstance.set(report.serviceInstanceId, Date.now());
|
|
1582
1632
|
this.missedHeartbeatsByInstance.set(report.serviceInstanceId, 0);
|
|
@@ -1587,9 +1637,23 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1587
1637
|
},
|
|
1588
1638
|
"Handles status update from socket broadcast"
|
|
1589
1639
|
).doOn("meta.socket_client.status_received");
|
|
1640
|
+
CadenzaService.createMetaTask(
|
|
1641
|
+
"Request full sync after CadenzaDB fetch handshake",
|
|
1642
|
+
(ctx) => {
|
|
1643
|
+
const serviceName = typeof ctx.serviceName === "string" ? ctx.serviceName.trim() : typeof ctx.__serviceName === "string" ? ctx.__serviceName.trim() : "";
|
|
1644
|
+
if (serviceName !== "CadenzaDB") {
|
|
1645
|
+
return false;
|
|
1646
|
+
}
|
|
1647
|
+
return this.scheduleEarlyFullSyncRequests("cadenza_db_fetch_handshake");
|
|
1648
|
+
},
|
|
1649
|
+
"Schedules a few early service-registry full-sync retries after the authority fetch transport comes up."
|
|
1650
|
+
).doOn("meta.fetch.handshake_complete");
|
|
1590
1651
|
this.fullSyncTask = CadenzaService.createMetaTask(
|
|
1591
1652
|
"Full sync",
|
|
1592
1653
|
async (ctx) => {
|
|
1654
|
+
if (this.connectsToCadenzaDB && this.serviceName !== "CadenzaDB" && !this.hasBootstrapFullSyncDeputies()) {
|
|
1655
|
+
return false;
|
|
1656
|
+
}
|
|
1593
1657
|
const inquiryResult = await CadenzaService.inquire(
|
|
1594
1658
|
META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
1595
1659
|
{
|
|
@@ -1646,7 +1710,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1646
1710
|
);
|
|
1647
1711
|
this.handleDeputyRegistrationTask = CadenzaService.createMetaTask(
|
|
1648
1712
|
"Handle Deputy Registration",
|
|
1649
|
-
(ctx) => {
|
|
1713
|
+
(ctx, emit) => {
|
|
1650
1714
|
const { serviceName } = ctx;
|
|
1651
1715
|
if (!this.deputies.has(serviceName)) this.deputies.set(serviceName, []);
|
|
1652
1716
|
this.deputies.get(serviceName).push({
|
|
@@ -1656,6 +1720,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1656
1720
|
localTaskName: ctx.localTaskName,
|
|
1657
1721
|
communicationType: ctx.communicationType
|
|
1658
1722
|
});
|
|
1723
|
+
this.ensureDependeeClientsForService(serviceName, emit, ctx);
|
|
1659
1724
|
}
|
|
1660
1725
|
).doOn("meta.deputy.created");
|
|
1661
1726
|
this.getAllInstances = CadenzaService.createMetaTask(
|
|
@@ -2208,9 +2273,29 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2208
2273
|
retryDelayFactor: 1.3
|
|
2209
2274
|
}
|
|
2210
2275
|
).emits("meta.service_registry.service_inserted").emitsOnFail("meta.service_registry.service_insertion_failed");
|
|
2211
|
-
|
|
2276
|
+
const insertServiceInstanceResolverTask = resolveServiceRegistryInsertTask(
|
|
2212
2277
|
"service_instance",
|
|
2213
|
-
{
|
|
2278
|
+
{
|
|
2279
|
+
onConflict: {
|
|
2280
|
+
target: ["uuid"],
|
|
2281
|
+
action: {
|
|
2282
|
+
do: "update",
|
|
2283
|
+
set: {
|
|
2284
|
+
process_pid: "excluded",
|
|
2285
|
+
is_primary: "excluded",
|
|
2286
|
+
service_name: "excluded",
|
|
2287
|
+
is_database: "excluded",
|
|
2288
|
+
is_frontend: "excluded",
|
|
2289
|
+
is_blocked: "excluded",
|
|
2290
|
+
is_non_responsive: "excluded",
|
|
2291
|
+
is_active: "excluded",
|
|
2292
|
+
last_active: "excluded",
|
|
2293
|
+
health: "excluded",
|
|
2294
|
+
deleted: "false"
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
},
|
|
2214
2299
|
{
|
|
2215
2300
|
inputSchema: {
|
|
2216
2301
|
type: "object",
|
|
@@ -2266,7 +2351,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2266
2351
|
retryCount: 5,
|
|
2267
2352
|
retryDelay: 1e3
|
|
2268
2353
|
}
|
|
2269
|
-
).
|
|
2354
|
+
).emitsOnFail("meta.service_registry.instance_insertion_failed");
|
|
2355
|
+
this.insertServiceInstanceTask = insertServiceInstanceResolverTask.then(
|
|
2270
2356
|
CadenzaService.createMetaTask(
|
|
2271
2357
|
"Setup service",
|
|
2272
2358
|
(ctx) => {
|
|
@@ -2283,6 +2369,21 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2283
2369
|
transports: ctx.__transportData ?? ctx.transportData ?? []
|
|
2284
2370
|
});
|
|
2285
2371
|
if (!normalizedLocalInstance?.uuid || !normalizedLocalInstance.serviceName) {
|
|
2372
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2373
|
+
console.log("[CADENZA_INSTANCE_DEBUG] setup_service_rejected_instance", {
|
|
2374
|
+
hasServiceInstance: !!serviceInstance,
|
|
2375
|
+
hasData: !!data,
|
|
2376
|
+
hasQueryDataData: !!queryData?.data,
|
|
2377
|
+
serviceInstanceKeys: serviceInstance && typeof serviceInstance === "object" ? Object.keys(serviceInstance) : [],
|
|
2378
|
+
dataKeys: data && typeof data === "object" ? Object.keys(data) : [],
|
|
2379
|
+
queryDataDataKeys: queryData?.data && typeof queryData.data === "object" ? Object.keys(queryData.data) : [],
|
|
2380
|
+
normalizedLocalInstance,
|
|
2381
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2382
|
+
errored: ctx.errored === true,
|
|
2383
|
+
error: ctx.__error ?? null,
|
|
2384
|
+
inquiryMeta: ctx.__inquiryMeta ?? null
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2286
2387
|
return false;
|
|
2287
2388
|
}
|
|
2288
2389
|
this.serviceInstanceId = normalizedLocalInstance.uuid;
|
|
@@ -2334,9 +2435,41 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2334
2435
|
).attachSignal("meta.service_registry.transport_registration_requested")
|
|
2335
2436
|
)
|
|
2336
2437
|
);
|
|
2438
|
+
CadenzaService.createMetaTask(
|
|
2439
|
+
"Retry local service instance registration after failed insert",
|
|
2440
|
+
(ctx) => {
|
|
2441
|
+
const serviceName = String(
|
|
2442
|
+
ctx.__serviceName ?? ctx.data?.service_name ?? this.serviceName ?? ""
|
|
2443
|
+
).trim();
|
|
2444
|
+
if (!serviceName || serviceName !== this.serviceName) {
|
|
2445
|
+
return false;
|
|
2446
|
+
}
|
|
2447
|
+
CadenzaService.schedule(
|
|
2448
|
+
"meta.service_registry.instance_registration_requested",
|
|
2449
|
+
{ ...ctx },
|
|
2450
|
+
5e3
|
|
2451
|
+
);
|
|
2452
|
+
return true;
|
|
2453
|
+
},
|
|
2454
|
+
"Retries local service instance registration only after the previous insert attempt has failed.",
|
|
2455
|
+
{
|
|
2456
|
+
register: false,
|
|
2457
|
+
isHidden: true
|
|
2458
|
+
}
|
|
2459
|
+
).doOn("meta.service_registry.instance_insertion_failed");
|
|
2337
2460
|
CadenzaService.createMetaTask(
|
|
2338
2461
|
"Prepare service instance registration",
|
|
2339
2462
|
(ctx) => {
|
|
2463
|
+
if (process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") {
|
|
2464
|
+
console.log("[CADENZA_INSTANCE_DEBUG] prepare_service_instance_registration", {
|
|
2465
|
+
serviceName: ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? null,
|
|
2466
|
+
serviceInstanceId: ctx.data?.uuid ?? ctx.__serviceInstanceId ?? this.serviceInstanceId ?? null,
|
|
2467
|
+
hasData: !!ctx.data,
|
|
2468
|
+
dataKeys: ctx.data && typeof ctx.data === "object" ? Object.keys(ctx.data) : [],
|
|
2469
|
+
transportCount: Array.isArray(ctx.__transportData) ? ctx.__transportData.length : Array.isArray(ctx.transportData) ? ctx.transportData.length : 0,
|
|
2470
|
+
skipRemoteExecution: ctx.__skipRemoteExecution === true
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2340
2473
|
const serviceName = String(
|
|
2341
2474
|
ctx.data?.service_name ?? ctx.__serviceName ?? this.serviceName ?? ""
|
|
2342
2475
|
).trim();
|
|
@@ -2529,21 +2662,40 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2529
2662
|
return [];
|
|
2530
2663
|
}
|
|
2531
2664
|
normalizeSignalMaps(ctx) {
|
|
2532
|
-
|
|
2665
|
+
const arrayPayload = this.readArrayPayload(ctx, [
|
|
2533
2666
|
"signalToTaskMaps",
|
|
2534
2667
|
"signal_to_task_maps",
|
|
2535
2668
|
"signalToTaskMap",
|
|
2536
2669
|
"signal_to_task_map"
|
|
2537
|
-
])
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2670
|
+
]);
|
|
2671
|
+
if (arrayPayload.length > 0) {
|
|
2672
|
+
return arrayPayload.map((map) => ({
|
|
2673
|
+
signalName: String(
|
|
2674
|
+
map.signalName ?? map.signal_name ?? ""
|
|
2675
|
+
).trim(),
|
|
2676
|
+
serviceName: String(
|
|
2677
|
+
map.serviceName ?? map.service_name ?? ""
|
|
2678
|
+
).trim(),
|
|
2679
|
+
isGlobal: Boolean(map.isGlobal ?? map.is_global ?? false),
|
|
2680
|
+
deleted: Boolean(map.deleted)
|
|
2681
|
+
})).filter((map) => map.signalName && map.serviceName);
|
|
2682
|
+
}
|
|
2683
|
+
const single = ctx.signalToTaskMap ?? ctx.signal_to_task_map ?? ctx.data ?? (ctx.signalName ?? ctx.signal_name ? ctx : void 0);
|
|
2684
|
+
if (!single || typeof single !== "object") {
|
|
2685
|
+
return [];
|
|
2686
|
+
}
|
|
2687
|
+
return [
|
|
2688
|
+
{
|
|
2689
|
+
signalName: String(
|
|
2690
|
+
single.signalName ?? single.signal_name ?? ""
|
|
2691
|
+
).trim(),
|
|
2692
|
+
serviceName: String(
|
|
2693
|
+
single.serviceName ?? single.service_name ?? ""
|
|
2694
|
+
).trim(),
|
|
2695
|
+
isGlobal: Boolean(single.isGlobal ?? single.is_global ?? false),
|
|
2696
|
+
deleted: Boolean(single.deleted)
|
|
2697
|
+
}
|
|
2698
|
+
].filter((map) => map.signalName && map.serviceName);
|
|
2547
2699
|
}
|
|
2548
2700
|
normalizeIntentMaps(ctx) {
|
|
2549
2701
|
const arrayPayload = this.readArrayPayload(ctx, [
|
|
@@ -2658,7 +2810,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2658
2810
|
)?.destroy();
|
|
2659
2811
|
this.gatheredSyncTransmissionServices.delete(serviceName);
|
|
2660
2812
|
}
|
|
2661
|
-
if (createdRecipients.length > 0
|
|
2813
|
+
if (createdRecipients.length > 0) {
|
|
2662
2814
|
emit("meta.cadenza_db.sync_tick", {
|
|
2663
2815
|
__syncing: true,
|
|
2664
2816
|
__reason: "gathered_sync_transmissions_reconciled"
|
|
@@ -2733,6 +2885,56 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2733
2885
|
}
|
|
2734
2886
|
}
|
|
2735
2887
|
}
|
|
2888
|
+
registerBootstrapFullSyncDeputies(emit, ctx) {
|
|
2889
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
CadenzaService.inquiryBroker.addIntent({
|
|
2893
|
+
name: META_SERVICE_REGISTRY_FULL_SYNC_INTENT
|
|
2894
|
+
});
|
|
2895
|
+
for (const taskName of BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS) {
|
|
2896
|
+
this.registerRemoteIntentDeputy({
|
|
2897
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
2898
|
+
serviceName: "CadenzaDB",
|
|
2899
|
+
taskName,
|
|
2900
|
+
taskVersion: 1
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
this.ensureDependeeClientsForService("CadenzaDB", emit, ctx);
|
|
2904
|
+
return true;
|
|
2905
|
+
}
|
|
2906
|
+
hasBootstrapFullSyncDeputies() {
|
|
2907
|
+
if (!this.serviceName || this.serviceName === "CadenzaDB") {
|
|
2908
|
+
return true;
|
|
2909
|
+
}
|
|
2910
|
+
return BOOTSTRAP_FULL_SYNC_RESPONDER_TASKS.every(
|
|
2911
|
+
(taskName) => this.remoteIntentDeputiesByKey.has(
|
|
2912
|
+
this.buildRemoteIntentDeputyKey({
|
|
2913
|
+
intentName: META_SERVICE_REGISTRY_FULL_SYNC_INTENT,
|
|
2914
|
+
serviceName: "CadenzaDB",
|
|
2915
|
+
taskName,
|
|
2916
|
+
taskVersion: 1
|
|
2917
|
+
})
|
|
2918
|
+
)
|
|
2919
|
+
);
|
|
2920
|
+
}
|
|
2921
|
+
scheduleEarlyFullSyncRequests(reason) {
|
|
2922
|
+
for (const delayMs of EARLY_FULL_SYNC_DELAYS_MS) {
|
|
2923
|
+
CadenzaService.schedule(
|
|
2924
|
+
"meta.sync_requested",
|
|
2925
|
+
{
|
|
2926
|
+
__syncing: false,
|
|
2927
|
+
__reason: reason
|
|
2928
|
+
},
|
|
2929
|
+
delayMs
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2932
|
+
return true;
|
|
2933
|
+
}
|
|
2934
|
+
bootstrapFullSync(emit, ctx, reason = "local_instance_inserted") {
|
|
2935
|
+
this.registerBootstrapFullSyncDeputies(emit, ctx);
|
|
2936
|
+
return this.scheduleEarlyFullSyncRequests(reason);
|
|
2937
|
+
}
|
|
2736
2938
|
getInquiryResponderDescriptor(task) {
|
|
2737
2939
|
const remote = this.remoteIntentDeputiesByTask.get(task);
|
|
2738
2940
|
if (remote) {
|
|
@@ -2761,6 +2963,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2761
2963
|
}
|
|
2762
2964
|
return this.getInstance(this.serviceName, this.serviceInstanceId);
|
|
2763
2965
|
}
|
|
2966
|
+
hasLocalInstanceRegistered() {
|
|
2967
|
+
return Boolean(this.getLocalInstance());
|
|
2968
|
+
}
|
|
2764
2969
|
summarizeTransportForDebug(transport) {
|
|
2765
2970
|
if (!transport) {
|
|
2766
2971
|
return void 0;
|
|
@@ -3748,6 +3953,7 @@ var SignalTransmissionTask = class extends import_core2.Task {
|
|
|
3748
3953
|
};
|
|
3749
3954
|
|
|
3750
3955
|
// src/network/RestController.browser.ts
|
|
3956
|
+
var FETCH_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3751
3957
|
var RestController = class _RestController {
|
|
3752
3958
|
constructor() {
|
|
3753
3959
|
this.fetchClientDiagnostics = /* @__PURE__ */ new Map();
|
|
@@ -3793,7 +3999,15 @@ var RestController = class _RestController {
|
|
|
3793
3999
|
is_blocked: false,
|
|
3794
4000
|
health: {}
|
|
3795
4001
|
},
|
|
3796
|
-
__transportData:
|
|
4002
|
+
__transportData: Array.isArray(ctx.__declaredTransports) ? ctx.__declaredTransports.map((transport) => ({
|
|
4003
|
+
uuid: transport.uuid,
|
|
4004
|
+
service_instance_id: ctx.__serviceInstanceId,
|
|
4005
|
+
role: transport.role,
|
|
4006
|
+
origin: transport.origin,
|
|
4007
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
4008
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
4009
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
4010
|
+
})) : []
|
|
3797
4011
|
});
|
|
3798
4012
|
return true;
|
|
3799
4013
|
},
|
|
@@ -3808,6 +4022,7 @@ var RestController = class _RestController {
|
|
|
3808
4022
|
if (!serviceName || !URL2 || !fetchId) {
|
|
3809
4023
|
return false;
|
|
3810
4024
|
}
|
|
4025
|
+
const clientTaskSuffix = `${URL2} (${fetchId})`;
|
|
3811
4026
|
const fetchDiagnostics = this.ensureFetchClientDiagnostics(
|
|
3812
4027
|
fetchId,
|
|
3813
4028
|
serviceName,
|
|
@@ -3815,11 +4030,11 @@ var RestController = class _RestController {
|
|
|
3815
4030
|
);
|
|
3816
4031
|
fetchDiagnostics.destroyed = false;
|
|
3817
4032
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3818
|
-
if (CadenzaService.get(`Send Handshake to ${
|
|
4033
|
+
if (CadenzaService.get(`Send Handshake to ${clientTaskSuffix}`)) {
|
|
3819
4034
|
return;
|
|
3820
4035
|
}
|
|
3821
4036
|
const handshakeTask = CadenzaService.createMetaTask(
|
|
3822
|
-
`Send Handshake to ${
|
|
4037
|
+
`Send Handshake to ${clientTaskSuffix}`,
|
|
3823
4038
|
async (handshakeCtx, emit) => {
|
|
3824
4039
|
try {
|
|
3825
4040
|
const response = await this.fetchDataWithTimeout(
|
|
@@ -3831,7 +4046,7 @@ var RestController = class _RestController {
|
|
|
3831
4046
|
method: "POST",
|
|
3832
4047
|
body: JSON.stringify(handshakeCtx.handshakeData)
|
|
3833
4048
|
},
|
|
3834
|
-
|
|
4049
|
+
FETCH_HANDSHAKE_TIMEOUT_MS
|
|
3835
4050
|
);
|
|
3836
4051
|
if (response.__status !== "success") {
|
|
3837
4052
|
const error = response.__error ?? `Failed to connect to service ${serviceName} ${handshakeCtx.serviceInstanceId}`;
|
|
@@ -3873,7 +4088,7 @@ var RestController = class _RestController {
|
|
|
3873
4088
|
"global.meta.fetch.service_communication_established"
|
|
3874
4089
|
);
|
|
3875
4090
|
const delegateTask = CadenzaService.createMetaTask(
|
|
3876
|
-
`Delegate flow to REST server ${
|
|
4091
|
+
`Delegate flow to REST server ${clientTaskSuffix}`,
|
|
3877
4092
|
async (delegateCtx, emit) => {
|
|
3878
4093
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
3879
4094
|
return;
|
|
@@ -3916,7 +4131,7 @@ var RestController = class _RestController {
|
|
|
3916
4131
|
`meta.service_registry.socket_failed:${fetchId}`
|
|
3917
4132
|
).emitsOnFail("meta.fetch.delegate_failed").attachSignal("meta.fetch.delegated");
|
|
3918
4133
|
const transmitTask = CadenzaService.createMetaTask(
|
|
3919
|
-
`Transmit signal to server ${
|
|
4134
|
+
`Transmit signal to server ${clientTaskSuffix}`,
|
|
3920
4135
|
async (signalCtx, emit) => {
|
|
3921
4136
|
if (signalCtx.__signalName === void 0) {
|
|
3922
4137
|
return;
|
|
@@ -3954,7 +4169,7 @@ var RestController = class _RestController {
|
|
|
3954
4169
|
"Sends signal request"
|
|
3955
4170
|
).doOn(`meta.service_registry.selected_instance_for_fetch:${fetchId}`).emitsOnFail("meta.fetch.signal_transmission_failed").attachSignal("meta.fetch.transmitted");
|
|
3956
4171
|
const statusTask = CadenzaService.createMetaTask(
|
|
3957
|
-
`Request status from ${
|
|
4172
|
+
`Request status from ${clientTaskSuffix}`,
|
|
3958
4173
|
async (statusCtx) => {
|
|
3959
4174
|
fetchDiagnostics.statusChecks++;
|
|
3960
4175
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -3979,7 +4194,7 @@ var RestController = class _RestController {
|
|
|
3979
4194
|
},
|
|
3980
4195
|
"Requests status"
|
|
3981
4196
|
).doOn("meta.fetch.status_check_requested").emits("meta.fetch.status_checked").emitsOnFail("meta.fetch.status_check_failed");
|
|
3982
|
-
CadenzaService.createEphemeralMetaTask(
|
|
4197
|
+
CadenzaService.createEphemeralMetaTask(`Destroy fetch client ${fetchId}`, () => {
|
|
3983
4198
|
fetchDiagnostics.connected = false;
|
|
3984
4199
|
fetchDiagnostics.destroyed = true;
|
|
3985
4200
|
fetchDiagnostics.updatedAt = Date.now();
|
|
@@ -6284,6 +6499,12 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
6284
6499
|
}
|
|
6285
6500
|
);
|
|
6286
6501
|
}).doOn("meta.task.attached_signal").emits("global.meta.graph_metadata.task_attached_signal");
|
|
6502
|
+
CadenzaService.createMetaTask("Handle task intent association", (ctx) => {
|
|
6503
|
+
return buildDatabaseTriggerContext({
|
|
6504
|
+
...ctx.data,
|
|
6505
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
6506
|
+
});
|
|
6507
|
+
}).doOn("meta.task.intent_associated").emits("global.meta.graph_metadata.task_intent_associated");
|
|
6287
6508
|
CadenzaService.createMetaTask("Handle task unsubscribing signal", (ctx) => {
|
|
6288
6509
|
return buildDatabaseTriggerContext(
|
|
6289
6510
|
{
|
|
@@ -6646,34 +6867,7 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
|
|
|
6646
6867
|
}
|
|
6647
6868
|
return nextQueryData;
|
|
6648
6869
|
}
|
|
6649
|
-
function buildSyncQueryQueryData(ctx, queryData = {}) {
|
|
6650
|
-
const joinedQueryData = getJoinedContextValue(ctx, "queryData");
|
|
6651
|
-
const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : joinedQueryData && typeof joinedQueryData === "object" ? joinedQueryData : {};
|
|
6652
|
-
const nextQueryData = {};
|
|
6653
|
-
const allowedKeys = [
|
|
6654
|
-
"transaction",
|
|
6655
|
-
"filter",
|
|
6656
|
-
"fields",
|
|
6657
|
-
"joins",
|
|
6658
|
-
"sort",
|
|
6659
|
-
"limit",
|
|
6660
|
-
"offset",
|
|
6661
|
-
"queryMode",
|
|
6662
|
-
"aggregates",
|
|
6663
|
-
"groupBy"
|
|
6664
|
-
];
|
|
6665
|
-
for (const key of allowedKeys) {
|
|
6666
|
-
if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
|
|
6667
|
-
nextQueryData[key] = existingQueryData[key];
|
|
6668
|
-
}
|
|
6669
|
-
}
|
|
6670
|
-
return {
|
|
6671
|
-
...nextQueryData,
|
|
6672
|
-
...queryData
|
|
6673
|
-
};
|
|
6674
|
-
}
|
|
6675
6870
|
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 5;
|
|
6676
|
-
var REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY = 3;
|
|
6677
6871
|
function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
6678
6872
|
if (!graph) {
|
|
6679
6873
|
return void 0;
|
|
@@ -6686,11 +6880,27 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
|
6686
6880
|
}
|
|
6687
6881
|
function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
6688
6882
|
const originalContext = { ...ctx };
|
|
6883
|
+
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();
|
|
6884
|
+
const rootDbOperationFields = {};
|
|
6885
|
+
for (const key of [
|
|
6886
|
+
"data",
|
|
6887
|
+
"batch",
|
|
6888
|
+
"transaction",
|
|
6889
|
+
"onConflict",
|
|
6890
|
+
"filter",
|
|
6891
|
+
"fields"
|
|
6892
|
+
]) {
|
|
6893
|
+
if (Object.prototype.hasOwnProperty.call(queryData, key)) {
|
|
6894
|
+
rootDbOperationFields[key] = queryData[key];
|
|
6895
|
+
}
|
|
6896
|
+
}
|
|
6689
6897
|
const nextContext = {
|
|
6690
6898
|
__syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
|
|
6899
|
+
__syncSourceServiceName: syncSourceServiceName,
|
|
6691
6900
|
__preferredTransportProtocol: "rest",
|
|
6692
6901
|
__resolverOriginalContext: originalContext,
|
|
6693
6902
|
__resolverQueryData: queryData,
|
|
6903
|
+
...rootDbOperationFields,
|
|
6694
6904
|
queryData
|
|
6695
6905
|
};
|
|
6696
6906
|
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
@@ -6698,9 +6908,26 @@ function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
|
6698
6908
|
}
|
|
6699
6909
|
return nextContext;
|
|
6700
6910
|
}
|
|
6911
|
+
function markCompletedSyncCycle(completedCycles, cycleId, limit = 32) {
|
|
6912
|
+
if (!cycleId) {
|
|
6913
|
+
return false;
|
|
6914
|
+
}
|
|
6915
|
+
if (completedCycles.has(cycleId)) {
|
|
6916
|
+
return false;
|
|
6917
|
+
}
|
|
6918
|
+
completedCycles.add(cycleId);
|
|
6919
|
+
while (completedCycles.size > limit) {
|
|
6920
|
+
const oldestCycleId = completedCycles.values().next().value;
|
|
6921
|
+
if (!oldestCycleId) {
|
|
6922
|
+
break;
|
|
6923
|
+
}
|
|
6924
|
+
completedCycles.delete(oldestCycleId);
|
|
6925
|
+
}
|
|
6926
|
+
return true;
|
|
6927
|
+
}
|
|
6701
6928
|
function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6702
6929
|
const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
|
|
6703
|
-
if (
|
|
6930
|
+
if (isCadenzaDBReady && !localInsertTask) {
|
|
6704
6931
|
return void 0;
|
|
6705
6932
|
}
|
|
6706
6933
|
const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
|
|
@@ -6751,6 +6978,11 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
6751
6978
|
...ctx,
|
|
6752
6979
|
queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
|
|
6753
6980
|
};
|
|
6981
|
+
if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
|
|
6982
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
6983
|
+
delayMs: 1e3
|
|
6984
|
+
});
|
|
6985
|
+
}
|
|
6754
6986
|
return normalizedContext;
|
|
6755
6987
|
},
|
|
6756
6988
|
`Finalizes ${tableName} graph-sync insert execution after the authority task finishes.`,
|
|
@@ -6778,63 +7010,16 @@ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
|
|
|
6778
7010
|
"intent_to_task_map",
|
|
6779
7011
|
"directional_task_graph_map"
|
|
6780
7012
|
];
|
|
6781
|
-
var
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
function resolveSyncQueryRows(ctx, tableName) {
|
|
6789
|
-
const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
|
|
6790
|
-
const rows = ctx?.[resultKey];
|
|
6791
|
-
return Array.isArray(rows) ? rows : [];
|
|
6792
|
-
}
|
|
6793
|
-
function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
|
|
6794
|
-
const localQueryTask = CadenzaService.getLocalCadenzaDBQueryTask(tableName);
|
|
6795
|
-
if (!localQueryTask && !isCadenzaDBReady) {
|
|
6796
|
-
return void 0;
|
|
6797
|
-
}
|
|
6798
|
-
const targetTask = localQueryTask ?? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, {
|
|
6799
|
-
...options,
|
|
6800
|
-
concurrency: Number(options.concurrency) > 0 ? Math.min(
|
|
6801
|
-
Number(options.concurrency),
|
|
6802
|
-
REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY
|
|
6803
|
-
) : REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY,
|
|
6804
|
-
register: false,
|
|
6805
|
-
isHidden: true
|
|
6806
|
-
});
|
|
6807
|
-
const prepareQueryTask = CadenzaService.createMetaTask(
|
|
6808
|
-
`Prepare graph sync query for ${tableName}`,
|
|
6809
|
-
(ctx) => buildSyncExecutionEnvelope(
|
|
6810
|
-
ctx,
|
|
6811
|
-
buildSyncQueryQueryData(ctx, queryData)
|
|
6812
|
-
),
|
|
6813
|
-
`Prepares ${tableName} graph-sync query payloads.`,
|
|
6814
|
-
{
|
|
6815
|
-
register: false,
|
|
6816
|
-
isHidden: true
|
|
6817
|
-
}
|
|
6818
|
-
);
|
|
6819
|
-
const finalizeQueryTask = CadenzaService.createMetaTask(
|
|
6820
|
-
`Finalize graph sync query for ${tableName}`,
|
|
6821
|
-
(ctx) => ctx,
|
|
6822
|
-
`Finalizes ${tableName} graph-sync query payloads after authority lookup.`,
|
|
6823
|
-
{
|
|
6824
|
-
register: false,
|
|
6825
|
-
isHidden: true
|
|
6826
|
-
}
|
|
6827
|
-
);
|
|
6828
|
-
prepareQueryTask.then(targetTask);
|
|
6829
|
-
targetTask.then(finalizeQueryTask);
|
|
6830
|
-
return {
|
|
6831
|
-
entryTask: prepareQueryTask,
|
|
6832
|
-
completionTask: finalizeQueryTask
|
|
6833
|
-
};
|
|
6834
|
-
}
|
|
7013
|
+
var BOOTSTRAP_SYNC_STALE_CYCLE_MS = 15e3;
|
|
7014
|
+
var EARLY_SYNC_TICK_DELAYS_MS = [
|
|
7015
|
+
400,
|
|
7016
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS + 1e3,
|
|
7017
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 2 + 2e3,
|
|
7018
|
+
BOOTSTRAP_SYNC_STALE_CYCLE_MS * 3 + 3e3
|
|
7019
|
+
];
|
|
6835
7020
|
function getRegistrableTasks() {
|
|
6836
7021
|
return Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
6837
|
-
(task) => task.register && !task.isHidden
|
|
7022
|
+
(task) => task.register && !task.isHidden && !task.isDeputy
|
|
6838
7023
|
);
|
|
6839
7024
|
}
|
|
6840
7025
|
function getRegistrableRoutines() {
|
|
@@ -6899,10 +7084,23 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6899
7084
|
this.signalsSynced = false;
|
|
6900
7085
|
this.intentsSynced = false;
|
|
6901
7086
|
this.routinesSynced = false;
|
|
7087
|
+
this.directionalTaskMapsSynced = false;
|
|
7088
|
+
this.signalTaskMapsSynced = false;
|
|
7089
|
+
this.intentTaskMapsSynced = false;
|
|
7090
|
+
this.actorTaskMapsSynced = false;
|
|
7091
|
+
this.routineTaskMapsSynced = false;
|
|
6902
7092
|
this.isCadenzaDBReady = false;
|
|
6903
7093
|
this.initialized = false;
|
|
6904
7094
|
this.initRetryScheduled = false;
|
|
6905
7095
|
this.lastMissingLocalCadenzaDBInsertTablesKey = "";
|
|
7096
|
+
this.syncCycleCounter = 0;
|
|
7097
|
+
this.primitivePhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7098
|
+
this.mapPhaseCompletedCycles = /* @__PURE__ */ new Set();
|
|
7099
|
+
this.activeSyncCycleId = null;
|
|
7100
|
+
this.activeSyncCycleStartedAt = 0;
|
|
7101
|
+
this.pendingBootstrapSyncRerun = false;
|
|
7102
|
+
this.localServiceInserted = false;
|
|
7103
|
+
this.localServiceInstanceInserted = false;
|
|
6906
7104
|
}
|
|
6907
7105
|
static get instance() {
|
|
6908
7106
|
if (!this._instance) this._instance = new _GraphSyncController();
|
|
@@ -6976,45 +7174,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6976
7174
|
},
|
|
6977
7175
|
{ concurrency: 30 }
|
|
6978
7176
|
);
|
|
6979
|
-
const ensureIntentRegistryBeforeIntentMapTask = resolveSyncInsertTask(
|
|
6980
|
-
this.isCadenzaDBReady,
|
|
6981
|
-
"intent_registry",
|
|
6982
|
-
{
|
|
6983
|
-
onConflict: {
|
|
6984
|
-
target: ["name"],
|
|
6985
|
-
action: {
|
|
6986
|
-
do: "nothing"
|
|
6987
|
-
}
|
|
6988
|
-
}
|
|
6989
|
-
},
|
|
6990
|
-
{ concurrency: 30 }
|
|
6991
|
-
);
|
|
6992
|
-
const authoritativeTaskQueryGraph = resolveSyncQueryTask(
|
|
6993
|
-
this.isCadenzaDBReady,
|
|
6994
|
-
"task",
|
|
6995
|
-
{},
|
|
6996
|
-
{ concurrency: 10 }
|
|
6997
|
-
);
|
|
6998
|
-
const authoritativeRoutineQueryGraph = resolveSyncQueryTask(
|
|
6999
|
-
this.isCadenzaDBReady,
|
|
7000
|
-
"routine",
|
|
7001
|
-
{},
|
|
7002
|
-
{ concurrency: 10 }
|
|
7003
|
-
);
|
|
7004
|
-
const authoritativeSignalQueryGraph = resolveSyncQueryTask(
|
|
7005
|
-
this.isCadenzaDBReady,
|
|
7006
|
-
"signal_registry",
|
|
7007
|
-
{},
|
|
7008
|
-
{ concurrency: 10 }
|
|
7009
|
-
);
|
|
7010
|
-
const authoritativeIntentQueryGraph = resolveSyncQueryTask(
|
|
7011
|
-
this.isCadenzaDBReady,
|
|
7012
|
-
"intent_registry",
|
|
7013
|
-
{},
|
|
7014
|
-
{ concurrency: 10 }
|
|
7015
|
-
);
|
|
7016
7177
|
const finalizeTaskSync = (emit, ctx) => {
|
|
7017
7178
|
const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
|
|
7179
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7018
7180
|
if (pendingTasks.length > 0) {
|
|
7019
7181
|
this.tasksSynced = false;
|
|
7020
7182
|
return false;
|
|
@@ -7033,6 +7195,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7033
7195
|
const pendingRoutines = getRegistrableRoutines().filter(
|
|
7034
7196
|
(routine) => !routine.registered
|
|
7035
7197
|
);
|
|
7198
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7036
7199
|
if (pendingRoutines.length > 0) {
|
|
7037
7200
|
this.routinesSynced = false;
|
|
7038
7201
|
return false;
|
|
@@ -7051,6 +7214,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7051
7214
|
const pendingSignals = getRegistrableSignalObservers().filter(
|
|
7052
7215
|
(observer) => observer.registered !== true
|
|
7053
7216
|
);
|
|
7217
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7054
7218
|
if (pendingSignals.length > 0) {
|
|
7055
7219
|
this.signalsSynced = false;
|
|
7056
7220
|
return false;
|
|
@@ -7069,6 +7233,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7069
7233
|
const pendingIntentNames = getRegistrableIntentNames().filter(
|
|
7070
7234
|
(intentName) => !this.registeredIntentDefinitions.has(intentName)
|
|
7071
7235
|
);
|
|
7236
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
7072
7237
|
if (pendingIntentNames.length > 0) {
|
|
7073
7238
|
this.intentsSynced = false;
|
|
7074
7239
|
return false;
|
|
@@ -7334,14 +7499,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7334
7499
|
);
|
|
7335
7500
|
const processSignalRegistrationTask = CadenzaService.createMetaTask(
|
|
7336
7501
|
"Process signal registration",
|
|
7337
|
-
(ctx) => {
|
|
7338
|
-
|
|
7502
|
+
(ctx, emit) => {
|
|
7503
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
7504
|
+
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7505
|
+
if (!insertSucceeded) {
|
|
7339
7506
|
return;
|
|
7340
7507
|
}
|
|
7341
7508
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7342
7509
|
delayMs: 3e3
|
|
7343
7510
|
});
|
|
7344
|
-
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7345
7511
|
if (!signalName) {
|
|
7346
7512
|
return false;
|
|
7347
7513
|
}
|
|
@@ -7353,6 +7519,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7353
7519
|
if (observer) {
|
|
7354
7520
|
observer.registered = true;
|
|
7355
7521
|
}
|
|
7522
|
+
emit(
|
|
7523
|
+
"meta.sync_controller.signal_registered",
|
|
7524
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
7525
|
+
__signal: signalName
|
|
7526
|
+
})
|
|
7527
|
+
);
|
|
7356
7528
|
return { signalName };
|
|
7357
7529
|
}
|
|
7358
7530
|
).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask);
|
|
@@ -7373,6 +7545,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7373
7545
|
return;
|
|
7374
7546
|
}
|
|
7375
7547
|
for (const task of tasks) {
|
|
7548
|
+
if (task.hidden || !task.register || task.isDeputy) continue;
|
|
7376
7549
|
if (task.registered) continue;
|
|
7377
7550
|
const { __functionString, __getTagCallback } = task.export();
|
|
7378
7551
|
this.tasksSynced = false;
|
|
@@ -7407,7 +7580,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7407
7580
|
signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
|
|
7408
7581
|
signalsToEmitOnFail: Array.from(task.signalsToEmitOnFail),
|
|
7409
7582
|
observed: Array.from(task.observedSignals)
|
|
7410
|
-
}
|
|
7583
|
+
},
|
|
7584
|
+
intents: Array.from(task.handlesIntents)
|
|
7411
7585
|
},
|
|
7412
7586
|
__taskName: task.name
|
|
7413
7587
|
};
|
|
@@ -7430,13 +7604,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7430
7604
|
const registerTaskTask = CadenzaService.createMetaTask(
|
|
7431
7605
|
"Record registration",
|
|
7432
7606
|
(ctx, emit) => {
|
|
7433
|
-
|
|
7607
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7608
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7609
|
+
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
7610
|
+
if (!insertSucceeded) {
|
|
7434
7611
|
return;
|
|
7435
7612
|
}
|
|
7436
7613
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7437
7614
|
delayMs: 3e3
|
|
7438
7615
|
});
|
|
7439
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7440
7616
|
if (!task) {
|
|
7441
7617
|
return true;
|
|
7442
7618
|
}
|
|
@@ -7451,24 +7627,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7451
7627
|
}
|
|
7452
7628
|
).then(gatherTaskRegistrationTask);
|
|
7453
7629
|
wireSyncTaskGraph(this.splitTasksForRegistration, registerTaskGraph, registerTaskTask);
|
|
7454
|
-
CadenzaService.createMetaTask(
|
|
7455
|
-
"Prepare created task for immediate sync",
|
|
7456
|
-
(ctx) => {
|
|
7457
|
-
const task = ctx.taskInstance ?? (ctx.data?.name ? CadenzaService.get(String(ctx.data.name)) : void 0);
|
|
7458
|
-
if (!task || task.hidden || !task.register || task.registered) {
|
|
7459
|
-
return false;
|
|
7460
|
-
}
|
|
7461
|
-
return {
|
|
7462
|
-
__syncing: true,
|
|
7463
|
-
tasks: [task]
|
|
7464
|
-
};
|
|
7465
|
-
},
|
|
7466
|
-
"Schedules newly created tasks into the graph sync registration flow without waiting for the next periodic tick.",
|
|
7467
|
-
{
|
|
7468
|
-
register: false,
|
|
7469
|
-
isHidden: true
|
|
7470
|
-
}
|
|
7471
|
-
).doOn("meta.task.created").then(this.splitTasksForRegistration);
|
|
7472
7630
|
this.splitActorsForRegistration = CadenzaService.createMetaTask(
|
|
7473
7631
|
"Split actors for registration",
|
|
7474
7632
|
function* (ctx) {
|
|
@@ -7607,13 +7765,14 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7607
7765
|
const registerSignalTask = CadenzaService.createMetaTask(
|
|
7608
7766
|
"Record signal registration",
|
|
7609
7767
|
(ctx) => {
|
|
7768
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7769
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
7610
7770
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7611
7771
|
return;
|
|
7612
7772
|
}
|
|
7613
7773
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7614
7774
|
delayMs: 3e3
|
|
7615
7775
|
});
|
|
7616
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7617
7776
|
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
7618
7777
|
if (!task || !signalName) {
|
|
7619
7778
|
return true;
|
|
@@ -7625,7 +7784,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7625
7784
|
"Split observed signals of task",
|
|
7626
7785
|
function* (ctx) {
|
|
7627
7786
|
const task = ctx.task;
|
|
7628
|
-
if (task.hidden || !task.register || !task.registered)
|
|
7787
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
7788
|
+
return false;
|
|
7629
7789
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7630
7790
|
if (!serviceName2) {
|
|
7631
7791
|
return false;
|
|
@@ -7707,7 +7867,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7707
7867
|
);
|
|
7708
7868
|
const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
|
|
7709
7869
|
"Record intent definition registration",
|
|
7710
|
-
(ctx) => {
|
|
7870
|
+
(ctx, emit) => {
|
|
7711
7871
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7712
7872
|
return;
|
|
7713
7873
|
}
|
|
@@ -7715,6 +7875,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7715
7875
|
delayMs: 3e3
|
|
7716
7876
|
});
|
|
7717
7877
|
this.registeredIntentDefinitions.add(ctx.__intentName);
|
|
7878
|
+
emit(
|
|
7879
|
+
"meta.sync_controller.intent_registered",
|
|
7880
|
+
buildMinimalSyncSignalContext(ctx, {
|
|
7881
|
+
__intentName: ctx.__intentName
|
|
7882
|
+
})
|
|
7883
|
+
);
|
|
7718
7884
|
return true;
|
|
7719
7885
|
}
|
|
7720
7886
|
).then(gatherIntentRegistrationTask);
|
|
@@ -7726,13 +7892,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7726
7892
|
const registerIntentTask = CadenzaService.createMetaTask(
|
|
7727
7893
|
"Record intent registration",
|
|
7728
7894
|
(ctx) => {
|
|
7895
|
+
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7729
7896
|
if (!didSyncInsertSucceed(ctx)) {
|
|
7730
7897
|
return;
|
|
7731
7898
|
}
|
|
7732
7899
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7733
7900
|
delayMs: 3e3
|
|
7734
7901
|
});
|
|
7735
|
-
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
7736
7902
|
if (!task) {
|
|
7737
7903
|
return true;
|
|
7738
7904
|
}
|
|
@@ -7744,7 +7910,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7744
7910
|
"Split intents of task",
|
|
7745
7911
|
function* (ctx) {
|
|
7746
7912
|
const task = ctx.task;
|
|
7747
|
-
if (task.hidden || !task.register || !task.registered)
|
|
7913
|
+
if (task.hidden || !task.register || task.isDeputy || !task.registered)
|
|
7914
|
+
return false;
|
|
7748
7915
|
const serviceName2 = resolveSyncServiceName(task);
|
|
7749
7916
|
if (!serviceName2) {
|
|
7750
7917
|
return false;
|
|
@@ -7799,30 +7966,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7799
7966
|
return emittedCount > 0;
|
|
7800
7967
|
}.bind(this)
|
|
7801
7968
|
);
|
|
7802
|
-
const prepareIntentDefinitionForIntentMapTask = CadenzaService.createMetaTask(
|
|
7803
|
-
"Prepare intent definition for intent-to-task map",
|
|
7804
|
-
(ctx) => {
|
|
7805
|
-
if (!ctx.__intentDefinition || !ctx.__intentMapData) {
|
|
7806
|
-
return false;
|
|
7807
|
-
}
|
|
7808
|
-
return {
|
|
7809
|
-
...ctx,
|
|
7810
|
-
data: ctx.__intentDefinition
|
|
7811
|
-
};
|
|
7812
|
-
}
|
|
7813
|
-
);
|
|
7814
|
-
const restoreIntentToTaskMapPayloadTask = CadenzaService.createMetaTask(
|
|
7815
|
-
"Restore intent-to-task map payload",
|
|
7816
|
-
(ctx) => {
|
|
7817
|
-
if (!ctx.__intentMapData) {
|
|
7818
|
-
return false;
|
|
7819
|
-
}
|
|
7820
|
-
return {
|
|
7821
|
-
...ctx,
|
|
7822
|
-
data: ctx.__intentMapData
|
|
7823
|
-
};
|
|
7824
|
-
}
|
|
7825
|
-
);
|
|
7826
7969
|
const intentToTaskMapGraph = resolveSyncInsertTask(
|
|
7827
7970
|
this.isCadenzaDBReady,
|
|
7828
7971
|
"intent_to_task_map",
|
|
@@ -7841,20 +7984,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7841
7984
|
},
|
|
7842
7985
|
{ concurrency: 30 }
|
|
7843
7986
|
);
|
|
7844
|
-
this.registerIntentToTaskMapTask.then(prepareIntentDefinitionForIntentMapTask);
|
|
7845
|
-
if (ensureIntentRegistryBeforeIntentMapTask) {
|
|
7846
|
-
wireSyncTaskGraph(
|
|
7847
|
-
prepareIntentDefinitionForIntentMapTask,
|
|
7848
|
-
ensureIntentRegistryBeforeIntentMapTask,
|
|
7849
|
-
restoreIntentToTaskMapPayloadTask
|
|
7850
|
-
);
|
|
7851
|
-
} else {
|
|
7852
|
-
prepareIntentDefinitionForIntentMapTask.then(
|
|
7853
|
-
restoreIntentToTaskMapPayloadTask
|
|
7854
|
-
);
|
|
7855
|
-
}
|
|
7856
7987
|
wireSyncTaskGraph(
|
|
7857
|
-
|
|
7988
|
+
this.registerIntentToTaskMapTask,
|
|
7858
7989
|
intentToTaskMapGraph,
|
|
7859
7990
|
registerIntentTask
|
|
7860
7991
|
);
|
|
@@ -7865,7 +7996,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7865
7996
|
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7866
7997
|
delayMs: 3e3
|
|
7867
7998
|
});
|
|
7868
|
-
if (task.hidden || !task.register) return;
|
|
7999
|
+
if (task.hidden || !task.register || task.isDeputy) return;
|
|
7869
8000
|
const predecessorServiceName = resolveSyncServiceName(task);
|
|
7870
8001
|
if (!predecessorServiceName) {
|
|
7871
8002
|
return;
|
|
@@ -7999,452 +8130,583 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7999
8130
|
deputyRelationshipRegistrationGraph,
|
|
8000
8131
|
recordDeputyRelationshipRegistrationTask
|
|
8001
8132
|
);
|
|
8002
|
-
const
|
|
8003
|
-
|
|
8004
|
-
(
|
|
8005
|
-
|
|
8006
|
-
let changed = false;
|
|
8007
|
-
for (const row of authoritativeTasks) {
|
|
8008
|
-
const taskName = typeof row.name === "string" ? row.name : "";
|
|
8009
|
-
if (!taskName) {
|
|
8010
|
-
continue;
|
|
8011
|
-
}
|
|
8012
|
-
const task = CadenzaService.get(taskName);
|
|
8013
|
-
if (!task || task.registered) {
|
|
8014
|
-
continue;
|
|
8015
|
-
}
|
|
8016
|
-
task.registered = true;
|
|
8017
|
-
changed = true;
|
|
8018
|
-
emit("meta.sync_controller.task_registered", {
|
|
8019
|
-
...ctx,
|
|
8020
|
-
__taskName: task.name,
|
|
8021
|
-
task,
|
|
8022
|
-
__authoritativeReconciliation: true
|
|
8023
|
-
});
|
|
8024
|
-
}
|
|
8025
|
-
if (authoritativeTasks.length > 0 || changed) {
|
|
8026
|
-
finalizeTaskSync(emit, {
|
|
8027
|
-
...ctx,
|
|
8028
|
-
__authoritativeReconciliation: true
|
|
8029
|
-
});
|
|
8030
|
-
}
|
|
8031
|
-
return changed;
|
|
8032
|
-
},
|
|
8033
|
-
"Marks local tasks as registered when authority rows already exist.",
|
|
8034
|
-
{
|
|
8035
|
-
register: false,
|
|
8036
|
-
isHidden: true
|
|
8133
|
+
const hasPendingDirectionalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8134
|
+
const taskWithDeputyState = task;
|
|
8135
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8136
|
+
return false;
|
|
8037
8137
|
}
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
const routineName = typeof row.name === "string" ? row.name : "";
|
|
8046
|
-
if (!routineName) {
|
|
8047
|
-
continue;
|
|
8048
|
-
}
|
|
8049
|
-
const routine = CadenzaService.getRoutine(routineName);
|
|
8050
|
-
if (!routine || routine.registered) {
|
|
8051
|
-
continue;
|
|
8052
|
-
}
|
|
8053
|
-
routine.registered = true;
|
|
8054
|
-
changed = true;
|
|
8138
|
+
const predecessorServiceName = resolveSyncServiceName(task);
|
|
8139
|
+
if (!predecessorServiceName) {
|
|
8140
|
+
return false;
|
|
8141
|
+
}
|
|
8142
|
+
for (const nextTask of task.nextTasks) {
|
|
8143
|
+
if (task.taskMapRegistration.has(nextTask.name) || nextTask.isHidden || !nextTask.register || !nextTask.registered) {
|
|
8144
|
+
continue;
|
|
8055
8145
|
}
|
|
8056
|
-
if (
|
|
8057
|
-
|
|
8058
|
-
...ctx,
|
|
8059
|
-
__authoritativeReconciliation: true
|
|
8060
|
-
});
|
|
8146
|
+
if (resolveSyncServiceName(nextTask)) {
|
|
8147
|
+
return true;
|
|
8061
8148
|
}
|
|
8062
|
-
return changed;
|
|
8063
|
-
},
|
|
8064
|
-
"Marks local routines as registered when authority rows already exist.",
|
|
8065
|
-
{
|
|
8066
|
-
register: false,
|
|
8067
|
-
isHidden: true
|
|
8068
8149
|
}
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8150
|
+
if (task.isDeputy && !taskWithDeputyState.signalName && !taskWithDeputyState.registeredDeputyMap) {
|
|
8151
|
+
return Boolean(resolveSyncServiceName(task) && resolveSyncServiceName());
|
|
8152
|
+
}
|
|
8153
|
+
return false;
|
|
8154
|
+
});
|
|
8155
|
+
const hasPendingSignalTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8156
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8157
|
+
return false;
|
|
8158
|
+
}
|
|
8159
|
+
for (const signal of task.observedSignals) {
|
|
8160
|
+
if (task.registeredSignals.has(signal)) {
|
|
8161
|
+
continue;
|
|
8162
|
+
}
|
|
8163
|
+
const signalName = signal.split(":")[0];
|
|
8164
|
+
if (!decomposeSignalName(signalName).isGlobal) {
|
|
8165
|
+
continue;
|
|
8166
|
+
}
|
|
8167
|
+
if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
|
|
8168
|
+
continue;
|
|
8169
|
+
}
|
|
8170
|
+
return true;
|
|
8171
|
+
}
|
|
8172
|
+
return false;
|
|
8173
|
+
});
|
|
8174
|
+
const hasPendingIntentTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8175
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8176
|
+
return false;
|
|
8177
|
+
}
|
|
8178
|
+
const registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
|
|
8179
|
+
for (const intent of task.handlesIntents) {
|
|
8180
|
+
if (registeredIntents.has(intent) || isLocalOnlySyncIntent(intent)) {
|
|
8181
|
+
continue;
|
|
8182
|
+
}
|
|
8183
|
+
if (isMetaIntentName(intent) && !task.isMeta) {
|
|
8184
|
+
continue;
|
|
8185
|
+
}
|
|
8186
|
+
const intentDefinition = buildIntentRegistryData(CadenzaService.inquiryBroker.intents.get(intent)) ?? buildIntentRegistryData({ name: intent });
|
|
8187
|
+
if (!intentDefinition) {
|
|
8188
|
+
continue;
|
|
8189
|
+
}
|
|
8190
|
+
return true;
|
|
8191
|
+
}
|
|
8192
|
+
return false;
|
|
8193
|
+
});
|
|
8194
|
+
const hasPendingActorTaskMaps = () => getRegistrableTasks().some((task) => {
|
|
8195
|
+
if (task.isHidden || !task.register || !task.registered) {
|
|
8196
|
+
return false;
|
|
8197
|
+
}
|
|
8198
|
+
const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
|
|
8199
|
+
if (!metadata?.actorName) {
|
|
8200
|
+
return false;
|
|
8201
|
+
}
|
|
8202
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
8203
|
+
if (!serviceName2) {
|
|
8204
|
+
return false;
|
|
8205
|
+
}
|
|
8206
|
+
const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
|
|
8207
|
+
return !this.registeredActorTaskMaps.has(registrationKey);
|
|
8208
|
+
});
|
|
8209
|
+
const hasPendingRoutineTaskMaps = () => getRegistrableRoutines().some((routine) => {
|
|
8210
|
+
if (!routine.registered) {
|
|
8211
|
+
return false;
|
|
8212
|
+
}
|
|
8213
|
+
for (const task of routine.tasks) {
|
|
8214
|
+
if (!task) {
|
|
8215
|
+
continue;
|
|
8216
|
+
}
|
|
8217
|
+
const tasks = task.getIterator();
|
|
8218
|
+
while (tasks.hasNext()) {
|
|
8219
|
+
const nextTask = tasks.next();
|
|
8220
|
+
if (!nextTask?.registered) {
|
|
8079
8221
|
continue;
|
|
8080
8222
|
}
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
continue;
|
|
8223
|
+
if (!routine.registeredTasks.has(nextTask.name)) {
|
|
8224
|
+
return true;
|
|
8084
8225
|
}
|
|
8085
|
-
observer.registered = true;
|
|
8086
|
-
changed = true;
|
|
8087
8226
|
}
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8227
|
+
}
|
|
8228
|
+
return false;
|
|
8229
|
+
});
|
|
8230
|
+
const gatherDirectionalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8231
|
+
"Gather directional task map registration",
|
|
8232
|
+
(ctx) => {
|
|
8233
|
+
if (hasPendingDirectionalTaskMaps()) {
|
|
8234
|
+
this.directionalTaskMapsSynced = false;
|
|
8235
|
+
return false;
|
|
8093
8236
|
}
|
|
8094
|
-
|
|
8237
|
+
this.directionalTaskMapsSynced = true;
|
|
8238
|
+
return ctx;
|
|
8095
8239
|
},
|
|
8096
|
-
"
|
|
8240
|
+
"Completes directional task graph registration when task edges and deputy edges are registered.",
|
|
8097
8241
|
{
|
|
8098
8242
|
register: false,
|
|
8099
8243
|
isHidden: true
|
|
8100
8244
|
}
|
|
8101
8245
|
);
|
|
8102
|
-
const
|
|
8103
|
-
"
|
|
8246
|
+
const gatherSignalTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8247
|
+
"Gather signal task map registration",
|
|
8248
|
+
(ctx) => {
|
|
8249
|
+
if (hasPendingSignalTaskMaps()) {
|
|
8250
|
+
this.signalTaskMapsSynced = false;
|
|
8251
|
+
return false;
|
|
8252
|
+
}
|
|
8253
|
+
this.signalTaskMapsSynced = true;
|
|
8254
|
+
return ctx;
|
|
8255
|
+
},
|
|
8256
|
+
"Completes signal-to-task map registration when all global observed signal edges are registered.",
|
|
8257
|
+
{
|
|
8258
|
+
register: false,
|
|
8259
|
+
isHidden: true
|
|
8260
|
+
}
|
|
8261
|
+
);
|
|
8262
|
+
const gatherIntentTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8263
|
+
"Gather intent task map registration",
|
|
8264
|
+
(ctx) => {
|
|
8265
|
+
if (hasPendingIntentTaskMaps()) {
|
|
8266
|
+
this.intentTaskMapsSynced = false;
|
|
8267
|
+
return false;
|
|
8268
|
+
}
|
|
8269
|
+
this.intentTaskMapsSynced = true;
|
|
8270
|
+
return ctx;
|
|
8271
|
+
},
|
|
8272
|
+
"Completes intent-to-task map registration when all task responders are registered.",
|
|
8273
|
+
{
|
|
8274
|
+
register: false,
|
|
8275
|
+
isHidden: true
|
|
8276
|
+
}
|
|
8277
|
+
);
|
|
8278
|
+
const gatherActorTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8279
|
+
"Gather actor task map registration",
|
|
8280
|
+
(ctx) => {
|
|
8281
|
+
if (hasPendingActorTaskMaps()) {
|
|
8282
|
+
this.actorTaskMapsSynced = false;
|
|
8283
|
+
return false;
|
|
8284
|
+
}
|
|
8285
|
+
this.actorTaskMapsSynced = true;
|
|
8286
|
+
return ctx;
|
|
8287
|
+
},
|
|
8288
|
+
"Completes actor-to-task map registration when all actor-backed tasks are registered.",
|
|
8289
|
+
{
|
|
8290
|
+
register: false,
|
|
8291
|
+
isHidden: true
|
|
8292
|
+
}
|
|
8293
|
+
);
|
|
8294
|
+
const gatherRoutineTaskMapRegistrationTask = CadenzaService.createUniqueMetaTask(
|
|
8295
|
+
"Gather routine task map registration",
|
|
8296
|
+
(ctx) => {
|
|
8297
|
+
if (hasPendingRoutineTaskMaps()) {
|
|
8298
|
+
this.routineTaskMapsSynced = false;
|
|
8299
|
+
return false;
|
|
8300
|
+
}
|
|
8301
|
+
this.routineTaskMapsSynced = true;
|
|
8302
|
+
return ctx;
|
|
8303
|
+
},
|
|
8304
|
+
"Completes task-to-routine map registration when all routine task memberships are registered.",
|
|
8305
|
+
{
|
|
8306
|
+
register: false,
|
|
8307
|
+
isHidden: true
|
|
8308
|
+
}
|
|
8309
|
+
);
|
|
8310
|
+
const finishSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8311
|
+
"Finish sync",
|
|
8104
8312
|
(ctx, emit) => {
|
|
8105
|
-
const
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8313
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8314
|
+
if (syncCycleId && this.activeSyncCycleId === syncCycleId) {
|
|
8315
|
+
this.activeSyncCycleId = null;
|
|
8316
|
+
this.activeSyncCycleStartedAt = 0;
|
|
8317
|
+
}
|
|
8318
|
+
if (this.pendingBootstrapSyncRerun) {
|
|
8319
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8320
|
+
CadenzaService.debounce("meta.sync_requested", {
|
|
8321
|
+
delayMs: 100
|
|
8322
|
+
});
|
|
8323
|
+
}
|
|
8324
|
+
emit("global.meta.sync_controller.synced", {
|
|
8325
|
+
data: {
|
|
8326
|
+
is_active: true,
|
|
8327
|
+
is_non_responsive: false,
|
|
8328
|
+
is_blocked: false,
|
|
8329
|
+
last_active: formatTimestamp(Date.now())
|
|
8330
|
+
},
|
|
8331
|
+
filter: {
|
|
8332
|
+
uuid: CadenzaService.serviceRegistry.serviceInstanceId
|
|
8114
8333
|
}
|
|
8115
|
-
|
|
8116
|
-
|
|
8334
|
+
});
|
|
8335
|
+
return true;
|
|
8336
|
+
},
|
|
8337
|
+
"Marks the current bootstrap sync cycle as complete.",
|
|
8338
|
+
{
|
|
8339
|
+
register: false,
|
|
8340
|
+
isHidden: true
|
|
8341
|
+
}
|
|
8342
|
+
).attachSignal("global.meta.sync_controller.synced");
|
|
8343
|
+
const mapPhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8344
|
+
"Complete map sync phase",
|
|
8345
|
+
(ctx) => {
|
|
8346
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8347
|
+
if (!syncCycleId) {
|
|
8348
|
+
return false;
|
|
8117
8349
|
}
|
|
8118
|
-
if (
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8350
|
+
if (!this.directionalTaskMapsSynced || !this.signalTaskMapsSynced || !this.intentTaskMapsSynced || !this.actorTaskMapsSynced || !this.routineTaskMapsSynced) {
|
|
8351
|
+
return false;
|
|
8352
|
+
}
|
|
8353
|
+
if (!markCompletedSyncCycle(this.mapPhaseCompletedCycles, syncCycleId)) {
|
|
8354
|
+
return false;
|
|
8123
8355
|
}
|
|
8124
|
-
return
|
|
8356
|
+
return ctx;
|
|
8125
8357
|
},
|
|
8126
|
-
"
|
|
8358
|
+
"Fans in map branch completion and ends the current sync cycle once every map branch is complete.",
|
|
8359
|
+
{
|
|
8360
|
+
register: false,
|
|
8361
|
+
isHidden: true
|
|
8362
|
+
}
|
|
8363
|
+
).then(finishSyncTask);
|
|
8364
|
+
const startDirectionalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8365
|
+
"Start directional task map sync",
|
|
8366
|
+
(ctx) => ctx,
|
|
8367
|
+
"Starts the directional task graph map branch for the current sync cycle.",
|
|
8127
8368
|
{
|
|
8128
8369
|
register: false,
|
|
8129
8370
|
isHidden: true
|
|
8130
8371
|
}
|
|
8131
8372
|
);
|
|
8132
|
-
const
|
|
8133
|
-
"
|
|
8134
|
-
() =>
|
|
8135
|
-
"
|
|
8373
|
+
const startSignalTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8374
|
+
"Start signal task map sync",
|
|
8375
|
+
(ctx) => ctx,
|
|
8376
|
+
"Starts the signal-to-task map branch for the current sync cycle.",
|
|
8136
8377
|
{
|
|
8137
8378
|
register: false,
|
|
8138
8379
|
isHidden: true
|
|
8139
8380
|
}
|
|
8140
8381
|
);
|
|
8141
|
-
const
|
|
8142
|
-
"
|
|
8143
|
-
() =>
|
|
8144
|
-
"
|
|
8382
|
+
const startIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8383
|
+
"Start intent task map sync",
|
|
8384
|
+
(ctx) => ctx,
|
|
8385
|
+
"Starts the intent-to-task map branch for the current sync cycle.",
|
|
8145
8386
|
{
|
|
8146
8387
|
register: false,
|
|
8147
8388
|
isHidden: true
|
|
8148
8389
|
}
|
|
8149
8390
|
);
|
|
8150
|
-
const
|
|
8151
|
-
"
|
|
8152
|
-
() =>
|
|
8153
|
-
"
|
|
8391
|
+
const startActorTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8392
|
+
"Start actor task map sync",
|
|
8393
|
+
(ctx) => ctx,
|
|
8394
|
+
"Starts the actor-to-task map branch for the current sync cycle.",
|
|
8154
8395
|
{
|
|
8155
8396
|
register: false,
|
|
8156
8397
|
isHidden: true
|
|
8157
8398
|
}
|
|
8158
8399
|
);
|
|
8159
|
-
const
|
|
8160
|
-
"
|
|
8161
|
-
() =>
|
|
8162
|
-
"
|
|
8400
|
+
const startRoutineTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
8401
|
+
"Start routine task map sync",
|
|
8402
|
+
(ctx) => ctx,
|
|
8403
|
+
"Starts the task-to-routine map branch for the current sync cycle.",
|
|
8163
8404
|
{
|
|
8164
8405
|
register: false,
|
|
8165
8406
|
isHidden: true
|
|
8166
8407
|
}
|
|
8167
8408
|
);
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
reconcileTaskRegistrationFromAuthorityTask
|
|
8171
|
-
);
|
|
8172
|
-
}
|
|
8173
|
-
if (authoritativeRoutineQueryGraph) {
|
|
8174
|
-
authoritativeRoutineQueryGraph.completionTask.then(
|
|
8175
|
-
reconcileRoutineRegistrationFromAuthorityTask
|
|
8176
|
-
);
|
|
8177
|
-
}
|
|
8178
|
-
if (authoritativeSignalQueryGraph) {
|
|
8179
|
-
authoritativeSignalQueryGraph.completionTask.then(
|
|
8180
|
-
reconcileSignalRegistrationFromAuthorityTask
|
|
8181
|
-
);
|
|
8182
|
-
}
|
|
8183
|
-
if (authoritativeIntentQueryGraph) {
|
|
8184
|
-
authoritativeIntentQueryGraph.completionTask.then(
|
|
8185
|
-
reconcileIntentRegistrationFromAuthorityTask
|
|
8186
|
-
);
|
|
8187
|
-
}
|
|
8188
|
-
const authoritativeRegistrationTriggers = [
|
|
8189
|
-
"meta.service_registry.initial_sync_complete",
|
|
8190
|
-
"meta.sync_requested",
|
|
8191
|
-
"meta.sync_controller.synced_resource",
|
|
8192
|
-
"meta.sync_controller.authority_registration_reconciliation_requested"
|
|
8193
|
-
];
|
|
8194
|
-
CadenzaService.createMetaTask(
|
|
8195
|
-
"Prepare authoritative task registration query",
|
|
8409
|
+
const primitivePhaseBarrierTask = CadenzaService.createUniqueMetaTask(
|
|
8410
|
+
"Complete primitive sync phase",
|
|
8196
8411
|
(ctx) => {
|
|
8197
|
-
|
|
8412
|
+
const syncCycleId = typeof ctx.__syncCycleId === "string" ? ctx.__syncCycleId.trim() : "";
|
|
8413
|
+
if (!syncCycleId) {
|
|
8198
8414
|
return false;
|
|
8199
8415
|
}
|
|
8200
|
-
const serviceName2 = resolveSyncServiceName();
|
|
8201
|
-
if (!
|
|
8416
|
+
const serviceName2 = typeof ctx.__serviceName === "string" ? ctx.__serviceName : resolveSyncServiceName();
|
|
8417
|
+
if (!this.tasksSynced || !this.signalsSynced || !this.intentsSynced || !this.actorsSynced || !this.routinesSynced) {
|
|
8202
8418
|
return false;
|
|
8203
8419
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
};
|
|
8420
|
+
if (!markCompletedSyncCycle(this.primitivePhaseCompletedCycles, syncCycleId)) {
|
|
8421
|
+
return false;
|
|
8422
|
+
}
|
|
8423
|
+
this.directionalTaskMapsSynced = false;
|
|
8424
|
+
this.signalTaskMapsSynced = false;
|
|
8425
|
+
this.intentTaskMapsSynced = false;
|
|
8426
|
+
this.actorTaskMapsSynced = false;
|
|
8427
|
+
this.routineTaskMapsSynced = false;
|
|
8428
|
+
return ctx;
|
|
8214
8429
|
},
|
|
8215
|
-
"
|
|
8430
|
+
"Fans in primitive registration and opens the map registration phase once every primitive branch is complete.",
|
|
8216
8431
|
{
|
|
8217
8432
|
register: false,
|
|
8218
8433
|
isHidden: true
|
|
8219
8434
|
}
|
|
8220
|
-
).
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8435
|
+
).then(
|
|
8436
|
+
startDirectionalTaskMapSyncTask,
|
|
8437
|
+
startSignalTaskMapSyncTask,
|
|
8438
|
+
startIntentTaskMapSyncTask,
|
|
8439
|
+
startActorTaskMapSyncTask,
|
|
8440
|
+
startRoutineTaskMapSyncTask
|
|
8441
|
+
);
|
|
8442
|
+
gatherTaskRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8443
|
+
gatherSignalRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8444
|
+
gatherIntentRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8445
|
+
gatherActorRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8446
|
+
gatherRoutineRegistrationTask.then(primitivePhaseBarrierTask);
|
|
8447
|
+
const markLocalServiceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8448
|
+
"Mark local service inserted for bootstrap sync",
|
|
8225
8449
|
(ctx) => {
|
|
8226
|
-
if (!this.isCadenzaDBReady) {
|
|
8227
|
-
return false;
|
|
8228
|
-
}
|
|
8229
8450
|
const serviceName2 = resolveSyncServiceName();
|
|
8230
|
-
|
|
8451
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8452
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8231
8453
|
return false;
|
|
8232
8454
|
}
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
__syncServiceName: serviceName2,
|
|
8236
|
-
queryData: {
|
|
8237
|
-
filter: {
|
|
8238
|
-
service_name: serviceName2
|
|
8239
|
-
},
|
|
8240
|
-
fields: ["name", "version", "service_name"]
|
|
8241
|
-
}
|
|
8242
|
-
};
|
|
8455
|
+
this.localServiceInserted = true;
|
|
8456
|
+
return true;
|
|
8243
8457
|
},
|
|
8244
|
-
"
|
|
8458
|
+
"Marks that the local service row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8245
8459
|
{
|
|
8246
8460
|
register: false,
|
|
8247
8461
|
isHidden: true
|
|
8248
8462
|
}
|
|
8249
|
-
).doOn(
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
CadenzaService.createMetaTask(
|
|
8253
|
-
"Prepare authoritative signal registration query",
|
|
8463
|
+
).doOn("meta.service_registry.service_inserted");
|
|
8464
|
+
const markLocalServiceInstanceInsertedForBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8465
|
+
"Mark local service instance inserted for bootstrap sync",
|
|
8254
8466
|
(ctx) => {
|
|
8255
|
-
|
|
8467
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8468
|
+
const insertedServiceName = typeof ctx.__serviceName === "string" ? ctx.__serviceName : typeof ctx.service_name === "string" ? ctx.service_name : null;
|
|
8469
|
+
if (!serviceName2 || insertedServiceName !== serviceName2) {
|
|
8256
8470
|
return false;
|
|
8257
8471
|
}
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
queryData: {
|
|
8261
|
-
fields: ["name"]
|
|
8262
|
-
}
|
|
8263
|
-
};
|
|
8472
|
+
this.localServiceInstanceInserted = true;
|
|
8473
|
+
return true;
|
|
8264
8474
|
},
|
|
8265
|
-
"
|
|
8475
|
+
"Marks that the local service instance row has been inserted in authority so bootstrap sync can start only after that prerequisite.",
|
|
8266
8476
|
{
|
|
8267
8477
|
register: false,
|
|
8268
8478
|
isHidden: true
|
|
8269
8479
|
}
|
|
8270
|
-
).doOn(
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
CadenzaService.createMetaTask(
|
|
8274
|
-
"Prepare authoritative intent registration query",
|
|
8480
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8481
|
+
const startBootstrapSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8482
|
+
"Start bootstrap graph sync",
|
|
8275
8483
|
(ctx) => {
|
|
8276
|
-
|
|
8484
|
+
const now = Date.now();
|
|
8485
|
+
const serviceName2 = resolveSyncServiceName();
|
|
8486
|
+
const serviceInstanceId = CadenzaService.serviceRegistry.serviceInstanceId;
|
|
8487
|
+
if (!serviceName2 || !serviceInstanceId) {
|
|
8488
|
+
return false;
|
|
8489
|
+
}
|
|
8490
|
+
if (!this.localServiceInserted) {
|
|
8491
|
+
return false;
|
|
8492
|
+
}
|
|
8493
|
+
if (!this.localServiceInstanceInserted) {
|
|
8277
8494
|
return false;
|
|
8278
8495
|
}
|
|
8496
|
+
if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
|
|
8497
|
+
return false;
|
|
8498
|
+
}
|
|
8499
|
+
if (this.activeSyncCycleId) {
|
|
8500
|
+
const activeCycleAgeMs = now - this.activeSyncCycleStartedAt;
|
|
8501
|
+
if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
|
|
8502
|
+
this.pendingBootstrapSyncRerun = true;
|
|
8503
|
+
return false;
|
|
8504
|
+
}
|
|
8505
|
+
}
|
|
8506
|
+
const syncCycleId = `${now}-${++this.syncCycleCounter}`;
|
|
8507
|
+
this.activeSyncCycleId = syncCycleId;
|
|
8508
|
+
this.activeSyncCycleStartedAt = now;
|
|
8509
|
+
this.pendingBootstrapSyncRerun = false;
|
|
8510
|
+
this.tasksSynced = false;
|
|
8511
|
+
this.signalsSynced = false;
|
|
8512
|
+
this.intentsSynced = false;
|
|
8513
|
+
this.actorsSynced = false;
|
|
8514
|
+
this.routinesSynced = false;
|
|
8279
8515
|
return {
|
|
8280
8516
|
...ctx,
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8517
|
+
__syncing: true,
|
|
8518
|
+
__syncCycleId: syncCycleId,
|
|
8519
|
+
__serviceName: serviceName2,
|
|
8520
|
+
__serviceInstanceId: serviceInstanceId
|
|
8284
8521
|
};
|
|
8285
8522
|
},
|
|
8286
|
-
"
|
|
8523
|
+
"Starts a deterministic bootstrap sync cycle once the local service instance exists.",
|
|
8287
8524
|
{
|
|
8288
8525
|
register: false,
|
|
8289
8526
|
isHidden: true
|
|
8290
8527
|
}
|
|
8291
|
-
).doOn(
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
CadenzaService.signalBroker.getSignalsTask.clone().doOn(
|
|
8295
|
-
"meta.sync_controller.sync_tick",
|
|
8296
|
-
"meta.service_registry.initial_sync_complete",
|
|
8297
|
-
"meta.sync_requested"
|
|
8298
|
-
).then(this.splitSignalsTask);
|
|
8299
|
-
CadenzaService.registry.getAllTasks.clone().doOn(
|
|
8300
|
-
"meta.sync_controller.sync_tick",
|
|
8301
|
-
"meta.sync_controller.synced_signals",
|
|
8302
|
-
"meta.sync_requested"
|
|
8303
|
-
).then(this.splitTasksForRegistration);
|
|
8304
|
-
CadenzaService.createMetaTask("Get all intents", (ctx) => {
|
|
8305
|
-
return {
|
|
8306
|
-
...ctx,
|
|
8307
|
-
intents: Array.from(CadenzaService.inquiryBroker.intents.values())
|
|
8308
|
-
};
|
|
8309
|
-
}).doOn(
|
|
8310
|
-
"meta.sync_controller.sync_tick",
|
|
8311
|
-
"meta.service_registry.initial_sync_complete",
|
|
8312
|
-
"meta.sync_requested"
|
|
8313
|
-
).then(this.splitIntentsTask);
|
|
8314
|
-
CadenzaService.registry.getAllRoutines.clone().doOn(
|
|
8315
|
-
"meta.sync_controller.sync_tick",
|
|
8316
|
-
"meta.service_registry.initial_sync_complete",
|
|
8317
|
-
"meta.sync_requested"
|
|
8318
|
-
).then(this.splitRoutinesTask);
|
|
8319
|
-
CadenzaService.createMetaTask("Get all actors", (ctx) => {
|
|
8320
|
-
return {
|
|
8321
|
-
...ctx,
|
|
8322
|
-
actors: CadenzaService.getAllActors()
|
|
8323
|
-
};
|
|
8324
|
-
}).doOn(
|
|
8528
|
+
).doOn(
|
|
8529
|
+
"meta.service_registry.service_inserted",
|
|
8530
|
+
"meta.service_registry.instance_inserted",
|
|
8325
8531
|
"meta.sync_controller.sync_tick",
|
|
8326
|
-
"meta.service_registry.initial_sync_complete",
|
|
8327
8532
|
"meta.sync_requested"
|
|
8328
|
-
)
|
|
8329
|
-
CadenzaService.createMetaTask(
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8533
|
+
);
|
|
8534
|
+
const startTaskPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8535
|
+
"Start task primitive sync",
|
|
8536
|
+
(ctx) => ctx,
|
|
8537
|
+
"Starts the task registration branch for the current sync cycle.",
|
|
8538
|
+
{
|
|
8539
|
+
register: false,
|
|
8540
|
+
isHidden: true
|
|
8333
8541
|
}
|
|
8334
|
-
return {
|
|
8335
|
-
...ctx,
|
|
8336
|
-
task
|
|
8337
|
-
};
|
|
8338
|
-
}).doOn("meta.sync_controller.task_registered").then(
|
|
8339
|
-
this.registerTaskMapTask,
|
|
8340
|
-
this.registerDeputyRelationshipTask
|
|
8341
8542
|
);
|
|
8342
|
-
CadenzaService.
|
|
8343
|
-
"
|
|
8344
|
-
|
|
8345
|
-
"
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
if (!task) {
|
|
8350
|
-
return false;
|
|
8543
|
+
const startSignalPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8544
|
+
"Start signal primitive sync",
|
|
8545
|
+
(ctx) => ctx,
|
|
8546
|
+
"Starts the signal registration branch for the current sync cycle.",
|
|
8547
|
+
{
|
|
8548
|
+
register: false,
|
|
8549
|
+
isHidden: true
|
|
8351
8550
|
}
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
"meta.sync_requested"
|
|
8361
|
-
).then(this.registerIntentToTaskMapTask);
|
|
8362
|
-
CadenzaService.createMetaTask("Get registered task for intent sync", (ctx) => {
|
|
8363
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8364
|
-
if (!task) {
|
|
8365
|
-
return false;
|
|
8551
|
+
);
|
|
8552
|
+
const startIntentPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8553
|
+
"Start intent primitive sync",
|
|
8554
|
+
(ctx) => ctx,
|
|
8555
|
+
"Starts the intent registration branch for the current sync cycle.",
|
|
8556
|
+
{
|
|
8557
|
+
register: false,
|
|
8558
|
+
isHidden: true
|
|
8366
8559
|
}
|
|
8367
|
-
|
|
8560
|
+
);
|
|
8561
|
+
const startActorPrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8562
|
+
"Start actor primitive sync",
|
|
8563
|
+
(ctx) => ctx,
|
|
8564
|
+
"Starts the actor registration branch for the current sync cycle.",
|
|
8565
|
+
{
|
|
8566
|
+
register: false,
|
|
8567
|
+
isHidden: true
|
|
8568
|
+
}
|
|
8569
|
+
);
|
|
8570
|
+
const startRoutinePrimitiveSyncTask = CadenzaService.createMetaTask(
|
|
8571
|
+
"Start routine primitive sync",
|
|
8572
|
+
(ctx) => ctx,
|
|
8573
|
+
"Starts the routine registration branch for the current sync cycle.",
|
|
8574
|
+
{
|
|
8575
|
+
register: false,
|
|
8576
|
+
isHidden: true
|
|
8577
|
+
}
|
|
8578
|
+
);
|
|
8579
|
+
startBootstrapSyncTask.then(
|
|
8580
|
+
startTaskPrimitiveSyncTask,
|
|
8581
|
+
startSignalPrimitiveSyncTask,
|
|
8582
|
+
startIntentPrimitiveSyncTask,
|
|
8583
|
+
startActorPrimitiveSyncTask,
|
|
8584
|
+
startRoutinePrimitiveSyncTask
|
|
8585
|
+
);
|
|
8586
|
+
const getAllTasksForSyncTask = CadenzaService.registry.getAllTasks.clone();
|
|
8587
|
+
startTaskPrimitiveSyncTask.then(
|
|
8588
|
+
getAllTasksForSyncTask,
|
|
8589
|
+
gatherTaskRegistrationTask
|
|
8590
|
+
);
|
|
8591
|
+
getAllTasksForSyncTask.then(this.splitTasksForRegistration);
|
|
8592
|
+
const getSignalsForSyncTask = CadenzaService.signalBroker.getSignalsTask.clone();
|
|
8593
|
+
startSignalPrimitiveSyncTask.then(
|
|
8594
|
+
getSignalsForSyncTask,
|
|
8595
|
+
gatherSignalRegistrationTask
|
|
8596
|
+
);
|
|
8597
|
+
getSignalsForSyncTask.then(this.splitSignalsTask);
|
|
8598
|
+
const getAllIntentsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8599
|
+
"Get all intents for sync",
|
|
8600
|
+
(ctx) => ({
|
|
8368
8601
|
...ctx,
|
|
8369
|
-
|
|
8370
|
-
}
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
"meta.sync_requested"
|
|
8376
|
-
).then(this.registerActorTaskMapTask);
|
|
8377
|
-
CadenzaService.createMetaTask("Get registered task for actor sync", (ctx) => {
|
|
8378
|
-
const task = ctx.task ?? (ctx.__taskName ? CadenzaService.get(ctx.__taskName) : void 0);
|
|
8379
|
-
if (!task) {
|
|
8380
|
-
return false;
|
|
8602
|
+
intents: Array.from(CadenzaService.inquiryBroker.intents.values())
|
|
8603
|
+
}),
|
|
8604
|
+
"Collects local intents for the primitive sync phase.",
|
|
8605
|
+
{
|
|
8606
|
+
register: false,
|
|
8607
|
+
isHidden: true
|
|
8381
8608
|
}
|
|
8382
|
-
|
|
8609
|
+
);
|
|
8610
|
+
startIntentPrimitiveSyncTask.then(
|
|
8611
|
+
getAllIntentsForSyncTask,
|
|
8612
|
+
gatherIntentRegistrationTask
|
|
8613
|
+
);
|
|
8614
|
+
getAllIntentsForSyncTask.then(this.splitIntentsTask);
|
|
8615
|
+
const getAllActorsForSyncTask = CadenzaService.createUniqueMetaTask(
|
|
8616
|
+
"Get all actors for sync",
|
|
8617
|
+
(ctx) => ({
|
|
8383
8618
|
...ctx,
|
|
8384
|
-
|
|
8385
|
-
}
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
return false;
|
|
8392
|
-
}
|
|
8393
|
-
return ctx;
|
|
8394
|
-
}
|
|
8395
|
-
).then(this.registerActorTaskMapTask)
|
|
8619
|
+
actors: CadenzaService.getAllActors()
|
|
8620
|
+
}),
|
|
8621
|
+
"Collects local actors for the primitive sync phase.",
|
|
8622
|
+
{
|
|
8623
|
+
register: false,
|
|
8624
|
+
isHidden: true
|
|
8625
|
+
}
|
|
8396
8626
|
);
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
"meta.sync_requested"
|
|
8401
|
-
).then(
|
|
8402
|
-
CadenzaService.createMetaTask(
|
|
8403
|
-
"Ensure routine and task sync ready",
|
|
8404
|
-
(ctx) => {
|
|
8405
|
-
if (!this.tasksSynced || !this.routinesSynced) {
|
|
8406
|
-
return false;
|
|
8407
|
-
}
|
|
8408
|
-
return ctx;
|
|
8409
|
-
}
|
|
8410
|
-
).then(this.splitTasksInRoutines)
|
|
8627
|
+
startActorPrimitiveSyncTask.then(
|
|
8628
|
+
getAllActorsForSyncTask,
|
|
8629
|
+
gatherActorRegistrationTask
|
|
8411
8630
|
);
|
|
8412
|
-
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8631
|
+
getAllActorsForSyncTask.then(this.splitActorsForRegistration);
|
|
8632
|
+
const getAllRoutinesForSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
8633
|
+
startRoutinePrimitiveSyncTask.then(
|
|
8634
|
+
getAllRoutinesForSyncTask,
|
|
8635
|
+
gatherRoutineRegistrationTask
|
|
8636
|
+
);
|
|
8637
|
+
getAllRoutinesForSyncTask.then(this.splitRoutinesTask);
|
|
8638
|
+
const iterateTasksForDirectionalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8639
|
+
startDirectionalTaskMapSyncTask.then(
|
|
8640
|
+
iterateTasksForDirectionalTaskMapSyncTask,
|
|
8641
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
8642
|
+
);
|
|
8643
|
+
iterateTasksForDirectionalTaskMapSyncTask.then(
|
|
8644
|
+
this.registerTaskMapTask,
|
|
8645
|
+
this.registerDeputyRelationshipTask
|
|
8646
|
+
);
|
|
8647
|
+
recordTaskMapRegistrationTask.then(gatherDirectionalTaskMapRegistrationTask);
|
|
8648
|
+
recordDeputyRelationshipRegistrationTask.then(
|
|
8649
|
+
gatherDirectionalTaskMapRegistrationTask
|
|
8650
|
+
);
|
|
8651
|
+
gatherDirectionalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8652
|
+
const iterateTasksForSignalTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8653
|
+
startSignalTaskMapSyncTask.then(
|
|
8654
|
+
iterateTasksForSignalTaskMapSyncTask,
|
|
8655
|
+
gatherSignalTaskMapRegistrationTask
|
|
8656
|
+
);
|
|
8657
|
+
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
8658
|
+
registerSignalTask.then(gatherSignalTaskMapRegistrationTask);
|
|
8659
|
+
gatherSignalTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8660
|
+
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8661
|
+
startIntentTaskMapSyncTask.then(
|
|
8662
|
+
iterateTasksForIntentTaskMapSyncTask,
|
|
8663
|
+
gatherIntentTaskMapRegistrationTask
|
|
8664
|
+
);
|
|
8665
|
+
iterateTasksForIntentTaskMapSyncTask.then(this.registerIntentToTaskMapTask);
|
|
8666
|
+
registerIntentTask.then(gatherIntentTaskMapRegistrationTask);
|
|
8667
|
+
gatherIntentTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8668
|
+
const iterateTasksForActorTaskMapSyncTask = CadenzaService.registry.doForEachTask.clone();
|
|
8669
|
+
startActorTaskMapSyncTask.then(
|
|
8670
|
+
iterateTasksForActorTaskMapSyncTask,
|
|
8671
|
+
gatherActorTaskMapRegistrationTask
|
|
8672
|
+
);
|
|
8673
|
+
iterateTasksForActorTaskMapSyncTask.then(this.registerActorTaskMapTask);
|
|
8674
|
+
recordActorTaskMapRegistrationTask.then(gatherActorTaskMapRegistrationTask);
|
|
8675
|
+
gatherActorTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8676
|
+
const getAllRoutinesForTaskMapSyncTask = CadenzaService.registry.getAllRoutines.clone();
|
|
8677
|
+
startRoutineTaskMapSyncTask.then(
|
|
8678
|
+
getAllRoutinesForTaskMapSyncTask,
|
|
8679
|
+
gatherRoutineTaskMapRegistrationTask
|
|
8680
|
+
);
|
|
8681
|
+
getAllRoutinesForTaskMapSyncTask.then(this.splitTasksInRoutines);
|
|
8682
|
+
registerTaskToRoutineMapTask.then(gatherRoutineTaskMapRegistrationTask);
|
|
8683
|
+
gatherRoutineTaskMapRegistrationTask.then(mapPhaseBarrierTask);
|
|
8684
|
+
CadenzaService.createMetaTask(
|
|
8685
|
+
"Request sync after local service instance registration",
|
|
8686
|
+
(ctx) => {
|
|
8687
|
+
for (const delayMs of EARLY_SYNC_TICK_DELAYS_MS) {
|
|
8688
|
+
CadenzaService.schedule(
|
|
8689
|
+
"meta.sync_controller.sync_tick",
|
|
8690
|
+
{
|
|
8691
|
+
...buildMinimalSyncSignalContext(ctx),
|
|
8692
|
+
__syncing: true
|
|
8693
|
+
},
|
|
8694
|
+
delayMs
|
|
8695
|
+
);
|
|
8422
8696
|
}
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
{ __syncing: true },
|
|
8430
|
-
3e5,
|
|
8431
|
-
true
|
|
8432
|
-
);
|
|
8433
|
-
} else {
|
|
8434
|
-
CadenzaService.interval(
|
|
8435
|
-
"meta.sync_controller.sync_tick",
|
|
8436
|
-
{ __syncing: true },
|
|
8437
|
-
18e4
|
|
8438
|
-
);
|
|
8439
|
-
CadenzaService.schedule(
|
|
8440
|
-
"meta.sync_controller.sync_tick",
|
|
8441
|
-
{ __syncing: true },
|
|
8442
|
-
250
|
|
8443
|
-
);
|
|
8444
|
-
for (const delayMs of EARLY_SYNC_REQUEST_DELAYS_MS) {
|
|
8445
|
-
CadenzaService.schedule("meta.sync_requested", { __syncing: true }, delayMs);
|
|
8697
|
+
return true;
|
|
8698
|
+
},
|
|
8699
|
+
"Schedules the early bootstrap sync burst after local instance registration so startup-defined primitives can converge deterministically.",
|
|
8700
|
+
{
|
|
8701
|
+
register: false,
|
|
8702
|
+
isHidden: true
|
|
8446
8703
|
}
|
|
8447
|
-
|
|
8704
|
+
).doOn("meta.service_registry.instance_inserted");
|
|
8705
|
+
CadenzaService.interval(
|
|
8706
|
+
"meta.sync_controller.sync_tick",
|
|
8707
|
+
{ __syncing: true },
|
|
8708
|
+
this.isCadenzaDBReady ? 18e4 : 3e5
|
|
8709
|
+
);
|
|
8448
8710
|
}
|
|
8449
8711
|
};
|
|
8450
8712
|
|
|
@@ -8619,6 +8881,47 @@ function resolveBootstrapEndpoint(options) {
|
|
|
8619
8881
|
|
|
8620
8882
|
// src/Cadenza.ts
|
|
8621
8883
|
var CadenzaService = class {
|
|
8884
|
+
static replayRegisteredTaskIntentAssociations() {
|
|
8885
|
+
for (const task of this.registry.tasks.values()) {
|
|
8886
|
+
if (!task.register || task.isHidden || task.handlesIntents.size === 0) {
|
|
8887
|
+
continue;
|
|
8888
|
+
}
|
|
8889
|
+
for (const intentName of task.handlesIntents) {
|
|
8890
|
+
task.emitWithMetadata("meta.task.intent_associated", {
|
|
8891
|
+
data: {
|
|
8892
|
+
intentName,
|
|
8893
|
+
taskName: task.name,
|
|
8894
|
+
taskVersion: task.version
|
|
8895
|
+
},
|
|
8896
|
+
taskInstance: task,
|
|
8897
|
+
__isSubMeta: task.isSubMeta
|
|
8898
|
+
});
|
|
8899
|
+
}
|
|
8900
|
+
}
|
|
8901
|
+
}
|
|
8902
|
+
static replayRegisteredTaskSignalObservations() {
|
|
8903
|
+
for (const task of this.registry.tasks.values()) {
|
|
8904
|
+
if (!task.register || task.isHidden || task.observedSignals.size === 0) {
|
|
8905
|
+
continue;
|
|
8906
|
+
}
|
|
8907
|
+
for (const signalName of task.observedSignals) {
|
|
8908
|
+
task.emitWithMetadata("meta.task.observed_signal", {
|
|
8909
|
+
data: {
|
|
8910
|
+
signalName,
|
|
8911
|
+
taskName: task.name,
|
|
8912
|
+
taskVersion: task.version
|
|
8913
|
+
},
|
|
8914
|
+
taskInstance: task,
|
|
8915
|
+
signalName,
|
|
8916
|
+
__isSubMeta: task.isSubMeta
|
|
8917
|
+
});
|
|
8918
|
+
}
|
|
8919
|
+
}
|
|
8920
|
+
}
|
|
8921
|
+
static replayRegisteredTaskGraphMetadata() {
|
|
8922
|
+
this.replayRegisteredTaskSignalObservations();
|
|
8923
|
+
this.replayRegisteredTaskIntentAssociations();
|
|
8924
|
+
}
|
|
8622
8925
|
static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
|
|
8623
8926
|
const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
8624
8927
|
const helperSuffix = (0, import_lodash_es.camelCase)(String(tableName ?? "").trim());
|
|
@@ -9487,6 +9790,7 @@ var CadenzaService = class {
|
|
|
9487
9790
|
const serviceId = options.customServiceId ?? (0, import_uuid5.v4)();
|
|
9488
9791
|
this.serviceRegistry.serviceName = serviceName;
|
|
9489
9792
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
9793
|
+
this.serviceRegistry.connectsToCadenzaDB = !!options.cadenzaDB?.connect;
|
|
9490
9794
|
this.setHydrationResults(options.hydration);
|
|
9491
9795
|
const explicitFrontendMode = options.isFrontend;
|
|
9492
9796
|
options = {
|
|
@@ -9515,6 +9819,22 @@ var CadenzaService = class {
|
|
|
9515
9819
|
this.serviceRegistry.useSocket = !!options.useSocket;
|
|
9516
9820
|
this.serviceRegistry.retryCount = options.retryCount ?? 3;
|
|
9517
9821
|
this.ensureTransportControllers(isFrontend);
|
|
9822
|
+
if (!isFrontend) {
|
|
9823
|
+
this.createMetaTask(
|
|
9824
|
+
"Initialize graph metadata controller after initial sync",
|
|
9825
|
+
() => {
|
|
9826
|
+
GraphMetadataController.instance;
|
|
9827
|
+
return true;
|
|
9828
|
+
},
|
|
9829
|
+
"Delays direct graph-metadata registration until the bootstrap sync has completed.",
|
|
9830
|
+
{
|
|
9831
|
+
register: false,
|
|
9832
|
+
isHidden: true
|
|
9833
|
+
}
|
|
9834
|
+
).doOn("meta.service_registry.initial_sync_complete");
|
|
9835
|
+
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB";
|
|
9836
|
+
GraphSyncController.instance.init();
|
|
9837
|
+
}
|
|
9518
9838
|
const resolvedBootstrapEndpoint = options.cadenzaDB?.connect ? resolveBootstrapEndpoint({
|
|
9519
9839
|
runtime: isFrontend ? "browser" : "server",
|
|
9520
9840
|
bootstrap: options.bootstrap,
|
|
@@ -9626,14 +9946,13 @@ var CadenzaService = class {
|
|
|
9626
9946
|
);
|
|
9627
9947
|
}).doOn("meta.rest.handshake", "meta.socket.handshake");
|
|
9628
9948
|
}
|
|
9629
|
-
this.createMetaTask("Handle service setup completion", () => {
|
|
9949
|
+
this.createMetaTask("Handle service setup completion", (ctx, emit) => {
|
|
9950
|
+
if (options.cadenzaDB?.connect) {
|
|
9951
|
+
this.serviceRegistry.bootstrapFullSync(emit, ctx, "service_setup_completed");
|
|
9952
|
+
}
|
|
9630
9953
|
if (isFrontend) {
|
|
9631
9954
|
registerActorSessionPersistenceTasks();
|
|
9632
9955
|
this.ensureFrontendSyncLoop();
|
|
9633
|
-
} else {
|
|
9634
|
-
GraphMetadataController.instance;
|
|
9635
|
-
GraphSyncController.instance.isCadenzaDBReady = serviceName === "CadenzaDB" || !!options.cadenzaDB?.connect;
|
|
9636
|
-
GraphSyncController.instance.init();
|
|
9637
9956
|
}
|
|
9638
9957
|
this.log("Service created.");
|
|
9639
9958
|
return true;
|
|
@@ -9662,7 +9981,15 @@ var CadenzaService = class {
|
|
|
9662
9981
|
is_blocked: false,
|
|
9663
9982
|
health: {}
|
|
9664
9983
|
},
|
|
9665
|
-
__transportData:
|
|
9984
|
+
__transportData: declaredTransports.map((transport) => ({
|
|
9985
|
+
uuid: transport.uuid,
|
|
9986
|
+
service_instance_id: serviceId,
|
|
9987
|
+
role: transport.role,
|
|
9988
|
+
origin: transport.origin,
|
|
9989
|
+
protocols: transport.protocols ?? ["rest", "socket"],
|
|
9990
|
+
...transport.securityProfile ? { security_profile: transport.securityProfile } : {},
|
|
9991
|
+
...transport.authStrategy ? { auth_strategy: transport.authStrategy } : {}
|
|
9992
|
+
})),
|
|
9666
9993
|
__serviceName: serviceName,
|
|
9667
9994
|
__serviceInstanceId: serviceId,
|
|
9668
9995
|
__useSocket: options.useSocket,
|