Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(grok-provider-attempt-contract): report text over the visual cap as text

Alfredo Lopez638e5b424026
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 89c3be23a..49071a9ff 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.448",
+ "version": "0.1.449",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.448",
+ "version": "0.1.449",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 1afe24588..3081caac1 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.448",
+ "version": "0.1.449",
"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/__tests__/grokSubscription.test.ts b/mcp-host/src/llm/__tests__/grokSubscription.test.ts
index 56a207e16..97a400423 100644
--- a/mcp-host/src/llm/__tests__/grokSubscription.test.ts
+++ b/mcp-host/src/llm/__tests__/grokSubscription.test.ts
@@ -1219,14 +1219,16 @@ describe('GrokSubscriptionProvider image input (#784)', () => {
expect(provider.classifyError(textOverCap).code).toBe(LlmErrorCode.ContextLengthExceeded)
// A V2 request with no image at all over the whole-body ceiling: the text
- // is what is too large, so it must not be blamed on an attachment.
+ // is what is too large, so it must not be blamed on an attachment. The
+ // contract checks the non-image share before the whole body, so this is
+ // reported as text too.
const text = 'x'.repeat(LIMITS.maxVisualRequestBodyBytes)
const wholeBody = await provider
.completeSingleTurn([{ role: 'user', content: text, contentParts: [{ type: 'text', text }] }])
.catch((e: unknown) => e)
expect(wholeBody).toMatchObject({
- code: 'payload_too_large',
- message: 'request exceeds maxVisualRequestBodyBytes',
+ code: 'request_limit_exceeded',
+ message: 'request exceeds maxRequestBodyBytes outside image data',
})
expect(provider.classifyError(wholeBody).code).toBe(LlmErrorCode.ContextLengthExceeded)
expect(wired.authorizer.authorize).not.toHaveBeenCalled()
diff --git a/packages/grok-provider-attempt-contract/index.cjs b/packages/grok-provider-attempt-contract/index.cjs
index e2736b4cf..ac2a4ed08 100644
--- a/packages/grok-provider-attempt-contract/index.cjs
+++ b/packages/grok-provider-attempt-contract/index.cjs
@@ -575,6 +575,12 @@ function parseGrokCompletionRequestRoot(input, schemaVersion, messageKeys) {
} catch {
return fail('invalid', 'request is not JSON-serializable')
}
+ // The non-image check runs first, so a V2 request over the visual ceiling
+ // because of its text is reported as text; only image data can reach the
+ // whole-body message below.
+ if (visualSchema && measureNonImageRequestBytes(input) > LIMITS.maxRequestBodyBytes) {
+ return fail('limit', 'request exceeds maxRequestBodyBytes outside image data', 'size')
+ }
// The byte count covers the whole request, tool definitions included. A
// tool catalog that alone exceeds the cap is refused with this message and
// the Host labels it context length, although compaction shrinks only the
@@ -588,9 +594,6 @@ function parseGrokCompletionRequestRoot(input, schemaVersion, messageKeys) {
'size'
)
}
- if (visualSchema && measureNonImageRequestBytes(input) > LIMITS.maxRequestBodyBytes) {
- return fail('limit', 'request exceeds maxRequestBodyBytes outside image data', 'size')
- }
const extra = rejectUnknown(input, ROOT_KEYS, 'request')
if (extra) return extra
if (input.schemaVersion !== schemaVersion) {
@@ -780,8 +783,10 @@ function hashGrokCompletionRequest(request) {
* carries. Its exact UTF-8 byte length (JSON.stringify minus whitespace, the
* same serialization the transport sends) must fit the ceiling of the schema it
* carries — `requestBodyLimitBytes(request)`, i.e. 35 MiB for V2 and 8 MiB
- * otherwise. A deployment that lowers the proxy's visual body limit below the
- * contract limit is not covered by this measurement.
+ * otherwise. The Host and the authorizer build it for V2 only, where 35 MiB is
+ * the number the proxy enforces through GROK_LLM_PROXY_MAX_VISUAL_BODY_BYTES.
+ * A deployment that lowers that proxy limit below the contract limit is not
+ * covered by this measurement.
*
* The request inside the envelope already passed the V2 non-image budget, so
* the V2 headroom here can only be spent by the ticket and the digest the
diff --git a/packages/grok-provider-attempt-contract/visualPayload.cjs b/packages/grok-provider-attempt-contract/visualPayload.cjs
index dd01355d8..0fc3d786a 100644
--- a/packages/grok-provider-attempt-contract/visualPayload.cjs
+++ b/packages/grok-provider-attempt-contract/visualPayload.cjs
@@ -22,8 +22,10 @@
*
* The decoder and the container readers are a copy of the Codex contract's
* visualPayload.cjs, kept separate so this package never imports the Codex
- * one. index.test.cjs requires identical verdicts from both copies on images
- * inside both budgets.
+ * one. index.test.cjs runs every container-reader branch through both copies
+ * and requires the same exact verdict from each, and requires identical
+ * verdicts on images inside both budgets; dimension limits, which only the
+ * Codex copy has, are the one intended difference.
*/
const GROK_VISUAL_LIMITS = Object.freeze({