@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.
@@ -5793,18 +5793,89 @@ function buildIntentRegistryData(intent) {
5793
5793
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
5794
5794
  return CadenzaService.getLocalCadenzaDBInsertTask(tableName) ?? (isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0);
5795
5795
  }
5796
+ var CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES = [
5797
+ "intent_registry",
5798
+ "routine",
5799
+ "task_to_routine_map",
5800
+ "signal_registry",
5801
+ "task",
5802
+ "actor",
5803
+ "actor_task_map",
5804
+ "signal_to_task_map",
5805
+ "intent_to_task_map",
5806
+ "directional_task_graph_map"
5807
+ ];
5796
5808
  var GraphSyncController = class _GraphSyncController {
5797
5809
  constructor() {
5798
5810
  this.registeredActors = /* @__PURE__ */ new Set();
5799
5811
  this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
5800
5812
  this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
5813
+ this.loggedAuthorityTaskIntentDiagnostics = /* @__PURE__ */ new Set();
5801
5814
  this.isCadenzaDBReady = false;
5815
+ this.initialized = false;
5816
+ this.initRetryScheduled = false;
5817
+ this.loggedCadenzaDBIntentSweep = false;
5818
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
5802
5819
  }
5803
5820
  static get instance() {
5804
5821
  if (!this._instance) this._instance = new _GraphSyncController();
5805
5822
  return this._instance;
5806
5823
  }
5824
+ getMissingLocalCadenzaDBInsertTables() {
5825
+ return CADENZA_DB_REQUIRED_LOCAL_SYNC_INSERT_TABLES.filter(
5826
+ (tableName) => !CadenzaService.getLocalCadenzaDBInsertTask(tableName)
5827
+ );
5828
+ }
5829
+ ensureRetryInitTask() {
5830
+ if (this.initRetryTask) {
5831
+ return this.initRetryTask;
5832
+ }
5833
+ this.initRetryTask = CadenzaService.get("Retry graph sync init") ?? CadenzaService.createUniqueMetaTask(
5834
+ "Retry graph sync init",
5835
+ () => {
5836
+ this.initRetryScheduled = false;
5837
+ this.init();
5838
+ return true;
5839
+ },
5840
+ "Retries graph sync controller initialization once local authority tasks exist."
5841
+ ).doOn("meta.sync_controller.init_retry");
5842
+ return this.initRetryTask;
5843
+ }
5807
5844
  init() {
5845
+ if (this.initialized) {
5846
+ return;
5847
+ }
5848
+ const serviceName = resolveSyncServiceName();
5849
+ if (serviceName === "CadenzaDB") {
5850
+ const missingLocalInsertTables = this.getMissingLocalCadenzaDBInsertTables();
5851
+ if (missingLocalInsertTables.length > 0) {
5852
+ this.ensureRetryInitTask();
5853
+ const missingKey = missingLocalInsertTables.join(",");
5854
+ if (missingKey !== this.lastMissingLocalCadenzaDBInsertTablesKey) {
5855
+ this.lastMissingLocalCadenzaDBInsertTablesKey = missingKey;
5856
+ CadenzaService.log(
5857
+ "Waiting for local CadenzaDB sync insert tasks before initializing graph sync controller.",
5858
+ {
5859
+ missingLocalInsertTables
5860
+ },
5861
+ "info"
5862
+ );
5863
+ }
5864
+ if (!this.initRetryScheduled) {
5865
+ this.initRetryScheduled = true;
5866
+ CadenzaService.schedule(
5867
+ "meta.sync_controller.init_retry",
5868
+ {
5869
+ __missingLocalInsertTables: missingLocalInsertTables
5870
+ },
5871
+ 250
5872
+ );
5873
+ }
5874
+ return;
5875
+ }
5876
+ this.lastMissingLocalCadenzaDBInsertTablesKey = "";
5877
+ }
5878
+ this.initialized = true;
5808
5879
  const insertIntentRegistryTask = resolveSyncInsertTask(
5809
5880
  this.isCadenzaDBReady,
5810
5881
  "intent_registry",
@@ -5823,8 +5894,8 @@ var GraphSyncController = class _GraphSyncController {
5823
5894
  async function* (ctx, emit) {
5824
5895
  const { routines } = ctx;
5825
5896
  if (!routines) return;
5826
- const serviceName = resolveSyncServiceName();
5827
- if (!serviceName) {
5897
+ const serviceName2 = resolveSyncServiceName();
5898
+ if (!serviceName2) {
5828
5899
  return;
5829
5900
  }
5830
5901
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -5837,7 +5908,7 @@ var GraphSyncController = class _GraphSyncController {
5837
5908
  name: routine.name,
5838
5909
  version: routine.version,
5839
5910
  description: routine.description,
5840
- serviceName,
5911
+ serviceName: serviceName2,
5841
5912
  isMeta: routine.isMeta
5842
5913
  },
5843
5914
  __routineName: routine.name
@@ -5880,8 +5951,8 @@ var GraphSyncController = class _GraphSyncController {
5880
5951
  function* (ctx) {
5881
5952
  const { routines } = ctx;
5882
5953
  if (!routines) return;
5883
- const serviceName = resolveSyncServiceName();
5884
- if (!serviceName) {
5954
+ const serviceName2 = resolveSyncServiceName();
5955
+ if (!serviceName2) {
5885
5956
  return;
5886
5957
  }
5887
5958
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
@@ -5903,7 +5974,7 @@ var GraphSyncController = class _GraphSyncController {
5903
5974
  taskVersion: nextTask.version,
5904
5975
  routineName: routine.name,
5905
5976
  routineVersion: routine.version,
5906
- serviceName
5977
+ serviceName: serviceName2
5907
5978
  },
5908
5979
  __routineName: routine.name,
5909
5980
  __taskName: nextTask.name
@@ -6008,8 +6079,8 @@ var GraphSyncController = class _GraphSyncController {
6008
6079
  delayMs: 3e3
6009
6080
  });
6010
6081
  const tasks = ctx.tasks;
6011
- const serviceName = resolveSyncServiceName();
6012
- if (!serviceName) {
6082
+ const serviceName2 = resolveSyncServiceName();
6083
+ if (!serviceName2) {
6013
6084
  return;
6014
6085
  }
6015
6086
  for (const task of tasks) {
@@ -6041,7 +6112,7 @@ var GraphSyncController = class _GraphSyncController {
6041
6112
  retryDelay: task.retryDelay,
6042
6113
  retryDelayMax: task.retryDelayMax,
6043
6114
  retryDelayFactor: task.retryDelayFactor,
6044
- service_name: serviceName,
6115
+ service_name: serviceName2,
6045
6116
  signals: {
6046
6117
  emits: Array.from(task.emitsSignals),
6047
6118
  signalsToEmitAfter: Array.from(task.signalsToEmitAfter),
@@ -6094,15 +6165,15 @@ var GraphSyncController = class _GraphSyncController {
6094
6165
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
6095
6166
  delayMs: 3e3
6096
6167
  });
6097
- const serviceName = resolveSyncServiceName();
6098
- if (!serviceName) {
6168
+ const serviceName2 = resolveSyncServiceName();
6169
+ if (!serviceName2) {
6099
6170
  return;
6100
6171
  }
6101
6172
  const actors = ctx.actors ?? [];
6102
6173
  for (const actor of actors) {
6103
6174
  const data = {
6104
6175
  ...buildActorRegistrationData(actor),
6105
- service_name: serviceName
6176
+ service_name: serviceName2
6106
6177
  };
6107
6178
  if (!data.name) {
6108
6179
  continue;
@@ -6159,11 +6230,11 @@ var GraphSyncController = class _GraphSyncController {
6159
6230
  if (!metadata?.actorName) {
6160
6231
  return;
6161
6232
  }
6162
- const serviceName = resolveSyncServiceName(task);
6163
- if (!serviceName) {
6233
+ const serviceName2 = resolveSyncServiceName(task);
6234
+ if (!serviceName2) {
6164
6235
  return;
6165
6236
  }
6166
- const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName}`;
6237
+ const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${serviceName2}`;
6167
6238
  if (this.registeredActorTaskMaps.has(registrationKey)) {
6168
6239
  return;
6169
6240
  }
@@ -6173,7 +6244,7 @@ var GraphSyncController = class _GraphSyncController {
6173
6244
  actor_version: 1,
6174
6245
  task_name: task.name,
6175
6246
  task_version: task.version,
6176
- service_name: serviceName,
6247
+ service_name: serviceName2,
6177
6248
  mode: metadata.mode,
6178
6249
  description: task.description ?? metadata.actorDescription ?? "",
6179
6250
  is_meta: metadata.actorKind === "meta" || task.isMeta === true
@@ -6229,8 +6300,8 @@ var GraphSyncController = class _GraphSyncController {
6229
6300
  function* (ctx) {
6230
6301
  const task = ctx.task;
6231
6302
  if (task.hidden || !task.register) return;
6232
- const serviceName = resolveSyncServiceName(task);
6233
- if (!serviceName) {
6303
+ const serviceName2 = resolveSyncServiceName(task);
6304
+ if (!serviceName2) {
6234
6305
  return;
6235
6306
  }
6236
6307
  for (const signal of task.observedSignals) {
@@ -6243,7 +6314,7 @@ var GraphSyncController = class _GraphSyncController {
6243
6314
  isGlobal,
6244
6315
  taskName: task.name,
6245
6316
  taskVersion: task.version,
6246
- serviceName
6317
+ serviceName: serviceName2
6247
6318
  },
6248
6319
  __taskName: task.name,
6249
6320
  __signal: signal
@@ -6277,6 +6348,24 @@ var GraphSyncController = class _GraphSyncController {
6277
6348
  delayMs: 3e3
6278
6349
  });
6279
6350
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
6351
+ if (resolveSyncServiceName() === "CadenzaDB" && !this.loggedCadenzaDBIntentSweep) {
6352
+ const intentNames = intents.map((intent) => String(intent?.name ?? "").trim()).filter(Boolean);
6353
+ const authorityIntentNames = intentNames.filter(
6354
+ (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")
6355
+ );
6356
+ CadenzaService.log(
6357
+ "CadenzaDB intent sweep diagnostics.",
6358
+ {
6359
+ totalIntents: intentNames.length,
6360
+ hasMetaServiceRegistryFullSync: intentNames.includes(
6361
+ "meta-service-registry-full-sync"
6362
+ ),
6363
+ authorityIntentNames
6364
+ },
6365
+ "info"
6366
+ );
6367
+ this.loggedCadenzaDBIntentSweep = true;
6368
+ }
6280
6369
  for (const intent of intents) {
6281
6370
  const intentData = buildIntentRegistryData(intent);
6282
6371
  if (!intentData) {
@@ -6329,12 +6418,34 @@ var GraphSyncController = class _GraphSyncController {
6329
6418
  function* (ctx) {
6330
6419
  const task = ctx.task;
6331
6420
  if (task.hidden || !task.register) return;
6332
- const serviceName = resolveSyncServiceName(task);
6333
- if (!serviceName) {
6421
+ const serviceName2 = resolveSyncServiceName(task);
6422
+ if (!serviceName2) {
6334
6423
  return;
6335
6424
  }
6336
6425
  task.__registeredIntents = task.__registeredIntents ?? /* @__PURE__ */ new Set();
6337
6426
  task.__invalidMetaIntentWarnings = task.__invalidMetaIntentWarnings ?? /* @__PURE__ */ new Set();
6427
+ if (serviceName2 === "CadenzaDB" && [
6428
+ "Query service_instance",
6429
+ "Query service_instance_transport",
6430
+ "Query intent_to_task_map",
6431
+ "Query signal_to_task_map"
6432
+ ].includes(task.name)) {
6433
+ const authorityTaskKey = `${task.name}:${task.version}`;
6434
+ if (!this.loggedAuthorityTaskIntentDiagnostics.has(authorityTaskKey)) {
6435
+ this.loggedAuthorityTaskIntentDiagnostics.add(authorityTaskKey);
6436
+ CadenzaService.log(
6437
+ "CadenzaDB authority task intent diagnostics.",
6438
+ {
6439
+ taskName: task.name,
6440
+ taskVersion: task.version,
6441
+ isMeta: task.isMeta,
6442
+ handlesIntents: Array.from(task.handlesIntents ?? []),
6443
+ registeredIntents: Array.from(task.__registeredIntents ?? [])
6444
+ },
6445
+ "info"
6446
+ );
6447
+ }
6448
+ }
6338
6449
  for (const intent of task.handlesIntents) {
6339
6450
  if (task.__registeredIntents.has(intent)) continue;
6340
6451
  if (isMetaIntentName(intent) && !task.isMeta) {
@@ -6361,7 +6472,7 @@ var GraphSyncController = class _GraphSyncController {
6361
6472
  intentName: intent,
6362
6473
  taskName: task.name,
6363
6474
  taskVersion: task.version,
6364
- serviceName
6475
+ serviceName: serviceName2
6365
6476
  },
6366
6477
  __taskName: task.name,
6367
6478
  __intent: intent,
@@ -6370,11 +6481,11 @@ var GraphSyncController = class _GraphSyncController {
6370
6481
  intentName: intent,
6371
6482
  taskName: task.name,
6372
6483
  taskVersion: task.version,
6373
- serviceName
6484
+ serviceName: serviceName2
6374
6485
  }
6375
6486
  };
6376
6487
  }
6377
- }
6488
+ }.bind(this)
6378
6489
  ).then(
6379
6490
  CadenzaService.createMetaTask(
6380
6491
  "Prepare intent definition for intent-to-task map",
@@ -6439,8 +6550,8 @@ var GraphSyncController = class _GraphSyncController {
6439
6550
  if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register) {
6440
6551
  continue;
6441
6552
  }
6442
- const serviceName = resolveSyncServiceName(t);
6443
- if (!serviceName) {
6553
+ const serviceName2 = resolveSyncServiceName(t);
6554
+ if (!serviceName2) {
6444
6555
  continue;
6445
6556
  }
6446
6557
  yield {
@@ -6449,7 +6560,7 @@ var GraphSyncController = class _GraphSyncController {
6449
6560
  taskVersion: t.version,
6450
6561
  predecessorTaskName: task.name,
6451
6562
  predecessorTaskVersion: task.version,
6452
- serviceName,
6563
+ serviceName: serviceName2,
6453
6564
  predecessorServiceName
6454
6565
  },
6455
6566
  __taskName: task.name,
@@ -6498,16 +6609,16 @@ var GraphSyncController = class _GraphSyncController {
6498
6609
  if (task.hidden || !task.register) return;
6499
6610
  if (task.isDeputy && !task.signalName) {
6500
6611
  if (task.registeredDeputyMap) return;
6501
- const serviceName = resolveSyncServiceName(task);
6612
+ const serviceName2 = resolveSyncServiceName(task);
6502
6613
  const predecessorServiceName = resolveSyncServiceName();
6503
- if (!serviceName || !predecessorServiceName) {
6614
+ if (!serviceName2 || !predecessorServiceName) {
6504
6615
  return;
6505
6616
  }
6506
6617
  return {
6507
6618
  data: {
6508
6619
  task_name: task.remoteRoutineName,
6509
6620
  task_version: 1,
6510
- service_name: serviceName,
6621
+ service_name: serviceName2,
6511
6622
  predecessor_task_name: task.name,
6512
6623
  predecessor_task_version: task.version,
6513
6624
  predecessor_service_name: predecessorServiceName