@agent-vm/agent-vm 0.0.91 → 0.0.93
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/build/gondolin-image-builder.d.ts +1 -0
- package/dist/build/gondolin-image-builder.d.ts.map +1 -1
- package/dist/build/gondolin-image-builder.js +11 -1
- package/dist/build/gondolin-image-builder.js.map +1 -1
- package/dist/build/managed-image-dockerfile.d.ts +2 -1
- package/dist/build/managed-image-dockerfile.d.ts.map +1 -1
- package/dist/build/managed-image-dockerfile.js +51 -27
- package/dist/build/managed-image-dockerfile.js.map +1 -1
- package/dist/cli/commands/controller-definition.d.ts +42 -42
- package/dist/cli/commands/create-app.d.ts +60 -60
- package/dist/cli/manual-templates.d.ts.map +1 -1
- package/dist/cli/manual-templates.js +14 -1
- package/dist/cli/manual-templates.js.map +1 -1
- package/dist/config/system-config.d.ts +15 -0
- package/dist/config/system-config.d.ts.map +1 -1
- package/dist/config/system-config.js +74 -0
- package/dist/config/system-config.js.map +1 -1
- package/dist/controller/controller-runtime-operations.d.ts +1 -0
- package/dist/controller/controller-runtime-operations.d.ts.map +1 -1
- package/dist/controller/controller-runtime-operations.js +2 -0
- package/dist/controller/controller-runtime-operations.js.map +1 -1
- package/dist/controller/controller-runtime-types.d.ts +5 -0
- package/dist/controller/controller-runtime-types.d.ts.map +1 -1
- package/dist/controller/controller-runtime.d.ts +1 -0
- package/dist/controller/controller-runtime.d.ts.map +1 -1
- package/dist/controller/controller-runtime.js +220 -3
- package/dist/controller/controller-runtime.js.map +1 -1
- package/dist/controller/health/channel-provider-recovery-observation.d.ts +23 -0
- package/dist/controller/health/channel-provider-recovery-observation.d.ts.map +1 -0
- package/dist/controller/health/channel-provider-recovery-observation.js +69 -0
- package/dist/controller/health/channel-provider-recovery-observation.js.map +1 -0
- package/dist/controller/health/durable-health-event-log.d.ts +24 -0
- package/dist/controller/health/durable-health-event-log.d.ts.map +1 -0
- package/dist/controller/health/durable-health-event-log.js +89 -0
- package/dist/controller/health/durable-health-event-log.js.map +1 -0
- package/dist/controller/health/gateway-recovery-actions.d.ts +27 -0
- package/dist/controller/health/gateway-recovery-actions.d.ts.map +1 -0
- package/dist/controller/health/gateway-recovery-actions.js +71 -0
- package/dist/controller/health/gateway-recovery-actions.js.map +1 -0
- package/dist/controller/health/gateway-service-health-monitor.d.ts +71 -3
- package/dist/controller/health/gateway-service-health-monitor.d.ts.map +1 -1
- package/dist/controller/health/gateway-service-health-monitor.js +383 -10
- package/dist/controller/health/gateway-service-health-monitor.js.map +1 -1
- package/dist/controller/health/gateway-vm-recovery-policy.d.ts +68 -0
- package/dist/controller/health/gateway-vm-recovery-policy.d.ts.map +1 -0
- package/dist/controller/health/gateway-vm-recovery-policy.js +199 -0
- package/dist/controller/health/gateway-vm-recovery-policy.js.map +1 -0
- package/dist/controller/health/gateway-vm-recovery-runner.d.ts +39 -0
- package/dist/controller/health/gateway-vm-recovery-runner.d.ts.map +1 -0
- package/dist/controller/health/gateway-vm-recovery-runner.js +251 -0
- package/dist/controller/health/gateway-vm-recovery-runner.js.map +1 -0
- package/dist/controller/health/health-event-store.d.ts +4 -0
- package/dist/controller/health/health-event-store.d.ts.map +1 -1
- package/dist/controller/health/health-event-store.js +19 -0
- package/dist/controller/health/health-event-store.js.map +1 -1
- package/dist/controller/http/controller-health-event-routes.d.ts +6 -0
- package/dist/controller/http/controller-health-event-routes.d.ts.map +1 -1
- package/dist/controller/http/controller-health-event-routes.js +49 -0
- package/dist/controller/http/controller-health-event-routes.js.map +1 -1
- package/dist/controller/http/controller-http-routes.d.ts.map +1 -1
- package/dist/controller/http/controller-http-routes.js +6 -0
- package/dist/controller/http/controller-http-routes.js.map +1 -1
- package/dist/controller/leases/lease-manager.d.ts.map +1 -1
- package/dist/controller/leases/lease-manager.js +37 -16
- package/dist/controller/leases/lease-manager.js.map +1 -1
- package/dist/controller/leases/tool-vm-lease-lifecycle.d.ts +44 -0
- package/dist/controller/leases/tool-vm-lease-lifecycle.d.ts.map +1 -0
- package/dist/controller/leases/tool-vm-lease-lifecycle.js +28 -0
- package/dist/controller/leases/tool-vm-lease-lifecycle.js.map +1 -0
- package/dist/controller/zone-runtimes/gateway-lifecycle-operation-record.d.ts +37 -0
- package/dist/controller/zone-runtimes/gateway-lifecycle-operation-record.d.ts.map +1 -0
- package/dist/controller/zone-runtimes/gateway-lifecycle-operation-record.js +133 -0
- package/dist/controller/zone-runtimes/gateway-lifecycle-operation-record.js.map +1 -0
- package/dist/controller/zone-runtimes/gateway-zone-state-machine.d.ts +101 -0
- package/dist/controller/zone-runtimes/gateway-zone-state-machine.d.ts.map +1 -0
- package/dist/controller/zone-runtimes/gateway-zone-state-machine.js +143 -0
- package/dist/controller/zone-runtimes/gateway-zone-state-machine.js.map +1 -0
- package/dist/controller/zone-runtimes/openclaw-zone-runtime.d.ts +16 -1
- package/dist/controller/zone-runtimes/openclaw-zone-runtime.d.ts.map +1 -1
- package/dist/controller/zone-runtimes/openclaw-zone-runtime.js +700 -40
- package/dist/controller/zone-runtimes/openclaw-zone-runtime.js.map +1 -1
- package/dist/controller/zone-runtimes/zone-runtime-errors.d.ts +7 -1
- package/dist/controller/zone-runtimes/zone-runtime-errors.d.ts.map +1 -1
- package/dist/controller/zone-runtimes/zone-runtime-errors.js +5 -1
- package/dist/controller/zone-runtimes/zone-runtime-errors.js.map +1 -1
- package/dist/controller/zone-runtimes/zone-runtime-registry.d.ts +2 -0
- package/dist/controller/zone-runtimes/zone-runtime-registry.d.ts.map +1 -1
- package/dist/controller/zone-runtimes/zone-runtime-registry.js +23 -0
- package/dist/controller/zone-runtimes/zone-runtime-registry.js.map +1 -1
- package/dist/controller/zone-runtimes/zone-runtime-types.d.ts +14 -1
- package/dist/controller/zone-runtimes/zone-runtime-types.d.ts.map +1 -1
- package/dist/gateway/gateway-ownership-evidence.d.ts +35 -0
- package/dist/gateway/gateway-ownership-evidence.d.ts.map +1 -0
- package/dist/gateway/gateway-ownership-evidence.js +10 -0
- package/dist/gateway/gateway-ownership-evidence.js.map +1 -0
- package/dist/gateway/gateway-recovery.d.ts +16 -0
- package/dist/gateway/gateway-recovery.d.ts.map +1 -1
- package/dist/gateway/gateway-recovery.js +105 -9
- package/dist/gateway/gateway-recovery.js.map +1 -1
- package/dist/gateway/gateway-zone-orchestrator.d.ts.map +1 -1
- package/dist/gateway/gateway-zone-orchestrator.js +50 -39
- package/dist/gateway/gateway-zone-orchestrator.js.map +1 -1
- package/dist/integration-tests/{smoke-harness.d.ts → e2e-harness.d.ts} +45 -37
- package/dist/integration-tests/e2e-harness.d.ts.map +1 -0
- package/dist/integration-tests/{smoke-harness.js → e2e-harness.js} +134 -108
- package/dist/integration-tests/e2e-harness.js.map +1 -0
- package/dist/integration-tests/e2e-workspace-build-global-setup.d.ts +16 -0
- package/dist/integration-tests/e2e-workspace-build-global-setup.d.ts.map +1 -0
- package/dist/integration-tests/e2e-workspace-build-global-setup.js +27 -0
- package/dist/integration-tests/e2e-workspace-build-global-setup.js.map +1 -0
- package/dist/integration-tests/live-agent-model-roundtrip-deployment.d.ts +11 -0
- package/dist/integration-tests/live-agent-model-roundtrip-deployment.d.ts.map +1 -0
- package/dist/integration-tests/live-agent-model-roundtrip-deployment.js +48 -0
- package/dist/integration-tests/live-agent-model-roundtrip-deployment.js.map +1 -0
- package/dist/integration-tests/live-agent-model-roundtrip-gates.d.ts +11 -0
- package/dist/integration-tests/live-agent-model-roundtrip-gates.d.ts.map +1 -0
- package/dist/integration-tests/live-agent-model-roundtrip-gates.js +21 -0
- package/dist/integration-tests/live-agent-model-roundtrip-gates.js.map +1 -0
- package/dist/integration-tests/live-vm-e2e-gates.d.ts +2 -0
- package/dist/integration-tests/live-vm-e2e-gates.d.ts.map +1 -0
- package/dist/integration-tests/live-vm-e2e-gates.js +4 -0
- package/dist/integration-tests/live-vm-e2e-gates.js.map +1 -0
- package/dist/operations/controller-status.d.ts +5 -0
- package/dist/operations/controller-status.d.ts.map +1 -1
- package/dist/operations/controller-status.js +42 -0
- package/dist/operations/controller-status.js.map +1 -1
- package/package.json +11 -11
- package/dist/integration-tests/live-integration-gates.d.ts +0 -2
- package/dist/integration-tests/live-integration-gates.d.ts.map +0 -1
- package/dist/integration-tests/live-integration-gates.js +0 -4
- package/dist/integration-tests/live-integration-gates.js.map +0 -1
- package/dist/integration-tests/smoke-harness.d.ts.map +0 -1
- package/dist/integration-tests/smoke-harness.js.map +0 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export const defaultGatewayVmChannelProviderRecoveryPolicy = {
|
|
2
|
+
consecutiveFailureThreshold: 3,
|
|
3
|
+
enabled: true,
|
|
4
|
+
restartGatewayOnRecoverable: true,
|
|
5
|
+
restartGatewayOnUnrecoverable: false,
|
|
6
|
+
transitioningTimeoutMs: 120_000,
|
|
7
|
+
};
|
|
8
|
+
function createInitialGatewayVmRecoveryBudgetState() {
|
|
9
|
+
return {
|
|
10
|
+
consecutiveFailedRecoveries: 0,
|
|
11
|
+
lastRecoveryAttemptAtMs: undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const createInitialGatewayVmRecoveryTrackerState = () => ({
|
|
15
|
+
agentChannelProviderConsecutiveFailuresById: new Map(),
|
|
16
|
+
gatewayControlLinkConsecutiveFailures: 0,
|
|
17
|
+
gatewayServiceConsecutiveFailures: 0,
|
|
18
|
+
recoveryBudgets: {
|
|
19
|
+
'gateway-vm-cold-start': createInitialGatewayVmRecoveryBudgetState(),
|
|
20
|
+
'gateway-vm-restart': createInitialGatewayVmRecoveryBudgetState(),
|
|
21
|
+
},
|
|
22
|
+
recoveryInFlight: false,
|
|
23
|
+
});
|
|
24
|
+
function recoveryBudgetClassForEvent(event) {
|
|
25
|
+
return event.recoveryBudgetClass ?? 'gateway-vm-restart';
|
|
26
|
+
}
|
|
27
|
+
function isHealthyObservation(result) {
|
|
28
|
+
return result === 'ok';
|
|
29
|
+
}
|
|
30
|
+
function isDegradedObservation(result) {
|
|
31
|
+
return result === 'failed' || result === 'stale' || result === 'timeout';
|
|
32
|
+
}
|
|
33
|
+
function isWithinCooldown(budgetState, policy, observedAtMs) {
|
|
34
|
+
return (budgetState.lastRecoveryAttemptAtMs !== undefined &&
|
|
35
|
+
observedAtMs - budgetState.lastRecoveryAttemptAtMs < policy.cooldownMs);
|
|
36
|
+
}
|
|
37
|
+
function hasActiveRecoverySuspension(budgetState, policy, observedAtMs) {
|
|
38
|
+
return (budgetState.consecutiveFailedRecoveries >= policy.maxConsecutiveFailedRecoveries &&
|
|
39
|
+
budgetState.lastRecoveryAttemptAtMs !== undefined &&
|
|
40
|
+
observedAtMs - budgetState.lastRecoveryAttemptAtMs < policy.failedRecoveryResetMs);
|
|
41
|
+
}
|
|
42
|
+
function resetFailedRecoveriesIfSuspensionExpired(budgetState, policy, observedAtMs) {
|
|
43
|
+
if (budgetState.consecutiveFailedRecoveries >= policy.maxConsecutiveFailedRecoveries &&
|
|
44
|
+
budgetState.lastRecoveryAttemptAtMs !== undefined &&
|
|
45
|
+
observedAtMs - budgetState.lastRecoveryAttemptAtMs >= policy.failedRecoveryResetMs) {
|
|
46
|
+
budgetState.consecutiveFailedRecoveries = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function channelProviderCounterKey(observation) {
|
|
50
|
+
return observation.channelProviderId ?? '(unknown-channel-provider)';
|
|
51
|
+
}
|
|
52
|
+
function decideRecovery(props) {
|
|
53
|
+
if (!props.policy.enabled) {
|
|
54
|
+
return { consecutiveFailures: props.consecutiveFailures, kind: 'none', reason: 'disabled' };
|
|
55
|
+
}
|
|
56
|
+
if (props.state.recoveryInFlight) {
|
|
57
|
+
return { consecutiveFailures: props.consecutiveFailures, kind: 'none', reason: 'in-flight' };
|
|
58
|
+
}
|
|
59
|
+
if (props.consecutiveFailures < props.policy.consecutiveFailureThreshold) {
|
|
60
|
+
return { consecutiveFailures: props.consecutiveFailures, kind: 'none' };
|
|
61
|
+
}
|
|
62
|
+
const budgetState = props.state.recoveryBudgets[props.recoveryBudgetClass];
|
|
63
|
+
if (isWithinCooldown(budgetState, props.policy, props.observedAtMs)) {
|
|
64
|
+
return { consecutiveFailures: props.consecutiveFailures, kind: 'none', reason: 'cooldown' };
|
|
65
|
+
}
|
|
66
|
+
resetFailedRecoveriesIfSuspensionExpired(budgetState, props.policy, props.observedAtMs);
|
|
67
|
+
if (hasActiveRecoverySuspension(budgetState, props.policy, props.observedAtMs)) {
|
|
68
|
+
return {
|
|
69
|
+
consecutiveFailedRecoveries: budgetState.consecutiveFailedRecoveries,
|
|
70
|
+
consecutiveFailures: props.consecutiveFailures,
|
|
71
|
+
kind: 'suspended',
|
|
72
|
+
reason: 'max-failed-recoveries',
|
|
73
|
+
zoneId: props.zoneId,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
consecutiveFailures: props.consecutiveFailures,
|
|
78
|
+
kind: 'restart',
|
|
79
|
+
reason: props.reason,
|
|
80
|
+
zoneId: props.zoneId,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function createGatewayVmRecoveryTracker(options) {
|
|
84
|
+
const stateByZoneId = new Map();
|
|
85
|
+
const getStateForZone = (zoneId) => {
|
|
86
|
+
const existingState = stateByZoneId.get(zoneId);
|
|
87
|
+
if (existingState) {
|
|
88
|
+
return existingState;
|
|
89
|
+
}
|
|
90
|
+
const state = createInitialGatewayVmRecoveryTrackerState();
|
|
91
|
+
stateByZoneId.set(zoneId, state);
|
|
92
|
+
return state;
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
markRecoveryFinished(event) {
|
|
96
|
+
const state = getStateForZone(event.zoneId);
|
|
97
|
+
state.recoveryInFlight = false;
|
|
98
|
+
if (event.result === 'ok') {
|
|
99
|
+
state.agentChannelProviderConsecutiveFailuresById.clear();
|
|
100
|
+
state.gatewayControlLinkConsecutiveFailures = 0;
|
|
101
|
+
state.gatewayServiceConsecutiveFailures = 0;
|
|
102
|
+
for (const budgetState of Object.values(state.recoveryBudgets)) {
|
|
103
|
+
budgetState.consecutiveFailedRecoveries = 0;
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (event.result === 'failed') {
|
|
108
|
+
state.recoveryBudgets[recoveryBudgetClassForEvent(event)].consecutiveFailedRecoveries += 1;
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
markRecoveryStarted(event) {
|
|
112
|
+
const state = getStateForZone(event.zoneId);
|
|
113
|
+
state.recoveryBudgets[recoveryBudgetClassForEvent(event)].lastRecoveryAttemptAtMs =
|
|
114
|
+
event.observedAtMs;
|
|
115
|
+
state.recoveryInFlight = true;
|
|
116
|
+
},
|
|
117
|
+
recordAgentChannelProviderObservation(observation) {
|
|
118
|
+
const channelProviderPolicy = options.policy.channelProviderHealth ?? defaultGatewayVmChannelProviderRecoveryPolicy;
|
|
119
|
+
const state = getStateForZone(observation.zoneId);
|
|
120
|
+
const counterKey = channelProviderCounterKey(observation);
|
|
121
|
+
const currentConsecutiveFailures = state.agentChannelProviderConsecutiveFailuresById.get(counterKey) ?? 0;
|
|
122
|
+
if (observation.result === 'unobserved') {
|
|
123
|
+
return {
|
|
124
|
+
consecutiveFailures: currentConsecutiveFailures,
|
|
125
|
+
kind: 'none',
|
|
126
|
+
reason: 'unobserved',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (isHealthyObservation(observation.result)) {
|
|
130
|
+
state.agentChannelProviderConsecutiveFailuresById.set(counterKey, 0);
|
|
131
|
+
return { consecutiveFailures: 0, kind: 'none' };
|
|
132
|
+
}
|
|
133
|
+
let consecutiveFailures = currentConsecutiveFailures;
|
|
134
|
+
if (isDegradedObservation(observation.result)) {
|
|
135
|
+
consecutiveFailures += 1;
|
|
136
|
+
state.agentChannelProviderConsecutiveFailuresById.set(counterKey, consecutiveFailures);
|
|
137
|
+
}
|
|
138
|
+
return decideRecovery({
|
|
139
|
+
consecutiveFailures,
|
|
140
|
+
observedAtMs: observation.observedAtMs,
|
|
141
|
+
policy: {
|
|
142
|
+
...options.policy,
|
|
143
|
+
consecutiveFailureThreshold: channelProviderPolicy.consecutiveFailureThreshold,
|
|
144
|
+
enabled: options.policy.enabled && channelProviderPolicy.enabled,
|
|
145
|
+
},
|
|
146
|
+
reason: 'agent-channel-provider-unhealthy',
|
|
147
|
+
recoveryBudgetClass: observation.recoveryBudgetClass ?? 'gateway-vm-restart',
|
|
148
|
+
state,
|
|
149
|
+
zoneId: observation.zoneId,
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
recordGatewayControlLinkObservation(observation) {
|
|
153
|
+
const state = getStateForZone(observation.zoneId);
|
|
154
|
+
if (observation.result === 'unobserved') {
|
|
155
|
+
return {
|
|
156
|
+
consecutiveFailures: state.gatewayControlLinkConsecutiveFailures,
|
|
157
|
+
kind: 'none',
|
|
158
|
+
reason: 'unobserved',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (isHealthyObservation(observation.result)) {
|
|
162
|
+
state.gatewayControlLinkConsecutiveFailures = 0;
|
|
163
|
+
return { consecutiveFailures: 0, kind: 'none' };
|
|
164
|
+
}
|
|
165
|
+
if (isDegradedObservation(observation.result)) {
|
|
166
|
+
state.gatewayControlLinkConsecutiveFailures += 1;
|
|
167
|
+
}
|
|
168
|
+
return decideRecovery({
|
|
169
|
+
consecutiveFailures: state.gatewayControlLinkConsecutiveFailures,
|
|
170
|
+
observedAtMs: observation.observedAtMs,
|
|
171
|
+
policy: options.policy,
|
|
172
|
+
reason: 'gateway-control-link-unhealthy',
|
|
173
|
+
recoveryBudgetClass: observation.recoveryBudgetClass ?? 'gateway-vm-restart',
|
|
174
|
+
state,
|
|
175
|
+
zoneId: observation.zoneId,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
recordGatewayServiceProbe(observation) {
|
|
179
|
+
const state = getStateForZone(observation.zoneId);
|
|
180
|
+
if (isHealthyObservation(observation.result)) {
|
|
181
|
+
state.gatewayServiceConsecutiveFailures = 0;
|
|
182
|
+
return { consecutiveFailures: 0, kind: 'none' };
|
|
183
|
+
}
|
|
184
|
+
if (isDegradedObservation(observation.result)) {
|
|
185
|
+
state.gatewayServiceConsecutiveFailures += 1;
|
|
186
|
+
}
|
|
187
|
+
return decideRecovery({
|
|
188
|
+
consecutiveFailures: state.gatewayServiceConsecutiveFailures,
|
|
189
|
+
observedAtMs: observation.observedAtMs,
|
|
190
|
+
policy: options.policy,
|
|
191
|
+
reason: 'gateway-service-unhealthy',
|
|
192
|
+
recoveryBudgetClass: observation.recoveryBudgetClass ?? 'gateway-vm-restart',
|
|
193
|
+
state,
|
|
194
|
+
zoneId: observation.zoneId,
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=gateway-vm-recovery-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-vm-recovery-policy.js","sourceRoot":"","sources":["../../../src/controller/health/gateway-vm-recovery-policy.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAC,MAAM,6CAA6C,GAAG;IAC5D,2BAA2B,EAAE,CAAC;IAC9B,OAAO,EAAE,IAAI;IACb,2BAA2B,EAAE,IAAI;IACjC,6BAA6B,EAAE,KAAK;IACpC,sBAAsB,EAAE,OAAO;CACkB,CAAC;AAoEnD,SAAS,yCAAyC;IACjD,OAAO;QACN,2BAA2B,EAAE,CAAC;QAC9B,uBAAuB,EAAE,SAAS;KAClC,CAAC;AACH,CAAC;AAED,MAAM,0CAA0C,GAAG,GAAkC,EAAE,CAAC,CAAC;IACxF,2CAA2C,EAAE,IAAI,GAAG,EAAE;IACtD,qCAAqC,EAAE,CAAC;IACxC,iCAAiC,EAAE,CAAC;IACpC,eAAe,EAAE;QAChB,uBAAuB,EAAE,yCAAyC,EAAE;QACpE,oBAAoB,EAAE,yCAAyC,EAAE;KACjE;IACD,gBAAgB,EAAE,KAAK;CACvB,CAAC,CAAC;AAEH,SAAS,2BAA2B,CACnC,KAA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KAAK;gBACL,MAAM,EAAE,WAAW,CAAC,MAAM;aAC1B,CAAC,CAAC;QACJ,CAAC;QACD,yBAAyB,CAAC,WAAW;YACpC,MAAM,KAAK,GAAG,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,oBAAoB,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9C,KAAK,CAAC,iCAAiC,GAAG,CAAC,CAAC;gBAC5C,OAAO,EAAE,mBAAmB,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YACjD,CAAC;YACD,IAAI,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/C,KAAK,CAAC,iCAAiC,IAAI,CAAC,CAAC;YAC9C,CAAC;YACD,OAAO,cAAc,CAAC;gBACrB,mBAAmB,EAAE,KAAK,CAAC,iCAAiC;gBAC5D,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,MAAM,EAAE,2BAA2B;gBACnC,mBAAmB,EAAE,WAAW,CAAC,mBAAmB,IAAI,oBAAoB;gBAC5E,KAAK;gBACL,MAAM,EAAE,WAAW,CAAC,MAAM;aAC1B,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ControllerRuntimeReadiness } from '../http/controller-http-route-support.js';
|
|
2
|
+
import type { GatewayZoneLifecycleState } from '../zone-runtimes/gateway-zone-state-machine.js';
|
|
3
|
+
import type { OpenClawZoneRestartResult } from '../zone-runtimes/zone-runtime-types.js';
|
|
4
|
+
import type { GatewayVmRecoveryRequest, GatewayVmRecoveryResult } from './gateway-service-health-monitor.js';
|
|
5
|
+
export interface CreateGatewayVmRecoveryRunnerOptions {
|
|
6
|
+
readonly getRecoverableGatewayRuntime: (zoneId: string) => RecoverableGatewayRuntime;
|
|
7
|
+
readonly getRuntimeReadiness: () => ControllerRuntimeReadiness;
|
|
8
|
+
readonly now: () => number;
|
|
9
|
+
readonly restartTimeoutMs: number;
|
|
10
|
+
readonly writeLog: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface RecoverableGatewayRuntime {
|
|
13
|
+
readonly coldStart: (options: {
|
|
14
|
+
readonly operationTrigger: 'auto-recovery';
|
|
15
|
+
readonly timeoutMs: number;
|
|
16
|
+
}) => Promise<OpenClawZoneRestartResult>;
|
|
17
|
+
readonly getLifecycleState: () => GatewayZoneLifecycleState;
|
|
18
|
+
readonly getSnapshot: () => {
|
|
19
|
+
readonly bootedAt?: string | undefined;
|
|
20
|
+
readonly gateway?: {
|
|
21
|
+
readonly vm: {
|
|
22
|
+
readonly hostPid?: number | undefined;
|
|
23
|
+
readonly id: string;
|
|
24
|
+
};
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly lifecycleState: 'failed' | 'running' | 'stopped';
|
|
27
|
+
};
|
|
28
|
+
readonly refreshCredentials: () => Promise<{
|
|
29
|
+
readonly ok: true;
|
|
30
|
+
readonly zoneId: string;
|
|
31
|
+
}>;
|
|
32
|
+
readonly restart: (options: {
|
|
33
|
+
readonly operationTrigger: 'auto-recovery';
|
|
34
|
+
readonly timeoutMs: number;
|
|
35
|
+
}) => Promise<OpenClawZoneRestartResult>;
|
|
36
|
+
}
|
|
37
|
+
export declare function classifyGatewayRecoveryRestartError(error: unknown): string;
|
|
38
|
+
export declare function createGatewayVmRecoveryRunner(options: CreateGatewayVmRecoveryRunnerOptions): (request: GatewayVmRecoveryRequest) => Promise<GatewayVmRecoveryResult>;
|
|
39
|
+
//# sourceMappingURL=gateway-vm-recovery-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-vm-recovery-runner.d.ts","sourceRoot":"","sources":["../../../src/controller/health/gateway-vm-recovery-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAC3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AC;QAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE;QAC3B,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC;QAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC3B,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACzC;AAgBD,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAiC1E;AAoBD,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oCAAoC,GAC3C,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAyLzE"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { isOpenClawZoneRestartTimeoutError } from '../zone-runtimes/openclaw-zone-runtime.js';
|
|
2
|
+
import { ControllerZoneRuntimeStartError } from '../zone-runtimes/zone-runtime-errors.js';
|
|
3
|
+
import { classifyGatewayRecoveryAction } from './gateway-recovery-actions.js';
|
|
4
|
+
function formatUnknownError(error) {
|
|
5
|
+
if (error instanceof Error) {
|
|
6
|
+
return error.message;
|
|
7
|
+
}
|
|
8
|
+
return typeof error === 'string' ? error : JSON.stringify(error);
|
|
9
|
+
}
|
|
10
|
+
function getUnknownErrorCode(error) {
|
|
11
|
+
if (typeof error !== 'object' || error === null || !('code' in error)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return typeof error.code === 'string' ? error.code : undefined;
|
|
15
|
+
}
|
|
16
|
+
export function classifyGatewayRecoveryRestartError(error) {
|
|
17
|
+
if (error instanceof ControllerZoneRuntimeStartError &&
|
|
18
|
+
error.gatewayLifecycleErrorCode !== undefined) {
|
|
19
|
+
return error.gatewayLifecycleErrorCode;
|
|
20
|
+
}
|
|
21
|
+
if (isOpenClawZoneRestartTimeoutError(error)) {
|
|
22
|
+
return 'recovery-timeout';
|
|
23
|
+
}
|
|
24
|
+
const code = getUnknownErrorCode(error);
|
|
25
|
+
if (code === 'EACCES' ||
|
|
26
|
+
code === 'EIO' ||
|
|
27
|
+
code === 'ENOENT' ||
|
|
28
|
+
code === 'ENOSPC' ||
|
|
29
|
+
code === 'EROFS') {
|
|
30
|
+
return 'restart-disk-failure';
|
|
31
|
+
}
|
|
32
|
+
const message = formatUnknownError(error).toLowerCase();
|
|
33
|
+
if (message.includes('1password') ||
|
|
34
|
+
message.includes('credential') ||
|
|
35
|
+
message.includes('op://') ||
|
|
36
|
+
message.includes('secret')) {
|
|
37
|
+
return 'restart-secret-failure';
|
|
38
|
+
}
|
|
39
|
+
if (message.includes('gondolin') || message.includes('qemu') || message.includes('vm.create')) {
|
|
40
|
+
return 'restart-vm-create-failed';
|
|
41
|
+
}
|
|
42
|
+
return 'restart-threw';
|
|
43
|
+
}
|
|
44
|
+
function operationIdForRecoveryError(error) {
|
|
45
|
+
return error instanceof ControllerZoneRuntimeStartError ? error.operationId : undefined;
|
|
46
|
+
}
|
|
47
|
+
function classifyGatewayRecoveryRuntimeError(runtime, error) {
|
|
48
|
+
const lifecycleState = runtime.getLifecycleState();
|
|
49
|
+
if (lifecycleState.kind === 'failed' && lifecycleState.error.code === 'owner-unsafe') {
|
|
50
|
+
return 'owner-unsafe';
|
|
51
|
+
}
|
|
52
|
+
if (lifecycleState.kind === 'owner-unsafe') {
|
|
53
|
+
return 'owner-unsafe';
|
|
54
|
+
}
|
|
55
|
+
return classifyGatewayRecoveryRestartError(error);
|
|
56
|
+
}
|
|
57
|
+
export function createGatewayVmRecoveryRunner(options) {
|
|
58
|
+
return async (request) => {
|
|
59
|
+
const startedAtMs = options.now();
|
|
60
|
+
const elapsedMs = () => options.now() - startedAtMs;
|
|
61
|
+
if (options.getRuntimeReadiness().state === 'stopping') {
|
|
62
|
+
return {
|
|
63
|
+
action: 'observe-only',
|
|
64
|
+
elapsedMs: elapsedMs(),
|
|
65
|
+
errorCode: 'controller-stopping',
|
|
66
|
+
result: 'failed',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
let runtime;
|
|
70
|
+
try {
|
|
71
|
+
runtime = options.getRecoverableGatewayRuntime(request.zoneId);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
options.writeLog(`Gateway VM recovery failed to find OpenClaw runtime for zone '${request.zoneId}': ${formatUnknownError(error)}`);
|
|
75
|
+
return {
|
|
76
|
+
action: 'observe-only',
|
|
77
|
+
elapsedMs: elapsedMs(),
|
|
78
|
+
errorCode: 'runtime-unavailable',
|
|
79
|
+
result: 'failed',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const oldSnapshot = runtime.getSnapshot();
|
|
83
|
+
const recoveryAction = classifyGatewayRecoveryAction({
|
|
84
|
+
lifecycleState: runtime.getLifecycleState(),
|
|
85
|
+
recoveryDecision: {
|
|
86
|
+
consecutiveFailures: request.consecutiveFailures,
|
|
87
|
+
kind: 'restart',
|
|
88
|
+
reason: request.reason,
|
|
89
|
+
zoneId: request.zoneId,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
if (recoveryAction.kind === 'refresh-secret-resolver') {
|
|
93
|
+
options.writeLog(`Refreshing gateway secret resolver for zone '${request.zoneId}' after ${request.consecutiveFailures} consecutive ${request.reason} observations.`);
|
|
94
|
+
try {
|
|
95
|
+
await runtime.refreshCredentials();
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
options.writeLog(`Gateway VM recovery credential refresh failed for zone '${request.zoneId}': ${formatUnknownError(error)}`);
|
|
99
|
+
return {
|
|
100
|
+
action: 'gateway-vm-cold-start',
|
|
101
|
+
elapsedMs: elapsedMs(),
|
|
102
|
+
errorCode: classifyGatewayRecoveryRuntimeError(runtime, error),
|
|
103
|
+
...(operationIdForRecoveryError(error) === undefined
|
|
104
|
+
? {}
|
|
105
|
+
: { operationId: operationIdForRecoveryError(error) }),
|
|
106
|
+
result: 'failed',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return verifyColdStartRecovery({
|
|
110
|
+
elapsedMs,
|
|
111
|
+
leaseReleaseFailureCount: 0,
|
|
112
|
+
operationId: undefined,
|
|
113
|
+
runtime,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (recoveryAction.kind === 'cold-start-gateway') {
|
|
117
|
+
options.writeLog(`Auto cold-starting gateway VM for zone '${request.zoneId}' after ${request.consecutiveFailures} consecutive ${request.reason} observations.`);
|
|
118
|
+
let coldStartResult;
|
|
119
|
+
try {
|
|
120
|
+
coldStartResult = await runtime.coldStart({
|
|
121
|
+
operationTrigger: 'auto-recovery',
|
|
122
|
+
timeoutMs: options.restartTimeoutMs,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
options.writeLog(`Gateway VM recovery cold-start failed for zone '${request.zoneId}': ${formatUnknownError(error)}`);
|
|
127
|
+
return {
|
|
128
|
+
action: 'gateway-vm-cold-start',
|
|
129
|
+
elapsedMs: elapsedMs(),
|
|
130
|
+
errorCode: classifyGatewayRecoveryRuntimeError(runtime, error),
|
|
131
|
+
...(operationIdForRecoveryError(error) === undefined
|
|
132
|
+
? {}
|
|
133
|
+
: { operationId: operationIdForRecoveryError(error) }),
|
|
134
|
+
result: 'failed',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return verifyColdStartRecovery({
|
|
138
|
+
elapsedMs,
|
|
139
|
+
leaseReleaseFailureCount: coldStartResult.leaseReleaseFailureCount,
|
|
140
|
+
operationId: coldStartResult.operationId,
|
|
141
|
+
runtime,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (oldSnapshot.lifecycleState !== 'running' || !oldSnapshot.gateway) {
|
|
145
|
+
const failedAction = recoveryAction.kind === 'operator-required'
|
|
146
|
+
? 'operator-required'
|
|
147
|
+
: recoveryAction.kind === 'observe-only'
|
|
148
|
+
? 'observe-only'
|
|
149
|
+
: 'operator-required';
|
|
150
|
+
return {
|
|
151
|
+
action: failedAction,
|
|
152
|
+
elapsedMs: elapsedMs(),
|
|
153
|
+
errorCode: recoveryAction.kind === 'operator-required'
|
|
154
|
+
? recoveryAction.reason
|
|
155
|
+
: recoveryAction.kind === 'observe-only'
|
|
156
|
+
? recoveryAction.reason
|
|
157
|
+
: 'old-gateway-not-running',
|
|
158
|
+
result: 'failed',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const oldGateway = oldSnapshot.gateway;
|
|
162
|
+
const oldBootedAt = oldSnapshot.bootedAt;
|
|
163
|
+
const oldHostPid = oldGateway.vm.hostPid;
|
|
164
|
+
options.writeLog(`Auto-restarting gateway VM for zone '${request.zoneId}' after ${request.consecutiveFailures} consecutive ${request.reason} observations.`);
|
|
165
|
+
let restartResult;
|
|
166
|
+
try {
|
|
167
|
+
restartResult = await runtime.restart({
|
|
168
|
+
operationTrigger: 'auto-recovery',
|
|
169
|
+
timeoutMs: options.restartTimeoutMs,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
options.writeLog(`Gateway VM recovery restart failed for zone '${request.zoneId}': ${formatUnknownError(error)}`);
|
|
174
|
+
return {
|
|
175
|
+
action: 'gateway-vm-restart',
|
|
176
|
+
elapsedMs: elapsedMs(),
|
|
177
|
+
errorCode: classifyGatewayRecoveryRuntimeError(runtime, error),
|
|
178
|
+
...(oldBootedAt === undefined ? {} : { oldBootedAt }),
|
|
179
|
+
...(oldHostPid === undefined ? {} : { oldHostPid }),
|
|
180
|
+
oldVmId: oldGateway.vm.id,
|
|
181
|
+
...(operationIdForRecoveryError(error) === undefined
|
|
182
|
+
? {}
|
|
183
|
+
: { operationId: operationIdForRecoveryError(error) }),
|
|
184
|
+
result: 'failed',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const newSnapshot = runtime.getSnapshot();
|
|
188
|
+
const newBootedAt = newSnapshot.bootedAt;
|
|
189
|
+
const newGateway = newSnapshot.gateway;
|
|
190
|
+
if (newSnapshot.lifecycleState !== 'running' ||
|
|
191
|
+
!newGateway ||
|
|
192
|
+
oldBootedAt === undefined ||
|
|
193
|
+
newBootedAt === undefined ||
|
|
194
|
+
oldHostPid === undefined ||
|
|
195
|
+
newGateway.vm.hostPid === undefined ||
|
|
196
|
+
newGateway.vm.id === oldGateway.vm.id ||
|
|
197
|
+
newGateway.vm.hostPid === oldHostPid ||
|
|
198
|
+
newBootedAt === oldBootedAt) {
|
|
199
|
+
return {
|
|
200
|
+
action: 'gateway-vm-restart',
|
|
201
|
+
elapsedMs: elapsedMs(),
|
|
202
|
+
errorCode: 'restart-verification-failed',
|
|
203
|
+
...(oldBootedAt === undefined ? {} : { oldBootedAt }),
|
|
204
|
+
...(oldHostPid === undefined ? {} : { oldHostPid }),
|
|
205
|
+
oldVmId: oldGateway.vm.id,
|
|
206
|
+
result: 'failed',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
elapsedMs: elapsedMs(),
|
|
211
|
+
leaseReleaseFailureCount: restartResult.leaseReleaseFailureCount,
|
|
212
|
+
newBootedAt,
|
|
213
|
+
newHostPid: newGateway.vm.hostPid,
|
|
214
|
+
newVmId: newGateway.vm.id,
|
|
215
|
+
oldBootedAt,
|
|
216
|
+
oldHostPid,
|
|
217
|
+
oldVmId: oldGateway.vm.id,
|
|
218
|
+
...(restartResult.operationId === undefined
|
|
219
|
+
? {}
|
|
220
|
+
: { operationId: restartResult.operationId }),
|
|
221
|
+
result: 'ok',
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function verifyColdStartRecovery(options) {
|
|
226
|
+
const newSnapshot = options.runtime.getSnapshot();
|
|
227
|
+
const newBootedAt = newSnapshot.bootedAt;
|
|
228
|
+
const newGateway = newSnapshot.gateway;
|
|
229
|
+
if (newSnapshot.lifecycleState !== 'running' ||
|
|
230
|
+
!newGateway ||
|
|
231
|
+
newBootedAt === undefined ||
|
|
232
|
+
newGateway.vm.hostPid === undefined) {
|
|
233
|
+
return {
|
|
234
|
+
action: 'gateway-vm-cold-start',
|
|
235
|
+
elapsedMs: options.elapsedMs(),
|
|
236
|
+
errorCode: 'cold-start-verification-failed',
|
|
237
|
+
result: 'failed',
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
action: 'gateway-vm-cold-start',
|
|
242
|
+
elapsedMs: options.elapsedMs(),
|
|
243
|
+
leaseReleaseFailureCount: options.leaseReleaseFailureCount,
|
|
244
|
+
newBootedAt,
|
|
245
|
+
newHostPid: newGateway.vm.hostPid,
|
|
246
|
+
newVmId: newGateway.vm.id,
|
|
247
|
+
...(options.operationId === undefined ? {} : { operationId: options.operationId }),
|
|
248
|
+
result: 'ok',
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=gateway-vm-recovery-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-vm-recovery-runner.js","sourceRoot":"","sources":["../../../src/controller/health/gateway-vm-recovery-runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAC9F,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAE1F,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAoC9E,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC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,UAAU,CAAC,EAAE,CAAC,OAAO;QACjC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE;QACzB,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAClF,MAAM,EAAE,IAAI;KACZ,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type AgentVmHealthEvent, type ZoneHealthSnapshot } from '@agent-vm/gateway-interface';
|
|
2
2
|
export interface HealthEventStoreOptions {
|
|
3
|
+
readonly durableEventLog?: {
|
|
4
|
+
readonly append: (event: AgentVmHealthEvent) => Promise<void>;
|
|
5
|
+
} | undefined;
|
|
3
6
|
readonly eventHistoryLimit: number;
|
|
4
7
|
readonly latestBucketLimit?: number | undefined;
|
|
5
8
|
readonly staleAfterMs: number;
|
|
@@ -13,6 +16,7 @@ export declare class HealthEventStore {
|
|
|
13
16
|
constructor(options: HealthEventStoreOptions);
|
|
14
17
|
record(event: AgentVmHealthEvent): void;
|
|
15
18
|
listHistory(): readonly AgentVmHealthEvent[];
|
|
19
|
+
flushDurableWrites(): Promise<void>;
|
|
16
20
|
listLatestEventsForZone(zoneId: string): readonly AgentVmHealthEvent[];
|
|
17
21
|
deriveSnapshot(options: DeriveHealthSnapshotOptions): ZoneHealthSnapshot;
|
|
18
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health-event-store.d.ts","sourceRoot":"","sources":["../../../src/controller/health/health-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,gBAAgB;;
|
|
1
|
+
{"version":3,"file":"health-event-store.d.ts","sourceRoot":"","sources":["../../../src/controller/health/health-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,eAAe,CAAC,EACtB;QAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,GACjE,SAAS,CAAC;IACb,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,gBAAgB;;gBAShB,OAAO,EAAE,uBAAuB;IAO5C,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IA6BvC,WAAW,IAAI,SAAS,kBAAkB,EAAE;IAItC,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,kBAAkB,EAAE;IAMtE,cAAc,CAAC,OAAO,EAAE,2BAA2B,GAAG,kBAAkB;CAoBxE"}
|
|
@@ -4,8 +4,11 @@ export class HealthEventStore {
|
|
|
4
4
|
#latestBucketLimit;
|
|
5
5
|
#latestByBucket = new Map();
|
|
6
6
|
#history = [];
|
|
7
|
+
#durableEventLog;
|
|
8
|
+
#durableWriteQueue = Promise.resolve();
|
|
7
9
|
#staleAfterMs;
|
|
8
10
|
constructor(options) {
|
|
11
|
+
this.#durableEventLog = options.durableEventLog;
|
|
9
12
|
this.#eventHistoryLimit = options.eventHistoryLimit;
|
|
10
13
|
this.#latestBucketLimit = options.latestBucketLimit ?? 1_000;
|
|
11
14
|
this.#staleAfterMs = options.staleAfterMs;
|
|
@@ -21,6 +24,7 @@ export class HealthEventStore {
|
|
|
21
24
|
this.#latestByBucket.set(key, event);
|
|
22
25
|
}
|
|
23
26
|
this.#evictOldestLatestBuckets();
|
|
27
|
+
this.#queueDurableWrite(event);
|
|
24
28
|
}
|
|
25
29
|
#evictOldestLatestBuckets() {
|
|
26
30
|
if (this.#latestByBucket.size <= this.#latestBucketLimit) {
|
|
@@ -38,6 +42,9 @@ export class HealthEventStore {
|
|
|
38
42
|
listHistory() {
|
|
39
43
|
return [...this.#history];
|
|
40
44
|
}
|
|
45
|
+
async flushDurableWrites() {
|
|
46
|
+
await this.#durableWriteQueue;
|
|
47
|
+
}
|
|
41
48
|
listLatestEventsForZone(zoneId) {
|
|
42
49
|
return [...this.#latestByBucket.values()]
|
|
43
50
|
.filter((event) => event.zoneId === zoneId)
|
|
@@ -50,5 +57,17 @@ export class HealthEventStore {
|
|
|
50
57
|
zoneId: options.zoneId,
|
|
51
58
|
});
|
|
52
59
|
}
|
|
60
|
+
#queueDurableWrite(event) {
|
|
61
|
+
if (!this.#durableEventLog) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.#durableWriteQueue = this.#durableWriteQueue
|
|
65
|
+
.then(async () => {
|
|
66
|
+
await this.#durableEventLog?.append(event);
|
|
67
|
+
})
|
|
68
|
+
.catch(() => {
|
|
69
|
+
// Durable logs are evidence. In-memory health remains the serving path.
|
|
70
|
+
});
|
|
71
|
+
}
|
|
53
72
|
}
|
|
54
73
|
//# sourceMappingURL=health-event-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health-event-store.js","sourceRoot":"","sources":["../../../src/controller/health/health-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,EACxB,oBAAoB,GAGpB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"health-event-store.js","sourceRoot":"","sources":["../../../src/controller/health/health-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,EACxB,oBAAoB,GAGpB,MAAM,6BAA6B,CAAC;AAgBrC,MAAM,OAAO,gBAAgB;IACnB,kBAAkB,CAAS;IAC3B,kBAAkB,CAAS;IAC3B,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAC;IACxD,QAAQ,GAAyB,EAAE,CAAC;IACpC,gBAAgB,CAA6C;IACtE,kBAAkB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7C,aAAa,CAAS;IAE/B,YAAY,OAAgC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACpD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,IAAI,KAAK,CAAC;QAC7D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,KAAyB;QAC/B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QAED,MAAM,GAAG,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAA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KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;aAC1C,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IACzE,CAAC;IAED,cAAc,CAAC,OAAoC;QAClD,OAAO,wBAAwB,CAAC,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC7E,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,MAAM,EAAE,OAAO,CAAC,MAAM;SACtB,CAAC,CAAC;IACJ,CAAC;IAED,kBAAkB,CAAC,KAAyB;QAC3C,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC5B,OAAO;QACR,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB;aAC/C,IAAI,CAAC,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACX,wEAAwE;QACzE,CAAC,CAAC,CAAC;IACL,CAAC;CACD"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type Hono } from 'hono';
|
|
2
2
|
import type { HealthEventStore } from '../health/health-event-store.js';
|
|
3
3
|
export interface RegisterControllerHealthEventRoutesOptions {
|
|
4
|
+
readonly leaseRemediation?: {
|
|
5
|
+
readonly getLeaseOwner: ((leaseId: string) => {
|
|
6
|
+
readonly agentId: string;
|
|
7
|
+
readonly zoneId: string;
|
|
8
|
+
} | undefined) | undefined;
|
|
9
|
+
} | undefined;
|
|
4
10
|
readonly now: () => number;
|
|
5
11
|
readonly store: HealthEventStore;
|
|
6
12
|
readonly zoneIds?: ReadonlySet<string> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-health-event-routes.d.ts","sourceRoot":"","sources":["../../../src/controller/http/controller-health-event-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"controller-health-event-routes.d.ts","sourceRoot":"","sources":["../../../src/controller/http/controller-health-event-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAcxE,MAAM,WAAW,0CAA0C;IAC1D,QAAQ,CAAC,gBAAgB,CAAC,EACvB;QACA,QAAQ,CAAC,aAAa,EACnB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;YAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC,GACxF,SAAS,CAAC;KACZ,GACD,SAAS,CAAC;IACb,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CACnD;AAuDD,wBAAgB,mCAAmC,CAClD,GAAG,EAAE,IAAI,EACT,OAAO,EAAE,0CAA0C,GACjD,IAAI,CAsEN"}
|