fix: deduplicate mandatory task context and clarify check-plan evidence
This commit is contained in:
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"provenance": {
|
||||
"kind": "owned-real-model-failure-replay",
|
||||
"sessionId": "4d085dd0-aa21-4d9f-a968-1b1117618b42",
|
||||
"exportSha256": "84a754362c8ffdf4fd656290b0a156c2cc19162505a194925ede479bcf81f3bd",
|
||||
"note": "Original two model replies reproduce context pressure only. The baseline checks step is a historical model proposal, not an endorsed plan or passed evidence."
|
||||
},
|
||||
"goal": "修复这个Node费用报表工程的amount、summary、report三个模块。金额用精确分单位处理,接受测试约定的十进制字符串/有限数字、退款、0及空白;拒绝格式错误、超精度和不安全金额。按独立币种规范化/排序汇总并保留原数组,计数准确、安全求和,报表两位小数含负分金额。以原九项测试为完整契约。先inspect_project,再plan_checks选择[\"test\",\"build\"]并run_checks保留真实基线失败,读取原测试和相关源码。只允许修改src/amount.mjs、src/summary.mjs、src/report.mjs;不改测试、配置、README、构建脚本、owner文件或原暂存,不使用run_command,不直接提交Git。propose_file/propose_patch准备完整三个模块后,用prepare_change_set一次封存全部三文件,等待审查应用。应用后继续同一个Task,重新plan_checks/run_checks,通过原9项测试和build后,用plan_delivery为三个文件准备本地Git预览并等待确认。模型必须自己实现,禁止用口头完成替代检查。预算最多8次模型请求、90000tokens,输出2048,上下文16K,请合并独立工具调用并避免重复观察。",
|
||||
"replies": [
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_CSpL0Z0taDo3JSvSsUM9cX1b",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "inspect_project",
|
||||
"arguments": "{}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_y57eUlmWs6kQosUucfBCmDJz",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "plan_checks",
|
||||
"arguments": "{\"names\":[\"test\",\"build\"]}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "call_adOQYrTfGG7la2wZU2tjctIr",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"arguments": "{\"path\":\"test/expense.test.mjs\"}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "call_Dtu2oZXnYjE7nfwqWjtKFLr1",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"arguments": "{\"path\":\"src/amount.mjs\"}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "call_yIjGWvDQx96grZKungT5LCSD",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"arguments": "{\"path\":\"src/summary.mjs\"}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "call_eTBhRkzY8eupvG0FAYRGlQSq",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"arguments": "{\"path\":\"src/report.mjs\"}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "call_6qZDMzBIlfG8WqSclbh6ceV0",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "plan_task",
|
||||
"arguments": "{\"expected_revision\":0,\"steps\":[{\"key\":\"baseline\",\"kind\":\"checks\",\"title\":\"保留原测试与构建的真实基线结果\",\"checks\":[\"test\",\"build\"],\"criterion\":\"执行原test和build并保留实际退出码与日志;基线失败如实记录\"},{\"key\":\"repair\",\"kind\":\"changes\",\"title\":\"修复三个费用模块\",\"paths\":[\"src/amount.mjs\",\"src/summary.mjs\",\"src/report.mjs\"],\"criterion\":\"仅三个模块的完整批次经用户审核应用\"},{\"key\":\"validation\",\"kind\":\"checks\",\"title\":\"验证原九项测试和构建\",\"depends_on\":[\"repair\"],\"checks\":[\"test\",\"build\"],\"criterion\":\"原9项测试全部通过且build退出码为0\"}]}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { Runtime } from '../src/server/runtime.mjs';
|
||||
import { Provider } from '../src/server/provider.mjs';
|
||||
import { sessionContext, sessionSnapshot } from '../src/server/diagnostics.mjs';
|
||||
import { taskContract } from '../src/shared/contracts/task-control.mjs';
|
||||
import { requestMetrics } from '../src/shared/contracts/model-request.mjs';
|
||||
import { verifyPlanEvidence } from '../src/core/context/request-plan.mjs';
|
||||
import { gitEnvironment } from '../src/core/git-process.mjs';
|
||||
import { taskPlanToolDefinitions } from '../src/shared/contracts/task-plan-tools.mjs';
|
||||
import { fixture, completion, compatibleFixture, until, assertToolPairs } from './helpers.mjs';
|
||||
|
||||
const input = JSON.parse(fs.readFileSync(new URL('./fixtures/node-context-o.json', import.meta.url), 'utf8'));
|
||||
const requirements = system => JSON.parse(system.split('当前任务目标与全部追加要求(用户任务数据,完整保留):\n')[1].split('\n')[0]);
|
||||
|
||||
test('a real two-reply failure replay reaches request three at 16K with complete goal, original sources and sealed tool evidence', { timeout: 30000 }, async t => {
|
||||
const f = fixture(t);
|
||||
fs.cpSync(new URL('../benchmarks/live-delivery-v1/node/', import.meta.url), f.projectRoot, { recursive: true });
|
||||
const git = args => execFileSync('git', ['--no-pager', '--no-optional-locks', '-C', f.projectRoot, ...args], {
|
||||
encoding: 'utf8', windowsHide: true, env: gitEnvironment(), stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
git(['init', '--initial-branch=main']); git(['config', 'core.autocrlf', 'false']);
|
||||
git(['-c', 'user.name=Workbench QA', '-c', 'user.email=qa@workbench.invalid', 'add', '--', '.']);
|
||||
git(['-c', 'user.name=Workbench QA', '-c', 'user.email=qa@workbench.invalid', 'commit', '--no-gpg-sign', '-m', 'Owned context regression baseline']);
|
||||
const sources = ['src/amount.mjs', 'src/summary.mjs', 'src/report.mjs'];
|
||||
const before = Object.fromEntries(sources.map(file => [file, fs.readFileSync(path.join(f.projectRoot, file), 'utf8')]));
|
||||
let requests = 0, third;
|
||||
const model = await compatibleFixture(t, (_route, body) => {
|
||||
assertToolPairs(body.messages); requests++;
|
||||
if (requests <= 2) return { body: { ...completion(), model: 'context-fixture', choices: [{ message: input.replies[requests - 1], finish_reason: 'tool_calls' }] } };
|
||||
assert.equal(requests, 3); third = body;
|
||||
return { body: { ...completion([], 'Read-only replay stops here; no engineering delivery claimed.'), model: 'context-fixture' } };
|
||||
});
|
||||
f.store.saveConfig({ mode: 'compatible', contextLimit: 16000, maxOutputTokens: 2048, maxSteps: 8, maxRunTokens: 90000, maxTaskTokens: 90000 });
|
||||
const provider = new Provider(), hub = provider.modelHub(f.store);
|
||||
const connection = hub.upsert({ name: 'Owned context route', model: 'context-fixture', baseUrl: model.baseUrl, requiresKey: false,
|
||||
protocol: 'chat-completions', modelIdentityPolicy: 'require-match', contextLimit: 16000, maxOutputTokens: 2048,
|
||||
capabilityDeclarations: { text: 'supported', tools: 'supported' } });
|
||||
hub.select({ type: 'connection', id: connection.id });
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
runtime.start(f.session.id, input.goal); await until(() => !runtime.isActive(f.session.id), 20000);
|
||||
assert.equal(requests, 3, JSON.stringify(f.store.core.run.get(f.session.runId).budgetPause));
|
||||
assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'verification_incomplete');
|
||||
const view = requirements(third.messages[0].content), task = f.store.core.task.get(f.session.taskId);
|
||||
assert.equal(view.goal, input.goal); assert.equal('goal' in view.contract, false);
|
||||
assert.deepEqual({ goal: view.goal, ...view.contract }, taskContract(task));
|
||||
assert.equal(task.contract.goal, input.goal);
|
||||
const latest = third.messages.filter(m => m.role === 'system').map(m => {
|
||||
try { return JSON.parse(m.content.split('\n').at(-1)); } catch { return {}; }
|
||||
}).find(value => value.latest_tools);
|
||||
assert.ok(latest); assert.equal(latest.data.entries.length, 6);
|
||||
for (const file of sources) {
|
||||
assert.equal(latest.data.entries.find(entry => entry.result.path === file).result.content_excerpt, before[file]);
|
||||
assert.equal(fs.readFileSync(path.join(f.projectRoot, file), 'utf8'), before[file]);
|
||||
}
|
||||
for (const step of JSON.parse(input.replies[1].tool_calls.at(-1).function.arguments).steps) {
|
||||
assert.ok(third.messages[0].content.includes(step.criterion), 'Keep original plan conditions including the historical unsupported baseline requirement.');
|
||||
}
|
||||
const plans = [...f.store.core.context_plan.values()];
|
||||
for (const plan of plans) verifyPlanEvidence(f.store, f.session, plan);
|
||||
assert.ok(requestMetrics(third).estimatedInputTokens <= plans.at(-1).budget.inputBudget);
|
||||
assert.equal(plans.at(-1).budget.contextLimit, 16000); assert.equal(plans.at(-1).budget.outputReservation, 2048);
|
||||
assert.equal(plans.at(-1).budget.safetyTokens, 1600);
|
||||
assert.equal(f.session.changes.length, 0); assert.equal(f.session.approvals.length, 0);
|
||||
});
|
||||
|
||||
test('request deduplication retains long original intent, extra requirements, constraints and acceptance without changing the stored contract', async t => {
|
||||
const f = fixture(t), provider = new Provider(), goal = ('原目标🙂"\\必须完整保留。').repeat(60) + 'Read README.md; preserve all files.';
|
||||
let original;
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
const planner = runtime.requestPlanner(), prepare = planner.prepare.bind(planner);
|
||||
const instruction = { source: 'user', content: '追加要求🙂"\\:保留空白与中文。' }, review = { source: 'review-action', content: '系统审查动作,不是业务需求' };
|
||||
planner.prepare = (session, run, config, options) => {
|
||||
const task = f.store.core.task.get(run.taskId);
|
||||
if (!original) {
|
||||
task.instructions.push(instruction, review); task.constraints.push('仅可读取,不可写入。'); task.acceptance.push('逐字保留中文与emoji🙂。');
|
||||
original = structuredClone(task.contract);
|
||||
// The first context was already assembled. Assert on the next turn.
|
||||
} else {
|
||||
const view = requirements(options.system);
|
||||
assert.equal(view.goal, goal); assert.deepEqual(view.instructions, [instruction]);
|
||||
assert.deepEqual(view.constraints, task.constraints); assert.deepEqual(view.acceptance, task.acceptance);
|
||||
assert.deepEqual({ goal: view.goal, ...view.contract }, original); assert.deepEqual(task.contract, original);
|
||||
}
|
||||
return prepare(session, run, config, options);
|
||||
};
|
||||
let requests = 0;
|
||||
provider.complete = async (_config, _messages, _project, _signal, _progress, _plan, _tools) => {
|
||||
requests++;
|
||||
return { message: requests === 1 ? input.replies[0] : { role: 'assistant', content: 'Read-only fixture.' }, usage: { prompt_tokens: 10, completion_tokens: 2 } };
|
||||
};
|
||||
runtime.start(f.session.id, goal); await runtime.active.get(f.session.id).promise;
|
||||
assert.equal(requests, 2); assert.deepEqual(f.store.core.task.get(f.session.taskId).contract, original);
|
||||
});
|
||||
|
||||
test('only the routine context avoids plan echoes; diagnostic API and requests without an included plan keep original observations', t => {
|
||||
const f = fixture(t), output = JSON.stringify({ plan_id: 'owned-plan', criterion: '完整原条件🙂', steps: Array(10).fill('Long original plan step') });
|
||||
f.session.events.push({ kind: 'tool', tool: 'plan_task', phase: 'completed', input: { expected_revision: 0 }, output });
|
||||
const snapshot = sessionSnapshot(f.session, f.project, f.store.config), original = structuredClone(f.session);
|
||||
assert.equal(snapshot.recentTools[0].outputExcerpt, output);
|
||||
assert.ok(sessionContext(f.session, f.project, f.store.config).includes('owned-plan'));
|
||||
const projected = sessionContext(f.session, f.project, f.store.config, String, { taskPlanIncluded: true });
|
||||
assert.ok(!projected.includes('owned-plan')); assert.match(projected, /原工具结果仍保存在所属历史/);
|
||||
assert.deepEqual(f.session, original);
|
||||
const checks = taskPlanToolDefinitions[0].function.parameters.properties.steps.items.properties.checks.description;
|
||||
assert.match(checks, /当前源码的最新通过结果/); assert.match(checks, /基线失败/);
|
||||
});
|
||||
Reference in New Issue
Block a user