fix(runtime): apply open policy when continuing legacy tasks

This commit is contained in:
Agent Workbench Dev
2026-11-06 05:08:02 +08:00
parent 2fa220735d
commit c93c434808
6 changed files with 36 additions and 1 deletions
+14
View File
@@ -18,6 +18,20 @@ import { taskPlanInput } from '../src/shared/contracts/task-plans.mjs';
import { ChangeSetManager } from '../src/core/workspaces/change-sets.mjs';
import { proposeFile, rollbackChange } from '../src/server/files.mjs';
test('an unrestricted continuation releases an exhausted legacy Task allowance without rewriting its original Run or usage', async t => {
const f=fixture(t),first=f.store.beginRun(f.session,'Original bounded task',false,f.store.config),task=f.store.core.task.get(first.taskId);
task.budget.maxTokens=100;task.usage.totalTokens=200;
f.store.finishRun(f.session,first,'task_token_limit');
const original=structuredClone(first),usage=structuredClone(task.usage);
const server=await compatibleFixture(t,(_url,body)=>{for(const key of ['max_tokens','max_output_tokens','max_completion_tokens'])assert.equal(Object.hasOwn(body,key),false);return completion([],'Continued the original task.');});
f.store.saveConfig({...openDefaults,mode:'compatible',model:'owned',baseUrl:server.baseUrl});
const runtime=new Runtime(f.store,new Provider());f.onCleanup(()=>runtime.stopAll());
runtime.start(f.session.id,'Continue the saved task.',true);await until(()=>!runtime.isActive(f.session.id),30000);
assert.equal(f.session.status,'completed',JSON.stringify(f.session.failure));assert.equal(f.session.taskId,task.id);
assert.equal(task.budget.maxTokens,0);assert.equal(server.requests.length,1);
assert.ok(task.usage.totalTokens>=usage.totalTokens);assert.deepEqual(f.store.core.run.get(first.id),original);
});
test('open change sets apply and restore a file larger than the old four MiB batch ceiling', async t => {
const f = fixture(t, { modernDefaults: true }), before = '\uFEFFORIGINAL\r\n' + 'a'.repeat(5 * 1024 * 1024);
fs.writeFileSync(path.join(f.projectRoot, 'large-change.txt'), before);