@teamvibe/poller 0.1.54 → 0.1.55
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/config.js +1 -1
- package/dist/heartbeat-manager.d.ts +1 -1
- package/dist/heartbeat-manager.js +30 -1
- package/dist/maintenance-reporter.js +9 -0
- package/dist/poller.js +1 -1
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -40,7 +40,7 @@ const configSchema = z.object({
|
|
|
40
40
|
.transform((v) => v.toLowerCase() === 'true'),
|
|
41
41
|
BRAIN_UPDATE_COOLDOWN_MS: z.coerce.number().default(300000), // 5 minutes
|
|
42
42
|
// Maintenance heartbeat
|
|
43
|
-
MAINTENANCE_INTERVAL_MS: z.coerce.number().default(
|
|
43
|
+
MAINTENANCE_INTERVAL_MS: z.coerce.number().default(86400000), // 24 hours between maintenance per brain
|
|
44
44
|
MAINTENANCE_CHECK_INTERVAL_MS: z.coerce.number().default(300000), // 5 min check loop
|
|
45
45
|
MAINTENANCE_ENABLED: z.string().default('true').transform((v) => v.toLowerCase() === 'true'),
|
|
46
46
|
});
|
|
@@ -3,7 +3,7 @@ import type { TeamVibeQueueMessage } from './types.js';
|
|
|
3
3
|
* Register a brain from a real message so we know about it for heartbeats.
|
|
4
4
|
* Called from processMessage() after brain path is resolved.
|
|
5
5
|
*/
|
|
6
|
-
export declare function registerBrain(msg: TeamVibeQueueMessage): void;
|
|
6
|
+
export declare function registerBrain(msg: TeamVibeQueueMessage, brainDir?: string): void;
|
|
7
7
|
/**
|
|
8
8
|
* Start the periodic heartbeat check loop.
|
|
9
9
|
* Checks every MAINTENANCE_CHECK_INTERVAL_MS whether any brain needs maintenance.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
1
3
|
import { config } from './config.js';
|
|
2
4
|
import { logger } from './logger.js';
|
|
3
5
|
import { isAtCapacity } from './claude-spawner.js';
|
|
@@ -7,7 +9,7 @@ let heartbeatInterval = null;
|
|
|
7
9
|
* Register a brain from a real message so we know about it for heartbeats.
|
|
8
10
|
* Called from processMessage() after brain path is resolved.
|
|
9
11
|
*/
|
|
10
|
-
export function registerBrain(msg) {
|
|
12
|
+
export function registerBrain(msg, brainDir) {
|
|
11
13
|
const brain = msg.teamvibe.brain;
|
|
12
14
|
if (!brain?.brainId)
|
|
13
15
|
return;
|
|
@@ -25,9 +27,30 @@ export function registerBrain(msg) {
|
|
|
25
27
|
botToken: msg.teamvibe.botToken,
|
|
26
28
|
channelId: msg.teamvibe.channelId,
|
|
27
29
|
lastHeartbeat: existing?.lastHeartbeat ?? 0,
|
|
30
|
+
brainDir: brainDir ?? existing?.brainDir,
|
|
28
31
|
});
|
|
29
32
|
logger.debug(`[Heartbeat] Registered brain: ${brain.brainId}`);
|
|
30
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if consolidation ran recently by reading memory/.last_consolidation.
|
|
36
|
+
* Returns true if consolidation should be skipped (ran within last 24h).
|
|
37
|
+
*/
|
|
38
|
+
function shouldSkipConsolidation(brainDir) {
|
|
39
|
+
try {
|
|
40
|
+
const filePath = join(brainDir, 'memory', '.last_consolidation');
|
|
41
|
+
if (!existsSync(filePath))
|
|
42
|
+
return false;
|
|
43
|
+
const content = readFileSync(filePath, 'utf-8').trim();
|
|
44
|
+
const lastDate = new Date(content);
|
|
45
|
+
if (isNaN(lastDate.getTime()))
|
|
46
|
+
return false;
|
|
47
|
+
const elapsedMs = Date.now() - lastDate.getTime();
|
|
48
|
+
return elapsedMs < 86_400_000; // 24 hours
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false; // lenient: allow heartbeat on any error
|
|
52
|
+
}
|
|
53
|
+
}
|
|
31
54
|
/**
|
|
32
55
|
* Start the periodic heartbeat check loop.
|
|
33
56
|
* Checks every MAINTENANCE_CHECK_INTERVAL_MS whether any brain needs maintenance.
|
|
@@ -45,6 +68,12 @@ export function startHeartbeatLoop(processMessageFn) {
|
|
|
45
68
|
if (elapsed < config.MAINTENANCE_INTERVAL_MS) {
|
|
46
69
|
continue;
|
|
47
70
|
}
|
|
71
|
+
// Skip if consolidation ran recently (code-enforced guard)
|
|
72
|
+
if (info.brainDir && shouldSkipConsolidation(info.brainDir)) {
|
|
73
|
+
logger.debug(`[Heartbeat] Skipping heartbeat for ${brainId} — last_consolidation < 24h`);
|
|
74
|
+
info.lastHeartbeat = now;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
48
77
|
if (isAtCapacity()) {
|
|
49
78
|
logger.debug(`[Heartbeat] At capacity, skipping heartbeat for ${brainId}`);
|
|
50
79
|
continue;
|
|
@@ -30,6 +30,15 @@ export async function postMaintenanceReports(brainPath, channelId) {
|
|
|
30
30
|
try {
|
|
31
31
|
const content = await readFile(filePath, 'utf-8');
|
|
32
32
|
const report = JSON.parse(content);
|
|
33
|
+
// Skip no-op reports (consolidation ran but found nothing to do)
|
|
34
|
+
if (report.operationCounts) {
|
|
35
|
+
const { created, modified, deleted } = report.operationCounts;
|
|
36
|
+
if (created === 0 && modified === 0 && deleted === 0) {
|
|
37
|
+
logger.info(`[MaintenanceReporter] Skipping no-op report ${file} (0 changes)`);
|
|
38
|
+
await unlink(filePath).catch(() => { });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
33
42
|
if (!report.operationType) {
|
|
34
43
|
logger.warn(`[MaintenanceReporter] Skipping ${file}: missing operationType`);
|
|
35
44
|
continue;
|
package/dist/poller.js
CHANGED
|
@@ -125,7 +125,7 @@ async function processMessage(received) {
|
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
127
|
// Register brain for heartbeat tracking
|
|
128
|
-
registerBrain(queueMessage);
|
|
128
|
+
registerBrain(queueMessage, kbPath);
|
|
129
129
|
// Try to acquire session lock
|
|
130
130
|
let lockResult = await acquireSessionLock(threadId, kbPath);
|
|
131
131
|
if (!lockResult.success) {
|