🔧 代码审查修复: Registry状态更新走模块自身方法+HLDP队列大小限制+NOT EXISTS优化

Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/e6744e69-7bd7-44fd-afcd-cc69135c95aa

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-08 11:00:48 +00:00 committed by GitHub
parent 13e033590d
commit 71912809eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -41,6 +41,7 @@ class HLDPBus {
// ─── 消息队列(内存) ───
this._queues = new Map(); // moduleId → [messages]
this._handlers = new Map(); // msgType → [handler]
this._maxQueueSize = 1000; // 每个模块最多1000条待处理消息
// ─── 广播订阅 ───
this._subscribers = new Map(); // topic → Set(moduleId)
@ -82,7 +83,15 @@ class HLDPBus {
if (!this._queues.has(toModule)) {
this._queues.set(toModule, []);
}
this._queues.get(toModule).push(message);
const queue = this._queues.get(toModule);
// 队列大小限制:丢弃最旧的消息
if (queue.length >= this._maxQueueSize) {
queue.shift();
this.stats.totalFailed++;
}
queue.push(message);
// 持久化
await this._persistMessage(message);

View File

@ -193,9 +193,8 @@ class ModuleRegistry {
const sinceLastHeart = now - module.lastHeartbeatAt.getTime();
if (sinceLastHeart > this._heartbeatTimeoutMs && module.status === 'alive') {
console.warn(`[Registry] ${moduleId} 心跳超时 ${Math.round(sinceLastHeart / 1000)}`);
module.status = 'degraded';
// 尝试触发自诊断
// 通过模块自身的诊断方法更新状态
try {
await module.selfDiagnose();
} catch (err) {

View File

@ -98,7 +98,7 @@ class LivingSyScan extends LivingModule {
// 尝试清理空目录
try {
await db.query(
"UPDATE brain_nodes SET status = 'archived' WHERE node_type = 'folder' AND status = 'active' AND id NOT IN (SELECT DISTINCT parent_id FROM brain_nodes WHERE parent_id IS NOT NULL AND status = 'active')"
"UPDATE brain_nodes bn SET status = 'archived' WHERE bn.node_type = 'folder' AND bn.status = 'active' AND NOT EXISTS (SELECT 1 FROM brain_nodes child WHERE child.parent_id = bn.id AND child.status = 'active')"
);
return { action: 'empty_folders_archived', success: true };
} catch (err) {