perf(reading): share bounded file and log budgets across independent reads
This commit is contained in:
@@ -28,7 +28,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, readBatchBudget, spendReadBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT, beginReadTurn, finishReadTurn } from '../core/context/read-budget.mjs';
|
||||
import { artifactPage, filePage, readMessageBudget, readBatchBudget, spendReadBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT, beginReadTurn, finishReadTurn, orderReadCalls } 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';
|
||||
@@ -484,6 +484,13 @@ export class Runtime {
|
||||
beginReadTurn(task, run.id, stepRecord.id);
|
||||
run.readPageCharacters = planned.record.budget.inputBudget - planned.record.nextReadFixedInputTokens
|
||||
- (planned.record.workingRetentionTokens ?? 0) < 4096 ? 2000 : Infinity;
|
||||
const executionCalls = orderReadCalls(run.readBatchBudget, calls, call => {
|
||||
const args = JSON.parse(call.function.arguments);
|
||||
validateToolArgs(call.function.name, args);
|
||||
const size = call.function.name === 'read_file' ? fs.statSync(safePath(run.project, args.path)).size
|
||||
: this.store.owned('artifact', args.artifact_id, session.id).bytes;
|
||||
return Math.max(0, Math.min(size - (args.offset ?? 0), args.limit ?? (call.function.name === 'read_artifact' ? 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);
|
||||
@@ -539,7 +546,7 @@ export class Runtime {
|
||||
}
|
||||
let deliveryReview = null, mcpReview = null;
|
||||
const preparedSets = new Set();
|
||||
for (const call of calls) {
|
||||
for (const call of executionCalls) {
|
||||
let result;
|
||||
if (deliveryReview || mcpReview) {
|
||||
const event = session.events.find(value => value.toolCallId === call.id && value.runId === run.id);
|
||||
|
||||
Reference in New Issue
Block a user