fix(runtime): separate liveness health from deep life audit

This commit is contained in:
冰朔 2026-09-13 10:35:41 +08:00
commit 306b2b1a01
7 changed files with 327 additions and 2 deletions

View file

@ -157,7 +157,9 @@ export class PersonaSelfLoop {
}
async drain() {
if (this.draining) return {status: 'BUSY'}; const lifeLine = this.lifeLineStatus(); if (this.requireLifeLine && lifeLine.wake_allowed !== true) { this.lastDrain = {status: 'LIFE_LINE_BLOCKED', at: this.now().toISOString(), life_line_state: lifeLine.state}; return this.lastDrain; }
if (this.draining) return {status: 'BUSY'};
if (this.pendingJobs.size === 0) return this.lastDrain = {status:'DRAINED',at:this.now().toISOString(),processed:0,duration_ms:0};
const lifeLine = this.lifeLineStatus(); if (this.requireLifeLine && lifeLine.wake_allowed !== true) { this.lastDrain = {status: 'LIFE_LINE_BLOCKED', at: this.now().toISOString(), life_line_state: lifeLine.state}; return this.lastDrain; }
this.draining = true; const started = Date.now(); let processed = 0;
try { while (processed < this.queueBatchSize && Date.now() - started < this.drainBudgetMs) { const entry = this.nextPending(); if (!entry) break; await this.process(entry.id); processed += 1; } this.lastDrain = {status: 'DRAINED', at: this.now().toISOString(), processed, duration_ms: Date.now() - started}; return this.lastDrain; }
finally { this.draining = false; }