From 0efc3450d24ca42fef8e067f320d5fb1e9f75842 Mon Sep 17 00:00:00 2001 From: Agent Workbench Dev Date: Sun, 1 Nov 2026 13:41:32 +0800 Subject: [PATCH] fix: seal pause inputs before publishing a terminal run state --- CHANGELOG.md | 1 + src/server/runtime.mjs | 14 +++++++++----- tests/task-control.test.mjs | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb350ec7..1e64e4d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - 完整终结响应中的空参数只对schema明确允许空对象的工具兼容;必填参数、坏JSON、截断流继续整批拒绝,原流与适配凭据分别保存。 - 每次真实模型请求按尝试身份去重记账,失败响应的已报告用量不再丢失;unknown单列估算,池内切换与受控引擎避免重复累计。历史漏账不静默重写。 - 相同已记录源码、命令和环境输入的自动检查返回原日志;用户可明确重跑。交替重复读取、无产出的空续接受到进展保护,合理分页和新输入可继续。 +- 暂停前先核对无进展输入摘要,再发布已封存的运行终态,避免界面已暂停而续接或改连接仍被执行锁拒绝。 - 显示任务交付、文件应用、诊断答复与检查的各自状态;启动选择与实际模型路由分开显示。源码、界面与本地发行验收见QA-1.20.1,实际部署以发行身份收据为准。 ## 1.20.0 · 固定工程评测与受控候选采纳 diff --git a/src/server/runtime.mjs b/src/server/runtime.mjs index 35e47888..91960dbf 100644 --- a/src/server/runtime.mjs +++ b/src/server/runtime.mjs @@ -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 { diff --git a/tests/task-control.test.mjs b/tests/task-control.test.mjs index ceb424c7..fa64e893 100644 --- a/tests/task-control.test.mjs +++ b/tests/task-control.test.mjs @@ -99,6 +99,27 @@ test('a provider cannot execute tests against an explicit no-test task even if i assertToolPairs(f.session.providerMessages); }); +test('a budget pause becomes visible only after its input snapshot can be sealed with the original Run', async t => { + const f = harness(t, () => calls(call('one-read', 'read_file', { path: 'README.md' }))); + f.store.config.maxSteps = 1; + let entered, release; + const capturing = new Promise(resolve => { entered = resolve; }); + const held = new Promise(resolve => { release = resolve; }); + const capture = f.runtime.capturePauseInputs.bind(f.runtime); + f.runtime.capturePauseInputs = async run => { entered(); await held; return capture(run); }; + t.after(() => release()); + f.runtime.start(f.session.id, '读取原文件'); + await capturing; + const run = f.store.core.run.get(f.session.runId); + assert.equal(f.session.status, 'running'); assert.equal(run.finishedAt, null); + assert.equal(f.runtime.isActive(f.session.id), true); + assert.throws(() => f.runtime.resume(f.session.id), { status: 409 }); + release(); await f.wait(); + assert.equal(f.session.status, 'paused'); assert.equal(run.stopReason, 'step_limit'); + assert.ok(run.finishedAt); assert.ok(run.finalSourceFingerprint); + assert.equal(f.runtime.isActive(f.session.id), false); +}); + test('alternating duplicate file reads and listing files still pauses without treating new pages as duplicates', async t => { const f = harness(t, round => calls(call('duplicate-read-' + round, 'read_file', { path: round % 2 ? 'README.md' : 'second.txt' }), call('list-between-' + round, 'list_files', { path: '' }))); fs.writeFileSync(path.join(f.projectRoot, 'second.txt'), 'another original source\n');