Files
goodbuddy/src/main/assistant/supervision-model-pool.ts
T
mesalogo db5e43d7d5 fix: complete supervisor review coverage and execution workflow
Replace truncated review input with paged, resumable batches and retain extracted facts and source references through navigation summaries. Expose concurrency, timeouts, batch budgets and response capacity in supervisor settings.

Separate automatic supervision from review results, activity and settings; use a standard plan modal and show execution stages with saved batch details. Fix historical entity identity mapping, navigation output validation and arbitrary summary length failures.

Include focused regressions, isolated real-data validation scripts and updated design and verification records. Overall layout acceptance remains outstanding; this commit does not claim that all visual issues are resolved.

Release note: 监督回顾支持完整分页、分批保存和暂停后继续,可配置并发、超时及响应容量;修复实体引用、汇总校验和长摘要报错,并重新组织自动监督与活动记录入口。
2026-09-25 22:32:43 +08:00

84 lines
2.6 KiB
TypeScript

import { defaultSupervisorModelConcurrency } from '../../shared/application-settings-contracts'
export type SupervisionModelSlot = { signal: AbortSignal; release: () => void }
export class SupervisionModelPool {
private limit = defaultSupervisorModelConcurrency
private active = 0
private readonly controllers = new Set<AbortController>()
private readonly queue: Array<() => void> = []
private disposed = false
setLimit(limit: number): void {
this.limit = limit
this.dispatch()
}
private dispatch(): void {
while (this.active < this.limit && this.queue.length) this.queue.shift()!()
}
cancelAll(reason: Error): void {
for (const controller of this.controllers) controller.abort(reason)
}
dispose(): void {
this.disposed = true
this.cancelAll(new Error('Supervision is shutting down'))
}
async run<T>(operation: (signal: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<T> {
const slot = await this.acquire(signal)
try {
slot.signal.throwIfAborted()
return await operation(slot.signal)
} finally {
slot.release()
}
}
async acquire(signal?: AbortSignal): Promise<SupervisionModelSlot> {
if (this.disposed) throw new Error('Supervision is shutting down')
signal?.throwIfAborted()
const controller = new AbortController()
const cancel = () => controller.abort(signal?.reason)
signal?.addEventListener('abort', cancel, { once: true })
this.controllers.add(controller)
let acquired = false
try {
await new Promise<void>((resolve, reject) => {
const admit = (): void => {
controller.signal.removeEventListener('abort', abort)
this.active++
acquired = true
resolve()
}
const abort = (): void => {
const index = this.queue.indexOf(admit)
if (index >= 0) this.queue.splice(index, 1)
reject(controller.signal.reason)
}
controller.signal.addEventListener('abort', abort, { once: true })
this.queue.push(admit)
this.dispatch()
})
controller.signal.throwIfAborted()
let released = false
return { signal: controller.signal, release: () => {
if (released) return
released = true
this.controllers.delete(controller)
signal?.removeEventListener('abort', cancel)
this.active--
this.dispatch()
} }
} catch (error) {
this.controllers.delete(controller)
signal?.removeEventListener('abort', cancel)
if (acquired) this.active--
this.dispatch()
throw error
}
}
}