fix: retain source continuation and explain request reservation pauses
This commit is contained in:
+14
-3
@@ -27,7 +27,7 @@ import { RequestPlanner, verifyPlanEvidence } from '../core/context/request-plan
|
||||
import { ENGINE_SEED_RESERVATION } from '../shared/contracts/engine-context.mjs';
|
||||
import { InputAttachments } from '../core/context/input-attachments.mjs';
|
||||
import { BudgetResume } from '../core/context/budget-resume.mjs';
|
||||
import { artifactPage, filePage, readMessageBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT } from '../core/context/read-budget.mjs';
|
||||
import { artifactPage, filePage, readMessageBudget, readBatchBudget, spendReadBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT } from '../core/context/read-budget.mjs';
|
||||
import { taskDeliveryProgress } from '../core/context/delivery-progress.mjs';
|
||||
import { ChangeSetManager } from '../core/workspaces/change-sets.mjs';
|
||||
import { assertChangeSetsResolved } from '../shared/contracts/change-sets.mjs';
|
||||
@@ -119,6 +119,7 @@ export function validateToolArgs(tool, args) {
|
||||
for (const field of required) if (typeof args[field] !== 'string') throw new Error('工具参数 ' + field + ' 必须是文本。');
|
||||
for (const field of ['depth', 'start_line', 'end_line', 'offset', 'limit']) if (args[field] !== undefined && (!Number.isInteger(args[field]) || args[field] < 0)) throw new Error('工具参数 ' + field + ' 必须是非负整数。');
|
||||
if (tool === 'read_file' && args.limit !== undefined && (args.limit < 1 || args.limit > 16000)) throw new Error('文件分页limit需要1到16000个字符。');
|
||||
if (tool === 'read_file' && args.expected_sha256 !== undefined && (typeof args.expected_sha256 !== 'string' || !/^[a-f0-9]{64}$/i.test(args.expected_sha256))) throw new Error('文件续读expected_sha256需要64位SHA256。');
|
||||
if (args.case_sensitive !== undefined && typeof args.case_sensitive !== 'boolean') throw new Error('case_sensitive 必须是布尔值。');
|
||||
if (tool === 'plan_checks' && args.names !== undefined && (!Array.isArray(args.names) || args.names.some(name => typeof name !== 'string'))) throw new Error('检查脚本名称需要文本数组。');
|
||||
if (tool === 'plan_delivery' && args.message !== undefined && typeof args.message !== 'string') throw new Error('提交说明需要文本。');
|
||||
@@ -464,6 +465,9 @@ export class Runtime {
|
||||
const calls = message.tool_calls ?? [];
|
||||
if (run.worker && (calls.length > 16 || workerUsage(this.store, run.worker).toolCalls + calls.length > run.worker.budget.maxToolCalls)) throw new BudgetExceeded('worker_tool_limit', '子任务工具次数超出固定累计预算或单次16项上限;这批工具未执行,原响应和用量已保存。');
|
||||
run.readMessageBytes = readMessageBudget(planned.record, message);
|
||||
run.readBatchBudget = readBatchBudget(planned.record, message);
|
||||
run.readPageCharacters = planned.record.budget.inputBudget - planned.record.nextReadFixedInputTokens
|
||||
- (planned.record.workingRetentionTokens ?? 0) < 4096 ? 2000 : Infinity;
|
||||
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);
|
||||
@@ -526,6 +530,7 @@ export class Runtime {
|
||||
}
|
||||
else if (signal.aborted) result = { status: 'interrupted', message: '用户停止了任务,这次调用没有执行。' };
|
||||
else result = await this.executeTool(session, call, run);
|
||||
spendReadBudget(run.readBatchBudget, call, result);
|
||||
session.providerMessages.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result) });
|
||||
if (call.function.name === 'prepare_change_set' && result.status === 'awaiting_review') preparedSets.add(result.change_set_id);
|
||||
if (call.function.name === 'call_registered_mcp' && result.requires_verification) mcpReview = result.mcp_job_id;
|
||||
@@ -625,7 +630,9 @@ export class Runtime {
|
||||
const proofHint = !!this.store.core.task.get(run.taskId)?.currentTaskPlanId && PLAN_READ_TOOLS.includes(tool);
|
||||
const readMetadata = { ...(proofHint ? { tool_invocation_id: event.invocationId } : {}),
|
||||
...(tool === 'read_browser_result' ? { repeated_read_count: Number.MAX_SAFE_INTEGER, reading_hint: BROWSER_READ_HINT } : {}) };
|
||||
const maximumMessageBytes = Math.max(1, (run.readMessageBytes ?? 16000) - readMetadataReserve(readMetadata));
|
||||
const batch = run.readBatchBudget;
|
||||
const pageBytes = batch?.remainingCalls ? Math.floor(batch.remainingBytes / batch.remainingCalls) : run.readMessageBytes ?? 16000;
|
||||
const maximumMessageBytes = Math.max(1, pageBytes - readMetadataReserve(readMetadata));
|
||||
if (!['act_browser_tab','prepare_environment','run_command', 'run_checks', 'run_browser'].includes(tool)) this.store.invocationState(session, event, 'running');
|
||||
else this.store.save(session);
|
||||
if (tool === 'inspect_session') result = { ...sessionSnapshot(session, run.project, run.config, value => this.provider.redact(value)), execution: this.store.executionSnapshot(session) };
|
||||
@@ -765,7 +772,11 @@ export class Runtime {
|
||||
}
|
||||
else if (tool === 'list_files') result = listFiles(run.project, args.path, args.depth ?? 3, 500);
|
||||
else if (tool === 'read_file') {
|
||||
result = filePage(readLines(run.project, args), args, { callId: call.id, maximumMessageBytes });
|
||||
result = filePage(readLines(run.project, args), args, { callId: call.id, maximumMessageBytes,
|
||||
// Match the planner's complete-small-source retention boundary;
|
||||
// returning a larger page that is immediately trimmed adds no useful
|
||||
// throughput. The escaped JSON budget can still make this smaller.
|
||||
...(run.readBatchBudget ? { maximumPageCharacters: run.readPageCharacters } : {}) });
|
||||
recordFileRead(this.store.core.task.get(run.taskId), result, event.invocationId, run.id);
|
||||
}
|
||||
else if (tool === 'search_files') result = searchFiles(run.project, args);
|
||||
|
||||
Reference in New Issue
Block a user