@addai/node 0.23.0 → 0.24.0
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/control-server.js +6 -1
- package/dist/heartbeat.js +6 -0
- package/dist/request-pump.d.ts +11 -0
- package/dist/request-pump.js +51 -3
- package/dist/tui/dashboard.d.ts +2 -0
- package/dist/tui/dashboard.js +1 -1
- package/dist/tui/run.js +2 -1
- package/dist/win.d.ts +26 -2
- package/dist/win.js +94 -5
- package/package.json +1 -1
package/dist/control-server.js
CHANGED
|
@@ -114,7 +114,12 @@ async function handleRequest(req, res) {
|
|
|
114
114
|
if (data == null)
|
|
115
115
|
return;
|
|
116
116
|
const inflight = (0, request_pump_1.inflightCount)();
|
|
117
|
-
|
|
117
|
+
// The ceiling next to the count: "3 inflight" means nothing without it.
|
|
118
|
+
return send(res, 200, {
|
|
119
|
+
...data,
|
|
120
|
+
inflight,
|
|
121
|
+
max_concurrent: (0, request_pump_1.maxConcurrentRuns)(),
|
|
122
|
+
});
|
|
118
123
|
}
|
|
119
124
|
// Recent requests (most recent first). ?limit=20 caps the count.
|
|
120
125
|
if (path === '/requests' && method === 'GET') {
|
package/dist/heartbeat.js
CHANGED
|
@@ -53,6 +53,12 @@ async function tick() {
|
|
|
53
53
|
}
|
|
54
54
|
if (res && typeof res.auto_update === 'boolean')
|
|
55
55
|
autoUpdateArmed = res.auto_update;
|
|
56
|
+
// How many runs this node may hold at once. Same rationale as auto_update:
|
|
57
|
+
// one number on the node's own row, and the daemon is already talking to
|
|
58
|
+
// the server every 30s. Absent field = older server = leave the pump on
|
|
59
|
+
// whatever it already had (its own default of 4).
|
|
60
|
+
if (res && res.max_concurrent_runs != null)
|
|
61
|
+
(0, request_pump_1.setMaxConcurrent)(res.max_concurrent_runs);
|
|
56
62
|
}
|
|
57
63
|
catch (err) {
|
|
58
64
|
if (err instanceof supabase_client_1.RpcError && err.status === 401) {
|
package/dist/request-pump.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_CONCURRENT = 4;
|
|
2
|
+
/** Clamp whatever the server sent into something the pump can act on. A null,
|
|
3
|
+
* a string, a 0 or a 10_000 must not be able to wedge the pump shut or uncap
|
|
4
|
+
* it — the ceiling matches the DB's own 1..32 check constraint. */
|
|
5
|
+
export declare function clampMaxConcurrent(value: unknown): number;
|
|
6
|
+
/** Called by the heartbeat when the node's row says a different number.
|
|
7
|
+
* Lowering it never interrupts a run already in flight — those finish; the
|
|
8
|
+
* pump simply stops picking up new work until it is back under the line. */
|
|
9
|
+
export declare function setMaxConcurrent(value: unknown): void;
|
|
10
|
+
/** The node's current ceiling. Exported for /stats and the TUI. */
|
|
11
|
+
export declare function maxConcurrentRuns(): number;
|
|
1
12
|
export declare function inflightCount(): number;
|
|
2
13
|
export declare function activeRequestIdList(): string[];
|
|
3
14
|
export declare function start(): void;
|
package/dist/request-pump.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
// from spawning unlimited Claude processes when a burst of requests
|
|
5
5
|
// arrives.
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_MAX_CONCURRENT = void 0;
|
|
8
|
+
exports.clampMaxConcurrent = clampMaxConcurrent;
|
|
9
|
+
exports.setMaxConcurrent = setMaxConcurrent;
|
|
10
|
+
exports.maxConcurrentRuns = maxConcurrentRuns;
|
|
7
11
|
exports.inflightCount = inflightCount;
|
|
8
12
|
exports.activeRequestIdList = activeRequestIdList;
|
|
9
13
|
exports.start = start;
|
|
@@ -25,7 +29,51 @@ const diskguard_1 = require("./diskguard");
|
|
|
25
29
|
// ~16x cheaper at steady state. Successful pickups still re-tick
|
|
26
30
|
// immediately so bursts drain fast.
|
|
27
31
|
const POLL_INTERVAL_MS = 2_000;
|
|
28
|
-
const MAX_CONCURRENT
|
|
32
|
+
// How many runs this node holds at once. This used to be `const MAX_CONCURRENT
|
|
33
|
+
// = 4` — one number, compiled in, the same for a 64-core box and a Mac mini.
|
|
34
|
+
// It is now the node's own setting (entity_runtimes.max_concurrent_runs),
|
|
35
|
+
// pushed in by the heartbeat that already talks to the server every 30s.
|
|
36
|
+
//
|
|
37
|
+
// The default is still 4, and specifically 4 when the server says NOTHING: a
|
|
38
|
+
// server without the migration must read as "the behaviour you had yesterday",
|
|
39
|
+
// never as 0 (a node that accepts no work at all) or unbounded.
|
|
40
|
+
exports.DEFAULT_MAX_CONCURRENT = 4;
|
|
41
|
+
const MAX_MAX_CONCURRENT = 32;
|
|
42
|
+
let maxConcurrent = exports.DEFAULT_MAX_CONCURRENT;
|
|
43
|
+
/** Clamp whatever the server sent into something the pump can act on. A null,
|
|
44
|
+
* a string, a 0 or a 10_000 must not be able to wedge the pump shut or uncap
|
|
45
|
+
* it — the ceiling matches the DB's own 1..32 check constraint. */
|
|
46
|
+
function clampMaxConcurrent(value) {
|
|
47
|
+
// Absent is NOT zero. `Number(null)` and `Number('')` are both 0, which the
|
|
48
|
+
// clamp below would happily read as "one slot" — so a server that said
|
|
49
|
+
// nothing would quietly throttle the node to a single run. Anything that
|
|
50
|
+
// isn't a real number-shaped value means "no answer", which means: keep
|
|
51
|
+
// doing what you were doing.
|
|
52
|
+
if (typeof value !== 'number' && typeof value !== 'string')
|
|
53
|
+
return exports.DEFAULT_MAX_CONCURRENT;
|
|
54
|
+
if (typeof value === 'string' && value.trim() === '')
|
|
55
|
+
return exports.DEFAULT_MAX_CONCURRENT;
|
|
56
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
57
|
+
if (!Number.isFinite(n))
|
|
58
|
+
return exports.DEFAULT_MAX_CONCURRENT;
|
|
59
|
+
return Math.min(MAX_MAX_CONCURRENT, Math.max(1, Math.floor(n)));
|
|
60
|
+
}
|
|
61
|
+
/** Called by the heartbeat when the node's row says a different number.
|
|
62
|
+
* Lowering it never interrupts a run already in flight — those finish; the
|
|
63
|
+
* pump simply stops picking up new work until it is back under the line. */
|
|
64
|
+
function setMaxConcurrent(value) {
|
|
65
|
+
const next = clampMaxConcurrent(value);
|
|
66
|
+
if (next === maxConcurrent)
|
|
67
|
+
return;
|
|
68
|
+
console.log(`[request-pump] runs at once: ${maxConcurrent} -> ${next}`);
|
|
69
|
+
maxConcurrent = next;
|
|
70
|
+
// Raising the cap should take effect NOW, not at the next 2s poll — the
|
|
71
|
+
// usual reason someone raises it is that work is queued up behind it.
|
|
72
|
+
if (!stopped && inflight < maxConcurrent)
|
|
73
|
+
queueMicrotask(() => { void tick(); });
|
|
74
|
+
}
|
|
75
|
+
/** The node's current ceiling. Exported for /stats and the TUI. */
|
|
76
|
+
function maxConcurrentRuns() { return maxConcurrent; }
|
|
29
77
|
// Anti-leak backstop ONLY — how long the pump will hold a concurrency slot
|
|
30
78
|
// for a run whose promise never resolves (e.g. a spawn whose onExit is
|
|
31
79
|
// lost). This does NOT kill the agent and is NOT an execution limit: it
|
|
@@ -72,7 +120,7 @@ function activeRequestIdList() { return [...activeRequestIds]; }
|
|
|
72
120
|
async function tick() {
|
|
73
121
|
if (stopped)
|
|
74
122
|
return;
|
|
75
|
-
if (inflight >=
|
|
123
|
+
if (inflight >= maxConcurrent)
|
|
76
124
|
return;
|
|
77
125
|
// Honour the backoff window — skip this tick if we recently failed.
|
|
78
126
|
if (Date.now() < nextPickAllowedAt)
|
|
@@ -215,7 +263,7 @@ async function tick() {
|
|
|
215
263
|
// Re-tick immediately so back-to-back requests don't wait for the
|
|
216
264
|
// next interval. If there's nothing to pick up the next call is a
|
|
217
265
|
// cheap no-op.
|
|
218
|
-
if (!stopped && inflight <
|
|
266
|
+
if (!stopped && inflight < maxConcurrent) {
|
|
219
267
|
queueMicrotask(() => { void tick(); });
|
|
220
268
|
}
|
|
221
269
|
}
|
package/dist/tui/dashboard.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface DashboardState {
|
|
|
20
20
|
pid: number | null;
|
|
21
21
|
startedAt: number | null;
|
|
22
22
|
inflight: number;
|
|
23
|
+
/** The node's ceiling on concurrent runs — the denominator for `inflight`. */
|
|
24
|
+
maxConcurrent: number;
|
|
23
25
|
paired: boolean;
|
|
24
26
|
viewerMode: boolean;
|
|
25
27
|
/** First press of 'd' asks; the second one does it. */
|
package/dist/tui/dashboard.js
CHANGED
|
@@ -84,7 +84,7 @@ function headerLines(st) {
|
|
|
84
84
|
const up = st.startedAt ? (0, render_1.fmtDuration)(st.now - st.startedAt) : '—';
|
|
85
85
|
const daemon = st.viewerMode
|
|
86
86
|
? `${(0, render_1.cyan)('⏺')} Viewer ${(0, render_1.dim)(`pid ${st.pid ?? '?'}`)} ${(0, render_1.dim)('· another process owns this node')}`
|
|
87
|
-
: `${(0, render_1.green)('⏺')} Running ${(0, render_1.dim)(`pid ${st.pid ?? '?'}`)} ${(0, render_1.dim)(`up ${up}`)} ${(0, render_1.dim)(`${st.inflight} in flight`)}`;
|
|
87
|
+
: `${(0, render_1.green)('⏺')} Running ${(0, render_1.dim)(`pid ${st.pid ?? '?'}`)} ${(0, render_1.dim)(`up ${up}`)} ${(0, render_1.dim)(`${st.inflight}/${st.maxConcurrent} in flight`)}`;
|
|
88
88
|
const chip = st.offline ? ` ${(0, render_1.yellow)('⚠ Offline · retrying')}` : '';
|
|
89
89
|
return [first, daemon + chip, autostartLine(st)];
|
|
90
90
|
}
|
package/dist/tui/run.js
CHANGED
|
@@ -195,7 +195,7 @@ async function runDashboard(opts) {
|
|
|
195
195
|
const state = {
|
|
196
196
|
self: null, stats: null, recent: [], sel: 0, nowSelId: null, nowRows: 0, spin: 0,
|
|
197
197
|
pid: opts.pid, startedAt: opts.startedAt,
|
|
198
|
-
inflight: 0, paired: (0, store_1.isPaired)(), viewerMode: opts.viewerMode,
|
|
198
|
+
inflight: 0, maxConcurrent: request_pump_1.DEFAULT_MAX_CONCURRENT, paired: (0, store_1.isPaired)(), viewerMode: opts.viewerMode,
|
|
199
199
|
offline: false, now: Date.now(), version: opts.version,
|
|
200
200
|
logCount: 0,
|
|
201
201
|
// Read on the first poll rather than here — the first frame must paint
|
|
@@ -229,6 +229,7 @@ async function runDashboard(opts) {
|
|
|
229
229
|
// The daemon's own numbers don't come from an RPC.
|
|
230
230
|
setInterval(() => {
|
|
231
231
|
state.inflight = (0, request_pump_1.inflightCount)();
|
|
232
|
+
state.maxConcurrent = (0, request_pump_1.maxConcurrentRuns)();
|
|
232
233
|
state.logCount = logs.count();
|
|
233
234
|
}, 1000).unref();
|
|
234
235
|
await ui.run();
|
package/dist/win.d.ts
CHANGED
|
@@ -35,13 +35,37 @@ export declare function resolveCliInvocation(bin: string, args: string[]): CliIn
|
|
|
35
35
|
* note: no trailing `%`). */
|
|
36
36
|
declare function resolveNpmShimScript(shimPath: string): string | null;
|
|
37
37
|
/**
|
|
38
|
-
* Kill an agent child process
|
|
39
|
-
*
|
|
38
|
+
* Kill an agent child process AND everything it spawned.
|
|
39
|
+
*
|
|
40
|
+
* win32: `taskkill /T /F` — Node's SIGINT emulation is a hard
|
|
40
41
|
* TerminateProcess on the one process anyway, and /T also reaps the MCP
|
|
41
42
|
* server grandchildren that would otherwise be orphaned.
|
|
43
|
+
*
|
|
44
|
+
* POSIX used to be one line — `proc.kill('SIGINT')` — which is neither a
|
|
45
|
+
* tree nor a guarantee, and both halves of that bit us. On 2026-08-12 a
|
|
46
|
+
* chatflows stop killed grok's direct child (the run reported
|
|
47
|
+
* `session_end exitCode -1`, i.e. died by signal) while the process it had
|
|
48
|
+
* forked carried on for another 49 seconds on the inherited stdout pipe,
|
|
49
|
+
* finished its turn, and posted a real message into someone's DM 22 seconds
|
|
50
|
+
* after the user pressed stop. So:
|
|
51
|
+
*
|
|
52
|
+
* 1. Signal the whole tree, not just the handle. We do not spawn agents
|
|
53
|
+
* `detached`, so there is no process group to signal — walking `ps` is
|
|
54
|
+
* the portable way to find the descendants, and it also catches stdio
|
|
55
|
+
* MCP servers the agent started (the same ones /T reaps on Windows).
|
|
56
|
+
* 2. Escalate. SIGINT first, because an agent CLI flushes its session
|
|
57
|
+
* file on it; SIGKILL KILL_ESCALATE_MS later for anything still there.
|
|
58
|
+
* A CLI is entitled to treat SIGINT as "interrupt the current input"
|
|
59
|
+
* rather than "exit" — being polite once and never following up is how
|
|
60
|
+
* a stop button turns into a suggestion.
|
|
61
|
+
*
|
|
62
|
+
* The escalation re-walks the tree: a process that ignored SIGINT may have
|
|
63
|
+
* forked since. The timer is unref'd so it never holds the daemon open.
|
|
42
64
|
*/
|
|
43
65
|
export declare function killProcessTree(proc: {
|
|
44
66
|
pid?: number | undefined;
|
|
67
|
+
exitCode?: number | null;
|
|
68
|
+
signalCode?: NodeJS.Signals | null;
|
|
45
69
|
kill(signal?: NodeJS.Signals): boolean | void;
|
|
46
70
|
}): void;
|
|
47
71
|
/**
|
package/dist/win.js
CHANGED
|
@@ -244,11 +244,77 @@ function resolveNpmShimScript(shimPath) {
|
|
|
244
244
|
}
|
|
245
245
|
return null;
|
|
246
246
|
}
|
|
247
|
+
/** How long a POSIX agent gets to honour SIGINT before we stop asking. */
|
|
248
|
+
const KILL_ESCALATE_MS = 3000;
|
|
249
|
+
/** One `ps` snapshot as (pid, ppid) pairs. Empty on any failure — callers
|
|
250
|
+
* then fall back to signalling just the process they were handed, which is
|
|
251
|
+
* the old behaviour and never worse than it. */
|
|
252
|
+
function posixProcessTable() {
|
|
253
|
+
try {
|
|
254
|
+
const out = (0, child_process_1.execFileSync)('ps', ['-Ao', 'pid=,ppid='], { encoding: 'utf8', timeout: 5000 });
|
|
255
|
+
return out.split('\n')
|
|
256
|
+
.map(line => line.trim().split(/\s+/))
|
|
257
|
+
.filter(parts => parts.length === 2)
|
|
258
|
+
.map(([a, b]) => ({ pid: Number(a), ppid: Number(b) }))
|
|
259
|
+
.filter(r => Number.isInteger(r.pid) && Number.isInteger(r.ppid) && r.pid > 0);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** Every descendant of `root`, breadth-first (so the deepest come last). */
|
|
266
|
+
function posixDescendants(root) {
|
|
267
|
+
const byParent = new Map();
|
|
268
|
+
for (const { pid, ppid } of posixProcessTable()) {
|
|
269
|
+
if (pid === ppid)
|
|
270
|
+
continue; // pid 1 parents itself on some kernels
|
|
271
|
+
const kids = byParent.get(ppid);
|
|
272
|
+
if (kids)
|
|
273
|
+
kids.push(pid);
|
|
274
|
+
else
|
|
275
|
+
byParent.set(ppid, [pid]);
|
|
276
|
+
}
|
|
277
|
+
const out = [];
|
|
278
|
+
const seen = new Set([root]);
|
|
279
|
+
const queue = [root];
|
|
280
|
+
while (queue.length > 0) {
|
|
281
|
+
for (const kid of byParent.get(queue.shift()) ?? []) {
|
|
282
|
+
if (seen.has(kid))
|
|
283
|
+
continue;
|
|
284
|
+
seen.add(kid);
|
|
285
|
+
out.push(kid);
|
|
286
|
+
queue.push(kid);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
247
291
|
/**
|
|
248
|
-
* Kill an agent child process
|
|
249
|
-
*
|
|
292
|
+
* Kill an agent child process AND everything it spawned.
|
|
293
|
+
*
|
|
294
|
+
* win32: `taskkill /T /F` — Node's SIGINT emulation is a hard
|
|
250
295
|
* TerminateProcess on the one process anyway, and /T also reaps the MCP
|
|
251
296
|
* server grandchildren that would otherwise be orphaned.
|
|
297
|
+
*
|
|
298
|
+
* POSIX used to be one line — `proc.kill('SIGINT')` — which is neither a
|
|
299
|
+
* tree nor a guarantee, and both halves of that bit us. On 2026-08-12 a
|
|
300
|
+
* chatflows stop killed grok's direct child (the run reported
|
|
301
|
+
* `session_end exitCode -1`, i.e. died by signal) while the process it had
|
|
302
|
+
* forked carried on for another 49 seconds on the inherited stdout pipe,
|
|
303
|
+
* finished its turn, and posted a real message into someone's DM 22 seconds
|
|
304
|
+
* after the user pressed stop. So:
|
|
305
|
+
*
|
|
306
|
+
* 1. Signal the whole tree, not just the handle. We do not spawn agents
|
|
307
|
+
* `detached`, so there is no process group to signal — walking `ps` is
|
|
308
|
+
* the portable way to find the descendants, and it also catches stdio
|
|
309
|
+
* MCP servers the agent started (the same ones /T reaps on Windows).
|
|
310
|
+
* 2. Escalate. SIGINT first, because an agent CLI flushes its session
|
|
311
|
+
* file on it; SIGKILL KILL_ESCALATE_MS later for anything still there.
|
|
312
|
+
* A CLI is entitled to treat SIGINT as "interrupt the current input"
|
|
313
|
+
* rather than "exit" — being polite once and never following up is how
|
|
314
|
+
* a stop button turns into a suggestion.
|
|
315
|
+
*
|
|
316
|
+
* The escalation re-walks the tree: a process that ignored SIGINT may have
|
|
317
|
+
* forked since. The timer is unref'd so it never holds the daemon open.
|
|
252
318
|
*/
|
|
253
319
|
function killProcessTree(proc) {
|
|
254
320
|
if (exports.IS_WINDOWS && proc.pid) {
|
|
@@ -261,10 +327,33 @@ function killProcessTree(proc) {
|
|
|
261
327
|
}
|
|
262
328
|
catch { /* fall through to plain kill */ }
|
|
263
329
|
}
|
|
264
|
-
|
|
265
|
-
|
|
330
|
+
const pid = proc.pid;
|
|
331
|
+
// Already reaped: the pid is no longer ours and could belong to something
|
|
332
|
+
// else by now. proc.kill() is safe (Node no-ops it); process.kill() is not.
|
|
333
|
+
if (!pid || proc.exitCode !== null && proc.exitCode !== undefined
|
|
334
|
+
|| proc.signalCode !== null && proc.signalCode !== undefined) {
|
|
335
|
+
try {
|
|
336
|
+
proc.kill('SIGINT');
|
|
337
|
+
}
|
|
338
|
+
catch { /* already gone */ }
|
|
339
|
+
return;
|
|
266
340
|
}
|
|
267
|
-
|
|
341
|
+
const signalTree = (signal) => {
|
|
342
|
+
// Deepest first: a parent that is about to die cannot usefully re-fork,
|
|
343
|
+
// but a live parent handed the signal first might.
|
|
344
|
+
for (const child of posixDescendants(pid).reverse()) {
|
|
345
|
+
try {
|
|
346
|
+
process.kill(child, signal);
|
|
347
|
+
}
|
|
348
|
+
catch { /* gone already */ }
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
proc.kill(signal);
|
|
352
|
+
}
|
|
353
|
+
catch { /* already gone */ }
|
|
354
|
+
};
|
|
355
|
+
signalTree('SIGINT');
|
|
356
|
+
setTimeout(() => signalTree('SIGKILL'), KILL_ESCALATE_MS).unref();
|
|
268
357
|
}
|
|
269
358
|
/**
|
|
270
359
|
* Rewrite a stdio MCP server command for the platform. On native Windows,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@addai/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Daemon that pairs a machine with your +Ai account and runs Claude / Codex / Kimi / Gemini agents on its behalf. Reachable via Supabase from Vault, Entity Studio, or any other +Ai surface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|