amalgm 0.1.251 → 0.1.252
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/package.json
CHANGED
|
@@ -3,36 +3,10 @@
|
|
|
3
3
|
const { activeAgentConversations } = require('../../agents/talk');
|
|
4
4
|
|
|
5
5
|
// /healthz is a liveness signal: the parent supervisor kills this process
|
|
6
|
-
// after three slow answers
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let countsRefreshedAt = 0;
|
|
11
|
-
let countsRefreshing = false;
|
|
12
|
-
|
|
13
|
-
function refreshCountsSoon() {
|
|
14
|
-
if (countsRefreshing || Date.now() - countsRefreshedAt < COUNTS_TTL_MS) return;
|
|
15
|
-
countsRefreshing = true;
|
|
16
|
-
setImmediate(() => {
|
|
17
|
-
try {
|
|
18
|
-
const { loadAgents } = require('../../agents/store');
|
|
19
|
-
const { loadApps } = require('../../apps/store');
|
|
20
|
-
const { listAutomations } = require('../../automations/store');
|
|
21
|
-
const automations = listAutomations();
|
|
22
|
-
cachedCounts = {
|
|
23
|
-
automations: automations.length,
|
|
24
|
-
enabledAutomations: automations.filter((automation) => automation.enabled !== false).length,
|
|
25
|
-
apps: loadApps().apps.length,
|
|
26
|
-
customAgents: loadAgents().agents.length,
|
|
27
|
-
};
|
|
28
|
-
countsRefreshedAt = Date.now();
|
|
29
|
-
} catch {
|
|
30
|
-
// Counts stay stale; liveness must not depend on store reads succeeding.
|
|
31
|
-
} finally {
|
|
32
|
-
countsRefreshing = false;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
6
|
+
// after three slow answers. It therefore performs no I/O and starts no
|
|
7
|
+
// follow-up work. Operational counts belong on diagnostic routes: allowing a
|
|
8
|
+
// liveness probe to inspect the user's state store made a large, healthy
|
|
9
|
+
// installation look dead by blocking its own event loop.
|
|
36
10
|
|
|
37
11
|
async function handleHealthRoutes(ctx) {
|
|
38
12
|
if (ctx.pathname !== '/healthz') return false;
|
|
@@ -43,10 +17,8 @@ async function handleHealthRoutes(ctx) {
|
|
|
43
17
|
runtime_label: process.env.AMALGM_RUNTIME_LABEL || 'main',
|
|
44
18
|
runtime_instance_id: process.env.AMALGM_RUNTIME_INSTANCE_ID || '',
|
|
45
19
|
pid: process.pid,
|
|
46
|
-
...cachedCounts,
|
|
47
20
|
activeAgentConversations: activeAgentConversations.size,
|
|
48
21
|
});
|
|
49
|
-
refreshCountsSoon();
|
|
50
22
|
return true;
|
|
51
23
|
}
|
|
52
24
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
|
|
6
|
+
test('/healthz is an I/O-free liveness response', async () => {
|
|
7
|
+
const { handleHealthRoutes } = require('../server/routes/health');
|
|
8
|
+
const replies = [];
|
|
9
|
+
const handled = await handleHealthRoutes({
|
|
10
|
+
pathname: '/healthz',
|
|
11
|
+
sendJson: (status, body) => replies.push({ status, body }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
assert.equal(handled, true);
|
|
15
|
+
assert.equal(replies.length, 1);
|
|
16
|
+
assert.equal(replies[0].status, 200);
|
|
17
|
+
assert.equal(replies[0].body.status, 'ok');
|
|
18
|
+
assert.equal(Object.hasOwn(replies[0].body, 'automations'), false);
|
|
19
|
+
assert.equal(Object.hasOwn(replies[0].body, 'apps'), false);
|
|
20
|
+
});
|