@link-assistant/hive-mind 2.1.5 → 2.1.6
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/config.lib.mjs +3 -2
- package/src/isolation-runner.lib.mjs +13 -1
- package/src/limits.lib.mjs +2 -2
- package/src/locales/en.lino +1 -0
- package/src/locales/hi.lino +1 -0
- package/src/locales/ru.lino +1 -0
- package/src/locales/zh.lino +1 -0
- package/src/queue-config.lib.mjs +6 -3
- package/src/session-monitor.lib.mjs +70 -1
- package/src/telegram-solve-queue.lib.mjs +11 -9
- package/src/work-session-formatting.lib.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @link-assistant/hive-mind
|
|
2
2
|
|
|
3
|
+
## 2.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- efcbcce: Handle Docker `oomKilled` status markers as terminal Telegram work-session failures, delay Docker backend-gone killed notifications long enough for start-command to publish a real terminal status or log footer, pace queued task startups at a minimum 10-minute interval, and cap system resource cache freshness at 1 minute.
|
|
8
|
+
|
|
3
9
|
## 2.1.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
package/src/config.lib.mjs
CHANGED
|
@@ -687,8 +687,9 @@ export const cacheTtl = {
|
|
|
687
687
|
// because users still hit "Resets in 3m xs" rate-limit responses. The API
|
|
688
688
|
// returns null values or 429 when called too frequently.
|
|
689
689
|
usageApi: parseIntWithDefault('HIVE_MIND_USAGE_API_CACHE_TTL_MS', 13 * 60 * 1000), // 13 minutes
|
|
690
|
-
// System metrics cache TTL (RAM, CPU, disk)
|
|
691
|
-
|
|
690
|
+
// System metrics cache TTL (RAM, CPU, disk). Issue #2015 caps this at
|
|
691
|
+
// 1 minute so queue decisions do not use stale host pressure data.
|
|
692
|
+
system: Math.min(parseIntWithDefault('HIVE_MIND_SYSTEM_CACHE_TTL_MS', 60 * 1000), 60 * 1000), // max 1 minute
|
|
692
693
|
};
|
|
693
694
|
|
|
694
695
|
// File and path configurations
|
|
@@ -321,9 +321,18 @@ export function generateSessionId() {
|
|
|
321
321
|
export function parseSessionStatusOutput(output) {
|
|
322
322
|
const raw = (output || '').trim();
|
|
323
323
|
if (!raw) {
|
|
324
|
-
return { exists: false, uuid: null, status: null, exitCode: null, startTime: null, endTime: null, currentTime: null, logPath: null, command: null, isolation: null, workingDirectory: null, sessionName: null, processIds: {}, raw: '' };
|
|
324
|
+
return { exists: false, uuid: null, status: null, exitCode: null, startTime: null, endTime: null, currentTime: null, logPath: null, command: null, isolation: null, workingDirectory: null, sessionName: null, processIds: {}, oomKilled: null, raw: '' };
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
const normalizeBooleanField = value => {
|
|
328
|
+
if (typeof value === 'boolean') return value;
|
|
329
|
+
if (value === null || value === undefined) return null;
|
|
330
|
+
const normalized = String(value).trim().toLowerCase();
|
|
331
|
+
if (['true', '1', 'yes'].includes(normalized)) return true;
|
|
332
|
+
if (['false', '0', 'no'].includes(normalized)) return false;
|
|
333
|
+
return null;
|
|
334
|
+
};
|
|
335
|
+
|
|
327
336
|
try {
|
|
328
337
|
const parsed = JSON.parse(raw);
|
|
329
338
|
const data = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
@@ -350,6 +359,7 @@ export function parseSessionStatusOutput(output) {
|
|
|
350
359
|
workingDirectory: data?.workingDirectory || null,
|
|
351
360
|
sessionName: data?.sessionName || data?.options?.sessionName || null,
|
|
352
361
|
processIds,
|
|
362
|
+
oomKilled: normalizeBooleanField(data?.oomKilled ?? data?.OOMKilled ?? data?.options?.oomKilled ?? data?.state?.oomKilled ?? data?.State?.OOMKilled),
|
|
353
363
|
raw,
|
|
354
364
|
};
|
|
355
365
|
} catch {
|
|
@@ -365,6 +375,7 @@ export function parseSessionStatusOutput(output) {
|
|
|
365
375
|
const match = raw.match(new RegExp(`^\\s*${name}\\s+"?([^"\\n]+)"?\\s*$`, 'mi'));
|
|
366
376
|
return match ? match[1].trim() : null;
|
|
367
377
|
};
|
|
378
|
+
const readBooleanField = name => normalizeBooleanField(readField(name));
|
|
368
379
|
|
|
369
380
|
const status = readField('status')?.toLowerCase() || null;
|
|
370
381
|
const exitCodeText = readField('exitCode');
|
|
@@ -396,6 +407,7 @@ export function parseSessionStatusOutput(output) {
|
|
|
396
407
|
workingDirectory: readField('workingDirectory'),
|
|
397
408
|
sessionName: readField('sessionName'),
|
|
398
409
|
processIds,
|
|
410
|
+
oomKilled: readBooleanField('oomKilled'),
|
|
399
411
|
raw,
|
|
400
412
|
};
|
|
401
413
|
}
|
package/src/limits.lib.mjs
CHANGED
|
@@ -1239,12 +1239,12 @@ export function formatCodexLimitsSection(codexLimits, codexError = null, options
|
|
|
1239
1239
|
* Configurable via environment variables:
|
|
1240
1240
|
* - HIVE_MIND_API_CACHE_TTL_MS: General API cache TTL (default: 180000 = 3 minutes)
|
|
1241
1241
|
* - HIVE_MIND_USAGE_API_CACHE_TTL_MS: Claude Usage API cache TTL (default: 780000 = 13 minutes)
|
|
1242
|
-
* - HIVE_MIND_SYSTEM_CACHE_TTL_MS: System metrics cache TTL (default:
|
|
1242
|
+
* - HIVE_MIND_SYSTEM_CACHE_TTL_MS: System metrics cache TTL (default: 60000 = 1 minute, capped at 1 minute)
|
|
1243
1243
|
*/
|
|
1244
1244
|
export const CACHE_TTL = {
|
|
1245
1245
|
API: cacheTtl.api, // 3 minutes for regular API calls (GitHub)
|
|
1246
1246
|
USAGE_API: cacheTtl.usageApi, // 13 minutes for Claude Usage API (rate limited)
|
|
1247
|
-
SYSTEM: cacheTtl.system, //
|
|
1247
|
+
SYSTEM: cacheTtl.system, // max 1 minute for system metrics (RAM, CPU, disk)
|
|
1248
1248
|
};
|
|
1249
1249
|
|
|
1250
1250
|
/**
|
package/src/locales/en.lino
CHANGED
package/src/locales/hi.lino
CHANGED
package/src/locales/ru.lino
CHANGED
|
@@ -623,6 +623,7 @@ ru
|
|
|
623
623
|
executing "⏳ Выполняется..."
|
|
624
624
|
finished "Рабочий сеанс успешно завершен"
|
|
625
625
|
failed "Рабочий сеанс завершился с ошибкой (код выхода: {{exitCode}})"
|
|
626
|
+
killed "Рабочий сеанс остановлен: {{reason}}{{exitSuffix}}"
|
|
626
627
|
duration
|
|
627
628
|
label "Длительность"
|
|
628
629
|
session
|
package/src/locales/zh.lino
CHANGED
package/src/queue-config.lib.mjs
CHANGED
|
@@ -192,6 +192,8 @@ const parseIntWithDefault = (envVar, defaultValue) => {
|
|
|
192
192
|
return isNaN(parsed) ? defaultValue : parsed;
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
const MINIMUM_START_INTERVAL_MS = 10 * 60 * 1000;
|
|
196
|
+
|
|
195
197
|
// Parse links notation config from environment variable (if provided)
|
|
196
198
|
const linoConfig = parseQueueConfig(getenv('HIVE_MIND_QUEUE_CONFIG', ''));
|
|
197
199
|
|
|
@@ -271,9 +273,10 @@ export const QUEUE_CONFIG = {
|
|
|
271
273
|
GITHUB_API_THRESHOLD: getThresholdConfig('githubApi', 'HIVE_MIND_GITHUB_API_THRESHOLD', 'HIVE_MIND_GITHUB_API_STRATEGY', 0.5, 'enqueue').value,
|
|
272
274
|
|
|
273
275
|
// Timing
|
|
274
|
-
// MIN_START_INTERVAL_MS:
|
|
275
|
-
//
|
|
276
|
-
|
|
276
|
+
// MIN_START_INTERVAL_MS: Minimum global spacing between task startups.
|
|
277
|
+
// Issue #2015: after resource thresholds clear, starting a backlog in a burst
|
|
278
|
+
// can kill the next batch before host metrics have time to settle.
|
|
279
|
+
MIN_START_INTERVAL_MS: Math.max(parseIntWithDefault('HIVE_MIND_MIN_START_INTERVAL_MS', MINIMUM_START_INTERVAL_MS), MINIMUM_START_INTERVAL_MS), // at least 10 minutes between starts
|
|
277
280
|
CONSUMER_POLL_INTERVAL_MS: parseIntWithDefault('HIVE_MIND_CONSUMER_POLL_INTERVAL_MS', 60000), // 1 minute between queue checks
|
|
278
281
|
MESSAGE_UPDATE_INTERVAL_MS: parseIntWithDefault('HIVE_MIND_MESSAGE_UPDATE_INTERVAL_MS', 60000), // 1 minute between status message updates
|
|
279
282
|
|
|
@@ -24,7 +24,7 @@ import fs from 'fs/promises';
|
|
|
24
24
|
import { promisify } from 'util';
|
|
25
25
|
import { formatSessionCompletionMessage, getSessionCompletionExitCode, classifySessionOutcome } from './work-session-formatting.lib.mjs';
|
|
26
26
|
import { notifySubscribers, getSubscriberCount } from './telegram-subscribers.lib.mjs';
|
|
27
|
-
import { classifyExitStatus } from './session-status.lib.mjs';
|
|
27
|
+
import { classifyExitStatus, normalizeExitCode } from './session-status.lib.mjs';
|
|
28
28
|
import path from 'node:path';
|
|
29
29
|
import { readLastSessionIdFromLog, findLatestSessionLogId, buildResumeCommand, formatResumeSection } from './session-resume.lib.mjs';
|
|
30
30
|
|
|
@@ -504,6 +504,8 @@ function isNonIsolationSessionActive(sessionName, sessionInfo, verbose = false)
|
|
|
504
504
|
* this, because a written "Exit Code:" footer is proof the command terminated.
|
|
505
505
|
*/
|
|
506
506
|
export const STALE_EXECUTING_MIN_AGE_MS = 90 * 1000;
|
|
507
|
+
export const DOCKER_BACKEND_GONE_GRACE_MS = 2 * 60 * 1000;
|
|
508
|
+
const DOCKER_BACKEND_GONE_FIRST_SEEN_FIELD = 'dockerBackendGoneFirstSeenAt';
|
|
507
509
|
|
|
508
510
|
function sessionStartMs(sessionInfo) {
|
|
509
511
|
const start = sessionInfo?.startTime;
|
|
@@ -513,6 +515,23 @@ function sessionStartMs(sessionInfo) {
|
|
|
513
515
|
return Number.isFinite(ms) ? ms : null;
|
|
514
516
|
}
|
|
515
517
|
|
|
518
|
+
function isDockerIsolation(sessionInfo, statusResult) {
|
|
519
|
+
return sessionInfo?.isolationBackend === 'docker' || statusResult?.isolation === 'docker';
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function getDockerBackendGoneFirstSeenMs(sessionInfo) {
|
|
523
|
+
const raw = sessionInfo?.[DOCKER_BACKEND_GONE_FIRST_SEEN_FIELD];
|
|
524
|
+
if (!raw) return null;
|
|
525
|
+
const ms = new Date(raw).getTime();
|
|
526
|
+
return Number.isFinite(ms) ? ms : null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function clearDockerBackendGoneMarker(sessionName, sessionInfo) {
|
|
530
|
+
if (!sessionInfo?.[DOCKER_BACKEND_GONE_FIRST_SEEN_FIELD]) return;
|
|
531
|
+
delete sessionInfo[DOCKER_BACKEND_GONE_FIRST_SEEN_FIELD];
|
|
532
|
+
persistSessionSnapshot(sessionName, sessionInfo);
|
|
533
|
+
}
|
|
534
|
+
|
|
516
535
|
/**
|
|
517
536
|
* Cross-check whether a session that `$ --status` still reports as `executing`
|
|
518
537
|
* has actually terminated. Issue #1927: start-command's status can get stuck on
|
|
@@ -552,13 +571,60 @@ async function resolveStaleExecutingState(sessionName, sessionInfo, statusResult
|
|
|
552
571
|
// Only `false` (definitively gone) counts as killed; `null` (unknown backend)
|
|
553
572
|
// is treated as "no signal" so we don't kill on an indeterminate probe.
|
|
554
573
|
if (alive === false) {
|
|
574
|
+
if (isDockerIsolation(sessionInfo, statusResult)) {
|
|
575
|
+
const nowMs = Date.now();
|
|
576
|
+
const firstSeenMs = getDockerBackendGoneFirstSeenMs(sessionInfo);
|
|
577
|
+
if (firstSeenMs === null) {
|
|
578
|
+
sessionInfo[DOCKER_BACKEND_GONE_FIRST_SEEN_FIELD] = new Date(nowMs).toISOString();
|
|
579
|
+
persistSessionSnapshot(sessionName, sessionInfo);
|
|
580
|
+
if (verbose) {
|
|
581
|
+
console.log(`[VERBOSE] Session ${sessionName} docker backend is gone but no terminal status/footer is available yet; deferring killed classification for ${DOCKER_BACKEND_GONE_GRACE_MS}ms`);
|
|
582
|
+
}
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
if (nowMs - firstSeenMs < DOCKER_BACKEND_GONE_GRACE_MS) {
|
|
586
|
+
if (verbose) {
|
|
587
|
+
console.log(`[VERBOSE] Session ${sessionName} docker backend is still gone; waiting for terminal status/footer before reporting killed`);
|
|
588
|
+
}
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
555
592
|
return { exitCode: null, status: 'killed', reason: 'backend-gone' };
|
|
556
593
|
}
|
|
594
|
+
if (alive === true) {
|
|
595
|
+
clearDockerBackendGoneMarker(sessionName, sessionInfo);
|
|
596
|
+
}
|
|
557
597
|
}
|
|
558
598
|
|
|
559
599
|
return null;
|
|
560
600
|
}
|
|
561
601
|
|
|
602
|
+
function resolveOomKilledState(sessionName, sessionInfo, statusResult, { verbose, runner, exitFromLog }) {
|
|
603
|
+
const logPath = statusResult?.logPath || sessionInfo?.logPath || null;
|
|
604
|
+
let footer = null;
|
|
605
|
+
if (logPath) {
|
|
606
|
+
const readFooter = exitFromLog || runner.readSessionExitFromLog;
|
|
607
|
+
footer = readFooter ? readFooter(logPath, { verbose }) : null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const statusExitCode = normalizeExitCode(statusResult?.exitCode);
|
|
611
|
+
const footerExitCode = footer?.finished ? normalizeExitCode(footer.exitCode) : null;
|
|
612
|
+
let exitCode = 137;
|
|
613
|
+
if (statusExitCode !== null && statusExitCode > 0) {
|
|
614
|
+
exitCode = statusExitCode;
|
|
615
|
+
} else if (footerExitCode !== null && footerExitCode > 0) {
|
|
616
|
+
exitCode = footerExitCode;
|
|
617
|
+
}
|
|
618
|
+
const endTime = statusResult?.endTime || footer?.endTime || statusResult?.currentTime || null;
|
|
619
|
+
const corrected = { ...statusResult, status: 'oom-killed', exitCode, endTime };
|
|
620
|
+
|
|
621
|
+
if (verbose) {
|
|
622
|
+
console.log(`[VERBOSE] Session ${sessionName} status includes oomKilled=true; treating it as terminal oom-killed (exit ${exitCode})`);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return { running: false, exitCode, status: 'oom-killed', statusResult: corrected, stale: true };
|
|
626
|
+
}
|
|
627
|
+
|
|
562
628
|
async function getIsolationSessionState(sessionName, sessionInfo, options = {}) {
|
|
563
629
|
const { verbose = false, statusProvider = null, exitFromLog = null, backendAlive = null, sessionRunning = null } = options;
|
|
564
630
|
const sessionId = sessionInfo.sessionId || sessionName;
|
|
@@ -568,6 +634,9 @@ async function getIsolationSessionState(sessionName, sessionInfo, options = {})
|
|
|
568
634
|
const statusResult = statusProvider ? await statusProvider(sessionId, sessionInfo) : await runner.querySessionStatus(sessionId, verbose);
|
|
569
635
|
|
|
570
636
|
if (statusResult?.exists && statusResult.status) {
|
|
637
|
+
if (statusResult.oomKilled === true) {
|
|
638
|
+
return resolveOomKilledState(sessionName, sessionInfo, statusResult, { verbose, runner, exitFromLog });
|
|
639
|
+
}
|
|
571
640
|
if (runner.isExecutingSessionStatus(statusResult.status)) {
|
|
572
641
|
// Issue #1927: an `executing` status is not trusted blindly — verify the
|
|
573
642
|
// process is really alive. start-command can keep reporting `executing`
|
|
@@ -374,9 +374,11 @@ export class SolveQueue {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
/**
|
|
377
|
-
* Find startable
|
|
378
|
-
*
|
|
379
|
-
*
|
|
377
|
+
* Find the next startable item across all tool queues.
|
|
378
|
+
* With separate queues, each tool is checked independently so tool-specific
|
|
379
|
+
* limits do not block unrelated tools. Issue #2015 adds a global startup
|
|
380
|
+
* interval, so even when multiple tools are startable this returns only the
|
|
381
|
+
* oldest startable item to prevent burst launches.
|
|
380
382
|
*
|
|
381
383
|
* Also immediately rejects all queued items when a 'reject' strategy threshold
|
|
382
384
|
* is exceeded, instead of leaving them waiting indefinitely.
|
|
@@ -417,7 +419,8 @@ export class SolveQueue {
|
|
|
417
419
|
}
|
|
418
420
|
}
|
|
419
421
|
|
|
420
|
-
|
|
422
|
+
startableItems.sort((a, b) => a.item.createdAt - b.item.createdAt);
|
|
423
|
+
return startableItems.slice(0, 1);
|
|
421
424
|
}
|
|
422
425
|
|
|
423
426
|
/**
|
|
@@ -571,10 +574,10 @@ export class SolveQueue {
|
|
|
571
574
|
let rejected = false;
|
|
572
575
|
let rejectReason = null;
|
|
573
576
|
|
|
574
|
-
// Check minimum interval since last start
|
|
575
|
-
//
|
|
576
|
-
//
|
|
577
|
-
const lastStartTime = this.
|
|
577
|
+
// Check minimum interval since the last task start globally.
|
|
578
|
+
// Issue #2015: do not let another tool queue bypass startup pacing; host
|
|
579
|
+
// CPU/RAM/disk metrics need time to settle before any next task starts.
|
|
580
|
+
const lastStartTime = this.lastStartTime || null;
|
|
578
581
|
if (lastStartTime) {
|
|
579
582
|
const timeSinceLastStart = Date.now() - lastStartTime;
|
|
580
583
|
if (timeSinceLastStart < QUEUE_CONFIG.MIN_START_INTERVAL_MS) {
|
|
@@ -765,7 +768,6 @@ export class SolveQueue {
|
|
|
765
768
|
}
|
|
766
769
|
|
|
767
770
|
// Check CPU using 5-minute load average (more stable than 1-minute)
|
|
768
|
-
// Cache TTL is 2 minutes, which is appropriate for this metric
|
|
769
771
|
const cpuResult = await getCachedCpuInfo(this.verbose);
|
|
770
772
|
if (cpuResult.success) {
|
|
771
773
|
// Use loadAvg5 (5-minute average) instead of usagePercentage (1-minute based)
|
|
@@ -145,7 +145,7 @@ export function formatSessionCompletionMessage({ sessionName, sessionInfo, statu
|
|
|
145
145
|
const showCode = finalExitCode !== null && !(!signal && finalExitCode === 1);
|
|
146
146
|
const exitSuffix = showCode ? ` (exit code: ${finalExitCode})` : '';
|
|
147
147
|
const reason = signal ? signal.reason : 'killed';
|
|
148
|
-
statusText = text(messageLocale, 'telegram.work_session_killed', `Work session ${reason}${exitSuffix}`, { reason, exitCode: finalExitCode ?? '', signal: signal?.signal ?? '' });
|
|
148
|
+
statusText = text(messageLocale, 'telegram.work_session_killed', `Work session ${reason}${exitSuffix}`, { reason, exitCode: finalExitCode ?? '', signal: signal?.signal ?? '', exitSuffix });
|
|
149
149
|
} else if (failed) {
|
|
150
150
|
statusText = text(messageLocale, 'telegram.work_session_failed', `Work session failed (exit code: ${finalExitCode})`, { exitCode: finalExitCode });
|
|
151
151
|
} else {
|