@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.mjs CHANGED
@@ -8661,10 +8661,21 @@ function buildSyncInsertQueryData(ctx, queryData = {}) {
8661
8661
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8662
8662
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
8663
8663
  const remoteInsertTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0;
8664
+ const debugTable = shouldDebugSyncTable(tableName);
8664
8665
  if (!localInsertTask && !remoteInsertTask) {
8665
8666
  return void 0;
8666
8667
  }
8667
8668
  const targetTask = localInsertTask ?? remoteInsertTask;
8669
+ if (debugTable) {
8670
+ logSyncDebug("insert_task_resolved", {
8671
+ tableName,
8672
+ localInsertTaskName: localInsertTask?.name ?? null,
8673
+ remoteInsertTaskName: remoteInsertTask?.name ?? null,
8674
+ targetTaskName: targetTask.name,
8675
+ queryData,
8676
+ options
8677
+ });
8678
+ }
8668
8679
  const executionRequestedSignal = `meta.sync_controller.insert_execution_requested:${tableName}`;
8669
8680
  const executionResolvedSignal = `meta.sync_controller.insert_execution_resolved:${tableName}`;
8670
8681
  const executionFailedSignal = `meta.sync_controller.insert_execution_failed:${tableName}`;
@@ -8698,6 +8709,26 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8698
8709
  isHidden: true
8699
8710
  }
8700
8711
  ).doOn(executionRequestedSignal).emitsOnFail(executionFailedSignal);
8712
+ if (debugTable) {
8713
+ prepareExecutionTask.then(
8714
+ CadenzaService.createMetaTask(
8715
+ `Log prepared graph sync insert execution for ${tableName}`,
8716
+ (ctx) => {
8717
+ logSyncDebug("insert_prepare", {
8718
+ tableName,
8719
+ targetTaskName: targetTask.name,
8720
+ ctx
8721
+ });
8722
+ return ctx;
8723
+ },
8724
+ `Logs prepared ${tableName} sync insert payloads.`,
8725
+ {
8726
+ register: false,
8727
+ isHidden: true
8728
+ }
8729
+ )
8730
+ );
8731
+ }
8701
8732
  const finalizeExecutionTask = CadenzaService.createMetaTask(
8702
8733
  `Finalize graph sync insert execution for ${tableName}`,
8703
8734
  (ctx, emit) => {
@@ -8714,6 +8745,14 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8714
8745
  ...ctx,
8715
8746
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
8716
8747
  };
8748
+ if (debugTable) {
8749
+ logSyncDebug("insert_finalize", {
8750
+ tableName,
8751
+ targetTaskName: targetTask.name,
8752
+ success: didSyncInsertSucceed(normalizedContext),
8753
+ ctx: normalizedContext
8754
+ });
8755
+ }
8717
8756
  pendingResolverContexts.delete(ctx.__resolverRequestId);
8718
8757
  emit(executionResolvedSignal, normalizedContext);
8719
8758
  return normalizedContext;
@@ -8726,6 +8765,27 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8726
8765
  );
8727
8766
  targetTask.then(finalizeExecutionTask).emitsOnFail(executionFailedSignal);
8728
8767
  prepareExecutionTask.then(targetTask);
8768
+ if (debugTable) {
8769
+ CadenzaService.createMetaTask(
8770
+ `Log failed graph sync insert execution for ${tableName}`,
8771
+ (ctx) => {
8772
+ logSyncDebug("insert_failed", {
8773
+ tableName,
8774
+ targetTaskName: targetTask.name,
8775
+ ctx
8776
+ });
8777
+ if (typeof ctx.__resolverRequestId === "string") {
8778
+ pendingResolverContexts.delete(ctx.__resolverRequestId);
8779
+ }
8780
+ return false;
8781
+ },
8782
+ `Logs failed ${tableName} sync insert executions.`,
8783
+ {
8784
+ register: false,
8785
+ isHidden: true
8786
+ }
8787
+ ).doOn(executionFailedSignal);
8788
+ }
8729
8789
  return CadenzaService.createMetaTask(
8730
8790
  `Resolve graph sync insert for ${tableName}`,
8731
8791
  (ctx, emit) => new Promise((resolve) => {
@@ -8781,6 +8841,104 @@ var AUTHORITY_QUERY_RESULT_KEYS = {
8781
8841
  intent_registry: "intentRegistrys"
8782
8842
  };
8783
8843
  var EARLY_SYNC_REQUEST_DELAYS_MS = [2e3, 1e4, 3e4];
8844
+ var SYNC_DEBUG_PREFIX = "[CADENZA_SYNC_DEBUG]";
8845
+ var SYNC_DEBUG_TABLES = /* @__PURE__ */ new Set([
8846
+ "task",
8847
+ "routine",
8848
+ "task_to_routine_map",
8849
+ "signal_registry",
8850
+ "intent_registry",
8851
+ "signal_to_task_map",
8852
+ "intent_to_task_map"
8853
+ ]);
8854
+ var SYNC_DEBUG_TASK_NAMES = /* @__PURE__ */ new Set([
8855
+ "Query service_instance",
8856
+ "Query service_instance_transport",
8857
+ "Query intent_to_task_map",
8858
+ "Query signal_to_task_map",
8859
+ "Prepare for signal sync",
8860
+ "Compile sync data and broadcast",
8861
+ "Forward service instance sync",
8862
+ "Forward service transport sync",
8863
+ "Forward intent to task map sync",
8864
+ "Forward signal to task map sync"
8865
+ ]);
8866
+ var SYNC_DEBUG_ROUTINE_NAMES = /* @__PURE__ */ new Set(["Sync services"]);
8867
+ var SYNC_DEBUG_INTENT_NAMES = /* @__PURE__ */ new Set([
8868
+ "meta-service-registry-full-sync",
8869
+ "runner-traffic-runtime-get",
8870
+ "iot-telemetry-ingest",
8871
+ "query-pg-CadenzaDBPostgresActor-service_instance",
8872
+ "query-pg-CadenzaDBPostgresActor-service_instance_transport",
8873
+ "query-pg-CadenzaDBPostgresActor-intent_to_task_map",
8874
+ "query-pg-CadenzaDBPostgresActor-signal_to_task_map"
8875
+ ]);
8876
+ function shouldDebugSyncTable(tableName) {
8877
+ return SYNC_DEBUG_TABLES.has(tableName);
8878
+ }
8879
+ function shouldDebugSyncTaskName(taskName) {
8880
+ return typeof taskName === "string" && SYNC_DEBUG_TASK_NAMES.has(taskName);
8881
+ }
8882
+ function shouldDebugSyncRoutineName(routineName) {
8883
+ return typeof routineName === "string" && SYNC_DEBUG_ROUTINE_NAMES.has(routineName);
8884
+ }
8885
+ function shouldDebugSyncIntentName(intentName) {
8886
+ return typeof intentName === "string" && SYNC_DEBUG_INTENT_NAMES.has(intentName);
8887
+ }
8888
+ function summarizeSyncDebugValue(value, depth = 0) {
8889
+ if (value === null || value === void 0) {
8890
+ return value;
8891
+ }
8892
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
8893
+ return value;
8894
+ }
8895
+ if (value instanceof Set) {
8896
+ return {
8897
+ __type: "Set",
8898
+ size: value.size,
8899
+ values: Array.from(value).slice(0, 8).map((item) => summarizeSyncDebugValue(item, depth + 1))
8900
+ };
8901
+ }
8902
+ if (value instanceof Map) {
8903
+ return {
8904
+ __type: "Map",
8905
+ size: value.size
8906
+ };
8907
+ }
8908
+ if (Array.isArray(value)) {
8909
+ return {
8910
+ __type: "Array",
8911
+ length: value.length,
8912
+ items: value.slice(0, 5).map((item) => summarizeSyncDebugValue(item, depth + 1))
8913
+ };
8914
+ }
8915
+ if (typeof value === "object") {
8916
+ if (depth >= 2) {
8917
+ return "[object]";
8918
+ }
8919
+ const output = {};
8920
+ const entries = Object.entries(value).filter(
8921
+ ([key]) => ![
8922
+ "functionString",
8923
+ "tagIdGetter",
8924
+ "__functionString",
8925
+ "__getTagCallback",
8926
+ "joinedContexts",
8927
+ "task",
8928
+ "taskInstance",
8929
+ "tasks"
8930
+ ].includes(key)
8931
+ ).slice(0, 12);
8932
+ for (const [key, nestedValue] of entries) {
8933
+ output[key] = summarizeSyncDebugValue(nestedValue, depth + 1);
8934
+ }
8935
+ return output;
8936
+ }
8937
+ return String(value);
8938
+ }
8939
+ function logSyncDebug(event, payload) {
8940
+ console.log(`${SYNC_DEBUG_PREFIX} ${event}`, summarizeSyncDebugValue(payload));
8941
+ }
8784
8942
  function resolveSyncQueryRows(ctx, tableName) {
8785
8943
  const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
8786
8944
  const rows = ctx?.[resultKey];
@@ -8809,6 +8967,31 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
8809
8967
  }
8810
8968
  ).then(targetTask);
8811
8969
  }
8970
+ function getRegistrableTasks() {
8971
+ return Array.from(CadenzaService.registry.tasks.values()).filter(
8972
+ (task) => task.register && !task.isHidden
8973
+ );
8974
+ }
8975
+ function getRegistrableRoutines() {
8976
+ return Array.from(CadenzaService.registry.routines.values());
8977
+ }
8978
+ function getRegistrableSignalObservers() {
8979
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
8980
+ return signalObservers ? Array.from(signalObservers.values()) : [];
8981
+ }
8982
+ function getRegistrableIntentNames() {
8983
+ return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
8984
+ (intentDefinition) => intentDefinition !== null
8985
+ ).map((intentDefinition) => String(intentDefinition.name));
8986
+ }
8987
+ function buildActorRegistrationKey(actor, serviceName) {
8988
+ const data = buildActorRegistrationData(actor);
8989
+ const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
8990
+ if (!name) {
8991
+ return null;
8992
+ }
8993
+ return `${name}|${data.version}|${serviceName}`;
8994
+ }
8812
8995
  var GraphSyncController = class _GraphSyncController {
8813
8996
  constructor() {
8814
8997
  this.registeredActors = /* @__PURE__ */ new Set();
@@ -8933,22 +9116,158 @@ var GraphSyncController = class _GraphSyncController {
8933
9116
  {},
8934
9117
  { concurrency: 10 }
8935
9118
  );
9119
+ const finalizeTaskSync = (emit, ctx) => {
9120
+ const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
9121
+ if (pendingTasks.length > 0) {
9122
+ this.tasksSynced = false;
9123
+ return false;
9124
+ }
9125
+ const shouldEmit = !this.tasksSynced;
9126
+ this.tasksSynced = true;
9127
+ if (shouldEmit) {
9128
+ emit("meta.sync_controller.synced_tasks", {
9129
+ __syncing: true,
9130
+ ...ctx
9131
+ });
9132
+ }
9133
+ return true;
9134
+ };
9135
+ const finalizeRoutineSync = (emit, ctx) => {
9136
+ const pendingRoutines = getRegistrableRoutines().filter(
9137
+ (routine) => !routine.registered
9138
+ );
9139
+ if (pendingRoutines.length > 0) {
9140
+ this.routinesSynced = false;
9141
+ return false;
9142
+ }
9143
+ const shouldEmit = !this.routinesSynced;
9144
+ this.routinesSynced = true;
9145
+ if (shouldEmit) {
9146
+ emit("meta.sync_controller.synced_routines", {
9147
+ __syncing: true,
9148
+ ...ctx
9149
+ });
9150
+ }
9151
+ return true;
9152
+ };
9153
+ const finalizeSignalSync = (emit, ctx) => {
9154
+ const pendingSignals = getRegistrableSignalObservers().filter(
9155
+ (observer) => observer?.registered !== true
9156
+ );
9157
+ if (pendingSignals.length > 0) {
9158
+ this.signalsSynced = false;
9159
+ return false;
9160
+ }
9161
+ const shouldEmit = !this.signalsSynced;
9162
+ this.signalsSynced = true;
9163
+ if (shouldEmit) {
9164
+ emit("meta.sync_controller.synced_signals", {
9165
+ __syncing: true,
9166
+ ...ctx
9167
+ });
9168
+ }
9169
+ return true;
9170
+ };
9171
+ const finalizeIntentSync = (emit, ctx) => {
9172
+ const pendingIntentNames = getRegistrableIntentNames().filter(
9173
+ (intentName) => !this.registeredIntentDefinitions.has(intentName)
9174
+ );
9175
+ if (pendingIntentNames.length > 0) {
9176
+ this.intentsSynced = false;
9177
+ return false;
9178
+ }
9179
+ const shouldEmit = !this.intentsSynced;
9180
+ this.intentsSynced = true;
9181
+ if (shouldEmit) {
9182
+ emit("meta.sync_controller.synced_intents", {
9183
+ __syncing: true,
9184
+ ...ctx
9185
+ });
9186
+ }
9187
+ return true;
9188
+ };
9189
+ const finalizeActorSync = (emit, ctx) => {
9190
+ const syncServiceName = resolveSyncServiceName();
9191
+ if (!syncServiceName) {
9192
+ this.actorsSynced = false;
9193
+ return false;
9194
+ }
9195
+ const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
9196
+ if (pendingActorKeys.length > 0) {
9197
+ this.actorsSynced = false;
9198
+ return false;
9199
+ }
9200
+ const shouldEmit = !this.actorsSynced;
9201
+ this.actorsSynced = true;
9202
+ if (shouldEmit) {
9203
+ emit("meta.sync_controller.synced_actors", {
9204
+ __syncing: true,
9205
+ ...ctx
9206
+ });
9207
+ }
9208
+ return true;
9209
+ };
9210
+ const gatherTaskRegistrationTask = CadenzaService.createUniqueMetaTask(
9211
+ "Gather task registration",
9212
+ (ctx, emit) => finalizeTaskSync(emit, ctx),
9213
+ "Completes task registration when all registrable tasks are marked registered.",
9214
+ {
9215
+ register: false,
9216
+ isHidden: true
9217
+ }
9218
+ );
9219
+ const gatherRoutineRegistrationTask = CadenzaService.createUniqueMetaTask(
9220
+ "Gather routine registration",
9221
+ (ctx, emit) => finalizeRoutineSync(emit, ctx),
9222
+ "Completes routine registration when all registrable routines are marked registered.",
9223
+ {
9224
+ register: false,
9225
+ isHidden: true
9226
+ }
9227
+ );
9228
+ const gatherSignalRegistrationTask = CadenzaService.createUniqueMetaTask(
9229
+ "Gather signal registration",
9230
+ (ctx, emit) => finalizeSignalSync(emit, ctx),
9231
+ "Completes signal registration when all signal observers are marked registered.",
9232
+ {
9233
+ register: false,
9234
+ isHidden: true
9235
+ }
9236
+ );
9237
+ const gatherIntentRegistrationTask = CadenzaService.createUniqueMetaTask(
9238
+ "Gather intent registration",
9239
+ (ctx, emit) => finalizeIntentSync(emit, ctx),
9240
+ "Completes intent registration when all registrable intents are marked registered.",
9241
+ {
9242
+ register: false,
9243
+ isHidden: true
9244
+ }
9245
+ );
9246
+ const gatherActorRegistrationTask = CadenzaService.createUniqueMetaTask(
9247
+ "Gather actor registration",
9248
+ (ctx, emit) => finalizeActorSync(emit, ctx),
9249
+ "Completes actor registration when all registrable actors are marked registered.",
9250
+ {
9251
+ register: false,
9252
+ isHidden: true
9253
+ }
9254
+ );
8936
9255
  this.splitRoutinesTask = CadenzaService.createMetaTask(
8937
9256
  "Split routines for registration",
8938
- (ctx, emit) => {
9257
+ function* (ctx) {
8939
9258
  const { routines } = ctx;
8940
- if (!routines) return false;
9259
+ if (!routines) return;
8941
9260
  const serviceName2 = resolveSyncServiceName();
8942
9261
  if (!serviceName2) {
8943
- return false;
9262
+ return;
8944
9263
  }
8945
9264
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
8946
9265
  delayMs: 2e3
8947
9266
  });
8948
- let emittedCount = 0;
8949
9267
  for (const routine of routines) {
8950
9268
  if (routine.registered) continue;
8951
- emit("meta.sync_controller.routine_registration_split", {
9269
+ this.routinesSynced = false;
9270
+ yield {
8952
9271
  __syncing: ctx.__syncing,
8953
9272
  data: {
8954
9273
  name: routine.name,
@@ -8958,13 +9277,11 @@ var GraphSyncController = class _GraphSyncController {
8958
9277
  isMeta: routine.isMeta
8959
9278
  },
8960
9279
  __routineName: routine.name
8961
- });
8962
- emittedCount += 1;
9280
+ };
8963
9281
  }
8964
- return emittedCount > 0;
8965
- }
9282
+ }.bind(this)
8966
9283
  );
8967
- CadenzaService.createMetaTask("Process split routine registration", (ctx) => ctx).doOn("meta.sync_controller.routine_registration_split").then(
9284
+ this.splitRoutinesTask.then(
8968
9285
  resolveSyncInsertTask(
8969
9286
  this.isCadenzaDBReady,
8970
9287
  "routine",
@@ -8986,22 +9303,10 @@ var GraphSyncController = class _GraphSyncController {
8986
9303
  delayMs: 3e3
8987
9304
  });
8988
9305
  CadenzaService.getRoutine(ctx.__routineName).registered = true;
8989
- CadenzaService.debounce(
8990
- "meta.sync_controller.routine_registration_settled",
8991
- { __syncing: true },
8992
- 300
8993
- );
8994
9306
  return true;
8995
- })
9307
+ }).then(gatherRoutineRegistrationTask)
8996
9308
  )
8997
9309
  );
8998
- CadenzaService.createUniqueMetaTask(
8999
- "Gather routine registration",
9000
- () => {
9001
- this.routinesSynced = true;
9002
- return true;
9003
- }
9004
- ).doOn("meta.sync_controller.routine_registration_settled").emits("meta.sync_controller.synced_routines");
9005
9310
  this.splitTasksInRoutines = CadenzaService.createMetaTask(
9006
9311
  "Split tasks in routines",
9007
9312
  function* (ctx) {
@@ -9027,6 +9332,16 @@ var GraphSyncController = class _GraphSyncController {
9027
9332
  if (!nextTask?.registered) {
9028
9333
  continue;
9029
9334
  }
9335
+ if (shouldDebugSyncRoutineName(routine.name) || shouldDebugSyncTaskName(nextTask.name)) {
9336
+ logSyncDebug("task_to_routine_split", {
9337
+ routineName: routine.name,
9338
+ routineVersion: routine.version,
9339
+ taskName: nextTask.name,
9340
+ taskVersion: nextTask.version,
9341
+ serviceName: serviceName2,
9342
+ registered: nextTask.registered
9343
+ });
9344
+ }
9030
9345
  yield {
9031
9346
  __syncing: ctx.__syncing,
9032
9347
  data: {
@@ -9080,18 +9395,19 @@ var GraphSyncController = class _GraphSyncController {
9080
9395
  }
9081
9396
  this.splitSignalsTask = CadenzaService.createMetaTask(
9082
9397
  "Split signals for registration",
9083
- (ctx, emit) => {
9398
+ function* (ctx) {
9084
9399
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9085
9400
  delayMs: 3e3
9086
9401
  });
9087
9402
  const { signals } = ctx;
9088
- if (!signals) return false;
9403
+ if (!signals) return;
9089
9404
  const filteredSignals = signals.filter(
9090
9405
  (signal) => !signal.data.registered
9091
9406
  ).map((signal) => signal.signal);
9092
9407
  for (const signal of filteredSignals) {
9093
9408
  const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
9094
- emit("meta.sync_controller.signal_registration_split", {
9409
+ this.signalsSynced = false;
9410
+ yield {
9095
9411
  __syncing: ctx.__syncing,
9096
9412
  data: {
9097
9413
  name: signal,
@@ -9101,12 +9417,11 @@ var GraphSyncController = class _GraphSyncController {
9101
9417
  isMeta
9102
9418
  },
9103
9419
  __signal: signal
9104
- });
9420
+ };
9105
9421
  }
9106
- return filteredSignals.length > 0;
9107
- }
9422
+ }.bind(this)
9108
9423
  );
9109
- CadenzaService.createMetaTask("Process split signal registration", (ctx) => ctx).doOn("meta.sync_controller.signal_registration_split").then(
9424
+ this.splitSignalsTask.then(
9110
9425
  resolveSyncInsertTask(
9111
9426
  this.isCadenzaDBReady,
9112
9427
  "signal_registry",
@@ -9127,22 +9442,10 @@ var GraphSyncController = class _GraphSyncController {
9127
9442
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9128
9443
  delayMs: 3e3
9129
9444
  });
9130
- CadenzaService.debounce(
9131
- "meta.sync_controller.signal_registration_settled",
9132
- { __syncing: true },
9133
- 300
9134
- );
9135
9445
  return { signalName: ctx.__signal };
9136
- }).then(CadenzaService.signalBroker.registerSignalTask)
9446
+ }).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask)
9137
9447
  )
9138
9448
  );
9139
- CadenzaService.createUniqueMetaTask(
9140
- "Gather signal registration",
9141
- () => {
9142
- this.signalsSynced = true;
9143
- return true;
9144
- }
9145
- ).doOn("meta.sync_controller.signal_registration_settled").emits("meta.sync_controller.synced_signals");
9146
9449
  this.splitTasksForRegistration = CadenzaService.createMetaTask(
9147
9450
  "Split tasks for registration",
9148
9451
  function* (ctx) {
@@ -9157,6 +9460,19 @@ var GraphSyncController = class _GraphSyncController {
9157
9460
  for (const task of tasks) {
9158
9461
  if (task.registered) continue;
9159
9462
  const { __functionString, __getTagCallback } = task.export();
9463
+ this.tasksSynced = false;
9464
+ if (shouldDebugSyncTaskName(task.name)) {
9465
+ logSyncDebug("task_registration_split", {
9466
+ taskName: task.name,
9467
+ taskVersion: task.version,
9468
+ serviceName: serviceName2,
9469
+ register: task.register,
9470
+ registered: task.registered,
9471
+ hidden: task.hidden,
9472
+ observedSignals: Array.from(task.observedSignals),
9473
+ handledIntents: Array.from(task.handlesIntents)
9474
+ });
9475
+ }
9160
9476
  yield {
9161
9477
  __syncing: ctx.__syncing,
9162
9478
  data: {
@@ -9193,7 +9509,7 @@ var GraphSyncController = class _GraphSyncController {
9193
9509
  __taskName: task.name
9194
9510
  };
9195
9511
  }
9196
- }
9512
+ }.bind(this)
9197
9513
  );
9198
9514
  const registerTaskTask = resolveSyncInsertTask(
9199
9515
  this.isCadenzaDBReady,
@@ -9209,6 +9525,13 @@ var GraphSyncController = class _GraphSyncController {
9209
9525
  { concurrency: 30 }
9210
9526
  )?.then(
9211
9527
  CadenzaService.createMetaTask("Record registration", (ctx, emit) => {
9528
+ if (shouldDebugSyncTaskName(ctx.__taskName)) {
9529
+ logSyncDebug("task_registration_result", {
9530
+ taskName: ctx.__taskName,
9531
+ success: didSyncInsertSucceed(ctx),
9532
+ ctx
9533
+ });
9534
+ }
9212
9535
  if (!didSyncInsertSucceed(ctx)) {
9213
9536
  return;
9214
9537
  }
@@ -9220,13 +9543,8 @@ var GraphSyncController = class _GraphSyncController {
9220
9543
  ...ctx,
9221
9544
  task: CadenzaService.get(ctx.__taskName)
9222
9545
  });
9223
- CadenzaService.debounce(
9224
- "meta.sync_controller.task_registration_settled",
9225
- { __syncing: true },
9226
- 300
9227
- );
9228
9546
  return true;
9229
- })
9547
+ }).then(gatherTaskRegistrationTask)
9230
9548
  );
9231
9549
  if (registerTaskTask) {
9232
9550
  this.splitTasksForRegistration.then(registerTaskTask);
@@ -9235,6 +9553,16 @@ var GraphSyncController = class _GraphSyncController {
9235
9553
  "Prepare created task for immediate sync",
9236
9554
  (ctx) => {
9237
9555
  const task = ctx.taskInstance ?? (ctx.data?.name ? CadenzaService.get(String(ctx.data.name)) : void 0);
9556
+ if (shouldDebugSyncTaskName(task?.name ?? ctx?.data?.name)) {
9557
+ logSyncDebug("task_created_for_immediate_sync", {
9558
+ incomingTaskName: ctx?.data?.name ?? null,
9559
+ resolvedTaskName: task?.name ?? null,
9560
+ exists: Boolean(task),
9561
+ hidden: task?.hidden ?? null,
9562
+ register: task?.register ?? null,
9563
+ registered: task?.registered ?? null
9564
+ });
9565
+ }
9238
9566
  if (!task || task.hidden || !task.register || task.registered) {
9239
9567
  return false;
9240
9568
  }
@@ -9249,13 +9577,6 @@ var GraphSyncController = class _GraphSyncController {
9249
9577
  isHidden: true
9250
9578
  }
9251
9579
  ).doOn("meta.task.created").then(this.splitTasksForRegistration);
9252
- CadenzaService.createUniqueMetaTask(
9253
- "Gather task registration",
9254
- () => {
9255
- this.tasksSynced = true;
9256
- return true;
9257
- }
9258
- ).doOn("meta.sync_controller.task_registration_settled").emits("meta.sync_controller.synced_tasks");
9259
9580
  this.splitActorsForRegistration = CadenzaService.createMetaTask(
9260
9581
  "Split actors for registration",
9261
9582
  function* (ctx) {
@@ -9279,6 +9600,7 @@ var GraphSyncController = class _GraphSyncController {
9279
9600
  if (this.registeredActors.has(registrationKey)) {
9280
9601
  continue;
9281
9602
  }
9603
+ this.actorsSynced = false;
9282
9604
  yield {
9283
9605
  data,
9284
9606
  __actorRegistrationKey: registrationKey
@@ -9307,22 +9629,10 @@ var GraphSyncController = class _GraphSyncController {
9307
9629
  delayMs: 3e3
9308
9630
  });
9309
9631
  this.registeredActors.add(ctx.__actorRegistrationKey);
9310
- CadenzaService.debounce(
9311
- "meta.sync_controller.actor_registration_settled",
9312
- { __syncing: true },
9313
- 300
9314
- );
9315
9632
  return true;
9316
- })
9633
+ }).then(gatherActorRegistrationTask)
9317
9634
  )
9318
9635
  );
9319
- CadenzaService.createUniqueMetaTask(
9320
- "Gather actor registration",
9321
- () => {
9322
- this.actorsSynced = true;
9323
- return true;
9324
- }
9325
- ).doOn("meta.sync_controller.actor_registration_settled").emits("meta.sync_controller.synced_actors");
9326
9636
  this.registerActorTaskMapTask = CadenzaService.createMetaTask(
9327
9637
  "Split actor task maps",
9328
9638
  function* (ctx) {
@@ -9419,6 +9729,17 @@ var GraphSyncController = class _GraphSyncController {
9419
9729
  continue;
9420
9730
  }
9421
9731
  const { isGlobal } = decomposeSignalName(_signal);
9732
+ if (shouldDebugSyncTaskName(task.name)) {
9733
+ logSyncDebug("signal_to_task_map_split", {
9734
+ taskName: task.name,
9735
+ signalName: _signal,
9736
+ rawSignal: signal,
9737
+ serviceName: serviceName2,
9738
+ observerRegistered: CadenzaService.signalBroker.signalObservers?.get(
9739
+ _signal
9740
+ )?.registered
9741
+ });
9742
+ }
9422
9743
  emit("meta.sync_controller.signal_task_map_split", {
9423
9744
  __syncing: ctx.__syncing,
9424
9745
  data: {
@@ -9458,12 +9779,11 @@ var GraphSyncController = class _GraphSyncController {
9458
9779
  );
9459
9780
  this.splitIntentsTask = CadenzaService.createMetaTask(
9460
9781
  "Split intents for registration",
9461
- function(ctx, emit) {
9782
+ function* (ctx) {
9462
9783
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9463
9784
  delayMs: 3e3
9464
9785
  });
9465
9786
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
9466
- let emittedCount = 0;
9467
9787
  for (const intent of intents) {
9468
9788
  const intentData = buildIntentRegistryData(intent);
9469
9789
  if (!intentData) {
@@ -9472,17 +9792,16 @@ var GraphSyncController = class _GraphSyncController {
9472
9792
  if (this.registeredIntentDefinitions.has(intentData.name)) {
9473
9793
  continue;
9474
9794
  }
9475
- emit("meta.sync_controller.intent_registration_split", {
9795
+ this.intentsSynced = false;
9796
+ yield {
9476
9797
  __syncing: ctx.__syncing,
9477
9798
  data: intentData,
9478
9799
  __intentName: intentData.name
9479
- });
9480
- emittedCount += 1;
9800
+ };
9481
9801
  }
9482
- return emittedCount > 0;
9483
9802
  }.bind(this)
9484
9803
  );
9485
- CadenzaService.createMetaTask("Process split intent registration", (ctx) => ctx).doOn("meta.sync_controller.intent_registration_split").then(
9804
+ this.splitIntentsTask.then(
9486
9805
  insertIntentRegistryTask?.then(
9487
9806
  CadenzaService.createMetaTask("Record intent definition registration", (ctx) => {
9488
9807
  if (!didSyncInsertSucceed(ctx)) {
@@ -9492,22 +9811,10 @@ var GraphSyncController = class _GraphSyncController {
9492
9811
  delayMs: 3e3
9493
9812
  });
9494
9813
  this.registeredIntentDefinitions.add(ctx.__intentName);
9495
- CadenzaService.debounce(
9496
- "meta.sync_controller.intent_registration_settled",
9497
- { __syncing: true },
9498
- 300
9499
- );
9500
9814
  return true;
9501
- })
9815
+ }).then(gatherIntentRegistrationTask)
9502
9816
  )
9503
9817
  );
9504
- CadenzaService.createUniqueMetaTask(
9505
- "Gather intent registration",
9506
- () => {
9507
- this.intentsSynced = true;
9508
- return true;
9509
- }
9510
- ).doOn("meta.sync_controller.intent_registration_settled").emits("meta.sync_controller.synced_intents");
9511
9818
  const registerIntentTask = CadenzaService.createMetaTask(
9512
9819
  "Record intent registration",
9513
9820
  (ctx) => {
@@ -9557,6 +9864,15 @@ var GraphSyncController = class _GraphSyncController {
9557
9864
  if (!intentDefinition) {
9558
9865
  continue;
9559
9866
  }
9867
+ if (shouldDebugSyncTaskName(task.name) || shouldDebugSyncIntentName(intent)) {
9868
+ logSyncDebug("intent_to_task_map_split", {
9869
+ taskName: task.name,
9870
+ taskVersion: task.version,
9871
+ intentName: intent,
9872
+ serviceName: serviceName2,
9873
+ intentDefinition
9874
+ });
9875
+ }
9560
9876
  emit("meta.sync_controller.intent_task_map_split", {
9561
9877
  __syncing: ctx.__syncing,
9562
9878
  data: {
@@ -9586,6 +9902,13 @@ var GraphSyncController = class _GraphSyncController {
9586
9902
  if (!ctx.__intentDefinition || !ctx.__intentMapData) {
9587
9903
  return false;
9588
9904
  }
9905
+ if (shouldDebugSyncTaskName(ctx.__taskName) || shouldDebugSyncIntentName(ctx.__intent)) {
9906
+ logSyncDebug("intent_definition_prepare", {
9907
+ taskName: ctx.__taskName,
9908
+ intentName: ctx.__intent,
9909
+ intentDefinition: ctx.__intentDefinition
9910
+ });
9911
+ }
9589
9912
  return {
9590
9913
  ...ctx,
9591
9914
  data: ctx.__intentDefinition
@@ -9599,6 +9922,13 @@ var GraphSyncController = class _GraphSyncController {
9599
9922
  if (!ctx.__intentMapData) {
9600
9923
  return false;
9601
9924
  }
9925
+ if (shouldDebugSyncTaskName(ctx.__taskName) || shouldDebugSyncIntentName(ctx.__intent)) {
9926
+ logSyncDebug("intent_map_payload_restore", {
9927
+ taskName: ctx.__taskName,
9928
+ intentName: ctx.__intent,
9929
+ intentMapData: ctx.__intentMapData
9930
+ });
9931
+ }
9602
9932
  return {
9603
9933
  ...ctx,
9604
9934
  data: ctx.__intentMapData
@@ -9778,15 +10108,11 @@ var GraphSyncController = class _GraphSyncController {
9778
10108
  __authoritativeReconciliation: true
9779
10109
  });
9780
10110
  }
9781
- if (authoritativeTasks.length > 0) {
9782
- CadenzaService.debounce(
9783
- "meta.sync_controller.task_registration_settled",
9784
- {
9785
- __syncing: true,
9786
- __authoritativeReconciliation: true
9787
- },
9788
- 300
9789
- );
10111
+ if (authoritativeTasks.length > 0 || changed) {
10112
+ finalizeTaskSync(emit, {
10113
+ ...ctx,
10114
+ __authoritativeReconciliation: true
10115
+ });
9790
10116
  }
9791
10117
  return changed;
9792
10118
  },
@@ -9798,7 +10124,7 @@ var GraphSyncController = class _GraphSyncController {
9798
10124
  );
9799
10125
  const reconcileRoutineRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9800
10126
  "Reconcile routine registration from authority",
9801
- (ctx) => {
10127
+ (ctx, emit) => {
9802
10128
  const authoritativeRoutines = resolveSyncQueryRows(ctx, "routine");
9803
10129
  let changed = false;
9804
10130
  for (const row of authoritativeRoutines) {
@@ -9813,15 +10139,11 @@ var GraphSyncController = class _GraphSyncController {
9813
10139
  routine.registered = true;
9814
10140
  changed = true;
9815
10141
  }
9816
- if (authoritativeRoutines.length > 0) {
9817
- CadenzaService.debounce(
9818
- "meta.sync_controller.routine_registration_settled",
9819
- {
9820
- __syncing: true,
9821
- __authoritativeReconciliation: true
9822
- },
9823
- 300
9824
- );
10142
+ if (authoritativeRoutines.length > 0 || changed) {
10143
+ finalizeRoutineSync(emit, {
10144
+ ...ctx,
10145
+ __authoritativeReconciliation: true
10146
+ });
9825
10147
  }
9826
10148
  return changed;
9827
10149
  },
@@ -9833,7 +10155,7 @@ var GraphSyncController = class _GraphSyncController {
9833
10155
  );
9834
10156
  const reconcileSignalRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9835
10157
  "Reconcile signal registration from authority",
9836
- (ctx) => {
10158
+ (ctx, emit) => {
9837
10159
  const authoritativeSignals = resolveSyncQueryRows(ctx, "signal_registry");
9838
10160
  const signalObservers = CadenzaService.signalBroker.signalObservers;
9839
10161
  let changed = false;
@@ -9849,15 +10171,11 @@ var GraphSyncController = class _GraphSyncController {
9849
10171
  observer.registered = true;
9850
10172
  changed = true;
9851
10173
  }
9852
- if (authoritativeSignals.length > 0) {
9853
- CadenzaService.debounce(
9854
- "meta.sync_controller.signal_registration_settled",
9855
- {
9856
- __syncing: true,
9857
- __authoritativeReconciliation: true
9858
- },
9859
- 300
9860
- );
10174
+ if (authoritativeSignals.length > 0 || changed) {
10175
+ finalizeSignalSync(emit, {
10176
+ ...ctx,
10177
+ __authoritativeReconciliation: true
10178
+ });
9861
10179
  }
9862
10180
  return changed;
9863
10181
  },
@@ -9869,7 +10187,7 @@ var GraphSyncController = class _GraphSyncController {
9869
10187
  );
9870
10188
  const reconcileIntentRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
9871
10189
  "Reconcile intent registration from authority",
9872
- (ctx) => {
10190
+ (ctx, emit) => {
9873
10191
  const authoritativeIntents = resolveSyncQueryRows(ctx, "intent_registry");
9874
10192
  let changed = false;
9875
10193
  for (const row of authoritativeIntents) {
@@ -9883,15 +10201,11 @@ var GraphSyncController = class _GraphSyncController {
9883
10201
  this.registeredIntentDefinitions.add(intentName);
9884
10202
  changed = true;
9885
10203
  }
9886
- if (authoritativeIntents.length > 0) {
9887
- CadenzaService.debounce(
9888
- "meta.sync_controller.intent_registration_settled",
9889
- {
9890
- __syncing: true,
9891
- __authoritativeReconciliation: true
9892
- },
9893
- 300
9894
- );
10204
+ if (authoritativeIntents.length > 0 || changed) {
10205
+ finalizeIntentSync(emit, {
10206
+ ...ctx,
10207
+ __authoritativeReconciliation: true
10208
+ });
9895
10209
  }
9896
10210
  return changed;
9897
10211
  },