fix(reading): preserve mixed-turn progress without disabling no-op guards

This commit is contained in:
Agent Workbench Dev
2026-11-04 19:43:48 +08:00
parent b4d7d2c965
commit d2703ad340
5 changed files with 89 additions and 2 deletions
+27
View File
@@ -87,6 +87,27 @@ export function filePage(file, args, { maximumMessageBytes = 16000, callId = '',
return make(end);
}
export function beginReadTurn(task, runId, stepId) {
const progress = task.readProgress ??= { schemaVersion: 1, reads: [], repeated: 0, changingIndexes: [], warning: null, pause: false };
progress.readTurn = { runId, stepId, newCharacters: 0, repeatedReads: 0, settled: false };
}
export function finishReadTurn(task, runId, stepId) {
const progress = task.readProgress, turn = progress?.readTurn;
if (!turn || turn.runId !== runId || turn.stepId !== stepId || turn.settled) return;
turn.settled = true;
const independentPause = progress.checkPause === true || progress.noopPause === true
|| (progress.sessionInspection?.consecutive ?? 0) >= 3 || progress.changingIndexes.length >= 6;
progress.pause ||= independentPause;
// A trailing sequence of repeated tools is not a wholly repeated turn when
// this same response returned new source/evidence bytes. Keep independent
// unchanged-check/action/state and changing-index guards authoritative.
if (turn.newCharacters > 0 && !independentPause) {
progress.pause = false;
progress.repeated = 0;
}
}
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 };
const identity = artifact.id + ':' + (artifact.section ? artifact.section + ':' : '') + artifact.sha256, start = result.offset, end = result.next_offset;
@@ -99,6 +120,12 @@ export function recordArtifactRead(task, artifact, result, invocationId, runId =
let window = progress.readWindow.reads.find(value => value.identity === identity);
if (!window) { window = { identity, ranges: [] }; progress.readWindow.reads.push(window); if (progress.readWindow.reads.length > 128) progress.readWindow.reads.shift(); }
const covered = window.ranges.some(range => start >= range[0] && end <= range[1]);
const turn = progress.readTurn;
if (turn?.runId === runId && !turn.settled) {
if (covered) turn.repeatedReads++;
else if (artifact.kind !== 'context-history-index') turn.newCharacters += Math.max(0, end - start
- window.ranges.reduce((sum, [left, right]) => sum + Math.max(0, Math.min(end, right) - Math.max(start, left)), 0));
}
progress.repeated = covered ? progress.repeated + 1 : 0;
const merge = ranges => {
ranges.sort((a, b) => a[0] - b[0]); const merged = [];