fix: account failed attempts and stop unchanged task loops in 1.20.1

This commit is contained in:
Agent Workbench Dev
2026-11-01 13:18:03 +08:00
parent 0736eca4cd
commit 441785a8b7
35 changed files with 579 additions and 106 deletions
+25 -7
View File
@@ -65,10 +65,9 @@ export function filePage(file, args, { maximumMessageBytes = 16000, callId = ''
export function recordArtifactRead(task, artifact, result, invocationId, runId = task.activeRunId ?? null) {
const progress = task.readProgress ??= { schemaVersion: 1, reads: [], repeated: 0, changingIndexes: [], warning: null, pause: false };
progress.sessionInspection = null;
const identity = artifact.id + ':' + (artifact.section ? artifact.section + ':' : '') + artifact.sha256, start = result.offset, end = result.next_offset;
let read = progress.reads.find(value => value.identity === identity);
if (!read) { read = { identity, ranges: [] }; progress.reads.push(read); if (progress.reads.length > 128) progress.reads.shift(); }
if (!read) { read = { identity, kind: artifact.kind, ranges: [] }; progress.reads.push(read); if (progress.reads.length > 128) progress.reads.shift(); }
// Historical coverage is an audit of returned pages, not proof that a new
// Run received them in its bounded request. Re-reading different old pages
// in a continuation must not accumulate as three semantic repeats.
@@ -90,7 +89,7 @@ export function recordArtifactRead(task, artifact, result, invocationId, runId =
} else progress.changingIndexes = [];
progress.warning = progress.repeated >= 1 ? '本次运行已经返回该工件区间,请使用已返回内容,或按next_offset读取新的区间。'
: progress.changingIndexes.length >= 3 ? '连续读取更新的历史索引没有推进工程;请直接读取实际结果或项目文件,依据已有信息继续任务。' : null;
progress.pause = progress.repeated >= 3 || progress.changingIndexes.length >= 6;
progress.pause = progress.checkPause === true || progress.repeated >= 3 || progress.changingIndexes.length >= 6;
progress.last = { artifactId: artifact.id, sha256: artifact.sha256, offset: start, nextOffset: end, invocationId,
contentSha256: createHash('sha256').update(result.content, 'utf8').digest('hex') };
return progress;
@@ -100,6 +99,25 @@ export function clearReadStreak(task) {
if (!task.readProgress) return;
task.readProgress.repeated = 0; task.readProgress.changingIndexes = []; task.readProgress.warning = null; task.readProgress.pause = false;
task.readProgress.sessionInspection = null;
task.readProgress.observations = [];
task.readProgress.checkPause = false;
}
export function recordFileRead(task, result, invocationId, runId) {
return recordArtifactRead(task, { id: 'file:' + result.path + ':' + result.range_start_line + ':' + result.range_end_line,
sha256: result.sha256, kind: 'project-file' }, result, invocationId, runId);
}
export function recordUnchangedCheck(task, job, runId) {
const progress = task.readProgress ??= { schemaVersion: 1, reads: [], repeated: 0, changingIndexes: [], warning: null, pause: false };
const observations = progress.observations ??= [];
let value = observations.find(value => value.runId === runId && value.key === 'check:' + job.inputIdentity);
if (!value) { value = { runId, key: 'check:' + job.inputIdentity, count: 0 }; observations.push(value); if (observations.length > 64) observations.shift(); }
value.count++;
progress.warning = '所选检查的已记录输入未变化,已返回原检查日志,没有再次执行。请依据失败修复源码;确需重跑可由用户在工程检查中确认。';
progress.checkPause ||= value.count >= 2;
progress.pause ||= progress.checkPause;
return progress;
}
export function recordBrowserRead(task, result, invocationId, runId = task.activeRunId ?? null) {
@@ -115,14 +133,14 @@ export function recordSessionInspection(task, result) {
const execution = result.execution ?? {};
// Revision, request usage and tool counters change merely by inspecting.
// They must not make identical engineering state appear to be progress.
const state = { sessionId: result.session?.id, status: result.session?.status,
const state = { sessionId: result.session?.id,
lastFailure: result.lastFailure, changes: result.changes, approvals: result.pendingApprovals,
verification: execution.task?.verification,
verification: execution.task?.verification && { status: execution.task.verification.status, sourceFingerprint: execution.task.verification.sourceFingerprint },
taskPlanId: execution.task?.currentTaskPlanId,
taskProofs: execution.taskProofs?.map(proof => ({ id: proof.id, planId: proof.planId, stepKey: proof.stepKey, status: proof.status })),
browserJobs: execution.browserJobs?.map(job => ({ id: job.id, planId: job.planId, status: job.status, resultSha256: job.resultSha256, assertions: job.assertions })),
needsVerification: execution.progress?.requiresVerification,
checks: execution.checks?.map(job => ({ id: job.id, status: job.status, stale: job.stale,
checks: execution.checks?.map(job => ({ inputIdentity: job.inputIdentity, fingerprint: job.fingerprint, status: job.status, stale: job.stale,
results: job.results.map(check => ({ name: check.name, status: check.status, exitCode: check.exitCode, tests: check.tests })) })),
changeSets: execution.changeSets?.map(set => ({ id: set.id, status: set.status, requiresVerification: set.requiresVerification })),
deliveries: execution.deliveries?.map(job => ({ id: job.id, status: job.status, commit: job.commit })) };
@@ -131,6 +149,6 @@ export function recordSessionInspection(task, result) {
const consecutive = previous?.signature === signature ? previous.consecutive + 1 : 1;
progress.sessionInspection = { signature, consecutive };
progress.warning = consecutive >= 2 ? '连续核对的工程状态没有变化,请使用已经返回的状态与源码推进当前任务。' : null;
progress.pause = consecutive >= 3;
progress.pause = progress.checkPause === true || consecutive >= 3 || progress.repeated >= 3;
return progress;
}