fix: keep artifact pages observable and pause repeated context reads

This commit is contained in:
Agent Workbench Dev
2026-10-29 21:50:53 +08:00
parent 3825142a68
commit 6e465a26d4
42 changed files with 520 additions and 30 deletions
+9 -4
View File
@@ -12,6 +12,7 @@ import { inspectProject } from '../core/project-inspector.mjs';
import { GitDelivery } from '../core/git-delivery.mjs';
import { ProjectIndex } from '../core/context/project-index.mjs';
import { RequestPlanner } from '../core/context/request-plan.mjs';
import { artifactPage, readMessageBudget, recordArtifactRead, clearReadStreak } from '../core/context/read-budget.mjs';
import { ChangeSetManager } from '../core/workspaces/change-sets.mjs';
import { assertChangeSetsResolved } from '../shared/contracts/change-sets.mjs';
@@ -130,7 +131,8 @@ export class Runtime {
+ '\n当前任务目标与全部追加要求(用户任务数据,完整保留):\n' + JSON.stringify({
goal: task.goal, instructions: task.instructions, constraints: task.constraints ?? [], acceptance: task.acceptance ?? [],
}) + '\n结果未知的调用,不得假定成功或重放:' + JSON.stringify(unknown)
+ '\n' + sessionContext(session, run.project, config, value => this.provider.redact(value)));
+ '\n' + sessionContext(session, run.project, config, value => this.provider.redact(value))
+ (task.readProgress?.warning ? '\n当前读取进展:' + task.readProgress.warning : ''));
const planned = this.requestPlanner().prepare(session, run.record, config, { system: context, tools: toolDefinitions, stepId: stepRecord.id });
if (planned.record.archivedGroups && !projectionLogged) {
projectionLogged = true; session.compactions++;
@@ -165,6 +167,7 @@ export class Runtime {
signal.throwIfAborted();
const message = response.message;
const calls = message.tool_calls ?? [];
run.readMessageBytes = readMessageBudget(planned.record, message);
const previousIds = new Set(session.providerMessages.flatMap(item => (item.tool_calls ?? []).map(call => call.id)));
if (new Set(calls.map(call => call.id)).size !== calls.length || calls.some(call => previousIds.has(call.id))) throw new Error('模型返回了重复的工具调用 ID,请重新发送任务。');
session.providerMessages.push(message);
@@ -191,6 +194,8 @@ export class Runtime {
signal.throwIfAborted();
}
this.store.finishStep(session, stepRecord);
if (this.store.core.task.get(run.taskId).readProgress?.pause) throw new BudgetExceeded('no_progress',
'模型连续重复读取已覆盖工件区间或更新的历史索引,未推进当前任务。已读取内容和原任务已保存,请核对结果或调整任务要求后继续。');
}
session.status = 'paused';
run.stopReason = 'step_limit';
@@ -250,9 +255,8 @@ export class Runtime {
}
else if (tool === 'read_artifact') {
const artifact = this.store.owned('artifact', args.artifact_id, session.id), text = this.store.artifactStore.read(artifact);
const offset = args.offset ?? 0, limit = Math.min(16000, Math.max(1, args.limit ?? 8000));
result = { artifact_id: artifact.id, kind: artifact.kind, sha256: artifact.sha256, content: text.slice(offset, offset + limit), offset,
total_characters: text.length, truncated: offset + limit < text.length };
result = artifactPage(artifact, text, args, { callId: call.id, maximumMessageBytes: run.readMessageBytes ?? 16000 });
recordArtifactRead(this.store.core.task.get(run.taskId), artifact, result, event.invocationId);
}
else if (tool === 'prepare_change_set') {
const set = await this.changeSetManager().prepare(session, args.change_ids, { source: 'agent' });
@@ -294,6 +298,7 @@ export class Runtime {
else if (tool === 'run_command') result = await this.requestCommand(session, event, args, run);
else throw new Error('当前能力表没有工具:' + tool);
event.phase = ['denied', 'interrupted', 'unknown', 'unverified', 'stale'].includes(result.status) ? result.status : result.status === 'failed' ? 'failed' : 'completed';
if (tool !== 'read_artifact' && !['error', 'interrupted', 'unknown', 'denied'].includes(result.status)) clearReadStreak(this.store.core.task.get(run.taskId));
if (typeof result.stdout === 'string') { result.stdout = this.provider.redact(result.stdout); result.stderr = this.provider.redact(result.stderr ?? ''); }
event.output = this.provider.redact(typeof result.stdout === 'string' ? result.stdout + (result.stderr ? '\n' + result.stderr : '') : JSON.stringify(result).slice(0, 16000));
if (result.exit_code !== undefined) event.exitCode = result.exit_code;