@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.js CHANGED
@@ -8232,18 +8232,89 @@ function buildIntentRegistryData(intent) {
8232
8232
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8233
8233
  return CadenzaService.getLocalCadenzaDBInsertTask(tableName) ?? (isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0);
8234
8234
  }
8235
+ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
8236
+ "intent_registry",
8237
+ "routine",
8238
+ "task_to_routine_map",
8239
+ "signal_registry",
8240
+ "task",
8241
+ "actor",
8242
+ "actor_task_map",
8243
+ "signal_to_task_map",
8244
+ "intent_to_task_map",
8245
+ "directional_task_graph_map"
8246
+ ];
8235
8247
  var GraphSyncController = class _GraphSyncController {
8236
8248
  constructor() {
8237
8249
  this.registeredActors = /* @__PURE__ */ new Set();
8238
8250
  this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
8239
8251
  this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
8252
+ this.loggedAuthorityTaskIntentDiagnostics = /* @__PURE__ */ new Set();
8240
8253
  this.isCadenzaDBReady = false;
8254
+ this.initialized = false;
8255
+ this.initRetryScheduled = false;
8256
+ this.loggedCadenzaDBIntentSweep = false;
8257
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
8241
8258
  }
8242
8259
  static get instance() {
8243
8260
  if (!this._instance) this._instance = new _GraphSyncController();
8244
8261
  return this._instance;
8245
8262
  }
8263
+ getMissingLocalCadenzaDBInsertTables() {
8264
+ return CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES.filter(
8265
+ (tableName) => !CadenzaService.getLocalCadenzaDBInsertTask(tableName)
8266
+ );
8267
+ }
8268
+ ensureRetryInitTask() {
8269
+ if (this.initRetryTask) {
8270
+ return this.initRetryTask;
8271
+ }
8272
+ this.initRetryTask = CadenzaService.get("Retry graph sync init") ?? CadenzaService.createUniqueMetaTask(
8273
+ "Retry graph sync init",
8274
+ () => {
8275
+ this.initRetryScheduled = false;
8276
+ this.init();
8277
+ return true;
8278
+ },
8279
+ "Retries graph sync controller initialization once local authority tasks exist."
8280
+ ).doOn("meta.sync_controller.init_retry");
8281
+ return this.initRetryTask;
8282
+ }
8246
8283
  init() {
8284
+ if (this.initialized) {
8285
+ return;
8286
+ }
8287
+ const serviceName = resolveSyncServiceName();
8288
+ if (serviceName === "CadenzaDB") {
8289
+ const missingLocalInsertTables = this.getMissingLocalCadenzaDBInsertTables();
8290
+ if (missingLocalInsertTables.length > 0) {
8291
+ this.ensureRetryInitTask();
8292
+ const missingKey = missingLocalInsertTables.join(",");
8293
+ if (missingKey !== this.lastMissingLocalCadenzaDBInsertTablesKey) {
8294
+ this.lastMissingLocalCadenzaDBInsertTablesKey = missingKey;
8295
+ CadenzaService.log(
8296
+ "Waiting for local CadenzaDB sync insert tasks before initializing graph sync controller.",
8297
+ {
8298
+ missingLocalInsertTables
8299
+ },
8300
+ "info"
8301
+ );
8302
+ }
8303
+ if (!this.initRetryScheduled) {
8304
+ this.initRetryScheduled = true;
8305
+ CadenzaService.schedule(
8306
+ "meta.sync_controller.init_retry",
8307
+ {
8308
+ __missingLocalInsertTables: missingLocalInsertTables
8309
+ },
8310
+ 250
8311
+ );
8312
+ }
8313
+ return;
8314
+ }
8315
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
8316
+ }
8317
+ this.initialized = true;
8247
8318
  const insertIntentRegistryTask = resolveSyncInsertTask(
8248
8319
  this.isCadenzaDBReady,
8249
8320
  "intent_registry",
@@ -8262,8 +8333,8 @@ var GraphSyncController = class _GraphSyncController {
8262
8333
  async function* (ctx, emit) {
8263
8334
  const { routines } = ctx;
8264
8335
  if (!routines) return;
8265
- const serviceName = resolveSyncServiceName();
8266
- if (!serviceName) {
8336
+ const serviceName2 = resolveSyncServiceName();
8337
+ if (!serviceName2) {
8267
8338
  return;
8268
8339
  }
8269
8340
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -8276,7 +8347,7 @@ var GraphSyncController = class _GraphSyncController {
8276
8347
  name: routine.name,
8277
8348
  version: routine.version,
8278
8349
  description: routine.description,
8279
- serviceName,
8350
+ serviceName: serviceName2,
8280
8351
  isMeta: routine.isMeta
8281
8352
  },
8282
8353
  __routineName: routine.name
@@ -8319,8 +8390,8 @@ var GraphSyncController = class _GraphSyncController {
8319
8390
  function* (ctx) {
8320
8391
  const { routines } = ctx;
8321
8392
  if (!routines) return;
8322
- const serviceName = resolveSyncServiceName();
8323
- if (!serviceName) {
8393
+ const serviceName2 = resolveSyncServiceName();
8394
+ if (!serviceName2) {
8324
8395
  return;
8325
8396
  }
8326
8397
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -8342,7 +8413,7 @@ var GraphSyncController = class _GraphSyncController {
8342
8413
  taskVersion: nextTask.version,
8343
8414
  routineName: routine.name,
8344
8415
  routineVersion: routine.version,
8345
- serviceName
8416
+ serviceName: serviceName2
8346
8417
  },
8347
8418
  __routineName: routine.name,
8348
8419
  __taskName: nextTask.name
@@ -8447,8 +8518,8 @@ var GraphSyncController = class _GraphSyncController {
8447
8518
  delayMs: 3e3
8448
8519
  });
8449
8520
  const tasks = ctx.tasks;
8450
- const serviceName = resolveSyncServiceName();
8451
- if (!serviceName) {
8521
+ const serviceName2 = resolveSyncServiceName();
8522
+ if (!serviceName2) {
8452
8523
  return;
8453
8524
  }
8454
8525
  for (const task of tasks) {
@@ -8480,7 +8551,7 @@ var GraphSyncController = class _GraphSyncController {
8480
8551
  retryDelay: task.retryDelay,
8481
8552
  retryDelayMax: task.retryDelayMax,
8482
8553
  retryDelayFactor: task.retryDelayFactor,
8483
- service_name: serviceName,
8554
+ service_name: serviceName2,
8484
8555
  signals: {
8485
8556
  emits: Array.from(task.emitsSignals),
8486
8557
  signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
@@ -8533,15 +8604,15 @@ var GraphSyncController = class _GraphSyncController {
8533
8604
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
8534
8605
  delayMs: 3e3
8535
8606
  });
8536
- const serviceName = resolveSyncServiceName();
8537
- if (!serviceName) {
8607
+ const serviceName2 = resolveSyncServiceName();
8608
+ if (!serviceName2) {
8538
8609
  return;
8539
8610
  }
8540
8611
  const actors = ctx.actors ?? [];
8541
8612
  for (const actor of actors) {
8542
8613
  const data = {
8543
8614
  ...buildActorRegistrationData(actor),
8544
- service_name: serviceName
8615
+ service_name: serviceName2
8545
8616
  };
8546
8617
  if (!data.name) {
8547
8618
  continue;
@@ -8598,11 +8669,11 @@ var GraphSyncController = class _GraphSyncController {
8598
8669
  if (!metadata?.actorName) {
8599
8670
  return;
8600
8671
  }
8601
- const serviceName = resolveSyncServiceName(task);
8602
- if (!serviceName) {
8672
+ const serviceName2 = resolveSyncServiceName(task);
8673
+ if (!serviceName2) {
8603
8674
  return;
8604
8675
  }
8605
- const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName}`;
8676
+ const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
8606
8677
  if (this.registeredActorTaskMaps.has(registrationKey)) {
8607
8678
  return;
8608
8679
  }
@@ -8612,7 +8683,7 @@ var GraphSyncController = class _GraphSyncController {
8612
8683
  actor_version: 1,
8613
8684
  task_name: task.name,
8614
8685
  task_version: task.version,
8615
- service_name: serviceName,
8686
+ service_name: serviceName2,
8616
8687
  mode: metadata.mode,
8617
8688
  description: task.description ?? metadata.actorDescription ?? "",
8618
8689
  is_meta: metadata.actorKind === "meta" || task.isMeta === true
@@ -8668,8 +8739,8 @@ var GraphSyncController = class _GraphSyncController {
8668
8739
  function* (ctx) {
8669
8740
  const task = ctx.task;
8670
8741
  if (task.hidden || !task.register) return;
8671
- const serviceName = resolveSyncServiceName(task);
8672
- if (!serviceName) {
8742
+ const serviceName2 = resolveSyncServiceName(task);
8743
+ if (!serviceName2) {
8673
8744
  return;
8674
8745
  }
8675
8746
  for (const signal of task.observedSignals) {
@@ -8682,7 +8753,7 @@ var GraphSyncController = class _GraphSyncController {
8682
8753
  isGlobal,
8683
8754
  taskName: task.name,
8684
8755
  taskVersion: task.version,
8685
- serviceName
8756
+ serviceName: serviceName2
8686
8757
  },
8687
8758
  __taskName: task.name,
8688
8759
  __signal: signal
@@ -8716,6 +8787,24 @@ var GraphSyncController = class _GraphSyncController {
8716
8787
  delayMs: 3e3
8717
8788
  });
8718
8789
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
8790
+ if (resolveSyncServiceName() === "CadenzaDB" && !this.loggedCadenzaDBIntentSweep) {
8791
+ const intentNames = intents.map((intent) => String(intent?.name ?? "").trim()).filter(Boolean);
8792
+ const authorityIntentNames = intentNames.filter(
8793
+ (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")
8794
+ );
8795
+ CadenzaService.log(
8796
+ "CadenzaDB intent sweep diagnostics.",
8797
+ {
8798
+ totalIntents: intentNames.length,
8799
+ hasMetaServiceRegistryFullSync: intentNames.includes(
8800
+ "meta-service-registry-full-sync"
8801
+ ),
8802
+ authorityIntentNames
8803
+ },
8804
+ "info"
8805
+ );
8806
+ this.loggedCadenzaDBIntentSweep = true;
8807
+ }
8719
8808
  for (const intent of intents) {
8720
8809
  const intentData = buildIntentRegistryData(intent);
8721
8810
  if (!intentData) {
@@ -8768,12 +8857,34 @@ var GraphSyncController = class _GraphSyncController {
8768
8857
  function* (ctx) {
8769
8858
  const task = ctx.task;
8770
8859
  if (task.hidden || !task.register) return;
8771
- const serviceName = resolveSyncServiceName(task);
8772
- if (!serviceName) {
8860
+ const serviceName2 = resolveSyncServiceName(task);
8861
+ if (!serviceName2) {
8773
8862
  return;
8774
8863
  }
8775
8864
  task.__registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
8776
8865
  task.__invalidMetaIntentWarnings = task.__invalidMetaIntentWarnings ?? /* @__PURE__ */ new Set();
8866
+ if (serviceName2 === "CadenzaDB" && [
8867
+ "Query service_instance",
8868
+ "Query service_instance_transport",
8869
+ "Query intent_to_task_map",
8870
+ "Query signal_to_task_map"
8871
+ ].includes(task.name)) {
8872
+ const authorityTaskKey = `${task.name}:${task.version}`;
8873
+ if (!this.loggedAuthorityTaskIntentDiagnostics.has(authorityTaskKey)) {
8874
+ this.loggedAuthorityTaskIntentDiagnostics.add(authorityTaskKey);
8875
+ CadenzaService.log(
8876
+ "CadenzaDB authority task intent diagnostics.",
8877
+ {
8878
+ taskName: task.name,
8879
+ taskVersion: task.version,
8880
+ isMeta: task.isMeta,
8881
+ handlesIntents: Array.from(task.handlesIntents ?? []),
8882
+ registeredIntents: Array.from(task.__registeredIntents ?? [])
8883
+ },
8884
+ "info"
8885
+ );
8886
+ }
8887
+ }
8777
8888
  for (const intent of task.handlesIntents) {
8778
8889
  if (task.__registeredIntents.has(intent)) continue;
8779
8890
  if (isMetaIntentName(intent) && !task.isMeta) {
@@ -8800,7 +8911,7 @@ var GraphSyncController = class _GraphSyncController {
8800
8911
  intentName: intent,
8801
8912
  taskName: task.name,
8802
8913
  taskVersion: task.version,
8803
- serviceName
8914
+ serviceName: serviceName2
8804
8915
  },
8805
8916
  __taskName: task.name,
8806
8917
  __intent: intent,
@@ -8809,11 +8920,11 @@ var GraphSyncController = class _GraphSyncController {
8809
8920
  intentName: intent,
8810
8921
  taskName: task.name,
8811
8922
  taskVersion: task.version,
8812
- serviceName
8923
+ serviceName: serviceName2
8813
8924
  }
8814
8925
  };
8815
8926
  }
8816
- }
8927
+ }.bind(this)
8817
8928
  ).then(
8818
8929
  CadenzaService.createMetaTask(
8819
8930
  "Prepare intent definition for intent-to-task map",
@@ -8878,8 +8989,8 @@ var GraphSyncController = class _GraphSyncController {
8878
8989
  if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register) {
8879
8990
  continue;
8880
8991
  }
8881
- const serviceName = resolveSyncServiceName(t);
8882
- if (!serviceName) {
8992
+ const serviceName2 = resolveSyncServiceName(t);
8993
+ if (!serviceName2) {
8883
8994
  continue;
8884
8995
  }
8885
8996
  yield {
@@ -8888,7 +8999,7 @@ var GraphSyncController = class _GraphSyncController {
8888
8999
  taskVersion: t.version,
8889
9000
  predecessorTaskName: task.name,
8890
9001
  predecessorTaskVersion: task.version,
8891
- serviceName,
9002
+ serviceName: serviceName2,
8892
9003
  predecessorServiceName
8893
9004
  },
8894
9005
  __taskName: task.name,
@@ -8937,16 +9048,16 @@ var GraphSyncController = class _GraphSyncController {
8937
9048
  if (task.hidden || !task.register) return;
8938
9049
  if (task.isDeputy && !task.signalName) {
8939
9050
  if (task.registeredDeputyMap) return;
8940
- const serviceName = resolveSyncServiceName(task);
9051
+ const serviceName2 = resolveSyncServiceName(task);
8941
9052
  const predecessorServiceName = resolveSyncServiceName();
8942
- if (!serviceName || !predecessorServiceName) {
9053
+ if (!serviceName2 || !predecessorServiceName) {
8943
9054
  return;
8944
9055
  }
8945
9056
  return {
8946
9057
  data: {
8947
9058
  task_name: task.remoteRoutineName,
8948
9059
  task_version: 1,
8949
- service_name: serviceName,
9060
+ service_name: serviceName2,
8950
9061
  predecessor_task_name: task.name,
8951
9062
  predecessor_task_version: task.version,
8952
9063
  predecessor_service_name: predecessorServiceName