@cadenza.io/service 2.17.18 → 2.17.20

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/index.mjs CHANGED
@@ -8181,18 +8181,89 @@ function buildIntentRegistryData(intent) {
8181
8181
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8182
8182
  return CadenzaService.getLocalCadenzaDBInsertTask(tableName) ?? (isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0);
8183
8183
  }
8184
+ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
8185
+ "intent_registry",
8186
+ "routine",
8187
+ "task_to_routine_map",
8188
+ "signal_registry",
8189
+ "task",
8190
+ "actor",
8191
+ "actor_task_map",
8192
+ "signal_to_task_map",
8193
+ "intent_to_task_map",
8194
+ "directional_task_graph_map"
8195
+ ];
8184
8196
  var GraphSyncController = class _GraphSyncController {
8185
8197
  constructor() {
8186
8198
  this.registeredActors = /* @__PURE__ */ new Set();
8187
8199
  this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
8188
8200
  this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
8201
+ this.loggedAuthorityTaskIntentDiagnostics = /* @__PURE__ */ new Set();
8189
8202
  this.isCadenzaDBReady = false;
8203
+ this.initialized = false;
8204
+ this.initRetryScheduled = false;
8205
+ this.loggedCadenzaDBIntentSweep = false;
8206
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
8190
8207
  }
8191
8208
  static get instance() {
8192
8209
  if (!this._instance) this._instance = new _GraphSyncController();
8193
8210
  return this._instance;
8194
8211
  }
8212
+ getMissingLocalCadenzaDBInsertTables() {
8213
+ return CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES.filter(
8214
+ (tableName) => !CadenzaService.getLocalCadenzaDBInsertTask(tableName)
8215
+ );
8216
+ }
8217
+ ensureRetryInitTask() {
8218
+ if (this.initRetryTask) {
8219
+ return this.initRetryTask;
8220
+ }
8221
+ this.initRetryTask = CadenzaService.get("Retry graph sync init") ?? CadenzaService.createUniqueMetaTask(
8222
+ "Retry graph sync init",
8223
+ () => {
8224
+ this.initRetryScheduled = false;
8225
+ this.init();
8226
+ return true;
8227
+ },
8228
+ "Retries graph sync controller initialization once local authority tasks exist."
8229
+ ).doOn("meta.sync_controller.init_retry");
8230
+ return this.initRetryTask;
8231
+ }
8195
8232
  init() {
8233
+ if (this.initialized) {
8234
+ return;
8235
+ }
8236
+ const serviceName = resolveSyncServiceName();
8237
+ if (serviceName === "CadenzaDB") {
8238
+ const missingLocalInsertTables = this.getMissingLocalCadenzaDBInsertTables();
8239
+ if (missingLocalInsertTables.length > 0) {
8240
+ this.ensureRetryInitTask();
8241
+ const missingKey = missingLocalInsertTables.join(",");
8242
+ if (missingKey !== this.lastMissingLocalCadenzaDBInsertTablesKey) {
8243
+ this.lastMissingLocalCadenzaDBInsertTablesKey = missingKey;
8244
+ CadenzaService.log(
8245
+ "Waiting for local CadenzaDB sync insert tasks before initializing graph sync controller.",
8246
+ {
8247
+ missingLocalInsertTables
8248
+ },
8249
+ "info"
8250
+ );
8251
+ }
8252
+ if (!this.initRetryScheduled) {
8253
+ this.initRetryScheduled = true;
8254
+ CadenzaService.schedule(
8255
+ "meta.sync_controller.init_retry",
8256
+ {
8257
+ __missingLocalInsertTables: missingLocalInsertTables
8258
+ },
8259
+ 250
8260
+ );
8261
+ }
8262
+ return;
8263
+ }
8264
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
8265
+ }
8266
+ this.initialized = true;
8196
8267
  const insertIntentRegistryTask = resolveSyncInsertTask(
8197
8268
  this.isCadenzaDBReady,
8198
8269
  "intent_registry",
@@ -8211,8 +8282,8 @@ var GraphSyncController = class _GraphSyncController {
8211
8282
  async function* (ctx, emit) {
8212
8283
  const { routines } = ctx;
8213
8284
  if (!routines) return;
8214
- const serviceName = resolveSyncServiceName();
8215
- if (!serviceName) {
8285
+ const serviceName2 = resolveSyncServiceName();
8286
+ if (!serviceName2) {
8216
8287
  return;
8217
8288
  }
8218
8289
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -8225,7 +8296,7 @@ var GraphSyncController = class _GraphSyncController {
8225
8296
  name: routine.name,
8226
8297
  version: routine.version,
8227
8298
  description: routine.description,
8228
- serviceName,
8299
+ serviceName: serviceName2,
8229
8300
  isMeta: routine.isMeta
8230
8301
  },
8231
8302
  __routineName: routine.name
@@ -8268,8 +8339,8 @@ var GraphSyncController = class _GraphSyncController {
8268
8339
  function* (ctx) {
8269
8340
  const { routines } = ctx;
8270
8341
  if (!routines) return;
8271
- const serviceName = resolveSyncServiceName();
8272
- if (!serviceName) {
8342
+ const serviceName2 = resolveSyncServiceName();
8343
+ if (!serviceName2) {
8273
8344
  return;
8274
8345
  }
8275
8346
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -8291,7 +8362,7 @@ var GraphSyncController = class _GraphSyncController {
8291
8362
  taskVersion: nextTask.version,
8292
8363
  routineName: routine.name,
8293
8364
  routineVersion: routine.version,
8294
- serviceName
8365
+ serviceName: serviceName2
8295
8366
  },
8296
8367
  __routineName: routine.name,
8297
8368
  __taskName: nextTask.name
@@ -8396,8 +8467,8 @@ var GraphSyncController = class _GraphSyncController {
8396
8467
  delayMs: 3e3
8397
8468
  });
8398
8469
  const tasks = ctx.tasks;
8399
- const serviceName = resolveSyncServiceName();
8400
- if (!serviceName) {
8470
+ const serviceName2 = resolveSyncServiceName();
8471
+ if (!serviceName2) {
8401
8472
  return;
8402
8473
  }
8403
8474
  for (const task of tasks) {
@@ -8429,7 +8500,7 @@ var GraphSyncController = class _GraphSyncController {
8429
8500
  retryDelay: task.retryDelay,
8430
8501
  retryDelayMax: task.retryDelayMax,
8431
8502
  retryDelayFactor: task.retryDelayFactor,
8432
- service_name: serviceName,
8503
+ service_name: serviceName2,
8433
8504
  signals: {
8434
8505
  emits: Array.from(task.emitsSignals),
8435
8506
  signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
@@ -8482,15 +8553,15 @@ var GraphSyncController = class _GraphSyncController {
8482
8553
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
8483
8554
  delayMs: 3e3
8484
8555
  });
8485
- const serviceName = resolveSyncServiceName();
8486
- if (!serviceName) {
8556
+ const serviceName2 = resolveSyncServiceName();
8557
+ if (!serviceName2) {
8487
8558
  return;
8488
8559
  }
8489
8560
  const actors = ctx.actors ?? [];
8490
8561
  for (const actor of actors) {
8491
8562
  const data = {
8492
8563
  ...buildActorRegistrationData(actor),
8493
- service_name: serviceName
8564
+ service_name: serviceName2
8494
8565
  };
8495
8566
  if (!data.name) {
8496
8567
  continue;
@@ -8547,11 +8618,11 @@ var GraphSyncController = class _GraphSyncController {
8547
8618
  if (!metadata?.actorName) {
8548
8619
  return;
8549
8620
  }
8550
- const serviceName = resolveSyncServiceName(task);
8551
- if (!serviceName) {
8621
+ const serviceName2 = resolveSyncServiceName(task);
8622
+ if (!serviceName2) {
8552
8623
  return;
8553
8624
  }
8554
- const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName}`;
8625
+ const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
8555
8626
  if (this.registeredActorTaskMaps.has(registrationKey)) {
8556
8627
  return;
8557
8628
  }
@@ -8561,7 +8632,7 @@ var GraphSyncController = class _GraphSyncController {
8561
8632
  actor_version: 1,
8562
8633
  task_name: task.name,
8563
8634
  task_version: task.version,
8564
- service_name: serviceName,
8635
+ service_name: serviceName2,
8565
8636
  mode: metadata.mode,
8566
8637
  description: task.description ?? metadata.actorDescription ?? "",
8567
8638
  is_meta: metadata.actorKind === "meta" || task.isMeta === true
@@ -8617,8 +8688,8 @@ var GraphSyncController = class _GraphSyncController {
8617
8688
  function* (ctx) {
8618
8689
  const task = ctx.task;
8619
8690
  if (task.hidden || !task.register) return;
8620
- const serviceName = resolveSyncServiceName(task);
8621
- if (!serviceName) {
8691
+ const serviceName2 = resolveSyncServiceName(task);
8692
+ if (!serviceName2) {
8622
8693
  return;
8623
8694
  }
8624
8695
  for (const signal of task.observedSignals) {
@@ -8631,7 +8702,7 @@ var GraphSyncController = class _GraphSyncController {
8631
8702
  isGlobal,
8632
8703
  taskName: task.name,
8633
8704
  taskVersion: task.version,
8634
- serviceName
8705
+ serviceName: serviceName2
8635
8706
  },
8636
8707
  __taskName: task.name,
8637
8708
  __signal: signal
@@ -8665,6 +8736,24 @@ var GraphSyncController = class _GraphSyncController {
8665
8736
  delayMs: 3e3
8666
8737
  });
8667
8738
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
8739
+ if (resolveSyncServiceName() === "CadenzaDB" && !this.loggedCadenzaDBIntentSweep) {
8740
+ const intentNames = intents.map((intent) => String(intent?.name ?? "").trim()).filter(Boolean);
8741
+ const authorityIntentNames = intentNames.filter(
8742
+ (intentName) => intentName === "meta-service-registry-full-sync" || intentName.includes("service_instance") || intentName.includes("service_instance_transport") || intentName.includes("intent_to_task_map") || intentName.includes("signal_to_task_map")
8743
+ );
8744
+ CadenzaService.log(
8745
+ "CadenzaDB intent sweep diagnostics.",
8746
+ {
8747
+ totalIntents: intentNames.length,
8748
+ hasMetaServiceRegistryFullSync: intentNames.includes(
8749
+ "meta-service-registry-full-sync"
8750
+ ),
8751
+ authorityIntentNames
8752
+ },
8753
+ "info"
8754
+ );
8755
+ this.loggedCadenzaDBIntentSweep = true;
8756
+ }
8668
8757
  for (const intent of intents) {
8669
8758
  const intentData = buildIntentRegistryData(intent);
8670
8759
  if (!intentData) {
@@ -8717,12 +8806,34 @@ var GraphSyncController = class _GraphSyncController {
8717
8806
  function* (ctx) {
8718
8807
  const task = ctx.task;
8719
8808
  if (task.hidden || !task.register) return;
8720
- const serviceName = resolveSyncServiceName(task);
8721
- if (!serviceName) {
8809
+ const serviceName2 = resolveSyncServiceName(task);
8810
+ if (!serviceName2) {
8722
8811
  return;
8723
8812
  }
8724
8813
  task.__registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
8725
8814
  task.__invalidMetaIntentWarnings = task.__invalidMetaIntentWarnings ?? /* @__PURE__ */ new Set();
8815
+ if (serviceName2 === "CadenzaDB" && [
8816
+ "Query service_instance",
8817
+ "Query service_instance_transport",
8818
+ "Query intent_to_task_map",
8819
+ "Query signal_to_task_map"
8820
+ ].includes(task.name)) {
8821
+ const authorityTaskKey = `${task.name}:${task.version}`;
8822
+ if (!this.loggedAuthorityTaskIntentDiagnostics.has(authorityTaskKey)) {
8823
+ this.loggedAuthorityTaskIntentDiagnostics.add(authorityTaskKey);
8824
+ CadenzaService.log(
8825
+ "CadenzaDB authority task intent diagnostics.",
8826
+ {
8827
+ taskName: task.name,
8828
+ taskVersion: task.version,
8829
+ isMeta: task.isMeta,
8830
+ handlesIntents: Array.from(task.handlesIntents ?? []),
8831
+ registeredIntents: Array.from(task.__registeredIntents ?? [])
8832
+ },
8833
+ "info"
8834
+ );
8835
+ }
8836
+ }
8726
8837
  for (const intent of task.handlesIntents) {
8727
8838
  if (task.__registeredIntents.has(intent)) continue;
8728
8839
  if (isMetaIntentName(intent) && !task.isMeta) {
@@ -8749,7 +8860,7 @@ var GraphSyncController = class _GraphSyncController {
8749
8860
  intentName: intent,
8750
8861
  taskName: task.name,
8751
8862
  taskVersion: task.version,
8752
- serviceName
8863
+ serviceName: serviceName2
8753
8864
  },
8754
8865
  __taskName: task.name,
8755
8866
  __intent: intent,
@@ -8758,11 +8869,11 @@ var GraphSyncController = class _GraphSyncController {
8758
8869
  intentName: intent,
8759
8870
  taskName: task.name,
8760
8871
  taskVersion: task.version,
8761
- serviceName
8872
+ serviceName: serviceName2
8762
8873
  }
8763
8874
  };
8764
8875
  }
8765
- }
8876
+ }.bind(this)
8766
8877
  ).then(
8767
8878
  CadenzaService.createMetaTask(
8768
8879
  "Prepare intent definition for intent-to-task map",
@@ -8827,8 +8938,8 @@ var GraphSyncController = class _GraphSyncController {
8827
8938
  if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register) {
8828
8939
  continue;
8829
8940
  }
8830
- const serviceName = resolveSyncServiceName(t);
8831
- if (!serviceName) {
8941
+ const serviceName2 = resolveSyncServiceName(t);
8942
+ if (!serviceName2) {
8832
8943
  continue;
8833
8944
  }
8834
8945
  yield {
@@ -8837,7 +8948,7 @@ var GraphSyncController = class _GraphSyncController {
8837
8948
  taskVersion: t.version,
8838
8949
  predecessorTaskName: task.name,
8839
8950
  predecessorTaskVersion: task.version,
8840
- serviceName,
8951
+ serviceName: serviceName2,
8841
8952
  predecessorServiceName
8842
8953
  },
8843
8954
  __taskName: task.name,
@@ -8886,16 +8997,16 @@ var GraphSyncController = class _GraphSyncController {
8886
8997
  if (task.hidden || !task.register) return;
8887
8998
  if (task.isDeputy && !task.signalName) {
8888
8999
  if (task.registeredDeputyMap) return;
8889
- const serviceName = resolveSyncServiceName(task);
9000
+ const serviceName2 = resolveSyncServiceName(task);
8890
9001
  const predecessorServiceName = resolveSyncServiceName();
8891
- if (!serviceName || !predecessorServiceName) {
9002
+ if (!serviceName2 || !predecessorServiceName) {
8892
9003
  return;
8893
9004
  }
8894
9005
  return {
8895
9006
  data: {
8896
9007
  task_name: task.remoteRoutineName,
8897
9008
  task_version: 1,
8898
- service_name: serviceName,
9009
+ service_name: serviceName2,
8899
9010
  predecessor_task_name: task.name,
8900
9011
  predecessor_task_version: task.version,
8901
9012
  predecessor_service_name: predecessorServiceName