feat: seal isolated worker recovery, parent integration and review console

This commit is contained in:
Agent Workbench Dev
2026-10-31 02:02:06 +08:00
parent 3abc0e8595
commit 2ada7b899f
34 changed files with 2877 additions and 64 deletions
+28 -3
View File
@@ -13,7 +13,7 @@ import { ENGINE_ACTIVE, publicEngineJob } from '../shared/contracts/engines.mjs'
import { BROWSER_ACTIVE } from '../shared/contracts/browser.mjs';
import { publicBrowserPlan } from '../core/browser/browser-manager.mjs';
import { MCP_ACTIVE } from '../core/tools/mcp-contract.mjs';
import { COLLABORATION_ACTIVE } from '../shared/contracts/workers.mjs';
import { COLLABORATION_ACTIVE, COLLABORATION_CLOSED } from '../shared/contracts/workers.mjs';
export const now = () => new Date().toISOString();
@@ -191,8 +191,17 @@ export class Store extends EventEmitter {
for (const step of this.core.step.values()) if (step.sessionId === session.id && ['running', 'waiting'].includes(step.status)) {
step.status = 'interrupted'; step.finishedAt = now(); changed = true;
}
for (const plan of this.core.context_plan.values()) if (plan.sessionId === session.id && ['prepared', 'requesting'].includes(plan.status)) {
plan.status = 'interrupted'; plan.finishedAt = now(); plan.error = '进程中断,未保存完整模型响应;不自动发送请求或重放工具。'; changed = true;
for (const plan of this.core.context_plan.values()) if (plan.sessionId === session.id) {
if (plan.workerDispatchedAt && !plan.workerUsageAccounted) {
const run = this.core.run.get(plan.runId);
if (run && this.core.task.get(run.taskId)?.workerId) {
this.recordResponse(session, run, null, plan.estimatedInputTokens + (run.model.maxOutputTokens ?? 2048));
plan.workerUsageAccounted = true; plan.workerUsageRecovered = true; changed = true;
}
}
if (['prepared', 'requesting'].includes(plan.status)) {
plan.status = 'interrupted'; plan.finishedAt = now(); plan.error = '进程中断,未保存完整模型响应;不自动发送请求或重放工具。'; changed = true;
}
}
for (const job of this.core.check_job.values()) if (job.sessionId === session.id && ['queued', 'running', 'waiting'].includes(job.status)) {
job.requiresVerification = job.status !== 'queued'; job.status = job.requiresVerification ? 'unknown' : 'interrupted'; job.finishedAt = now();
@@ -295,6 +304,18 @@ export class Store extends EventEmitter {
}
if (changed) this.save(session, { type: 'session.recovered' });
}
for (const group of this.core.collaboration.values()) {
const unresolved = group.children.some(child => this.core.worker.get(child.id)?.requiresVerification
|| this.core.workspace.get(child.workspaceId)?.requiresVerification
|| ['tool', 'check_job', 'change_set'].some(kind => [...this.core[kind].values()].some(record => record.taskId === child.taskId && record.requiresVerification)))
|| [...this.core.change_set.values()].some(set => set.taskId === group.taskId && set.requiresVerification);
if (!COLLABORATION_CLOSED.has(group.status) && unresolved && (!group.requiresVerification || group.status !== 'unknown')) {
group.status = 'unknown'; group.requiresVerification = true; group.finishedAt = now();
group.summary = '所属子执行或父批次仍有未知结果,原协作需要核对;不自动重放。';
const session = this.session(group.sessionId); session.status = 'paused'; session.recoveryNotice = group.summary;
this.save(session, { type: 'collaboration.recovered_children' });
}
}
}
save(session, { type = 'session.updated', detail = {} } = {}) {
@@ -507,6 +528,10 @@ export class Store extends EventEmitter {
savedToolResult(sessionId, callId) {
const record = [...this.core.tool.values()].find(value => value.sessionId === sessionId && value.callId === callId);
if (record?.state === 'resolved_external' && record.review?.result === 'unknown-preserved') return {
status: 'unknown', requires_verification: false, invocation_id: record.id, evidence_sha256: record.review.evidenceSha256,
message: '原结果保持未知,用户已核对原输入与现场;此调用不会重放,重新检查须使用新计划与审批。',
};
if (!record || !['completed', 'failed', 'denied', 'interrupted', 'unknown'].includes(record.state)) return null;
if (record.resultArtifactId) {
try { return JSON.parse(this.artifactStore.read(this.core.artifact.get(record.resultArtifactId))); }