Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: skip exhausted attachment page fitting
Josué6a283f7658b9
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 1928bc87d..0e6daaf99 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.557",+ "version": "0.1.558","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.557",+ "version": "0.1.558","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 2e9f5111a..17bcdd016 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.557",+ "version": "0.1.558","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/agent/__tests__/attachmentRead.integration.test.ts b/mcp-host/src/agent/__tests__/attachmentRead.integration.test.tsindex 5260584bd..eaf8bffe4 100644--- a/mcp-host/src/agent/__tests__/attachmentRead.integration.test.ts+++ b/mcp-host/src/agent/__tests__/attachmentRead.integration.test.ts@@ -16,6 +16,7 @@ import {attachmentReadBudgets,} from '../../core/attachments/attachmentReadBudget'import { ConversationManager } from '../../core/conversation/conversation'+import * as contextManager from '../../core/extensions/contextManager'import { SimpleEventEmitter } from '../../core/orchestration/eventEmitter'import { ATTACHED_FILES_INSTRUCTION } from '../../core/orchestration/turnContext'import { ATTACHMENT_READ_TURN_STOP_MESSAGE } from '../../core/tools/attachmentRead'@@ -222,6 +223,7 @@ describe('clerum__attachment_read through a complete task (#666)', () => {afterEach(() => {Object.assign(appConfig, saved)+ vi.restoreAllMocks()})it('lists the text file, reads it in the same turn and answers with its sentinel', async () => {@@ -390,6 +392,7 @@ describe('clerum__attachment_read through a complete task (#666)', () => {}it('ends the task with a stop message instead of failing it when the model keeps reading', async () => {+ const measurement = vi.spyOn(contextManager, 'toolMessageBudgetTokens')Object.assign(appConfig, {enableApproval: false,dynamicToolsEnabled: false,@@ -416,6 +419,16 @@ describe('clerum__attachment_read through a complete task (#666)', () => {const kinds = Array.from({ length: 18 }, (_, i) => kindSeenAfter(providerCalls, i + 1, i + 1))expect(kinds.slice(0, 2)).toEqual(['text', 'text'])expect(kinds.slice(2).every(kind => kind === 'read_budget_exhausted')).toBe(true)+ // After the first exhausted reply, retries must not keep fitting full+ // text candidates that cannot reach the model. Keep the real measurer:+ // this exercises TaskExecutor's budget fence, not a cheaper test counter.+ const retryMeasurements = measurement.mock.calls+ .map(([message]) => message)+ .filter(message => Number(message.tool_call_id?.slice('read-'.length)) >= 4)+ expect(retryMeasurements.length).toBeGreaterThan(0)+ expect(+ retryMeasurements.some(message => toolPayload(message.content ?? '').kind === 'text')+ ).toBe(false)expect(ledgerOf(executor).spentTokens).toBeGreaterThan(turnTokens)expect(ledgerOf(executor).spentTokens).toBeLessThanOrEqual(ceiling)})diff --git a/mcp-host/src/core/tools/attachmentRead.ts b/mcp-host/src/core/tools/attachmentRead.tsindex 63e8c7f4d..4cff37cfa 100644--- a/mcp-host/src/core/tools/attachmentRead.ts+++ b/mcp-host/src/core/tools/attachmentRead.ts@@ -381,6 +381,18 @@ export class AttachmentReadTool implements Tool {const notice = this.exhaustedResult(identity.attachmentId, identity.referenceId, offset)const noticeCost = measure(JSON.stringify(notice))const allowance = this.ledger.pageAllowance(this.contextWindowTokens, noticeCost)+ // No text page can fit once the reserved notices consume the allowance.+ // Avoid serializing, sanitizing and tokenizing full candidates on every+ // retry; finalizeResult still charges the notice and enforces the stop.+ if (allowance === 0) {+ return this.ok(notice, start, {+ identity,+ offset,+ fileBytes: bytes.length,+ reservedCost: noticeCost,+ exhausted: true,+ })+ }let binding: AttachmentReadLimit | null = end < bytes.length ? 'max_bytes' : nullconst serialized = this.serializePage(bytes, identity, offset, end, end < bytes.length, binding)if (measure(serialized) > allowance) {