@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.1 → 3.8.3-ultramodern.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.
Files changed (82) hide show
  1. package/dist/cjs/backend-federation-security/index.js +415 -0
  2. package/dist/cjs/backend-federation-security/node.js +74 -0
  3. package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
  4. package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
  5. package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
  6. package/dist/cjs/index.js +45 -13
  7. package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
  8. package/dist/cjs/runtimeLifecycle.js +129 -0
  9. package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
  10. package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
  11. package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
  12. package/dist/cjs/telemetry/lifecycle.js +14 -14
  13. package/dist/cjs/telemetry/plugin.js +9 -9
  14. package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
  15. package/dist/cjs/telemetryCore.js +4 -4
  16. package/dist/esm/backend-federation-security/index.mjs +361 -0
  17. package/dist/esm/backend-federation-security/node.mjs +30 -0
  18. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
  19. package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
  20. package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  21. package/dist/esm/index.mjs +4 -2
  22. package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
  23. package/dist/esm/runtimeLifecycle.mjs +82 -0
  24. package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  25. package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  26. package/dist/esm/telemetry/healthSetup.mjs +65 -0
  27. package/dist/esm/telemetry/lifecycle.mjs +14 -14
  28. package/dist/esm/telemetry/plugin.mjs +8 -8
  29. package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
  30. package/dist/esm/telemetryCore.mjs +1 -1
  31. package/dist/esm-node/backend-federation-security/index.mjs +362 -0
  32. package/dist/esm-node/backend-federation-security/node.mjs +31 -0
  33. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
  34. package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
  35. package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  36. package/dist/esm-node/index.mjs +4 -2
  37. package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
  38. package/dist/esm-node/runtimeLifecycle.mjs +83 -0
  39. package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  40. package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  41. package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
  42. package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
  43. package/dist/esm-node/telemetry/plugin.mjs +8 -8
  44. package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
  45. package/dist/esm-node/telemetryCore.mjs +1 -1
  46. package/dist/types/backend-federation-security/index.d.ts +68 -0
  47. package/dist/types/backend-federation-security/node.d.ts +3 -0
  48. package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
  49. package/dist/types/index.d.ts +4 -2
  50. package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
  51. package/dist/types/runtimeLifecycle.d.ts +10 -0
  52. package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
  53. package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
  54. package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
  55. package/dist/types/telemetry/lifecycle.d.ts +4 -4
  56. package/dist/types/telemetry/plugin.d.ts +1 -1
  57. package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
  58. package/dist/types/telemetryCore.d.ts +1 -1
  59. package/package.json +46 -8
  60. package/src/backend-federation-security/index.ts +831 -0
  61. package/src/backend-federation-security/node.ts +51 -0
  62. package/src/contract-gate-snapshot-store/http-store.ts +1 -1
  63. package/src/contract-gate-snapshot-store/resolve.ts +4 -4
  64. package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
  65. package/src/index.ts +42 -6
  66. package/src/runtime-fallback-signal/resolver.ts +5 -5
  67. package/src/runtimeLifecycle.ts +125 -0
  68. package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
  69. package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
  70. package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
  71. package/src/telemetry/lifecycle.ts +20 -20
  72. package/src/telemetry/plugin.ts +16 -16
  73. package/src/telemetry/runtimeEndpoints.ts +6 -6
  74. package/src/telemetryCore.ts +11 -11
  75. package/tests/backendFederationSecurity.test.ts +416 -0
  76. package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
  77. package/tests/runtimeLifecycle.test.ts +107 -0
  78. package/tests/telemetryHealthMonitor.test.ts +187 -0
  79. package/dist/esm/telemetry/canarySetup.mjs +0 -69
  80. package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
  81. package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
  82. package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
@@ -1,97 +1,105 @@
1
- import {
2
- evaluateCanaryHealth,
3
- type TelemetryCanaryHealthEvaluation,
4
- } from './canaryEvaluation';
5
1
  import { clamp } from './envelope';
2
+ import {
3
+ evaluateTelemetryHealth,
4
+ type TelemetryHealthEvaluationResult,
5
+ } from './healthEvaluation';
6
6
 
7
7
  import type { TelemetryRegistry } from './registry';
8
-
9
8
  import type { TelemetryQueueStats } from './registryTypes';
10
9
 
11
- export type TelemetryCanaryState = 'canary' | 'promoted' | 'rolled_back';
12
- export type TelemetryCanaryAction = 'hold' | 'promote' | 'rollback';
13
- export type TelemetryCanaryFailureReason =
10
+ export type TelemetryHealthState = 'pending' | 'healthy' | 'unhealthy';
11
+ export type TelemetryHealthTransition =
12
+ | 'none'
13
+ | 'became_healthy'
14
+ | 'became_unhealthy';
15
+ export type TelemetryHealthFailureReason =
14
16
  | 'queue_utilization'
15
17
  | 'queue_dropped'
16
18
  | 'unhealthy_exporter'
17
19
  | 'contract_gate_missing'
18
20
  | 'contract_gate_failed';
19
21
 
20
- export interface TelemetryCanaryFailure {
21
- reason: TelemetryCanaryFailureReason;
22
+ export interface TelemetryHealthFailure {
23
+ reason: TelemetryHealthFailureReason;
22
24
  gate?: string;
23
25
  message?: string;
24
26
  threshold?: number;
25
27
  value?: number;
26
28
  }
27
29
 
28
- export interface TelemetryCanaryContractGateStatus {
30
+ export interface TelemetryContractGateStatus {
29
31
  name: string;
30
32
  passed: boolean;
31
33
  reason?: string;
32
34
  updatedAt: number;
33
35
  }
34
36
 
35
- export interface TelemetryCanaryDecision {
37
+ export interface TelemetryHealthEvaluation {
36
38
  timestamp: number;
37
- action: TelemetryCanaryAction;
38
- state: TelemetryCanaryState;
39
+ transition: TelemetryHealthTransition;
40
+ state: TelemetryHealthState;
39
41
  consecutiveHealthy: number;
40
42
  consecutiveFailures: number;
41
- failures: TelemetryCanaryFailure[];
43
+ failures: TelemetryHealthFailure[];
42
44
  queueStats: TelemetryQueueStats;
43
45
  unhealthyExporterCount: number;
44
- contractGates: TelemetryCanaryContractGateStatus[];
46
+ contractGates: TelemetryContractGateStatus[];
45
47
  }
46
48
 
47
- export interface TelemetryCanaryStatusSnapshot {
49
+ export interface TelemetryHealthStatusSnapshot {
48
50
  timestamp: number;
49
- state: TelemetryCanaryState;
51
+ state: TelemetryHealthState;
50
52
  consecutiveHealthy: number;
51
53
  consecutiveFailures: number;
52
54
  queueStats: TelemetryQueueStats;
53
55
  unhealthyExporterCount: number;
54
56
  requiredContractGates: string[];
55
- contractGates: TelemetryCanaryContractGateStatus[];
56
- failurePreview: TelemetryCanaryFailure[];
57
+ contractGates: TelemetryContractGateStatus[];
58
+ failurePreview: TelemetryHealthFailure[];
57
59
  }
58
60
 
59
- export interface TelemetryCanaryOrchestratorOptions {
61
+ export interface TelemetryHealthMonitorOptions {
60
62
  registry: TelemetryRegistry;
61
63
  evaluationIntervalMs?: number;
62
64
  minConsecutiveHealthyEvaluations?: number;
63
- rollbackConsecutiveFailures?: number;
65
+ minConsecutiveFailedEvaluations?: number;
64
66
  maxQueueUtilization?: number;
65
67
  maxTotalDropped?: number;
66
68
  maxUnhealthyExporters?: number;
67
69
  requiredContractGates?: string[];
68
- onEvaluate?: (decision: TelemetryCanaryDecision) => void;
69
- onPromote?: (decision: TelemetryCanaryDecision) => void;
70
- onRollback?: (decision: TelemetryCanaryDecision) => void;
70
+ onEvaluate?: (evaluation: TelemetryHealthEvaluation) => void;
71
+ onTransition?: (evaluation: TelemetryHealthEvaluation) => void;
71
72
  }
72
73
 
73
- export class TelemetryCanaryOrchestrator {
74
+ /**
75
+ * Observes telemetry and contract-gate health with hysteresis.
76
+ *
77
+ * This class reports health only. It does not deploy, promote, route, or roll
78
+ * back application revisions.
79
+ */
80
+ export class TelemetryHealthMonitor {
74
81
  private readonly registry: TelemetryRegistry;
75
82
  private readonly evaluationIntervalMs: number;
76
83
  private readonly minConsecutiveHealthyEvaluations: number;
77
- private readonly rollbackConsecutiveFailures: number;
84
+ private readonly minConsecutiveFailedEvaluations: number;
78
85
  private readonly maxQueueUtilization: number;
79
86
  private readonly maxTotalDropped: number;
80
87
  private readonly maxUnhealthyExporters: number;
81
88
  private requiredContractGates: string[] = [];
82
- private readonly onEvaluate?: (decision: TelemetryCanaryDecision) => void;
83
- private readonly onPromote?: (decision: TelemetryCanaryDecision) => void;
84
- private readonly onRollback?: (decision: TelemetryCanaryDecision) => void;
89
+ private readonly onEvaluate?: (evaluation: TelemetryHealthEvaluation) => void;
90
+ private readonly onTransition?: (
91
+ evaluation: TelemetryHealthEvaluation,
92
+ ) => void;
85
93
  private readonly contractGates = new Map<
86
94
  string,
87
- TelemetryCanaryContractGateStatus
95
+ TelemetryContractGateStatus
88
96
  >();
89
- private state: TelemetryCanaryState = 'canary';
97
+ private state: TelemetryHealthState = 'pending';
90
98
  private consecutiveHealthy = 0;
91
99
  private consecutiveFailures = 0;
92
100
  private evaluationTimer?: ReturnType<typeof setInterval>;
93
101
 
94
- constructor(options: TelemetryCanaryOrchestratorOptions) {
102
+ constructor(options: TelemetryHealthMonitorOptions) {
95
103
  this.registry = options.registry;
96
104
  this.evaluationIntervalMs = Math.max(
97
105
  250,
@@ -101,9 +109,9 @@ export class TelemetryCanaryOrchestrator {
101
109
  1,
102
110
  options.minConsecutiveHealthyEvaluations ?? 3,
103
111
  );
104
- this.rollbackConsecutiveFailures = Math.max(
112
+ this.minConsecutiveFailedEvaluations = Math.max(
105
113
  1,
106
- options.rollbackConsecutiveFailures ?? 2,
114
+ options.minConsecutiveFailedEvaluations ?? 2,
107
115
  );
108
116
  this.maxQueueUtilization = clamp(options.maxQueueUtilization ?? 0.8, 0, 1);
109
117
  this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
@@ -113,8 +121,7 @@ export class TelemetryCanaryOrchestrator {
113
121
  );
114
122
  this.setRequiredContractGates(options.requiredContractGates || []);
115
123
  this.onEvaluate = options.onEvaluate;
116
- this.onPromote = options.onPromote;
117
- this.onRollback = options.onRollback;
124
+ this.onTransition = options.onTransition;
118
125
  }
119
126
 
120
127
  setRequiredContractGates(gates: string[]) {
@@ -125,11 +132,10 @@ export class TelemetryCanaryOrchestrator {
125
132
 
126
133
  addRequiredContractGate(name: string) {
127
134
  const normalizedName = name.trim();
128
- if (!normalizedName) {
129
- return;
130
- }
131
-
132
- if (!this.requiredContractGates.includes(normalizedName)) {
135
+ if (
136
+ normalizedName &&
137
+ !this.requiredContractGates.includes(normalizedName)
138
+ ) {
133
139
  this.requiredContractGates.push(normalizedName);
134
140
  }
135
141
  }
@@ -149,26 +155,19 @@ export class TelemetryCanaryOrchestrator {
149
155
  for (const [name, value] of Object.entries(gates)) {
150
156
  if (typeof value === 'boolean') {
151
157
  this.setContractGate(name, value);
152
- continue;
158
+ } else {
159
+ this.setContractGate(name, value.passed, value.reason);
153
160
  }
154
-
155
- this.setContractGate(name, value.passed, value.reason);
156
161
  }
157
162
  }
158
163
 
159
- resetToCanary() {
160
- this.state = 'canary';
161
- this.consecutiveHealthy = 0;
162
- this.consecutiveFailures = 0;
163
- }
164
-
165
- private collectFailures(): TelemetryCanaryHealthEvaluation {
164
+ private collectFailures(): TelemetryHealthEvaluationResult {
166
165
  const queueStats = this.registry.getQueueStats();
167
166
  const unhealthyExporterCount = this.registry
168
167
  .getExporterHealth()
169
168
  .filter(item => !item.healthy).length;
170
169
 
171
- return evaluateCanaryHealth(
170
+ return evaluateTelemetryHealth(
172
171
  {
173
172
  queueStats,
174
173
  unhealthyExporterCount,
@@ -183,38 +182,36 @@ export class TelemetryCanaryOrchestrator {
183
182
  );
184
183
  }
185
184
 
186
- evaluate(): TelemetryCanaryDecision {
187
- const now = Date.now();
185
+ evaluate(): TelemetryHealthEvaluation {
188
186
  const { failures, queueStats, unhealthyExporterCount } =
189
187
  this.collectFailures();
190
- let action: TelemetryCanaryAction = 'hold';
188
+ let transition: TelemetryHealthTransition = 'none';
191
189
 
192
190
  if (failures.length > 0) {
193
191
  this.consecutiveHealthy = 0;
194
192
  this.consecutiveFailures += 1;
195
-
196
193
  if (
197
- this.state !== 'rolled_back' &&
198
- this.consecutiveFailures >= this.rollbackConsecutiveFailures
194
+ this.state !== 'unhealthy' &&
195
+ this.consecutiveFailures >= this.minConsecutiveFailedEvaluations
199
196
  ) {
200
- this.state = 'rolled_back';
201
- action = 'rollback';
197
+ this.state = 'unhealthy';
198
+ transition = 'became_unhealthy';
202
199
  }
203
200
  } else {
204
201
  this.consecutiveFailures = 0;
205
202
  this.consecutiveHealthy += 1;
206
203
  if (
207
- this.state === 'canary' &&
204
+ this.state !== 'healthy' &&
208
205
  this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations
209
206
  ) {
210
- this.state = 'promoted';
211
- action = 'promote';
207
+ this.state = 'healthy';
208
+ transition = 'became_healthy';
212
209
  }
213
210
  }
214
211
 
215
- const decision: TelemetryCanaryDecision = {
216
- timestamp: now,
217
- action,
212
+ const evaluation: TelemetryHealthEvaluation = {
213
+ timestamp: Date.now(),
214
+ transition,
218
215
  state: this.state,
219
216
  consecutiveHealthy: this.consecutiveHealthy,
220
217
  consecutiveFailures: this.consecutiveFailures,
@@ -227,36 +224,27 @@ export class TelemetryCanaryOrchestrator {
227
224
  };
228
225
 
229
226
  try {
230
- this.onEvaluate?.(decision);
227
+ this.onEvaluate?.(evaluation);
231
228
  } catch (_error) {
232
- // canary observer hooks must never crash server.
233
- }
234
-
235
- if (action === 'promote') {
236
- try {
237
- this.onPromote?.(decision);
238
- } catch (_error) {
239
- // canary observer hooks must never crash server.
240
- }
229
+ // Health observers must never crash the server.
241
230
  }
242
231
 
243
- if (action === 'rollback') {
232
+ if (transition !== 'none') {
244
233
  try {
245
- this.onRollback?.(decision);
234
+ this.onTransition?.(evaluation);
246
235
  } catch (_error) {
247
- // canary observer hooks must never crash server.
236
+ // Health observers must never crash the server.
248
237
  }
249
238
  }
250
239
 
251
- return decision;
240
+ return evaluation;
252
241
  }
253
242
 
254
- getStatusSnapshot(): TelemetryCanaryStatusSnapshot {
255
- const now = Date.now();
243
+ getStatusSnapshot(): TelemetryHealthStatusSnapshot {
256
244
  const { failures, queueStats, unhealthyExporterCount } =
257
245
  this.collectFailures();
258
246
  return {
259
- timestamp: now,
247
+ timestamp: Date.now(),
260
248
  state: this.state,
261
249
  consecutiveHealthy: this.consecutiveHealthy,
262
250
  consecutiveFailures: this.consecutiveFailures,
@@ -18,141 +18,138 @@ import {
18
18
  resolveRuntimeFallbackSignalEndpoint,
19
19
  } from '../runtimeFallbackSignal';
20
20
  import {
21
- type TelemetryCanaryDecision,
22
- TelemetryCanaryOrchestrator,
21
+ type TelemetryHealthEvaluation,
22
+ TelemetryHealthMonitor,
23
23
  TelemetryRegistry,
24
24
  } from '../telemetryCore';
25
25
 
26
- type SetupTelemetryCanaryOptions = {
26
+ type SetupTelemetryHealthMonitoringOptions = {
27
27
  registry: TelemetryRegistry;
28
28
  appDirectory: string;
29
- canaryConfig: ServerTelemetryUserConfig['canary'] | undefined;
29
+ legacyHealthConfig: ServerTelemetryUserConfig['canary'] | undefined;
30
30
  };
31
31
 
32
- type SetupTelemetryCanaryResult = {
33
- canaryOrchestrator?: TelemetryCanaryOrchestrator;
32
+ type SetupTelemetryHealthMonitoringResult = {
33
+ healthMonitor?: TelemetryHealthMonitor;
34
34
  gateSnapshotStorePromise?: Promise<ContractGateSnapshotStore>;
35
35
  runtimeFallbackSignalConfig?: RuntimeFallbackSignalConfig;
36
36
  runtimeStatusAuthConfig?: RuntimeFallbackSignalAuthConfig;
37
37
  };
38
38
 
39
- function emitCanaryDecisionMetric(
39
+ function emitHealthTransitionMetric(
40
40
  registry: TelemetryRegistry,
41
- decision: TelemetryCanaryDecision,
42
- action: 'promote' | 'rollback',
41
+ evaluation: TelemetryHealthEvaluation,
43
42
  ) {
44
43
  try {
45
44
  registry.enqueueMetric({
46
- name: `telemetry.canary.${action}`,
45
+ name: 'telemetry.health.transition',
47
46
  value: 1,
48
47
  unit: 'count',
49
48
  tags: {
50
- action,
51
- state: decision.state,
52
- failures: String(decision.failures.length),
49
+ transition: evaluation.transition,
50
+ state: evaluation.state,
51
+ failures: String(evaluation.failures.length),
53
52
  },
54
53
  });
55
54
  } catch (_error) {
56
- // Canary decision metrics are best-effort and must never break request flow.
55
+ // Health transition metrics are best-effort and must not break requests.
57
56
  }
58
57
  }
59
58
 
60
- export const setupTelemetryCanary = ({
59
+ export const setupTelemetryHealthMonitoring = ({
61
60
  registry,
62
61
  appDirectory,
63
- canaryConfig,
64
- }: SetupTelemetryCanaryOptions): SetupTelemetryCanaryResult => {
65
- if (!canaryConfig?.enabled) {
62
+ legacyHealthConfig,
63
+ }: SetupTelemetryHealthMonitoringOptions): SetupTelemetryHealthMonitoringResult => {
64
+ if (!legacyHealthConfig?.enabled) {
66
65
  return {};
67
66
  }
68
67
 
69
- const contractGates = canaryConfig.contractGates as
68
+ const contractGates = legacyHealthConfig.contractGates as
70
69
  | Record<string, boolean | { passed: boolean; reason?: string }>
71
70
  | undefined;
72
71
 
73
- const canaryOrchestrator = new TelemetryCanaryOrchestrator({
72
+ const healthMonitor = new TelemetryHealthMonitor({
74
73
  registry,
75
- evaluationIntervalMs: canaryConfig.evaluationIntervalMs,
74
+ evaluationIntervalMs: legacyHealthConfig.evaluationIntervalMs,
76
75
  minConsecutiveHealthyEvaluations:
77
- canaryConfig.minConsecutiveHealthyEvaluations,
78
- rollbackConsecutiveFailures: canaryConfig.rollbackConsecutiveFailures,
79
- maxQueueUtilization: canaryConfig.maxQueueUtilization,
80
- maxTotalDropped: canaryConfig.maxTotalDropped,
81
- maxUnhealthyExporters: canaryConfig.maxUnhealthyExporters,
76
+ legacyHealthConfig.minConsecutiveHealthyEvaluations,
77
+ // `rollbackConsecutiveFailures` is the legacy public config key. It now
78
+ // controls health-state hysteresis and never triggers a deployment action.
79
+ minConsecutiveFailedEvaluations:
80
+ legacyHealthConfig.rollbackConsecutiveFailures,
81
+ maxQueueUtilization: legacyHealthConfig.maxQueueUtilization,
82
+ maxTotalDropped: legacyHealthConfig.maxTotalDropped,
83
+ maxUnhealthyExporters: legacyHealthConfig.maxUnhealthyExporters,
82
84
  requiredContractGates: Object.keys(contractGates || {}),
83
- onPromote: decision => {
84
- emitCanaryDecisionMetric(registry, decision, 'promote');
85
- },
86
- onRollback: decision => {
87
- emitCanaryDecisionMetric(registry, decision, 'rollback');
85
+ onTransition: evaluation => {
86
+ emitHealthTransitionMetric(registry, evaluation);
88
87
  },
89
88
  });
90
89
 
91
90
  if (contractGates) {
92
- canaryOrchestrator.setContractGates(contractGates);
91
+ healthMonitor.setContractGates(contractGates);
93
92
  }
94
93
 
95
94
  let gateSnapshotStorePromise: Promise<ContractGateSnapshotStore> | undefined;
96
95
  let runtimeFallbackSignalConfig: RuntimeFallbackSignalConfig | undefined;
97
96
 
98
- const autopilotEnabled = canaryConfig.autopilot?.enabled ?? true;
99
- if (autopilotEnabled) {
97
+ // `autopilot` is retained only as the legacy config key for snapshot input.
98
+ const snapshotObservationEnabled =
99
+ legacyHealthConfig.autopilot?.enabled ?? true;
100
+ if (snapshotObservationEnabled) {
100
101
  const gateSnapshotPath = resolveContractGateSnapshotPath(
101
102
  appDirectory,
102
- canaryConfig.autopilot?.gateSnapshotPath,
103
+ legacyHealthConfig.autopilot?.gateSnapshotPath,
103
104
  );
104
105
  gateSnapshotStorePromise = resolveContractGateSnapshotStore({
105
106
  appDirectory,
106
107
  gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
107
- stateStore: canaryConfig.autopilot?.stateStore,
108
+ stateStore: legacyHealthConfig.autopilot?.stateStore,
108
109
  });
109
110
 
110
- const runtimeSignalConfig = canaryConfig.autopilot?.runtimeFallbackSignal;
111
- // The signal endpoint can persist failing contract gates and force
112
- // canary orchestrator into rollback, so it is opt-in (default
113
- // OFF) and requires a configured auth token when enabled.
114
- const runtimeSignalEnabled = runtimeSignalConfig?.enabled === true;
115
- if (runtimeSignalEnabled && gateSnapshotStorePromise) {
111
+ const runtimeSignalConfig =
112
+ legacyHealthConfig.autopilot?.runtimeFallbackSignal;
113
+ if (runtimeSignalConfig?.enabled === true) {
116
114
  runtimeFallbackSignalConfig = {
117
115
  endpoint: resolveRuntimeFallbackSignalEndpoint(
118
- runtimeSignalConfig?.endpoint,
116
+ runtimeSignalConfig.endpoint,
119
117
  ),
120
118
  gateName:
121
- runtimeSignalConfig?.gateName?.trim() ||
119
+ runtimeSignalConfig.gateName?.trim() ||
122
120
  DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
123
121
  gateSnapshotStore: gateSnapshotStorePromise,
124
122
  failureHoldMs: Math.max(
125
123
  1_000,
126
- runtimeSignalConfig?.failureHoldMs ??
124
+ runtimeSignalConfig.failureHoldMs ??
127
125
  DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
128
126
  ),
129
127
  maxBodyBytes: Math.max(
130
128
  512,
131
- runtimeSignalConfig?.maxBodyBytes ??
129
+ runtimeSignalConfig.maxBodyBytes ??
132
130
  DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
133
131
  ),
134
132
  auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(
135
- runtimeSignalConfig?.auth,
133
+ runtimeSignalConfig.auth,
136
134
  ),
137
135
  trustPolicy: normalizeRuntimeFallbackTrustPolicy(
138
- runtimeSignalConfig?.trustPolicy,
136
+ runtimeSignalConfig.trustPolicy,
139
137
  ),
140
138
  runtimeState: createRuntimeFallbackSignalRuntimeState(),
141
139
  };
142
140
  }
143
141
  }
144
142
 
145
- // The runtime status endpoint exposes detail only to authenticated
146
- // callers. Auth can be configured through runtimeFallbackSignal.auth
147
- // even when the signal endpoint itself stays disabled.
143
+ // Detailed runtime status stays authenticated even when signal ingestion is
144
+ // disabled. The auth source remains the legacy config path for compatibility.
148
145
  const runtimeStatusAuthConfig =
149
146
  runtimeFallbackSignalConfig?.auth ??
150
147
  normalizeRuntimeFallbackSignalAuthConfig(
151
- canaryConfig.autopilot?.runtimeFallbackSignal?.auth,
148
+ legacyHealthConfig.autopilot?.runtimeFallbackSignal?.auth,
152
149
  );
153
150
 
154
151
  return {
155
- canaryOrchestrator,
152
+ healthMonitor,
156
153
  gateSnapshotStorePromise,
157
154
  runtimeFallbackSignalConfig,
158
155
  runtimeStatusAuthConfig,
@@ -3,12 +3,12 @@ import {
3
3
  type ContractGateSnapshotStore,
4
4
  resolveContractGateSnapshotPath,
5
5
  } from '../contract-gate-snapshot-store';
6
- import { ContractGateAutopilot } from '../contractGateAutopilot';
6
+ import { ContractGateSnapshotObserver } from '../contractGateSnapshotObserver';
7
7
  import {
8
8
  createOtlpTelemetryExporter,
9
9
  createVictoriaMetricsTelemetryExporter,
10
10
  maybeWarnLegacyOtlpEndpoint,
11
- TelemetryCanaryOrchestrator,
11
+ TelemetryHealthMonitor,
12
12
  TelemetryRegistry,
13
13
  } from '../telemetryCore';
14
14
 
@@ -21,8 +21,8 @@ type RegisterTelemetryLifecycleOptions = {
21
21
  api: TelemetryLifecycleApi;
22
22
  registry: TelemetryRegistry;
23
23
  telemetryConfig: ServerTelemetryUserConfig;
24
- canaryConfig: ServerTelemetryUserConfig['canary'] | undefined;
25
- canaryOrchestrator?: TelemetryCanaryOrchestrator;
24
+ legacyHealthConfig: ServerTelemetryUserConfig['canary'] | undefined;
25
+ healthMonitor?: TelemetryHealthMonitor;
26
26
  gateSnapshotStorePromise?: Promise<ContractGateSnapshotStore>;
27
27
  appDirectory: string;
28
28
  };
@@ -50,12 +50,12 @@ export const registerTelemetryLifecycle = ({
50
50
  api,
51
51
  registry,
52
52
  telemetryConfig,
53
- canaryConfig,
54
- canaryOrchestrator,
53
+ legacyHealthConfig,
54
+ healthMonitor,
55
55
  gateSnapshotStorePromise,
56
56
  appDirectory,
57
57
  }: RegisterTelemetryLifecycleOptions) => {
58
- let contractGateAutopilot: ContractGateAutopilot | undefined;
58
+ let contractGateSnapshotObserver: ContractGateSnapshotObserver | undefined;
59
59
  let telemetryLaneClosed = false;
60
60
  const closeTelemetryLane = async () => {
61
61
  if (telemetryLaneClosed) {
@@ -63,8 +63,8 @@ export const registerTelemetryLifecycle = ({
63
63
  }
64
64
  telemetryLaneClosed = true;
65
65
  activeTelemetryLaneClosers.delete(closeTelemetryLane);
66
- contractGateAutopilot?.stop();
67
- canaryOrchestrator?.stop();
66
+ contractGateSnapshotObserver?.stop();
67
+ healthMonitor?.stop();
68
68
  await registry.shutdown();
69
69
  };
70
70
 
@@ -76,7 +76,7 @@ export const registerTelemetryLifecycle = ({
76
76
  prepared = true;
77
77
 
78
78
  // Shutdown path for the telemetry lane: flush pending envelopes and
79
- // stop canary/autopilot pollers when the node server closes (this also
79
+ // stop health/snapshot pollers when the node server closes (this also
80
80
  // covers dev-server restarts, which close the previous node server
81
81
  // before assembling a new one), with process beforeExit as the
82
82
  // final-flush floor when no node server handle exists.
@@ -112,27 +112,27 @@ export const registerTelemetryLifecycle = ({
112
112
  failLoud: telemetryConfig.failLoudStartup ?? true,
113
113
  });
114
114
 
115
- if (!canaryOrchestrator) {
115
+ if (!healthMonitor) {
116
116
  return;
117
117
  }
118
118
 
119
- canaryOrchestrator.start();
119
+ healthMonitor.start();
120
120
  if (gateSnapshotStorePromise) {
121
121
  const gateSnapshotStore = await gateSnapshotStorePromise;
122
- contractGateAutopilot = new ContractGateAutopilot({
123
- orchestrator: canaryOrchestrator,
122
+ contractGateSnapshotObserver = new ContractGateSnapshotObserver({
123
+ monitor: healthMonitor,
124
124
  gateSnapshotPath: resolveContractGateSnapshotPath(
125
125
  appDirectory,
126
- canaryConfig?.autopilot?.gateSnapshotPath,
126
+ legacyHealthConfig?.autopilot?.gateSnapshotPath,
127
127
  ),
128
128
  gateSnapshotStore,
129
- pollIntervalMs: canaryConfig?.autopilot?.pollIntervalMs,
130
- gateStaleAfterMs: canaryConfig?.autopilot?.gateStaleAfterMs,
129
+ pollIntervalMs: legacyHealthConfig?.autopilot?.pollIntervalMs,
130
+ gateStaleAfterMs: legacyHealthConfig?.autopilot?.gateStaleAfterMs,
131
131
  });
132
132
  }
133
- if (contractGateAutopilot) {
134
- await contractGateAutopilot.start();
133
+ if (contractGateSnapshotObserver) {
134
+ await contractGateSnapshotObserver.start();
135
135
  }
136
- canaryOrchestrator.evaluate();
136
+ healthMonitor.evaluate();
137
137
  });
138
138
  };
@@ -14,7 +14,7 @@ import {
14
14
  type TelemetryRegistryOptions,
15
15
  toTelemetryEnvelope,
16
16
  } from '../telemetryCore';
17
- import { setupTelemetryCanary } from './canarySetup';
17
+ import { setupTelemetryHealthMonitoring } from './healthSetup';
18
18
  import { registerTelemetryLifecycle } from './lifecycle';
19
19
  import {
20
20
  createRuntimeFallbackSignalMiddleware,
@@ -47,18 +47,18 @@ export {
47
47
  createTelemetryAwareMetrics,
48
48
  createVictoriaMetricsTelemetryExporter,
49
49
  type OtlpExporterOptions,
50
- type TelemetryCanaryAction,
51
- type TelemetryCanaryContractGateStatus,
52
- type TelemetryCanaryDecision,
53
- type TelemetryCanaryFailure,
54
- type TelemetryCanaryFailureReason,
55
- TelemetryCanaryOrchestrator,
56
- type TelemetryCanaryOrchestratorOptions,
57
- type TelemetryCanaryState,
58
- type TelemetryCanaryStatusSnapshot,
50
+ type TelemetryContractGateStatus,
59
51
  type TelemetryEnvelope,
60
52
  type TelemetryExporter,
61
53
  type TelemetryExporterHealthStatus,
54
+ type TelemetryHealthEvaluation,
55
+ type TelemetryHealthFailure,
56
+ type TelemetryHealthFailureReason,
57
+ TelemetryHealthMonitor,
58
+ type TelemetryHealthMonitorOptions,
59
+ type TelemetryHealthState,
60
+ type TelemetryHealthStatusSnapshot,
61
+ type TelemetryHealthTransition,
62
62
  type TelemetryQueueStats,
63
63
  TelemetryRegistry,
64
64
  type TelemetryRegistryOptions,
@@ -132,14 +132,14 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
132
132
  });
133
133
 
134
134
  const {
135
- canaryOrchestrator,
135
+ healthMonitor,
136
136
  gateSnapshotStorePromise,
137
137
  runtimeFallbackSignalConfig,
138
138
  runtimeStatusAuthConfig,
139
- } = setupTelemetryCanary({
139
+ } = setupTelemetryHealthMonitoring({
140
140
  registry,
141
141
  appDirectory,
142
- canaryConfig: telemetryConfig.canary,
142
+ legacyHealthConfig: telemetryConfig.canary,
143
143
  });
144
144
 
145
145
  if (runtimeFallbackSignalConfig) {
@@ -150,7 +150,7 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
150
150
  middlewares.push(
151
151
  createRuntimeStatusMiddleware({
152
152
  registry,
153
- canaryOrchestrator,
153
+ healthMonitor,
154
154
  runtimeFallbackSignalConfig,
155
155
  runtimeStatusAuthConfig,
156
156
  }),
@@ -188,8 +188,8 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
188
188
  api,
189
189
  registry,
190
190
  telemetryConfig,
191
- canaryConfig: telemetryConfig.canary,
192
- canaryOrchestrator,
191
+ legacyHealthConfig: telemetryConfig.canary,
192
+ healthMonitor,
193
193
  gateSnapshotStorePromise,
194
194
  appDirectory,
195
195
  });