@cadenza.io/service 2.17.47 → 2.17.49

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
@@ -8710,10 +8710,21 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
8710
8710
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8711
8711
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
8712
8712
  const remoteInsertTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0;
8713
+ const debugTable = shouldDebugSyncTable(tableName);
8713
8714
  if (!localInsertTask && !remoteInsertTask) {
8714
8715
  return void 0;
8715
8716
  }
8716
8717
  const targetTask = localInsertTask ?? remoteInsertTask;
8718
+ if (debugTable) {
8719
+ logSyncDebug("insert_task_resolved", {
8720
+ tableName,
8721
+ localInsertTaskName: localInsertTask?.name ?? null,
8722
+ remoteInsertTaskName: remoteInsertTask?.name ?? null,
8723
+ targetTaskName: targetTask.name,
8724
+ queryData,
8725
+ options
8726
+ });
8727
+ }
8717
8728
  const executionRequestedSignal = `meta.sync_controller.insert_execution_requested:${tableName}`;
8718
8729
  const executionResolvedSignal = `meta.sync_controller.insert_execution_resolved:${tableName}`;
8719
8730
  const executionFailedSignal = `meta.sync_controller.insert_execution_failed:${tableName}`;
@@ -8747,6 +8758,26 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8747
8758
  isHidden: true
8748
8759
  }
8749
8760
  ).doOn(executionRequestedSignal).emitsOnFail(executionFailedSignal);
8761
+ if (debugTable) {
8762
+ prepareExecutionTask.then(
8763
+ CadenzaService.createMetaTask(
8764
+ `Log prepared graph sync insert execution for ${tableName}`,
8765
+ (ctx) => {
8766
+ logSyncDebug("insert_prepare", {
8767
+ tableName,
8768
+ targetTaskName: targetTask.name,
8769
+ ctx
8770
+ });
8771
+ return ctx;
8772
+ },
8773
+ `Logs prepared ${tableName} sync insert payloads.`,
8774
+ {
8775
+ register: false,
8776
+ isHidden: true
8777
+ }
8778
+ )
8779
+ );
8780
+ }
8750
8781
  const finalizeExecutionTask = CadenzaService.createMetaTask(
8751
8782
  `Finalize graph sync insert execution for ${tableName}`,
8752
8783
  (ctx, emit) => {
@@ -8763,6 +8794,14 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8763
8794
  ...ctx,
8764
8795
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
8765
8796
  };
8797
+ if (debugTable) {
8798
+ logSyncDebug("insert_finalize", {
8799
+ tableName,
8800
+ targetTaskName: targetTask.name,
8801
+ success: didSyncInsertSucceed(normalizedContext),
8802
+ ctx: normalizedContext
8803
+ });
8804
+ }
8766
8805
  pendingResolverContexts.delete(ctx.__resolverRequestId);
8767
8806
  emit(executionResolvedSignal, normalizedContext);
8768
8807
  return normalizedContext;
@@ -8775,6 +8814,27 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8775
8814
  );
8776
8815
  targetTask.then(finalizeExecutionTask).emitsOnFail(executionFailedSignal);
8777
8816
  prepareExecutionTask.then(targetTask);
8817
+ if (debugTable) {
8818
+ CadenzaService.createMetaTask(
8819
+ `Log failed graph sync insert execution for ${tableName}`,
8820
+ (ctx) => {
8821
+ logSyncDebug("insert_failed", {
8822
+ tableName,
8823
+ targetTaskName: targetTask.name,
8824
+ ctx
8825
+ });
8826
+ if (typeof ctx.__resolverRequestId === "string") {
8827
+ pendingResolverContexts.delete(ctx.__resolverRequestId);
8828
+ }
8829
+ return false;
8830
+ },
8831
+ `Logs failed ${tableName} sync insert executions.`,
8832
+ {
8833
+ register: false,
8834
+ isHidden: true
8835
+ }
8836
+ ).doOn(executionFailedSignal);
8837
+ }
8778
8838
  return CadenzaService.createMetaTask(
8779
8839
  `Resolve graph sync insert for ${tableName}`,
8780
8840
  (ctx, emit) => new Promise((resolve) => {
@@ -8830,6 +8890,104 @@ var AUTHORITY_QUERY_RESULT_KEYS = {
8830
8890
  intent_registry: "intentRegistrys"
8831
8891
  };
8832
8892
  var EARLY_SYNC_REQUEST_DELAYS_MS = [2e3, 1e4, 3e4];
8893
+ var SYNC_DEBUG_PREFIX = "[CADENZA_SYNC_DEBUG]";
8894
+ var SYNC_DEBUG_TABLES = /* @__PURE__ */ new Set([
8895
+ "task",
8896
+ "routine",
8897
+ "task_to_routine_map",
8898
+ "signal_registry",
8899
+ "intent_registry",
8900
+ "signal_to_task_map",
8901
+ "intent_to_task_map"
8902
+ ]);
8903
+ var SYNC_DEBUG_TASK_NAMES = /* @__PURE__ */ new Set([
8904
+ "Query service_instance",
8905
+ "Query service_instance_transport",
8906
+ "Query intent_to_task_map",
8907
+ "Query signal_to_task_map",
8908
+ "Prepare for signal sync",
8909
+ "Compile sync data and broadcast",
8910
+ "Forward service instance sync",
8911
+ "Forward service transport sync",
8912
+ "Forward intent to task map sync",
8913
+ "Forward signal to task map sync"
8914
+ ]);
8915
+ var SYNC_DEBUG_ROUTINE_NAMES = /* @__PURE__ */ new Set(["Sync services"]);
8916
+ var SYNC_DEBUG_INTENT_NAMES = /* @__PURE__ */ new Set([
8917
+ "meta-service-registry-full-sync",
8918
+ "runner-traffic-runtime-get",
8919
+ "iot-telemetry-ingest",
8920
+ "query-pg-CadenzaDBPostgresActor-service_instance",
8921
+ "query-pg-CadenzaDBPostgresActor-service_instance_transport",
8922
+ "query-pg-CadenzaDBPostgresActor-intent_to_task_map",
8923
+ "query-pg-CadenzaDBPostgresActor-signal_to_task_map"
8924
+ ]);
8925
+ function shouldDebugSyncTable(tableName) {
8926
+ return SYNC_DEBUG_TABLES.has(tableName);
8927
+ }
8928
+ function shouldDebugSyncTaskName(taskName) {
8929
+ return typeof taskName === "string" && SYNC_DEBUG_TASK_NAMES.has(taskName);
8930
+ }
8931
+ function shouldDebugSyncRoutineName(routineName) {
8932
+ return typeof routineName === "string" && SYNC_DEBUG_ROUTINE_NAMES.has(routineName);
8933
+ }
8934
+ function shouldDebugSyncIntentName(intentName) {
8935
+ return typeof intentName === "string" && SYNC_DEBUG_INTENT_NAMES.has(intentName);
8936
+ }
8937
+ function summarizeSyncDebugValue(value, depth = 0) {
8938
+ if (value === null || value === void 0) {
8939
+ return value;
8940
+ }
8941
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
8942
+ return value;
8943
+ }
8944
+ if (value instanceof Set) {
8945
+ return {
8946
+ __type: "Set",
8947
+ size: value.size,
8948
+ values: Array.from(value).slice(0, 8).map((item) => summarizeSyncDebugValue(item, depth + 1))
8949
+ };
8950
+ }
8951
+ if (value instanceof Map) {
8952
+ return {
8953
+ __type: "Map",
8954
+ size: value.size
8955
+ };
8956
+ }
8957
+ if (Array.isArray(value)) {
8958
+ return {
8959
+ __type: "Array",
8960
+ length: value.length,
8961
+ items: value.slice(0, 5).map((item) => summarizeSyncDebugValue(item, depth + 1))
8962
+ };
8963
+ }
8964
+ if (typeof value === "object") {
8965
+ if (depth >= 2) {
8966
+ return "[object]";
8967
+ }
8968
+ const output = {};
8969
+ const entries = Object.entries(value).filter(
8970
+ ([key]) => ![
8971
+ "functionString",
8972
+ "tagIdGetter",
8973
+ "__functionString",
8974
+ "__getTagCallback",
8975
+ "joinedContexts",
8976
+ "task",
8977
+ "taskInstance",
8978
+ "tasks"
8979
+ ].includes(key)
8980
+ ).slice(0, 12);
8981
+ for (const [key, nestedValue] of entries) {
8982
+ output[key] = summarizeSyncDebugValue(nestedValue, depth + 1);
8983
+ }
8984
+ return output;
8985
+ }
8986
+ return String(value);
8987
+ }
8988
+ function logSyncDebug(event, payload) {
8989
+ console.log(`${SYNC_DEBUG_PREFIX} ${event}`, summarizeSyncDebugValue(payload));
8990
+ }
8833
8991
  function resolveSyncQueryRows(ctx, tableName) {
8834
8992
  const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
8835
8993
  const rows = ctx?.[resultKey];
@@ -8858,6 +9016,31 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
8858
9016
  }
8859
9017
  ).then(targetTask);
8860
9018
  }
9019
+ function getRegistrableTasks() {
9020
+ return Array.from(CadenzaService.registry.tasks.values()).filter(
9021
+ (task) => task.register && !task.isHidden
9022
+ );
9023
+ }
9024
+ function getRegistrableRoutines() {
9025
+ return Array.from(CadenzaService.registry.routines.values());
9026
+ }
9027
+ function getRegistrableSignalObservers() {
9028
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
9029
+ return signalObservers ? Array.from(signalObservers.values()) : [];
9030
+ }
9031
+ function getRegistrableIntentNames() {
9032
+ return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
9033
+ (intentDefinition) => intentDefinition !== null
9034
+ ).map((intentDefinition) => String(intentDefinition.name));
9035
+ }
9036
+ function buildActorRegistrationKey(actor, serviceName) {
9037
+ const data = buildActorRegistrationData(actor);
9038
+ const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
9039
+ if (!name) {
9040
+ return null;
9041
+ }
9042
+ return `${name}|${data.version}|${serviceName}`;
9043
+ }
8861
9044
  var GraphSyncController = class _GraphSyncController {
8862
9045
  constructor() {
8863
9046
  this.registeredActors = /* @__PURE__ */ new Set();
@@ -8982,22 +9165,158 @@ var GraphSyncController = class _GraphSyncController {
8982
9165
  {},
8983
9166
  { concurrency: 10 }
8984
9167
  );
9168
+ const finalizeTaskSync = (emit, ctx) => {
9169
+ const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
9170
+ if (pendingTasks.length > 0) {
9171
+ this.tasksSynced = false;
9172
+ return false;
9173
+ }
9174
+ const shouldEmit = !this.tasksSynced;
9175
+ this.tasksSynced = true;
9176
+ if (shouldEmit) {
9177
+ emit("meta.sync_controller.synced_tasks", {
9178
+ __syncing: true,
9179
+ ...ctx
9180
+ });
9181
+ }
9182
+ return true;
9183
+ };
9184
+ const finalizeRoutineSync = (emit, ctx) => {
9185
+ const pendingRoutines = getRegistrableRoutines().filter(
9186
+ (routine) => !routine.registered
9187
+ );
9188
+ if (pendingRoutines.length > 0) {
9189
+ this.routinesSynced = false;
9190
+ return false;
9191
+ }
9192
+ const shouldEmit = !this.routinesSynced;
9193
+ this.routinesSynced = true;
9194
+ if (shouldEmit) {
9195
+ emit("meta.sync_controller.synced_routines", {
9196
+ __syncing: true,
9197
+ ...ctx
9198
+ });
9199
+ }
9200
+ return true;
9201
+ };
9202
+ const finalizeSignalSync = (emit, ctx) => {
9203
+ const pendingSignals = getRegistrableSignalObservers().filter(
9204
+ (observer) => observer?.registered !== true
9205
+ );
9206
+ if (pendingSignals.length > 0) {
9207
+ this.signalsSynced = false;
9208
+ return false;
9209
+ }
9210
+ const shouldEmit = !this.signalsSynced;
9211
+ this.signalsSynced = true;
9212
+ if (shouldEmit) {
9213
+ emit("meta.sync_controller.synced_signals", {
9214
+ __syncing: true,
9215
+ ...ctx
9216
+ });
9217
+ }
9218
+ return true;
9219
+ };
9220
+ const finalizeIntentSync = (emit, ctx) => {
9221
+ const pendingIntentNames = getRegistrableIntentNames().filter(
9222
+ (intentName) => !this.registeredIntentDefinitions.has(intentName)
9223
+ );
9224
+ if (pendingIntentNames.length > 0) {
9225
+ this.intentsSynced = false;
9226
+ return false;
9227
+ }
9228
+ const shouldEmit = !this.intentsSynced;
9229
+ this.intentsSynced = true;
9230
+ if (shouldEmit) {
9231
+ emit("meta.sync_controller.synced_intents", {
9232
+ __syncing: true,
9233
+ ...ctx
9234
+ });
9235
+ }
9236
+ return true;
9237
+ };
9238
+ const finalizeActorSync = (emit, ctx) => {
9239
+ const syncServiceName = resolveSyncServiceName();
9240
+ if (!syncServiceName) {
9241
+ this.actorsSynced = false;
9242
+ return false;
9243
+ }
9244
+ const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
9245
+ if (pendingActorKeys.length > 0) {
9246
+ this.actorsSynced = false;
9247
+ return false;
9248
+ }
9249
+ const shouldEmit = !this.actorsSynced;
9250
+ this.actorsSynced = true;
9251
+ if (shouldEmit) {
9252
+ emit("meta.sync_controller.synced_actors", {
9253
+ __syncing: true,
9254
+ ...ctx
9255
+ });
9256
+ }
9257
+ return true;
9258
+ };
9259
+ const gatherTaskRegistrationTask = CadenzaService.createUniqueMetaTask(
9260
+ "Gather task registration",
9261
+ (ctx, emit) => finalizeTaskSync(emit, ctx),
9262
+ "Completes task registration when all registrable tasks are marked registered.",
9263
+ {
9264
+ register: false,
9265
+ isHidden: true
9266
+ }
9267
+ );
9268
+ const gatherRoutineRegistrationTask = CadenzaService.createUniqueMetaTask(
9269
+ "Gather routine registration",
9270
+ (ctx, emit) => finalizeRoutineSync(emit, ctx),
9271
+ "Completes routine registration when all registrable routines are marked registered.",
9272
+ {
9273
+ register: false,
9274
+ isHidden: true
9275
+ }
9276
+ );
9277
+ const gatherSignalRegistrationTask = CadenzaService.createUniqueMetaTask(
9278
+ "Gather signal registration",
9279
+ (ctx, emit) => finalizeSignalSync(emit, ctx),
9280
+ "Completes signal registration when all signal observers are marked registered.",
9281
+ {
9282
+ register: false,
9283
+ isHidden: true
9284
+ }
9285
+ );
9286
+ const gatherIntentRegistrationTask = CadenzaService.createUniqueMetaTask(
9287
+ "Gather intent registration",
9288
+ (ctx, emit) => finalizeIntentSync(emit, ctx),
9289
+ "Completes intent registration when all registrable intents are marked registered.",
9290
+ {
9291
+ register: false,
9292
+ isHidden: true
9293
+ }
9294
+ );
9295
+ const gatherActorRegistrationTask = CadenzaService.createUniqueMetaTask(
9296
+ "Gather actor registration",
9297
+ (ctx, emit) => finalizeActorSync(emit, ctx),
9298
+ "Completes actor registration when all registrable actors are marked registered.",
9299
+ {
9300
+ register: false,
9301
+ isHidden: true
9302
+ }
9303
+ );
8985
9304
  this.splitRoutinesTask = CadenzaService.createMetaTask(
8986
9305
  "Split routines for registration",
8987
- (ctx, emit) => {
9306
+ function* (ctx) {
8988
9307
  const { routines } = ctx;
8989
- if (!routines) return false;
9308
+ if (!routines) return;
8990
9309
  const serviceName2 = resolveSyncServiceName();
8991
9310
  if (!serviceName2) {
8992
- return false;
9311
+ return;
8993
9312
  }
8994
9313
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
8995
9314
  delayMs: 2e3
8996
9315
  });
8997
- let emittedCount = 0;
8998
9316
  for (const routine of routines) {
8999
9317
  if (routine.registered) continue;
9000
- emit("meta.sync_controller.routine_registration_split", {
9318
+ this.routinesSynced = false;
9319
+ yield {
9001
9320
  __syncing: ctx.__syncing,
9002
9321
  data: {
9003
9322
  name: routine.name,
@@ -9007,13 +9326,11 @@ var GraphSyncController = class _GraphSyncController {
9007
9326
  isMeta: routine.isMeta
9008
9327
  },
9009
9328
  __routineName: routine.name
9010
- });
9011
- emittedCount += 1;
9329
+ };
9012
9330
  }
9013
- return emittedCount > 0;
9014
- }
9331
+ }.bind(this)
9015
9332
  );
9016
- CadenzaService.createMetaTask("Process split routine registration", (ctx) => ctx).doOn("meta.sync_controller.routine_registration_split").then(
9333
+ this.splitRoutinesTask.then(
9017
9334
  resolveSyncInsertTask(
9018
9335
  this.isCadenzaDBReady,
9019
9336
  "routine",
@@ -9035,22 +9352,10 @@ var GraphSyncController = class _GraphSyncController {
9035
9352
  delayMs: 3e3
9036
9353
  });
9037
9354
  CadenzaService.getRoutine(ctx.__routineName).registered = true;
9038
- CadenzaService.debounce(
9039
- "meta.sync_controller.routine_registration_settled",
9040
- { __syncing: true },
9041
- 300
9042
- );
9043
9355
  return true;
9044
- })
9356
+ }).then(gatherRoutineRegistrationTask)
9045
9357
  )
9046
9358
  );
9047
- CadenzaService.createUniqueMetaTask(
9048
- "Gather routine registration",
9049
- () => {
9050
- this.routinesSynced = true;
9051
- return true;
9052
- }
9053
- ).doOn("meta.sync_controller.routine_registration_settled").emits("meta.sync_controller.synced_routines");
9054
9359
  this.splitTasksInRoutines = CadenzaService.createMetaTask(
9055
9360
  "Split tasks in routines",
9056
9361
  function* (ctx) {
@@ -9076,6 +9381,16 @@ var GraphSyncController = class _GraphSyncController {
9076
9381
  if (!nextTask?.registered) {
9077
9382
  continue;
9078
9383
  }
9384
+ if (shouldDebugSyncRoutineName(routine.name) || shouldDebugSyncTaskName(nextTask.name)) {
9385
+ logSyncDebug("task_to_routine_split", {
9386
+ routineName: routine.name,
9387
+ routineVersion: routine.version,
9388
+ taskName: nextTask.name,
9389
+ taskVersion: nextTask.version,
9390
+ serviceName: serviceName2,
9391
+ registered: nextTask.registered
9392
+ });
9393
+ }
9079
9394
  yield {
9080
9395
  __syncing: ctx.__syncing,
9081
9396
  data: {
@@ -9129,18 +9444,19 @@ var GraphSyncController = class _GraphSyncController {
9129
9444
  }
9130
9445
  this.splitSignalsTask = CadenzaService.createMetaTask(
9131
9446
  "Split signals for registration",
9132
- (ctx, emit) => {
9447
+ function* (ctx) {
9133
9448
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9134
9449
  delayMs: 3e3
9135
9450
  });
9136
9451
  const { signals } = ctx;
9137
- if (!signals) return false;
9452
+ if (!signals) return;
9138
9453
  const filteredSignals = signals.filter(
9139
9454
  (signal) => !signal.data.registered
9140
9455
  ).map((signal) => signal.signal);
9141
9456
  for (const signal of filteredSignals) {
9142
9457
  const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
9143
- emit("meta.sync_controller.signal_registration_split", {
9458
+ this.signalsSynced = false;
9459
+ yield {
9144
9460
  __syncing: ctx.__syncing,
9145
9461
  data: {
9146
9462
  name: signal,
@@ -9150,12 +9466,11 @@ var GraphSyncController = class _GraphSyncController {
9150
9466
  isMeta
9151
9467
  },
9152
9468
  __signal: signal
9153
- });
9469
+ };
9154
9470
  }
9155
- return filteredSignals.length > 0;
9156
- }
9471
+ }.bind(this)
9157
9472
  );
9158
- CadenzaService.createMetaTask("Process split signal registration", (ctx) => ctx).doOn("meta.sync_controller.signal_registration_split").then(
9473
+ this.splitSignalsTask.then(
9159
9474
  resolveSyncInsertTask(
9160
9475
  this.isCadenzaDBReady,
9161
9476
  "signal_registry",
@@ -9176,22 +9491,10 @@ var GraphSyncController = class _GraphSyncController {
9176
9491
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9177
9492
  delayMs: 3e3
9178
9493
  });
9179
- CadenzaService.debounce(
9180
- "meta.sync_controller.signal_registration_settled",
9181
- { __syncing: true },
9182
- 300
9183
- );
9184
9494
  return { signalName: ctx.__signal };
9185
- }).then(CadenzaService.signalBroker.registerSignalTask)
9495
+ }).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask)
9186
9496
  )
9187
9497
  );
9188
- CadenzaService.createUniqueMetaTask(
9189
- "Gather signal registration",
9190
- () => {
9191
- this.signalsSynced = true;
9192
- return true;
9193
- }
9194
- ).doOn("meta.sync_controller.signal_registration_settled").emits("meta.sync_controller.synced_signals");
9195
9498
  this.splitTasksForRegistration = CadenzaService.createMetaTask(
9196
9499
  "Split tasks for registration",
9197
9500
  function* (ctx) {
@@ -9206,6 +9509,19 @@ var GraphSyncController = class _GraphSyncController {
9206
9509
  for (const task of tasks) {
9207
9510
  if (task.registered) continue;
9208
9511
  const { __functionString, __getTagCallback } = task.export();
9512
+ this.tasksSynced = false;
9513
+ if (shouldDebugSyncTaskName(task.name)) {
9514
+ logSyncDebug("task_registration_split", {
9515
+ taskName: task.name,
9516
+ taskVersion: task.version,
9517
+ serviceName: serviceName2,
9518
+ register: task.register,
9519
+ registered: task.registered,
9520
+ hidden: task.hidden,
9521
+ observedSignals: Array.from(task.observedSignals),
9522
+ handledIntents: Array.from(task.handlesIntents)
9523
+ });
9524
+ }
9209
9525
  yield {
9210
9526
  __syncing: ctx.__syncing,
9211
9527
  data: {
@@ -9242,7 +9558,7 @@ var GraphSyncController = class _GraphSyncController {
9242
9558
  __taskName: task.name
9243
9559
  };
9244
9560
  }
9245
- }
9561
+ }.bind(this)
9246
9562
  );
9247
9563
  const registerTaskTask = resolveSyncInsertTask(
9248
9564
  this.isCadenzaDBReady,
@@ -9258,6 +9574,13 @@ var GraphSyncController = class _GraphSyncController {
9258
9574
  { concurrency: 30 }
9259
9575
  )?.then(
9260
9576
  CadenzaService.createMetaTask("Record registration", (ctx, emit) => {
9577
+ if (shouldDebugSyncTaskName(ctx.__taskName)) {
9578
+ logSyncDebug("task_registration_result", {
9579
+ taskName: ctx.__taskName,
9580
+ success: didSyncInsertSucceed(ctx),
9581
+ ctx
9582
+ });
9583
+ }
9261
9584
  if (!didSyncInsertSucceed(ctx)) {
9262
9585
  return;
9263
9586
  }
@@ -9269,13 +9592,8 @@ var GraphSyncController = class _GraphSyncController {
9269
9592
  ...ctx,
9270
9593
  task: CadenzaService.get(ctx.__taskName)
9271
9594
  });
9272
- CadenzaService.debounce(
9273
- "meta.sync_controller.task_registration_settled",
9274
- { __syncing: true },
9275
- 300
9276
- );
9277
9595
  return true;
9278
- })
9596
+ }).then(gatherTaskRegistrationTask)
9279
9597
  );
9280
9598
  if (registerTaskTask) {
9281
9599
  this.splitTasksForRegistration.then(registerTaskTask);
@@ -9284,6 +9602,16 @@ var GraphSyncController = class _GraphSyncController {
9284
9602
  "Prepare created task for immediate sync",
9285
9603
  (ctx) => {
9286
9604
  const task = ctx.taskInstance ?? (ctx.data?.name ? CadenzaService.get(String(ctx.data.name)) : void 0);
9605
+ if (shouldDebugSyncTaskName(task?.name ?? ctx?.data?.name)) {
9606
+ logSyncDebug("task_created_for_immediate_sync", {
9607
+ incomingTaskName: ctx?.data?.name ?? null,
9608
+ resolvedTaskName: task?.name ?? null,
9609
+ exists: Boolean(task),
9610
+ hidden: task?.hidden ?? null,
9611
+ register: task?.register ?? null,
9612
+ registered: task?.registered ?? null
9613
+ });
9614
+ }
9287
9615
  if (!task || task.hidden || !task.register || task.registered) {
9288
9616
  return false;
9289
9617
  }
@@ -9298,13 +9626,6 @@ var GraphSyncController = class _GraphSyncController {
9298
9626
  isHidden: true
9299
9627
  }
9300
9628
  ).doOn("meta.task.created").then(this.splitTasksForRegistration);
9301
- CadenzaService.createUniqueMetaTask(
9302
- "Gather task registration",
9303
- () => {
9304
- this.tasksSynced = true;
9305
- return true;
9306
- }
9307
- ).doOn("meta.sync_controller.task_registration_settled").emits("meta.sync_controller.synced_tasks");
9308
9629
  this.splitActorsForRegistration = CadenzaService.createMetaTask(
9309
9630
  "Split actors for registration",
9310
9631
  function* (ctx) {
@@ -9328,6 +9649,7 @@ var GraphSyncController = class _GraphSyncController {
9328
9649
  if (this.registeredActors.has(registrationKey)) {
9329
9650
  continue;
9330
9651
  }
9652
+ this.actorsSynced = false;
9331
9653
  yield {
9332
9654
  data,
9333
9655
  __actorRegistrationKey: registrationKey
@@ -9356,22 +9678,10 @@ var GraphSyncController = class _GraphSyncController {
9356
9678
  delayMs: 3e3
9357
9679
  });
9358
9680
  this.registeredActors.add(ctx.__actorRegistrationKey);
9359
- CadenzaService.debounce(
9360
- "meta.sync_controller.actor_registration_settled",
9361
- { __syncing: true },
9362
- 300
9363
- );
9364
9681
  return true;
9365
- })
9682
+ }).then(gatherActorRegistrationTask)
9366
9683
  )
9367
9684
  );
9368
- CadenzaService.createUniqueMetaTask(
9369
- "Gather actor registration",
9370
- () => {
9371
- this.actorsSynced = true;
9372
- return true;
9373
- }
9374
- ).doOn("meta.sync_controller.actor_registration_settled").emits("meta.sync_controller.synced_actors");
9375
9685
  this.registerActorTaskMapTask = CadenzaService.createMetaTask(
9376
9686
  "Split actor task maps",
9377
9687
  function* (ctx) {
@@ -9468,6 +9778,17 @@ var GraphSyncController = class _GraphSyncController {
9468
9778
  continue;
9469
9779
  }
9470
9780
  const { isGlobal } = decomposeSignalName(_signal);
9781
+ if (shouldDebugSyncTaskName(task.name)) {
9782
+ logSyncDebug("signal_to_task_map_split", {
9783
+ taskName: task.name,
9784
+ signalName: _signal,
9785
+ rawSignal: signal,
9786
+ serviceName: serviceName2,
9787
+ observerRegistered: CadenzaService.signalBroker.signalObservers?.get(
9788
+ _signal
9789
+ )?.registered
9790
+ });
9791
+ }
9471
9792
  emit("meta.sync_controller.signal_task_map_split", {
9472
9793
  __syncing: ctx.__syncing,
9473
9794
  data: {
@@ -9507,12 +9828,11 @@ var GraphSyncController = class _GraphSyncController {
9507
9828
  );
9508
9829
  this.splitIntentsTask = CadenzaService.createMetaTask(
9509
9830
  "Split intents for registration",
9510
- function(ctx, emit) {
9831
+ function* (ctx) {
9511
9832
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9512
9833
  delayMs: 3e3
9513
9834
  });
9514
9835
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
9515
- let emittedCount = 0;
9516
9836
  for (const intent of intents) {
9517
9837
  const intentData = buildIntentRegistryData(intent);
9518
9838
  if (!intentData) {
@@ -9521,17 +9841,16 @@ var GraphSyncController = class _GraphSyncController {
9521
9841
  if (this.registeredIntentDefinitions.has(intentData.name)) {
9522
9842
  continue;
9523
9843
  }
9524
- emit("meta.sync_controller.intent_registration_split", {
9844
+ this.intentsSynced = false;
9845
+ yield {
9525
9846
  __syncing: ctx.__syncing,
9526
9847
  data: intentData,
9527
9848
  __intentName: intentData.name
9528
- });
9529
- emittedCount += 1;
9849
+ };
9530
9850
  }
9531
- return emittedCount > 0;
9532
9851
  }.bind(this)
9533
9852
  );
9534
- CadenzaService.createMetaTask("Process split intent registration", (ctx) => ctx).doOn("meta.sync_controller.intent_registration_split").then(
9853
+ this.splitIntentsTask.then(
9535
9854
  insertIntentRegistryTask?.then(
9536
9855
  CadenzaService.createMetaTask("Record intent definition registration", (ctx) => {
9537
9856
  if (!didSyncInsertSucceed(ctx)) {
@@ -9541,22 +9860,10 @@ var GraphSyncController = class _GraphSyncController {
9541
9860
  delayMs: 3e3
9542
9861
  });
9543
9862
  this.registeredIntentDefinitions.add(ctx.__intentName);
9544
- CadenzaService.debounce(
9545
- "meta.sync_controller.intent_registration_settled",
9546
- { __syncing: true },
9547
- 300
9548
- );
9549
9863
  return true;
9550
- })
9864
+ }).then(gatherIntentRegistrationTask)
9551
9865
  )
9552
9866
  );
9553
- CadenzaService.createUniqueMetaTask(
9554
- "Gather intent registration",
9555
- () => {
9556
- this.intentsSynced = true;
9557
- return true;
9558
- }
9559
- ).doOn("meta.sync_controller.intent_registration_settled").emits("meta.sync_controller.synced_intents");
9560
9867
  const registerIntentTask = CadenzaService.createMetaTask(
9561
9868
  "Record intent registration",
9562
9869
  (ctx) => {
@@ -9606,6 +9913,15 @@ var GraphSyncController = class _GraphSyncController {
9606
9913
  if (!intentDefinition) {
9607
9914
  continue;
9608
9915
  }
9916
+ if (shouldDebugSyncTaskName(task.name) || shouldDebugSyncIntentName(intent)) {
9917
+ logSyncDebug("intent_to_task_map_split", {
9918
+ taskName: task.name,
9919
+ taskVersion: task.version,
9920
+ intentName: intent,
9921
+ serviceName: serviceName2,
9922
+ intentDefinition
9923
+ });
9924
+ }
9609
9925
  emit("meta.sync_controller.intent_task_map_split", {
9610
9926
  __syncing: ctx.__syncing,
9611
9927
  data: {
@@ -9635,6 +9951,13 @@ var GraphSyncController = class _GraphSyncController {
9635
9951
  if (!ctx.__intentDefinition || !ctx.__intentMapData) {
9636
9952
  return false;
9637
9953
  }
9954
+ if (shouldDebugSyncTaskName(ctx.__taskName) || shouldDebugSyncIntentName(ctx.__intent)) {
9955
+ logSyncDebug("intent_definition_prepare", {
9956
+ taskName: ctx.__taskName,
9957
+ intentName: ctx.__intent,
9958
+ intentDefinition: ctx.__intentDefinition
9959
+ });
9960
+ }
9638
9961
  return {
9639
9962
  ...ctx,
9640
9963
  data: ctx.__intentDefinition
@@ -9648,6 +9971,13 @@ var GraphSyncController = class _GraphSyncController {
9648
9971
  if (!ctx.__intentMapData) {
9649
9972
  return false;
9650
9973
  }
9974
+ if (shouldDebugSyncTaskName(ctx.__taskName) || shouldDebugSyncIntentName(ctx.__intent)) {
9975
+ logSyncDebug("intent_map_payload_restore", {
9976
+ taskName: ctx.__taskName,
9977
+ intentName: ctx.__intent,
9978
+ intentMapData: ctx.__intentMapData
9979
+ });
9980
+ }
9651
9981
  return {
9652
9982
  ...ctx,
9653
9983
  data: ctx.__intentMapData
@@ -9827,15 +10157,11 @@ var GraphSyncController = class _GraphSyncController {
9827
10157
  __authoritativeReconciliation: true
9828
10158
  });
9829
10159
  }
9830
- if (authoritativeTasks.length > 0) {
9831
- CadenzaService.debounce(
9832
- "meta.sync_controller.task_registration_settled",
9833
- {
9834
- __syncing: true,
9835
- __authoritativeReconciliation: true
9836
- },
9837
- 300
9838
- );
10160
+ if (authoritativeTasks.length > 0 || changed) {
10161
+ finalizeTaskSync(emit, {
10162
+ ...ctx,
10163
+ __authoritativeReconciliation: true
10164
+ });
9839
10165
  }
9840
10166
  return changed;
9841
10167
  },
@@ -9847,7 +10173,7 @@ var GraphSyncController = class _GraphSyncController {
9847
10173
  );
9848
10174
  const reconcileRoutineRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9849
10175
  "Reconcile routine registration from authority",
9850
- (ctx) => {
10176
+ (ctx, emit) => {
9851
10177
  const authoritativeRoutines = resolveSyncQueryRows(ctx, "routine");
9852
10178
  let changed = false;
9853
10179
  for (const row of authoritativeRoutines) {
@@ -9862,15 +10188,11 @@ var GraphSyncController = class _GraphSyncController {
9862
10188
  routine.registered = true;
9863
10189
  changed = true;
9864
10190
  }
9865
- if (authoritativeRoutines.length > 0) {
9866
- CadenzaService.debounce(
9867
- "meta.sync_controller.routine_registration_settled",
9868
- {
9869
- __syncing: true,
9870
- __authoritativeReconciliation: true
9871
- },
9872
- 300
9873
- );
10191
+ if (authoritativeRoutines.length > 0 || changed) {
10192
+ finalizeRoutineSync(emit, {
10193
+ ...ctx,
10194
+ __authoritativeReconciliation: true
10195
+ });
9874
10196
  }
9875
10197
  return changed;
9876
10198
  },
@@ -9882,7 +10204,7 @@ var GraphSyncController = class _GraphSyncController {
9882
10204
  );
9883
10205
  const reconcileSignalRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9884
10206
  "Reconcile signal registration from authority",
9885
- (ctx) => {
10207
+ (ctx, emit) => {
9886
10208
  const authoritativeSignals = resolveSyncQueryRows(ctx, "signal_registry");
9887
10209
  const signalObservers = CadenzaService.signalBroker.signalObservers;
9888
10210
  let changed = false;
@@ -9898,15 +10220,11 @@ var GraphSyncController = class _GraphSyncController {
9898
10220
  observer.registered = true;
9899
10221
  changed = true;
9900
10222
  }
9901
- if (authoritativeSignals.length > 0) {
9902
- CadenzaService.debounce(
9903
- "meta.sync_controller.signal_registration_settled",
9904
- {
9905
- __syncing: true,
9906
- __authoritativeReconciliation: true
9907
- },
9908
- 300
9909
- );
10223
+ if (authoritativeSignals.length > 0 || changed) {
10224
+ finalizeSignalSync(emit, {
10225
+ ...ctx,
10226
+ __authoritativeReconciliation: true
10227
+ });
9910
10228
  }
9911
10229
  return changed;
9912
10230
  },
@@ -9918,7 +10236,7 @@ var GraphSyncController = class _GraphSyncController {
9918
10236
  );
9919
10237
  const reconcileIntentRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9920
10238
  "Reconcile intent registration from authority",
9921
- (ctx) => {
10239
+ (ctx, emit) => {
9922
10240
  const authoritativeIntents = resolveSyncQueryRows(ctx, "intent_registry");
9923
10241
  let changed = false;
9924
10242
  for (const row of authoritativeIntents) {
@@ -9932,15 +10250,11 @@ var GraphSyncController = class _GraphSyncController {
9932
10250
  this.registeredIntentDefinitions.add(intentName);
9933
10251
  changed = true;
9934
10252
  }
9935
- if (authoritativeIntents.length > 0) {
9936
- CadenzaService.debounce(
9937
- "meta.sync_controller.intent_registration_settled",
9938
- {
9939
- __syncing: true,
9940
- __authoritativeReconciliation: true
9941
- },
9942
- 300
9943
- );
10253
+ if (authoritativeIntents.length > 0 || changed) {
10254
+ finalizeIntentSync(emit, {
10255
+ ...ctx,
10256
+ __authoritativeReconciliation: true
10257
+ });
9944
10258
  }
9945
10259
  return changed;
9946
10260
  },