feat: connect controlled engines to owned Tasks, approvals and budget ledger

This commit is contained in:
Agent Workbench Dev
2026-10-31 05:04:55 +08:00
parent a01c41811b
commit f0eecbda47
27 changed files with 1653 additions and 33 deletions
+26 -2
View File
@@ -10,6 +10,7 @@ import { ACTIVE_STATES, CORE_KINDS, createTask, createRun, ownedRecord, emptyUsa
import { WORKSPACE_ACTIVE, projectWorkspaceIdentity, assertWorkspacePath } from '../shared/contracts/workspaces.mjs';
import { RESEARCH_ACTIVE } from '../shared/contracts/research.mjs';
import { ENGINE_ACTIVE, publicEngineJob } from '../shared/contracts/engines.mjs';
import { ENGINE_RUN_ACTIVE, publicEngineRun, verifyEngineModelInput } from '../shared/contracts/engine-execution.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';
@@ -192,7 +193,7 @@ export class Store extends EventEmitter {
step.status = 'interrupted'; step.finishedAt = now(); changed = true;
}
for (const plan of this.core.context_plan.values()) if (plan.sessionId === session.id) {
if (plan.workerDispatchedAt && !plan.workerUsageAccounted) {
if (plan.workerDispatchedAt && !plan.workerUsageAccounted && !plan.engineStepOnly) {
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));
@@ -252,6 +253,28 @@ export class Store extends EventEmitter {
worker.summary = '子执行在宿主中断时没有完整收尾;原进程结束及实际修改待核对,不按历史PID停止进程或重放工具。';
session.status = 'paused'; session.recoveryNotice = worker.summary; changed = true;
}
for (const job of this.core.engine_run.values()) if (job.sessionId === session.id && ENGINE_RUN_ACTIVE.has(job.status)) {
for (const request of job.requests) if (request.dispatchedAt && !request.finishedAt) {
const run = this.core.run.get(job.runId);
try {
verifyEngineModelInput(this, session, job, request);
const count = request.actualAttemptsFinal ?? request.maxAttempts;
if (run) while (request.accountedAttempts < count) {
request.accountedAttempts++; this.recordResponse(session, run, null, request.reservedPerAttempt);
request.recoveredUnknownAttempts = (request.recoveredUnknownAttempts ?? 0) + 1;
}
} catch (error) {
request.verificationError = error.message;
if (run) this.recordResponse(session, run, null, Math.max(0, this.core.task.get(job.taskId).budget.maxTokens - accountedTokens(this.core.task.get(job.taskId).usage)));
request.recoveryConservativeCharge = true;
}
request.status = 'interrupted'; request.finishedAt = now();
request.error = '宿主中断,原模型结果未完整封存;按原尝试预算核对,不自动请求。';
}
job.status = 'unknown'; job.requiresVerification = true; job.verified = false; job.finishedAt = now();
job.error = '受控引擎宿主中断,原工具/模型结果及进程树待核对。原输入保留,不按历史PID终止或重放。';
session.status = 'paused'; session.recoveryNotice = job.error; changed = true;
}
for (const job of this.core.engine_job.values()) if (job.sessionId === session.id && ENGINE_ACTIVE.has(job.status)) {
job.status = 'unknown'; job.requiresVerification = true; job.verification = null; job.finishedAt = now();
job.summary = '外部引擎连接检查中断,原进程关闭状态未知。不会根据历史PID停止进程或重放请求,请查看所属原记录。';
@@ -307,7 +330,7 @@ export class Store extends EventEmitter {
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)))
|| ['tool', 'check_job', 'change_set', 'engine_run'].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();
@@ -584,6 +607,7 @@ export class Store extends EventEmitter {
researchTargets: [...this.core.research_target.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-32),
researchJobs: [...this.core.research_job.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification)).slice(-20),
engineJobs: [...this.core.engine_job.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification)).slice(-20).map(publicEngineJob),
engineRuns: [...this.core.engine_run.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification)).slice(-20).map(publicEngineRun),
browserPlans: [...this.core.browser_plan.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-5).map(publicBrowserPlan),
browserJobs: [...this.core.browser_job.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification)).slice(-12),
contextPlans: [...this.core.context_plan.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-30),