@cadenza.io/service 2.21.0 → 2.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Cadenza-Cq1mscQf.d.mts → Cadenza-CRVK2HUv.d.mts} +46 -1
- package/dist/{Cadenza-Cq1mscQf.d.ts → Cadenza-CRVK2HUv.d.ts} +46 -1
- package/dist/browser/index.js +1369 -482
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +1368 -479
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +1480 -568
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1476 -568
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +2 -2
- package/dist/nuxt/index.d.ts +2 -2
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/vue/index.d.mts +2 -2
- package/dist/vue/index.d.ts +2 -2
- package/package.json +4 -4
package/dist/browser/index.js
CHANGED
|
@@ -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,
|
|
@@ -288,6 +294,16 @@ var DELEGATION_FAILURE_CONTEXT_KEYS = [
|
|
|
288
294
|
"transportProtocols",
|
|
289
295
|
"transportProtocol"
|
|
290
296
|
];
|
|
297
|
+
var ACTOR_SESSION_STATE_REMOTE_ROUTINE = "Insert actor_session_state";
|
|
298
|
+
var ACTOR_SESSION_SNAPSHOT_ROOT_KEYS = [
|
|
299
|
+
"__remoteRoutineName",
|
|
300
|
+
"__serviceName",
|
|
301
|
+
"__localTaskName",
|
|
302
|
+
"__localTaskVersion",
|
|
303
|
+
"__localServiceName",
|
|
304
|
+
"__timeout",
|
|
305
|
+
...ROOT_METADATA_PASSTHROUGH_KEYS
|
|
306
|
+
];
|
|
291
307
|
function isPlainObject(value) {
|
|
292
308
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
293
309
|
return false;
|
|
@@ -312,6 +328,9 @@ function cloneDelegationValue(value) {
|
|
|
312
328
|
return value;
|
|
313
329
|
}
|
|
314
330
|
function buildDelegationRequestSnapshot(context) {
|
|
331
|
+
if (typeof context.__remoteRoutineName === "string" && context.__remoteRoutineName.trim() === ACTOR_SESSION_STATE_REMOTE_ROUTINE) {
|
|
332
|
+
return buildActorSessionDelegationSnapshot(context);
|
|
333
|
+
}
|
|
315
334
|
const snapshot = {};
|
|
316
335
|
for (const [key, value] of Object.entries(context)) {
|
|
317
336
|
if (key === DELEGATION_REQUEST_SNAPSHOT_KEY || key === "task" || key === "routine") {
|
|
@@ -321,6 +340,21 @@ function buildDelegationRequestSnapshot(context) {
|
|
|
321
340
|
}
|
|
322
341
|
return snapshot;
|
|
323
342
|
}
|
|
343
|
+
function buildActorSessionDelegationSnapshot(context) {
|
|
344
|
+
const snapshot = {};
|
|
345
|
+
for (const key of ACTOR_SESSION_SNAPSHOT_ROOT_KEYS) {
|
|
346
|
+
if (context[key] !== void 0) {
|
|
347
|
+
snapshot[key] = cloneDelegationValue(context[key]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (context.data !== void 0) {
|
|
351
|
+
snapshot.data = cloneDelegationValue(context.data);
|
|
352
|
+
}
|
|
353
|
+
if (context.queryData !== void 0) {
|
|
354
|
+
snapshot.queryData = cloneDelegationValue(context.queryData);
|
|
355
|
+
}
|
|
356
|
+
return snapshot;
|
|
357
|
+
}
|
|
324
358
|
function hoistDelegationMetadataFields(input, metadataInput) {
|
|
325
359
|
const context = input && typeof input === "object" ? { ...input } : {};
|
|
326
360
|
const mutableContext = context;
|
|
@@ -429,6 +463,12 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
429
463
|
return;
|
|
430
464
|
}
|
|
431
465
|
const processId = (0, import_uuid2.v4)();
|
|
466
|
+
const resolvedTimeoutMs = Math.max(
|
|
467
|
+
1e3,
|
|
468
|
+
Number(context.__timeout ?? task.timeout ?? 0) || 6e4
|
|
469
|
+
);
|
|
470
|
+
let settled = false;
|
|
471
|
+
let timeoutHandle = null;
|
|
432
472
|
context.__metadata.__deputyExecId = processId;
|
|
433
473
|
if ((process.env.CADENZA_INSTANCE_DEBUG === "1" || process.env.CADENZA_INSTANCE_DEBUG === "true") && context.__remoteRoutineName === "Insert service_instance") {
|
|
434
474
|
console.log("[CADENZA_INSTANCE_DEBUG] deputy_delegation_requested", {
|
|
@@ -445,7 +485,37 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
445
485
|
emit2("meta.deputy.delegation_requested", {
|
|
446
486
|
...context
|
|
447
487
|
});
|
|
448
|
-
|
|
488
|
+
let progressTask = null;
|
|
489
|
+
let resolveTask = null;
|
|
490
|
+
const cleanup = () => {
|
|
491
|
+
if (timeoutHandle) {
|
|
492
|
+
clearTimeout(timeoutHandle);
|
|
493
|
+
timeoutHandle = null;
|
|
494
|
+
}
|
|
495
|
+
if (progressTask && !progressTask.destroyed) {
|
|
496
|
+
progressTask.destroy();
|
|
497
|
+
}
|
|
498
|
+
if (resolveTask && !resolveTask.destroyed) {
|
|
499
|
+
resolveTask.destroy();
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
const settleSuccess = (value) => {
|
|
503
|
+
if (settled) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
settled = true;
|
|
507
|
+
cleanup();
|
|
508
|
+
resolve(value);
|
|
509
|
+
};
|
|
510
|
+
const settleFailure = (error) => {
|
|
511
|
+
if (settled) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
settled = true;
|
|
515
|
+
cleanup();
|
|
516
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
517
|
+
};
|
|
518
|
+
progressTask = CadenzaService.createEphemeralMetaTask(
|
|
449
519
|
`On progress deputy ${task.remoteRoutineName}`,
|
|
450
520
|
(ctx) => {
|
|
451
521
|
if (typeof progressCallback === "function" && ctx.progress) {
|
|
@@ -464,7 +534,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
464
534
|
`meta.fetch.delegated:${processId}`,
|
|
465
535
|
`meta.service_registry.load_balance_failed:${processId}`
|
|
466
536
|
);
|
|
467
|
-
CadenzaService.createEphemeralMetaTask(
|
|
537
|
+
resolveTask = CadenzaService.createEphemeralMetaTask(
|
|
468
538
|
`Resolve deputy ${task.remoteRoutineName}`,
|
|
469
539
|
(responseCtx) => {
|
|
470
540
|
const mergedResponseCtx = responseCtx && typeof responseCtx === "object" ? {
|
|
@@ -472,7 +542,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
472
542
|
...responseCtx
|
|
473
543
|
} : responseCtx;
|
|
474
544
|
if (responseCtx?.errored) {
|
|
475
|
-
|
|
545
|
+
settleFailure(new Error(responseCtx.__error));
|
|
476
546
|
} else {
|
|
477
547
|
if (SERVICE_REGISTRY_TRACE_SERVICE.length > 0 && CadenzaService.serviceRegistry.serviceName === SERVICE_REGISTRY_TRACE_SERVICE && context.__remoteRoutineName === "Insert service_instance") {
|
|
478
548
|
console.log(
|
|
@@ -489,7 +559,7 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
489
559
|
if (mergedResponseCtx && typeof mergedResponseCtx === "object") {
|
|
490
560
|
delete mergedResponseCtx.__isDeputy;
|
|
491
561
|
}
|
|
492
|
-
|
|
562
|
+
settleSuccess(mergedResponseCtx);
|
|
493
563
|
}
|
|
494
564
|
},
|
|
495
565
|
`Ephemeral resolver for deputy process ${processId}`,
|
|
@@ -499,6 +569,14 @@ function deputyTaskExecutor(context, emit2, inquire, _tools, progressCallback) {
|
|
|
499
569
|
`meta.fetch.delegated:${processId}`,
|
|
500
570
|
`meta.service_registry.load_balance_failed:${processId}`
|
|
501
571
|
);
|
|
572
|
+
timeoutHandle = setTimeout(() => {
|
|
573
|
+
settleFailure(
|
|
574
|
+
new Error(
|
|
575
|
+
`Deputy task '${task.name}' timed out waiting for remote resolution after ${resolvedTimeoutMs}ms.`
|
|
576
|
+
)
|
|
577
|
+
);
|
|
578
|
+
}, resolvedTimeoutMs);
|
|
579
|
+
timeoutHandle.unref?.();
|
|
502
580
|
});
|
|
503
581
|
}
|
|
504
582
|
var DeputyTask = class extends import_core.Task {
|
|
@@ -644,6 +722,21 @@ var EXECUTION_OBSERVABILITY_INSERT_ROUTINES = /* @__PURE__ */ new Set([
|
|
|
644
722
|
"Insert task_execution",
|
|
645
723
|
"Insert inquiry"
|
|
646
724
|
]);
|
|
725
|
+
var ROOT_DB_OPERATION_CONTEXT_KEYS = [
|
|
726
|
+
"data",
|
|
727
|
+
"batch",
|
|
728
|
+
"transaction",
|
|
729
|
+
"onConflict",
|
|
730
|
+
"filter",
|
|
731
|
+
"fields",
|
|
732
|
+
"joins",
|
|
733
|
+
"sort",
|
|
734
|
+
"limit",
|
|
735
|
+
"offset",
|
|
736
|
+
"queryMode",
|
|
737
|
+
"aggregates",
|
|
738
|
+
"groupBy"
|
|
739
|
+
];
|
|
647
740
|
var DatabaseTask = class extends DeputyTask {
|
|
648
741
|
/**
|
|
649
742
|
* Constructs an instance of the class with the provided parameters, defining
|
|
@@ -752,6 +845,27 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
752
845
|
if (dynamicQueryData.data === void 0 && ctx.data !== void 0) {
|
|
753
846
|
nextQueryData.data = ctx.data && typeof ctx.data === "object" && !Array.isArray(ctx.data) ? { ...ctx.data } : ctx.data;
|
|
754
847
|
}
|
|
848
|
+
const shouldCompactAuthorityBootstrapContext = this.serviceName === "CadenzaDB" && (ctx.__authorityBootstrapChannel === true || metadata.__authorityBootstrapChannel === true || ctx.__metadata?.__authorityBootstrapChannel === true);
|
|
849
|
+
const rootDbOperationContext = shouldCompactAuthorityBootstrapContext ? {} : {
|
|
850
|
+
data: nextQueryData.data ?? ctx.data,
|
|
851
|
+
batch: nextQueryData.batch ?? ctx.batch,
|
|
852
|
+
transaction: nextQueryData.transaction ?? ctx.transaction,
|
|
853
|
+
onConflict: Object.prototype.hasOwnProperty.call(nextQueryData, "onConflict") ? nextQueryData.onConflict : void 0,
|
|
854
|
+
filter: nextQueryData.filter ?? ctx.filter,
|
|
855
|
+
fields: nextQueryData.fields ?? ctx.fields,
|
|
856
|
+
joins: nextQueryData.joins ?? ctx.joins,
|
|
857
|
+
sort: nextQueryData.sort ?? ctx.sort,
|
|
858
|
+
limit: nextQueryData.limit ?? ctx.limit,
|
|
859
|
+
offset: nextQueryData.offset ?? ctx.offset,
|
|
860
|
+
queryMode: nextQueryData.queryMode ?? ctx.queryMode,
|
|
861
|
+
aggregates: nextQueryData.aggregates ?? ctx.aggregates,
|
|
862
|
+
groupBy: nextQueryData.groupBy ?? ctx.groupBy
|
|
863
|
+
};
|
|
864
|
+
if (shouldCompactAuthorityBootstrapContext) {
|
|
865
|
+
for (const key of ROOT_DB_OPERATION_CONTEXT_KEYS) {
|
|
866
|
+
delete ctx[key];
|
|
867
|
+
}
|
|
868
|
+
}
|
|
755
869
|
const deputyContext = attachDelegationRequestSnapshot(
|
|
756
870
|
stripDelegationRequestSnapshot(
|
|
757
871
|
hoistDelegationMetadataFields({
|
|
@@ -771,12 +885,7 @@ var DatabaseTask = class extends DeputyTask {
|
|
|
771
885
|
__blockRemoteExecution: metadata.__blockRemoteExecution ?? ctx.__blockRemoteExecution ?? false,
|
|
772
886
|
__deputyTaskName: this.name
|
|
773
887
|
},
|
|
774
|
-
|
|
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,
|
|
888
|
+
...rootDbOperationContext,
|
|
780
889
|
queryData: nextQueryData
|
|
781
890
|
})
|
|
782
891
|
)
|
|
@@ -1941,6 +2050,163 @@ function getAuthorityBootstrapInsertIntentSpecForTable(tableName) {
|
|
|
1941
2050
|
return getAuthorityBootstrapIntentSpec(intentName);
|
|
1942
2051
|
}
|
|
1943
2052
|
|
|
2053
|
+
// src/execution/ExecutionPersistenceCoordinator.ts
|
|
2054
|
+
var EXECUTION_PERSISTENCE_BUNDLE_SIGNAL = "global.meta.execution_persistence.bundle_requested";
|
|
2055
|
+
function readString(value) {
|
|
2056
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
2057
|
+
}
|
|
2058
|
+
function readRecord(value) {
|
|
2059
|
+
return value && typeof value === "object" && !Array.isArray(value) ? { ...value } : null;
|
|
2060
|
+
}
|
|
2061
|
+
function normalizeRoutineExecutionTraceFields(data) {
|
|
2062
|
+
if (!data) {
|
|
2063
|
+
return null;
|
|
2064
|
+
}
|
|
2065
|
+
const normalizedData = { ...data };
|
|
2066
|
+
const traceId = readString(
|
|
2067
|
+
normalizedData.execution_trace_id ?? normalizedData.executionTraceId
|
|
2068
|
+
);
|
|
2069
|
+
const metaContext = readRecord(normalizedData.meta_context) ?? readRecord(normalizedData.metaContext);
|
|
2070
|
+
const isMeta = normalizedData.is_meta === true || normalizedData.isMeta === true;
|
|
2071
|
+
const serviceName = readString(
|
|
2072
|
+
normalizedData.service_name ?? normalizedData.serviceName
|
|
2073
|
+
);
|
|
2074
|
+
const serviceInstanceId = readString(
|
|
2075
|
+
normalizedData.service_instance_id ?? normalizedData.serviceInstanceId
|
|
2076
|
+
);
|
|
2077
|
+
if (traceId) {
|
|
2078
|
+
normalizedData.execution_trace_id = traceId;
|
|
2079
|
+
}
|
|
2080
|
+
if (metaContext) {
|
|
2081
|
+
normalizedData.meta_context = metaContext;
|
|
2082
|
+
}
|
|
2083
|
+
if (normalizedData.is_meta !== void 0 || normalizedData.isMeta !== void 0) {
|
|
2084
|
+
normalizedData.is_meta = isMeta;
|
|
2085
|
+
}
|
|
2086
|
+
if (serviceName) {
|
|
2087
|
+
normalizedData.service_name = serviceName;
|
|
2088
|
+
}
|
|
2089
|
+
if (serviceInstanceId) {
|
|
2090
|
+
normalizedData.service_instance_id = serviceInstanceId;
|
|
2091
|
+
} else if (normalizedData.serviceInstanceId === null || normalizedData.service_instance_id === null) {
|
|
2092
|
+
normalizedData.service_instance_id = null;
|
|
2093
|
+
}
|
|
2094
|
+
delete normalizedData.executionTraceId;
|
|
2095
|
+
delete normalizedData.traceId;
|
|
2096
|
+
delete normalizedData.metaContext;
|
|
2097
|
+
delete normalizedData.isMeta;
|
|
2098
|
+
delete normalizedData.serviceName;
|
|
2099
|
+
delete normalizedData.serviceInstanceId;
|
|
2100
|
+
return normalizedData;
|
|
2101
|
+
}
|
|
2102
|
+
function stripExecutionTraceServiceInstanceFields(data) {
|
|
2103
|
+
if (!data) {
|
|
2104
|
+
return null;
|
|
2105
|
+
}
|
|
2106
|
+
const normalizedData = { ...data };
|
|
2107
|
+
delete normalizedData.serviceInstanceId;
|
|
2108
|
+
delete normalizedData.service_instance_id;
|
|
2109
|
+
return normalizedData;
|
|
2110
|
+
}
|
|
2111
|
+
function normalizeEnsureData(entityType, data) {
|
|
2112
|
+
switch (entityType) {
|
|
2113
|
+
case "execution_trace":
|
|
2114
|
+
return stripExecutionTraceServiceInstanceFields(data);
|
|
2115
|
+
case "routine_execution":
|
|
2116
|
+
return normalizeRoutineExecutionTraceFields(data);
|
|
2117
|
+
default:
|
|
2118
|
+
return data;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
function buildExecutionPersistenceDependency(entityType, entityId) {
|
|
2122
|
+
const normalizedEntityId = readString(entityId);
|
|
2123
|
+
return normalizedEntityId ? `${entityType}:${normalizedEntityId}` : null;
|
|
2124
|
+
}
|
|
2125
|
+
function resolveEnsureEntityId(entityType, data) {
|
|
2126
|
+
switch (entityType) {
|
|
2127
|
+
default:
|
|
2128
|
+
return readString(data.uuid);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
function resolveUpdateEntityId(_entityType, data, filter) {
|
|
2132
|
+
return readString(
|
|
2133
|
+
filter.uuid ?? filter.taskExecutionId ?? filter.task_execution_id ?? data.uuid ?? data.taskExecutionId ?? data.task_execution_id
|
|
2134
|
+
);
|
|
2135
|
+
}
|
|
2136
|
+
function dedupeDependencies(values) {
|
|
2137
|
+
return Array.from(
|
|
2138
|
+
new Set(values.filter((value) => typeof value === "string"))
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
function resolveTraceIdFromData(data) {
|
|
2142
|
+
if (!data) {
|
|
2143
|
+
return null;
|
|
2144
|
+
}
|
|
2145
|
+
return readString(
|
|
2146
|
+
data.traceId ?? data.executionTraceId ?? data.execution_trace_id ?? data.metaContext?.__executionTraceId ?? data.metaContext?.__metadata?.__executionTraceId ?? data.meta_context?.__executionTraceId ?? data.meta_context?.__metadata?.__executionTraceId
|
|
2147
|
+
);
|
|
2148
|
+
}
|
|
2149
|
+
function buildExecutionPersistenceEnsureEvent(entityType, data, deps = []) {
|
|
2150
|
+
const normalizedData = normalizeEnsureData(entityType, readRecord(data));
|
|
2151
|
+
if (!normalizedData) {
|
|
2152
|
+
return null;
|
|
2153
|
+
}
|
|
2154
|
+
const entityId = resolveEnsureEntityId(entityType, normalizedData);
|
|
2155
|
+
if (!entityId) {
|
|
2156
|
+
return null;
|
|
2157
|
+
}
|
|
2158
|
+
return {
|
|
2159
|
+
kind: "ensure",
|
|
2160
|
+
entityType,
|
|
2161
|
+
entityId,
|
|
2162
|
+
data: normalizedData,
|
|
2163
|
+
deps: dedupeDependencies(deps)
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
function buildExecutionPersistenceUpdateEvent(entityType, data, filter, deps = []) {
|
|
2167
|
+
const normalizedData = readRecord(data);
|
|
2168
|
+
const normalizedFilter = readRecord(filter);
|
|
2169
|
+
if (!normalizedData || !normalizedFilter) {
|
|
2170
|
+
return null;
|
|
2171
|
+
}
|
|
2172
|
+
const entityId = resolveUpdateEntityId(
|
|
2173
|
+
entityType,
|
|
2174
|
+
normalizedData,
|
|
2175
|
+
normalizedFilter
|
|
2176
|
+
);
|
|
2177
|
+
if (!entityId) {
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
return {
|
|
2181
|
+
kind: "update",
|
|
2182
|
+
entityType,
|
|
2183
|
+
entityId,
|
|
2184
|
+
data: normalizedData,
|
|
2185
|
+
filter: normalizedFilter,
|
|
2186
|
+
deps: dedupeDependencies(deps)
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
function createExecutionPersistenceBundle(input) {
|
|
2190
|
+
const ensures = (input.ensures ?? []).filter(
|
|
2191
|
+
(event) => Boolean(event)
|
|
2192
|
+
);
|
|
2193
|
+
const updates = (input.updates ?? []).filter(
|
|
2194
|
+
(event) => Boolean(event)
|
|
2195
|
+
);
|
|
2196
|
+
if (ensures.length === 0 && updates.length === 0) {
|
|
2197
|
+
return null;
|
|
2198
|
+
}
|
|
2199
|
+
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));
|
|
2200
|
+
if (!traceId) {
|
|
2201
|
+
return null;
|
|
2202
|
+
}
|
|
2203
|
+
return {
|
|
2204
|
+
traceId,
|
|
2205
|
+
ensures,
|
|
2206
|
+
updates
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
|
|
1944
2210
|
// src/utils/tools.ts
|
|
1945
2211
|
function formatTimestamp(timestamp) {
|
|
1946
2212
|
return new Date(timestamp).toISOString();
|
|
@@ -2171,12 +2437,24 @@ function listManifestGlobals() {
|
|
|
2171
2437
|
(globalDefinition) => Boolean(globalDefinition && !globalDefinition.destroyed)
|
|
2172
2438
|
);
|
|
2173
2439
|
}
|
|
2174
|
-
function isRoutingCriticalMetaSignal(
|
|
2175
|
-
return
|
|
2440
|
+
function isRoutingCriticalMetaSignal(signal) {
|
|
2441
|
+
return ROUTING_CRITICAL_META_SIGNALS.has(signal.name);
|
|
2176
2442
|
}
|
|
2177
|
-
function isRoutingCriticalMetaIntent(
|
|
2178
|
-
return
|
|
2443
|
+
function isRoutingCriticalMetaIntent(intent) {
|
|
2444
|
+
return ROUTING_CRITICAL_META_INTENTS.has(intent.name);
|
|
2179
2445
|
}
|
|
2446
|
+
var ROUTING_CRITICAL_META_INTENTS = /* @__PURE__ */ new Set([
|
|
2447
|
+
AUTHORITY_BOOTSTRAP_FULL_SYNC_INTENT,
|
|
2448
|
+
AUTHORITY_SERVICE_INSTANCE_REGISTER_INTENT,
|
|
2449
|
+
AUTHORITY_SERVICE_INSTANCE_TRANSPORT_REGISTER_INTENT,
|
|
2450
|
+
AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
|
|
2451
|
+
AUTHORITY_RUNTIME_STATUS_REPORT_INTENT
|
|
2452
|
+
]);
|
|
2453
|
+
var ROUTING_CRITICAL_META_SIGNALS = /* @__PURE__ */ new Set([
|
|
2454
|
+
AUTHORITY_SERVICE_MANIFEST_UPDATED_SIGNAL,
|
|
2455
|
+
EXECUTION_PERSISTENCE_BUNDLE_SIGNAL,
|
|
2456
|
+
...AUTHORITY_BOOTSTRAP_SIGNAL_NAMES
|
|
2457
|
+
]);
|
|
2180
2458
|
function buildServiceManifestSnapshot(params) {
|
|
2181
2459
|
const {
|
|
2182
2460
|
serviceName,
|
|
@@ -2586,87 +2864,9 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2586
2864
|
`${right.routine_name}:${right.task_name}`
|
|
2587
2865
|
)
|
|
2588
2866
|
);
|
|
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
2867
|
const cumulativeTasks = publicationLayer === "routing_capability" ? routingTasks : publicationLayer === "business_structural" ? Array.from(
|
|
2668
2868
|
new Map(
|
|
2669
|
-
[...routingTasks, ...businessTasks
|
|
2869
|
+
[...routingTasks, ...businessTasks].map((task) => [
|
|
2670
2870
|
buildTaskKey(task),
|
|
2671
2871
|
task
|
|
2672
2872
|
])
|
|
@@ -2685,7 +2885,7 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2685
2885
|
);
|
|
2686
2886
|
const cumulativeSignals = publicationLayer === "routing_capability" ? routingSignals : publicationLayer === "business_structural" ? Array.from(
|
|
2687
2887
|
new Map(
|
|
2688
|
-
[...routingSignals, ...businessSignals
|
|
2888
|
+
[...routingSignals, ...businessSignals].map(
|
|
2689
2889
|
(signal) => [signal.name, signal]
|
|
2690
2890
|
)
|
|
2691
2891
|
).values()
|
|
@@ -2699,7 +2899,7 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2699
2899
|
).sort((left, right) => left.name.localeCompare(right.name));
|
|
2700
2900
|
const cumulativeIntents = publicationLayer === "routing_capability" ? routingIntents : publicationLayer === "business_structural" ? Array.from(
|
|
2701
2901
|
new Map(
|
|
2702
|
-
[...routingIntents, ...businessIntents
|
|
2902
|
+
[...routingIntents, ...businessIntents].map(
|
|
2703
2903
|
(intent) => [intent.name, intent]
|
|
2704
2904
|
)
|
|
2705
2905
|
).values()
|
|
@@ -2711,16 +2911,7 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2711
2911
|
])
|
|
2712
2912
|
).values()
|
|
2713
2913
|
).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(
|
|
2914
|
+
const cumulativeActors = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessActors : Array.from(
|
|
2724
2915
|
new Map(
|
|
2725
2916
|
[...businessActors, ...localMetaActors].map((actor) => [
|
|
2726
2917
|
buildActorKey(actor),
|
|
@@ -2730,16 +2921,7 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2730
2921
|
).sort(
|
|
2731
2922
|
(left, right) => `${left.name}:${left.version}`.localeCompare(`${right.name}:${right.version}`)
|
|
2732
2923
|
);
|
|
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(
|
|
2924
|
+
const cumulativeRoutines = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessRoutines : Array.from(
|
|
2743
2925
|
new Map(
|
|
2744
2926
|
[...businessRoutines, ...localMetaRoutines].map((routine) => [
|
|
2745
2927
|
buildRoutineKey(routine),
|
|
@@ -2865,14 +3047,7 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2865
3047
|
)
|
|
2866
3048
|
).values()
|
|
2867
3049
|
);
|
|
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(
|
|
3050
|
+
const cumulativeActorTaskMaps = publicationLayer === "routing_capability" ? [] : publicationLayer === "business_structural" ? businessActorTaskMaps : Array.from(
|
|
2876
3051
|
new Map(
|
|
2877
3052
|
[...businessActorTaskMaps, ...localMetaActorTaskMaps].map((map) => [
|
|
2878
3053
|
`${map.service_name}|${map.actor_name}|${map.actor_version}|${map.task_name}|${map.task_version}|${map.mode}`,
|
|
@@ -2900,8 +3075,8 @@ function buildServiceManifestSnapshot(params) {
|
|
|
2900
3075
|
helpers: cumulativeHelpers,
|
|
2901
3076
|
globals: cumulativeGlobals,
|
|
2902
3077
|
directionalTaskMaps: cumulativeDirectionalTaskMaps,
|
|
2903
|
-
signalToTaskMaps: publicationLayer === "routing_capability" ? publishedSignalTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps] :
|
|
2904
|
-
intentToTaskMaps: publicationLayer === "routing_capability" ? publishedIntentTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps] :
|
|
3078
|
+
signalToTaskMaps: publicationLayer === "routing_capability" ? publishedSignalTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedSignalTaskMaps, ...localMetaSignalTaskMaps] : publishedSignalTaskMaps,
|
|
3079
|
+
intentToTaskMaps: publicationLayer === "routing_capability" ? publishedIntentTaskMaps : publicationLayer === "local_meta_structural" ? [...publishedIntentTaskMaps, ...localMetaIntentTaskMaps] : publishedIntentTaskMaps,
|
|
2905
3080
|
actorTaskMaps: cumulativeActorTaskMaps,
|
|
2906
3081
|
taskToRoutineMaps: cumulativeTaskToRoutineMaps,
|
|
2907
3082
|
taskToHelperMaps: cumulativeTaskToHelperMaps,
|
|
@@ -3065,6 +3240,13 @@ var META_SERVICE_INSTANCE_SHUTDOWN_TRANSPORT_DEACTIVATION_SIGNAL = "meta.service
|
|
|
3065
3240
|
var META_AUTHORITY_BOOTSTRAP_HANDSHAKE_REQUESTED_SIGNAL = "meta.service_registry.authority_bootstrap_handshake_requested";
|
|
3066
3241
|
var META_RUNTIME_STATUS_REST_REFRESH_TICK_SIGNAL = "meta.service_registry.runtime_status.rest_refresh_tick";
|
|
3067
3242
|
var AUTHORITY_BOOTSTRAP_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3243
|
+
var AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS = [
|
|
3244
|
+
1e3,
|
|
3245
|
+
3e3,
|
|
3246
|
+
7e3,
|
|
3247
|
+
15e3
|
|
3248
|
+
];
|
|
3249
|
+
var AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS = 6e4;
|
|
3068
3250
|
var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
3069
3251
|
100,
|
|
3070
3252
|
1500,
|
|
@@ -3074,25 +3256,41 @@ var EARLY_FULL_SYNC_DELAYS_MS = [
|
|
|
3074
3256
|
45e3,
|
|
3075
3257
|
7e4
|
|
3076
3258
|
];
|
|
3259
|
+
var PENDING_ROUTE_SELECTION_RETRY_DELAYS_MS = [
|
|
3260
|
+
50,
|
|
3261
|
+
125,
|
|
3262
|
+
250,
|
|
3263
|
+
500
|
|
3264
|
+
];
|
|
3077
3265
|
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
3266
|
var SERVICE_REGISTRY_TRACE_SERVICE2 = (process.env.CADENZA_SERVICE_REGISTRY_TRACE_SERVICE ?? "").trim();
|
|
3093
3267
|
function shouldTraceServiceRegistry(serviceName) {
|
|
3094
3268
|
return SERVICE_REGISTRY_TRACE_SERVICE2.length > 0 && serviceName === SERVICE_REGISTRY_TRACE_SERVICE2;
|
|
3095
3269
|
}
|
|
3270
|
+
function getFetchFailureText(ctx) {
|
|
3271
|
+
return String(ctx?.__error ?? ctx?.error ?? ctx?.message ?? "").trim();
|
|
3272
|
+
}
|
|
3273
|
+
function isTerminalFetchTransportFailure(ctx) {
|
|
3274
|
+
const errorText = getFetchFailureText(ctx);
|
|
3275
|
+
if (!errorText) {
|
|
3276
|
+
return false;
|
|
3277
|
+
}
|
|
3278
|
+
return errorText.includes("ENOTFOUND") || errorText.includes("ECONNREFUSED") || errorText.includes("EHOSTUNREACH");
|
|
3279
|
+
}
|
|
3280
|
+
function isRecoverableFetchTransportFailure(ctx, options = {}) {
|
|
3281
|
+
const errorText = getFetchFailureText(ctx);
|
|
3282
|
+
if (!errorText) {
|
|
3283
|
+
return false;
|
|
3284
|
+
}
|
|
3285
|
+
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");
|
|
3286
|
+
}
|
|
3287
|
+
function isHardFetchHandshakeFailure(ctx) {
|
|
3288
|
+
const errorText = getFetchFailureText(ctx);
|
|
3289
|
+
if (!errorText) {
|
|
3290
|
+
return false;
|
|
3291
|
+
}
|
|
3292
|
+
return isTerminalFetchTransportFailure(ctx) || isRecoverableFetchTransportFailure(ctx);
|
|
3293
|
+
}
|
|
3096
3294
|
function normalizeLeaseStatus(value) {
|
|
3097
3295
|
const status = String(value ?? "").trim();
|
|
3098
3296
|
if (status === "active" || status === "non_responsive" || status === "inactive" || status === "deleted") {
|
|
@@ -3238,18 +3436,28 @@ function compactAuthorityBootstrapRequestBody(ctx) {
|
|
|
3238
3436
|
if (!isBootstrapDbOperationRoutineName(ctx.__remoteRoutineName)) {
|
|
3239
3437
|
return ctx;
|
|
3240
3438
|
}
|
|
3241
|
-
const
|
|
3242
|
-
|
|
3243
|
-
|
|
3439
|
+
const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? { ...ctx.queryData } : {};
|
|
3440
|
+
const compactQueryData = {};
|
|
3441
|
+
for (const key of BOOTSTRAP_DB_OPERATION_CONTEXT_KEYS) {
|
|
3442
|
+
if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
|
|
3443
|
+
compactQueryData[key] = existingQueryData[key];
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
if (Object.prototype.hasOwnProperty.call(ctx, key)) {
|
|
3447
|
+
compactQueryData[key] = ctx[key];
|
|
3448
|
+
}
|
|
3244
3449
|
}
|
|
3245
3450
|
const compacted = {
|
|
3246
|
-
|
|
3247
|
-
|
|
3451
|
+
__remoteRoutineName: ctx.__remoteRoutineName,
|
|
3452
|
+
__serviceName: ctx.__serviceName,
|
|
3453
|
+
__localServiceName: ctx.__localServiceName,
|
|
3454
|
+
__timeout: ctx.__timeout,
|
|
3455
|
+
__syncing: true,
|
|
3456
|
+
__authorityBootstrapChannel: true,
|
|
3457
|
+
queryData: compactQueryData
|
|
3248
3458
|
};
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
delete compacted[key];
|
|
3252
|
-
}
|
|
3459
|
+
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
3460
|
+
compacted.__reason = ctx.__reason;
|
|
3253
3461
|
}
|
|
3254
3462
|
return compacted;
|
|
3255
3463
|
}
|
|
@@ -3969,6 +4177,11 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
3969
4177
|
handshakeEstablished: false
|
|
3970
4178
|
};
|
|
3971
4179
|
this.authorityBootstrapHandshakeInFlight = false;
|
|
4180
|
+
this.authorityBootstrapHandshakeRetryTimer = null;
|
|
4181
|
+
this.authorityBootstrapHandshakeRetryIndex = 0;
|
|
4182
|
+
this.authorityBootstrapHandshakeRetryGeneration = 0;
|
|
4183
|
+
this.authorityBootstrapHandshakeRetryReason = null;
|
|
4184
|
+
this.authorityBootstrapRecoveryActive = false;
|
|
3972
4185
|
this.authorityFullSyncResponderTask = null;
|
|
3973
4186
|
this.authorityServiceCommunicationPersistenceTask = null;
|
|
3974
4187
|
this.localLifecycleFlushActor = CadenzaService.createActor(
|
|
@@ -4504,7 +4717,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4504
4717
|
return false;
|
|
4505
4718
|
}
|
|
4506
4719
|
this.clearTransportReadyFromContext(ctx);
|
|
4507
|
-
const
|
|
4720
|
+
const serviceName = resolveServiceNameFromContext(ctx);
|
|
4721
|
+
const serviceInstanceId = String(
|
|
4722
|
+
ctx.serviceInstanceId ?? ctx.__instance ?? ctx.filter?.uuid ?? ""
|
|
4723
|
+
).trim();
|
|
4724
|
+
const serviceTransportId = String(
|
|
4725
|
+
ctx.serviceTransportId ?? ctx.__transportId ?? ""
|
|
4726
|
+
).trim();
|
|
4508
4727
|
if (serviceName === "CadenzaDB" && this.hasAuthorityBootstrapHandshakeEstablished()) {
|
|
4509
4728
|
const currentAuthorityInstanceId = String(
|
|
4510
4729
|
this.authorityBootstrapRoute.serviceInstanceId ?? ""
|
|
@@ -4520,6 +4739,26 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4520
4739
|
return true;
|
|
4521
4740
|
}
|
|
4522
4741
|
}
|
|
4742
|
+
const signalName = String(
|
|
4743
|
+
ctx.__signalName ?? ctx.__signalEmission?.fullSignalName ?? ""
|
|
4744
|
+
).trim();
|
|
4745
|
+
const isFetchHandshakeFailure = signalName === "meta.fetch.handshake_failed" || signalName.startsWith("meta.fetch.handshake_failed:");
|
|
4746
|
+
const hardFetchHandshakeFailure = isFetchHandshakeFailure && isHardFetchHandshakeFailure(ctx);
|
|
4747
|
+
const recoverableFetchHandshakeFailure = isFetchHandshakeFailure && isRecoverableFetchTransportFailure(ctx, {
|
|
4748
|
+
includeConnectionRefused: true
|
|
4749
|
+
});
|
|
4750
|
+
const isFetchDelegateFailure = signalName === "meta.fetch.delegate_failed" || signalName.startsWith("meta.fetch.delegate_failed:");
|
|
4751
|
+
const hardFetchDelegateFailure = isFetchDelegateFailure && isHardFetchHandshakeFailure(ctx);
|
|
4752
|
+
const recoverableFetchDelegateFailure = isFetchDelegateFailure && isRecoverableFetchTransportFailure(ctx);
|
|
4753
|
+
if (isFetchDelegateFailure && !hardFetchDelegateFailure) {
|
|
4754
|
+
return false;
|
|
4755
|
+
}
|
|
4756
|
+
if (serviceName === "CadenzaDB" && (isFetchHandshakeFailure && recoverableFetchHandshakeFailure || isFetchDelegateFailure && recoverableFetchDelegateFailure)) {
|
|
4757
|
+
return false;
|
|
4758
|
+
}
|
|
4759
|
+
if (serviceName === "CadenzaDB" && this.authorityBootstrapRecoveryActive) {
|
|
4760
|
+
return false;
|
|
4761
|
+
}
|
|
4523
4762
|
const serviceInstances = this.instances.get(serviceName);
|
|
4524
4763
|
const instances = serviceInstances?.filter((instance) => {
|
|
4525
4764
|
if (serviceInstanceId && instance.uuid === serviceInstanceId) {
|
|
@@ -4543,6 +4782,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4543
4782
|
"warning",
|
|
4544
4783
|
serviceName
|
|
4545
4784
|
);
|
|
4785
|
+
if (serviceName === "CadenzaDB") {
|
|
4786
|
+
this.restartAuthorityBootstrapRecovery("cadenza_db_unreachable");
|
|
4787
|
+
}
|
|
4546
4788
|
for (const instance of instances ?? []) {
|
|
4547
4789
|
if (instance.serviceName === this.serviceName && instance.uuid === this.serviceInstanceId) {
|
|
4548
4790
|
continue;
|
|
@@ -4551,13 +4793,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4551
4793
|
if (affectedTransport && this.hasAnyReadyClientProtocolForTransport(instance, affectedTransport)) {
|
|
4552
4794
|
continue;
|
|
4553
4795
|
}
|
|
4554
|
-
|
|
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, {
|
|
4796
|
+
if ((isFetchHandshakeFailure && (!hardFetchHandshakeFailure || recoverableFetchHandshakeFailure) || isFetchDelegateFailure && (!hardFetchDelegateFailure || recoverableFetchDelegateFailure)) && affectedTransport && this.isCurrentRouteContext(ctx) && this.scheduleDependeeClientRecovery(instance, affectedTransport, {
|
|
4559
4797
|
...ctx,
|
|
4560
|
-
__reason: "fetch_handshake_failed_retry"
|
|
4798
|
+
__reason: isFetchDelegateFailure ? "fetch_delegate_failed_retry" : "fetch_handshake_failed_retry"
|
|
4561
4799
|
})) {
|
|
4562
4800
|
continue;
|
|
4563
4801
|
}
|
|
@@ -4568,10 +4806,36 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4568
4806
|
});
|
|
4569
4807
|
continue;
|
|
4570
4808
|
}
|
|
4809
|
+
if (isFetchHandshakeFailure && recoverableFetchHandshakeFailure || isFetchDelegateFailure && recoverableFetchDelegateFailure) {
|
|
4810
|
+
continue;
|
|
4811
|
+
}
|
|
4571
4812
|
this.applyInstanceLifecycleState(instance, {
|
|
4572
4813
|
isActive: false,
|
|
4573
4814
|
isNonResponsive: true
|
|
4574
4815
|
});
|
|
4816
|
+
const transportsToClear = affectedTransport ? [affectedTransport] : (instance.transports ?? []).filter((transport) => !transport.deleted);
|
|
4817
|
+
for (const transport of transportsToClear) {
|
|
4818
|
+
this.clearTransportFailureState(instance.uuid, transport.uuid);
|
|
4819
|
+
this.clearTransportClientState(instance, transport);
|
|
4820
|
+
this.clearRemoteRouteRecordIfCurrent(
|
|
4821
|
+
instance.serviceName,
|
|
4822
|
+
instance.uuid,
|
|
4823
|
+
transport
|
|
4824
|
+
);
|
|
4825
|
+
this.emitTransportHandleShutdowns(
|
|
4826
|
+
emit2,
|
|
4827
|
+
this.buildTransportRouteKey(instance.serviceName, transport),
|
|
4828
|
+
transport
|
|
4829
|
+
);
|
|
4830
|
+
}
|
|
4831
|
+
emit2("meta.service_registry.service_not_responding", {
|
|
4832
|
+
...ctx,
|
|
4833
|
+
serviceName: instance.serviceName,
|
|
4834
|
+
serviceInstanceId: instance.uuid,
|
|
4835
|
+
serviceTransportId: affectedTransport?.uuid ?? serviceTransportId ?? void 0,
|
|
4836
|
+
routeKey: affectedTransport ? this.buildTransportRouteKey(instance.serviceName, affectedTransport) : ctx.routeKey ?? ctx.__routeKey,
|
|
4837
|
+
__routeKey: affectedTransport ? this.buildTransportRouteKey(instance.serviceName, affectedTransport) : ctx.__routeKey ?? ctx.routeKey
|
|
4838
|
+
});
|
|
4575
4839
|
emit2("global.meta.service_registry.service_not_responding", {
|
|
4576
4840
|
data: {
|
|
4577
4841
|
isActive: false,
|
|
@@ -4600,6 +4864,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4600
4864
|
).doOn(
|
|
4601
4865
|
"meta.fetch.handshake_failed",
|
|
4602
4866
|
"meta.fetch.handshake_failed.*",
|
|
4867
|
+
"meta.fetch.delegate_failed",
|
|
4868
|
+
"meta.fetch.delegate_failed.*",
|
|
4603
4869
|
"meta.socket_client.disconnected",
|
|
4604
4870
|
"meta.socket_client.disconnected.*",
|
|
4605
4871
|
"meta.service_registry.runtime_status_unreachable"
|
|
@@ -4785,12 +5051,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4785
5051
|
return false;
|
|
4786
5052
|
}
|
|
4787
5053
|
}
|
|
4788
|
-
this.
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
__reason: "cadenza_db_unreachable"
|
|
4793
|
-
});
|
|
5054
|
+
if (this.authorityBootstrapRecoveryActive) {
|
|
5055
|
+
return false;
|
|
5056
|
+
}
|
|
5057
|
+
this.restartAuthorityBootstrapRecovery("cadenza_db_unreachable");
|
|
4794
5058
|
return true;
|
|
4795
5059
|
},
|
|
4796
5060
|
"Clears bootstrap full-sync retry satisfaction when the authority becomes unreachable."
|
|
@@ -4810,7 +5074,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
4810
5074
|
return false;
|
|
4811
5075
|
}
|
|
4812
5076
|
this.ensureBootstrapAuthorityControlPlane(ctx, emit2);
|
|
4813
|
-
return this.
|
|
5077
|
+
return this.scheduleNextBootstrapFullSyncRetry(
|
|
4814
5078
|
"cadenza_db_fetch_handshake"
|
|
4815
5079
|
);
|
|
4816
5080
|
},
|
|
@@ -5177,12 +5441,24 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5177
5441
|
preferredRole,
|
|
5178
5442
|
preferredProtocol
|
|
5179
5443
|
);
|
|
5444
|
+
if (this.shouldDemandEstablishRemoteClients(context)) {
|
|
5445
|
+
this.ensureDependeeClientsForService(__serviceName, emit2, context);
|
|
5446
|
+
}
|
|
5447
|
+
const hasPendingRouteableInstance = Boolean(__serviceName) && __serviceName !== "CadenzaDB" && this.hasPendingRouteableInstanceForSelection(
|
|
5448
|
+
__serviceName,
|
|
5449
|
+
context,
|
|
5450
|
+
preferredRole,
|
|
5451
|
+
targetServiceInstanceId
|
|
5452
|
+
);
|
|
5180
5453
|
const activeRoutingCooldown = __serviceName && !targetServiceInstanceId ? this.getActiveRoutingCooldown(
|
|
5181
5454
|
__serviceName,
|
|
5182
5455
|
preferredRole,
|
|
5183
5456
|
preferredProtocol
|
|
5184
5457
|
) : null;
|
|
5185
5458
|
if (activeRoutingCooldown) {
|
|
5459
|
+
if (hasPendingRouteableInstance && this.maybeSchedulePendingRouteSelectionRetry(context, __serviceName)) {
|
|
5460
|
+
return false;
|
|
5461
|
+
}
|
|
5186
5462
|
context.errored = true;
|
|
5187
5463
|
context.__error = `No routeable ${preferredRole} transport available for ${__serviceName}. Waiting for authority route updates before retrying.`;
|
|
5188
5464
|
emit2(
|
|
@@ -5224,9 +5500,6 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5224
5500
|
}
|
|
5225
5501
|
let retries = __retries ?? 0;
|
|
5226
5502
|
let triedInstances = __triedInstances ?? [];
|
|
5227
|
-
if (this.shouldDemandEstablishRemoteClients(context)) {
|
|
5228
|
-
this.ensureDependeeClientsForService(__serviceName, emit2, context);
|
|
5229
|
-
}
|
|
5230
5503
|
const filteredInstances = this.instances.get(__serviceName)?.filter((instance) => {
|
|
5231
5504
|
if (targetServiceInstanceId && instance.uuid !== targetServiceInstanceId) {
|
|
5232
5505
|
return false;
|
|
@@ -5245,6 +5518,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5245
5518
|
)
|
|
5246
5519
|
);
|
|
5247
5520
|
}) ?? [];
|
|
5521
|
+
if (filteredInstances.length === 0 && __serviceName && hasPendingRouteableInstance && this.maybeSchedulePendingRouteSelectionRetry(context, __serviceName)) {
|
|
5522
|
+
return false;
|
|
5523
|
+
}
|
|
5248
5524
|
const instances = this.collapseInstancesByRouteOrigin(
|
|
5249
5525
|
filteredInstances,
|
|
5250
5526
|
context,
|
|
@@ -5588,10 +5864,6 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5588
5864
|
CadenzaService.createMetaTask(
|
|
5589
5865
|
"Track local routine start",
|
|
5590
5866
|
(ctx, emit2) => {
|
|
5591
|
-
const sourceTaskName = String(ctx.__signalEmission?.taskName ?? "");
|
|
5592
|
-
if (INTERNAL_RUNTIME_STATUS_TASK_NAMES.has(sourceTaskName)) {
|
|
5593
|
-
return false;
|
|
5594
|
-
}
|
|
5595
5867
|
const routineId = String(
|
|
5596
5868
|
ctx.filter?.uuid ?? ctx.__routineExecId ?? ""
|
|
5597
5869
|
);
|
|
@@ -5622,10 +5894,6 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
5622
5894
|
CadenzaService.createMetaTask(
|
|
5623
5895
|
"Track local routine end",
|
|
5624
5896
|
(ctx, emit2) => {
|
|
5625
|
-
const sourceTaskName = String(ctx.__signalEmission?.taskName ?? "");
|
|
5626
|
-
if (INTERNAL_RUNTIME_STATUS_TASK_NAMES.has(sourceTaskName)) {
|
|
5627
|
-
return false;
|
|
5628
|
-
}
|
|
5629
5897
|
const routineId = String(
|
|
5630
5898
|
ctx.filter?.uuid ?? ctx.__routineExecId ?? ""
|
|
5631
5899
|
);
|
|
@@ -6259,6 +6527,19 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6259
6527
|
}
|
|
6260
6528
|
return false;
|
|
6261
6529
|
}
|
|
6530
|
+
if (this.serviceName && normalizedLocalInstance.serviceName !== this.serviceName || this.serviceInstanceId && normalizedLocalInstance.uuid !== this.serviceInstanceId) {
|
|
6531
|
+
if (shouldTraceServiceRegistry(
|
|
6532
|
+
resolveServiceNameFromContext(ctx) || this.serviceName
|
|
6533
|
+
)) {
|
|
6534
|
+
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] setup_service_ignored_non_local_instance", {
|
|
6535
|
+
localServiceName: this.serviceName,
|
|
6536
|
+
localServiceInstanceId: this.serviceInstanceId,
|
|
6537
|
+
resolvedServiceName: normalizedLocalInstance.serviceName,
|
|
6538
|
+
resolvedServiceInstanceId: normalizedLocalInstance.uuid
|
|
6539
|
+
});
|
|
6540
|
+
}
|
|
6541
|
+
return false;
|
|
6542
|
+
}
|
|
6262
6543
|
if (shouldTraceServiceRegistry(normalizedLocalInstance.serviceName)) {
|
|
6263
6544
|
console.log("[CADENZA_SERVICE_REGISTRY_TRACE] setup_service", {
|
|
6264
6545
|
localServiceName: this.serviceName,
|
|
@@ -6474,7 +6755,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
6474
6755
|
security_profile: "excluded",
|
|
6475
6756
|
auth_strategy: "excluded",
|
|
6476
6757
|
deleted: "false"
|
|
6477
|
-
}
|
|
6758
|
+
},
|
|
6759
|
+
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
6760
|
}
|
|
6479
6761
|
}
|
|
6480
6762
|
},
|
|
@@ -7406,6 +7688,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7406
7688
|
serviceTransportId: String(ctx.serviceTransportId ?? "").trim() || null,
|
|
7407
7689
|
handshakeEstablished: true
|
|
7408
7690
|
};
|
|
7691
|
+
this.markAuthorityBootstrapHandshakeSatisfied();
|
|
7409
7692
|
return true;
|
|
7410
7693
|
}
|
|
7411
7694
|
getAuthorityBootstrapRestTarget() {
|
|
@@ -7434,6 +7717,92 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7434
7717
|
handshakeEstablished: false
|
|
7435
7718
|
};
|
|
7436
7719
|
}
|
|
7720
|
+
clearAuthorityBootstrapHandshakeRetryTimer() {
|
|
7721
|
+
if (this.authorityBootstrapHandshakeRetryTimer) {
|
|
7722
|
+
clearTimeout(this.authorityBootstrapHandshakeRetryTimer);
|
|
7723
|
+
this.authorityBootstrapHandshakeRetryTimer = null;
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
7726
|
+
invalidateAuthorityBootstrapHandshakeRetryState(reason) {
|
|
7727
|
+
this.authorityBootstrapHandshakeRetryGeneration += 1;
|
|
7728
|
+
this.clearAuthorityBootstrapHandshakeRetryTimer();
|
|
7729
|
+
this.authorityBootstrapHandshakeRetryIndex = 0;
|
|
7730
|
+
if (typeof reason === "string" && reason.trim()) {
|
|
7731
|
+
this.authorityBootstrapHandshakeRetryReason = reason.trim();
|
|
7732
|
+
}
|
|
7733
|
+
}
|
|
7734
|
+
markAuthorityBootstrapHandshakeSatisfied() {
|
|
7735
|
+
this.clearAuthorityBootstrapHandshakeRetryTimer();
|
|
7736
|
+
this.authorityBootstrapHandshakeRetryIndex = AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.length;
|
|
7737
|
+
this.authorityBootstrapHandshakeRetryReason = null;
|
|
7738
|
+
this.authorityBootstrapRecoveryActive = false;
|
|
7739
|
+
}
|
|
7740
|
+
buildJitteredAuthorityBootstrapHandshakeRetryDelayMs(baseDelayMs, attempt) {
|
|
7741
|
+
return buildDeterministicJitteredDelayMs(
|
|
7742
|
+
baseDelayMs,
|
|
7743
|
+
this.bootstrapFullSyncRetryJitterRatio,
|
|
7744
|
+
this.buildDeterministicInstanceJitterKey(
|
|
7745
|
+
`authority-bootstrap-handshake-retry-${attempt}`
|
|
7746
|
+
)
|
|
7747
|
+
);
|
|
7748
|
+
}
|
|
7749
|
+
scheduleAuthorityBootstrapHandshakeRetry(reason) {
|
|
7750
|
+
if (!this.connectsToCadenzaDB || !this.serviceName || this.serviceName === "CadenzaDB") {
|
|
7751
|
+
return false;
|
|
7752
|
+
}
|
|
7753
|
+
if (this.hasAuthorityBootstrapHandshakeEstablished()) {
|
|
7754
|
+
return false;
|
|
7755
|
+
}
|
|
7756
|
+
if (this.authorityBootstrapHandshakeInFlight) {
|
|
7757
|
+
return false;
|
|
7758
|
+
}
|
|
7759
|
+
if (typeof reason === "string" && reason.trim()) {
|
|
7760
|
+
this.authorityBootstrapHandshakeRetryReason = reason.trim();
|
|
7761
|
+
}
|
|
7762
|
+
if (this.authorityBootstrapHandshakeRetryTimer) {
|
|
7763
|
+
return false;
|
|
7764
|
+
}
|
|
7765
|
+
const retryGeneration = this.authorityBootstrapHandshakeRetryGeneration;
|
|
7766
|
+
const retryReason = this.authorityBootstrapHandshakeRetryReason ?? "authority_bootstrap_handshake_retry";
|
|
7767
|
+
const attempt = this.authorityBootstrapHandshakeRetryIndex + 1;
|
|
7768
|
+
const baseDelayMs = AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS[Math.min(
|
|
7769
|
+
this.authorityBootstrapHandshakeRetryIndex,
|
|
7770
|
+
AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.length - 1
|
|
7771
|
+
)] ?? AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.at(-1);
|
|
7772
|
+
const delayMs = this.buildJitteredAuthorityBootstrapHandshakeRetryDelayMs(
|
|
7773
|
+
baseDelayMs,
|
|
7774
|
+
attempt
|
|
7775
|
+
);
|
|
7776
|
+
this.authorityBootstrapHandshakeRetryIndex += 1;
|
|
7777
|
+
this.authorityBootstrapHandshakeRetryTimer = setTimeout(() => {
|
|
7778
|
+
this.authorityBootstrapHandshakeRetryTimer = null;
|
|
7779
|
+
if (this.hasAuthorityBootstrapHandshakeEstablished() || this.authorityBootstrapHandshakeInFlight || retryGeneration !== this.authorityBootstrapHandshakeRetryGeneration) {
|
|
7780
|
+
return;
|
|
7781
|
+
}
|
|
7782
|
+
this.requestAuthorityBootstrapHandshake({
|
|
7783
|
+
__reason: retryReason,
|
|
7784
|
+
__authorityBootstrapRetry: true,
|
|
7785
|
+
__authorityBootstrapRetryAttempt: attempt
|
|
7786
|
+
});
|
|
7787
|
+
}, delayMs);
|
|
7788
|
+
return true;
|
|
7789
|
+
}
|
|
7790
|
+
restartAuthorityBootstrapHandshakeRetryChain(reason) {
|
|
7791
|
+
this.invalidateAuthorityBootstrapHandshakeRetryState(reason);
|
|
7792
|
+
return this.scheduleAuthorityBootstrapHandshakeRetry(reason);
|
|
7793
|
+
}
|
|
7794
|
+
restartAuthorityBootstrapRecovery(reason) {
|
|
7795
|
+
if (this.authorityBootstrapRecoveryActive) {
|
|
7796
|
+
if (typeof reason === "string" && reason.trim()) {
|
|
7797
|
+
this.authorityBootstrapHandshakeRetryReason = reason.trim();
|
|
7798
|
+
}
|
|
7799
|
+
return false;
|
|
7800
|
+
}
|
|
7801
|
+
this.authorityBootstrapRecoveryActive = true;
|
|
7802
|
+
this.invalidateAuthorityBootstrapHandshake();
|
|
7803
|
+
this.invalidateBootstrapFullSyncRetryState(reason);
|
|
7804
|
+
return this.restartAuthorityBootstrapHandshakeRetryChain(reason);
|
|
7805
|
+
}
|
|
7437
7806
|
requestAuthorityBootstrapHandshake(ctx) {
|
|
7438
7807
|
if (!this.connectsToCadenzaDB || !this.serviceName || this.serviceName === "CadenzaDB") {
|
|
7439
7808
|
return false;
|
|
@@ -7640,12 +8009,16 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7640
8009
|
return;
|
|
7641
8010
|
}
|
|
7642
8011
|
const deputyTaskName = `Inquire ${map.intentName} via ${map.serviceName} (${map.taskName} v${map.taskVersion})`;
|
|
7643
|
-
const
|
|
8012
|
+
const shouldUseAuthorityBootstrapTimeout = map.serviceName === "CadenzaDB" && isMetaIntentName(map.intentName);
|
|
8013
|
+
const effectiveTimeout = shouldUseAuthorityBootstrapTimeout ? Math.max(map.timeout ?? 0, AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS) : map.timeout;
|
|
8014
|
+
const authorityBootstrapIntentSpec = map.serviceName === "CadenzaDB" ? getAuthorityBootstrapIntentSpec(map.intentName) : null;
|
|
8015
|
+
const authorityBootstrapTaskName = authorityBootstrapIntentSpec?.authorityTaskName ?? map.taskName;
|
|
8016
|
+
const deputyTask = authorityBootstrapIntentSpec ? CadenzaService.createMetaTask(
|
|
7644
8017
|
deputyTaskName,
|
|
7645
8018
|
async (ctx) => this.invokeAuthorityBootstrapRoutine(
|
|
7646
|
-
|
|
8019
|
+
authorityBootstrapTaskName,
|
|
7647
8020
|
ctx,
|
|
7648
|
-
|
|
8021
|
+
effectiveTimeout ?? AUTHORITY_BOOTSTRAP_ROUTINE_TIMEOUT_MS
|
|
7649
8022
|
),
|
|
7650
8023
|
"Routes reserved authority bootstrap inquiries directly through the post-handshake authority control-plane channel.",
|
|
7651
8024
|
{
|
|
@@ -7655,14 +8028,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7655
8028
|
) : isMetaIntentName(map.intentName) ? CadenzaService.createMetaDeputyTask(map.taskName, map.serviceName, {
|
|
7656
8029
|
register: false,
|
|
7657
8030
|
isHidden: true,
|
|
7658
|
-
timeout:
|
|
8031
|
+
timeout: effectiveTimeout,
|
|
7659
8032
|
retryCount: 1,
|
|
7660
8033
|
retryDelay: 50,
|
|
7661
8034
|
retryDelayFactor: 1.2
|
|
7662
8035
|
}) : CadenzaService.createDeputyTask(map.taskName, map.serviceName, {
|
|
7663
8036
|
register: false,
|
|
7664
8037
|
isHidden: true,
|
|
7665
|
-
timeout:
|
|
8038
|
+
timeout: effectiveTimeout,
|
|
7666
8039
|
retryCount: 1,
|
|
7667
8040
|
retryDelay: 50,
|
|
7668
8041
|
retryDelayFactor: 1.2
|
|
@@ -7676,7 +8049,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7676
8049
|
key,
|
|
7677
8050
|
intentName: map.intentName,
|
|
7678
8051
|
serviceName: map.serviceName,
|
|
7679
|
-
remoteTaskName:
|
|
8052
|
+
remoteTaskName: authorityBootstrapTaskName,
|
|
7680
8053
|
remoteTaskVersion: map.taskVersion,
|
|
7681
8054
|
localTaskName: deputyTask.name || deputyTaskName,
|
|
7682
8055
|
localTask: deputyTask
|
|
@@ -7688,7 +8061,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
7688
8061
|
localServiceName: this.serviceName,
|
|
7689
8062
|
intentName: map.intentName,
|
|
7690
8063
|
remoteServiceName: map.serviceName,
|
|
7691
|
-
remoteTaskName:
|
|
8064
|
+
remoteTaskName: authorityBootstrapTaskName,
|
|
7692
8065
|
remoteTaskVersion: map.taskVersion
|
|
7693
8066
|
});
|
|
7694
8067
|
}
|
|
@@ -8383,11 +8756,55 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
8383
8756
|
if (instance.isFrontend) {
|
|
8384
8757
|
return role === "public";
|
|
8385
8758
|
}
|
|
8386
|
-
return Boolean(
|
|
8387
|
-
this.selectReadyTransportForInstance(instance, routingContext, role)
|
|
8388
|
-
);
|
|
8759
|
+
return Boolean(
|
|
8760
|
+
this.selectReadyTransportForInstance(instance, routingContext, role)
|
|
8761
|
+
);
|
|
8762
|
+
});
|
|
8763
|
+
}
|
|
8764
|
+
hasPendingRouteableInstanceForSelection(serviceName, ctx, role, targetServiceInstanceId) {
|
|
8765
|
+
return (this.instances.get(serviceName) ?? []).some((instance) => {
|
|
8766
|
+
if (targetServiceInstanceId && instance.uuid !== targetServiceInstanceId) {
|
|
8767
|
+
return false;
|
|
8768
|
+
}
|
|
8769
|
+
if (!instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
8770
|
+
return false;
|
|
8771
|
+
}
|
|
8772
|
+
if (instance.isFrontend) {
|
|
8773
|
+
return false;
|
|
8774
|
+
}
|
|
8775
|
+
const transport = this.selectTransportForInstance(instance, ctx, role);
|
|
8776
|
+
if (!transport) {
|
|
8777
|
+
return false;
|
|
8778
|
+
}
|
|
8779
|
+
return !this.hasTransportClientReady(instance, transport);
|
|
8389
8780
|
});
|
|
8390
8781
|
}
|
|
8782
|
+
maybeSchedulePendingRouteSelectionRetry(ctx, serviceName) {
|
|
8783
|
+
const signalName = String(
|
|
8784
|
+
ctx.__signalName ?? ctx.__signalEmission?.fullSignalName ?? ""
|
|
8785
|
+
).trim();
|
|
8786
|
+
if (!signalName) {
|
|
8787
|
+
return false;
|
|
8788
|
+
}
|
|
8789
|
+
const attempt = Math.max(
|
|
8790
|
+
0,
|
|
8791
|
+
Number(ctx.__pendingRouteSelectionAttempt ?? 0) || 0
|
|
8792
|
+
);
|
|
8793
|
+
const delayMs = PENDING_ROUTE_SELECTION_RETRY_DELAYS_MS[attempt];
|
|
8794
|
+
if (delayMs === void 0) {
|
|
8795
|
+
return false;
|
|
8796
|
+
}
|
|
8797
|
+
CadenzaService.schedule(
|
|
8798
|
+
signalName,
|
|
8799
|
+
{
|
|
8800
|
+
...ctx,
|
|
8801
|
+
__pendingRouteSelectionAttempt: attempt + 1,
|
|
8802
|
+
__pendingRouteSelectionServiceName: serviceName
|
|
8803
|
+
},
|
|
8804
|
+
delayMs
|
|
8805
|
+
);
|
|
8806
|
+
return true;
|
|
8807
|
+
}
|
|
8391
8808
|
refreshRoutingCooldownsForService(serviceName) {
|
|
8392
8809
|
if (!serviceName) {
|
|
8393
8810
|
return;
|
|
@@ -9207,8 +9624,8 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
9207
9624
|
this.refreshRoutingCooldownsForService(serviceName);
|
|
9208
9625
|
}
|
|
9209
9626
|
clearTransportReadyFromContext(ctx) {
|
|
9210
|
-
const serviceName =
|
|
9211
|
-
const explicitRouteKey = String(ctx.routeKey ?? "").trim() || parseTransportHandleKey(ctx.fetchId ?? ctx.__fetchId)?.routeKey || "";
|
|
9627
|
+
const serviceName = resolveServiceNameFromContext(ctx);
|
|
9628
|
+
const explicitRouteKey = String(ctx.routeKey ?? ctx.__routeKey ?? "").trim() || parseTransportHandleKey(ctx.fetchId ?? ctx.__fetchId)?.routeKey || "";
|
|
9212
9629
|
const serviceTransportId = String(
|
|
9213
9630
|
ctx.serviceTransportId ?? ctx.__transportId ?? ""
|
|
9214
9631
|
).trim();
|
|
@@ -10803,6 +11220,10 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
10803
11220
|
this.bootstrapFullSyncRetryGeneration = 0;
|
|
10804
11221
|
this.bootstrapFullSyncSatisfied = false;
|
|
10805
11222
|
this.bootstrapFullSyncRetryReason = null;
|
|
11223
|
+
this.clearAuthorityBootstrapHandshakeRetryTimer();
|
|
11224
|
+
this.authorityBootstrapHandshakeRetryIndex = 0;
|
|
11225
|
+
this.authorityBootstrapHandshakeRetryGeneration = 0;
|
|
11226
|
+
this.authorityBootstrapHandshakeRetryReason = null;
|
|
10806
11227
|
this.knownGlobalSignalMaps.clear();
|
|
10807
11228
|
this.authorityBootstrapRoute = {
|
|
10808
11229
|
origin: null,
|
|
@@ -13238,163 +13659,6 @@ var SocketController = class _SocketController {
|
|
|
13238
13659
|
}
|
|
13239
13660
|
};
|
|
13240
13661
|
|
|
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
13662
|
// src/signals/SignalController.ts
|
|
13399
13663
|
var import_uuid5 = require("uuid");
|
|
13400
13664
|
function resolveExecutionObservabilityServiceInstanceId() {
|
|
@@ -13547,7 +13811,7 @@ var SignalController = class _SignalController {
|
|
|
13547
13811
|
intent: traceContext.__metadata?.__intent ?? traceContext.__intent ?? null,
|
|
13548
13812
|
context: {
|
|
13549
13813
|
id: (0, import_uuid5.v4)(),
|
|
13550
|
-
context:
|
|
13814
|
+
context: sanitizedTraceContext
|
|
13551
13815
|
},
|
|
13552
13816
|
is_meta: signalEmission.isMeta,
|
|
13553
13817
|
service_name: CadenzaService.serviceRegistry.serviceName,
|
|
@@ -14137,6 +14401,18 @@ function registerActorSessionPersistenceTasks() {
|
|
|
14137
14401
|
var import_core5 = require("@cadenza.io/core");
|
|
14138
14402
|
var import_uuid6 = require("uuid");
|
|
14139
14403
|
var ACTOR_TASK_METADATA2 = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
|
|
14404
|
+
var ROUTING_CRITICAL_META_INTENTS2 = /* @__PURE__ */ new Set([
|
|
14405
|
+
AUTHORITY_BOOTSTRAP_FULL_SYNC_INTENT,
|
|
14406
|
+
AUTHORITY_SERVICE_INSTANCE_REGISTER_INTENT,
|
|
14407
|
+
AUTHORITY_SERVICE_INSTANCE_TRANSPORT_REGISTER_INTENT,
|
|
14408
|
+
AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
|
|
14409
|
+
AUTHORITY_RUNTIME_STATUS_REPORT_INTENT
|
|
14410
|
+
]);
|
|
14411
|
+
var ROUTING_CRITICAL_META_SIGNALS2 = /* @__PURE__ */ new Set([
|
|
14412
|
+
AUTHORITY_SERVICE_MANIFEST_UPDATED_SIGNAL,
|
|
14413
|
+
EXECUTION_PERSISTENCE_BUNDLE_SIGNAL,
|
|
14414
|
+
...AUTHORITY_BOOTSTRAP_SIGNAL_NAMES
|
|
14415
|
+
]);
|
|
14140
14416
|
function getActorTaskRuntimeMetadata2(taskFunction) {
|
|
14141
14417
|
if (typeof taskFunction !== "function") {
|
|
14142
14418
|
return void 0;
|
|
@@ -14228,7 +14504,7 @@ function buildIntentRegistryData(intent) {
|
|
|
14228
14504
|
};
|
|
14229
14505
|
}
|
|
14230
14506
|
function isLocalOnlySyncIntent(intentName) {
|
|
14231
|
-
return intentName === import_core5.META_ACTOR_SESSION_STATE_PERSIST_INTENT;
|
|
14507
|
+
return intentName === import_core5.META_ACTOR_SESSION_STATE_PERSIST_INTENT || intentName.startsWith("meta-") || intentName.startsWith("global.meta-");
|
|
14232
14508
|
}
|
|
14233
14509
|
function getJoinedContextValue(ctx, key) {
|
|
14234
14510
|
const joinedContexts = Array.isArray(ctx.joinedContexts) ? ctx.joinedContexts : [];
|
|
@@ -14268,6 +14544,32 @@ function buildMinimalSyncSignalContext(ctx, extra = {}) {
|
|
|
14268
14544
|
}
|
|
14269
14545
|
return nextContext;
|
|
14270
14546
|
}
|
|
14547
|
+
function buildMinimalSyncShardContext(ctx, extra = {}) {
|
|
14548
|
+
return {
|
|
14549
|
+
...buildMinimalSyncSignalContext(ctx, extra),
|
|
14550
|
+
tasks: void 0,
|
|
14551
|
+
signals: void 0,
|
|
14552
|
+
intents: void 0,
|
|
14553
|
+
actors: void 0,
|
|
14554
|
+
routines: void 0,
|
|
14555
|
+
serviceInstances: void 0,
|
|
14556
|
+
service_instance_rows: void 0,
|
|
14557
|
+
service_instance_transport_rows: void 0,
|
|
14558
|
+
serviceManifests: void 0,
|
|
14559
|
+
manifests: void 0,
|
|
14560
|
+
signalToTaskMaps: void 0,
|
|
14561
|
+
signal_to_task_maps: void 0,
|
|
14562
|
+
intentToTaskMaps: void 0,
|
|
14563
|
+
intent_to_task_maps: void 0,
|
|
14564
|
+
actorTaskMaps: void 0,
|
|
14565
|
+
actor_task_maps: void 0,
|
|
14566
|
+
directionalTaskMaps: void 0,
|
|
14567
|
+
directional_task_maps: void 0,
|
|
14568
|
+
taskToRoutineMaps: void 0,
|
|
14569
|
+
task_to_routine_maps: void 0,
|
|
14570
|
+
task: void 0
|
|
14571
|
+
};
|
|
14572
|
+
}
|
|
14271
14573
|
function buildSyncInsertQueryData(ctx, queryData = {}) {
|
|
14272
14574
|
const pickQueryData = (source, allowedKeys) => {
|
|
14273
14575
|
const next = {};
|
|
@@ -14305,7 +14607,40 @@ var DEFAULT_SYNC_CYCLE_RUNTIME_STATE = {
|
|
|
14305
14607
|
activeSyncCycleStartedAt: 0,
|
|
14306
14608
|
phase: "idle"
|
|
14307
14609
|
};
|
|
14308
|
-
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY =
|
|
14610
|
+
var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 2;
|
|
14611
|
+
function stripSyncResolverPayload(ctx) {
|
|
14612
|
+
const nextContext = {
|
|
14613
|
+
...ctx
|
|
14614
|
+
};
|
|
14615
|
+
const bulkyStructuralKeys = [
|
|
14616
|
+
"tasks",
|
|
14617
|
+
"helpers",
|
|
14618
|
+
"globals",
|
|
14619
|
+
"signals",
|
|
14620
|
+
"intents",
|
|
14621
|
+
"actors",
|
|
14622
|
+
"routines",
|
|
14623
|
+
"serviceInstances",
|
|
14624
|
+
"serviceInstanceTransports",
|
|
14625
|
+
"serviceManifests",
|
|
14626
|
+
"signalToTaskMaps",
|
|
14627
|
+
"intentToTaskMaps",
|
|
14628
|
+
"actorTaskMaps",
|
|
14629
|
+
"directionalTaskMaps",
|
|
14630
|
+
"taskToRoutineMaps",
|
|
14631
|
+
"registeredGlobalSignals",
|
|
14632
|
+
"registeredGlobalIntents",
|
|
14633
|
+
"registeredActors",
|
|
14634
|
+
"registeredRoutines"
|
|
14635
|
+
];
|
|
14636
|
+
delete nextContext.__resolverOriginalContext;
|
|
14637
|
+
delete nextContext.__resolverQueryData;
|
|
14638
|
+
delete nextContext.joinedContexts;
|
|
14639
|
+
for (const key of bulkyStructuralKeys) {
|
|
14640
|
+
delete nextContext[key];
|
|
14641
|
+
}
|
|
14642
|
+
return nextContext;
|
|
14643
|
+
}
|
|
14309
14644
|
function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
14310
14645
|
if (!graph) {
|
|
14311
14646
|
return void 0;
|
|
@@ -14317,28 +14652,14 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
|
|
|
14317
14652
|
return graph.completionTask;
|
|
14318
14653
|
}
|
|
14319
14654
|
function buildSyncExecutionEnvelope(ctx, queryData) {
|
|
14320
|
-
const originalContext =
|
|
14655
|
+
const originalContext = stripSyncResolverPayload(ctx);
|
|
14321
14656
|
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
14657
|
const nextContext = {
|
|
14336
14658
|
__syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
|
|
14337
14659
|
__syncSourceServiceName: syncSourceServiceName,
|
|
14338
14660
|
__preferredTransportProtocol: "rest",
|
|
14339
14661
|
__resolverOriginalContext: originalContext,
|
|
14340
14662
|
__resolverQueryData: queryData,
|
|
14341
|
-
...rootDbOperationFields,
|
|
14342
14663
|
queryData
|
|
14343
14664
|
};
|
|
14344
14665
|
if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
|
|
@@ -14357,6 +14678,7 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
14357
14678
|
Number(options.concurrency),
|
|
14358
14679
|
REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY
|
|
14359
14680
|
) : REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY,
|
|
14681
|
+
timeout: Number(options.timeout) > 0 ? Number(options.timeout) : 6e4,
|
|
14360
14682
|
register: false,
|
|
14361
14683
|
isHidden: true
|
|
14362
14684
|
});
|
|
@@ -14396,13 +14718,15 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
|
|
|
14396
14718
|
const finalizeExecutionTask = CadenzaService.createMetaTask(
|
|
14397
14719
|
`Finalize graph sync insert for ${tableName}`,
|
|
14398
14720
|
(ctx) => {
|
|
14399
|
-
const originalContext = ctx.__resolverOriginalContext && typeof ctx.__resolverOriginalContext === "object" ?
|
|
14721
|
+
const originalContext = ctx.__resolverOriginalContext && typeof ctx.__resolverOriginalContext === "object" ? stripSyncResolverPayload(
|
|
14722
|
+
ctx.__resolverOriginalContext
|
|
14723
|
+
) : {};
|
|
14400
14724
|
const originalQueryData = ctx.__resolverQueryData && typeof ctx.__resolverQueryData === "object" ? ctx.__resolverQueryData : void 0;
|
|
14401
|
-
const normalizedContext = {
|
|
14725
|
+
const normalizedContext = stripSyncResolverPayload({
|
|
14402
14726
|
...originalContext,
|
|
14403
14727
|
...ctx,
|
|
14404
14728
|
queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : originalQueryData
|
|
14405
|
-
};
|
|
14729
|
+
});
|
|
14406
14730
|
if (originalContext.__syncing === true && !didSyncInsertSucceed(normalizedContext)) {
|
|
14407
14731
|
CadenzaService.debounce("meta.sync_requested", {}, 1e3);
|
|
14408
14732
|
}
|
|
@@ -14476,22 +14800,103 @@ function isBootstrapLocalOnlySignal(signalName) {
|
|
|
14476
14800
|
function hasNonZeroPending(summary) {
|
|
14477
14801
|
return Object.values(summary).some((value) => Number(value) > 0);
|
|
14478
14802
|
}
|
|
14803
|
+
function shouldSkipIdleBootstrapSyncTrigger(input) {
|
|
14804
|
+
if (input?.__forceSyncCycle === true) {
|
|
14805
|
+
return false;
|
|
14806
|
+
}
|
|
14807
|
+
const triggerSignal = typeof input?.__signal === "string" ? input.__signal.trim() : "";
|
|
14808
|
+
const reason = typeof input?.__reason === "string" ? input.__reason.trim() : "";
|
|
14809
|
+
if (!triggerSignal) {
|
|
14810
|
+
return input?.__bootstrapFullSync === true || reason.length > 0;
|
|
14811
|
+
}
|
|
14812
|
+
return triggerSignal === "meta.sync_controller.sync_tick" || triggerSignal === "meta.sync_requested";
|
|
14813
|
+
}
|
|
14479
14814
|
function isRegistrableRoutine(routine) {
|
|
14480
14815
|
return routine?.name !== "RestServer";
|
|
14481
14816
|
}
|
|
14482
14817
|
function scheduleSyncPassEvaluation(delayMs = SYNC_PASS_SETTLE_DELAY_MS) {
|
|
14483
14818
|
CadenzaService.debounce(SYNC_PASS_EVALUATION_SIGNAL, {}, delayMs);
|
|
14484
14819
|
}
|
|
14820
|
+
function isRoutingCriticalMetaSignalName(signalName) {
|
|
14821
|
+
return ROUTING_CRITICAL_META_SIGNALS2.has(canonicalizeSignalName2(signalName));
|
|
14822
|
+
}
|
|
14823
|
+
function isRoutingCriticalMetaIntentName(intentName) {
|
|
14824
|
+
return ROUTING_CRITICAL_META_INTENTS2.has(String(intentName ?? "").trim());
|
|
14825
|
+
}
|
|
14826
|
+
function isRoutingCapabilityBootstrapSignalName(signalName) {
|
|
14827
|
+
const canonicalSignalName = canonicalizeSignalName2(signalName);
|
|
14828
|
+
if (!canonicalSignalName) {
|
|
14829
|
+
return false;
|
|
14830
|
+
}
|
|
14831
|
+
const signalParts = decomposeSignalName(canonicalSignalName);
|
|
14832
|
+
if (!signalParts.isGlobal) {
|
|
14833
|
+
return false;
|
|
14834
|
+
}
|
|
14835
|
+
if (signalParts.isMeta) {
|
|
14836
|
+
return isRoutingCriticalMetaSignalName(canonicalSignalName);
|
|
14837
|
+
}
|
|
14838
|
+
return !isBootstrapLocalOnlySignal(canonicalSignalName);
|
|
14839
|
+
}
|
|
14840
|
+
function isRouteableBusinessBootstrapSignalName(signalName) {
|
|
14841
|
+
const canonicalSignalName = canonicalizeSignalName2(signalName);
|
|
14842
|
+
if (!canonicalSignalName) {
|
|
14843
|
+
return false;
|
|
14844
|
+
}
|
|
14845
|
+
const signalParts = decomposeSignalName(canonicalSignalName);
|
|
14846
|
+
if (!signalParts.isGlobal || signalParts.isMeta) {
|
|
14847
|
+
return false;
|
|
14848
|
+
}
|
|
14849
|
+
return !isBootstrapLocalOnlySignal(canonicalSignalName);
|
|
14850
|
+
}
|
|
14851
|
+
function isRouteableBusinessBootstrapIntentName(intentName) {
|
|
14852
|
+
const normalizedIntentName = String(intentName ?? "").trim();
|
|
14853
|
+
return normalizedIntentName.length > 0 && !isLocalOnlySyncIntent(normalizedIntentName) && !isMetaIntentName(normalizedIntentName);
|
|
14854
|
+
}
|
|
14855
|
+
function isRoutingCapabilityBootstrapTask(task) {
|
|
14856
|
+
if (!task || !task.register || task.isHidden || task.isDeputy) {
|
|
14857
|
+
return false;
|
|
14858
|
+
}
|
|
14859
|
+
const isMetaTask = task.isMeta === true || task.isSubMeta === true;
|
|
14860
|
+
for (const signalName of task.observedSignals) {
|
|
14861
|
+
if (isMetaTask ? isRoutingCriticalMetaSignalName(signalName) : isRouteableBusinessBootstrapSignalName(signalName)) {
|
|
14862
|
+
return true;
|
|
14863
|
+
}
|
|
14864
|
+
}
|
|
14865
|
+
for (const intentName of task.handlesIntents) {
|
|
14866
|
+
if (isMetaTask ? isRoutingCriticalMetaIntentName(intentName) : isRouteableBusinessBootstrapIntentName(intentName)) {
|
|
14867
|
+
return true;
|
|
14868
|
+
}
|
|
14869
|
+
}
|
|
14870
|
+
return false;
|
|
14871
|
+
}
|
|
14872
|
+
function shouldDirectSyncSignalTaskMapForBootstrap(task, signalName) {
|
|
14873
|
+
const canonicalSignalName = canonicalizeSignalName2(signalName);
|
|
14874
|
+
if (!task || !canonicalSignalName || task.isHidden || !task.register || !task.registered) {
|
|
14875
|
+
return false;
|
|
14876
|
+
}
|
|
14877
|
+
if (!decomposeSignalName(canonicalSignalName).isGlobal) {
|
|
14878
|
+
return false;
|
|
14879
|
+
}
|
|
14880
|
+
if (!isRegistrableBootstrapTask(task)) {
|
|
14881
|
+
return false;
|
|
14882
|
+
}
|
|
14883
|
+
return isRoutingCapabilityBootstrapSignalName(canonicalSignalName);
|
|
14884
|
+
}
|
|
14885
|
+
function isRegistrableBootstrapTask(task) {
|
|
14886
|
+
return isRoutingCapabilityBootstrapTask(task);
|
|
14887
|
+
}
|
|
14485
14888
|
function getRegistrableTasks() {
|
|
14486
14889
|
return Array.from(CadenzaService.registry.tasks.values()).filter(
|
|
14487
|
-
|
|
14890
|
+
isRegistrableBootstrapTask
|
|
14488
14891
|
);
|
|
14489
14892
|
}
|
|
14490
14893
|
function getBootstrapBlockingTasks() {
|
|
14491
|
-
return getRegistrableTasks()
|
|
14894
|
+
return getRegistrableTasks();
|
|
14492
14895
|
}
|
|
14493
14896
|
function getRegistrableRoutines() {
|
|
14494
|
-
return Array.from(CadenzaService.registry.routines.values()).filter(
|
|
14897
|
+
return Array.from(CadenzaService.registry.routines.values()).filter(
|
|
14898
|
+
isRegistrableRoutine
|
|
14899
|
+
);
|
|
14495
14900
|
}
|
|
14496
14901
|
function getRegistrableSignalObservers() {
|
|
14497
14902
|
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
@@ -14501,19 +14906,23 @@ function getRegistrableSignalObservers() {
|
|
|
14501
14906
|
const canonicalObservers = /* @__PURE__ */ new Map();
|
|
14502
14907
|
for (const [rawSignalName, observer] of signalObservers.entries()) {
|
|
14503
14908
|
const signalName = canonicalizeSignalName2(rawSignalName);
|
|
14504
|
-
|
|
14909
|
+
const isRoutingCriticalMetaSignal2 = signalName.length > 0 && isRoutingCriticalMetaSignalName(signalName);
|
|
14910
|
+
if (!signalName || isBootstrapLocalOnlySignal(signalName) && !isRoutingCriticalMetaSignal2) {
|
|
14911
|
+
continue;
|
|
14912
|
+
}
|
|
14913
|
+
if (!decomposeSignalName(signalName).isGlobal) {
|
|
14505
14914
|
continue;
|
|
14506
14915
|
}
|
|
14507
14916
|
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
|
-
)) {
|
|
14917
|
+
if (observerTasks.length > 0 && !observerTasks.some((task) => isRegistrableBootstrapTask(task))) {
|
|
14511
14918
|
continue;
|
|
14512
14919
|
}
|
|
14920
|
+
const metadata = CadenzaService.signalBroker.getSignalMetadata(signalName) ?? null;
|
|
14513
14921
|
const existing = canonicalObservers.get(signalName);
|
|
14514
14922
|
canonicalObservers.set(signalName, {
|
|
14515
14923
|
signalName,
|
|
14516
|
-
registered: existing?.registered === true || observer?.registered === true
|
|
14924
|
+
registered: existing?.registered === true || observer?.registered === true,
|
|
14925
|
+
metadata: existing?.metadata ?? metadata
|
|
14517
14926
|
});
|
|
14518
14927
|
}
|
|
14519
14928
|
return Array.from(canonicalObservers.values());
|
|
@@ -14524,7 +14933,10 @@ function isLocallyHandledIntentName(intentName) {
|
|
|
14524
14933
|
return false;
|
|
14525
14934
|
}
|
|
14526
14935
|
for (const task of observer.tasks) {
|
|
14527
|
-
if (
|
|
14936
|
+
if (!task) {
|
|
14937
|
+
continue;
|
|
14938
|
+
}
|
|
14939
|
+
if (isRegistrableBootstrapTask(task)) {
|
|
14528
14940
|
return true;
|
|
14529
14941
|
}
|
|
14530
14942
|
}
|
|
@@ -14555,8 +14967,12 @@ function buildActorRegistrationKey(actor, serviceName) {
|
|
|
14555
14967
|
return `${name}|${data.version}|${serviceName}`;
|
|
14556
14968
|
}
|
|
14557
14969
|
function isBootstrapRegistrableActor(actor) {
|
|
14558
|
-
const
|
|
14559
|
-
|
|
14970
|
+
const actorData = buildActorRegistrationData(actor);
|
|
14971
|
+
const actorName = String(actorData.name ?? "").trim();
|
|
14972
|
+
if (!actorName || isBootstrapLocalOnlyActorName(actorName)) {
|
|
14973
|
+
return false;
|
|
14974
|
+
}
|
|
14975
|
+
return false;
|
|
14560
14976
|
}
|
|
14561
14977
|
function buildSignalTaskMapRegistrationKey(input) {
|
|
14562
14978
|
return `${canonicalizeSignalName2(input.signalName)}|${input.serviceName}|${input.taskName}|${input.taskVersion ?? 1}`;
|
|
@@ -14723,6 +15139,7 @@ function resolveSignalNameFromSyncContext(ctx) {
|
|
|
14723
15139
|
var GraphSyncController = class _GraphSyncController {
|
|
14724
15140
|
constructor() {
|
|
14725
15141
|
this.registeredActors = /* @__PURE__ */ new Set();
|
|
15142
|
+
this.requestedActorRegistrations = /* @__PURE__ */ new Set();
|
|
14726
15143
|
this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
|
|
14727
15144
|
this.registeredIntentDefinitions = /* @__PURE__ */ new Set();
|
|
14728
15145
|
this.authoritativeSignalTaskMaps = /* @__PURE__ */ new Set();
|
|
@@ -15051,9 +15468,10 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15051
15468
|
for (const routine of routines) {
|
|
15052
15469
|
if (!isRegistrableRoutine(routine)) continue;
|
|
15053
15470
|
if (routine.registered) continue;
|
|
15471
|
+
if (routine.registrationRequested === true) continue;
|
|
15472
|
+
routine.registrationRequested = true;
|
|
15054
15473
|
this.routinesSynced = false;
|
|
15055
|
-
yield {
|
|
15056
|
-
__syncing: ctx.__syncing,
|
|
15474
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15057
15475
|
data: {
|
|
15058
15476
|
name: routine.name,
|
|
15059
15477
|
version: routine.version,
|
|
@@ -15062,7 +15480,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15062
15480
|
is_meta: routine.isMeta
|
|
15063
15481
|
},
|
|
15064
15482
|
__routineName: routine.name
|
|
15065
|
-
};
|
|
15483
|
+
});
|
|
15066
15484
|
}
|
|
15067
15485
|
}.bind(this)
|
|
15068
15486
|
);
|
|
@@ -15080,15 +15498,19 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15080
15498
|
{ concurrency: 30 }
|
|
15081
15499
|
);
|
|
15082
15500
|
const registerRoutineTask = CadenzaService.createMetaTask("Register routine", (ctx) => {
|
|
15501
|
+
const routine = resolveLocalRoutineFromSyncContext(ctx);
|
|
15083
15502
|
if (!didSyncInsertSucceed(ctx)) {
|
|
15503
|
+
if (routine) {
|
|
15504
|
+
routine.registrationRequested = false;
|
|
15505
|
+
}
|
|
15084
15506
|
return;
|
|
15085
15507
|
}
|
|
15086
15508
|
scheduleSyncPassEvaluation();
|
|
15087
|
-
const routine = resolveLocalRoutineFromSyncContext(ctx);
|
|
15088
15509
|
if (!routine) {
|
|
15089
15510
|
return true;
|
|
15090
15511
|
}
|
|
15091
15512
|
routine.registered = true;
|
|
15513
|
+
routine.registrationRequested = false;
|
|
15092
15514
|
return true;
|
|
15093
15515
|
}).then(gatherRoutineRegistrationTask);
|
|
15094
15516
|
wireSyncTaskGraph(this.splitRoutinesTask, routineRegistrationGraph, registerRoutineTask);
|
|
@@ -15115,8 +15537,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15115
15537
|
if (!nextTask?.registered) {
|
|
15116
15538
|
continue;
|
|
15117
15539
|
}
|
|
15118
|
-
yield {
|
|
15119
|
-
__syncing: ctx.__syncing,
|
|
15540
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15120
15541
|
data: {
|
|
15121
15542
|
task_name: nextTask.name,
|
|
15122
15543
|
task_version: nextTask.version,
|
|
@@ -15126,7 +15547,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15126
15547
|
},
|
|
15127
15548
|
__routineName: routine.name,
|
|
15128
15549
|
__taskName: nextTask.name
|
|
15129
|
-
};
|
|
15550
|
+
});
|
|
15130
15551
|
}
|
|
15131
15552
|
}
|
|
15132
15553
|
}
|
|
@@ -15180,7 +15601,8 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15180
15601
|
signalName: canonicalizeSignalName2(signal.signal),
|
|
15181
15602
|
data: signal.data
|
|
15182
15603
|
})).filter((signal) => {
|
|
15183
|
-
|
|
15604
|
+
const isRoutingCriticalMetaSignal2 = isRoutingCriticalMetaSignalName(signal.signalName);
|
|
15605
|
+
if (!signal.signalName || signal.data?.registered || isBootstrapLocalOnlySignal(signal.signalName) && !isRoutingCriticalMetaSignal2 || signal.data?.metadata?.is_meta === true && !isRoutingCriticalMetaSignal2) {
|
|
15184
15606
|
return false;
|
|
15185
15607
|
}
|
|
15186
15608
|
if (seenSignals.has(signal.signalName)) {
|
|
@@ -15190,10 +15612,20 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15190
15612
|
return true;
|
|
15191
15613
|
}).map((signal) => signal.signalName);
|
|
15192
15614
|
for (const signal of filteredSignals) {
|
|
15615
|
+
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
15616
|
+
if (!signalObservers?.has(signal)) {
|
|
15617
|
+
CadenzaService.signalBroker.addSignal(signal);
|
|
15618
|
+
}
|
|
15619
|
+
const observer = signalObservers?.get(signal);
|
|
15620
|
+
if (observer?.registrationRequested === true) {
|
|
15621
|
+
continue;
|
|
15622
|
+
}
|
|
15623
|
+
if (observer) {
|
|
15624
|
+
observer.registrationRequested = true;
|
|
15625
|
+
}
|
|
15193
15626
|
const { isMeta, isGlobal, domain, action } = decomposeSignalName(signal);
|
|
15194
15627
|
this.signalsSynced = false;
|
|
15195
|
-
yield {
|
|
15196
|
-
__syncing: ctx.__syncing,
|
|
15628
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15197
15629
|
data: {
|
|
15198
15630
|
name: signal,
|
|
15199
15631
|
is_global: isGlobal,
|
|
@@ -15202,7 +15634,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15202
15634
|
is_meta: isMeta
|
|
15203
15635
|
},
|
|
15204
15636
|
__signal: signal
|
|
15205
|
-
};
|
|
15637
|
+
});
|
|
15206
15638
|
}
|
|
15207
15639
|
}.bind(this)
|
|
15208
15640
|
);
|
|
@@ -15224,21 +15656,25 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15224
15656
|
(ctx, emit2) => {
|
|
15225
15657
|
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
15226
15658
|
const signalName = resolveSignalNameFromSyncContext(ctx);
|
|
15659
|
+
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
15660
|
+
const observer = signalName ? signalObservers?.get(signalName) : void 0;
|
|
15227
15661
|
if (!insertSucceeded) {
|
|
15662
|
+
if (observer) {
|
|
15663
|
+
observer.registrationRequested = false;
|
|
15664
|
+
}
|
|
15228
15665
|
return;
|
|
15229
15666
|
}
|
|
15230
15667
|
scheduleSyncPassEvaluation();
|
|
15231
15668
|
if (!signalName) {
|
|
15232
15669
|
return false;
|
|
15233
15670
|
}
|
|
15234
|
-
const signalObservers = CadenzaService.signalBroker.signalObservers;
|
|
15235
15671
|
if (!signalObservers?.has(signalName)) {
|
|
15236
15672
|
CadenzaService.signalBroker.addSignal(signalName);
|
|
15237
15673
|
}
|
|
15238
|
-
const
|
|
15239
|
-
if (
|
|
15240
|
-
|
|
15241
|
-
|
|
15674
|
+
const resolvedObserver = signalObservers?.get(signalName);
|
|
15675
|
+
if (resolvedObserver) {
|
|
15676
|
+
resolvedObserver.registered = true;
|
|
15677
|
+
resolvedObserver.registrationRequested = false;
|
|
15242
15678
|
}
|
|
15243
15679
|
emit2(
|
|
15244
15680
|
"meta.sync_controller.signal_registered",
|
|
@@ -15318,8 +15754,13 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15318
15754
|
return;
|
|
15319
15755
|
}
|
|
15320
15756
|
for (const task of tasks) {
|
|
15321
|
-
if (
|
|
15757
|
+
if (!task) {
|
|
15758
|
+
continue;
|
|
15759
|
+
}
|
|
15760
|
+
if (!isRegistrableBootstrapTask(task)) continue;
|
|
15322
15761
|
if (task.registered) continue;
|
|
15762
|
+
if (task.registrationRequested === true) continue;
|
|
15763
|
+
task.registrationRequested = true;
|
|
15323
15764
|
const { __functionString, __getTagCallback } = task.export();
|
|
15324
15765
|
this.tasksSynced = false;
|
|
15325
15766
|
const taskRegistrationData = sanitizePersistedTaskSourceFields(task, {
|
|
@@ -15354,11 +15795,10 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15354
15795
|
},
|
|
15355
15796
|
intents: Array.from(task.handlesIntents)
|
|
15356
15797
|
});
|
|
15357
|
-
yield {
|
|
15358
|
-
__syncing: ctx.__syncing,
|
|
15798
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15359
15799
|
data: taskRegistrationData,
|
|
15360
15800
|
__taskName: task.name
|
|
15361
|
-
};
|
|
15801
|
+
});
|
|
15362
15802
|
}
|
|
15363
15803
|
}.bind(this)
|
|
15364
15804
|
);
|
|
@@ -15379,9 +15819,11 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15379
15819
|
"Record registration",
|
|
15380
15820
|
(ctx, emit2) => {
|
|
15381
15821
|
const task = resolveLocalTaskFromSyncContext(ctx);
|
|
15382
|
-
const serviceName2 = resolveSyncServiceName(task);
|
|
15383
15822
|
const insertSucceeded = didSyncInsertSucceed(ctx);
|
|
15384
15823
|
if (!insertSucceeded) {
|
|
15824
|
+
if (task) {
|
|
15825
|
+
task.registrationRequested = false;
|
|
15826
|
+
}
|
|
15385
15827
|
return;
|
|
15386
15828
|
}
|
|
15387
15829
|
scheduleSyncPassEvaluation();
|
|
@@ -15423,11 +15865,15 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15423
15865
|
if (this.registeredActors.has(registrationKey)) {
|
|
15424
15866
|
continue;
|
|
15425
15867
|
}
|
|
15868
|
+
if (this.requestedActorRegistrations.has(registrationKey)) {
|
|
15869
|
+
continue;
|
|
15870
|
+
}
|
|
15871
|
+
this.requestedActorRegistrations.add(registrationKey);
|
|
15426
15872
|
this.actorsSynced = false;
|
|
15427
|
-
yield {
|
|
15873
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15428
15874
|
data,
|
|
15429
15875
|
__actorRegistrationKey: registrationKey
|
|
15430
|
-
};
|
|
15876
|
+
});
|
|
15431
15877
|
}
|
|
15432
15878
|
}.bind(this)
|
|
15433
15879
|
);
|
|
@@ -15447,11 +15893,18 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15447
15893
|
const recordActorRegistrationTask = CadenzaService.createMetaTask(
|
|
15448
15894
|
"Record actor registration",
|
|
15449
15895
|
(ctx) => {
|
|
15896
|
+
const registrationKey = typeof ctx.__actorRegistrationKey === "string" ? ctx.__actorRegistrationKey : "";
|
|
15450
15897
|
if (!didSyncInsertSucceed(ctx)) {
|
|
15898
|
+
if (registrationKey) {
|
|
15899
|
+
this.requestedActorRegistrations.delete(registrationKey);
|
|
15900
|
+
}
|
|
15451
15901
|
return;
|
|
15452
15902
|
}
|
|
15453
15903
|
scheduleSyncPassEvaluation();
|
|
15454
|
-
|
|
15904
|
+
if (registrationKey) {
|
|
15905
|
+
this.requestedActorRegistrations.delete(registrationKey);
|
|
15906
|
+
this.registeredActors.add(registrationKey);
|
|
15907
|
+
}
|
|
15455
15908
|
return true;
|
|
15456
15909
|
}
|
|
15457
15910
|
).then(gatherActorRegistrationTask);
|
|
@@ -15470,17 +15923,95 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15470
15923
|
}
|
|
15471
15924
|
);
|
|
15472
15925
|
this.registerSignalToTaskMapTask = CadenzaService.createMetaTask(
|
|
15473
|
-
"
|
|
15474
|
-
()
|
|
15475
|
-
|
|
15476
|
-
|
|
15477
|
-
|
|
15478
|
-
|
|
15926
|
+
"Register routing-critical signal task maps to DB",
|
|
15927
|
+
function* (ctx) {
|
|
15928
|
+
const task = ctx.task;
|
|
15929
|
+
if (!task) {
|
|
15930
|
+
return;
|
|
15931
|
+
}
|
|
15932
|
+
const serviceName2 = resolveSyncServiceName(task);
|
|
15933
|
+
if (!serviceName2) {
|
|
15934
|
+
return;
|
|
15935
|
+
}
|
|
15936
|
+
for (const signal of task.observedSignals) {
|
|
15937
|
+
const signalName = canonicalizeSignalName2(signal);
|
|
15938
|
+
if (!shouldDirectSyncSignalTaskMapForBootstrap(task, signalName)) {
|
|
15939
|
+
continue;
|
|
15940
|
+
}
|
|
15941
|
+
if (task.registeredSignals.has(signalName)) {
|
|
15942
|
+
continue;
|
|
15943
|
+
}
|
|
15944
|
+
const registrationKey = buildSignalTaskMapRegistrationKey({
|
|
15945
|
+
signalName,
|
|
15946
|
+
serviceName: serviceName2,
|
|
15947
|
+
taskName: task.name,
|
|
15948
|
+
taskVersion: task.version
|
|
15949
|
+
});
|
|
15950
|
+
if (this.authoritativeSignalTaskMaps.has(registrationKey)) {
|
|
15951
|
+
continue;
|
|
15952
|
+
}
|
|
15953
|
+
if (!CadenzaService.signalBroker.signalObservers?.get(signalName)?.registered) {
|
|
15954
|
+
continue;
|
|
15955
|
+
}
|
|
15956
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15957
|
+
data: {
|
|
15958
|
+
signal_name: signalName,
|
|
15959
|
+
is_global: true,
|
|
15960
|
+
task_name: task.name,
|
|
15961
|
+
task_version: task.version,
|
|
15962
|
+
service_name: serviceName2
|
|
15963
|
+
},
|
|
15964
|
+
__taskName: task.name,
|
|
15965
|
+
__signalName: signalName
|
|
15966
|
+
});
|
|
15967
|
+
}
|
|
15968
|
+
}.bind(this),
|
|
15969
|
+
"Routing-critical meta signal-task maps are persisted during bootstrap so authority can route required control-plane signals before deferred manifest replay completes.",
|
|
15479
15970
|
{
|
|
15480
15971
|
register: false,
|
|
15481
15972
|
isHidden: true
|
|
15482
15973
|
}
|
|
15483
15974
|
);
|
|
15975
|
+
const signalTaskMapRegistrationGraph = resolveSyncInsertTask(
|
|
15976
|
+
this.isCadenzaDBReady,
|
|
15977
|
+
"signal_to_task_map",
|
|
15978
|
+
{
|
|
15979
|
+
onConflict: {
|
|
15980
|
+
target: [
|
|
15981
|
+
"signal_name",
|
|
15982
|
+
"is_global",
|
|
15983
|
+
"task_name",
|
|
15984
|
+
"task_version",
|
|
15985
|
+
"service_name"
|
|
15986
|
+
],
|
|
15987
|
+
action: {
|
|
15988
|
+
do: "nothing"
|
|
15989
|
+
}
|
|
15990
|
+
}
|
|
15991
|
+
},
|
|
15992
|
+
{ concurrency: 30 }
|
|
15993
|
+
);
|
|
15994
|
+
const recordSignalTaskMapRegistrationTask = CadenzaService.createMetaTask(
|
|
15995
|
+
"Record signal task map registration",
|
|
15996
|
+
(ctx) => {
|
|
15997
|
+
if (!didSyncInsertSucceed(ctx)) {
|
|
15998
|
+
return;
|
|
15999
|
+
}
|
|
16000
|
+
scheduleSyncPassEvaluation();
|
|
16001
|
+
const task = CadenzaService.get(ctx.__taskName);
|
|
16002
|
+
const signalName = typeof ctx.__signalName === "string" ? canonicalizeSignalName2(ctx.__signalName) : "";
|
|
16003
|
+
if (!task || !signalName) {
|
|
16004
|
+
return true;
|
|
16005
|
+
}
|
|
16006
|
+
task.registeredSignals.add(signalName);
|
|
16007
|
+
return true;
|
|
16008
|
+
}
|
|
16009
|
+
);
|
|
16010
|
+
wireSyncTaskGraph(
|
|
16011
|
+
this.registerSignalToTaskMapTask,
|
|
16012
|
+
signalTaskMapRegistrationGraph,
|
|
16013
|
+
recordSignalTaskMapRegistrationTask
|
|
16014
|
+
);
|
|
15484
16015
|
this.splitIntentsTask = CadenzaService.createMetaTask(
|
|
15485
16016
|
"Split intents for registration",
|
|
15486
16017
|
function* (ctx) {
|
|
@@ -15496,25 +16027,31 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15496
16027
|
if (this.registeredIntentDefinitions.has(intentData.name)) {
|
|
15497
16028
|
continue;
|
|
15498
16029
|
}
|
|
16030
|
+
if (intent.registrationRequested === true) {
|
|
16031
|
+
continue;
|
|
16032
|
+
}
|
|
16033
|
+
intent.registrationRequested = true;
|
|
15499
16034
|
this.intentsSynced = false;
|
|
15500
|
-
yield {
|
|
15501
|
-
__syncing: ctx.__syncing,
|
|
16035
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15502
16036
|
data: intentData,
|
|
15503
16037
|
__intentName: intentData.name
|
|
15504
|
-
};
|
|
16038
|
+
});
|
|
15505
16039
|
}
|
|
15506
16040
|
}.bind(this)
|
|
15507
16041
|
);
|
|
15508
16042
|
const recordIntentDefinitionRegistrationTask = CadenzaService.createMetaTask(
|
|
15509
16043
|
"Record intent definition registration",
|
|
15510
16044
|
(ctx, emit2) => {
|
|
16045
|
+
const intentName = typeof ctx.__intentName === "string" ? ctx.__intentName : "";
|
|
16046
|
+
const intentDefinition = intentName ? CadenzaService.inquiryBroker.intents.get(intentName) ?? null : null;
|
|
15511
16047
|
if (!didSyncInsertSucceed(ctx)) {
|
|
16048
|
+
if (intentDefinition) {
|
|
16049
|
+
intentDefinition.registrationRequested = false;
|
|
16050
|
+
}
|
|
15512
16051
|
return;
|
|
15513
16052
|
}
|
|
15514
16053
|
scheduleSyncPassEvaluation();
|
|
15515
|
-
const intentName = typeof ctx.__intentName === "string" ? ctx.__intentName : "";
|
|
15516
16054
|
this.registeredIntentDefinitions.add(intentName);
|
|
15517
|
-
const intentDefinition = intentName ? CadenzaService.inquiryBroker.intents.get(intentName) ?? null : null;
|
|
15518
16055
|
if (intentDefinition) {
|
|
15519
16056
|
intentDefinition.registered = true;
|
|
15520
16057
|
intentDefinition.registrationRequested = false;
|
|
@@ -15774,6 +16311,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15774
16311
|
"Register task map to DB",
|
|
15775
16312
|
function* (ctx) {
|
|
15776
16313
|
const task = ctx.task;
|
|
16314
|
+
if (!task) {
|
|
16315
|
+
return;
|
|
16316
|
+
}
|
|
15777
16317
|
if (task.hidden || !task.register || task.isDeputy || !task.registered) {
|
|
15778
16318
|
return;
|
|
15779
16319
|
}
|
|
@@ -15782,6 +16322,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15782
16322
|
return;
|
|
15783
16323
|
}
|
|
15784
16324
|
for (const t of task.nextTasks) {
|
|
16325
|
+
if (!t) {
|
|
16326
|
+
continue;
|
|
16327
|
+
}
|
|
15785
16328
|
if (task.taskMapRegistration.has(t.name) || t.hidden || !t.register || !t.registered || !shouldTrackDirectionalTaskMapForBootstrap(task, t)) {
|
|
15786
16329
|
continue;
|
|
15787
16330
|
}
|
|
@@ -15789,7 +16332,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15789
16332
|
if (!serviceName2) {
|
|
15790
16333
|
continue;
|
|
15791
16334
|
}
|
|
15792
|
-
yield {
|
|
16335
|
+
yield buildMinimalSyncShardContext(ctx, {
|
|
15793
16336
|
data: {
|
|
15794
16337
|
task_name: t.name,
|
|
15795
16338
|
task_version: t.version,
|
|
@@ -15800,7 +16343,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
15800
16343
|
},
|
|
15801
16344
|
__taskName: task.name,
|
|
15802
16345
|
__nextTaskName: t.name
|
|
15803
|
-
};
|
|
16346
|
+
});
|
|
15804
16347
|
}
|
|
15805
16348
|
}
|
|
15806
16349
|
);
|
|
@@ -16388,19 +16931,6 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16388
16931
|
if (!ServiceRegistry.instance.hasLocalInstanceRegistered()) {
|
|
16389
16932
|
return false;
|
|
16390
16933
|
}
|
|
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
16934
|
if (state.activeSyncCycleId) {
|
|
16405
16935
|
const activeCycleAgeMs = now - state.activeSyncCycleStartedAt;
|
|
16406
16936
|
if (activeCycleAgeMs < BOOTSTRAP_SYNC_STALE_CYCLE_MS) {
|
|
@@ -16427,6 +16957,19 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16427
16957
|
});
|
|
16428
16958
|
}
|
|
16429
16959
|
}
|
|
16960
|
+
const primitivePendingSummary = buildPrimitivePendingSummary();
|
|
16961
|
+
const mapPendingSummary = buildMapPendingSummary();
|
|
16962
|
+
const hasPendingWork = hasNonZeroPending(primitivePendingSummary) || hasNonZeroPending(mapPendingSummary);
|
|
16963
|
+
if (!hasPendingWork && shouldSkipIdleBootstrapSyncTrigger(ctx)) {
|
|
16964
|
+
if (shouldTraceSyncPhase(serviceName2)) {
|
|
16965
|
+
console.log("[CADENZA_SYNC_PHASE_TRACE] sync_cycle_skipped_idle", {
|
|
16966
|
+
serviceName: serviceName2,
|
|
16967
|
+
triggerSignal: typeof ctx.__signal === "string" ? ctx.__signal : void 0,
|
|
16968
|
+
reason: typeof ctx.__reason === "string" ? ctx.__reason : void 0
|
|
16969
|
+
});
|
|
16970
|
+
}
|
|
16971
|
+
return false;
|
|
16972
|
+
}
|
|
16430
16973
|
const syncCycleId = `${now}-${(0, import_uuid6.v4)()}`;
|
|
16431
16974
|
setRuntimeState({
|
|
16432
16975
|
activeSyncCycleId: syncCycleId,
|
|
@@ -16535,22 +17078,43 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16535
17078
|
const getSignalsForSyncTask = CadenzaService.createMetaTask(
|
|
16536
17079
|
"Get signals for sync",
|
|
16537
17080
|
(ctx) => {
|
|
16538
|
-
const
|
|
16539
|
-
|
|
16540
|
-
|
|
16541
|
-
|
|
16542
|
-
|
|
16543
|
-
|
|
16544
|
-
|
|
16545
|
-
|
|
16546
|
-
|
|
16547
|
-
|
|
16548
|
-
|
|
17081
|
+
const canonicalSignals = /* @__PURE__ */ new Map();
|
|
17082
|
+
for (const observer of getRegistrableSignalObservers()) {
|
|
17083
|
+
const signalName = canonicalizeSignalName2(observer.signalName);
|
|
17084
|
+
if (!signalName || signalName.includes(":")) {
|
|
17085
|
+
continue;
|
|
17086
|
+
}
|
|
17087
|
+
canonicalSignals.set(signalName, {
|
|
17088
|
+
signal: signalName,
|
|
17089
|
+
data: {
|
|
17090
|
+
registered: observer.registered ?? false,
|
|
17091
|
+
metadata: observer.metadata ?? null
|
|
17092
|
+
}
|
|
17093
|
+
});
|
|
17094
|
+
}
|
|
17095
|
+
for (const emittedSignal of CadenzaService.signalBroker.emittedSignalsRegistry) {
|
|
17096
|
+
const signalName = canonicalizeSignalName2(emittedSignal);
|
|
17097
|
+
if (!signalName || signalName.includes(":")) {
|
|
17098
|
+
continue;
|
|
17099
|
+
}
|
|
17100
|
+
if (canonicalSignals.has(signalName)) {
|
|
17101
|
+
continue;
|
|
16549
17102
|
}
|
|
16550
|
-
|
|
17103
|
+
const metadata = CadenzaService.signalBroker.getSignalMetadata(signalName) ?? null;
|
|
17104
|
+
if (metadata?.is_meta === true || isBootstrapLocalOnlySignal(signalName)) {
|
|
17105
|
+
continue;
|
|
17106
|
+
}
|
|
17107
|
+
canonicalSignals.set(signalName, {
|
|
17108
|
+
signal: signalName,
|
|
17109
|
+
data: {
|
|
17110
|
+
registered: CadenzaService.signalBroker.signalObservers.get(signalName)?.registered ?? false,
|
|
17111
|
+
metadata
|
|
17112
|
+
}
|
|
17113
|
+
});
|
|
17114
|
+
}
|
|
16551
17115
|
return {
|
|
16552
17116
|
...ctx,
|
|
16553
|
-
signals:
|
|
17117
|
+
signals: Array.from(canonicalSignals.values())
|
|
16554
17118
|
};
|
|
16555
17119
|
},
|
|
16556
17120
|
"Collects local signals for the primitive sync phase.",
|
|
@@ -16587,9 +17151,9 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16587
17151
|
"Get all actors for sync",
|
|
16588
17152
|
(ctx) => ({
|
|
16589
17153
|
...ctx,
|
|
16590
|
-
actors:
|
|
17154
|
+
actors: []
|
|
16591
17155
|
}),
|
|
16592
|
-
"
|
|
17156
|
+
"Actor definitions are staged through service-manifest publication rather than the bootstrap primitive sync phase.",
|
|
16593
17157
|
{
|
|
16594
17158
|
register: false,
|
|
16595
17159
|
isHidden: true
|
|
@@ -16621,7 +17185,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16621
17185
|
"Iterate tasks for directional task map sync",
|
|
16622
17186
|
function* (ctx) {
|
|
16623
17187
|
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16624
|
-
yield
|
|
17188
|
+
yield buildMinimalSyncShardContext(ctx, { task });
|
|
16625
17189
|
}
|
|
16626
17190
|
},
|
|
16627
17191
|
"Iterates local tasks for directional task-map sync.",
|
|
@@ -16640,7 +17204,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16640
17204
|
"Iterate tasks for signal task map sync",
|
|
16641
17205
|
function* (ctx) {
|
|
16642
17206
|
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16643
|
-
yield
|
|
17207
|
+
yield buildMinimalSyncShardContext(ctx, { task });
|
|
16644
17208
|
}
|
|
16645
17209
|
},
|
|
16646
17210
|
"Iterates local tasks for signal-to-task map sync.",
|
|
@@ -16654,12 +17218,12 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16654
17218
|
gatherSignalTaskMapRegistrationTask
|
|
16655
17219
|
);
|
|
16656
17220
|
iterateTasksForSignalTaskMapSyncTask.then(this.registerSignalToTaskMapTask);
|
|
16657
|
-
|
|
17221
|
+
recordSignalTaskMapRegistrationTask.then(gatherSignalTaskMapRegistrationTask);
|
|
16658
17222
|
const iterateTasksForIntentTaskMapSyncTask = CadenzaService.createMetaTask(
|
|
16659
17223
|
"Iterate tasks for intent task map sync",
|
|
16660
17224
|
function* (ctx) {
|
|
16661
17225
|
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16662
|
-
yield
|
|
17226
|
+
yield buildMinimalSyncShardContext(ctx, { task });
|
|
16663
17227
|
}
|
|
16664
17228
|
},
|
|
16665
17229
|
"Iterates local tasks for intent-to-task map sync.",
|
|
@@ -16678,7 +17242,7 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
16678
17242
|
"Iterate tasks for actor task map sync",
|
|
16679
17243
|
function* (ctx) {
|
|
16680
17244
|
for (const task of CadenzaService.registry.tasks.values()) {
|
|
16681
|
-
yield
|
|
17245
|
+
yield buildMinimalSyncShardContext(ctx, { task });
|
|
16682
17246
|
}
|
|
16683
17247
|
},
|
|
16684
17248
|
"Iterates local tasks for actor-to-task map sync.",
|
|
@@ -16811,7 +17375,7 @@ function sanitizePersistedTaskSourceFields2(task, data) {
|
|
|
16811
17375
|
};
|
|
16812
17376
|
}
|
|
16813
17377
|
function shouldSkipDirectTaskMetadata(task) {
|
|
16814
|
-
return !task || !task.register || task.isHidden || task.isDeputy;
|
|
17378
|
+
return !task || !task.register || task.isHidden || task.isDeputy || task.isMeta || task.isSubMeta;
|
|
16815
17379
|
}
|
|
16816
17380
|
function isManagedRouteRecoveryTaskError(errorMessage) {
|
|
16817
17381
|
if (typeof errorMessage !== "string") {
|
|
@@ -16825,7 +17389,10 @@ function isLocallyHandledIntentName2(intentName) {
|
|
|
16825
17389
|
return false;
|
|
16826
17390
|
}
|
|
16827
17391
|
for (const task of observer.tasks) {
|
|
16828
|
-
if (
|
|
17392
|
+
if (!task) {
|
|
17393
|
+
continue;
|
|
17394
|
+
}
|
|
17395
|
+
if (task.register && !task.isHidden && !task.isDeputy && !task.isMeta && !task.isSubMeta) {
|
|
16829
17396
|
return true;
|
|
16830
17397
|
}
|
|
16831
17398
|
}
|
|
@@ -17064,7 +17631,7 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17064
17631
|
return false;
|
|
17065
17632
|
}
|
|
17066
17633
|
const helper = resolveHelperFromMetadataContext(ctx);
|
|
17067
|
-
if (!helper) {
|
|
17634
|
+
if (!helper || helper.isMeta) {
|
|
17068
17635
|
return false;
|
|
17069
17636
|
}
|
|
17070
17637
|
return buildDatabaseTriggerContext({
|
|
@@ -17079,7 +17646,7 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17079
17646
|
return false;
|
|
17080
17647
|
}
|
|
17081
17648
|
const globalDefinition = resolveGlobalFromMetadataContext(ctx);
|
|
17082
|
-
if (!globalDefinition) {
|
|
17649
|
+
if (!globalDefinition || globalDefinition.isMeta) {
|
|
17083
17650
|
return false;
|
|
17084
17651
|
}
|
|
17085
17652
|
return buildDatabaseTriggerContext({
|
|
@@ -17181,6 +17748,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17181
17748
|
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17182
17749
|
return false;
|
|
17183
17750
|
}
|
|
17751
|
+
if (ctx.data?.isMeta === true) {
|
|
17752
|
+
return false;
|
|
17753
|
+
}
|
|
17184
17754
|
return buildDatabaseTriggerContext({
|
|
17185
17755
|
...ctx.data,
|
|
17186
17756
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
@@ -17190,6 +17760,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17190
17760
|
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17191
17761
|
return false;
|
|
17192
17762
|
}
|
|
17763
|
+
if (ctx.data?.isMeta === true) {
|
|
17764
|
+
return false;
|
|
17765
|
+
}
|
|
17193
17766
|
return buildDatabaseTriggerContext(
|
|
17194
17767
|
ctx.data ?? void 0,
|
|
17195
17768
|
{
|
|
@@ -17858,6 +18431,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17858
18431
|
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17859
18432
|
return false;
|
|
17860
18433
|
}
|
|
18434
|
+
if (ctx.data?.is_meta === true) {
|
|
18435
|
+
return false;
|
|
18436
|
+
}
|
|
17861
18437
|
if (shouldSkipDirectActorMetadata(ctx?.data?.name)) {
|
|
17862
18438
|
return false;
|
|
17863
18439
|
}
|
|
@@ -17870,6 +18446,9 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
17870
18446
|
if (!shouldEmitDirectPrimitiveMetadata()) {
|
|
17871
18447
|
return false;
|
|
17872
18448
|
}
|
|
18449
|
+
if (ctx.data?.is_meta === true) {
|
|
18450
|
+
return false;
|
|
18451
|
+
}
|
|
17873
18452
|
if (shouldSkipDirectActorMetadata(ctx?.data?.actor_name)) {
|
|
17874
18453
|
return false;
|
|
17875
18454
|
}
|
|
@@ -18335,6 +18914,8 @@ function resetBrowserRuntimeActorHandles() {
|
|
|
18335
18914
|
|
|
18336
18915
|
// src/Cadenza.ts
|
|
18337
18916
|
var POSTGRES_SETUP_DEBUG_ENABLED = process.env.CADENZA_POSTGRES_SETUP_DEBUG === "1" || process.env.CADENZA_POSTGRES_SETUP_DEBUG === "true";
|
|
18917
|
+
var DEFAULT_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS = 15e3;
|
|
18918
|
+
var LOCAL_AUTHORITY_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS = 6e4;
|
|
18338
18919
|
function resolveInquiryFailureError(inquiry, value, depth = 3, seen = /* @__PURE__ */ new Set()) {
|
|
18339
18920
|
if (depth < 0 || value === null || value === void 0) {
|
|
18340
18921
|
return `Inquiry '${inquiry}' did not complete successfully`;
|
|
@@ -18396,6 +18977,10 @@ var SERVICE_MANIFEST_PUBLICATION_ORDER = [
|
|
|
18396
18977
|
"business_structural",
|
|
18397
18978
|
"local_meta_structural"
|
|
18398
18979
|
];
|
|
18980
|
+
var ROUTING_CAPABILITY_PUBLICATION_RETRY_DELAY_MS = 250;
|
|
18981
|
+
var BUSINESS_STRUCTURAL_PUBLICATION_CALM_DELAY_MS = 1500;
|
|
18982
|
+
var LOCAL_META_STRUCTURAL_PUBLICATION_CALM_DELAY_MS = 15e3;
|
|
18983
|
+
var MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS = 1e3;
|
|
18399
18984
|
function getServiceManifestPublicationLayerRank(layer) {
|
|
18400
18985
|
const index = SERVICE_MANIFEST_PUBLICATION_ORDER.indexOf(layer);
|
|
18401
18986
|
return index >= 0 ? index : SERVICE_MANIFEST_PUBLICATION_ORDER.length - 1;
|
|
@@ -18529,43 +19114,250 @@ var CadenzaService = class {
|
|
|
18529
19114
|
static normalizeServiceManifestPublicationLayer(value, fallback = "business_structural") {
|
|
18530
19115
|
return value === "routing_capability" || value === "business_structural" || value === "local_meta_structural" ? value : fallback;
|
|
18531
19116
|
}
|
|
19117
|
+
static clampServiceManifestPublicationLayer(targetLayer) {
|
|
19118
|
+
const maximumLayer = this.isLocalAuthorityService() ? "routing_capability" : "local_meta_structural";
|
|
19119
|
+
return getServiceManifestPublicationLayerRank(targetLayer) > getServiceManifestPublicationLayerRank(maximumLayer) ? maximumLayer : targetLayer;
|
|
19120
|
+
}
|
|
18532
19121
|
static mergeServiceManifestPublicationRequest(reason, targetLayer) {
|
|
18533
19122
|
this.serviceManifestPublicationPendingReason = reason;
|
|
19123
|
+
const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
|
|
18534
19124
|
const currentTargetLayer = this.serviceManifestPublicationPendingLayer ?? "routing_capability";
|
|
18535
|
-
this.serviceManifestPublicationPendingLayer = getServiceManifestPublicationLayerRank(
|
|
19125
|
+
this.serviceManifestPublicationPendingLayer = getServiceManifestPublicationLayerRank(normalizedTargetLayer) >= getServiceManifestPublicationLayerRank(currentTargetLayer) ? normalizedTargetLayer : currentTargetLayer;
|
|
19126
|
+
}
|
|
19127
|
+
static getServiceManifestPublicationGate(publicationLayer) {
|
|
19128
|
+
if (!this.localServiceManifestDefinitionInserted || !this.localServiceManifestInstanceInserted) {
|
|
19129
|
+
return {
|
|
19130
|
+
ready: false,
|
|
19131
|
+
delayMs: ROUTING_CAPABILITY_PUBLICATION_RETRY_DELAY_MS
|
|
19132
|
+
};
|
|
19133
|
+
}
|
|
19134
|
+
if (publicationLayer === "routing_capability") {
|
|
19135
|
+
return {
|
|
19136
|
+
ready: true,
|
|
19137
|
+
delayMs: 0
|
|
19138
|
+
};
|
|
19139
|
+
}
|
|
19140
|
+
if (!this.bootstrapSyncCompleted || this.bootstrapSyncCompletedAt <= 0) {
|
|
19141
|
+
return {
|
|
19142
|
+
ready: false,
|
|
19143
|
+
delayMs: MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS
|
|
19144
|
+
};
|
|
19145
|
+
}
|
|
19146
|
+
const now = Date.now();
|
|
19147
|
+
if (publicationLayer === "business_structural") {
|
|
19148
|
+
const allowedAt2 = this.bootstrapSyncCompletedAt + BUSINESS_STRUCTURAL_PUBLICATION_CALM_DELAY_MS;
|
|
19149
|
+
return {
|
|
19150
|
+
ready: now >= allowedAt2,
|
|
19151
|
+
delayMs: Math.max(1, allowedAt2 - now)
|
|
19152
|
+
};
|
|
19153
|
+
}
|
|
19154
|
+
const businessPublishedAt = this.serviceManifestPublishedAt.business_structural ?? 0;
|
|
19155
|
+
if (!this.lastPublishedServiceManifestHashes.business_structural || businessPublishedAt <= 0) {
|
|
19156
|
+
return {
|
|
19157
|
+
ready: false,
|
|
19158
|
+
delayMs: MANIFEST_PUBLICATION_PREREQUISITE_RETRY_DELAY_MS
|
|
19159
|
+
};
|
|
19160
|
+
}
|
|
19161
|
+
const allowedAt = businessPublishedAt + LOCAL_META_STRUCTURAL_PUBLICATION_CALM_DELAY_MS;
|
|
19162
|
+
return {
|
|
19163
|
+
ready: now >= allowedAt,
|
|
19164
|
+
delayMs: Math.max(1, allowedAt - now)
|
|
19165
|
+
};
|
|
18536
19166
|
}
|
|
18537
19167
|
static requestServiceManifestPublication(reason, immediate = false, targetLayer = "business_structural") {
|
|
18538
19168
|
if (!this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
|
|
18539
19169
|
return;
|
|
18540
19170
|
}
|
|
19171
|
+
const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
|
|
18541
19172
|
const signalName = "meta.service_manifest.publish_requested";
|
|
18542
19173
|
const payload = {
|
|
18543
19174
|
__reason: reason,
|
|
18544
19175
|
__serviceName: this.serviceRegistry.serviceName,
|
|
18545
19176
|
__serviceInstanceId: this.serviceRegistry.serviceInstanceId,
|
|
18546
|
-
__publicationLayer:
|
|
19177
|
+
__publicationLayer: normalizedTargetLayer
|
|
18547
19178
|
};
|
|
18548
19179
|
if (immediate) {
|
|
18549
|
-
this.
|
|
19180
|
+
if (this.serviceManifestPublicationRetryTimer) {
|
|
19181
|
+
clearTimeout(this.serviceManifestPublicationRetryTimer);
|
|
19182
|
+
this.serviceManifestPublicationRetryTimer = null;
|
|
19183
|
+
}
|
|
19184
|
+
void this.publishServiceManifestIfNeeded(reason, normalizedTargetLayer);
|
|
18550
19185
|
return;
|
|
18551
19186
|
}
|
|
18552
19187
|
this.debounce(signalName, payload, 100);
|
|
18553
19188
|
}
|
|
18554
|
-
static scheduleServiceManifestPublicationRetry(reason, targetLayer = "business_structural") {
|
|
19189
|
+
static scheduleServiceManifestPublicationRetry(reason, targetLayer = "business_structural", options) {
|
|
18555
19190
|
if (!this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
|
|
18556
19191
|
return;
|
|
18557
19192
|
}
|
|
19193
|
+
this.serviceManifestPublicationRetryReason = reason;
|
|
19194
|
+
const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
|
|
19195
|
+
const currentRetryLayer = this.serviceManifestPublicationRetryLayer ?? "routing_capability";
|
|
19196
|
+
this.serviceManifestPublicationRetryLayer = getServiceManifestPublicationLayerRank(normalizedTargetLayer) >= getServiceManifestPublicationLayerRank(currentRetryLayer) ? normalizedTargetLayer : currentRetryLayer;
|
|
19197
|
+
if (this.serviceManifestPublicationRetryTimer) {
|
|
19198
|
+
return;
|
|
19199
|
+
}
|
|
19200
|
+
const retryReason = this.serviceManifestPublicationRetryReason ?? reason;
|
|
19201
|
+
const retryTargetLayer = this.serviceManifestPublicationRetryLayer ?? targetLayer;
|
|
19202
|
+
const shouldIncrementRetryCount = options?.incrementRetryCount !== false;
|
|
19203
|
+
const delayMs = options?.delayMs ?? Math.min(
|
|
19204
|
+
1e4,
|
|
19205
|
+
1e3 * Math.max(1, 2 ** this.serviceManifestPublicationRetryCount)
|
|
19206
|
+
);
|
|
19207
|
+
if (shouldIncrementRetryCount) {
|
|
19208
|
+
this.serviceManifestPublicationRetryCount += 1;
|
|
19209
|
+
}
|
|
19210
|
+
this.serviceManifestPublicationRetryTimer = setTimeout(() => {
|
|
19211
|
+
this.serviceManifestPublicationRetryTimer = null;
|
|
19212
|
+
const pendingReason = this.serviceManifestPublicationRetryReason ?? retryReason;
|
|
19213
|
+
const pendingLayer = this.serviceManifestPublicationRetryLayer ?? retryTargetLayer;
|
|
19214
|
+
this.serviceManifestPublicationRetryReason = null;
|
|
19215
|
+
this.serviceManifestPublicationRetryLayer = null;
|
|
19216
|
+
void this.publishServiceManifestIfNeeded(pendingReason, pendingLayer);
|
|
19217
|
+
}, delayMs);
|
|
19218
|
+
}
|
|
19219
|
+
static shouldPublishBusinessManifestForTaskContext(ctx) {
|
|
19220
|
+
const task = ctx?.taskInstance ?? (typeof ctx?.data?.name === "string" ? this.get(ctx.data.name) : void 0);
|
|
19221
|
+
if (task) {
|
|
19222
|
+
if (this.isRoutingCriticalManifestTask(task)) {
|
|
19223
|
+
return true;
|
|
19224
|
+
}
|
|
19225
|
+
return task.register === true && task.isMeta !== true && task.isSubMeta !== true && task.isHidden !== true && task.isEphemeral !== true;
|
|
19226
|
+
}
|
|
19227
|
+
if (this.hasRoutingCriticalManifestBindingInContext(ctx)) {
|
|
19228
|
+
return true;
|
|
19229
|
+
}
|
|
19230
|
+
return ctx?.data?.isMeta !== true && ctx?.data?.isSubMeta !== true && ctx?.data?.isHidden !== true && ctx?.data?.isEphemeral !== true && ctx?.__isSubMeta !== true;
|
|
19231
|
+
}
|
|
19232
|
+
static isRoutingCriticalManifestSignalName(signalName) {
|
|
19233
|
+
const normalizedSignalName = String(signalName ?? "").trim();
|
|
19234
|
+
if (!normalizedSignalName) {
|
|
19235
|
+
return false;
|
|
19236
|
+
}
|
|
19237
|
+
return normalizedSignalName === EXECUTION_PERSISTENCE_BUNDLE_SIGNAL || isAuthorityBootstrapSignal(normalizedSignalName);
|
|
19238
|
+
}
|
|
19239
|
+
static isRoutingCriticalManifestIntentName(intentName) {
|
|
19240
|
+
return isAuthorityBootstrapIntent(intentName);
|
|
19241
|
+
}
|
|
19242
|
+
static isRoutingCriticalManifestTask(task) {
|
|
19243
|
+
for (const signalName of task.observedSignals ?? []) {
|
|
19244
|
+
if (this.isRoutingCriticalManifestSignalName(signalName)) {
|
|
19245
|
+
return true;
|
|
19246
|
+
}
|
|
19247
|
+
}
|
|
19248
|
+
for (const intentName of task.handlesIntents ?? []) {
|
|
19249
|
+
if (this.isRoutingCriticalManifestIntentName(intentName)) {
|
|
19250
|
+
return true;
|
|
19251
|
+
}
|
|
19252
|
+
}
|
|
19253
|
+
return false;
|
|
19254
|
+
}
|
|
19255
|
+
static hasRoutingCriticalManifestBindingInContext(ctx) {
|
|
19256
|
+
const signalCandidates = [
|
|
19257
|
+
ctx?.signalName,
|
|
19258
|
+
ctx?.data?.signalName,
|
|
19259
|
+
ctx?.data?.signal_name
|
|
19260
|
+
];
|
|
19261
|
+
for (const signalName of signalCandidates) {
|
|
19262
|
+
if (this.isRoutingCriticalManifestSignalName(signalName)) {
|
|
19263
|
+
return true;
|
|
19264
|
+
}
|
|
19265
|
+
}
|
|
19266
|
+
const intentCandidates = [
|
|
19267
|
+
ctx?.intentName,
|
|
19268
|
+
ctx?.data?.intentName,
|
|
19269
|
+
ctx?.data?.intent_name
|
|
19270
|
+
];
|
|
19271
|
+
for (const intentName of intentCandidates) {
|
|
19272
|
+
if (this.isRoutingCriticalManifestIntentName(intentName)) {
|
|
19273
|
+
return true;
|
|
19274
|
+
}
|
|
19275
|
+
}
|
|
19276
|
+
return false;
|
|
19277
|
+
}
|
|
19278
|
+
static shouldPublishBusinessManifestForHelperContext(ctx) {
|
|
19279
|
+
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 : "";
|
|
19280
|
+
const helper = helperName ? import_core6.default.getHelper(helperName) : void 0;
|
|
19281
|
+
if (helper) {
|
|
19282
|
+
return helper.isMeta !== true;
|
|
19283
|
+
}
|
|
19284
|
+
return ctx?.data?.isMeta !== true;
|
|
19285
|
+
}
|
|
19286
|
+
static shouldPublishBusinessManifestForGlobalContext(ctx) {
|
|
19287
|
+
const globalName = typeof ctx?.data?.name === "string" ? ctx.data.name : typeof ctx?.data?.globalName === "string" ? ctx.data.globalName : "";
|
|
19288
|
+
const globalDefinition = globalName ? import_core6.default.getGlobal(globalName) : void 0;
|
|
19289
|
+
if (globalDefinition) {
|
|
19290
|
+
return globalDefinition.isMeta !== true;
|
|
19291
|
+
}
|
|
19292
|
+
return ctx?.data?.isMeta !== true;
|
|
19293
|
+
}
|
|
19294
|
+
static shouldPublishBusinessManifestForRoutineContext(ctx) {
|
|
19295
|
+
const routineName = typeof ctx?.data?.name === "string" ? ctx.data.name : "";
|
|
19296
|
+
const routine = routineName ? this.getRoutine(routineName) : void 0;
|
|
19297
|
+
if (routine) {
|
|
19298
|
+
return routine.isMeta !== true;
|
|
19299
|
+
}
|
|
19300
|
+
return ctx?.data?.isMeta !== true;
|
|
19301
|
+
}
|
|
19302
|
+
static shouldRequestServiceManifestPublicationForSignal(ctx) {
|
|
19303
|
+
const signalName = typeof ctx?.signal === "string" && ctx.signal.trim().length > 0 ? ctx.signal.trim() : "";
|
|
19304
|
+
switch (signalName) {
|
|
19305
|
+
case "meta.task.created":
|
|
19306
|
+
case "meta.task.destroyed":
|
|
19307
|
+
case "meta.task.relationship_added":
|
|
19308
|
+
case "meta.task.relationship_removed":
|
|
19309
|
+
case "meta.task.intent_associated":
|
|
19310
|
+
case "meta.task.helper_associated":
|
|
19311
|
+
case "meta.task.global_associated":
|
|
19312
|
+
case "meta.task.observed_signal":
|
|
19313
|
+
case "meta.task.attached_signal":
|
|
19314
|
+
case "meta.task.detached_signal":
|
|
19315
|
+
return this.shouldPublishBusinessManifestForTaskContext(ctx);
|
|
19316
|
+
case "meta.helper.created":
|
|
19317
|
+
case "meta.helper.updated":
|
|
19318
|
+
case "meta.helper.helper_associated":
|
|
19319
|
+
case "meta.helper.global_associated":
|
|
19320
|
+
return this.shouldPublishBusinessManifestForHelperContext(ctx);
|
|
19321
|
+
case "meta.global.created":
|
|
19322
|
+
case "meta.global.updated":
|
|
19323
|
+
return this.shouldPublishBusinessManifestForGlobalContext(ctx);
|
|
19324
|
+
case "meta.actor.created":
|
|
19325
|
+
case "meta.actor.task_associated":
|
|
19326
|
+
return ctx?.data?.is_meta !== true && ctx?.__isSubMeta !== true;
|
|
19327
|
+
case "global.meta.graph_metadata.routine_created":
|
|
19328
|
+
case "global.meta.graph_metadata.routine_updated":
|
|
19329
|
+
return this.shouldPublishBusinessManifestForRoutineContext(ctx);
|
|
19330
|
+
default:
|
|
19331
|
+
return false;
|
|
19332
|
+
}
|
|
19333
|
+
}
|
|
19334
|
+
static maybeRequestInitialServiceManifestPublication(reason, targetLayer = "business_structural") {
|
|
19335
|
+
if (this.initialServiceManifestPublicationRequested || !this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId || !this.localServiceManifestDefinitionInserted || !this.localServiceManifestInstanceInserted) {
|
|
19336
|
+
return false;
|
|
19337
|
+
}
|
|
19338
|
+
this.initialServiceManifestPublicationRequested = true;
|
|
19339
|
+
this.requestServiceManifestPublication(reason, true, targetLayer);
|
|
19340
|
+
return true;
|
|
19341
|
+
}
|
|
19342
|
+
static scheduleInitialServiceManifestPublicationFallback(reason, targetLayer = "business_structural") {
|
|
19343
|
+
if (!this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
|
|
19344
|
+
return;
|
|
19345
|
+
}
|
|
18558
19346
|
setTimeout(() => {
|
|
18559
|
-
this.
|
|
19347
|
+
if (this.initialServiceManifestPublicationRequested || !this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
|
|
19348
|
+
return;
|
|
19349
|
+
}
|
|
19350
|
+
this.requestServiceManifestPublication(reason, true, targetLayer);
|
|
18560
19351
|
}, 1e3);
|
|
18561
19352
|
}
|
|
18562
19353
|
static async publishServiceManifestIfNeeded(reason, targetLayer = "business_structural") {
|
|
18563
|
-
if (!this.
|
|
19354
|
+
if (!this.canPublishServiceManifestToAuthority() || !this.serviceRegistry.serviceName || !this.serviceRegistry.serviceInstanceId) {
|
|
18564
19355
|
return false;
|
|
18565
19356
|
}
|
|
18566
19357
|
const publishReason = typeof reason === "string" && reason.trim().length > 0 ? reason.trim() : "service_manifest_publish";
|
|
19358
|
+
const normalizedTargetLayer = this.clampServiceManifestPublicationLayer(targetLayer);
|
|
18567
19359
|
const publishTargetLayer = this.normalizeServiceManifestPublicationLayer(
|
|
18568
|
-
|
|
19360
|
+
normalizedTargetLayer
|
|
18569
19361
|
);
|
|
18570
19362
|
if (this.serviceManifestPublicationInFlight) {
|
|
18571
19363
|
this.mergeServiceManifestPublicationRequest(
|
|
@@ -18598,13 +19390,23 @@ var CadenzaService = class {
|
|
|
18598
19390
|
const hasPendingFollowupLayer = publicationPlan.some(
|
|
18599
19391
|
(entry) => entry.changed && getServiceManifestPublicationLayerRank(entry.layer) > getServiceManifestPublicationLayerRank(publicationLayer)
|
|
18600
19392
|
);
|
|
19393
|
+
const publicationGate = this.getServiceManifestPublicationGate(publicationLayer);
|
|
19394
|
+
if (!publicationGate.ready) {
|
|
19395
|
+
this.scheduleServiceManifestPublicationRetry(publishReason, publishTargetLayer, {
|
|
19396
|
+
delayMs: publicationGate.delayMs,
|
|
19397
|
+
incrementRetryCount: false
|
|
19398
|
+
});
|
|
19399
|
+
return false;
|
|
19400
|
+
}
|
|
18601
19401
|
this.serviceManifestPublicationInFlight = true;
|
|
18602
19402
|
try {
|
|
18603
|
-
this.
|
|
18604
|
-
|
|
18605
|
-
|
|
18606
|
-
|
|
18607
|
-
|
|
19403
|
+
if (!this.isLocalAuthorityService()) {
|
|
19404
|
+
this.serviceRegistry.ensureBootstrapAuthorityControlPlaneForInquiry(
|
|
19405
|
+
AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT,
|
|
19406
|
+
snapshot
|
|
19407
|
+
);
|
|
19408
|
+
}
|
|
19409
|
+
if (this.shouldRequireAuthorityBootstrapHandshakeForManifestPublication() && !this.serviceRegistry.hasAuthorityBootstrapHandshakeEstablished()) {
|
|
18608
19410
|
this.scheduleServiceManifestPublicationRetry(
|
|
18609
19411
|
publishReason,
|
|
18610
19412
|
publishTargetLayer
|
|
@@ -18612,11 +19414,13 @@ var CadenzaService = class {
|
|
|
18612
19414
|
return false;
|
|
18613
19415
|
}
|
|
18614
19416
|
await this.inquire(AUTHORITY_SERVICE_MANIFEST_REPORT_INTENT, snapshot, {
|
|
18615
|
-
timeout:
|
|
19417
|
+
timeout: this.isLocalAuthorityService() ? LOCAL_AUTHORITY_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS : DEFAULT_SERVICE_MANIFEST_PUBLICATION_TIMEOUT_MS,
|
|
18616
19418
|
requireComplete: true
|
|
18617
19419
|
});
|
|
18618
19420
|
this.serviceManifestRevision = snapshot.revision;
|
|
18619
19421
|
this.lastPublishedServiceManifestHashes[publicationLayer] = snapshot.manifestHash;
|
|
19422
|
+
this.serviceManifestPublishedAt[publicationLayer] = Date.now();
|
|
19423
|
+
this.serviceManifestPublicationRetryCount = 0;
|
|
18620
19424
|
if (hasPendingFollowupLayer) {
|
|
18621
19425
|
this.mergeServiceManifestPublicationRequest(
|
|
18622
19426
|
publishReason,
|
|
@@ -18652,14 +19456,7 @@ var CadenzaService = class {
|
|
|
18652
19456
|
const pendingLayer = this.serviceManifestPublicationPendingLayer;
|
|
18653
19457
|
this.serviceManifestPublicationPendingReason = null;
|
|
18654
19458
|
this.serviceManifestPublicationPendingLayer = null;
|
|
18655
|
-
this.
|
|
18656
|
-
"meta.service_manifest.publish_requested",
|
|
18657
|
-
{
|
|
18658
|
-
__reason: pendingReason,
|
|
18659
|
-
__publicationLayer: pendingLayer
|
|
18660
|
-
},
|
|
18661
|
-
100
|
|
18662
|
-
);
|
|
19459
|
+
void this.publishServiceManifestIfNeeded(pendingReason, pendingLayer);
|
|
18663
19460
|
}
|
|
18664
19461
|
}
|
|
18665
19462
|
}
|
|
@@ -18673,7 +19470,7 @@ var CadenzaService = class {
|
|
|
18673
19470
|
typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0 ? ctx.__reason.trim() : "service_manifest_publish",
|
|
18674
19471
|
this.normalizeServiceManifestPublicationLayer(
|
|
18675
19472
|
ctx.__publicationLayer,
|
|
18676
|
-
"
|
|
19473
|
+
"local_meta_structural"
|
|
18677
19474
|
)
|
|
18678
19475
|
),
|
|
18679
19476
|
"Publishes staged static manifest snapshots to authority when the manifest hash changes.",
|
|
@@ -18685,14 +19482,17 @@ var CadenzaService = class {
|
|
|
18685
19482
|
this.createMetaTask(
|
|
18686
19483
|
"Request manifest publication after structural change",
|
|
18687
19484
|
(ctx) => {
|
|
19485
|
+
if (!this.shouldRequestServiceManifestPublicationForSignal(ctx)) {
|
|
19486
|
+
return false;
|
|
19487
|
+
}
|
|
18688
19488
|
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 =
|
|
19489
|
+
const targetLayer = this.normalizeServiceManifestPublicationLayer(
|
|
18690
19490
|
ctx.__publicationLayer,
|
|
18691
|
-
"
|
|
19491
|
+
"local_meta_structural"
|
|
18692
19492
|
);
|
|
18693
19493
|
this.requestServiceManifestPublication(
|
|
18694
19494
|
reason,
|
|
18695
|
-
|
|
19495
|
+
false,
|
|
18696
19496
|
targetLayer
|
|
18697
19497
|
);
|
|
18698
19498
|
return true;
|
|
@@ -18703,7 +19503,6 @@ var CadenzaService = class {
|
|
|
18703
19503
|
isHidden: true
|
|
18704
19504
|
}
|
|
18705
19505
|
).doOn(
|
|
18706
|
-
"meta.service_registry.instance_inserted",
|
|
18707
19506
|
"meta.task.created",
|
|
18708
19507
|
"meta.task.destroyed",
|
|
18709
19508
|
"meta.task.relationship_added",
|
|
@@ -18722,14 +19521,21 @@ var CadenzaService = class {
|
|
|
18722
19521
|
"meta.helper.global_associated",
|
|
18723
19522
|
"meta.actor.created",
|
|
18724
19523
|
"meta.actor.task_associated",
|
|
18725
|
-
"meta.fetch.handshake_complete",
|
|
18726
19524
|
"meta.service_registry.registered_global_signals",
|
|
18727
19525
|
"meta.service_registry.registered_global_intents",
|
|
18728
|
-
"meta.service_registry.initial_sync_complete",
|
|
18729
19526
|
"global.meta.graph_metadata.routine_created",
|
|
18730
19527
|
"global.meta.graph_metadata.routine_updated"
|
|
18731
19528
|
);
|
|
18732
19529
|
}
|
|
19530
|
+
static isLocalAuthorityService() {
|
|
19531
|
+
return this.serviceRegistry.serviceName === "CadenzaDB";
|
|
19532
|
+
}
|
|
19533
|
+
static canPublishServiceManifestToAuthority() {
|
|
19534
|
+
return this.serviceRegistry.connectsToCadenzaDB || this.isLocalAuthorityService();
|
|
19535
|
+
}
|
|
19536
|
+
static shouldRequireAuthorityBootstrapHandshakeForManifestPublication() {
|
|
19537
|
+
return !this.isLocalAuthorityService();
|
|
19538
|
+
}
|
|
18733
19539
|
static buildLegacyLocalCadenzaDBTaskName(tableName, operation) {
|
|
18734
19540
|
const operationPrefix = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
18735
19541
|
const helperSuffix = (0, import_lodash_es.camelCase)(String(tableName ?? "").trim());
|
|
@@ -18896,6 +19702,7 @@ var CadenzaService = class {
|
|
|
18896
19702
|
}
|
|
18897
19703
|
static markBootstrapSyncCompleted() {
|
|
18898
19704
|
this.bootstrapSyncCompleted = true;
|
|
19705
|
+
this.bootstrapSyncCompletedAt = Date.now();
|
|
18899
19706
|
}
|
|
18900
19707
|
/**
|
|
18901
19708
|
* Emits a signal with the specified data using the associated broker.
|
|
@@ -19726,6 +20533,7 @@ var CadenzaService = class {
|
|
|
19726
20533
|
this.validateServiceName(serviceName);
|
|
19727
20534
|
const serviceId = options.customServiceId ?? (0, import_uuid7.v4)();
|
|
19728
20535
|
this.bootstrapSyncCompleted = false;
|
|
20536
|
+
this.bootstrapSyncCompletedAt = 0;
|
|
19729
20537
|
this.bootstrapSignalRegistrationsCompleted = false;
|
|
19730
20538
|
this.bootstrapIntentRegistrationsCompleted = false;
|
|
19731
20539
|
this.serviceRegistry.serviceName = serviceName;
|
|
@@ -19961,6 +20769,7 @@ var CadenzaService = class {
|
|
|
19961
20769
|
__declaredTransports: declaredTransports
|
|
19962
20770
|
};
|
|
19963
20771
|
let bootstrapServiceCreationRequested = false;
|
|
20772
|
+
const emitLocalServiceCreationImmediately = !options.cadenzaDB?.connect;
|
|
19964
20773
|
if (options.cadenzaDB?.connect) {
|
|
19965
20774
|
this.createMetaTask(
|
|
19966
20775
|
"Create service",
|
|
@@ -19983,7 +20792,6 @@ var CadenzaService = class {
|
|
|
19983
20792
|
}
|
|
19984
20793
|
).doOn("meta.fetch.handshake_complete");
|
|
19985
20794
|
} else {
|
|
19986
|
-
this.emit("meta.create_service_requested", initContext);
|
|
19987
20795
|
this.createMetaTask("Create signal transmission for sync", (ctx, emit2) => {
|
|
19988
20796
|
emit2(
|
|
19989
20797
|
"meta.service_registry.gathered_sync_transmission_reconcile_requested",
|
|
@@ -19995,6 +20803,20 @@ var CadenzaService = class {
|
|
|
19995
20803
|
}).doOn("meta.rest.handshake", "meta.socket.handshake");
|
|
19996
20804
|
}
|
|
19997
20805
|
let serviceSetupCompletedHandled = false;
|
|
20806
|
+
this.createMetaTask("Handle local service definition insertion", (ctx) => {
|
|
20807
|
+
const insertedServiceName = String(
|
|
20808
|
+
ctx?.__serviceName ?? ctx?.serviceName ?? ctx?.service_name ?? ctx?.data?.name ?? ""
|
|
20809
|
+
).trim();
|
|
20810
|
+
if (!insertedServiceName || insertedServiceName !== serviceName) {
|
|
20811
|
+
return false;
|
|
20812
|
+
}
|
|
20813
|
+
this.localServiceManifestDefinitionInserted = true;
|
|
20814
|
+
this.maybeRequestInitialServiceManifestPublication(
|
|
20815
|
+
"service_setup_completed",
|
|
20816
|
+
"local_meta_structural"
|
|
20817
|
+
);
|
|
20818
|
+
return true;
|
|
20819
|
+
}).doOn("meta.service_registry.service_inserted");
|
|
19998
20820
|
this.createMetaTask("Handle service setup completion", (ctx, emit2) => {
|
|
19999
20821
|
if (serviceSetupCompletedHandled) {
|
|
20000
20822
|
return false;
|
|
@@ -20015,13 +20837,18 @@ var CadenzaService = class {
|
|
|
20015
20837
|
return false;
|
|
20016
20838
|
}
|
|
20017
20839
|
serviceSetupCompletedHandled = true;
|
|
20840
|
+
this.localServiceManifestInstanceInserted = true;
|
|
20018
20841
|
if (options.cadenzaDB?.connect) {
|
|
20019
20842
|
this.serviceRegistry.bootstrapFullSync(emit2, ctx, "service_setup_completed");
|
|
20020
|
-
void this.publishServiceManifestIfNeeded(
|
|
20021
|
-
"service_setup_completed",
|
|
20022
|
-
"business_structural"
|
|
20023
|
-
);
|
|
20024
20843
|
}
|
|
20844
|
+
this.maybeRequestInitialServiceManifestPublication(
|
|
20845
|
+
"service_setup_completed",
|
|
20846
|
+
"local_meta_structural"
|
|
20847
|
+
);
|
|
20848
|
+
this.scheduleInitialServiceManifestPublicationFallback(
|
|
20849
|
+
"service_setup_completed",
|
|
20850
|
+
"local_meta_structural"
|
|
20851
|
+
);
|
|
20025
20852
|
if (isFrontend) {
|
|
20026
20853
|
registerActorSessionPersistenceTasks();
|
|
20027
20854
|
this.ensureFrontendSyncLoop();
|
|
@@ -20029,6 +20856,9 @@ var CadenzaService = class {
|
|
|
20029
20856
|
this.log("Service created.");
|
|
20030
20857
|
return true;
|
|
20031
20858
|
}).doOn("meta.service_registry.instance_inserted");
|
|
20859
|
+
if (emitLocalServiceCreationImmediately) {
|
|
20860
|
+
this.emit("meta.create_service_requested", initContext);
|
|
20861
|
+
}
|
|
20032
20862
|
if (!options.cadenzaDB?.connect) {
|
|
20033
20863
|
import_core6.default.schedule(
|
|
20034
20864
|
"meta.service_registry.instance_registration_requested",
|
|
@@ -20493,6 +21323,30 @@ var CadenzaService = class {
|
|
|
20493
21323
|
this.bootstrap();
|
|
20494
21324
|
return import_core6.default.createTask(name, func, description, options);
|
|
20495
21325
|
}
|
|
21326
|
+
static createHelper(name, func, description = "") {
|
|
21327
|
+
this.bootstrap();
|
|
21328
|
+
return import_core6.default.createHelper(name, func, description);
|
|
21329
|
+
}
|
|
21330
|
+
static createMetaHelper(name, func, description = "") {
|
|
21331
|
+
this.bootstrap();
|
|
21332
|
+
return import_core6.default.createMetaHelper(name, func, description);
|
|
21333
|
+
}
|
|
21334
|
+
static createHelperFromDefinition(definition) {
|
|
21335
|
+
this.bootstrap();
|
|
21336
|
+
return import_core6.default.createHelperFromDefinition(definition);
|
|
21337
|
+
}
|
|
21338
|
+
static createGlobal(name, value, description = "") {
|
|
21339
|
+
this.bootstrap();
|
|
21340
|
+
return import_core6.default.createGlobal(name, value, description);
|
|
21341
|
+
}
|
|
21342
|
+
static createMetaGlobal(name, value, description = "") {
|
|
21343
|
+
this.bootstrap();
|
|
21344
|
+
return import_core6.default.createMetaGlobal(name, value, description);
|
|
21345
|
+
}
|
|
21346
|
+
static createGlobalFromDefinition(definition) {
|
|
21347
|
+
this.bootstrap();
|
|
21348
|
+
return import_core6.default.createGlobalFromDefinition(definition);
|
|
21349
|
+
}
|
|
20496
21350
|
/**
|
|
20497
21351
|
* Creates a meta task with the specified name, functionality, description, and options.
|
|
20498
21352
|
* This is used for creating tasks that lives on the meta layer.
|
|
@@ -20829,6 +21683,7 @@ var CadenzaService = class {
|
|
|
20829
21683
|
this.isBootstrapped = false;
|
|
20830
21684
|
this.serviceCreated = false;
|
|
20831
21685
|
this.bootstrapSyncCompleted = false;
|
|
21686
|
+
this.bootstrapSyncCompletedAt = 0;
|
|
20832
21687
|
this.bootstrapSignalRegistrationsCompleted = false;
|
|
20833
21688
|
this.bootstrapIntentRegistrationsCompleted = false;
|
|
20834
21689
|
this.defaultDatabaseServiceName = null;
|
|
@@ -20837,15 +21692,27 @@ var CadenzaService = class {
|
|
|
20837
21692
|
this.frontendSyncScheduled = false;
|
|
20838
21693
|
this.serviceManifestRevision = 0;
|
|
20839
21694
|
this.lastPublishedServiceManifestHashes = {};
|
|
21695
|
+
this.serviceManifestPublishedAt = {};
|
|
20840
21696
|
this.serviceManifestPublicationInFlight = false;
|
|
20841
21697
|
this.serviceManifestPublicationPendingReason = null;
|
|
20842
21698
|
this.serviceManifestPublicationPendingLayer = null;
|
|
21699
|
+
this.serviceManifestPublicationRetryReason = null;
|
|
21700
|
+
this.serviceManifestPublicationRetryLayer = null;
|
|
21701
|
+
if (this.serviceManifestPublicationRetryTimer) {
|
|
21702
|
+
clearTimeout(this.serviceManifestPublicationRetryTimer);
|
|
21703
|
+
this.serviceManifestPublicationRetryTimer = null;
|
|
21704
|
+
}
|
|
21705
|
+
this.serviceManifestPublicationRetryCount = 0;
|
|
21706
|
+
this.localServiceManifestDefinitionInserted = false;
|
|
21707
|
+
this.localServiceManifestInstanceInserted = false;
|
|
21708
|
+
this.initialServiceManifestPublicationRequested = false;
|
|
20843
21709
|
resetBrowserRuntimeActorHandles();
|
|
20844
21710
|
}
|
|
20845
21711
|
};
|
|
20846
21712
|
CadenzaService.isBootstrapped = false;
|
|
20847
21713
|
CadenzaService.serviceCreated = false;
|
|
20848
21714
|
CadenzaService.bootstrapSyncCompleted = false;
|
|
21715
|
+
CadenzaService.bootstrapSyncCompletedAt = 0;
|
|
20849
21716
|
CadenzaService.bootstrapSignalRegistrationsCompleted = false;
|
|
20850
21717
|
CadenzaService.bootstrapIntentRegistrationsCompleted = false;
|
|
20851
21718
|
CadenzaService.defaultDatabaseServiceName = null;
|
|
@@ -20854,9 +21721,17 @@ CadenzaService.hydratedInquiryResults = /* @__PURE__ */ new Map();
|
|
|
20854
21721
|
CadenzaService.frontendSyncScheduled = false;
|
|
20855
21722
|
CadenzaService.serviceManifestRevision = 0;
|
|
20856
21723
|
CadenzaService.lastPublishedServiceManifestHashes = {};
|
|
21724
|
+
CadenzaService.serviceManifestPublishedAt = {};
|
|
20857
21725
|
CadenzaService.serviceManifestPublicationInFlight = false;
|
|
20858
21726
|
CadenzaService.serviceManifestPublicationPendingReason = null;
|
|
20859
21727
|
CadenzaService.serviceManifestPublicationPendingLayer = null;
|
|
21728
|
+
CadenzaService.serviceManifestPublicationRetryReason = null;
|
|
21729
|
+
CadenzaService.serviceManifestPublicationRetryLayer = null;
|
|
21730
|
+
CadenzaService.serviceManifestPublicationRetryTimer = null;
|
|
21731
|
+
CadenzaService.serviceManifestPublicationRetryCount = 0;
|
|
21732
|
+
CadenzaService.localServiceManifestDefinitionInserted = false;
|
|
21733
|
+
CadenzaService.localServiceManifestInstanceInserted = false;
|
|
21734
|
+
CadenzaService.initialServiceManifestPublicationRequested = false;
|
|
20860
21735
|
CadenzaService.shutdownHandlersRegistered = false;
|
|
20861
21736
|
CadenzaService.shutdownInFlight = false;
|
|
20862
21737
|
CadenzaService.shutdownHandlerCleanup = [];
|
|
@@ -21158,6 +22033,18 @@ var createTask = CadenzaService.createTask.bind(
|
|
|
21158
22033
|
var createMetaTask = CadenzaService.createMetaTask.bind(
|
|
21159
22034
|
CadenzaService
|
|
21160
22035
|
);
|
|
22036
|
+
var createHelper = CadenzaService.createHelper.bind(
|
|
22037
|
+
CadenzaService
|
|
22038
|
+
);
|
|
22039
|
+
var createMetaHelper = CadenzaService.createMetaHelper.bind(
|
|
22040
|
+
CadenzaService
|
|
22041
|
+
);
|
|
22042
|
+
var createGlobal = CadenzaService.createGlobal.bind(
|
|
22043
|
+
CadenzaService
|
|
22044
|
+
);
|
|
22045
|
+
var createMetaGlobal = CadenzaService.createMetaGlobal.bind(
|
|
22046
|
+
CadenzaService
|
|
22047
|
+
);
|
|
21161
22048
|
var createActor = CadenzaService.createActor.bind(
|
|
21162
22049
|
CadenzaService
|
|
21163
22050
|
);
|