Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): bound a Grok authorize body with the Grok envelope allowance
Alfredo Lopez8a64f67e0a66
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex b8b9e59cf..0d5c41119 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.450",+ "version": "0.1.451","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.450",+ "version": "0.1.451","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex c706445fe..1a73f94db 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.450",+ "version": "0.1.451","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/llm/grokSubscription.ts b/mcp-host/src/llm/grokSubscription.tsindex 217dec4c8..f235406d4 100644--- a/mcp-host/src/llm/grokSubscription.ts+++ b/mcp-host/src/llm/grokSubscription.ts@@ -83,11 +83,11 @@ export type GrokAttemptContext = {** `hashCanonicalGrokRequest` also returns a `kind` (#784), but it cannot* replace the message here: `size` covers the conversation bytes and the image- * byte budgets alike, and `count` covers `maxMessages` and `maxImages` alike.- * A shorter conversation fixes the first of each pair and none of the second,- * so the message stays the discriminator at this boundary (#731). The byte- * pattern is a prefix so it covers the element bound's own wording and the- * `outside image data` check of a V2 request.+ * byte budgets alike, and a shorter conversation fixes the first and not the+ * second. `count` is only ever `maxImages`; the `maxMessages` and tool-call+ * refusals carry no `kind`. So the message stays the discriminator at this+ * boundary (#731). The byte pattern is a prefix so it covers the element+ * bound's own wording and the `outside image data` check of a V2 request.** `messages exceed` is defence in depth rather than a reachable branch: the* guard in `execute` raises that exact message with this same classificationdiff --git a/mcp-host/src/llm/providerAttemptAuthorizer.ts b/mcp-host/src/llm/providerAttemptAuthorizer.tsindex 32a66e6ad..f36070aa1 100644--- a/mcp-host/src/llm/providerAttemptAuthorizer.ts+++ b/mcp-host/src/llm/providerAttemptAuthorizer.ts@@ -1,4 +1,5 @@import {+ ENVELOPE_ALLOWANCE_BYTES as GROK_ENVELOPE_ALLOWANCE_BYTES,LIMITS as GROK_LIMITS,PROVIDER_ID as GROK_PROVIDER_ID,requestBodyLimitBytes as grokRequestBodyLimitBytes,@@ -15,6 +16,7 @@ export const AUTHORIZE_PATH = '/api/v1/mcp-host/llm/provider-attempts/authorize'type RequestContract = {label: 'Codex' | 'Grok'maxRequestBodyBytes: number+ envelopeAllowanceBytes: numberrequestBodyLimitBytes: (request: unknown) => number}@@ -29,10 +31,16 @@ function requestContract(request: unknown): RequestContract {return {label: 'Grok',maxRequestBodyBytes: GROK_LIMITS.maxRequestBodyBytes,+ envelopeAllowanceBytes: GROK_ENVELOPE_ALLOWANCE_BYTES,requestBodyLimitBytes: grokRequestBodyLimitBytes,}}- return { label: 'Codex', maxRequestBodyBytes: LIMITS.maxRequestBodyBytes, requestBodyLimitBytes }+ return {+ label: 'Codex',+ maxRequestBodyBytes: LIMITS.maxRequestBodyBytes,+ envelopeAllowanceBytes: ENVELOPE_ALLOWANCE_BYTES,+ requestBodyLimitBytes,+ }}/**@@ -40,6 +48,8 @@ function requestContract(request: unknown): RequestContract {* revisions, hashes and recipe names, a few hundred bytes in practice. The* contract owns the value and control-api imports the same one, so a request* control-api would accept is never refused here for its envelope (#739).+ * This is the Codex value; a Grok request uses the Grok contract's own+ * allowance through `requestContract`.*/export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = ENVELOPE_ALLOWANCE_BYTES@@ -124,7 +134,7 @@ export class ProviderAttemptAuthorizer {// non-image cap plus the envelope allowance, or the V2 visual envelope.const bodyLimit = Math.max(requestLimit,- contract.maxRequestBodyBytes + AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES+ contract.maxRequestBodyBytes + contract.envelopeAllowanceBytes)if (Buffer.byteLength(serialized, 'utf8') > bodyLimit) {throw new CodexAuthorizeError(