@cadenza.io/service 2.21.0 → 2.21.1

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.
@@ -46,8 +46,10 @@ __export(src_exports, {
46
46
  DeputyTask: () => DeputyTask,
47
47
  EXECUTION_PERSISTENCE_BUNDLE_SIGNAL: () => EXECUTION_PERSISTENCE_BUNDLE_SIGNAL,
48
48
  EphemeralTask: () => import_core7.EphemeralTask,
49
+ GlobalDefinition: () => import_core7.GlobalDefinition,
49
50
  GraphMetadataController: () => GraphMetadataController,
50
51
  GraphRoutine: () => import_core7.GraphRoutine,
52
+ HelperDefinition: () => import_core7.HelperDefinition,
51
53
  RUNTIME_STATUS_AUTHORITY_SYNC_REQUESTED_SIGNAL: () => RUNTIME_STATUS_AUTHORITY_SYNC_REQUESTED_SIGNAL,
52
54
  RUNTIME_VALIDATION_INTENTS: () => RUNTIME_VALIDATION_INTENTS,
53
55
  RUNTIME_VALIDATION_SIGNALS: () => RUNTIME_VALIDATION_SIGNALS,
@@ -67,6 +69,10 @@ __export(src_exports, {
67
69
  createCadenzaService: () => createCadenzaService,
68
70
  createDatabaseService: () => createDatabaseService,
69
71
  createExecutionPersistenceBundle: () => createExecutionPersistenceBundle,
72
+ createGlobal: () => createGlobal,
73
+ createHelper: () => createHelper,
74
+ createMetaGlobal: () => createMetaGlobal,
75
+ createMetaHelper: () => createMetaHelper,
70
76
  createMetaTask: () => createMetaTask,
71
77
  createSSRInquiryBridge: () => createSSRInquiryBridge,
72
78
  createTask: () => createTask,
@@ -429,6 +435,12 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
429
435
  return;
430
436
  }
431
437
  const processId = (0, import_uuid2.v4)();
438
+ const resolvedTimeoutMs = Math.max(
439
+ 1e3,
440
+ Number(context.__timeout ?? task.timeout ?? 0) || 6e4
441
+ );
442
+ let settled = false;
443
+ let timeoutHandle = null;
432
444
  context.__metadata.__deputyExecId = processId;
433
445
  if ((process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") && context.__remoteRoutineName === "Insert service_instance") {
434
446
  console.log("[CADENZA_INSTANCE_DEBUG] deputy_delegation_requested", {
@@ -445,7 +457,37 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
445
457
  emit2("meta.deputy.delegation_requested", {
446
458
  ...context
447
459
  });
448
- CadenzaService.createEphemeralMetaTask(
460
+ let progressTask = null;
461
+ let resolveTask = null;
462
+ const cleanup = () => {
463
+ if (timeoutHandle) {
464
+ clearTimeout(timeoutHandle);
465
+ timeoutHandle = null;
466
+ }
467
+ if (progressTask && !progressTask.destroyed) {
468
+ progressTask.destroy();
469
+ }
470
+ if (resolveTask && !resolveTask.destroyed) {
471
+ resolveTask.destroy();
472
+ }
473
+ };
474
+ const settleSuccess = (value) => {
475
+ if (settled) {
476
+ return;
477
+ }
478
+ settled = true;
479
+ cleanup();
480
+ resolve(value);
481
+ };
482
+ const settleFailure = (error) => {
483
+ if (settled) {
484
+ return;
485
+ }
486
+ settled = true;
487
+ cleanup();
488
+ reject(error instanceof Error ? error : new Error(String(error)));
489
+ };
490
+ progressTask = CadenzaService.createEphemeralMetaTask(
449
491
  `On progress deputy ${task.remoteRoutineName}`,
450
492
  (ctx) => {
451
493
  if (typeof progressCallback === "function" && ctx.progress) {
@@ -464,7 +506,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
464
506
  `meta.fetch.delegated:${processId}`,
465
507
  `meta.service_registry.load_balance_failed:${processId}`
466
508
  );
467
- CadenzaService.createEphemeralMetaTask(
509
+ resolveTask = CadenzaService.createEphemeralMetaTask(
468
510
  `Resolve deputy ${task.remoteRoutineName}`,
469
511
  (responseCtx) => {
470
512
  const mergedResponseCtx = responseCtx && typeof responseCtx === "object" ? {
@@ -472,7 +514,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
472
514
  ...responseCtx
473
515
  } : responseCtx;
474
516
  if (responseCtx?.errored) {
475
- reject(new Error(responseCtx.__error));
517
+ settleFailure(new Error(responseCtx.__error));
476
518
  } else {
477
519
  if (SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && CadenzaService.serviceRegistry.serviceName === SERVICE_REGISTRY_TRACE_SERVICE && context.__remoteRoutineName === "Insert service_instance") {
478
520
  console.log(
@@ -489,7 +531,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
489
531
  if (mergedResponseCtx && typeof mergedResponseCtx === "object") {
490
532
  delete mergedResponseCtx.__isDeputy;
491
533
  }
492
- resolve(mergedResponseCtx);
534
+ settleSuccess(mergedResponseCtx);
493
535
  }
494
536
  },
495
537
  `Ephemeral resolver for deputy process ${processId}`,
@@ -499,6 +541,14 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
499
541
  `meta.fetch.delegated:${processId}`,
500
542
  `meta.service_registry.load_balance_failed:${processId}`
501
543
  );
544
+ timeoutHandle = setTimeout(() => {
545
+ settleFailure(
546
+ new Error(
547
+ `Deputy task '${task.name}' timed out waiting for remote resolution after ${resolvedTimeoutMs}ms.`
548
+ )
549
+ );
550
+ }, resolvedTimeoutMs);
551
+ timeoutHandle.unref?.();
502
552
  });
503
553
  }
504
554
  var DeputyTask = class extends import_core.Task {
@@ -644,6 +694,21 @@ var EXECUTION_OBSERVABILITY_INSERT_ROUTINES = /* @__PURE__ */ new Set([
644
694
  "Insert task_execution",
645
695
  "Insert inquiry"
646
696
  ]);
697
+ var ROOT_DB_OPERATION_CONTEXT_KEYS = [
698
+ "data",
699
+ "batch",
700
+ "transaction",
701
+ "onConflict",
702
+ "filter",
703
+ "fields",
704
+ "joins",
705
+ "sort",
706
+ "limit",
707
+ "offset",
708
+ "queryMode",
709
+ "aggregates",
710
+ "groupBy"
711
+ ];
647
712
  var DatabaseTask = class extends DeputyTask {
648
713
  /**
649
714
  * Constructs an instance of the class with the provided parameters, defining
@@ -752,6 +817,27 @@ var DatabaseTask = class extends DeputyTask {
752
817
  if (dynamicQueryData.data === void 0 && ctx.data !== void 0) {
753
818
  nextQueryData.data = ctx.data && typeof ctx.data === "object" && !Array.isArray(ctx.data) ? { ...ctx.data } : ctx.data;
754
819
  }
820
+ const shouldCompactAuthorityBootstrapContext = this.serviceName === "CadenzaDB" && (ctx.__authorityBootstrapChannel === true || metadata.__authorityBootstrapChannel === true || ctx.__metadata?.__authorityBootstrapChannel === true);
821
+ const rootDbOperationContext = shouldCompactAuthorityBootstrapContext ? {} : {
822
+ data: nextQueryData.data ?? ctx.data,
823
+ batch: nextQueryData.batch ?? ctx.batch,
824
+ transaction: nextQueryData.transaction ?? ctx.transaction,
825
+ onConflict: Object.prototype.hasOwnProperty.call(nextQueryData, "onConflict") ? nextQueryData.onConflict : void 0,
826
+ filter: nextQueryData.filter ?? ctx.filter,
827
+ fields: nextQueryData.fields ?? ctx.fields,
828
+ joins: nextQueryData.joins ?? ctx.joins,
829
+ sort: nextQueryData.sort ?? ctx.sort,
830
+ limit: nextQueryData.limit ?? ctx.limit,
831
+ offset: nextQueryData.offset ?? ctx.offset,
832
+ queryMode: nextQueryData.queryMode ?? ctx.queryMode,
833
+ aggregates: nextQueryData.aggregates ?? ctx.aggregates,
834
+ groupBy: nextQueryData.groupBy ?? ctx.groupBy
835
+ };
836
+ if (shouldCompactAuthorityBootstrapContext) {
837
+ for (const key of ROOT_DB_OPERATION_CONTEXT_KEYS) {
838
+ delete ctx[key];
839
+ }
840
+ }
755
841
  const deputyContext = attachDelegationRequestSnapshot(
756
842
  stripDelegationRequestSnapshot(
757
843
  hoistDelegationMetadataFields({
@@ -771,12 +857,7 @@ var DatabaseTask = class extends DeputyTask {
771
857
  __blockRemoteExecution: metadata.__blockRemoteExecution ?? ctx.__blockRemoteExecution ?? false,
772
858
  __deputyTaskName: this.name
773
859
  },
774
- data: nextQueryData.data ?? ctx.data,
775
- batch: nextQueryData.batch ?? ctx.batch,
776
- transaction: nextQueryData.transaction ?? ctx.transaction,
777
- onConflict: Object.prototype.hasOwnProperty.call(nextQueryData, "onConflict") ? nextQueryData.onConflict : void 0,
778
- filter: nextQueryData.filter ?? ctx.filter,
779
- fields: nextQueryData.fields ?? ctx.fields,
860
+ ...rootDbOperationContext,
780
861
  queryData: nextQueryData
781
862
  })
782
863
  )
@@ -1941,6 +2022,163 @@ function getAuthorityBootstrapInsertIntentSpecForTable(tableName) {
1941
2022
  return getAuthorityBootstrapIntentSpec(intentName);
1942
2023
  }
1943
2024
 
2025
+ // src/execution/ExecutionPersistenceCoordinator.ts
2026
+ var EXECUTION_PERSISTENCE_BUNDLE_SIGNAL = "global.meta.execution_persistence.bundle_requested";
2027
+ function readString(value) {
2028
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
2029
+ }
2030
+ function readRecord(value) {
2031
+ return value && typeof value === "object" && !Array.isArray(value) ? { ...value } : null;
2032
+ }
2033
+ function normalizeRoutineExecutionTraceFields(data) {
2034
+ if (!data) {
2035
+ return null;
2036
+ }
2037
+ const normalizedData = { ...data };
2038
+ const traceId = readString(
2039
+ normalizedData.execution_trace_id ?? normalizedData.executionTraceId
2040
+ );
2041
+ const metaContext = readRecord(normalizedData.meta_context) ?? readRecord(normalizedData.metaContext);
2042
+ const isMeta = normalizedData.is_meta === true || normalizedData.isMeta === true;
2043
+ const serviceName = readString(
2044
+ normalizedData.service_name ?? normalizedData.serviceName
2045
+ );
2046
+ const serviceInstanceId = readString(
2047
+ normalizedData.service_instance_id ?? normalizedData.serviceInstanceId
2048
+ );
2049
+ if (traceId) {
2050
+ normalizedData.execution_trace_id = traceId;
2051
+ }
2052
+ if (metaContext) {
2053
+ normalizedData.meta_context = metaContext;
2054
+ }
2055
+ if (normalizedData.is_meta !== void 0 || normalizedData.isMeta !== void 0) {
2056
+ normalizedData.is_meta = isMeta;
2057
+ }
2058
+ if (serviceName) {
2059
+ normalizedData.service_name = serviceName;
2060
+ }
2061
+ if (serviceInstanceId) {
2062
+ normalizedData.service_instance_id = serviceInstanceId;
2063
+ } else if (normalizedData.serviceInstanceId === null || normalizedData.service_instance_id === null) {
2064
+ normalizedData.service_instance_id = null;
2065
+ }
2066
+ delete normalizedData.executionTraceId;
2067
+ delete normalizedData.traceId;
2068
+ delete normalizedData.metaContext;
2069
+ delete normalizedData.isMeta;
2070
+ delete normalizedData.serviceName;
2071
+ delete normalizedData.serviceInstanceId;
2072
+ return normalizedData;
2073
+ }
2074
+ function stripExecutionTraceServiceInstanceFields(data) {
2075
+ if (!data) {
2076
+ return null;
2077
+ }
2078
+ const normalizedData = { ...data };
2079
+ delete normalizedData.serviceInstanceId;
2080
+ delete normalizedData.service_instance_id;
2081
+ return normalizedData;
2082
+ }
2083
+ function normalizeEnsureData(entityType, data) {
2084
+ switch (entityType) {
2085
+ case "execution_trace":
2086
+ return stripExecutionTraceServiceInstanceFields(data);
2087
+ case "routine_execution":
2088
+ return normalizeRoutineExecutionTraceFields(data);
2089
+ default:
2090
+ return data;
2091
+ }
2092
+ }
2093
+ function buildExecutionPersistenceDependency(entityType, entityId) {
2094
+ const normalizedEntityId = readString(entityId);
2095
+ return normalizedEntityId ? `${entityType}:${normalizedEntityId}` : null;
2096
+ }
2097
+ function resolveEnsureEntityId(entityType, data) {
2098
+ switch (entityType) {
2099
+ default:
2100
+ return readString(data.uuid);
2101
+ }
2102
+ }
2103
+ function resolveUpdateEntityId(_entityType, data, filter) {
2104
+ return readString(
2105
+ filter.uuid ?? filter.taskExecutionId ?? filter.task_execution_id ?? data.uuid ?? data.taskExecutionId ?? data.task_execution_id
2106
+ );
2107
+ }
2108
+ function dedupeDependencies(values) {
2109
+ return Array.from(
2110
+ new Set(values.filter((value) => typeof value === "string"))
2111
+ );
2112
+ }
2113
+ function resolveTraceIdFromData(data) {
2114
+ if (!data) {
2115
+ return null;
2116
+ }
2117
+ return readString(
2118
+ data.traceId ?? data.executionTraceId ?? data.execution_trace_id ?? data.metaContext?.__executionTraceId ?? data.metaContext?.__metadata?.__executionTraceId ?? data.meta_context?.__executionTraceId ?? data.meta_context?.__metadata?.__executionTraceId
2119
+ );
2120
+ }
2121
+ function buildExecutionPersistenceEnsureEvent(entityType, data, deps = []) {
2122
+ const normalizedData = normalizeEnsureData(entityType, readRecord(data));
2123
+ if (!normalizedData) {
2124
+ return null;
2125
+ }
2126
+ const entityId = resolveEnsureEntityId(entityType, normalizedData);
2127
+ if (!entityId) {
2128
+ return null;
2129
+ }
2130
+ return {
2131
+ kind: "ensure",
2132
+ entityType,
2133
+ entityId,
2134
+ data: normalizedData,
2135
+ deps: dedupeDependencies(deps)
2136
+ };
2137
+ }
2138
+ function buildExecutionPersistenceUpdateEvent(entityType, data, filter, deps = []) {
2139
+ const normalizedData = readRecord(data);
2140
+ const normalizedFilter = readRecord(filter);
2141
+ if (!normalizedData || !normalizedFilter) {
2142
+ return null;
2143
+ }
2144
+ const entityId = resolveUpdateEntityId(
2145
+ entityType,
2146
+ normalizedData,
2147
+ normalizedFilter
2148
+ );
2149
+ if (!entityId) {
2150
+ return null;
2151
+ }
2152
+ return {
2153
+ kind: "update",
2154
+ entityType,
2155
+ entityId,
2156
+ data: normalizedData,
2157
+ filter: normalizedFilter,
2158
+ deps: dedupeDependencies(deps)
2159
+ };
2160
+ }
2161
+ function createExecutionPersistenceBundle(input) {
2162
+ const ensures = (input.ensures ?? []).filter(
2163
+ (event) => Boolean(event)
2164
+ );
2165
+ const updates = (input.updates ?? []).filter(
2166
+ (event) => Boolean(event)
2167
+ );
2168
+ if (ensures.length === 0 && updates.length === 0) {
2169
+ return null;
2170
+ }
2171
+ const traceId = readString(input.traceId) ?? ensures.map((event) => resolveTraceIdFromData(event.data)).find((value) => Boolean(value)) ?? updates.map((event) => resolveTraceIdFromData(event.data)).find((value) => Boolean(value));
2172
+ if (!traceId) {
2173
+ return null;
2174
+ }
2175
+ return {
2176
+ traceId,
2177
+ ensures,
2178
+ updates
2179
+ };
2180
+ }
2181
+
1944
2182
  // src/utils/tools.ts
1945
2183
  function formatTimestamp(timestamp) {
1946
2184
  return new Date(timestamp).toISOString();
@@ -2171,12 +2409,24 @@ function listManifestGlobals() {
2171
2409
  (globalDefinition) => Boolean(globalDefinition && !globalDefinition.destroyed)
2172
2410
  );
2173
2411
  }
2174
- function isRoutingCriticalMetaSignal(_signal) {
2175
- return false;
2412
+ function isRoutingCriticalMetaSignal(signal) {
2413
+ return ROUTING_CRITICAL_META_SIGNALS.has(signal.name);
2176
2414
  }
2177
- function isRoutingCriticalMetaIntent(_intent) {
2178
- return false;
2415
+ function isRoutingCriticalMetaIntent(intent) {
2416
+ return ROUTING_CRITICAL_META_INTENTS.has(intent.name);
2179
2417
  }
2418
+ var ROUTING_CRITICAL_META_INTENTS = /* @__PURE__ */ new Set([
2419
+ AUTHORITY_BOOTSTRAP_FULL_SYNC_INTENT,
2420
+ AUTHORITY_SERVICE_INSTANCE_REGISTER_INTENT,
2421
+ AUTHORITY_SERVICE_INSTANCE_TRANSPORT_REGISTER_INTENT,
2422
+ AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
2423
+ AUTHORITY_RUNTIME_STATUS_REPORT_INTENT
2424
+ ]);
2425
+ var ROUTING_CRITICAL_META_SIGNALS = /* @__PURE__ */ new Set([
2426
+ AUTHORITY_SERVICE_MANIFEST_UPDATED_SIGNAL,
2427
+ EXECUTION_PERSISTENCE_BUNDLE_SIGNAL,
2428
+ ...AUTHORITY_BOOTSTRAP_SIGNAL_NAMES
2429
+ ]);
2180
2430
  function buildServiceManifestSnapshot(params) {
2181
2431
  const {
2182
2432
  serviceName,
@@ -2586,87 +2836,9 @@ function buildServiceManifestSnapshot(params) {
2586
2836
  `${right.routine_name}:${right.task_name}`
2587
2837
  )
2588
2838
  );
2589
- const businessLocalMetaTaskKeys = /* @__PURE__ */ new Set();
2590
- const businessLocalMetaSignalNames = /* @__PURE__ */ new Set();
2591
- const businessLocalMetaIntentNames = /* @__PURE__ */ new Set();
2592
- const businessLocalMetaActorKeys = /* @__PURE__ */ new Set();
2593
- const businessLocalMetaRoutineKeys = /* @__PURE__ */ new Set();
2594
- for (const map of localMetaSignalTaskMaps) {
2595
- businessLocalMetaSignalNames.add(map.signal_name);
2596
- businessLocalMetaTaskKeys.add(
2597
- buildTaskKey({
2598
- service_name: map.service_name,
2599
- name: map.task_name,
2600
- version: map.task_version
2601
- })
2602
- );
2603
- }
2604
- for (const map of localMetaIntentTaskMaps) {
2605
- businessLocalMetaIntentNames.add(map.intent_name);
2606
- businessLocalMetaTaskKeys.add(
2607
- buildTaskKey({
2608
- service_name: map.service_name,
2609
- name: map.task_name,
2610
- version: map.task_version
2611
- })
2612
- );
2613
- }
2614
- for (const map of localMetaActorTaskMaps) {
2615
- businessLocalMetaActorKeys.add(
2616
- buildActorKey({
2617
- service_name: map.service_name,
2618
- name: map.actor_name,
2619
- version: map.actor_version
2620
- })
2621
- );
2622
- businessLocalMetaTaskKeys.add(
2623
- buildTaskKey({
2624
- service_name: map.service_name,
2625
- name: map.task_name,
2626
- version: map.task_version
2627
- })
2628
- );
2629
- }
2630
- for (const map of localMetaTaskToRoutineMaps) {
2631
- businessLocalMetaRoutineKeys.add(
2632
- buildRoutineKey({
2633
- service_name: map.service_name,
2634
- name: map.routine_name,
2635
- version: map.routine_version
2636
- })
2637
- );
2638
- businessLocalMetaTaskKeys.add(
2639
- buildTaskKey({
2640
- service_name: map.service_name,
2641
- name: map.task_name,
2642
- version: map.task_version
2643
- })
2644
- );
2645
- }
2646
- const businessLocalMetaTasks = Array.from(businessLocalMetaTaskKeys).map((key) => taskDefinitionsByKey.get(key) ?? null).filter(
2647
- (task) => task !== null && (task.is_meta === true || task.is_sub_meta === true)
2648
- ).sort(
2649
- (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2650
- );
2651
- const businessLocalMetaSignals = Array.from(businessLocalMetaSignalNames).map((name) => signalDefinitionsByName.get(name) ?? null).filter(
2652
- (signal) => signal !== null && signal.is_meta === true
2653
- ).sort((left, right) => left.name.localeCompare(right.name));
2654
- const businessLocalMetaIntents = Array.from(businessLocalMetaIntentNames).map((name) => intentDefinitionsByName.get(name) ?? null).filter(
2655
- (intent) => intent !== null && intent.is_meta === true
2656
- ).sort((left, right) => left.name.localeCompare(right.name));
2657
- const businessLocalMetaActors = Array.from(businessLocalMetaActorKeys).map((key) => actorDefinitionsByKey.get(key) ?? null).filter(
2658
- (actor) => actor !== null && actor.is_meta === true
2659
- ).sort(
2660
- (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2661
- );
2662
- const businessLocalMetaRoutines = Array.from(businessLocalMetaRoutineKeys).map((key) => routineDefinitionsByKey.get(key) ?? null).filter(
2663
- (routine) => routine !== null && routine.is_meta === true
2664
- ).sort(
2665
- (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2666
- );
2667
2839
  const cumulativeTasks = publicationLayer === "routing_capability" ? routingTasks : publicationLayer === "business_structural" ? Array.from(
2668
2840
  new Map(
2669
- [...routingTasks, ...businessTasks, ...businessLocalMetaTasks].map((task) => [
2841
+ [...routingTasks, ...businessTasks].map((task) => [
2670
2842
  buildTaskKey(task),
2671
2843
  task
2672
2844
  ])
@@ -2685,7 +2857,7 @@ function buildServiceManifestSnapshot(params) {
2685
2857
  );
2686
2858
  const cumulativeSignals = publicationLayer === "routing_capability" ? routingSignals : publicationLayer === "business_structural" ? Array.from(
2687
2859
  new Map(
2688
- [...routingSignals, ...businessSignals, ...businessLocalMetaSignals].map(
2860
+ [...routingSignals, ...businessSignals].map(
2689
2861
  (signal) => [signal.name, signal]
2690
2862
  )
2691
2863
  ).values()
@@ -2699,7 +2871,7 @@ function buildServiceManifestSnapshot(params) {
2699
2871
  ).sort((left, right) => left.name.localeCompare(right.name));
2700
2872
  const cumulativeIntents = publicationLayer === "routing_capability" ? routingIntents : publicationLayer === "business_structural" ? Array.from(
2701
2873
  new Map(
2702
- [...routingIntents, ...businessIntents, ...businessLocalMetaIntents].map(
2874
+ [...routingIntents, ...businessIntents].map(
2703
2875
  (intent) => [intent.name, intent]
2704
2876
  )
2705
2877
  ).values()
@@ -2711,16 +2883,7 @@ function buildServiceManifestSnapshot(params) {
2711
2883
  ])
2712
2884
  ).values()
2713
2885
  ).sort((left, right) => left.name.localeCompare(right.name));
2714
- const cumulativeActors = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? Array.from(
2715
- new Map(
2716
- [...businessActors, ...businessLocalMetaActors].map((actor) => [
2717
- buildActorKey(actor),
2718
- actor
2719
- ])
2720
- ).values()
2721
- ).sort(
2722
- (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2723
- ) : Array.from(
2886
+ const cumulativeActors = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessActors : Array.from(
2724
2887
  new Map(
2725
2888
  [...businessActors, ...localMetaActors].map((actor) => [
2726
2889
  buildActorKey(actor),
@@ -2730,16 +2893,7 @@ function buildServiceManifestSnapshot(params) {
2730
2893
  ).sort(
2731
2894
  (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2732
2895
  );
2733
- const cumulativeRoutines = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? Array.from(
2734
- new Map(
2735
- [...businessRoutines, ...businessLocalMetaRoutines].map((routine) => [
2736
- buildRoutineKey(routine),
2737
- routine
2738
- ])
2739
- ).values()
2740
- ).sort(
2741
- (left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
2742
- ) : Array.from(
2896
+ const cumulativeRoutines = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessRoutines : Array.from(
2743
2897
  new Map(
2744
2898
  [...businessRoutines, ...localMetaRoutines].map((routine) => [
2745
2899
  buildRoutineKey(routine),
@@ -2865,14 +3019,7 @@ function buildServiceManifestSnapshot(params) {
2865
3019
  )
2866
3020
  ).values()
2867
3021
  );
2868
- const cumulativeActorTaskMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? Array.from(
2869
- new Map(
2870
- [...businessActorTaskMaps, ...localMetaActorTaskMaps].map((map) => [
2871
- `${map.service_name}|${map.actor_name}|${map.actor_version}|${map.task_name}|${map.task_version}|${map.mode}`,
2872
- map
2873
- ])
2874
- ).values()
2875
- ) : Array.from(
3022
+ const cumulativeActorTaskMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessActorTaskMaps : Array.from(
2876
3023
  new Map(
2877
3024
  [...businessActorTaskMaps, ...localMetaActorTaskMaps].map((map) => [
2878
3025
  `${map.service_name}|${map.actor_name}|${map.actor_version}|${map.task_name}|${map.task_version}|${map.mode}`,
@@ -2900,8 +3047,8 @@ function buildServiceManifestSnapshot(params) {
2900
3047
  helpers: cumulativeHelpers,
2901
3048
  globals: cumulativeGlobals,
2902
3049
  directionalTaskMaps: cumulativeDirectionalTaskMaps,
2903
- signalToTaskMaps: publicationLayer === "routing_capability" ? publishedSignalTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps] : [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps],
2904
- intentToTaskMaps: publicationLayer === "routing_capability" ? publishedIntentTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps] : [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps],
3050
+ signalToTaskMaps: publicationLayer === "routing_capability" ? publishedSignalTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps] : publishedSignalTaskMaps,
3051
+ intentToTaskMaps: publicationLayer === "routing_capability" ? publishedIntentTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps] : publishedIntentTaskMaps,
2905
3052
  actorTaskMaps: cumulativeActorTaskMaps,
2906
3053
  taskToRoutineMaps: cumulativeTaskToRoutineMaps,
2907
3054
  taskToHelperMaps: cumulativeTaskToHelperMaps,
@@ -3065,6 +3212,13 @@ var META_SERVICE_INSTANCE_SHUTDOWN_TRANSPORT_DEACTIVATION_SIGNAL = "meta.service
3065
3212
  var META_AUTHORITY_BOOTSTRAP_HANDSHAKE_REQUESTED_SIGNAL = "meta.service_registry.authority_bootstrap_handshake_requested";
3066
3213
  var META_RUNTIME_STATUS_REST_REFRESH_TICK_SIGNAL = "meta.service_registry.runtime_status.rest_refresh_tick";
3067
3214
  var AUTHORITY_BOOTSTRAP_HANDSHAKE_TIMEOUT_MS = 5e3;
3215
+ var AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS = [
3216
+ 1e3,
3217
+ 3e3,
3218
+ 7e3,
3219
+ 15e3
3220
+ ];
3221
+ var AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS = 6e4;
3068
3222
  var EARLY_FULL_SYNC_DELAYS_MS = [
3069
3223
  100,
3070
3224
  1500,
@@ -3074,25 +3228,41 @@ var EARLY_FULL_SYNC_DELAYS_MS = [
3074
3228
  45e3,
3075
3229
  7e4
3076
3230
  ];
3231
+ var PENDING_ROUTE_SELECTION_RETRY_DELAYS_MS = [
3232
+ 50,
3233
+ 125,
3234
+ 250,
3235
+ 500
3236
+ ];
3077
3237
  var MIN_BOOTSTRAP_FULL_SYNC_ATTEMPTS = 4;
3078
- var INTERNAL_RUNTIME_STATUS_TASK_NAMES = /* @__PURE__ */ new Set([
3079
- "Track local routine start",
3080
- "Track local routine end",
3081
- "Start runtime status sharing intervals",
3082
- "Broadcast runtime status",
3083
- "Flush local runtime status to authority",
3084
- "Monitor dependee heartbeat freshness",
3085
- "Refresh REST dependee runtime status",
3086
- "Resolve runtime status fallback inquiry",
3087
- "Respond runtime status inquiry",
3088
- "Respond readiness inquiry",
3089
- "Collect distributed readiness",
3090
- "Get status"
3091
- ]);
3092
3238
  var SERVICE_REGISTRY_TRACE_SERVICE2 = (process.env.CADENZA_SERVICE_REGISTRY_TRACE_SERVICE ?? "").trim();
3093
3239
  function shouldTraceServiceRegistry(serviceName) {
3094
3240
  return SERVICE_REGISTRY_TRACE_SERVICE2.length > 0 && serviceName === SERVICE_REGISTRY_TRACE_SERVICE2;
3095
3241
  }
3242
+ function getFetchFailureText(ctx) {
3243
+ return String(ctx?.__error ?? ctx?.error ?? ctx?.message ?? "").trim();
3244
+ }
3245
+ function isTerminalFetchTransportFailure(ctx) {
3246
+ const errorText = getFetchFailureText(ctx);
3247
+ if (!errorText) {
3248
+ return false;
3249
+ }
3250
+ return errorText.includes("ENOTFOUND") || errorText.includes("ECONNREFUSED") || errorText.includes("EHOSTUNREACH");
3251
+ }
3252
+ function isRecoverableFetchTransportFailure(ctx, options = {}) {
3253
+ const errorText = getFetchFailureText(ctx);
3254
+ if (!errorText) {
3255
+ return false;
3256
+ }
3257
+ return errorText.includes("AbortError") || errorText.includes("The operation was aborted") || errorText.includes("socket hang up") || errorText.includes("ECONNRESET") || errorText.includes("ETIMEDOUT") || options.includeConnectionRefused === true && errorText.includes("ECONNREFUSED");
3258
+ }
3259
+ function isHardFetchHandshakeFailure(ctx) {
3260
+ const errorText = getFetchFailureText(ctx);
3261
+ if (!errorText) {
3262
+ return false;
3263
+ }
3264
+ return isTerminalFetchTransportFailure(ctx) || isRecoverableFetchTransportFailure(ctx);
3265
+ }
3096
3266
  function normalizeLeaseStatus(value) {
3097
3267
  const status = String(value ?? "").trim();
3098
3268
  if (status === "active" || status === "non_responsive" || status === "inactive" || status === "deleted") {
@@ -3238,18 +3408,28 @@ function compactAuthorityBootstrapRequestBody(ctx) {
3238
3408
  if (!isBootstrapDbOperationRoutineName(ctx.__remoteRoutineName)) {
3239
3409
  return ctx;
3240
3410
  }
3241
- const queryData = ctx.queryData && typeof ctx.queryData === "object" ? { ...ctx.queryData } : null;
3242
- if (!queryData) {
3243
- return ctx;
3411
+ const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? { ...ctx.queryData } : {};
3412
+ const compactQueryData = {};
3413
+ for (const key of BOOTSTRAP_DB_OPERATION_CONTEXT_KEYS) {
3414
+ if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
3415
+ compactQueryData[key] = existingQueryData[key];
3416
+ continue;
3417
+ }
3418
+ if (Object.prototype.hasOwnProperty.call(ctx, key)) {
3419
+ compactQueryData[key] = ctx[key];
3420
+ }
3244
3421
  }
3245
3422
  const compacted = {
3246
- ...ctx,
3247
- queryData
3423
+ __remoteRoutineName: ctx.__remoteRoutineName,
3424
+ __serviceName: ctx.__serviceName,
3425
+ __localServiceName: ctx.__localServiceName,
3426
+ __timeout: ctx.__timeout,
3427
+ __syncing: true,
3428
+ __authorityBootstrapChannel: true,
3429
+ queryData: compactQueryData
3248
3430
  };
3249
- for (const key of BOOTSTRAP_DB_OPERATION_CONTEXT_KEYS) {
3250
- if (Object.prototype.hasOwnProperty.call(queryData, key)) {
3251
- delete compacted[key];
3252
- }
3431
+ if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
3432
+ compacted.__reason = ctx.__reason;
3253
3433
  }
3254
3434
  return compacted;
3255
3435
  }
@@ -3969,6 +4149,10 @@ var ServiceRegistry = class _ServiceRegistry {
3969
4149
  handshakeEstablished: false
3970
4150
  };
3971
4151
  this.authorityBootstrapHandshakeInFlight = false;
4152
+ this.authorityBootstrapHandshakeRetryTimer = null;
4153
+ this.authorityBootstrapHandshakeRetryIndex = 0;
4154
+ this.authorityBootstrapHandshakeRetryGeneration = 0;
4155
+ this.authorityBootstrapHandshakeRetryReason = null;
3972
4156
  this.authorityFullSyncResponderTask = null;
3973
4157
  this.authorityServiceCommunicationPersistenceTask = null;
3974
4158
  this.localLifecycleFlushActor = CadenzaService.createActor(
@@ -4504,7 +4688,13 @@ var ServiceRegistry = class _ServiceRegistry {
4504
4688
  return false;
4505
4689
  }
4506
4690
  this.clearTransportReadyFromContext(ctx);
4507
- const { serviceName, serviceInstanceId, serviceTransportId } = ctx;
4691
+ const serviceName = resolveServiceNameFromContext(ctx);
4692
+ const serviceInstanceId = String(
4693
+ ctx.serviceInstanceId ?? ctx.__instance ?? ctx.filter?.uuid ?? ""
4694
+ ).trim();
4695
+ const serviceTransportId = String(
4696
+ ctx.serviceTransportId ?? ctx.__transportId ?? ""
4697
+ ).trim();
4508
4698
  if (serviceName === "CadenzaDB" && this.hasAuthorityBootstrapHandshakeEstablished()) {
4509
4699
  const currentAuthorityInstanceId = String(
4510
4700
  this.authorityBootstrapRoute.serviceInstanceId ?? ""
@@ -4520,6 +4710,23 @@ var ServiceRegistry = class _ServiceRegistry {
4520
4710
  return true;
4521
4711
  }
4522
4712
  }
4713
+ const signalName = String(
4714
+ ctx.__signalName ?? ctx.__signalEmission?.fullSignalName ?? ""
4715
+ ).trim();
4716
+ const isFetchHandshakeFailure = signalName === "meta.fetch.handshake_failed" || signalName.startsWith("meta.fetch.handshake_failed:");
4717
+ const hardFetchHandshakeFailure = isFetchHandshakeFailure && isHardFetchHandshakeFailure(ctx);
4718
+ const recoverableFetchHandshakeFailure = isFetchHandshakeFailure && isRecoverableFetchTransportFailure(ctx, {
4719
+ includeConnectionRefused: true
4720
+ });
4721
+ const isFetchDelegateFailure = signalName === "meta.fetch.delegate_failed" || signalName.startsWith("meta.fetch.delegate_failed:");
4722
+ const hardFetchDelegateFailure = isFetchDelegateFailure && isHardFetchHandshakeFailure(ctx);
4723
+ const recoverableFetchDelegateFailure = isFetchDelegateFailure && isRecoverableFetchTransportFailure(ctx);
4724
+ if (isFetchDelegateFailure && !hardFetchDelegateFailure) {
4725
+ return false;
4726
+ }
4727
+ if (serviceName === "CadenzaDB" && (isFetchHandshakeFailure && recoverableFetchHandshakeFailure || isFetchDelegateFailure && recoverableFetchDelegateFailure)) {
4728
+ return false;
4729
+ }
4523
4730
  const serviceInstances = this.instances.get(serviceName);
4524
4731
  const instances = serviceInstances?.filter((instance) => {
4525
4732
  if (serviceInstanceId && instance.uuid === serviceInstanceId) {
@@ -4543,6 +4750,9 @@ var ServiceRegistry = class _ServiceRegistry {
4543
4750
  "warning",
4544
4751
  serviceName
4545
4752
  );
4753
+ if (serviceName === "CadenzaDB") {
4754
+ this.restartAuthorityBootstrapRecovery("cadenza_db_unreachable");
4755
+ }
4546
4756
  for (const instance of instances ?? []) {
4547
4757
  if (instance.serviceName === this.serviceName && instance.uuid === this.serviceInstanceId) {
4548
4758
  continue;
@@ -4551,13 +4761,9 @@ var ServiceRegistry = class _ServiceRegistry {
4551
4761
  if (affectedTransport && this.hasAnyReadyClientProtocolForTransport(instance, affectedTransport)) {
4552
4762
  continue;
4553
4763
  }
4554
- const signalName = String(
4555
- ctx.__signalName ?? ctx.__signalEmission?.fullSignalName ?? ""
4556
- ).trim();
4557
- const isFetchHandshakeFailure = signalName === "meta.fetch.handshake_failed" || signalName.startsWith("meta.fetch.handshake_failed:");
4558
- if (isFetchHandshakeFailure && affectedTransport && this.isCurrentRouteContext(ctx) && this.scheduleDependeeClientRecovery(instance, affectedTransport, {
4764
+ if ((isFetchHandshakeFailure && (!hardFetchHandshakeFailure || recoverableFetchHandshakeFailure) || isFetchDelegateFailure && (!hardFetchDelegateFailure || recoverableFetchDelegateFailure)) && affectedTransport && this.isCurrentRouteContext(ctx) && this.scheduleDependeeClientRecovery(instance, affectedTransport, {
4559
4765
  ...ctx,
4560
- __reason: "fetch_handshake_failed_retry"
4766
+ __reason: isFetchDelegateFailure ? "fetch_delegate_failed_retry" : "fetch_handshake_failed_retry"
4561
4767
  })) {
4562
4768
  continue;
4563
4769
  }
@@ -4568,10 +4774,36 @@ var ServiceRegistry = class _ServiceRegistry {
4568
4774
  });
4569
4775
  continue;
4570
4776
  }
4777
+ if (isFetchHandshakeFailure && recoverableFetchHandshakeFailure || isFetchDelegateFailure && recoverableFetchDelegateFailure) {
4778
+ continue;
4779
+ }
4571
4780
  this.applyInstanceLifecycleState(instance, {
4572
4781
  isActive: false,
4573
4782
  isNonResponsive: true
4574
4783
  });
4784
+ const transportsToClear = affectedTransport ? [affectedTransport] : (instance.transports ?? []).filter((transport) => !transport.deleted);
4785
+ for (const transport of transportsToClear) {
4786
+ this.clearTransportFailureState(instance.uuid, transport.uuid);
4787
+ this.clearTransportClientState(instance, transport);
4788
+ this.clearRemoteRouteRecordIfCurrent(
4789
+ instance.serviceName,
4790
+ instance.uuid,
4791
+ transport
4792
+ );
4793
+ this.emitTransportHandleShutdowns(
4794
+ emit2,
4795
+ this.buildTransportRouteKey(instance.serviceName, transport),
4796
+ transport
4797
+ );
4798
+ }
4799
+ emit2("meta.service_registry.service_not_responding", {
4800
+ ...ctx,
4801
+ serviceName: instance.serviceName,
4802
+ serviceInstanceId: instance.uuid,
4803
+ serviceTransportId: affectedTransport?.uuid ?? serviceTransportId ?? void 0,
4804
+ routeKey: affectedTransport ? this.buildTransportRouteKey(instance.serviceName, affectedTransport) : ctx.routeKey ?? ctx.__routeKey,
4805
+ __routeKey: affectedTransport ? this.buildTransportRouteKey(instance.serviceName, affectedTransport) : ctx.__routeKey ?? ctx.routeKey
4806
+ });
4575
4807
  emit2("global.meta.service_registry.service_not_responding", {
4576
4808
  data: {
4577
4809
  isActive: false,
@@ -4600,6 +4832,8 @@ var ServiceRegistry = class _ServiceRegistry {
4600
4832
  ).doOn(
4601
4833
  "meta.fetch.handshake_failed",
4602
4834
  "meta.fetch.handshake_failed.*",
4835
+ "meta.fetch.delegate_failed",
4836
+ "meta.fetch.delegate_failed.*",
4603
4837
  "meta.socket_client.disconnected",
4604
4838
  "meta.socket_client.disconnected.*",
4605
4839
  "meta.service_registry.runtime_status_unreachable"
@@ -4785,12 +5019,7 @@ var ServiceRegistry = class _ServiceRegistry {
4785
5019
  return false;
4786
5020
  }
4787
5021
  }
4788
- this.invalidateAuthorityBootstrapHandshake();
4789
- this.invalidateBootstrapFullSyncRetryState("cadenza_db_unreachable");
4790
- CadenzaService.emit(META_AUTHORITY_BOOTSTRAP_HANDSHAKE_REQUESTED_SIGNAL, {
4791
- ...ctx,
4792
- __reason: "cadenza_db_unreachable"
4793
- });
5022
+ this.restartAuthorityBootstrapRecovery("cadenza_db_unreachable");
4794
5023
  return true;
4795
5024
  },
4796
5025
  "Clears bootstrap full-sync retry satisfaction when the authority becomes unreachable."
@@ -4810,7 +5039,7 @@ var ServiceRegistry = class _ServiceRegistry {
4810
5039
  return false;
4811
5040
  }
4812
5041
  this.ensureBootstrapAuthorityControlPlane(ctx, emit2);
4813
- return this.restartBootstrapFullSyncRetryChain(
5042
+ return this.scheduleNextBootstrapFullSyncRetry(
4814
5043
  "cadenza_db_fetch_handshake"
4815
5044
  );
4816
5045
  },
@@ -5177,12 +5406,24 @@ var ServiceRegistry = class _ServiceRegistry {
5177
5406
  preferredRole,
5178
5407
  preferredProtocol
5179
5408
  );
5409
+ if (this.shouldDemandEstablishRemoteClients(context)) {
5410
+ this.ensureDependeeClientsForService(__serviceName, emit2, context);
5411
+ }
5412
+ const hasPendingRouteableInstance = Boolean(__serviceName) && __serviceName !== "CadenzaDB" && this.hasPendingRouteableInstanceForSelection(
5413
+ __serviceName,
5414
+ context,
5415
+ preferredRole,
5416
+ targetServiceInstanceId
5417
+ );
5180
5418
  const activeRoutingCooldown = __serviceName && !targetServiceInstanceId ? this.getActiveRoutingCooldown(
5181
5419
  __serviceName,
5182
5420
  preferredRole,
5183
5421
  preferredProtocol
5184
5422
  ) : null;
5185
5423
  if (activeRoutingCooldown) {
5424
+ if (hasPendingRouteableInstance && this.maybeSchedulePendingRouteSelectionRetry(context, __serviceName)) {
5425
+ return false;
5426
+ }
5186
5427
  context.errored = true;
5187
5428
  context.__error = `No routeable ${preferredRole} transport available for ${__serviceName}. Waiting for authority route updates before retrying.`;
5188
5429
  emit2(
@@ -5224,9 +5465,6 @@ var ServiceRegistry = class _ServiceRegistry {
5224
5465
  }
5225
5466
  let retries = __retries ?? 0;
5226
5467
  let triedInstances = __triedInstances ?? [];
5227
- if (this.shouldDemandEstablishRemoteClients(context)) {
5228
- this.ensureDependeeClientsForService(__serviceName, emit2, context);
5229
- }
5230
5468
  const filteredInstances = this.instances.get(__serviceName)?.filter((instance) => {
5231
5469
  if (targetServiceInstanceId && instance.uuid !== targetServiceInstanceId) {
5232
5470
  return false;
@@ -5245,6 +5483,9 @@ var ServiceRegistry = class _ServiceRegistry {
5245
5483
  )
5246
5484
  );
5247
5485
  }) ?? [];
5486
+ if (filteredInstances.length === 0 && __serviceName && hasPendingRouteableInstance && this.maybeSchedulePendingRouteSelectionRetry(context, __serviceName)) {
5487
+ return false;
5488
+ }
5248
5489
  const instances = this.collapseInstancesByRouteOrigin(
5249
5490
  filteredInstances,
5250
5491
  context,
@@ -5588,10 +5829,6 @@ var ServiceRegistry = class _ServiceRegistry {
5588
5829
  CadenzaService.createMetaTask(
5589
5830
  "Track local routine start",
5590
5831
  (ctx, emit2) => {
5591
- const sourceTaskName = String(ctx.__signalEmission?.taskName ?? "");
5592
- if (INTERNAL_RUNTIME_STATUS_TASK_NAMES.has(sourceTaskName)) {
5593
- return false;
5594
- }
5595
5832
  const routineId = String(
5596
5833
  ctx.filter?.uuid ?? ctx.__routineExecId ?? ""
5597
5834
  );
@@ -5622,10 +5859,6 @@ var ServiceRegistry = class _ServiceRegistry {
5622
5859
  CadenzaService.createMetaTask(
5623
5860
  "Track local routine end",
5624
5861
  (ctx, emit2) => {
5625
- const sourceTaskName = String(ctx.__signalEmission?.taskName ?? "");
5626
- if (INTERNAL_RUNTIME_STATUS_TASK_NAMES.has(sourceTaskName)) {
5627
- return false;
5628
- }
5629
5862
  const routineId = String(
5630
5863
  ctx.filter?.uuid ?? ctx.__routineExecId ?? ""
5631
5864
  );
@@ -6259,6 +6492,19 @@ var ServiceRegistry = class _ServiceRegistry {
6259
6492
  }
6260
6493
  return false;
6261
6494
  }
6495
+ if (this.serviceName && normalizedLocalInstance.serviceName !== this.serviceName || this.serviceInstanceId && normalizedLocalInstance.uuid !== this.serviceInstanceId) {
6496
+ if (shouldTraceServiceRegistry(
6497
+ resolveServiceNameFromContext(ctx) || this.serviceName
6498
+ )) {
6499
+ console.log("[CADENZA_SERVICE_REGISTRY_TRACE] setup_service_ignored_non_local_instance", {
6500
+ localServiceName: this.serviceName,
6501
+ localServiceInstanceId: this.serviceInstanceId,
6502
+ resolvedServiceName: normalizedLocalInstance.serviceName,
6503
+ resolvedServiceInstanceId: normalizedLocalInstance.uuid
6504
+ });
6505
+ }
6506
+ return false;
6507
+ }
6262
6508
  if (shouldTraceServiceRegistry(normalizedLocalInstance.serviceName)) {
6263
6509
  console.log("[CADENZA_SERVICE_REGISTRY_TRACE] setup_service", {
6264
6510
  localServiceName: this.serviceName,
@@ -6474,7 +6720,8 @@ var ServiceRegistry = class _ServiceRegistry {
6474
6720
  security_profile: "excluded",
6475
6721
  auth_strategy: "excluded",
6476
6722
  deleted: "false"
6477
- }
6723
+ },
6724
+ where: "service_instance_transport.deleted IS DISTINCT FROM FALSE OR service_instance_transport.protocols IS DISTINCT FROM excluded.protocols OR service_instance_transport.security_profile IS DISTINCT FROM excluded.security_profile OR service_instance_transport.auth_strategy IS DISTINCT FROM excluded.auth_strategy"
6478
6725
  }
6479
6726
  }
6480
6727
  },
@@ -7406,6 +7653,7 @@ var ServiceRegistry = class _ServiceRegistry {
7406
7653
  serviceTransportId: String(ctx.serviceTransportId ?? "").trim() || null,
7407
7654
  handshakeEstablished: true
7408
7655
  };
7656
+ this.markAuthorityBootstrapHandshakeSatisfied();
7409
7657
  return true;
7410
7658
  }
7411
7659
  getAuthorityBootstrapRestTarget() {
@@ -7434,6 +7682,84 @@ var ServiceRegistry = class _ServiceRegistry {
7434
7682
  handshakeEstablished: false
7435
7683
  };
7436
7684
  }
7685
+ clearAuthorityBootstrapHandshakeRetryTimer() {
7686
+ if (this.authorityBootstrapHandshakeRetryTimer) {
7687
+ clearTimeout(this.authorityBootstrapHandshakeRetryTimer);
7688
+ this.authorityBootstrapHandshakeRetryTimer = null;
7689
+ }
7690
+ }
7691
+ invalidateAuthorityBootstrapHandshakeRetryState(reason) {
7692
+ this.authorityBootstrapHandshakeRetryGeneration += 1;
7693
+ this.clearAuthorityBootstrapHandshakeRetryTimer();
7694
+ this.authorityBootstrapHandshakeRetryIndex = 0;
7695
+ if (typeof reason === "string" && reason.trim()) {
7696
+ this.authorityBootstrapHandshakeRetryReason = reason.trim();
7697
+ }
7698
+ }
7699
+ markAuthorityBootstrapHandshakeSatisfied() {
7700
+ this.clearAuthorityBootstrapHandshakeRetryTimer();
7701
+ this.authorityBootstrapHandshakeRetryIndex = AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.length;
7702
+ this.authorityBootstrapHandshakeRetryReason = null;
7703
+ }
7704
+ buildJitteredAuthorityBootstrapHandshakeRetryDelayMs(baseDelayMs, attempt) {
7705
+ return buildDeterministicJitteredDelayMs(
7706
+ baseDelayMs,
7707
+ this.bootstrapFullSyncRetryJitterRatio,
7708
+ this.buildDeterministicInstanceJitterKey(
7709
+ `authority-bootstrap-handshake-retry-${attempt}`
7710
+ )
7711
+ );
7712
+ }
7713
+ scheduleAuthorityBootstrapHandshakeRetry(reason) {
7714
+ if (!this.connectsToCadenzaDB || !this.serviceName || this.serviceName === "CadenzaDB") {
7715
+ return false;
7716
+ }
7717
+ if (this.hasAuthorityBootstrapHandshakeEstablished()) {
7718
+ return false;
7719
+ }
7720
+ if (this.authorityBootstrapHandshakeInFlight) {
7721
+ return false;
7722
+ }
7723
+ if (typeof reason === "string" && reason.trim()) {
7724
+ this.authorityBootstrapHandshakeRetryReason = reason.trim();
7725
+ }
7726
+ if (this.authorityBootstrapHandshakeRetryTimer) {
7727
+ return false;
7728
+ }
7729
+ const retryGeneration = this.authorityBootstrapHandshakeRetryGeneration;
7730
+ const retryReason = this.authorityBootstrapHandshakeRetryReason ?? "authority_bootstrap_handshake_retry";
7731
+ const attempt = this.authorityBootstrapHandshakeRetryIndex + 1;
7732
+ const baseDelayMs = AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS[Math.min(
7733
+ this.authorityBootstrapHandshakeRetryIndex,
7734
+ AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.length - 1
7735
+ )] ?? AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.at(-1);
7736
+ const delayMs = this.buildJitteredAuthorityBootstrapHandshakeRetryDelayMs(
7737
+ baseDelayMs,
7738
+ attempt
7739
+ );
7740
+ this.authorityBootstrapHandshakeRetryIndex += 1;
7741
+ this.authorityBootstrapHandshakeRetryTimer = setTimeout(() => {
7742
+ this.authorityBootstrapHandshakeRetryTimer = null;
7743
+ if (this.hasAuthorityBootstrapHandshakeEstablished() || this.authorityBootstrapHandshakeInFlight || retryGeneration !== this.authorityBootstrapHandshakeRetryGeneration) {
7744
+ return;
7745
+ }
7746
+ this.requestAuthorityBootstrapHandshake({
7747
+ __reason: retryReason,
7748
+ __authorityBootstrapRetry: true,
7749
+ __authorityBootstrapRetryAttempt: attempt
7750
+ });
7751
+ }, delayMs);
7752
+ return true;
7753
+ }
7754
+ restartAuthorityBootstrapHandshakeRetryChain(reason) {
7755
+ this.invalidateAuthorityBootstrapHandshakeRetryState(reason);
7756
+ return this.scheduleAuthorityBootstrapHandshakeRetry(reason);
7757
+ }
7758
+ restartAuthorityBootstrapRecovery(reason) {
7759
+ this.invalidateAuthorityBootstrapHandshake();
7760
+ this.invalidateBootstrapFullSyncRetryState(reason);
7761
+ return this.restartAuthorityBootstrapHandshakeRetryChain(reason);
7762
+ }
7437
7763
  requestAuthorityBootstrapHandshake(ctx) {
7438
7764
  if (!this.connectsToCadenzaDB || !this.serviceName || this.serviceName === "CadenzaDB") {
7439
7765
  return false;
@@ -7640,12 +7966,16 @@ var ServiceRegistry = class _ServiceRegistry {
7640
7966
  return;
7641
7967
  }
7642
7968
  const deputyTaskName = `Inquire ${map.intentName} via ${map.serviceName} (${map.taskName} v${map.taskVersion})`;
7643
- const deputyTask = map.serviceName === "CadenzaDB" && isAuthorityBootstrapIntent(map.intentName) ? CadenzaService.createMetaTask(
7969
+ const shouldUseAuthorityBootstrapTimeout = map.serviceName === "CadenzaDB" && isMetaIntentName(map.intentName);
7970
+ const effectiveTimeout = shouldUseAuthorityBootstrapTimeout ? Math.max(map.timeout ?? 0, AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS) : map.timeout;
7971
+ const authorityBootstrapIntentSpec = map.serviceName === "CadenzaDB" ? getAuthorityBootstrapIntentSpec(map.intentName) : null;
7972
+ const authorityBootstrapTaskName = authorityBootstrapIntentSpec?.authorityTaskName ?? map.taskName;
7973
+ const deputyTask = authorityBootstrapIntentSpec ? CadenzaService.createMetaTask(
7644
7974
  deputyTaskName,
7645
7975
  async (ctx) => this.invokeAuthorityBootstrapRoutine(
7646
- map.taskName,
7976
+ authorityBootstrapTaskName,
7647
7977
  ctx,
7648
- map.timeout ?? 15e3
7978
+ effectiveTimeout ?? AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS
7649
7979
  ),
7650
7980
  "Routes reserved authority bootstrap inquiries directly through the post-handshake authority control-plane channel.",
7651
7981
  {
@@ -7655,14 +7985,14 @@ var ServiceRegistry = class _ServiceRegistry {
7655
7985
  ) : isMetaIntentName(map.intentName) ? CadenzaService.createMetaDeputyTask(map.taskName, map.serviceName, {
7656
7986
  register: false,
7657
7987
  isHidden: true,
7658
- timeout: map.timeout,
7988
+ timeout: effectiveTimeout,
7659
7989
  retryCount: 1,
7660
7990
  retryDelay: 50,
7661
7991
  retryDelayFactor: 1.2
7662
7992
  }) : CadenzaService.createDeputyTask(map.taskName, map.serviceName, {
7663
7993
  register: false,
7664
7994
  isHidden: true,
7665
- timeout: map.timeout,
7995
+ timeout: effectiveTimeout,
7666
7996
  retryCount: 1,
7667
7997
  retryDelay: 50,
7668
7998
  retryDelayFactor: 1.2
@@ -7676,7 +8006,7 @@ var ServiceRegistry = class _ServiceRegistry {
7676
8006
  key,
7677
8007
  intentName: map.intentName,
7678
8008
  serviceName: map.serviceName,
7679
- remoteTaskName: map.taskName,
8009
+ remoteTaskName: authorityBootstrapTaskName,
7680
8010
  remoteTaskVersion: map.taskVersion,
7681
8011
  localTaskName: deputyTask.name || deputyTaskName,
7682
8012
  localTask: deputyTask
@@ -7688,7 +8018,7 @@ var ServiceRegistry = class _ServiceRegistry {
7688
8018
  localServiceName: this.serviceName,
7689
8019
  intentName: map.intentName,
7690
8020
  remoteServiceName: map.serviceName,
7691
- remoteTaskName: map.taskName,
8021
+ remoteTaskName: authorityBootstrapTaskName,
7692
8022
  remoteTaskVersion: map.taskVersion
7693
8023
  });
7694
8024
  }
@@ -8383,11 +8713,55 @@ var ServiceRegistry = class _ServiceRegistry {
8383
8713
  if (instance.isFrontend) {
8384
8714
  return role === "public";
8385
8715
  }
8386
- return Boolean(
8387
- this.selectReadyTransportForInstance(instance, routingContext, role)
8388
- );
8716
+ return Boolean(
8717
+ this.selectReadyTransportForInstance(instance, routingContext, role)
8718
+ );
8719
+ });
8720
+ }
8721
+ hasPendingRouteableInstanceForSelection(serviceName, ctx, role, targetServiceInstanceId) {
8722
+ return (this.instances.get(serviceName) ?? []).some((instance) => {
8723
+ if (targetServiceInstanceId && instance.uuid !== targetServiceInstanceId) {
8724
+ return false;
8725
+ }
8726
+ if (!instance.isActive || instance.isNonResponsive || instance.isBlocked) {
8727
+ return false;
8728
+ }
8729
+ if (instance.isFrontend) {
8730
+ return false;
8731
+ }
8732
+ const transport = this.selectTransportForInstance(instance, ctx, role);
8733
+ if (!transport) {
8734
+ return false;
8735
+ }
8736
+ return !this.hasTransportClientReady(instance, transport);
8389
8737
  });
8390
8738
  }
8739
+ maybeSchedulePendingRouteSelectionRetry(ctx, serviceName) {
8740
+ const signalName = String(
8741
+ ctx.__signalName ?? ctx.__signalEmission?.fullSignalName ?? ""
8742
+ ).trim();
8743
+ if (!signalName) {
8744
+ return false;
8745
+ }
8746
+ const attempt = Math.max(
8747
+ 0,
8748
+ Number(ctx.__pendingRouteSelectionAttempt ?? 0) || 0
8749
+ );
8750
+ const delayMs = PENDING_ROUTE_SELECTION_RETRY_DELAYS_MS[attempt];
8751
+ if (delayMs === void 0) {
8752
+ return false;
8753
+ }
8754
+ CadenzaService.schedule(
8755
+ signalName,
8756
+ {
8757
+ ...ctx,
8758
+ __pendingRouteSelectionAttempt: attempt + 1,
8759
+ __pendingRouteSelectionServiceName: serviceName
8760
+ },
8761
+ delayMs
8762
+ );
8763
+ return true;
8764
+ }
8391
8765
  refreshRoutingCooldownsForService(serviceName) {
8392
8766
  if (!serviceName) {
8393
8767
  return;
@@ -9207,8 +9581,8 @@ var ServiceRegistry = class _ServiceRegistry {
9207
9581
  this.refreshRoutingCooldownsForService(serviceName);
9208
9582
  }
9209
9583
  clearTransportReadyFromContext(ctx) {
9210
- const serviceName = String(ctx.serviceName ?? "").trim();
9211
- const explicitRouteKey = String(ctx.routeKey ?? "").trim() || parseTransportHandleKey(ctx.fetchId ?? ctx.__fetchId)?.routeKey || "";
9584
+ const serviceName = resolveServiceNameFromContext(ctx);
9585
+ const explicitRouteKey = String(ctx.routeKey ?? ctx.__routeKey ?? "").trim() || parseTransportHandleKey(ctx.fetchId ?? ctx.__fetchId)?.routeKey || "";
9212
9586
  const serviceTransportId = String(
9213
9587
  ctx.serviceTransportId ?? ctx.__transportId ?? ""
9214
9588
  ).trim();
@@ -10803,6 +11177,10 @@ var ServiceRegistry = class _ServiceRegistry {
10803
11177
  this.bootstrapFullSyncRetryGeneration = 0;
10804
11178
  this.bootstrapFullSyncSatisfied = false;
10805
11179
  this.bootstrapFullSyncRetryReason = null;
11180
+ this.clearAuthorityBootstrapHandshakeRetryTimer();
11181
+ this.authorityBootstrapHandshakeRetryIndex = 0;
11182
+ this.authorityBootstrapHandshakeRetryGeneration = 0;
11183
+ this.authorityBootstrapHandshakeRetryReason = null;
10806
11184
  this.knownGlobalSignalMaps.clear();
10807
11185
  this.authorityBootstrapRoute = {
10808
11186
  origin: null,
@@ -13238,163 +13616,6 @@ var SocketController = class _SocketController {
13238
13616
  }
13239
13617
  };
13240
13618
 
13241
- // src/execution/ExecutionPersistenceCoordinator.ts
13242
- var EXECUTION_PERSISTENCE_BUNDLE_SIGNAL = "global.meta.execution_persistence.bundle_requested";
13243
- function readString(value) {
13244
- return typeof value === "string" && value.trim().length > 0 ? value : null;
13245
- }
13246
- function readRecord(value) {
13247
- return value && typeof value === "object" && !Array.isArray(value) ? { ...value } : null;
13248
- }
13249
- function normalizeRoutineExecutionTraceFields(data) {
13250
- if (!data) {
13251
- return null;
13252
- }
13253
- const normalizedData = { ...data };
13254
- const traceId = readString(
13255
- normalizedData.execution_trace_id ?? normalizedData.executionTraceId
13256
- );
13257
- const metaContext = readRecord(normalizedData.meta_context) ?? readRecord(normalizedData.metaContext);
13258
- const isMeta = normalizedData.is_meta === true || normalizedData.isMeta === true;
13259
- const serviceName = readString(
13260
- normalizedData.service_name ?? normalizedData.serviceName
13261
- );
13262
- const serviceInstanceId = readString(
13263
- normalizedData.service_instance_id ?? normalizedData.serviceInstanceId
13264
- );
13265
- if (traceId) {
13266
- normalizedData.execution_trace_id = traceId;
13267
- }
13268
- if (metaContext) {
13269
- normalizedData.meta_context = metaContext;
13270
- }
13271
- if (normalizedData.is_meta !== void 0 || normalizedData.isMeta !== void 0) {
13272
- normalizedData.is_meta = isMeta;
13273
- }
13274
- if (serviceName) {
13275
- normalizedData.service_name = serviceName;
13276
- }
13277
- if (serviceInstanceId) {
13278
- normalizedData.service_instance_id = serviceInstanceId;
13279
- } else if (normalizedData.serviceInstanceId === null || normalizedData.service_instance_id === null) {
13280
- normalizedData.service_instance_id = null;
13281
- }
13282
- delete normalizedData.executionTraceId;
13283
- delete normalizedData.traceId;
13284
- delete normalizedData.metaContext;
13285
- delete normalizedData.isMeta;
13286
- delete normalizedData.serviceName;
13287
- delete normalizedData.serviceInstanceId;
13288
- return normalizedData;
13289
- }
13290
- function stripExecutionTraceServiceInstanceFields(data) {
13291
- if (!data) {
13292
- return null;
13293
- }
13294
- const normalizedData = { ...data };
13295
- delete normalizedData.serviceInstanceId;
13296
- delete normalizedData.service_instance_id;
13297
- return normalizedData;
13298
- }
13299
- function normalizeEnsureData(entityType, data) {
13300
- switch (entityType) {
13301
- case "execution_trace":
13302
- return stripExecutionTraceServiceInstanceFields(data);
13303
- case "routine_execution":
13304
- return normalizeRoutineExecutionTraceFields(data);
13305
- default:
13306
- return data;
13307
- }
13308
- }
13309
- function buildExecutionPersistenceDependency(entityType, entityId) {
13310
- const normalizedEntityId = readString(entityId);
13311
- return normalizedEntityId ? `${entityType}:${normalizedEntityId}` : null;
13312
- }
13313
- function resolveEnsureEntityId(entityType, data) {
13314
- switch (entityType) {
13315
- default:
13316
- return readString(data.uuid);
13317
- }
13318
- }
13319
- function resolveUpdateEntityId(_entityType, data, filter) {
13320
- return readString(
13321
- filter.uuid ?? filter.taskExecutionId ?? filter.task_execution_id ?? data.uuid ?? data.taskExecutionId ?? data.task_execution_id
13322
- );
13323
- }
13324
- function dedupeDependencies(values) {
13325
- return Array.from(
13326
- new Set(values.filter((value) => typeof value === "string"))
13327
- );
13328
- }
13329
- function resolveTraceIdFromData(data) {
13330
- if (!data) {
13331
- return null;
13332
- }
13333
- return readString(
13334
- data.traceId ?? data.executionTraceId ?? data.execution_trace_id ?? data.metaContext?.__executionTraceId ?? data.metaContext?.__metadata?.__executionTraceId ?? data.meta_context?.__executionTraceId ?? data.meta_context?.__metadata?.__executionTraceId
13335
- );
13336
- }
13337
- function buildExecutionPersistenceEnsureEvent(entityType, data, deps = []) {
13338
- const normalizedData = normalizeEnsureData(entityType, readRecord(data));
13339
- if (!normalizedData) {
13340
- return null;
13341
- }
13342
- const entityId = resolveEnsureEntityId(entityType, normalizedData);
13343
- if (!entityId) {
13344
- return null;
13345
- }
13346
- return {
13347
- kind: "ensure",
13348
- entityType,
13349
- entityId,
13350
- data: normalizedData,
13351
- deps: dedupeDependencies(deps)
13352
- };
13353
- }
13354
- function buildExecutionPersistenceUpdateEvent(entityType, data, filter, deps = []) {
13355
- const normalizedData = readRecord(data);
13356
- const normalizedFilter = readRecord(filter);
13357
- if (!normalizedData || !normalizedFilter) {
13358
- return null;
13359
- }
13360
- const entityId = resolveUpdateEntityId(
13361
- entityType,
13362
- normalizedData,
13363
- normalizedFilter
13364
- );
13365
- if (!entityId) {
13366
- return null;
13367
- }
13368
- return {
13369
- kind: "update",
13370
- entityType,
13371
- entityId,
13372
- data: normalizedData,
13373
- filter: normalizedFilter,
13374
- deps: dedupeDependencies(deps)
13375
- };
13376
- }
13377
- function createExecutionPersistenceBundle(input) {
13378
- const ensures = (input.ensures ?? []).filter(
13379
- (event) => Boolean(event)
13380
- );
13381
- const updates = (input.updates ?? []).filter(
13382
- (event) => Boolean(event)
13383
- );
13384
- if (ensures.length === 0 && updates.length === 0) {
13385
- return null;
13386
- }
13387
- const traceId = readString(input.traceId) ?? ensures.map((event) => resolveTraceIdFromData(event.data)).find((value) => Boolean(value)) ?? updates.map((event) => resolveTraceIdFromData(event.data)).find((value) => Boolean(value));
13388
- if (!traceId) {
13389
- return null;
13390
- }
13391
- return {
13392
- traceId,
13393
- ensures,
13394
- updates
13395
- };
13396
- }
13397
-
13398
13619
  // src/signals/SignalController.ts
13399
13620
  var import_uuid5 = require("uuid");
13400
13621
  function resolveExecutionObservabilityServiceInstanceId() {
@@ -13547,7 +13768,7 @@ var SignalController = class _SignalController {
13547
13768
  intent: traceContext.__metadata?.__intent ?? traceContext.__intent ?? null,
13548
13769
  context: {
13549
13770
  id: (0, import_uuid5.v4)(),
13550
- context: traceContext
13771
+ context: sanitizedTraceContext
13551
13772
  },
13552
13773
  is_meta: signalEmission.isMeta,
13553
13774
  service_name: CadenzaService.serviceRegistry.serviceName,
@@ -14137,6 +14358,18 @@ function registerActorSessionPersistenceTasks() {
14137
14358
  var import_core5 = require("@cadenza.io/core");
14138
14359
  var import_uuid6 = require("uuid");
14139
14360
  var ACTOR_TASK_METADATA2 = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
14361
+ var ROUTING_CRITICAL_META_INTENTS2 = /* @__PURE__ */ new Set([
14362
+ AUTHORITY_BOOTSTRAP_FULL_SYNC_INTENT,
14363
+ AUTHORITY_SERVICE_INSTANCE_REGISTER_INTENT,
14364
+ AUTHORITY_SERVICE_INSTANCE_TRANSPORT_REGISTER_INTENT,
14365
+ AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
14366
+ AUTHORITY_RUNTIME_STATUS_REPORT_INTENT
14367
+ ]);
14368
+ var ROUTING_CRITICAL_META_SIGNALS2 = /* @__PURE__ */ new Set([
14369
+ AUTHORITY_SERVICE_MANIFEST_UPDATED_SIGNAL,
14370
+ EXECUTION_PERSISTENCE_BUNDLE_SIGNAL,
14371
+ ...AUTHORITY_BOOTSTRAP_SIGNAL_NAMES
14372
+ ]);
14140
14373
  function getActorTaskRuntimeMetadata2(taskFunction) {
14141
14374
  if (typeof taskFunction !== "function") {
14142
14375
  return void 0;
@@ -14228,7 +14461,7 @@ function buildIntentRegistryData(intent) {
14228
14461
  };
14229
14462
  }
14230
14463
  function isLocalOnlySyncIntent(intentName) {
14231
- return intentName === import_core5.META_ACTOR_SESSION_STATE_PERSIST_INTENT;
14464
+ return intentName === import_core5.META_ACTOR_SESSION_STATE_PERSIST_INTENT || intentName.startsWith("meta-") || intentName.startsWith("global.meta-");
14232
14465
  }
14233
14466
  function getJoinedContextValue(ctx, key) {
14234
14467
  const joinedContexts = Array.isArray(ctx.joinedContexts) ? ctx.joinedContexts : [];
@@ -14268,6 +14501,32 @@ function buildMinimalSyncSignalContext(ctx, extra = {}) {
14268
14501
  }
14269
14502
  return nextContext;
14270
14503
  }
14504
+ function buildMinimalSyncShardContext(ctx, extra = {}) {
14505
+ return {
14506
+ ...buildMinimalSyncSignalContext(ctx, extra),
14507
+ tasks: void 0,
14508
+ signals: void 0,
14509
+ intents: void 0,
14510
+ actors: void 0,
14511
+ routines: void 0,
14512
+ serviceInstances: void 0,
14513
+ service_instance_rows: void 0,
14514
+ service_instance_transport_rows: void 0,
14515
+ serviceManifests: void 0,
14516
+ manifests: void 0,
14517
+ signalToTaskMaps: void 0,
14518
+ signal_to_task_maps: void 0,
14519
+ intentToTaskMaps: void 0,
14520
+ intent_to_task_maps: void 0,
14521
+ actorTaskMaps: void 0,
14522
+ actor_task_maps: void 0,
14523
+ directionalTaskMaps: void 0,
14524
+ directional_task_maps: void 0,
14525
+ taskToRoutineMaps: void 0,
14526
+ task_to_routine_maps: void 0,
14527
+ task: void 0
14528
+ };
14529
+ }
14271
14530
  function buildSyncInsertQueryData(ctx, queryData = {}) {
14272
14531
  const pickQueryData = (source, allowedKeys) => {
14273
14532
  const next = {};
@@ -14305,7 +14564,40 @@ var DEFAULT_SYNC_CYCLE_RUNTIME_STATE = {
14305
14564
  activeSyncCycleStartedAt: 0,
14306
14565
  phase: "idle"
14307
14566
  };
14308
- var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 15;
14567
+ var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 2;
14568
+ function stripSyncResolverPayload(ctx) {
14569
+ const nextContext = {
14570
+ ...ctx
14571
+ };
14572
+ const bulkyStructuralKeys = [
14573
+ "tasks",
14574
+ "helpers",
14575
+ "globals",
14576
+ "signals",
14577
+ "intents",
14578
+ "actors",
14579
+ "routines",
14580
+ "serviceInstances",
14581
+ "serviceInstanceTransports",
14582
+ "serviceManifests",
14583
+ "signalToTaskMaps",
14584
+ "intentToTaskMaps",
14585
+ "actorTaskMaps",
14586
+ "directionalTaskMaps",
14587
+ "taskToRoutineMaps",
14588
+ "registeredGlobalSignals",
14589
+ "registeredGlobalIntents",
14590
+ "registeredActors",
14591
+ "registeredRoutines"
14592
+ ];
14593
+ delete nextContext.__resolverOriginalContext;
14594
+ delete nextContext.__resolverQueryData;
14595
+ delete nextContext.joinedContexts;
14596
+ for (const key of bulkyStructuralKeys) {
14597
+ delete nextContext[key];
14598
+ }
14599
+ return nextContext;
14600
+ }
14309
14601
  function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
14310
14602
  if (!graph) {
14311
14603
  return void 0;
@@ -14317,28 +14609,14 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
14317
14609
  return graph.completionTask;
14318
14610
  }
14319
14611
  function buildSyncExecutionEnvelope(ctx, queryData) {
14320
- const originalContext = { ...ctx };
14612
+ const originalContext = stripSyncResolverPayload(ctx);
14321
14613
  const syncSourceServiceName = typeof ctx.__syncSourceServiceName === "string" && ctx.__syncSourceServiceName.trim().length > 0 ? ctx.__syncSourceServiceName : typeof ctx.__serviceName === "string" && ctx.__serviceName.trim().length > 0 ? ctx.__serviceName : resolveSyncServiceName();
14322
- const rootDbOperationFields = {};
14323
- for (const key of [
14324
- "data",
14325
- "batch",
14326
- "transaction",
14327
- "onConflict",
14328
- "filter",
14329
- "fields"
14330
- ]) {
14331
- if (Object.prototype.hasOwnProperty.call(queryData, key)) {
14332
- rootDbOperationFields[key] = queryData[key];
14333
- }
14334
- }
14335
14614
  const nextContext = {
14336
14615
  __syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
14337
14616
  __syncSourceServiceName: syncSourceServiceName,
14338
14617
  __preferredTransportProtocol: "rest",
14339
14618
  __resolverOriginalContext: originalContext,
14340
14619
  __resolverQueryData: queryData,
14341
- ...rootDbOperationFields,
14342
14620
  queryData
14343
14621
  };
14344
14622
  if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
@@ -14357,6 +14635,7 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
14357
14635
  Number(options.concurrency),
14358
14636
  REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY
14359
14637
  ) : REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY,
14638
+ timeout: Number(options.timeout) > 0 ? Number(options.timeout) : 6e4,
14360
14639
  register: false,
14361
14640
  isHidden: true
14362
14641
  });
@@ -14396,13 +14675,15 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
14396
14675
  const finalizeExecutionTask = CadenzaService.createMetaTask(
14397
14676
  `Finalize graph sync insert for ${tableName}`,
14398
14677
  (ctx) => {
14399
- const originalContext = ctx.__resolverOriginalContext && typeof ctx.__resolverOriginalContext === "object" ? ctx.__resolverOriginalContext : {};
14678
+ const originalContext = ctx.__resolverOriginalContext && typeof ctx.__resolverOriginalContext === "object" ? stripSyncResolverPayload(
14679
+ ctx.__resolverOriginalContext
14680
+ ) : {};
14400
14681
  const originalQueryData = ctx.__resolverQueryData && typeof ctx.__resolverQueryData === "object" ? ctx.__resolverQueryData : void 0;
14401
- const normalizedContext = {
14682
+ const normalizedContext = stripSyncResolverPayload({
14402
14683
  ...originalContext,
14403
14684
  ...ctx,
14404
14685
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
14405
- };
14686
+ });
14406
14687
  if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
14407
14688
  CadenzaService.debounce("meta.sync_requested", {}, 1e3);
14408
14689
  }
@@ -14476,22 +14757,103 @@ function isBootstrapLocalOnlySignal(signalName) {
14476
14757
  function hasNonZeroPending(summary) {
14477
14758
  return Object.values(summary).some((value) => Number(value) > 0);
14478
14759
  }
14760
+ function shouldSkipIdleBootstrapSyncTrigger(input) {
14761
+ if (input?.__forceSyncCycle === true) {
14762
+ return false;
14763
+ }
14764
+ const triggerSignal = typeof input?.__signal === "string" ? input.__signal.trim() : "";
14765
+ const reason = typeof input?.__reason === "string" ? input.__reason.trim() : "";
14766
+ if (!triggerSignal) {
14767
+ return input?.__bootstrapFullSync === true || reason.length > 0;
14768
+ }
14769
+ return triggerSignal === "meta.sync_controller.sync_tick" || triggerSignal === "meta.sync_requested";
14770
+ }
14479
14771
  function isRegistrableRoutine(routine) {
14480
14772
  return routine?.name !== "RestServer";
14481
14773
  }
14482
14774
  function scheduleSyncPassEvaluation(delayMs = SYNC_PASS_SETTLE_DELAY_MS) {
14483
14775
  CadenzaService.debounce(SYNC_PASS_EVALUATION_SIGNAL, {}, delayMs);
14484
14776
  }
14777
+ function isRoutingCriticalMetaSignalName(signalName) {
14778
+ return ROUTING_CRITICAL_META_SIGNALS2.has(canonicalizeSignalName2(signalName));
14779
+ }
14780
+ function isRoutingCriticalMetaIntentName(intentName) {
14781
+ return ROUTING_CRITICAL_META_INTENTS2.has(String(intentName ?? "").trim());
14782
+ }
14783
+ function isRoutingCapabilityBootstrapSignalName(signalName) {
14784
+ const canonicalSignalName = canonicalizeSignalName2(signalName);
14785
+ if (!canonicalSignalName) {
14786
+ return false;
14787
+ }
14788
+ const signalParts = decomposeSignalName(canonicalSignalName);
14789
+ if (!signalParts.isGlobal) {
14790
+ return false;
14791
+ }
14792
+ if (signalParts.isMeta) {
14793
+ return isRoutingCriticalMetaSignalName(canonicalSignalName);
14794
+ }
14795
+ return !isBootstrapLocalOnlySignal(canonicalSignalName);
14796
+ }
14797
+ function isRouteableBusinessBootstrapSignalName(signalName) {
14798
+ const canonicalSignalName = canonicalizeSignalName2(signalName);
14799
+ if (!canonicalSignalName) {
14800
+ return false;
14801
+ }
14802
+ const signalParts = decomposeSignalName(canonicalSignalName);
14803
+ if (!signalParts.isGlobal || signalParts.isMeta) {
14804
+ return false;
14805
+ }
14806
+ return !isBootstrapLocalOnlySignal(canonicalSignalName);
14807
+ }
14808
+ function isRouteableBusinessBootstrapIntentName(intentName) {
14809
+ const normalizedIntentName = String(intentName ?? "").trim();
14810
+ return normalizedIntentName.length > 0 && !isLocalOnlySyncIntent(normalizedIntentName) && !isMetaIntentName(normalizedIntentName);
14811
+ }
14812
+ function isRoutingCapabilityBootstrapTask(task) {
14813
+ if (!task || !task.register || task.isHidden || task.isDeputy) {
14814
+ return false;
14815
+ }
14816
+ const isMetaTask = task.isMeta === true || task.isSubMeta === true;
14817
+ for (const signalName of task.observedSignals) {
14818
+ if (isMetaTask ? isRoutingCriticalMetaSignalName(signalName) : isRouteableBusinessBootstrapSignalName(signalName)) {
14819
+ return true;
14820
+ }
14821
+ }
14822
+ for (const intentName of task.handlesIntents) {
14823
+ if (isMetaTask ? isRoutingCriticalMetaIntentName(intentName) : isRouteableBusinessBootstrapIntentName(intentName)) {
14824
+ return true;
14825
+ }
14826
+ }
14827
+ return false;
14828
+ }
14829
+ function shouldDirectSyncSignalTaskMapForBootstrap(task, signalName) {
14830
+ const canonicalSignalName = canonicalizeSignalName2(signalName);
14831
+ if (!task || !canonicalSignalName || task.isHidden || !task.register || !task.registered) {
14832
+ return false;
14833
+ }
14834
+ if (!decomposeSignalName(canonicalSignalName).isGlobal) {
14835
+ return false;
14836
+ }
14837
+ if (!isRegistrableBootstrapTask(task)) {
14838
+ return false;
14839
+ }
14840
+ return isRoutingCapabilityBootstrapSignalName(canonicalSignalName);
14841
+ }
14842
+ function isRegistrableBootstrapTask(task) {
14843
+ return isRoutingCapabilityBootstrapTask(task);
14844
+ }
14485
14845
  function getRegistrableTasks() {
14486
14846
  return Array.from(CadenzaService.registry.tasks.values()).filter(
14487
- (task) => task.register && !task.isHidden && !task.isDeputy
14847
+ isRegistrableBootstrapTask
14488
14848
  );
14489
14849
  }
14490
14850
  function getBootstrapBlockingTasks() {
14491
- return getRegistrableTasks().filter((task) => task.isMeta !== true);
14851
+ return getRegistrableTasks();
14492
14852
  }
14493
14853
  function getRegistrableRoutines() {
14494
- return Array.from(CadenzaService.registry.routines.values()).filter(isRegistrableRoutine);
14854
+ return Array.from(CadenzaService.registry.routines.values()).filter(
14855
+ isRegistrableRoutine
14856
+ );
14495
14857
  }
14496
14858
  function getRegistrableSignalObservers() {
14497
14859
  const signalObservers = CadenzaService.signalBroker.signalObservers;
@@ -14501,19 +14863,23 @@ function getRegistrableSignalObservers() {
14501
14863
  const canonicalObservers = /* @__PURE__ */ new Map();
14502
14864
  for (const [rawSignalName, observer] of signalObservers.entries()) {
14503
14865
  const signalName = canonicalizeSignalName2(rawSignalName);
14504
- if (!signalName || isBootstrapLocalOnlySignal(signalName)) {
14866
+ const isRoutingCriticalMetaSignal2 = signalName.length > 0 && isRoutingCriticalMetaSignalName(signalName);
14867
+ if (!signalName || isBootstrapLocalOnlySignal(signalName) && !isRoutingCriticalMetaSignal2) {
14868
+ continue;
14869
+ }
14870
+ if (!decomposeSignalName(signalName).isGlobal) {
14505
14871
  continue;
14506
14872
  }
14507
14873
  const observerTasks = Array.isArray(observer?.tasks) ? observer.tasks : observer?.tasks instanceof Set ? Array.from(observer.tasks) : [];
14508
- if (observerTasks.length > 0 && !observerTasks.some(
14509
- (task) => task?.register && !task.isHidden && !task.isDeputy
14510
- )) {
14874
+ if (observerTasks.length > 0 && !observerTasks.some((task) => isRegistrableBootstrapTask(task))) {
14511
14875
  continue;
14512
14876
  }
14877
+ const metadata = CadenzaService.signalBroker.getSignalMetadata(signalName) ?? null;
14513
14878
  const existing = canonicalObservers.get(signalName);
14514
14879
  canonicalObservers.set(signalName, {
14515
14880
  signalName,
14516
- registered: existing?.registered === true || observer?.registered === true
14881
+ registered: existing?.registered === true || observer?.registered === true,
14882
+ metadata: existing?.metadata ?? metadata
14517
14883
  });
14518
14884
  }
14519
14885
  return Array.from(canonicalObservers.values());
@@ -14524,7 +14890,10 @@ function isLocallyHandledIntentName(intentName) {
14524
14890
  return false;
14525
14891
  }
14526
14892
  for (const task of observer.tasks) {
14527
- if (task.register && !task.isHidden && !task.isDeputy) {
14893
+ if (!task) {
14894
+ continue;
14895
+ }
14896
+ if (isRegistrableBootstrapTask(task)) {
14528
14897
  return true;
14529
14898
  }
14530
14899
  }
@@ -14555,8 +14924,12 @@ function buildActorRegistrationKey(actor, serviceName) {
14555
14924
  return `${name}|${data.version}|${serviceName}`;
14556
14925
  }
14557
14926
  function isBootstrapRegistrableActor(actor) {
14558
- const actorName = String(buildActorRegistrationData(actor).name ?? "").trim();
14559
- return actorName.length > 0 && !isBootstrapLocalOnlyActorName(actorName);
14927
+ const actorData = buildActorRegistrationData(actor);
14928
+ const actorName = String(actorData.name ?? "").trim();
14929
+ if (!actorName || isBootstrapLocalOnlyActorName(actorName)) {
14930
+ return false;
14931
+ }
14932
+ return false;
14560
14933
  }
14561
14934
  function buildSignalTaskMapRegistrationKey(input) {
14562
14935
  return `${canonicalizeSignalName2(input.signalName)}|${input.serviceName}|${input.taskName}|${input.taskVersion ?? 1}`;
@@ -14723,6 +15096,7 @@ function resolveSignalNameFromSyncContext(ctx) {
14723
15096
  var GraphSyncController = class _GraphSyncController {
14724
15097
  constructor() {
14725
15098
  this.registeredActors = /* @__PURE__ */ new Set();
15099
+ this.requestedActorRegistrations = /* @__PURE__ */ new Set();
14726
15100
  this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
14727
15101
  this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
14728
15102
  this.authoritativeSignalTaskMaps = /* @__PURE__ */ new Set();
@@ -15051,9 +15425,10 @@ var GraphSyncController = class _GraphSyncController {
15051
15425
  for (const routine of routines) {
15052
15426
  if (!isRegistrableRoutine(routine)) continue;
15053
15427
  if (routine.registered) continue;
15428
+ if (routine.registrationRequested === true) continue;
15429
+ routine.registrationRequested = true;
15054
15430
  this.routinesSynced = false;
15055
- yield {
15056
- __syncing: ctx.__syncing,
15431
+ yield buildMinimalSyncShardContext(ctx, {
15057
15432
  data: {
15058
15433
  name: routine.name,
15059
15434
  version: routine.version,
@@ -15062,7 +15437,7 @@ var GraphSyncController = class _GraphSyncController {
15062
15437
  is_meta: routine.isMeta
15063
15438
  },
15064
15439
  __routineName: routine.name
15065
- };
15440
+ });
15066
15441
  }
15067
15442
  }.bind(this)
15068
15443
  );
@@ -15080,15 +15455,19 @@ var GraphSyncController = class _GraphSyncController {
15080
15455
  { concurrency: 30 }
15081
15456
  );
15082
15457
  const registerRoutineTask = CadenzaService.createMetaTask("Register routine", (ctx) => {
15458
+ const routine = resolveLocalRoutineFromSyncContext(ctx);
15083
15459
  if (!didSyncInsertSucceed(ctx)) {
15460
+ if (routine) {
15461
+ routine.registrationRequested = false;
15462
+ }
15084
15463
  return;
15085
15464
  }
15086
15465
  scheduleSyncPassEvaluation();
15087
- const routine = resolveLocalRoutineFromSyncContext(ctx);
15088
15466
  if (!routine) {
15089
15467
  return true;
15090
15468
  }
15091
15469
  routine.registered = true;
15470
+ routine.registrationRequested = false;
15092
15471
  return true;
15093
15472
  }).then(gatherRoutineRegistrationTask);
15094
15473
  wireSyncTaskGraph(this.splitRoutinesTask, routineRegistrationGraph, registerRoutineTask);
@@ -15115,8 +15494,7 @@ var GraphSyncController = class _GraphSyncController {
15115
15494
  if (!nextTask?.registered) {
15116
15495
  continue;
15117
15496
  }
15118
- yield {
15119
- __syncing: ctx.__syncing,
15497
+ yield buildMinimalSyncShardContext(ctx, {
15120
15498
  data: {
15121
15499
  task_name: nextTask.name,
15122
15500
  task_version: nextTask.version,
@@ -15126,7 +15504,7 @@ var GraphSyncController = class _GraphSyncController {
15126
15504
  },
15127
15505
  __routineName: routine.name,
15128
15506
  __taskName: nextTask.name
15129
- };
15507
+ });
15130
15508
  }
15131
15509
  }
15132
15510
  }
@@ -15180,7 +15558,8 @@ var GraphSyncController = class _GraphSyncController {
15180
15558
  signalName: canonicalizeSignalName2(signal.signal),
15181
15559
  data: signal.data
15182
15560
  })).filter((signal) => {
15183
- if (!signal.signalName || signal.data?.registered || isBootstrapLocalOnlySignal(signal.signalName)) {
15561
+ const isRoutingCriticalMetaSignal2 = isRoutingCriticalMetaSignalName(signal.signalName);
15562
+ if (!signal.signalName || signal.data?.registered || isBootstrapLocalOnlySignal(signal.signalName) && !isRoutingCriticalMetaSignal2 || signal.data?.metadata?.is_meta === true && !isRoutingCriticalMetaSignal2) {
15184
15563
  return false;
15185
15564
  }
15186
15565
  if (seenSignals.has(signal.signalName)) {
@@ -15190,10 +15569,20 @@ var GraphSyncController = class _GraphSyncController {
15190
15569
  return true;
15191
15570
  }).map((signal) => signal.signalName);
15192
15571
  for (const signal of filteredSignals) {
15572
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
15573
+ if (!signalObservers?.has(signal)) {
15574
+ CadenzaService.signalBroker.addSignal(signal);
15575
+ }
15576
+ const observer = signalObservers?.get(signal);
15577
+ if (observer?.registrationRequested === true) {
15578
+ continue;
15579
+ }
15580
+ if (observer) {
15581
+ observer.registrationRequested = true;
15582
+ }
15193
15583
  const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
15194
15584
  this.signalsSynced = false;
15195
- yield {
15196
- __syncing: ctx.__syncing,
15585
+ yield buildMinimalSyncShardContext(ctx, {
15197
15586
  data: {
15198
15587
  name: signal,
15199
15588
  is_global: isGlobal,
@@ -15202,7 +15591,7 @@ var GraphSyncController = class _GraphSyncController {
15202
15591
  is_meta: isMeta
15203
15592
  },
15204
15593
  __signal: signal
15205
- };
15594
+ });
15206
15595
  }
15207
15596
  }.bind(this)
15208
15597
  );
@@ -15224,21 +15613,25 @@ var GraphSyncController = class _GraphSyncController {
15224
15613
  (ctx, emit2) => {
15225
15614
  const insertSucceeded = didSyncInsertSucceed(ctx);
15226
15615
  const signalName = resolveSignalNameFromSyncContext(ctx);
15616
+ const signalObservers = CadenzaService.signalBroker.signalObservers;
15617
+ const observer = signalName ? signalObservers?.get(signalName) : void 0;
15227
15618
  if (!insertSucceeded) {
15619
+ if (observer) {
15620
+ observer.registrationRequested = false;
15621
+ }
15228
15622
  return;
15229
15623
  }
15230
15624
  scheduleSyncPassEvaluation();
15231
15625
  if (!signalName) {
15232
15626
  return false;
15233
15627
  }
15234
- const signalObservers = CadenzaService.signalBroker.signalObservers;
15235
15628
  if (!signalObservers?.has(signalName)) {
15236
15629
  CadenzaService.signalBroker.addSignal(signalName);
15237
15630
  }
15238
- const observer = signalObservers?.get(signalName);
15239
- if (observer) {
15240
- observer.registered = true;
15241
- observer.registrationRequested = false;
15631
+ const resolvedObserver = signalObservers?.get(signalName);
15632
+ if (resolvedObserver) {
15633
+ resolvedObserver.registered = true;
15634
+ resolvedObserver.registrationRequested = false;
15242
15635
  }
15243
15636
  emit2(
15244
15637
  "meta.sync_controller.signal_registered",
@@ -15318,8 +15711,13 @@ var GraphSyncController = class _GraphSyncController {
15318
15711
  return;
15319
15712
  }
15320
15713
  for (const task of tasks) {
15321
- if (task.hidden || !task.register || task.isDeputy) continue;
15714
+ if (!task) {
15715
+ continue;
15716
+ }
15717
+ if (!isRegistrableBootstrapTask(task)) continue;
15322
15718
  if (task.registered) continue;
15719
+ if (task.registrationRequested === true) continue;
15720
+ task.registrationRequested = true;
15323
15721
  const { __functionString, __getTagCallback } = task.export();
15324
15722
  this.tasksSynced = false;
15325
15723
  const taskRegistrationData = sanitizePersistedTaskSourceFields(task, {
@@ -15354,11 +15752,10 @@ var GraphSyncController = class _GraphSyncController {
15354
15752
  },
15355
15753
  intents: Array.from(task.handlesIntents)
15356
15754
  });
15357
- yield {
15358
- __syncing: ctx.__syncing,
15755
+ yield buildMinimalSyncShardContext(ctx, {
15359
15756
  data: taskRegistrationData,
15360
15757
  __taskName: task.name
15361
- };
15758
+ });
15362
15759
  }
15363
15760
  }.bind(this)
15364
15761
  );
@@ -15379,9 +15776,11 @@ var GraphSyncController = class _GraphSyncController {
15379
15776
  "Record registration",
15380
15777
  (ctx, emit2) => {
15381
15778
  const task = resolveLocalTaskFromSyncContext(ctx);
15382
- const serviceName2 = resolveSyncServiceName(task);
15383
15779
  const insertSucceeded = didSyncInsertSucceed(ctx);
15384
15780
  if (!insertSucceeded) {
15781
+ if (task) {
15782
+ task.registrationRequested = false;
15783
+ }
15385
15784
  return;
15386
15785
  }
15387
15786
  scheduleSyncPassEvaluation();
@@ -15423,11 +15822,15 @@ var GraphSyncController = class _GraphSyncController {
15423
15822
  if (this.registeredActors.has(registrationKey)) {
15424
15823
  continue;
15425
15824
  }
15825
+ if (this.requestedActorRegistrations.has(registrationKey)) {
15826
+ continue;
15827
+ }
15828
+ this.requestedActorRegistrations.add(registrationKey);
15426
15829
  this.actorsSynced = false;
15427
- yield {
15830
+ yield buildMinimalSyncShardContext(ctx, {
15428
15831
  data,
15429
15832
  __actorRegistrationKey: registrationKey
15430
- };
15833
+ });
15431
15834
  }
15432
15835
  }.bind(this)
15433
15836
  );
@@ -15447,11 +15850,18 @@ var GraphSyncController = class _GraphSyncController {
15447
15850
  const recordActorRegistrationTask = CadenzaService.createMetaTask(
15448
15851
  "Record actor registration",
15449
15852
  (ctx) => {
15853
+ const registrationKey = typeof ctx.__actorRegistrationKey === "string" ? ctx.__actorRegistrationKey : "";
15450
15854
  if (!didSyncInsertSucceed(ctx)) {
15855
+ if (registrationKey) {
15856
+ this.requestedActorRegistrations.delete(registrationKey);
15857
+ }
15451
15858
  return;
15452
15859
  }
15453
15860
  scheduleSyncPassEvaluation();
15454
- this.registeredActors.add(ctx.__actorRegistrationKey);
15861
+ if (registrationKey) {
15862
+ this.requestedActorRegistrations.delete(registrationKey);
15863
+ this.registeredActors.add(registrationKey);
15864
+ }
15455
15865
  return true;
15456
15866
  }
15457
15867
  ).then(gatherActorRegistrationTask);
@@ -15470,17 +15880,95 @@ var GraphSyncController = class _GraphSyncController {
15470
15880
  }
15471
15881
  );
15472
15882
  this.registerSignalToTaskMapTask = CadenzaService.createMetaTask(
15473
- "Defer signal task maps to manifest sync",
15474
- () => {
15475
- scheduleSyncPassEvaluation();
15476
- return false;
15477
- },
15478
- "Signal-task structural maps are derived from service manifests and authority full sync, not persisted incrementally on the hot registration path.",
15883
+ "Register routing-critical signal task maps to DB",
15884
+ function* (ctx) {
15885
+ const task = ctx.task;
15886
+ if (!task) {
15887
+ return;
15888
+ }
15889
+ const serviceName2 = resolveSyncServiceName(task);
15890
+ if (!serviceName2) {
15891
+ return;
15892
+ }
15893
+ for (const signal of task.observedSignals) {
15894
+ const signalName = canonicalizeSignalName2(signal);
15895
+ if (!shouldDirectSyncSignalTaskMapForBootstrap(task, signalName)) {
15896
+ continue;
15897
+ }
15898
+ if (task.registeredSignals.has(signalName)) {
15899
+ continue;
15900
+ }
15901
+ const registrationKey = buildSignalTaskMapRegistrationKey({
15902
+ signalName,
15903
+ serviceName: serviceName2,
15904
+ taskName: task.name,
15905
+ taskVersion: task.version
15906
+ });
15907
+ if (this.authoritativeSignalTaskMaps.has(registrationKey)) {
15908
+ continue;
15909
+ }
15910
+ if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
15911
+ continue;
15912
+ }
15913
+ yield buildMinimalSyncShardContext(ctx, {
15914
+ data: {
15915
+ signal_name: signalName,
15916
+ is_global: true,
15917
+ task_name: task.name,
15918
+ task_version: task.version,
15919
+ service_name: serviceName2
15920
+ },
15921
+ __taskName: task.name,
15922
+ __signalName: signalName
15923
+ });
15924
+ }
15925
+ }.bind(this),
15926
+ "Routing-critical meta signal-task maps are persisted during bootstrap so authority can route required control-plane signals before deferred manifest replay completes.",
15479
15927
  {
15480
15928
  register: false,
15481
15929
  isHidden: true
15482
15930
  }
15483
15931
  );
15932
+ const signalTaskMapRegistrationGraph = resolveSyncInsertTask(
15933
+ this.isCadenzaDBReady,
15934
+ "signal_to_task_map",
15935
+ {
15936
+ onConflict: {
15937
+ target: [
15938
+ "signal_name",
15939
+ "is_global",
15940
+ "task_name",
15941
+ "task_version",
15942
+ "service_name"
15943
+ ],
15944
+ action: {
15945
+ do: "nothing"
15946
+ }
15947
+ }
15948
+ },
15949
+ { concurrency: 30 }
15950
+ );
15951
+ const recordSignalTaskMapRegistrationTask = CadenzaService.createMetaTask(
15952
+ "Record signal task map registration",
15953
+ (ctx) => {
15954
+ if (!didSyncInsertSucceed(ctx)) {
15955
+ return;
15956
+ }
15957
+ scheduleSyncPassEvaluation();
15958
+ const task = CadenzaService.get(ctx.__taskName);
15959
+ const signalName = typeof ctx.__signalName === "string" ? canonicalizeSignalName2(ctx.__signalName) : "";
15960
+ if (!task || !signalName) {
15961
+ return true;
15962
+ }
15963
+ task.registeredSignals.add(signalName);
15964
+ return true;
15965
+ }
15966
+ );
15967
+ wireSyncTaskGraph(
15968
+ this.registerSignalToTaskMapTask,
15969
+ signalTaskMapRegistrationGraph,
15970
+ recordSignalTaskMapRegistrationTask
15971
+ );
15484
15972
  this.splitIntentsTask = CadenzaService.createMetaTask(
15485
15973
  "Split intents for registration",
15486
15974
  function* (ctx) {
@@ -15496,25 +15984,31 @@ var GraphSyncController = class _GraphSyncController {
15496
15984
  if (this.registeredIntentDefinitions.has(intentData.name)) {
15497
15985
  continue;
15498
15986
  }
15987
+ if (intent.registrationRequested === true) {
15988
+ continue;
15989
+ }
15990
+ intent.registrationRequested = true;
15499
15991
  this.intentsSynced = false;
15500
- yield {
15501
- __syncing: ctx.__syncing,
15992
+ yield buildMinimalSyncShardContext(ctx, {
15502
15993
  data: intentData,
15503
15994
  __intentName: intentData.name
15504
- };
15995
+ });
15505
15996
  }
15506
15997
  }.bind(this)
15507
15998
  );
15508
15999
  const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
15509
16000
  "Record intent definition registration",
15510
16001
  (ctx, emit2) => {
16002
+ const intentName = typeof ctx.__intentName === "string" ? ctx.__intentName : "";
16003
+ const intentDefinition = intentName ? CadenzaService.inquiryBroker.intents.get(intentName) ?? null : null;
15511
16004
  if (!didSyncInsertSucceed(ctx)) {
16005
+ if (intentDefinition) {
16006
+ intentDefinition.registrationRequested = false;
16007
+ }
15512
16008
  return;
15513
16009
  }
15514
16010
  scheduleSyncPassEvaluation();
15515
- const intentName = typeof ctx.__intentName === "string" ? ctx.__intentName : "";
15516
16011
  this.registeredIntentDefinitions.add(intentName);
15517
- const intentDefinition = intentName ? CadenzaService.inquiryBroker.intents.get(intentName) ?? null : null;
15518
16012
  if (intentDefinition) {
15519
16013
  intentDefinition.registered = true;
15520
16014
  intentDefinition.registrationRequested = false;
@@ -15774,6 +16268,9 @@ var GraphSyncController = class _GraphSyncController {
15774
16268
  "Register task map to DB",
15775
16269
  function* (ctx) {
15776
16270
  const task = ctx.task;
16271
+ if (!task) {
16272
+ return;
16273
+ }
15777
16274
  if (task.hidden || !task.register || task.isDeputy || !task.registered) {
15778
16275
  return;
15779
16276
  }
@@ -15782,6 +16279,9 @@ var GraphSyncController = class _GraphSyncController {
15782
16279
  return;
15783
16280
  }
15784
16281
  for (const t of task.nextTasks) {
16282
+ if (!t) {
16283
+ continue;
16284
+ }
15785
16285
  if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register || !t.registered || !shouldTrackDirectionalTaskMapForBootstrap(task, t)) {
15786
16286
  continue;
15787
16287
  }
@@ -15789,7 +16289,7 @@ var GraphSyncController = class _GraphSyncController {
15789
16289
  if (!serviceName2) {
15790
16290
  continue;
15791
16291
  }
15792
- yield {
16292
+ yield buildMinimalSyncShardContext(ctx, {
15793
16293
  data: {
15794
16294
  task_name: t.name,
15795
16295
  task_version: t.version,
@@ -15800,7 +16300,7 @@ var GraphSyncController = class _GraphSyncController {
15800
16300
  },
15801
16301
  __taskName: task.name,
15802
16302
  __nextTaskName: t.name
15803
- };
16303
+ });
15804
16304
  }
15805
16305
  }
15806
16306
  );
@@ -16388,19 +16888,6 @@ var GraphSyncController = class _GraphSyncController {
16388
16888
  if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
16389
16889
  return false;
16390
16890
  }
16391
- if (ctx.__bootstrapFullSync === true) {
16392
- if (shouldTraceSyncPhase(serviceName2)) {
16393
- console.log(
16394
- "[CADENZA_SYNC_PHASE_TRACE] sync_cycle_ignored_bootstrap_full_sync",
16395
- {
16396
- serviceName: serviceName2,
16397
- reason: typeof ctx.__reason === "string" ? ctx.__reason : void 0,
16398
- attempt: typeof ctx.__bootstrapFullSyncAttempt === "number" ? ctx.__bootstrapFullSyncAttempt : void 0
16399
- }
16400
- );
16401
- }
16402
- return false;
16403
- }
16404
16891
  if (state.activeSyncCycleId) {
16405
16892
  const activeCycleAgeMs = now - state.activeSyncCycleStartedAt;
16406
16893
  if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
@@ -16427,6 +16914,19 @@ var GraphSyncController = class _GraphSyncController {
16427
16914
  });
16428
16915
  }
16429
16916
  }
16917
+ const primitivePendingSummary = buildPrimitivePendingSummary();
16918
+ const mapPendingSummary = buildMapPendingSummary();
16919
+ const hasPendingWork = hasNonZeroPending(primitivePendingSummary) || hasNonZeroPending(mapPendingSummary);
16920
+ if (!hasPendingWork && shouldSkipIdleBootstrapSyncTrigger(ctx)) {
16921
+ if (shouldTraceSyncPhase(serviceName2)) {
16922
+ console.log("[CADENZA_SYNC_PHASE_TRACE] sync_cycle_skipped_idle", {
16923
+ serviceName: serviceName2,
16924
+ triggerSignal: typeof ctx.__signal === "string" ? ctx.__signal : void 0,
16925
+ reason: typeof ctx.__reason === "string" ? ctx.__reason : void 0
16926
+ });
16927
+ }
16928
+ return false;
16929
+ }
16430
16930
  const syncCycleId = `${now}-${(0, import_uuid6.v4)()}`;
16431
16931
  setRuntimeState({
16432
16932
  activeSyncCycleId: syncCycleId,
@@ -16535,22 +17035,43 @@ var GraphSyncController = class _GraphSyncController {
16535
17035
  const getSignalsForSyncTask = CadenzaService.createMetaTask(
16536
17036
  "Get signals for sync",
16537
17037
  (ctx) => {
16538
- const uniqueSignals = Array.from(
16539
- /* @__PURE__ */ new Set([
16540
- ...CadenzaService.signalBroker.signalObservers.keys(),
16541
- ...CadenzaService.signalBroker.emittedSignalsRegistry
16542
- ])
16543
- ).filter((signal) => !signal.includes(":"));
16544
- const processedSignals = uniqueSignals.map((signal) => ({
16545
- signal,
16546
- data: {
16547
- registered: CadenzaService.signalBroker.signalObservers.get(signal)?.registered ?? false,
16548
- metadata: CadenzaService.signalBroker.getSignalMetadata(signal) ?? null
17038
+ const canonicalSignals = /* @__PURE__ */ new Map();
17039
+ for (const observer of getRegistrableSignalObservers()) {
17040
+ const signalName = canonicalizeSignalName2(observer.signalName);
17041
+ if (!signalName || signalName.includes(":")) {
17042
+ continue;
17043
+ }
17044
+ canonicalSignals.set(signalName, {
17045
+ signal: signalName,
17046
+ data: {
17047
+ registered: observer.registered ?? false,
17048
+ metadata: observer.metadata ?? null
17049
+ }
17050
+ });
17051
+ }
17052
+ for (const emittedSignal of CadenzaService.signalBroker.emittedSignalsRegistry) {
17053
+ const signalName = canonicalizeSignalName2(emittedSignal);
17054
+ if (!signalName || signalName.includes(":")) {
17055
+ continue;
17056
+ }
17057
+ if (canonicalSignals.has(signalName)) {
17058
+ continue;
16549
17059
  }
16550
- }));
17060
+ const metadata = CadenzaService.signalBroker.getSignalMetadata(signalName) ?? null;
17061
+ if (metadata?.is_meta === true || isBootstrapLocalOnlySignal(signalName)) {
17062
+ continue;
17063
+ }
17064
+ canonicalSignals.set(signalName, {
17065
+ signal: signalName,
17066
+ data: {
17067
+ registered: CadenzaService.signalBroker.signalObservers.get(signalName)?.registered ?? false,
17068
+ metadata
17069
+ }
17070
+ });
17071
+ }
16551
17072
  return {
16552
17073
  ...ctx,
16553
- signals: processedSignals
17074
+ signals: Array.from(canonicalSignals.values())
16554
17075
  };
16555
17076
  },
16556
17077
  "Collects local signals for the primitive sync phase.",
@@ -16587,9 +17108,9 @@ var GraphSyncController = class _GraphSyncController {
16587
17108
  "Get all actors for sync",
16588
17109
  (ctx) => ({
16589
17110
  ...ctx,
16590
- actors: CadenzaService.getAllActors()
17111
+ actors: []
16591
17112
  }),
16592
- "Collects local actors for the primitive sync phase.",
17113
+ "Actor definitions are staged through service-manifest publication rather than the bootstrap primitive sync phase.",
16593
17114
  {
16594
17115
  register: false,
16595
17116
  isHidden: true
@@ -16621,7 +17142,7 @@ var GraphSyncController = class _GraphSyncController {
16621
17142
  "Iterate tasks for directional task map sync",
16622
17143
  function* (ctx) {
16623
17144
  for (const task of CadenzaService.registry.tasks.values()) {
16624
- yield { ...ctx, task };
17145
+ yield buildMinimalSyncShardContext(ctx, { task });
16625
17146
  }
16626
17147
  },
16627
17148
  "Iterates local tasks for directional task-map sync.",
@@ -16640,7 +17161,7 @@ var GraphSyncController = class _GraphSyncController {
16640
17161
  "Iterate tasks for signal task map sync",
16641
17162
  function* (ctx) {
16642
17163
  for (const task of CadenzaService.registry.tasks.values()) {
16643
- yield { ...ctx, task };
17164
+ yield buildMinimalSyncShardContext(ctx, { task });
16644
17165
  }
16645
17166
  },
16646
17167
  "Iterates local tasks for signal-to-task map sync.",
@@ -16654,12 +17175,12 @@ var GraphSyncController = class _GraphSyncController {
16654
17175
  gatherSignalTaskMapRegistrationTask
16655
17176
  );
16656
17177
  iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
16657
- this.registerSignalToTaskMapTask.then(gatherSignalTaskMapRegistrationTask);
17178
+ recordSignalTaskMapRegistrationTask.then(gatherSignalTaskMapRegistrationTask);
16658
17179
  const iterateTasksForIntentTaskMapSyncTask = CadenzaService.createMetaTask(
16659
17180
  "Iterate tasks for intent task map sync",
16660
17181
  function* (ctx) {
16661
17182
  for (const task of CadenzaService.registry.tasks.values()) {
16662
- yield { ...ctx, task };
17183
+ yield buildMinimalSyncShardContext(ctx, { task });
16663
17184
  }
16664
17185
  },
16665
17186
  "Iterates local tasks for intent-to-task map sync.",
@@ -16678,7 +17199,7 @@ var GraphSyncController = class _GraphSyncController {
16678
17199
  "Iterate tasks for actor task map sync",
16679
17200
  function* (ctx) {
16680
17201
  for (const task of CadenzaService.registry.tasks.values()) {
16681
- yield { ...ctx, task };
17202
+ yield buildMinimalSyncShardContext(ctx, { task });
16682
17203
  }
16683
17204
  },
16684
17205
  "Iterates local tasks for actor-to-task map sync.",
@@ -16811,7 +17332,7 @@ function sanitizePersistedTaskSourceFields2(task, data) {
16811
17332
  };
16812
17333
  }
16813
17334
  function shouldSkipDirectTaskMetadata(task) {
16814
- return !task || !task.register || task.isHidden || task.isDeputy;
17335
+ return !task || !task.register || task.isHidden || task.isDeputy || task.isMeta || task.isSubMeta;
16815
17336
  }
16816
17337
  function isManagedRouteRecoveryTaskError(errorMessage) {
16817
17338
  if (typeof errorMessage !== "string") {
@@ -16825,7 +17346,10 @@ function isLocallyHandledIntentName2(intentName) {
16825
17346
  return false;
16826
17347
  }
16827
17348
  for (const task of observer.tasks) {
16828
- if (task.register && !task.isHidden && !task.isDeputy) {
17349
+ if (!task) {
17350
+ continue;
17351
+ }
17352
+ if (task.register && !task.isHidden && !task.isDeputy && !task.isMeta && !task.isSubMeta) {
16829
17353
  return true;
16830
17354
  }
16831
17355
  }
@@ -17064,7 +17588,7 @@ var GraphMetadataController = class _GraphMetadataController {
17064
17588
  return false;
17065
17589
  }
17066
17590
  const helper = resolveHelperFromMetadataContext(ctx);
17067
- if (!helper) {
17591
+ if (!helper || helper.isMeta) {
17068
17592
  return false;
17069
17593
  }
17070
17594
  return buildDatabaseTriggerContext({
@@ -17079,7 +17603,7 @@ var GraphMetadataController = class _GraphMetadataController {
17079
17603
  return false;
17080
17604
  }
17081
17605
  const globalDefinition = resolveGlobalFromMetadataContext(ctx);
17082
- if (!globalDefinition) {
17606
+ if (!globalDefinition || globalDefinition.isMeta) {
17083
17607
  return false;
17084
17608
  }
17085
17609
  return buildDatabaseTriggerContext({
@@ -17181,6 +17705,9 @@ var GraphMetadataController = class _GraphMetadataController {
17181
17705
  if (!shouldEmitDirectPrimitiveMetadata()) {
17182
17706
  return false;
17183
17707
  }
17708
+ if (ctx.data?.isMeta === true) {
17709
+ return false;
17710
+ }
17184
17711
  return buildDatabaseTriggerContext({
17185
17712
  ...ctx.data,
17186
17713
  serviceName: CadenzaService.serviceRegistry.serviceName
@@ -17190,6 +17717,9 @@ var GraphMetadataController = class _GraphMetadataController {
17190
17717
  if (!shouldEmitDirectPrimitiveMetadata()) {
17191
17718
  return false;
17192
17719
  }
17720
+ if (ctx.data?.isMeta === true) {
17721
+ return false;
17722
+ }
17193
17723
  return buildDatabaseTriggerContext(
17194
17724
  ctx.data ?? void 0,
17195
17725
  {
@@ -17858,6 +18388,9 @@ var GraphMetadataController = class _GraphMetadataController {
17858
18388
  if (!shouldEmitDirectPrimitiveMetadata()) {
17859
18389
  return false;
17860
18390
  }
18391
+ if (ctx.data?.is_meta === true) {
18392
+ return false;
18393
+ }
17861
18394
  if (shouldSkipDirectActorMetadata(ctx?.data?.name)) {
17862
18395
  return false;
17863
18396
  }
@@ -17870,6 +18403,9 @@ var GraphMetadataController = class _GraphMetadataController {
17870
18403
  if (!shouldEmitDirectPrimitiveMetadata()) {
17871
18404
  return false;
17872
18405
  }
18406
+ if (ctx.data?.is_meta === true) {
18407
+ return false;
18408
+ }
17873
18409
  if (shouldSkipDirectActorMetadata(ctx?.data?.actor_name)) {
17874
18410
  return false;
17875
18411
  }
@@ -18335,6 +18871,8 @@ function resetBrowserRuntimeActorHandles() {
18335
18871
 
18336
18872
  // src/Cadenza.ts
18337
18873
  var POSTGRES_SETUP_DEBUG_ENABLED = process.env.CADENZA_POSTGRES_SETUP_DEBUG === "1" || process.env.CADENZA_POSTGRES_SETUP_DEBUG === "true";
18874
+ var DEFAULT_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS = 15e3;
18875
+ var LOCAL_AUTHORITY_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS = 6e4;
18338
18876
  function resolveInquiryFailureError(inquiry, value, depth = 3, seen = /* @__PURE__ */ new Set()) {
18339
18877
  if (depth < 0 || value === null || value === void 0) {
18340
18878
  return `Inquiry '${inquiry}' did not complete successfully`;
@@ -18396,6 +18934,10 @@ var SERVICE_MANIFEST_PUBLICATION_ORDER = [
18396
18934
  "business_structural",
18397
18935
  "local_meta_structural"
18398
18936
  ];
18937
+ var ROUTING_CAPABILITY_PUBLICATION_RETRY_DELAY_MS = 250;
18938
+ var BUSINESS_STRUCTURAL_PUBLICATION_CALM_DELAY_MS = 1500;
18939
+ var LOCAL_META_STRUCTURAL_PUBLICATION_CALM_DELAY_MS = 15e3;
18940
+ var MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS = 1e3;
18399
18941
  function getServiceManifestPublicationLayerRank(layer) {
18400
18942
  const index = SERVICE_MANIFEST_PUBLICATION_ORDER.indexOf(layer);
18401
18943
  return index >= 0 ? index : SERVICE_MANIFEST_PUBLICATION_ORDER.length - 1;
@@ -18529,43 +19071,250 @@ var CadenzaService = class {
18529
19071
  static normalizeServiceManifestPublicationLayer(value, fallback = "business_structural") {
18530
19072
  return value === "routing_capability" || value === "business_structural" || value === "local_meta_structural" ? value : fallback;
18531
19073
  }
19074
+ static clampServiceManifestPublicationLayer(targetLayer) {
19075
+ const maximumLayer = this.isLocalAuthorityService() ? "routing_capability" : "local_meta_structural";
19076
+ return getServiceManifestPublicationLayerRank(targetLayer) > getServiceManifestPublicationLayerRank(maximumLayer) ? maximumLayer : targetLayer;
19077
+ }
18532
19078
  static mergeServiceManifestPublicationRequest(reason, targetLayer) {
18533
19079
  this.serviceManifestPublicationPendingReason = reason;
19080
+ const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
18534
19081
  const currentTargetLayer = this.serviceManifestPublicationPendingLayer ?? "routing_capability";
18535
- this.serviceManifestPublicationPendingLayer = getServiceManifestPublicationLayerRank(targetLayer) >= getServiceManifestPublicationLayerRank(currentTargetLayer) ? targetLayer : currentTargetLayer;
19082
+ this.serviceManifestPublicationPendingLayer = getServiceManifestPublicationLayerRank(normalizedTargetLayer) >= getServiceManifestPublicationLayerRank(currentTargetLayer) ? normalizedTargetLayer : currentTargetLayer;
19083
+ }
19084
+ static getServiceManifestPublicationGate(publicationLayer) {
19085
+ if (!this.localServiceManifestDefinitionInserted || !this.localServiceManifestInstanceInserted) {
19086
+ return {
19087
+ ready: false,
19088
+ delayMs: ROUTING_CAPABILITY_PUBLICATION_RETRY_DELAY_MS
19089
+ };
19090
+ }
19091
+ if (publicationLayer === "routing_capability") {
19092
+ return {
19093
+ ready: true,
19094
+ delayMs: 0
19095
+ };
19096
+ }
19097
+ if (!this.bootstrapSyncCompleted || this.bootstrapSyncCompletedAt <= 0) {
19098
+ return {
19099
+ ready: false,
19100
+ delayMs: MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS
19101
+ };
19102
+ }
19103
+ const now = Date.now();
19104
+ if (publicationLayer === "business_structural") {
19105
+ const allowedAt2 = this.bootstrapSyncCompletedAt + BUSINESS_STRUCTURAL_PUBLICATION_CALM_DELAY_MS;
19106
+ return {
19107
+ ready: now >= allowedAt2,
19108
+ delayMs: Math.max(1, allowedAt2 - now)
19109
+ };
19110
+ }
19111
+ const businessPublishedAt = this.serviceManifestPublishedAt.business_structural ?? 0;
19112
+ if (!this.lastPublishedServiceManifestHashes.business_structural || businessPublishedAt <= 0) {
19113
+ return {
19114
+ ready: false,
19115
+ delayMs: MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS
19116
+ };
19117
+ }
19118
+ const allowedAt = businessPublishedAt + LOCAL_META_STRUCTURAL_PUBLICATION_CALM_DELAY_MS;
19119
+ return {
19120
+ ready: now >= allowedAt,
19121
+ delayMs: Math.max(1, allowedAt - now)
19122
+ };
18536
19123
  }
18537
19124
  static requestServiceManifestPublication(reason, immediate = false, targetLayer = "business_structural") {
18538
19125
  if (!this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
18539
19126
  return;
18540
19127
  }
19128
+ const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
18541
19129
  const signalName = "meta.service_manifest.publish_requested";
18542
19130
  const payload = {
18543
19131
  __reason: reason,
18544
19132
  __serviceName: this.serviceRegistry.serviceName,
18545
19133
  __serviceInstanceId: this.serviceRegistry.serviceInstanceId,
18546
- __publicationLayer: targetLayer
19134
+ __publicationLayer: normalizedTargetLayer
18547
19135
  };
18548
19136
  if (immediate) {
18549
- this.emit(signalName, payload);
19137
+ if (this.serviceManifestPublicationRetryTimer) {
19138
+ clearTimeout(this.serviceManifestPublicationRetryTimer);
19139
+ this.serviceManifestPublicationRetryTimer = null;
19140
+ }
19141
+ void this.publishServiceManifestIfNeeded(reason, normalizedTargetLayer);
18550
19142
  return;
18551
19143
  }
18552
19144
  this.debounce(signalName, payload, 100);
18553
19145
  }
18554
- static scheduleServiceManifestPublicationRetry(reason, targetLayer = "business_structural") {
19146
+ static scheduleServiceManifestPublicationRetry(reason, targetLayer = "business_structural", options) {
18555
19147
  if (!this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
18556
19148
  return;
18557
19149
  }
19150
+ this.serviceManifestPublicationRetryReason = reason;
19151
+ const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
19152
+ const currentRetryLayer = this.serviceManifestPublicationRetryLayer ?? "routing_capability";
19153
+ this.serviceManifestPublicationRetryLayer = getServiceManifestPublicationLayerRank(normalizedTargetLayer) >= getServiceManifestPublicationLayerRank(currentRetryLayer) ? normalizedTargetLayer : currentRetryLayer;
19154
+ if (this.serviceManifestPublicationRetryTimer) {
19155
+ return;
19156
+ }
19157
+ const retryReason = this.serviceManifestPublicationRetryReason ?? reason;
19158
+ const retryTargetLayer = this.serviceManifestPublicationRetryLayer ?? targetLayer;
19159
+ const shouldIncrementRetryCount = options?.incrementRetryCount !== false;
19160
+ const delayMs = options?.delayMs ?? Math.min(
19161
+ 1e4,
19162
+ 1e3 * Math.max(1, 2 ** this.serviceManifestPublicationRetryCount)
19163
+ );
19164
+ if (shouldIncrementRetryCount) {
19165
+ this.serviceManifestPublicationRetryCount += 1;
19166
+ }
19167
+ this.serviceManifestPublicationRetryTimer = setTimeout(() => {
19168
+ this.serviceManifestPublicationRetryTimer = null;
19169
+ const pendingReason = this.serviceManifestPublicationRetryReason ?? retryReason;
19170
+ const pendingLayer = this.serviceManifestPublicationRetryLayer ?? retryTargetLayer;
19171
+ this.serviceManifestPublicationRetryReason = null;
19172
+ this.serviceManifestPublicationRetryLayer = null;
19173
+ void this.publishServiceManifestIfNeeded(pendingReason, pendingLayer);
19174
+ }, delayMs);
19175
+ }
19176
+ static shouldPublishBusinessManifestForTaskContext(ctx) {
19177
+ const task = ctx?.taskInstance ?? (typeof ctx?.data?.name === "string" ? this.get(ctx.data.name) : void 0);
19178
+ if (task) {
19179
+ if (this.isRoutingCriticalManifestTask(task)) {
19180
+ return true;
19181
+ }
19182
+ return task.register === true && task.isMeta !== true && task.isSubMeta !== true && task.isHidden !== true && task.isEphemeral !== true;
19183
+ }
19184
+ if (this.hasRoutingCriticalManifestBindingInContext(ctx)) {
19185
+ return true;
19186
+ }
19187
+ return ctx?.data?.isMeta !== true && ctx?.data?.isSubMeta !== true && ctx?.data?.isHidden !== true && ctx?.data?.isEphemeral !== true && ctx?.__isSubMeta !== true;
19188
+ }
19189
+ static isRoutingCriticalManifestSignalName(signalName) {
19190
+ const normalizedSignalName = String(signalName ?? "").trim();
19191
+ if (!normalizedSignalName) {
19192
+ return false;
19193
+ }
19194
+ return normalizedSignalName === EXECUTION_PERSISTENCE_BUNDLE_SIGNAL || isAuthorityBootstrapSignal(normalizedSignalName);
19195
+ }
19196
+ static isRoutingCriticalManifestIntentName(intentName) {
19197
+ return isAuthorityBootstrapIntent(intentName);
19198
+ }
19199
+ static isRoutingCriticalManifestTask(task) {
19200
+ for (const signalName of task.observedSignals ?? []) {
19201
+ if (this.isRoutingCriticalManifestSignalName(signalName)) {
19202
+ return true;
19203
+ }
19204
+ }
19205
+ for (const intentName of task.handlesIntents ?? []) {
19206
+ if (this.isRoutingCriticalManifestIntentName(intentName)) {
19207
+ return true;
19208
+ }
19209
+ }
19210
+ return false;
19211
+ }
19212
+ static hasRoutingCriticalManifestBindingInContext(ctx) {
19213
+ const signalCandidates = [
19214
+ ctx?.signalName,
19215
+ ctx?.data?.signalName,
19216
+ ctx?.data?.signal_name
19217
+ ];
19218
+ for (const signalName of signalCandidates) {
19219
+ if (this.isRoutingCriticalManifestSignalName(signalName)) {
19220
+ return true;
19221
+ }
19222
+ }
19223
+ const intentCandidates = [
19224
+ ctx?.intentName,
19225
+ ctx?.data?.intentName,
19226
+ ctx?.data?.intent_name
19227
+ ];
19228
+ for (const intentName of intentCandidates) {
19229
+ if (this.isRoutingCriticalManifestIntentName(intentName)) {
19230
+ return true;
19231
+ }
19232
+ }
19233
+ return false;
19234
+ }
19235
+ static shouldPublishBusinessManifestForHelperContext(ctx) {
19236
+ const helperName = typeof ctx?.data?.name === "string" ? ctx.data.name : typeof ctx?.data?.helperName === "string" ? ctx.data.helperName : typeof ctx?.data?.dependencyHelperName === "string" ? ctx.data.dependencyHelperName : "";
19237
+ const helper = helperName ? import_core6.default.getHelper(helperName) : void 0;
19238
+ if (helper) {
19239
+ return helper.isMeta !== true;
19240
+ }
19241
+ return ctx?.data?.isMeta !== true;
19242
+ }
19243
+ static shouldPublishBusinessManifestForGlobalContext(ctx) {
19244
+ const globalName = typeof ctx?.data?.name === "string" ? ctx.data.name : typeof ctx?.data?.globalName === "string" ? ctx.data.globalName : "";
19245
+ const globalDefinition = globalName ? import_core6.default.getGlobal(globalName) : void 0;
19246
+ if (globalDefinition) {
19247
+ return globalDefinition.isMeta !== true;
19248
+ }
19249
+ return ctx?.data?.isMeta !== true;
19250
+ }
19251
+ static shouldPublishBusinessManifestForRoutineContext(ctx) {
19252
+ const routineName = typeof ctx?.data?.name === "string" ? ctx.data.name : "";
19253
+ const routine = routineName ? this.getRoutine(routineName) : void 0;
19254
+ if (routine) {
19255
+ return routine.isMeta !== true;
19256
+ }
19257
+ return ctx?.data?.isMeta !== true;
19258
+ }
19259
+ static shouldRequestServiceManifestPublicationForSignal(ctx) {
19260
+ const signalName = typeof ctx?.signal === "string" && ctx.signal.trim().length > 0 ? ctx.signal.trim() : "";
19261
+ switch (signalName) {
19262
+ case "meta.task.created":
19263
+ case "meta.task.destroyed":
19264
+ case "meta.task.relationship_added":
19265
+ case "meta.task.relationship_removed":
19266
+ case "meta.task.intent_associated":
19267
+ case "meta.task.helper_associated":
19268
+ case "meta.task.global_associated":
19269
+ case "meta.task.observed_signal":
19270
+ case "meta.task.attached_signal":
19271
+ case "meta.task.detached_signal":
19272
+ return this.shouldPublishBusinessManifestForTaskContext(ctx);
19273
+ case "meta.helper.created":
19274
+ case "meta.helper.updated":
19275
+ case "meta.helper.helper_associated":
19276
+ case "meta.helper.global_associated":
19277
+ return this.shouldPublishBusinessManifestForHelperContext(ctx);
19278
+ case "meta.global.created":
19279
+ case "meta.global.updated":
19280
+ return this.shouldPublishBusinessManifestForGlobalContext(ctx);
19281
+ case "meta.actor.created":
19282
+ case "meta.actor.task_associated":
19283
+ return ctx?.data?.is_meta !== true && ctx?.__isSubMeta !== true;
19284
+ case "global.meta.graph_metadata.routine_created":
19285
+ case "global.meta.graph_metadata.routine_updated":
19286
+ return this.shouldPublishBusinessManifestForRoutineContext(ctx);
19287
+ default:
19288
+ return false;
19289
+ }
19290
+ }
19291
+ static maybeRequestInitialServiceManifestPublication(reason, targetLayer = "business_structural") {
19292
+ if (this.initialServiceManifestPublicationRequested || !this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId || !this.localServiceManifestDefinitionInserted || !this.localServiceManifestInstanceInserted) {
19293
+ return false;
19294
+ }
19295
+ this.initialServiceManifestPublicationRequested = true;
19296
+ this.requestServiceManifestPublication(reason, true, targetLayer);
19297
+ return true;
19298
+ }
19299
+ static scheduleInitialServiceManifestPublicationFallback(reason, targetLayer = "business_structural") {
19300
+ if (!this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
19301
+ return;
19302
+ }
18558
19303
  setTimeout(() => {
18559
- this.requestServiceManifestPublication(reason, false, targetLayer);
19304
+ if (this.initialServiceManifestPublicationRequested || !this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
19305
+ return;
19306
+ }
19307
+ this.requestServiceManifestPublication(reason, true, targetLayer);
18560
19308
  }, 1e3);
18561
19309
  }
18562
19310
  static async publishServiceManifestIfNeeded(reason, targetLayer = "business_structural") {
18563
- if (!this.serviceRegistry.connectsToCadenzaDB || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
19311
+ if (!this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
18564
19312
  return false;
18565
19313
  }
18566
19314
  const publishReason = typeof reason === "string" && reason.trim().length > 0 ? reason.trim() : "service_manifest_publish";
19315
+ const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
18567
19316
  const publishTargetLayer = this.normalizeServiceManifestPublicationLayer(
18568
- targetLayer
19317
+ normalizedTargetLayer
18569
19318
  );
18570
19319
  if (this.serviceManifestPublicationInFlight) {
18571
19320
  this.mergeServiceManifestPublicationRequest(
@@ -18598,13 +19347,23 @@ var CadenzaService = class {
18598
19347
  const hasPendingFollowupLayer = publicationPlan.some(
18599
19348
  (entry) => entry.changed && getServiceManifestPublicationLayerRank(entry.layer) > getServiceManifestPublicationLayerRank(publicationLayer)
18600
19349
  );
19350
+ const publicationGate = this.getServiceManifestPublicationGate(publicationLayer);
19351
+ if (!publicationGate.ready) {
19352
+ this.scheduleServiceManifestPublicationRetry(publishReason, publishTargetLayer, {
19353
+ delayMs: publicationGate.delayMs,
19354
+ incrementRetryCount: false
19355
+ });
19356
+ return false;
19357
+ }
18601
19358
  this.serviceManifestPublicationInFlight = true;
18602
19359
  try {
18603
- this.serviceRegistry.ensureBootstrapAuthorityControlPlaneForInquiry(
18604
- AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
18605
- snapshot
18606
- );
18607
- if (!this.serviceRegistry.hasAuthorityBootstrapHandshakeEstablished()) {
19360
+ if (!this.isLocalAuthorityService()) {
19361
+ this.serviceRegistry.ensureBootstrapAuthorityControlPlaneForInquiry(
19362
+ AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
19363
+ snapshot
19364
+ );
19365
+ }
19366
+ if (this.shouldRequireAuthorityBootstrapHandshakeForManifestPublication() && !this.serviceRegistry.hasAuthorityBootstrapHandshakeEstablished()) {
18608
19367
  this.scheduleServiceManifestPublicationRetry(
18609
19368
  publishReason,
18610
19369
  publishTargetLayer
@@ -18612,11 +19371,13 @@ var CadenzaService = class {
18612
19371
  return false;
18613
19372
  }
18614
19373
  await this.inquire(AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT, snapshot, {
18615
- timeout: 15e3,
19374
+ timeout: this.isLocalAuthorityService() ? LOCAL_AUTHORITY_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS : DEFAULT_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS,
18616
19375
  requireComplete: true
18617
19376
  });
18618
19377
  this.serviceManifestRevision = snapshot.revision;
18619
19378
  this.lastPublishedServiceManifestHashes[publicationLayer] = snapshot.manifestHash;
19379
+ this.serviceManifestPublishedAt[publicationLayer] = Date.now();
19380
+ this.serviceManifestPublicationRetryCount = 0;
18620
19381
  if (hasPendingFollowupLayer) {
18621
19382
  this.mergeServiceManifestPublicationRequest(
18622
19383
  publishReason,
@@ -18652,14 +19413,7 @@ var CadenzaService = class {
18652
19413
  const pendingLayer = this.serviceManifestPublicationPendingLayer;
18653
19414
  this.serviceManifestPublicationPendingReason = null;
18654
19415
  this.serviceManifestPublicationPendingLayer = null;
18655
- this.debounce(
18656
- "meta.service_manifest.publish_requested",
18657
- {
18658
- __reason: pendingReason,
18659
- __publicationLayer: pendingLayer
18660
- },
18661
- 100
18662
- );
19416
+ void this.publishServiceManifestIfNeeded(pendingReason, pendingLayer);
18663
19417
  }
18664
19418
  }
18665
19419
  }
@@ -18673,7 +19427,7 @@ var CadenzaService = class {
18673
19427
  typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0 ? ctx.__reason.trim() : "service_manifest_publish",
18674
19428
  this.normalizeServiceManifestPublicationLayer(
18675
19429
  ctx.__publicationLayer,
18676
- "business_structural"
19430
+ "local_meta_structural"
18677
19431
  )
18678
19432
  ),
18679
19433
  "Publishes staged static manifest snapshots to authority when the manifest hash changes.",
@@ -18685,14 +19439,17 @@ var CadenzaService = class {
18685
19439
  this.createMetaTask(
18686
19440
  "Request manifest publication after structural change",
18687
19441
  (ctx) => {
19442
+ if (!this.shouldRequestServiceManifestPublicationForSignal(ctx)) {
19443
+ return false;
19444
+ }
18688
19445
  const reason = typeof ctx.signal === "string" && ctx.signal.trim().length > 0 ? ctx.signal : typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0 ? ctx.__reason : "manifest_structural_update";
18689
- const targetLayer = reason === "meta.service_registry.instance_inserted" ? "business_structural" : this.normalizeServiceManifestPublicationLayer(
19446
+ const targetLayer = this.normalizeServiceManifestPublicationLayer(
18690
19447
  ctx.__publicationLayer,
18691
- "business_structural"
19448
+ "local_meta_structural"
18692
19449
  );
18693
19450
  this.requestServiceManifestPublication(
18694
19451
  reason,
18695
- reason === "meta.service_registry.instance_inserted",
19452
+ false,
18696
19453
  targetLayer
18697
19454
  );
18698
19455
  return true;
@@ -18703,7 +19460,6 @@ var CadenzaService = class {
18703
19460
  isHidden: true
18704
19461
  }
18705
19462
  ).doOn(
18706
- "meta.service_registry.instance_inserted",
18707
19463
  "meta.task.created",
18708
19464
  "meta.task.destroyed",
18709
19465
  "meta.task.relationship_added",
@@ -18722,14 +19478,21 @@ var CadenzaService = class {
18722
19478
  "meta.helper.global_associated",
18723
19479
  "meta.actor.created",
18724
19480
  "meta.actor.task_associated",
18725
- "meta.fetch.handshake_complete",
18726
19481
  "meta.service_registry.registered_global_signals",
18727
19482
  "meta.service_registry.registered_global_intents",
18728
- "meta.service_registry.initial_sync_complete",
18729
19483
  "global.meta.graph_metadata.routine_created",
18730
19484
  "global.meta.graph_metadata.routine_updated"
18731
19485
  );
18732
19486
  }
19487
+ static isLocalAuthorityService() {
19488
+ return this.serviceRegistry.serviceName === "CadenzaDB";
19489
+ }
19490
+ static canPublishServiceManifestToAuthority() {
19491
+ return this.serviceRegistry.connectsToCadenzaDB || this.isLocalAuthorityService();
19492
+ }
19493
+ static shouldRequireAuthorityBootstrapHandshakeForManifestPublication() {
19494
+ return !this.isLocalAuthorityService();
19495
+ }
18733
19496
  static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
18734
19497
  const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
18735
19498
  const helperSuffix = (0, import_lodash_es.camelCase)(String(tableName ?? "").trim());
@@ -18896,6 +19659,7 @@ var CadenzaService = class {
18896
19659
  }
18897
19660
  static markBootstrapSyncCompleted() {
18898
19661
  this.bootstrapSyncCompleted = true;
19662
+ this.bootstrapSyncCompletedAt = Date.now();
18899
19663
  }
18900
19664
  /**
18901
19665
  * Emits a signal with the specified data using the associated broker.
@@ -19726,6 +20490,7 @@ var CadenzaService = class {
19726
20490
  this.validateServiceName(serviceName);
19727
20491
  const serviceId = options.customServiceId ?? (0, import_uuid7.v4)();
19728
20492
  this.bootstrapSyncCompleted = false;
20493
+ this.bootstrapSyncCompletedAt = 0;
19729
20494
  this.bootstrapSignalRegistrationsCompleted = false;
19730
20495
  this.bootstrapIntentRegistrationsCompleted = false;
19731
20496
  this.serviceRegistry.serviceName = serviceName;
@@ -19961,6 +20726,7 @@ var CadenzaService = class {
19961
20726
  __declaredTransports: declaredTransports
19962
20727
  };
19963
20728
  let bootstrapServiceCreationRequested = false;
20729
+ const emitLocalServiceCreationImmediately = !options.cadenzaDB?.connect;
19964
20730
  if (options.cadenzaDB?.connect) {
19965
20731
  this.createMetaTask(
19966
20732
  "Create service",
@@ -19983,7 +20749,6 @@ var CadenzaService = class {
19983
20749
  }
19984
20750
  ).doOn("meta.fetch.handshake_complete");
19985
20751
  } else {
19986
- this.emit("meta.create_service_requested", initContext);
19987
20752
  this.createMetaTask("Create signal transmission for sync", (ctx, emit2) => {
19988
20753
  emit2(
19989
20754
  "meta.service_registry.gathered_sync_transmission_reconcile_requested",
@@ -19995,6 +20760,20 @@ var CadenzaService = class {
19995
20760
  }).doOn("meta.rest.handshake", "meta.socket.handshake");
19996
20761
  }
19997
20762
  let serviceSetupCompletedHandled = false;
20763
+ this.createMetaTask("Handle local service definition insertion", (ctx) => {
20764
+ const insertedServiceName = String(
20765
+ ctx?.__serviceName ?? ctx?.serviceName ?? ctx?.service_name ?? ctx?.data?.name ?? ""
20766
+ ).trim();
20767
+ if (!insertedServiceName || insertedServiceName !== serviceName) {
20768
+ return false;
20769
+ }
20770
+ this.localServiceManifestDefinitionInserted = true;
20771
+ this.maybeRequestInitialServiceManifestPublication(
20772
+ "service_setup_completed",
20773
+ "local_meta_structural"
20774
+ );
20775
+ return true;
20776
+ }).doOn("meta.service_registry.service_inserted");
19998
20777
  this.createMetaTask("Handle service setup completion", (ctx, emit2) => {
19999
20778
  if (serviceSetupCompletedHandled) {
20000
20779
  return false;
@@ -20015,13 +20794,18 @@ var CadenzaService = class {
20015
20794
  return false;
20016
20795
  }
20017
20796
  serviceSetupCompletedHandled = true;
20797
+ this.localServiceManifestInstanceInserted = true;
20018
20798
  if (options.cadenzaDB?.connect) {
20019
20799
  this.serviceRegistry.bootstrapFullSync(emit2, ctx, "service_setup_completed");
20020
- void this.publishServiceManifestIfNeeded(
20021
- "service_setup_completed",
20022
- "business_structural"
20023
- );
20024
20800
  }
20801
+ this.maybeRequestInitialServiceManifestPublication(
20802
+ "service_setup_completed",
20803
+ "local_meta_structural"
20804
+ );
20805
+ this.scheduleInitialServiceManifestPublicationFallback(
20806
+ "service_setup_completed",
20807
+ "local_meta_structural"
20808
+ );
20025
20809
  if (isFrontend) {
20026
20810
  registerActorSessionPersistenceTasks();
20027
20811
  this.ensureFrontendSyncLoop();
@@ -20029,6 +20813,9 @@ var CadenzaService = class {
20029
20813
  this.log("Service created.");
20030
20814
  return true;
20031
20815
  }).doOn("meta.service_registry.instance_inserted");
20816
+ if (emitLocalServiceCreationImmediately) {
20817
+ this.emit("meta.create_service_requested", initContext);
20818
+ }
20032
20819
  if (!options.cadenzaDB?.connect) {
20033
20820
  import_core6.default.schedule(
20034
20821
  "meta.service_registry.instance_registration_requested",
@@ -20493,6 +21280,30 @@ var CadenzaService = class {
20493
21280
  this.bootstrap();
20494
21281
  return import_core6.default.createTask(name, func, description, options);
20495
21282
  }
21283
+ static createHelper(name, func, description = "") {
21284
+ this.bootstrap();
21285
+ return import_core6.default.createHelper(name, func, description);
21286
+ }
21287
+ static createMetaHelper(name, func, description = "") {
21288
+ this.bootstrap();
21289
+ return import_core6.default.createMetaHelper(name, func, description);
21290
+ }
21291
+ static createHelperFromDefinition(definition) {
21292
+ this.bootstrap();
21293
+ return import_core6.default.createHelperFromDefinition(definition);
21294
+ }
21295
+ static createGlobal(name, value, description = "") {
21296
+ this.bootstrap();
21297
+ return import_core6.default.createGlobal(name, value, description);
21298
+ }
21299
+ static createMetaGlobal(name, value, description = "") {
21300
+ this.bootstrap();
21301
+ return import_core6.default.createMetaGlobal(name, value, description);
21302
+ }
21303
+ static createGlobalFromDefinition(definition) {
21304
+ this.bootstrap();
21305
+ return import_core6.default.createGlobalFromDefinition(definition);
21306
+ }
20496
21307
  /**
20497
21308
  * Creates a meta task with the specified name, functionality, description, and options.
20498
21309
  * This is used for creating tasks that lives on the meta layer.
@@ -20829,6 +21640,7 @@ var CadenzaService = class {
20829
21640
  this.isBootstrapped = false;
20830
21641
  this.serviceCreated = false;
20831
21642
  this.bootstrapSyncCompleted = false;
21643
+ this.bootstrapSyncCompletedAt = 0;
20832
21644
  this.bootstrapSignalRegistrationsCompleted = false;
20833
21645
  this.bootstrapIntentRegistrationsCompleted = false;
20834
21646
  this.defaultDatabaseServiceName = null;
@@ -20837,15 +21649,27 @@ var CadenzaService = class {
20837
21649
  this.frontendSyncScheduled = false;
20838
21650
  this.serviceManifestRevision = 0;
20839
21651
  this.lastPublishedServiceManifestHashes = {};
21652
+ this.serviceManifestPublishedAt = {};
20840
21653
  this.serviceManifestPublicationInFlight = false;
20841
21654
  this.serviceManifestPublicationPendingReason = null;
20842
21655
  this.serviceManifestPublicationPendingLayer = null;
21656
+ this.serviceManifestPublicationRetryReason = null;
21657
+ this.serviceManifestPublicationRetryLayer = null;
21658
+ if (this.serviceManifestPublicationRetryTimer) {
21659
+ clearTimeout(this.serviceManifestPublicationRetryTimer);
21660
+ this.serviceManifestPublicationRetryTimer = null;
21661
+ }
21662
+ this.serviceManifestPublicationRetryCount = 0;
21663
+ this.localServiceManifestDefinitionInserted = false;
21664
+ this.localServiceManifestInstanceInserted = false;
21665
+ this.initialServiceManifestPublicationRequested = false;
20843
21666
  resetBrowserRuntimeActorHandles();
20844
21667
  }
20845
21668
  };
20846
21669
  CadenzaService.isBootstrapped = false;
20847
21670
  CadenzaService.serviceCreated = false;
20848
21671
  CadenzaService.bootstrapSyncCompleted = false;
21672
+ CadenzaService.bootstrapSyncCompletedAt = 0;
20849
21673
  CadenzaService.bootstrapSignalRegistrationsCompleted = false;
20850
21674
  CadenzaService.bootstrapIntentRegistrationsCompleted = false;
20851
21675
  CadenzaService.defaultDatabaseServiceName = null;
@@ -20854,9 +21678,17 @@ CadenzaService.hydratedInquiryResults = /* @__PURE__ */ new Map();
20854
21678
  CadenzaService.frontendSyncScheduled = false;
20855
21679
  CadenzaService.serviceManifestRevision = 0;
20856
21680
  CadenzaService.lastPublishedServiceManifestHashes = {};
21681
+ CadenzaService.serviceManifestPublishedAt = {};
20857
21682
  CadenzaService.serviceManifestPublicationInFlight = false;
20858
21683
  CadenzaService.serviceManifestPublicationPendingReason = null;
20859
21684
  CadenzaService.serviceManifestPublicationPendingLayer = null;
21685
+ CadenzaService.serviceManifestPublicationRetryReason = null;
21686
+ CadenzaService.serviceManifestPublicationRetryLayer = null;
21687
+ CadenzaService.serviceManifestPublicationRetryTimer = null;
21688
+ CadenzaService.serviceManifestPublicationRetryCount = 0;
21689
+ CadenzaService.localServiceManifestDefinitionInserted = false;
21690
+ CadenzaService.localServiceManifestInstanceInserted = false;
21691
+ CadenzaService.initialServiceManifestPublicationRequested = false;
20860
21692
  CadenzaService.shutdownHandlersRegistered = false;
20861
21693
  CadenzaService.shutdownInFlight = false;
20862
21694
  CadenzaService.shutdownHandlerCleanup = [];
@@ -21158,6 +21990,18 @@ var createTask = CadenzaService.createTask.bind(
21158
21990
  var createMetaTask = CadenzaService.createMetaTask.bind(
21159
21991
  CadenzaService
21160
21992
  );
21993
+ var createHelper = CadenzaService.createHelper.bind(
21994
+ CadenzaService
21995
+ );
21996
+ var createMetaHelper = CadenzaService.createMetaHelper.bind(
21997
+ CadenzaService
21998
+ );
21999
+ var createGlobal = CadenzaService.createGlobal.bind(
22000
+ CadenzaService
22001
+ );
22002
+ var createMetaGlobal = CadenzaService.createMetaGlobal.bind(
22003
+ CadenzaService
22004
+ );
21161
22005
  var createActor = CadenzaService.createActor.bind(
21162
22006
  CadenzaService
21163
22007
  );