@cadenza.io/service 2.17.48 → 2.17.50

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
@@ -8714,6 +8714,17 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8714
8714
  CadenzaService.createMetaTask(
8715
8715
  `Log prepared graph sync insert execution for ${tableName}`,
8716
8716
  (ctx) => {
8717
+ if (tableName === "task") {
8718
+ if (!shouldDebugTaskSyncPayload(ctx)) {
8719
+ return ctx;
8720
+ }
8721
+ logSyncDebug("insert_prepare", {
8722
+ tableName,
8723
+ targetTaskName: targetTask.name,
8724
+ payload: buildTaskSyncDebugPayload(ctx)
8725
+ });
8726
+ return ctx;
8727
+ }
8717
8728
  logSyncDebug("insert_prepare", {
8718
8729
  tableName,
8719
8730
  targetTaskName: targetTask.name,
@@ -8746,12 +8757,23 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8746
8757
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
8747
8758
  };
8748
8759
  if (debugTable) {
8749
- logSyncDebug("insert_finalize", {
8750
- tableName,
8751
- targetTaskName: targetTask.name,
8752
- success: didSyncInsertSucceed(normalizedContext),
8753
- ctx: normalizedContext
8754
- });
8760
+ if (tableName === "task") {
8761
+ if (shouldDebugTaskSyncPayload(normalizedContext)) {
8762
+ logSyncDebug("insert_finalize", {
8763
+ tableName,
8764
+ targetTaskName: targetTask.name,
8765
+ success: didSyncInsertSucceed(normalizedContext),
8766
+ payload: buildTaskSyncDebugPayload(normalizedContext)
8767
+ });
8768
+ }
8769
+ } else {
8770
+ logSyncDebug("insert_finalize", {
8771
+ tableName,
8772
+ targetTaskName: targetTask.name,
8773
+ success: didSyncInsertSucceed(normalizedContext),
8774
+ ctx: normalizedContext
8775
+ });
8776
+ }
8755
8777
  }
8756
8778
  pendingResolverContexts.delete(ctx.__resolverRequestId);
8757
8779
  emit(executionResolvedSignal, normalizedContext);
@@ -8769,11 +8791,21 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8769
8791
  CadenzaService.createMetaTask(
8770
8792
  `Log failed graph sync insert execution for ${tableName}`,
8771
8793
  (ctx) => {
8772
- logSyncDebug("insert_failed", {
8773
- tableName,
8774
- targetTaskName: targetTask.name,
8775
- ctx
8776
- });
8794
+ if (tableName === "task") {
8795
+ if (shouldDebugTaskSyncPayload(ctx)) {
8796
+ logSyncDebug("insert_failed", {
8797
+ tableName,
8798
+ targetTaskName: targetTask.name,
8799
+ payload: buildTaskSyncDebugPayload(ctx)
8800
+ });
8801
+ }
8802
+ } else {
8803
+ logSyncDebug("insert_failed", {
8804
+ tableName,
8805
+ targetTaskName: targetTask.name,
8806
+ ctx
8807
+ });
8808
+ }
8777
8809
  if (typeof ctx.__resolverRequestId === "string") {
8778
8810
  pendingResolverContexts.delete(ctx.__resolverRequestId);
8779
8811
  }
@@ -8939,6 +8971,37 @@ function summarizeSyncDebugValue(value, depth = 0) {
8939
8971
  function logSyncDebug(event, payload) {
8940
8972
  console.log(`${SYNC_DEBUG_PREFIX} ${event}`, summarizeSyncDebugValue(payload));
8941
8973
  }
8974
+ function buildTaskSyncDebugPayload(ctx) {
8975
+ const data = ctx.data && typeof ctx.data === "object" ? ctx.data : {};
8976
+ const queryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {};
8977
+ const queryDataData = queryData.data && typeof queryData.data === "object" ? queryData.data : {};
8978
+ const taskPayload = Object.keys(queryDataData).length > 0 ? queryDataData : data;
8979
+ const functionString = typeof taskPayload.functionString === "string" ? taskPayload.functionString : typeof taskPayload.function_string === "string" ? taskPayload.function_string : void 0;
8980
+ const tagIdGetter = typeof taskPayload.tagIdGetter === "string" ? taskPayload.tagIdGetter : typeof taskPayload.tag_id_getter === "string" ? taskPayload.tag_id_getter : void 0;
8981
+ const signals = taskPayload.signals && typeof taskPayload.signals === "object" ? taskPayload.signals : {};
8982
+ const intents = taskPayload.intents && typeof taskPayload.intents === "object" ? taskPayload.intents : {};
8983
+ return {
8984
+ taskName: taskPayload.name ?? taskPayload.taskName ?? taskPayload.task_name ?? ctx.__taskName ?? null,
8985
+ serviceName: taskPayload.service_name ?? taskPayload.serviceName ?? ctx.__syncServiceName ?? null,
8986
+ functionStringLength: functionString?.length ?? null,
8987
+ tagIdGetterLength: tagIdGetter?.length ?? null,
8988
+ isMeta: taskPayload.isMeta ?? taskPayload.is_meta ?? null,
8989
+ isSubMeta: taskPayload.isSubMeta ?? taskPayload.is_sub_meta ?? null,
8990
+ isHidden: taskPayload.isHidden ?? taskPayload.is_hidden ?? null,
8991
+ signalsEmitsCount: Array.isArray(signals.emits) ? signals.emits.length : null,
8992
+ signalsObservedCount: Array.isArray(signals.observed) ? signals.observed.length : null,
8993
+ intentHandlesCount: Array.isArray(intents.handles) ? intents.handles.length : null,
8994
+ intentInquiresCount: Array.isArray(intents.inquires) ? intents.inquires.length : null,
8995
+ rowCount: ctx.rowCount ?? null,
8996
+ errored: ctx.errored ?? false,
8997
+ success: ctx.__success ?? null,
8998
+ error: ctx.__error ?? null
8999
+ };
9000
+ }
9001
+ function shouldDebugTaskSyncPayload(ctx) {
9002
+ const payload = buildTaskSyncDebugPayload(ctx);
9003
+ return shouldDebugSyncTaskName(payload.taskName);
9004
+ }
8942
9005
  function resolveSyncQueryRows(ctx, tableName) {
8943
9006
  const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
8944
9007
  const rows = ctx?.[resultKey];
@@ -8967,6 +9030,31 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
8967
9030
  }
8968
9031
  ).then(targetTask);
8969
9032
  }
9033
+ function getRegistrableTasks() {
9034
+ return Array.from(CadenzaService.registry.tasks.values()).filter(
9035
+ (task) => task.register && !task.isHidden
9036
+ );
9037
+ }
9038
+ function getRegistrableRoutines() {
9039
+ return Array.from(CadenzaService.registry.routines.values());
9040
+ }
9041
+ function getRegistrableSignalObservers() {
9042
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
9043
+ return signalObservers ? Array.from(signalObservers.values()) : [];
9044
+ }
9045
+ function getRegistrableIntentNames() {
9046
+ return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
9047
+ (intentDefinition) => intentDefinition !== null
9048
+ ).map((intentDefinition) => String(intentDefinition.name));
9049
+ }
9050
+ function buildActorRegistrationKey(actor, serviceName) {
9051
+ const data = buildActorRegistrationData(actor);
9052
+ const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
9053
+ if (!name) {
9054
+ return null;
9055
+ }
9056
+ return `${name}|${data.version}|${serviceName}`;
9057
+ }
8970
9058
  var GraphSyncController = class _GraphSyncController {
8971
9059
  constructor() {
8972
9060
  this.registeredActors = /* @__PURE__ */ new Set();
@@ -9091,22 +9179,158 @@ var GraphSyncController = class _GraphSyncController {
9091
9179
  {},
9092
9180
  { concurrency: 10 }
9093
9181
  );
9182
+ const finalizeTaskSync = (emit, ctx) => {
9183
+ const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
9184
+ if (pendingTasks.length > 0) {
9185
+ this.tasksSynced = false;
9186
+ return false;
9187
+ }
9188
+ const shouldEmit = !this.tasksSynced;
9189
+ this.tasksSynced = true;
9190
+ if (shouldEmit) {
9191
+ emit("meta.sync_controller.synced_tasks", {
9192
+ __syncing: true,
9193
+ ...ctx
9194
+ });
9195
+ }
9196
+ return true;
9197
+ };
9198
+ const finalizeRoutineSync = (emit, ctx) => {
9199
+ const pendingRoutines = getRegistrableRoutines().filter(
9200
+ (routine) => !routine.registered
9201
+ );
9202
+ if (pendingRoutines.length > 0) {
9203
+ this.routinesSynced = false;
9204
+ return false;
9205
+ }
9206
+ const shouldEmit = !this.routinesSynced;
9207
+ this.routinesSynced = true;
9208
+ if (shouldEmit) {
9209
+ emit("meta.sync_controller.synced_routines", {
9210
+ __syncing: true,
9211
+ ...ctx
9212
+ });
9213
+ }
9214
+ return true;
9215
+ };
9216
+ const finalizeSignalSync = (emit, ctx) => {
9217
+ const pendingSignals = getRegistrableSignalObservers().filter(
9218
+ (observer) => observer?.registered !== true
9219
+ );
9220
+ if (pendingSignals.length > 0) {
9221
+ this.signalsSynced = false;
9222
+ return false;
9223
+ }
9224
+ const shouldEmit = !this.signalsSynced;
9225
+ this.signalsSynced = true;
9226
+ if (shouldEmit) {
9227
+ emit("meta.sync_controller.synced_signals", {
9228
+ __syncing: true,
9229
+ ...ctx
9230
+ });
9231
+ }
9232
+ return true;
9233
+ };
9234
+ const finalizeIntentSync = (emit, ctx) => {
9235
+ const pendingIntentNames = getRegistrableIntentNames().filter(
9236
+ (intentName) => !this.registeredIntentDefinitions.has(intentName)
9237
+ );
9238
+ if (pendingIntentNames.length > 0) {
9239
+ this.intentsSynced = false;
9240
+ return false;
9241
+ }
9242
+ const shouldEmit = !this.intentsSynced;
9243
+ this.intentsSynced = true;
9244
+ if (shouldEmit) {
9245
+ emit("meta.sync_controller.synced_intents", {
9246
+ __syncing: true,
9247
+ ...ctx
9248
+ });
9249
+ }
9250
+ return true;
9251
+ };
9252
+ const finalizeActorSync = (emit, ctx) => {
9253
+ const syncServiceName = resolveSyncServiceName();
9254
+ if (!syncServiceName) {
9255
+ this.actorsSynced = false;
9256
+ return false;
9257
+ }
9258
+ const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
9259
+ if (pendingActorKeys.length > 0) {
9260
+ this.actorsSynced = false;
9261
+ return false;
9262
+ }
9263
+ const shouldEmit = !this.actorsSynced;
9264
+ this.actorsSynced = true;
9265
+ if (shouldEmit) {
9266
+ emit("meta.sync_controller.synced_actors", {
9267
+ __syncing: true,
9268
+ ...ctx
9269
+ });
9270
+ }
9271
+ return true;
9272
+ };
9273
+ const gatherTaskRegistrationTask = CadenzaService.createUniqueMetaTask(
9274
+ "Gather task registration",
9275
+ (ctx, emit) => finalizeTaskSync(emit, ctx),
9276
+ "Completes task registration when all registrable tasks are marked registered.",
9277
+ {
9278
+ register: false,
9279
+ isHidden: true
9280
+ }
9281
+ );
9282
+ const gatherRoutineRegistrationTask = CadenzaService.createUniqueMetaTask(
9283
+ "Gather routine registration",
9284
+ (ctx, emit) => finalizeRoutineSync(emit, ctx),
9285
+ "Completes routine registration when all registrable routines are marked registered.",
9286
+ {
9287
+ register: false,
9288
+ isHidden: true
9289
+ }
9290
+ );
9291
+ const gatherSignalRegistrationTask = CadenzaService.createUniqueMetaTask(
9292
+ "Gather signal registration",
9293
+ (ctx, emit) => finalizeSignalSync(emit, ctx),
9294
+ "Completes signal registration when all signal observers are marked registered.",
9295
+ {
9296
+ register: false,
9297
+ isHidden: true
9298
+ }
9299
+ );
9300
+ const gatherIntentRegistrationTask = CadenzaService.createUniqueMetaTask(
9301
+ "Gather intent registration",
9302
+ (ctx, emit) => finalizeIntentSync(emit, ctx),
9303
+ "Completes intent registration when all registrable intents are marked registered.",
9304
+ {
9305
+ register: false,
9306
+ isHidden: true
9307
+ }
9308
+ );
9309
+ const gatherActorRegistrationTask = CadenzaService.createUniqueMetaTask(
9310
+ "Gather actor registration",
9311
+ (ctx, emit) => finalizeActorSync(emit, ctx),
9312
+ "Completes actor registration when all registrable actors are marked registered.",
9313
+ {
9314
+ register: false,
9315
+ isHidden: true
9316
+ }
9317
+ );
9094
9318
  this.splitRoutinesTask = CadenzaService.createMetaTask(
9095
9319
  "Split routines for registration",
9096
- (ctx, emit) => {
9320
+ function* (ctx) {
9097
9321
  const { routines } = ctx;
9098
- if (!routines) return false;
9322
+ if (!routines) return;
9099
9323
  const serviceName2 = resolveSyncServiceName();
9100
9324
  if (!serviceName2) {
9101
- return false;
9325
+ return;
9102
9326
  }
9103
9327
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9104
9328
  delayMs: 2e3
9105
9329
  });
9106
- let emittedCount = 0;
9107
9330
  for (const routine of routines) {
9108
9331
  if (routine.registered) continue;
9109
- emit("meta.sync_controller.routine_registration_split", {
9332
+ this.routinesSynced = false;
9333
+ yield {
9110
9334
  __syncing: ctx.__syncing,
9111
9335
  data: {
9112
9336
  name: routine.name,
@@ -9116,13 +9340,11 @@ var GraphSyncController = class _GraphSyncController {
9116
9340
  isMeta: routine.isMeta
9117
9341
  },
9118
9342
  __routineName: routine.name
9119
- });
9120
- emittedCount += 1;
9343
+ };
9121
9344
  }
9122
- return emittedCount > 0;
9123
- }
9345
+ }.bind(this)
9124
9346
  );
9125
- CadenzaService.createMetaTask("Process split routine registration", (ctx) => ctx).doOn("meta.sync_controller.routine_registration_split").then(
9347
+ this.splitRoutinesTask.then(
9126
9348
  resolveSyncInsertTask(
9127
9349
  this.isCadenzaDBReady,
9128
9350
  "routine",
@@ -9144,22 +9366,10 @@ var GraphSyncController = class _GraphSyncController {
9144
9366
  delayMs: 3e3
9145
9367
  });
9146
9368
  CadenzaService.getRoutine(ctx.__routineName).registered = true;
9147
- CadenzaService.debounce(
9148
- "meta.sync_controller.routine_registration_settled",
9149
- { __syncing: true },
9150
- 300
9151
- );
9152
9369
  return true;
9153
- })
9370
+ }).then(gatherRoutineRegistrationTask)
9154
9371
  )
9155
9372
  );
9156
- CadenzaService.createUniqueMetaTask(
9157
- "Gather routine registration",
9158
- () => {
9159
- this.routinesSynced = true;
9160
- return true;
9161
- }
9162
- ).doOn("meta.sync_controller.routine_registration_settled").emits("meta.sync_controller.synced_routines");
9163
9373
  this.splitTasksInRoutines = CadenzaService.createMetaTask(
9164
9374
  "Split tasks in routines",
9165
9375
  function* (ctx) {
@@ -9248,18 +9458,19 @@ var GraphSyncController = class _GraphSyncController {
9248
9458
  }
9249
9459
  this.splitSignalsTask = CadenzaService.createMetaTask(
9250
9460
  "Split signals for registration",
9251
- (ctx, emit) => {
9461
+ function* (ctx) {
9252
9462
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9253
9463
  delayMs: 3e3
9254
9464
  });
9255
9465
  const { signals } = ctx;
9256
- if (!signals) return false;
9466
+ if (!signals) return;
9257
9467
  const filteredSignals = signals.filter(
9258
9468
  (signal) => !signal.data.registered
9259
9469
  ).map((signal) => signal.signal);
9260
9470
  for (const signal of filteredSignals) {
9261
9471
  const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
9262
- emit("meta.sync_controller.signal_registration_split", {
9472
+ this.signalsSynced = false;
9473
+ yield {
9263
9474
  __syncing: ctx.__syncing,
9264
9475
  data: {
9265
9476
  name: signal,
@@ -9269,12 +9480,11 @@ var GraphSyncController = class _GraphSyncController {
9269
9480
  isMeta
9270
9481
  },
9271
9482
  __signal: signal
9272
- });
9483
+ };
9273
9484
  }
9274
- return filteredSignals.length > 0;
9275
- }
9485
+ }.bind(this)
9276
9486
  );
9277
- CadenzaService.createMetaTask("Process split signal registration", (ctx) => ctx).doOn("meta.sync_controller.signal_registration_split").then(
9487
+ this.splitSignalsTask.then(
9278
9488
  resolveSyncInsertTask(
9279
9489
  this.isCadenzaDBReady,
9280
9490
  "signal_registry",
@@ -9295,22 +9505,10 @@ var GraphSyncController = class _GraphSyncController {
9295
9505
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9296
9506
  delayMs: 3e3
9297
9507
  });
9298
- CadenzaService.debounce(
9299
- "meta.sync_controller.signal_registration_settled",
9300
- { __syncing: true },
9301
- 300
9302
- );
9303
9508
  return { signalName: ctx.__signal };
9304
- }).then(CadenzaService.signalBroker.registerSignalTask)
9509
+ }).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask)
9305
9510
  )
9306
9511
  );
9307
- CadenzaService.createUniqueMetaTask(
9308
- "Gather signal registration",
9309
- () => {
9310
- this.signalsSynced = true;
9311
- return true;
9312
- }
9313
- ).doOn("meta.sync_controller.signal_registration_settled").emits("meta.sync_controller.synced_signals");
9314
9512
  this.splitTasksForRegistration = CadenzaService.createMetaTask(
9315
9513
  "Split tasks for registration",
9316
9514
  function* (ctx) {
@@ -9325,6 +9523,7 @@ var GraphSyncController = class _GraphSyncController {
9325
9523
  for (const task of tasks) {
9326
9524
  if (task.registered) continue;
9327
9525
  const { __functionString, __getTagCallback } = task.export();
9526
+ this.tasksSynced = false;
9328
9527
  if (shouldDebugSyncTaskName(task.name)) {
9329
9528
  logSyncDebug("task_registration_split", {
9330
9529
  taskName: task.name,
@@ -9333,6 +9532,8 @@ var GraphSyncController = class _GraphSyncController {
9333
9532
  register: task.register,
9334
9533
  registered: task.registered,
9335
9534
  hidden: task.hidden,
9535
+ exportFunctionLength: __functionString?.length ?? null,
9536
+ exportTagGetterLength: __getTagCallback?.length ?? null,
9336
9537
  observedSignals: Array.from(task.observedSignals),
9337
9538
  handledIntents: Array.from(task.handlesIntents)
9338
9539
  });
@@ -9373,7 +9574,7 @@ var GraphSyncController = class _GraphSyncController {
9373
9574
  __taskName: task.name
9374
9575
  };
9375
9576
  }
9376
- }
9577
+ }.bind(this)
9377
9578
  );
9378
9579
  const registerTaskTask = resolveSyncInsertTask(
9379
9580
  this.isCadenzaDBReady,
@@ -9407,13 +9608,8 @@ var GraphSyncController = class _GraphSyncController {
9407
9608
  ...ctx,
9408
9609
  task: CadenzaService.get(ctx.__taskName)
9409
9610
  });
9410
- CadenzaService.debounce(
9411
- "meta.sync_controller.task_registration_settled",
9412
- { __syncing: true },
9413
- 300
9414
- );
9415
9611
  return true;
9416
- })
9612
+ }).then(gatherTaskRegistrationTask)
9417
9613
  );
9418
9614
  if (registerTaskTask) {
9419
9615
  this.splitTasksForRegistration.then(registerTaskTask);
@@ -9446,13 +9642,6 @@ var GraphSyncController = class _GraphSyncController {
9446
9642
  isHidden: true
9447
9643
  }
9448
9644
  ).doOn("meta.task.created").then(this.splitTasksForRegistration);
9449
- CadenzaService.createUniqueMetaTask(
9450
- "Gather task registration",
9451
- () => {
9452
- this.tasksSynced = true;
9453
- return true;
9454
- }
9455
- ).doOn("meta.sync_controller.task_registration_settled").emits("meta.sync_controller.synced_tasks");
9456
9645
  this.splitActorsForRegistration = CadenzaService.createMetaTask(
9457
9646
  "Split actors for registration",
9458
9647
  function* (ctx) {
@@ -9476,6 +9665,7 @@ var GraphSyncController = class _GraphSyncController {
9476
9665
  if (this.registeredActors.has(registrationKey)) {
9477
9666
  continue;
9478
9667
  }
9668
+ this.actorsSynced = false;
9479
9669
  yield {
9480
9670
  data,
9481
9671
  __actorRegistrationKey: registrationKey
@@ -9504,22 +9694,10 @@ var GraphSyncController = class _GraphSyncController {
9504
9694
  delayMs: 3e3
9505
9695
  });
9506
9696
  this.registeredActors.add(ctx.__actorRegistrationKey);
9507
- CadenzaService.debounce(
9508
- "meta.sync_controller.actor_registration_settled",
9509
- { __syncing: true },
9510
- 300
9511
- );
9512
9697
  return true;
9513
- })
9698
+ }).then(gatherActorRegistrationTask)
9514
9699
  )
9515
9700
  );
9516
- CadenzaService.createUniqueMetaTask(
9517
- "Gather actor registration",
9518
- () => {
9519
- this.actorsSynced = true;
9520
- return true;
9521
- }
9522
- ).doOn("meta.sync_controller.actor_registration_settled").emits("meta.sync_controller.synced_actors");
9523
9701
  this.registerActorTaskMapTask = CadenzaService.createMetaTask(
9524
9702
  "Split actor task maps",
9525
9703
  function* (ctx) {
@@ -9666,12 +9844,11 @@ var GraphSyncController = class _GraphSyncController {
9666
9844
  );
9667
9845
  this.splitIntentsTask = CadenzaService.createMetaTask(
9668
9846
  "Split intents for registration",
9669
- function(ctx, emit) {
9847
+ function* (ctx) {
9670
9848
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
9671
9849
  delayMs: 3e3
9672
9850
  });
9673
9851
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
9674
- let emittedCount = 0;
9675
9852
  for (const intent of intents) {
9676
9853
  const intentData = buildIntentRegistryData(intent);
9677
9854
  if (!intentData) {
@@ -9680,17 +9857,16 @@ var GraphSyncController = class _GraphSyncController {
9680
9857
  if (this.registeredIntentDefinitions.has(intentData.name)) {
9681
9858
  continue;
9682
9859
  }
9683
- emit("meta.sync_controller.intent_registration_split", {
9860
+ this.intentsSynced = false;
9861
+ yield {
9684
9862
  __syncing: ctx.__syncing,
9685
9863
  data: intentData,
9686
9864
  __intentName: intentData.name
9687
- });
9688
- emittedCount += 1;
9865
+ };
9689
9866
  }
9690
- return emittedCount > 0;
9691
9867
  }.bind(this)
9692
9868
  );
9693
- CadenzaService.createMetaTask("Process split intent registration", (ctx) => ctx).doOn("meta.sync_controller.intent_registration_split").then(
9869
+ this.splitIntentsTask.then(
9694
9870
  insertIntentRegistryTask?.then(
9695
9871
  CadenzaService.createMetaTask("Record intent definition registration", (ctx) => {
9696
9872
  if (!didSyncInsertSucceed(ctx)) {
@@ -9700,22 +9876,10 @@ var GraphSyncController = class _GraphSyncController {
9700
9876
  delayMs: 3e3
9701
9877
  });
9702
9878
  this.registeredIntentDefinitions.add(ctx.__intentName);
9703
- CadenzaService.debounce(
9704
- "meta.sync_controller.intent_registration_settled",
9705
- { __syncing: true },
9706
- 300
9707
- );
9708
9879
  return true;
9709
- })
9880
+ }).then(gatherIntentRegistrationTask)
9710
9881
  )
9711
9882
  );
9712
- CadenzaService.createUniqueMetaTask(
9713
- "Gather intent registration",
9714
- () => {
9715
- this.intentsSynced = true;
9716
- return true;
9717
- }
9718
- ).doOn("meta.sync_controller.intent_registration_settled").emits("meta.sync_controller.synced_intents");
9719
9883
  const registerIntentTask = CadenzaService.createMetaTask(
9720
9884
  "Record intent registration",
9721
9885
  (ctx) => {
@@ -10009,15 +10173,11 @@ var GraphSyncController = class _GraphSyncController {
10009
10173
  __authoritativeReconciliation: true
10010
10174
  });
10011
10175
  }
10012
- if (authoritativeTasks.length > 0) {
10013
- CadenzaService.debounce(
10014
- "meta.sync_controller.task_registration_settled",
10015
- {
10016
- __syncing: true,
10017
- __authoritativeReconciliation: true
10018
- },
10019
- 300
10020
- );
10176
+ if (authoritativeTasks.length > 0 || changed) {
10177
+ finalizeTaskSync(emit, {
10178
+ ...ctx,
10179
+ __authoritativeReconciliation: true
10180
+ });
10021
10181
  }
10022
10182
  return changed;
10023
10183
  },
@@ -10029,7 +10189,7 @@ var GraphSyncController = class _GraphSyncController {
10029
10189
  );
10030
10190
  const reconcileRoutineRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
10031
10191
  "Reconcile routine registration from authority",
10032
- (ctx) => {
10192
+ (ctx, emit) => {
10033
10193
  const authoritativeRoutines = resolveSyncQueryRows(ctx, "routine");
10034
10194
  let changed = false;
10035
10195
  for (const row of authoritativeRoutines) {
@@ -10044,15 +10204,11 @@ var GraphSyncController = class _GraphSyncController {
10044
10204
  routine.registered = true;
10045
10205
  changed = true;
10046
10206
  }
10047
- if (authoritativeRoutines.length > 0) {
10048
- CadenzaService.debounce(
10049
- "meta.sync_controller.routine_registration_settled",
10050
- {
10051
- __syncing: true,
10052
- __authoritativeReconciliation: true
10053
- },
10054
- 300
10055
- );
10207
+ if (authoritativeRoutines.length > 0 || changed) {
10208
+ finalizeRoutineSync(emit, {
10209
+ ...ctx,
10210
+ __authoritativeReconciliation: true
10211
+ });
10056
10212
  }
10057
10213
  return changed;
10058
10214
  },
@@ -10064,7 +10220,7 @@ var GraphSyncController = class _GraphSyncController {
10064
10220
  );
10065
10221
  const reconcileSignalRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
10066
10222
  "Reconcile signal registration from authority",
10067
- (ctx) => {
10223
+ (ctx, emit) => {
10068
10224
  const authoritativeSignals = resolveSyncQueryRows(ctx, "signal_registry");
10069
10225
  const signalObservers = CadenzaService.signalBroker.signalObservers;
10070
10226
  let changed = false;
@@ -10080,15 +10236,11 @@ var GraphSyncController = class _GraphSyncController {
10080
10236
  observer.registered = true;
10081
10237
  changed = true;
10082
10238
  }
10083
- if (authoritativeSignals.length > 0) {
10084
- CadenzaService.debounce(
10085
- "meta.sync_controller.signal_registration_settled",
10086
- {
10087
- __syncing: true,
10088
- __authoritativeReconciliation: true
10089
- },
10090
- 300
10091
- );
10239
+ if (authoritativeSignals.length > 0 || changed) {
10240
+ finalizeSignalSync(emit, {
10241
+ ...ctx,
10242
+ __authoritativeReconciliation: true
10243
+ });
10092
10244
  }
10093
10245
  return changed;
10094
10246
  },
@@ -10100,7 +10252,7 @@ var GraphSyncController = class _GraphSyncController {
10100
10252
  );
10101
10253
  const reconcileIntentRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
10102
10254
  "Reconcile intent registration from authority",
10103
- (ctx) => {
10255
+ (ctx, emit) => {
10104
10256
  const authoritativeIntents = resolveSyncQueryRows(ctx, "intent_registry");
10105
10257
  let changed = false;
10106
10258
  for (const row of authoritativeIntents) {
@@ -10114,15 +10266,11 @@ var GraphSyncController = class _GraphSyncController {
10114
10266
  this.registeredIntentDefinitions.add(intentName);
10115
10267
  changed = true;
10116
10268
  }
10117
- if (authoritativeIntents.length > 0) {
10118
- CadenzaService.debounce(
10119
- "meta.sync_controller.intent_registration_settled",
10120
- {
10121
- __syncing: true,
10122
- __authoritativeReconciliation: true
10123
- },
10124
- 300
10125
- );
10269
+ if (authoritativeIntents.length > 0 || changed) {
10270
+ finalizeIntentSync(emit, {
10271
+ ...ctx,
10272
+ __authoritativeReconciliation: true
10273
+ });
10126
10274
  }
10127
10275
  return changed;
10128
10276
  },