fix: seal pause inputs before publishing a terminal run state

This commit is contained in:
Agent Workbench Dev
2026-11-01 13:41:32 +08:00
parent 3f1c026195
commit 0efc3450d2
3 changed files with 31 additions and 5 deletions
+9 -5
View File
@@ -207,12 +207,9 @@ export class Runtime {
session.failure = null;
this.store.save(session);
const deadline = record.budget.maxDurationMs > 0 ? setTimeout(() => controller.abort(new BudgetExceeded('time_limit', '已到达本次运行的时间预算,执行记录已保存。')), record.budget.maxDurationMs) : null;
run.promise = this.run(session, config, run).finally(async () => {
run.promise = this.run(session, config, run).finally(() => {
clearTimeout(deadline);
try {
if (!run.worker && record.purpose !== 'diagnostic' && ['no_progress', 'step_limit'].includes(run.stopReason)) {
try { record.finalSourceFingerprint = (await inspectProject(project)).sourceFingerprint; } catch { /* No fingerprint means no claim of unchanged inputs. */ }
}
const status = session.status;
if (record.purpose === 'diagnostic') session.status = record.taskStatusBefore;
this.store.finishRun(session, record, run.stopReason ?? null, { status });
@@ -221,6 +218,11 @@ export class Runtime {
run.promise.catch(() => {});
return session;
}
async capturePauseInputs(run) {
if (!run.worker && run.record.purpose !== 'diagnostic' && ['no_progress', 'step_limit'].includes(run.stopReason)) {
try { run.record.finalSourceFingerprint = (await inspectProject(run.project)).sourceFingerprint; } catch { /* No fingerprint means no claim of unchanged inputs. */ }
}
}
resume(id, content) {
const session = this.store.session(id);
if (content) return this.start(id, content);
@@ -446,8 +448,9 @@ export class Runtime {
if (this.store.core.task.get(run.taskId).readProgress?.pause) throw new BudgetExceeded('no_progress',
'模型连续重复读取工件或核对相同的工程状态,未推进当前任务。实际结果和原任务已保存,请核对后继续。');
}
session.status = 'paused';
run.stopReason = 'step_limit';
await this.capturePauseInputs(run);
session.status = 'paused';
this.store.message(session, 'assistant', '已到达本次工具步数上限。执行记录已保存,可以查看结果后继续。');
this.store.save(session);
} catch (error) {
@@ -464,6 +467,7 @@ export class Runtime {
for (const event of session.events.filter(item => item.kind === 'model' && item.runId === run.id && ['running', 'retrying'].includes(item.phase))) {
event.phase = 'interrupted'; event.finishedAt = now(); event.output = '模型请求已停止,已完成的工具结果保留。';
}
await this.capturePauseInputs(run);
session.status = 'paused';
this.store.message(session, 'system', budget?.message ?? '任务已停止,执行记录已保存。');
} else {