@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.
@@ -6299,6 +6299,17 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
6299
6299
  CadenzaService.createMetaTask(
6300
6300
  `Log prepared graph sync insert execution for ${tableName}`,
6301
6301
  (ctx) => {
6302
+ if (tableName === "task") {
6303
+ if (!shouldDebugTaskSyncPayload(ctx)) {
6304
+ return ctx;
6305
+ }
6306
+ logSyncDebug("insert_prepare", {
6307
+ tableName,
6308
+ targetTaskName: targetTask.name,
6309
+ payload: buildTaskSyncDebugPayload(ctx)
6310
+ });
6311
+ return ctx;
6312
+ }
6302
6313
  logSyncDebug("insert_prepare", {
6303
6314
  tableName,
6304
6315
  targetTaskName: targetTask.name,
@@ -6331,12 +6342,23 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
6331
6342
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
6332
6343
  };
6333
6344
  if (debugTable) {
6334
- logSyncDebug("insert_finalize", {
6335
- tableName,
6336
- targetTaskName: targetTask.name,
6337
- success: didSyncInsertSucceed(normalizedContext),
6338
- ctx: normalizedContext
6339
- });
6345
+ if (tableName === "task") {
6346
+ if (shouldDebugTaskSyncPayload(normalizedContext)) {
6347
+ logSyncDebug("insert_finalize", {
6348
+ tableName,
6349
+ targetTaskName: targetTask.name,
6350
+ success: didSyncInsertSucceed(normalizedContext),
6351
+ payload: buildTaskSyncDebugPayload(normalizedContext)
6352
+ });
6353
+ }
6354
+ } else {
6355
+ logSyncDebug("insert_finalize", {
6356
+ tableName,
6357
+ targetTaskName: targetTask.name,
6358
+ success: didSyncInsertSucceed(normalizedContext),
6359
+ ctx: normalizedContext
6360
+ });
6361
+ }
6340
6362
  }
6341
6363
  pendingResolverContexts.delete(ctx.__resolverRequestId);
6342
6364
  emit(executionResolvedSignal, normalizedContext);
@@ -6354,11 +6376,21 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
6354
6376
  CadenzaService.createMetaTask(
6355
6377
  `Log failed graph sync insert execution for ${tableName}`,
6356
6378
  (ctx) => {
6357
- logSyncDebug("insert_failed", {
6358
- tableName,
6359
- targetTaskName: targetTask.name,
6360
- ctx
6361
- });
6379
+ if (tableName === "task") {
6380
+ if (shouldDebugTaskSyncPayload(ctx)) {
6381
+ logSyncDebug("insert_failed", {
6382
+ tableName,
6383
+ targetTaskName: targetTask.name,
6384
+ payload: buildTaskSyncDebugPayload(ctx)
6385
+ });
6386
+ }
6387
+ } else {
6388
+ logSyncDebug("insert_failed", {
6389
+ tableName,
6390
+ targetTaskName: targetTask.name,
6391
+ ctx
6392
+ });
6393
+ }
6362
6394
  if (typeof ctx.__resolverRequestId === "string") {
6363
6395
  pendingResolverContexts.delete(ctx.__resolverRequestId);
6364
6396
  }
@@ -6524,6 +6556,37 @@ function summarizeSyncDebugValue(value, depth = 0) {
6524
6556
  function logSyncDebug(event, payload) {
6525
6557
  console.log(`${SYNC_DEBUG_PREFIX} ${event}`, summarizeSyncDebugValue(payload));
6526
6558
  }
6559
+ function buildTaskSyncDebugPayload(ctx) {
6560
+ const data = ctx.data && typeof ctx.data === "object" ? ctx.data : {};
6561
+ const queryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {};
6562
+ const queryDataData = queryData.data && typeof queryData.data === "object" ? queryData.data : {};
6563
+ const taskPayload = Object.keys(queryDataData).length > 0 ? queryDataData : data;
6564
+ const functionString = typeof taskPayload.functionString === "string" ? taskPayload.functionString : typeof taskPayload.function_string === "string" ? taskPayload.function_string : void 0;
6565
+ const tagIdGetter = typeof taskPayload.tagIdGetter === "string" ? taskPayload.tagIdGetter : typeof taskPayload.tag_id_getter === "string" ? taskPayload.tag_id_getter : void 0;
6566
+ const signals = taskPayload.signals && typeof taskPayload.signals === "object" ? taskPayload.signals : {};
6567
+ const intents = taskPayload.intents && typeof taskPayload.intents === "object" ? taskPayload.intents : {};
6568
+ return {
6569
+ taskName: taskPayload.name ?? taskPayload.taskName ?? taskPayload.task_name ?? ctx.__taskName ?? null,
6570
+ serviceName: taskPayload.service_name ?? taskPayload.serviceName ?? ctx.__syncServiceName ?? null,
6571
+ functionStringLength: functionString?.length ?? null,
6572
+ tagIdGetterLength: tagIdGetter?.length ?? null,
6573
+ isMeta: taskPayload.isMeta ?? taskPayload.is_meta ?? null,
6574
+ isSubMeta: taskPayload.isSubMeta ?? taskPayload.is_sub_meta ?? null,
6575
+ isHidden: taskPayload.isHidden ?? taskPayload.is_hidden ?? null,
6576
+ signalsEmitsCount: Array.isArray(signals.emits) ? signals.emits.length : null,
6577
+ signalsObservedCount: Array.isArray(signals.observed) ? signals.observed.length : null,
6578
+ intentHandlesCount: Array.isArray(intents.handles) ? intents.handles.length : null,
6579
+ intentInquiresCount: Array.isArray(intents.inquires) ? intents.inquires.length : null,
6580
+ rowCount: ctx.rowCount ?? null,
6581
+ errored: ctx.errored ?? false,
6582
+ success: ctx.__success ?? null,
6583
+ error: ctx.__error ?? null
6584
+ };
6585
+ }
6586
+ function shouldDebugTaskSyncPayload(ctx) {
6587
+ const payload = buildTaskSyncDebugPayload(ctx);
6588
+ return shouldDebugSyncTaskName(payload.taskName);
6589
+ }
6527
6590
  function resolveSyncQueryRows(ctx, tableName) {
6528
6591
  const resultKey = AUTHORITY_QUERY_RESULT_KEYS[tableName];
6529
6592
  const rows = ctx?.[resultKey];
@@ -6552,6 +6615,31 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
6552
6615
  }
6553
6616
  ).then(targetTask);
6554
6617
  }
6618
+ function getRegistrableTasks() {
6619
+ return Array.from(CadenzaService.registry.tasks.values()).filter(
6620
+ (task) => task.register && !task.isHidden
6621
+ );
6622
+ }
6623
+ function getRegistrableRoutines() {
6624
+ return Array.from(CadenzaService.registry.routines.values());
6625
+ }
6626
+ function getRegistrableSignalObservers() {
6627
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
6628
+ return signalObservers ? Array.from(signalObservers.values()) : [];
6629
+ }
6630
+ function getRegistrableIntentNames() {
6631
+ return Array.from(CadenzaService.inquiryBroker.intents.values()).map((intent) => buildIntentRegistryData(intent)).filter(
6632
+ (intentDefinition) => intentDefinition !== null
6633
+ ).map((intentDefinition) => String(intentDefinition.name));
6634
+ }
6635
+ function buildActorRegistrationKey(actor, serviceName) {
6636
+ const data = buildActorRegistrationData(actor);
6637
+ const name = typeof data.name === "string" && data.name.trim().length > 0 ? data.name.trim() : "";
6638
+ if (!name) {
6639
+ return null;
6640
+ }
6641
+ return `${name}|${data.version}|${serviceName}`;
6642
+ }
6555
6643
  var GraphSyncController = class _GraphSyncController {
6556
6644
  constructor() {
6557
6645
  this.registeredActors = /* @__PURE__ */ new Set();
@@ -6676,22 +6764,158 @@ var GraphSyncController = class _GraphSyncController {
6676
6764
  {},
6677
6765
  { concurrency: 10 }
6678
6766
  );
6767
+ const finalizeTaskSync = (emit, ctx) => {
6768
+ const pendingTasks = getRegistrableTasks().filter((task) => !task.registered);
6769
+ if (pendingTasks.length > 0) {
6770
+ this.tasksSynced = false;
6771
+ return false;
6772
+ }
6773
+ const shouldEmit = !this.tasksSynced;
6774
+ this.tasksSynced = true;
6775
+ if (shouldEmit) {
6776
+ emit("meta.sync_controller.synced_tasks", {
6777
+ __syncing: true,
6778
+ ...ctx
6779
+ });
6780
+ }
6781
+ return true;
6782
+ };
6783
+ const finalizeRoutineSync = (emit, ctx) => {
6784
+ const pendingRoutines = getRegistrableRoutines().filter(
6785
+ (routine) => !routine.registered
6786
+ );
6787
+ if (pendingRoutines.length > 0) {
6788
+ this.routinesSynced = false;
6789
+ return false;
6790
+ }
6791
+ const shouldEmit = !this.routinesSynced;
6792
+ this.routinesSynced = true;
6793
+ if (shouldEmit) {
6794
+ emit("meta.sync_controller.synced_routines", {
6795
+ __syncing: true,
6796
+ ...ctx
6797
+ });
6798
+ }
6799
+ return true;
6800
+ };
6801
+ const finalizeSignalSync = (emit, ctx) => {
6802
+ const pendingSignals = getRegistrableSignalObservers().filter(
6803
+ (observer) => observer?.registered !== true
6804
+ );
6805
+ if (pendingSignals.length > 0) {
6806
+ this.signalsSynced = false;
6807
+ return false;
6808
+ }
6809
+ const shouldEmit = !this.signalsSynced;
6810
+ this.signalsSynced = true;
6811
+ if (shouldEmit) {
6812
+ emit("meta.sync_controller.synced_signals", {
6813
+ __syncing: true,
6814
+ ...ctx
6815
+ });
6816
+ }
6817
+ return true;
6818
+ };
6819
+ const finalizeIntentSync = (emit, ctx) => {
6820
+ const pendingIntentNames = getRegistrableIntentNames().filter(
6821
+ (intentName) => !this.registeredIntentDefinitions.has(intentName)
6822
+ );
6823
+ if (pendingIntentNames.length > 0) {
6824
+ this.intentsSynced = false;
6825
+ return false;
6826
+ }
6827
+ const shouldEmit = !this.intentsSynced;
6828
+ this.intentsSynced = true;
6829
+ if (shouldEmit) {
6830
+ emit("meta.sync_controller.synced_intents", {
6831
+ __syncing: true,
6832
+ ...ctx
6833
+ });
6834
+ }
6835
+ return true;
6836
+ };
6837
+ const finalizeActorSync = (emit, ctx) => {
6838
+ const syncServiceName = resolveSyncServiceName();
6839
+ if (!syncServiceName) {
6840
+ this.actorsSynced = false;
6841
+ return false;
6842
+ }
6843
+ const pendingActorKeys = CadenzaService.getAllActors().map((actor) => buildActorRegistrationKey(actor, syncServiceName)).filter((registrationKey) => Boolean(registrationKey)).filter((registrationKey) => !this.registeredActors.has(registrationKey));
6844
+ if (pendingActorKeys.length > 0) {
6845
+ this.actorsSynced = false;
6846
+ return false;
6847
+ }
6848
+ const shouldEmit = !this.actorsSynced;
6849
+ this.actorsSynced = true;
6850
+ if (shouldEmit) {
6851
+ emit("meta.sync_controller.synced_actors", {
6852
+ __syncing: true,
6853
+ ...ctx
6854
+ });
6855
+ }
6856
+ return true;
6857
+ };
6858
+ const gatherTaskRegistrationTask = CadenzaService.createUniqueMetaTask(
6859
+ "Gather task registration",
6860
+ (ctx, emit) => finalizeTaskSync(emit, ctx),
6861
+ "Completes task registration when all registrable tasks are marked registered.",
6862
+ {
6863
+ register: false,
6864
+ isHidden: true
6865
+ }
6866
+ );
6867
+ const gatherRoutineRegistrationTask = CadenzaService.createUniqueMetaTask(
6868
+ "Gather routine registration",
6869
+ (ctx, emit) => finalizeRoutineSync(emit, ctx),
6870
+ "Completes routine registration when all registrable routines are marked registered.",
6871
+ {
6872
+ register: false,
6873
+ isHidden: true
6874
+ }
6875
+ );
6876
+ const gatherSignalRegistrationTask = CadenzaService.createUniqueMetaTask(
6877
+ "Gather signal registration",
6878
+ (ctx, emit) => finalizeSignalSync(emit, ctx),
6879
+ "Completes signal registration when all signal observers are marked registered.",
6880
+ {
6881
+ register: false,
6882
+ isHidden: true
6883
+ }
6884
+ );
6885
+ const gatherIntentRegistrationTask = CadenzaService.createUniqueMetaTask(
6886
+ "Gather intent registration",
6887
+ (ctx, emit) => finalizeIntentSync(emit, ctx),
6888
+ "Completes intent registration when all registrable intents are marked registered.",
6889
+ {
6890
+ register: false,
6891
+ isHidden: true
6892
+ }
6893
+ );
6894
+ const gatherActorRegistrationTask = CadenzaService.createUniqueMetaTask(
6895
+ "Gather actor registration",
6896
+ (ctx, emit) => finalizeActorSync(emit, ctx),
6897
+ "Completes actor registration when all registrable actors are marked registered.",
6898
+ {
6899
+ register: false,
6900
+ isHidden: true
6901
+ }
6902
+ );
6679
6903
  this.splitRoutinesTask = CadenzaService.createMetaTask(
6680
6904
  "Split routines for registration",
6681
- (ctx, emit) => {
6905
+ function* (ctx) {
6682
6906
  const { routines } = ctx;
6683
- if (!routines) return false;
6907
+ if (!routines) return;
6684
6908
  const serviceName2 = resolveSyncServiceName();
6685
6909
  if (!serviceName2) {
6686
- return false;
6910
+ return;
6687
6911
  }
6688
6912
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
6689
6913
  delayMs: 2e3
6690
6914
  });
6691
- let emittedCount = 0;
6692
6915
  for (const routine of routines) {
6693
6916
  if (routine.registered) continue;
6694
- emit("meta.sync_controller.routine_registration_split", {
6917
+ this.routinesSynced = false;
6918
+ yield {
6695
6919
  __syncing: ctx.__syncing,
6696
6920
  data: {
6697
6921
  name: routine.name,
@@ -6701,13 +6925,11 @@ var GraphSyncController = class _GraphSyncController {
6701
6925
  isMeta: routine.isMeta
6702
6926
  },
6703
6927
  __routineName: routine.name
6704
- });
6705
- emittedCount += 1;
6928
+ };
6706
6929
  }
6707
- return emittedCount > 0;
6708
- }
6930
+ }.bind(this)
6709
6931
  );
6710
- CadenzaService.createMetaTask("Process split routine registration", (ctx) => ctx).doOn("meta.sync_controller.routine_registration_split").then(
6932
+ this.splitRoutinesTask.then(
6711
6933
  resolveSyncInsertTask(
6712
6934
  this.isCadenzaDBReady,
6713
6935
  "routine",
@@ -6729,22 +6951,10 @@ var GraphSyncController = class _GraphSyncController {
6729
6951
  delayMs: 3e3
6730
6952
  });
6731
6953
  CadenzaService.getRoutine(ctx.__routineName).registered = true;
6732
- CadenzaService.debounce(
6733
- "meta.sync_controller.routine_registration_settled",
6734
- { __syncing: true },
6735
- 300
6736
- );
6737
6954
  return true;
6738
- })
6955
+ }).then(gatherRoutineRegistrationTask)
6739
6956
  )
6740
6957
  );
6741
- CadenzaService.createUniqueMetaTask(
6742
- "Gather routine registration",
6743
- () => {
6744
- this.routinesSynced = true;
6745
- return true;
6746
- }
6747
- ).doOn("meta.sync_controller.routine_registration_settled").emits("meta.sync_controller.synced_routines");
6748
6958
  this.splitTasksInRoutines = CadenzaService.createMetaTask(
6749
6959
  "Split tasks in routines",
6750
6960
  function* (ctx) {
@@ -6833,18 +7043,19 @@ var GraphSyncController = class _GraphSyncController {
6833
7043
  }
6834
7044
  this.splitSignalsTask = CadenzaService.createMetaTask(
6835
7045
  "Split signals for registration",
6836
- (ctx, emit) => {
7046
+ function* (ctx) {
6837
7047
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
6838
7048
  delayMs: 3e3
6839
7049
  });
6840
7050
  const { signals } = ctx;
6841
- if (!signals) return false;
7051
+ if (!signals) return;
6842
7052
  const filteredSignals = signals.filter(
6843
7053
  (signal) => !signal.data.registered
6844
7054
  ).map((signal) => signal.signal);
6845
7055
  for (const signal of filteredSignals) {
6846
7056
  const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
6847
- emit("meta.sync_controller.signal_registration_split", {
7057
+ this.signalsSynced = false;
7058
+ yield {
6848
7059
  __syncing: ctx.__syncing,
6849
7060
  data: {
6850
7061
  name: signal,
@@ -6854,12 +7065,11 @@ var GraphSyncController = class _GraphSyncController {
6854
7065
  isMeta
6855
7066
  },
6856
7067
  __signal: signal
6857
- });
7068
+ };
6858
7069
  }
6859
- return filteredSignals.length > 0;
6860
- }
7070
+ }.bind(this)
6861
7071
  );
6862
- CadenzaService.createMetaTask("Process split signal registration", (ctx) => ctx).doOn("meta.sync_controller.signal_registration_split").then(
7072
+ this.splitSignalsTask.then(
6863
7073
  resolveSyncInsertTask(
6864
7074
  this.isCadenzaDBReady,
6865
7075
  "signal_registry",
@@ -6880,22 +7090,10 @@ var GraphSyncController = class _GraphSyncController {
6880
7090
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
6881
7091
  delayMs: 3e3
6882
7092
  });
6883
- CadenzaService.debounce(
6884
- "meta.sync_controller.signal_registration_settled",
6885
- { __syncing: true },
6886
- 300
6887
- );
6888
7093
  return { signalName: ctx.__signal };
6889
- }).then(CadenzaService.signalBroker.registerSignalTask)
7094
+ }).then(CadenzaService.signalBroker.registerSignalTask).then(gatherSignalRegistrationTask)
6890
7095
  )
6891
7096
  );
6892
- CadenzaService.createUniqueMetaTask(
6893
- "Gather signal registration",
6894
- () => {
6895
- this.signalsSynced = true;
6896
- return true;
6897
- }
6898
- ).doOn("meta.sync_controller.signal_registration_settled").emits("meta.sync_controller.synced_signals");
6899
7097
  this.splitTasksForRegistration = CadenzaService.createMetaTask(
6900
7098
  "Split tasks for registration",
6901
7099
  function* (ctx) {
@@ -6910,6 +7108,7 @@ var GraphSyncController = class _GraphSyncController {
6910
7108
  for (const task of tasks) {
6911
7109
  if (task.registered) continue;
6912
7110
  const { __functionString, __getTagCallback } = task.export();
7111
+ this.tasksSynced = false;
6913
7112
  if (shouldDebugSyncTaskName(task.name)) {
6914
7113
  logSyncDebug("task_registration_split", {
6915
7114
  taskName: task.name,
@@ -6918,6 +7117,8 @@ var GraphSyncController = class _GraphSyncController {
6918
7117
  register: task.register,
6919
7118
  registered: task.registered,
6920
7119
  hidden: task.hidden,
7120
+ exportFunctionLength: __functionString?.length ?? null,
7121
+ exportTagGetterLength: __getTagCallback?.length ?? null,
6921
7122
  observedSignals: Array.from(task.observedSignals),
6922
7123
  handledIntents: Array.from(task.handlesIntents)
6923
7124
  });
@@ -6958,7 +7159,7 @@ var GraphSyncController = class _GraphSyncController {
6958
7159
  __taskName: task.name
6959
7160
  };
6960
7161
  }
6961
- }
7162
+ }.bind(this)
6962
7163
  );
6963
7164
  const registerTaskTask = resolveSyncInsertTask(
6964
7165
  this.isCadenzaDBReady,
@@ -6992,13 +7193,8 @@ var GraphSyncController = class _GraphSyncController {
6992
7193
  ...ctx,
6993
7194
  task: CadenzaService.get(ctx.__taskName)
6994
7195
  });
6995
- CadenzaService.debounce(
6996
- "meta.sync_controller.task_registration_settled",
6997
- { __syncing: true },
6998
- 300
6999
- );
7000
7196
  return true;
7001
- })
7197
+ }).then(gatherTaskRegistrationTask)
7002
7198
  );
7003
7199
  if (registerTaskTask) {
7004
7200
  this.splitTasksForRegistration.then(registerTaskTask);
@@ -7031,13 +7227,6 @@ var GraphSyncController = class _GraphSyncController {
7031
7227
  isHidden: true
7032
7228
  }
7033
7229
  ).doOn("meta.task.created").then(this.splitTasksForRegistration);
7034
- CadenzaService.createUniqueMetaTask(
7035
- "Gather task registration",
7036
- () => {
7037
- this.tasksSynced = true;
7038
- return true;
7039
- }
7040
- ).doOn("meta.sync_controller.task_registration_settled").emits("meta.sync_controller.synced_tasks");
7041
7230
  this.splitActorsForRegistration = CadenzaService.createMetaTask(
7042
7231
  "Split actors for registration",
7043
7232
  function* (ctx) {
@@ -7061,6 +7250,7 @@ var GraphSyncController = class _GraphSyncController {
7061
7250
  if (this.registeredActors.has(registrationKey)) {
7062
7251
  continue;
7063
7252
  }
7253
+ this.actorsSynced = false;
7064
7254
  yield {
7065
7255
  data,
7066
7256
  __actorRegistrationKey: registrationKey
@@ -7089,22 +7279,10 @@ var GraphSyncController = class _GraphSyncController {
7089
7279
  delayMs: 3e3
7090
7280
  });
7091
7281
  this.registeredActors.add(ctx.__actorRegistrationKey);
7092
- CadenzaService.debounce(
7093
- "meta.sync_controller.actor_registration_settled",
7094
- { __syncing: true },
7095
- 300
7096
- );
7097
7282
  return true;
7098
- })
7283
+ }).then(gatherActorRegistrationTask)
7099
7284
  )
7100
7285
  );
7101
- CadenzaService.createUniqueMetaTask(
7102
- "Gather actor registration",
7103
- () => {
7104
- this.actorsSynced = true;
7105
- return true;
7106
- }
7107
- ).doOn("meta.sync_controller.actor_registration_settled").emits("meta.sync_controller.synced_actors");
7108
7286
  this.registerActorTaskMapTask = CadenzaService.createMetaTask(
7109
7287
  "Split actor task maps",
7110
7288
  function* (ctx) {
@@ -7251,12 +7429,11 @@ var GraphSyncController = class _GraphSyncController {
7251
7429
  );
7252
7430
  this.splitIntentsTask = CadenzaService.createMetaTask(
7253
7431
  "Split intents for registration",
7254
- function(ctx, emit) {
7432
+ function* (ctx) {
7255
7433
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
7256
7434
  delayMs: 3e3
7257
7435
  });
7258
7436
  const intents = Array.isArray(ctx.intents) ? ctx.intents : Array.from(CadenzaService.inquiryBroker.intents.values());
7259
- let emittedCount = 0;
7260
7437
  for (const intent of intents) {
7261
7438
  const intentData = buildIntentRegistryData(intent);
7262
7439
  if (!intentData) {
@@ -7265,17 +7442,16 @@ var GraphSyncController = class _GraphSyncController {
7265
7442
  if (this.registeredIntentDefinitions.has(intentData.name)) {
7266
7443
  continue;
7267
7444
  }
7268
- emit("meta.sync_controller.intent_registration_split", {
7445
+ this.intentsSynced = false;
7446
+ yield {
7269
7447
  __syncing: ctx.__syncing,
7270
7448
  data: intentData,
7271
7449
  __intentName: intentData.name
7272
- });
7273
- emittedCount += 1;
7450
+ };
7274
7451
  }
7275
- return emittedCount > 0;
7276
7452
  }.bind(this)
7277
7453
  );
7278
- CadenzaService.createMetaTask("Process split intent registration", (ctx) => ctx).doOn("meta.sync_controller.intent_registration_split").then(
7454
+ this.splitIntentsTask.then(
7279
7455
  insertIntentRegistryTask?.then(
7280
7456
  CadenzaService.createMetaTask("Record intent definition registration", (ctx) => {
7281
7457
  if (!didSyncInsertSucceed(ctx)) {
@@ -7285,22 +7461,10 @@ var GraphSyncController = class _GraphSyncController {
7285
7461
  delayMs: 3e3
7286
7462
  });
7287
7463
  this.registeredIntentDefinitions.add(ctx.__intentName);
7288
- CadenzaService.debounce(
7289
- "meta.sync_controller.intent_registration_settled",
7290
- { __syncing: true },
7291
- 300
7292
- );
7293
7464
  return true;
7294
- })
7465
+ }).then(gatherIntentRegistrationTask)
7295
7466
  )
7296
7467
  );
7297
- CadenzaService.createUniqueMetaTask(
7298
- "Gather intent registration",
7299
- () => {
7300
- this.intentsSynced = true;
7301
- return true;
7302
- }
7303
- ).doOn("meta.sync_controller.intent_registration_settled").emits("meta.sync_controller.synced_intents");
7304
7468
  const registerIntentTask = CadenzaService.createMetaTask(
7305
7469
  "Record intent registration",
7306
7470
  (ctx) => {
@@ -7594,15 +7758,11 @@ var GraphSyncController = class _GraphSyncController {
7594
7758
  __authoritativeReconciliation: true
7595
7759
  });
7596
7760
  }
7597
- if (authoritativeTasks.length > 0) {
7598
- CadenzaService.debounce(
7599
- "meta.sync_controller.task_registration_settled",
7600
- {
7601
- __syncing: true,
7602
- __authoritativeReconciliation: true
7603
- },
7604
- 300
7605
- );
7761
+ if (authoritativeTasks.length > 0 || changed) {
7762
+ finalizeTaskSync(emit, {
7763
+ ...ctx,
7764
+ __authoritativeReconciliation: true
7765
+ });
7606
7766
  }
7607
7767
  return changed;
7608
7768
  },
@@ -7614,7 +7774,7 @@ var GraphSyncController = class _GraphSyncController {
7614
7774
  );
7615
7775
  const reconcileRoutineRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
7616
7776
  "Reconcile routine registration from authority",
7617
- (ctx) => {
7777
+ (ctx, emit) => {
7618
7778
  const authoritativeRoutines = resolveSyncQueryRows(ctx, "routine");
7619
7779
  let changed = false;
7620
7780
  for (const row of authoritativeRoutines) {
@@ -7629,15 +7789,11 @@ var GraphSyncController = class _GraphSyncController {
7629
7789
  routine.registered = true;
7630
7790
  changed = true;
7631
7791
  }
7632
- if (authoritativeRoutines.length > 0) {
7633
- CadenzaService.debounce(
7634
- "meta.sync_controller.routine_registration_settled",
7635
- {
7636
- __syncing: true,
7637
- __authoritativeReconciliation: true
7638
- },
7639
- 300
7640
- );
7792
+ if (authoritativeRoutines.length > 0 || changed) {
7793
+ finalizeRoutineSync(emit, {
7794
+ ...ctx,
7795
+ __authoritativeReconciliation: true
7796
+ });
7641
7797
  }
7642
7798
  return changed;
7643
7799
  },
@@ -7649,7 +7805,7 @@ var GraphSyncController = class _GraphSyncController {
7649
7805
  );
7650
7806
  const reconcileSignalRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
7651
7807
  "Reconcile signal registration from authority",
7652
- (ctx) => {
7808
+ (ctx, emit) => {
7653
7809
  const authoritativeSignals = resolveSyncQueryRows(ctx, "signal_registry");
7654
7810
  const signalObservers = CadenzaService.signalBroker.signalObservers;
7655
7811
  let changed = false;
@@ -7665,15 +7821,11 @@ var GraphSyncController = class _GraphSyncController {
7665
7821
  observer.registered = true;
7666
7822
  changed = true;
7667
7823
  }
7668
- if (authoritativeSignals.length > 0) {
7669
- CadenzaService.debounce(
7670
- "meta.sync_controller.signal_registration_settled",
7671
- {
7672
- __syncing: true,
7673
- __authoritativeReconciliation: true
7674
- },
7675
- 300
7676
- );
7824
+ if (authoritativeSignals.length > 0 || changed) {
7825
+ finalizeSignalSync(emit, {
7826
+ ...ctx,
7827
+ __authoritativeReconciliation: true
7828
+ });
7677
7829
  }
7678
7830
  return changed;
7679
7831
  },
@@ -7685,7 +7837,7 @@ var GraphSyncController = class _GraphSyncController {
7685
7837
  );
7686
7838
  const reconcileIntentRegistrationFromAuthorityTask = CadenzaService.createMetaTask(
7687
7839
  "Reconcile intent registration from authority",
7688
- (ctx) => {
7840
+ (ctx, emit) => {
7689
7841
  const authoritativeIntents = resolveSyncQueryRows(ctx, "intent_registry");
7690
7842
  let changed = false;
7691
7843
  for (const row of authoritativeIntents) {
@@ -7699,15 +7851,11 @@ var GraphSyncController = class _GraphSyncController {
7699
7851
  this.registeredIntentDefinitions.add(intentName);
7700
7852
  changed = true;
7701
7853
  }
7702
- if (authoritativeIntents.length > 0) {
7703
- CadenzaService.debounce(
7704
- "meta.sync_controller.intent_registration_settled",
7705
- {
7706
- __syncing: true,
7707
- __authoritativeReconciliation: true
7708
- },
7709
- 300
7710
- );
7854
+ if (authoritativeIntents.length > 0 || changed) {
7855
+ finalizeIntentSync(emit, {
7856
+ ...ctx,
7857
+ __authoritativeReconciliation: true
7858
+ });
7711
7859
  }
7712
7860
  return changed;
7713
7861
  },