@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.
@@ -5742,18 +5742,89 @@ function buildIntentRegistryData(intent) {
5742
5742
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
5743
5743
  return CadenzaService.getLocalCadenzaDBInsertTask(tableName) ?? (isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0);
5744
5744
  }
5745
+ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
5746
+ "intent_registry",
5747
+ "routine",
5748
+ "task_to_routine_map",
5749
+ "signal_registry",
5750
+ "task",
5751
+ "actor",
5752
+ "actor_task_map",
5753
+ "signal_to_task_map",
5754
+ "intent_to_task_map",
5755
+ "directional_task_graph_map"
5756
+ ];
5745
5757
  var GraphSyncController = class _GraphSyncController {
5746
5758
  constructor() {
5747
5759
  this.registeredActors = /* @__PURE__ */ new Set();
5748
5760
  this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
5749
5761
  this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
5762
+ this.loggedAuthorityTaskIntentDiagnostics = /* @__PURE__ */ new Set();
5750
5763
  this.isCadenzaDBReady = false;
5764
+ this.initialized = false;
5765
+ this.initRetryScheduled = false;
5766
+ this.loggedCadenzaDBIntentSweep = false;
5767
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
5751
5768
  }
5752
5769
  static get instance() {
5753
5770
  if (!this._instance) this._instance = new _GraphSyncController();
5754
5771
  return this._instance;
5755
5772
  }
5773
+ getMissingLocalCadenzaDBInsertTables() {
5774
+ return CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES.filter(
5775
+ (tableName) => !CadenzaService.getLocalCadenzaDBInsertTask(tableName)
5776
+ );
5777
+ }
5778
+ ensureRetryInitTask() {
5779
+ if (this.initRetryTask) {
5780
+ return this.initRetryTask;
5781
+ }
5782
+ this.initRetryTask = CadenzaService.get("Retry graph sync init") ?? CadenzaService.createUniqueMetaTask(
5783
+ "Retry graph sync init",
5784
+ () => {
5785
+ this.initRetryScheduled = false;
5786
+ this.init();
5787
+ return true;
5788
+ },
5789
+ "Retries graph sync controller initialization once local authority tasks exist."
5790
+ ).doOn("meta.sync_controller.init_retry");
5791
+ return this.initRetryTask;
5792
+ }
5756
5793
  init() {
5794
+ if (this.initialized) {
5795
+ return;
5796
+ }
5797
+ const serviceName = resolveSyncServiceName();
5798
+ if (serviceName === "CadenzaDB") {
5799
+ const missingLocalInsertTables = this.getMissingLocalCadenzaDBInsertTables();
5800
+ if (missingLocalInsertTables.length > 0) {
5801
+ this.ensureRetryInitTask();
5802
+ const missingKey = missingLocalInsertTables.join(",");
5803
+ if (missingKey !== this.lastMissingLocalCadenzaDBInsertTablesKey) {
5804
+ this.lastMissingLocalCadenzaDBInsertTablesKey = missingKey;
5805
+ CadenzaService.log(
5806
+ "Waiting for local CadenzaDB sync insert tasks before initializing graph sync controller.",
5807
+ {
5808
+ missingLocalInsertTables
5809
+ },
5810
+ "info"
5811
+ );
5812
+ }
5813
+ if (!this.initRetryScheduled) {
5814
+ this.initRetryScheduled = true;
5815
+ CadenzaService.schedule(
5816
+ "meta.sync_controller.init_retry",
5817
+ {
5818
+ __missingLocalInsertTables: missingLocalInsertTables
5819
+ },
5820
+ 250
5821
+ );
5822
+ }
5823
+ return;
5824
+ }
5825
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
5826
+ }
5827
+ this.initialized = true;
5757
5828
  const insertIntentRegistryTask = resolveSyncInsertTask(
5758
5829
  this.isCadenzaDBReady,
5759
5830
  "intent_registry",
@@ -5772,8 +5843,8 @@ var GraphSyncController = class _GraphSyncController {
5772
5843
  async function* (ctx, emit) {
5773
5844
  const { routines } = ctx;
5774
5845
  if (!routines) return;
5775
- const serviceName = resolveSyncServiceName();
5776
- if (!serviceName) {
5846
+ const serviceName2 = resolveSyncServiceName();
5847
+ if (!serviceName2) {
5777
5848
  return;
5778
5849
  }
5779
5850
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -5786,7 +5857,7 @@ var GraphSyncController = class _GraphSyncController {
5786
5857
  name: routine.name,
5787
5858
  version: routine.version,
5788
5859
  description: routine.description,
5789
- serviceName,
5860
+ serviceName: serviceName2,
5790
5861
  isMeta: routine.isMeta
5791
5862
  },
5792
5863
  __routineName: routine.name
@@ -5829,8 +5900,8 @@ var GraphSyncController = class _GraphSyncController {
5829
5900
  function* (ctx) {
5830
5901
  const { routines } = ctx;
5831
5902
  if (!routines) return;
5832
- const serviceName = resolveSyncServiceName();
5833
- if (!serviceName) {
5903
+ const serviceName2 = resolveSyncServiceName();
5904
+ if (!serviceName2) {
5834
5905
  return;
5835
5906
  }
5836
5907
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -5852,7 +5923,7 @@ var GraphSyncController = class _GraphSyncController {
5852
5923
  taskVersion: nextTask.version,
5853
5924
  routineName: routine.name,
5854
5925
  routineVersion: routine.version,
5855
- serviceName
5926
+ serviceName: serviceName2
5856
5927
  },
5857
5928
  __routineName: routine.name,
5858
5929
  __taskName: nextTask.name
@@ -5957,8 +6028,8 @@ var GraphSyncController = class _GraphSyncController {
5957
6028
  delayMs: 3e3
5958
6029
  });
5959
6030
  const tasks = ctx.tasks;
5960
- const serviceName = resolveSyncServiceName();
5961
- if (!serviceName) {
6031
+ const serviceName2 = resolveSyncServiceName();
6032
+ if (!serviceName2) {
5962
6033
  return;
5963
6034
  }
5964
6035
  for (const task of tasks) {
@@ -5990,7 +6061,7 @@ var GraphSyncController = class _GraphSyncController {
5990
6061
  retryDelay: task.retryDelay,
5991
6062
  retryDelayMax: task.retryDelayMax,
5992
6063
  retryDelayFactor: task.retryDelayFactor,
5993
- service_name: serviceName,
6064
+ service_name: serviceName2,
5994
6065
  signals: {
5995
6066
  emits: Array.from(task.emitsSignals),
5996
6067
  signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
@@ -6043,15 +6114,15 @@ var GraphSyncController = class _GraphSyncController {
6043
6114
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
6044
6115
  delayMs: 3e3
6045
6116
  });
6046
- const serviceName = resolveSyncServiceName();
6047
- if (!serviceName) {
6117
+ const serviceName2 = resolveSyncServiceName();
6118
+ if (!serviceName2) {
6048
6119
  return;
6049
6120
  }
6050
6121
  const actors = ctx.actors ?? [];
6051
6122
  for (const actor of actors) {
6052
6123
  const data = {
6053
6124
  ...buildActorRegistrationData(actor),
6054
- service_name: serviceName
6125
+ service_name: serviceName2
6055
6126
  };
6056
6127
  if (!data.name) {
6057
6128
  continue;
@@ -6108,11 +6179,11 @@ var GraphSyncController = class _GraphSyncController {
6108
6179
  if (!metadata?.actorName) {
6109
6180
  return;
6110
6181
  }
6111
- const serviceName = resolveSyncServiceName(task);
6112
- if (!serviceName) {
6182
+ const serviceName2 = resolveSyncServiceName(task);
6183
+ if (!serviceName2) {
6113
6184
  return;
6114
6185
  }
6115
- const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName}`;
6186
+ const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
6116
6187
  if (this.registeredActorTaskMaps.has(registrationKey)) {
6117
6188
  return;
6118
6189
  }
@@ -6122,7 +6193,7 @@ var GraphSyncController = class _GraphSyncController {
6122
6193
  actor_version: 1,
6123
6194
  task_name: task.name,
6124
6195
  task_version: task.version,
6125
- service_name: serviceName,
6196
+ service_name: serviceName2,
6126
6197
  mode: metadata.mode,
6127
6198
  description: task.description ?? metadata.actorDescription ?? "",
6128
6199
  is_meta: metadata.actorKind === "meta" || task.isMeta === true
@@ -6178,8 +6249,8 @@ var GraphSyncController = class _GraphSyncController {
6178
6249
  function* (ctx) {
6179
6250
  const task = ctx.task;
6180
6251
  if (task.hidden || !task.register) return;
6181
- const serviceName = resolveSyncServiceName(task);
6182
- if (!serviceName) {
6252
+ const serviceName2 = resolveSyncServiceName(task);
6253
+ if (!serviceName2) {
6183
6254
  return;
6184
6255
  }
6185
6256
  for (const signal of task.observedSignals) {
@@ -6192,7 +6263,7 @@ var GraphSyncController = class _GraphSyncController {
6192
6263
  isGlobal,
6193
6264
  taskName: task.name,
6194
6265
  taskVersion: task.version,
6195
- serviceName
6266
+ serviceName: serviceName2
6196
6267
  },
6197
6268
  __taskName: task.name,
6198
6269
  __signal: signal
@@ -6226,6 +6297,24 @@ var GraphSyncController = class _GraphSyncController {
6226
6297
  delayMs: 3e3
6227
6298
  });
6228
6299
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
6300
+ if (resolveSyncServiceName() === "CadenzaDB" && !this.loggedCadenzaDBIntentSweep) {
6301
+ const intentNames = intents.map((intent) => String(intent?.name ?? "").trim()).filter(Boolean);
6302
+ const authorityIntentNames = intentNames.filter(
6303
+ (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")
6304
+ );
6305
+ CadenzaService.log(
6306
+ "CadenzaDB intent sweep diagnostics.",
6307
+ {
6308
+ totalIntents: intentNames.length,
6309
+ hasMetaServiceRegistryFullSync: intentNames.includes(
6310
+ "meta-service-registry-full-sync"
6311
+ ),
6312
+ authorityIntentNames
6313
+ },
6314
+ "info"
6315
+ );
6316
+ this.loggedCadenzaDBIntentSweep = true;
6317
+ }
6229
6318
  for (const intent of intents) {
6230
6319
  const intentData = buildIntentRegistryData(intent);
6231
6320
  if (!intentData) {
@@ -6278,12 +6367,34 @@ var GraphSyncController = class _GraphSyncController {
6278
6367
  function* (ctx) {
6279
6368
  const task = ctx.task;
6280
6369
  if (task.hidden || !task.register) return;
6281
- const serviceName = resolveSyncServiceName(task);
6282
- if (!serviceName) {
6370
+ const serviceName2 = resolveSyncServiceName(task);
6371
+ if (!serviceName2) {
6283
6372
  return;
6284
6373
  }
6285
6374
  task.__registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
6286
6375
  task.__invalidMetaIntentWarnings = task.__invalidMetaIntentWarnings ?? /* @__PURE__ */ new Set();
6376
+ if (serviceName2 === "CadenzaDB" && [
6377
+ "Query service_instance",
6378
+ "Query service_instance_transport",
6379
+ "Query intent_to_task_map",
6380
+ "Query signal_to_task_map"
6381
+ ].includes(task.name)) {
6382
+ const authorityTaskKey = `${task.name}:${task.version}`;
6383
+ if (!this.loggedAuthorityTaskIntentDiagnostics.has(authorityTaskKey)) {
6384
+ this.loggedAuthorityTaskIntentDiagnostics.add(authorityTaskKey);
6385
+ CadenzaService.log(
6386
+ "CadenzaDB authority task intent diagnostics.",
6387
+ {
6388
+ taskName: task.name,
6389
+ taskVersion: task.version,
6390
+ isMeta: task.isMeta,
6391
+ handlesIntents: Array.from(task.handlesIntents ?? []),
6392
+ registeredIntents: Array.from(task.__registeredIntents ?? [])
6393
+ },
6394
+ "info"
6395
+ );
6396
+ }
6397
+ }
6287
6398
  for (const intent of task.handlesIntents) {
6288
6399
  if (task.__registeredIntents.has(intent)) continue;
6289
6400
  if (isMetaIntentName(intent) && !task.isMeta) {
@@ -6310,7 +6421,7 @@ var GraphSyncController = class _GraphSyncController {
6310
6421
  intentName: intent,
6311
6422
  taskName: task.name,
6312
6423
  taskVersion: task.version,
6313
- serviceName
6424
+ serviceName: serviceName2
6314
6425
  },
6315
6426
  __taskName: task.name,
6316
6427
  __intent: intent,
@@ -6319,11 +6430,11 @@ var GraphSyncController = class _GraphSyncController {
6319
6430
  intentName: intent,
6320
6431
  taskName: task.name,
6321
6432
  taskVersion: task.version,
6322
- serviceName
6433
+ serviceName: serviceName2
6323
6434
  }
6324
6435
  };
6325
6436
  }
6326
- }
6437
+ }.bind(this)
6327
6438
  ).then(
6328
6439
  CadenzaService.createMetaTask(
6329
6440
  "Prepare intent definition for intent-to-task map",
@@ -6388,8 +6499,8 @@ var GraphSyncController = class _GraphSyncController {
6388
6499
  if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register) {
6389
6500
  continue;
6390
6501
  }
6391
- const serviceName = resolveSyncServiceName(t);
6392
- if (!serviceName) {
6502
+ const serviceName2 = resolveSyncServiceName(t);
6503
+ if (!serviceName2) {
6393
6504
  continue;
6394
6505
  }
6395
6506
  yield {
@@ -6398,7 +6509,7 @@ var GraphSyncController = class _GraphSyncController {
6398
6509
  taskVersion: t.version,
6399
6510
  predecessorTaskName: task.name,
6400
6511
  predecessorTaskVersion: task.version,
6401
- serviceName,
6512
+ serviceName: serviceName2,
6402
6513
  predecessorServiceName
6403
6514
  },
6404
6515
  __taskName: task.name,
@@ -6447,16 +6558,16 @@ var GraphSyncController = class _GraphSyncController {
6447
6558
  if (task.hidden || !task.register) return;
6448
6559
  if (task.isDeputy && !task.signalName) {
6449
6560
  if (task.registeredDeputyMap) return;
6450
- const serviceName = resolveSyncServiceName(task);
6561
+ const serviceName2 = resolveSyncServiceName(task);
6451
6562
  const predecessorServiceName = resolveSyncServiceName();
6452
- if (!serviceName || !predecessorServiceName) {
6563
+ if (!serviceName2 || !predecessorServiceName) {
6453
6564
  return;
6454
6565
  }
6455
6566
  return {
6456
6567
  data: {
6457
6568
  task_name: task.remoteRoutineName,
6458
6569
  task_version: 1,
6459
- service_name: serviceName,
6570
+ service_name: serviceName2,
6460
6571
  predecessor_task_name: task.name,
6461
6572
  predecessor_task_version: task.version,
6462
6573
  predecessor_service_name: predecessorServiceName