Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: classify proxy 413 as context length and derive the body limit (#731)
Alfredo Lopez2b04bd6a077c
diff --git a/codex-llm-proxy/src/config.ts b/codex-llm-proxy/src/config.tsindex 2baa3094d..50a43fc79 100644--- a/codex-llm-proxy/src/config.ts+++ b/codex-llm-proxy/src/config.ts@@ -1,3 +1,5 @@+import { DEFAULT_MAX_BODY_BYTES } from './requestLimits.js'+export type CodexLlmProxyConfig = {runtimePort: numberadminPort: number@@ -63,7 +65,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): CodexLlmProxyCmaxBodyBytes: requiredPositiveInt('CODEX_LLM_PROXY_MAX_BODY_BYTES',env.CODEX_LLM_PROXY_MAX_BODY_BYTES,- 1_048_576+ DEFAULT_MAX_BODY_BYTES),maxStreamDurationMs: requiredPositiveInt('CODEX_LLM_PROXY_MAX_STREAM_DURATION_MS',diff --git a/codex-llm-proxy/src/requestLimits.ts b/codex-llm-proxy/src/requestLimits.tsindex 550e48cde..4c06401f8 100644--- a/codex-llm-proxy/src/requestLimits.ts+++ b/codex-llm-proxy/src/requestLimits.ts@@ -1,5 +1,18 @@import { LIMITS as CONTRACT_LIMITS } from '@clerum/llm-provider-attempt-contract'+/**+ * #731 — room for the runtime envelope around the contract-capped `request`:+ * the execution ticket (a few KB by its claim bounds), the request hash, the+ * deadline and the JSON keys. 16 KiB is several times that.+ */+export const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024++/**+ * The default body limit, derived from the contract so the proxy never refuses,+ * as a 413, a request the contract accepts.+ */+export const DEFAULT_MAX_BODY_BYTES = CONTRACT_LIMITS.maxRequestBodyBytes + ENVELOPE_ALLOWANCE_BYTES+export const STREAM_LIMITS = {maxConcurrentStreams: 8,maxQueuedRequests: 16,diff --git a/deploy/base/control-plane/codex-llm-proxy.yaml b/deploy/base/control-plane/codex-llm-proxy.yamlindex 71e3abb29..42f6b7379 100644--- a/deploy/base/control-plane/codex-llm-proxy.yaml+++ b/deploy/base/control-plane/codex-llm-proxy.yaml@@ -18,7 +18,6 @@ data:CODEX_LLM_PROXY_RUNTIME_PORT: "8080"CODEX_LLM_PROXY_ADMIN_PORT: "8081"CODEX_LLM_PROXY_PROBE_PORT: "9090"- CODEX_LLM_PROXY_MAX_BODY_BYTES: "1048576"CODEX_LLM_PROXY_MAX_STREAM_DURATION_MS: "300000"CODEX_LLM_PROXY_MAX_DEADLINE_MS: "300000"CODEX_LLM_PROXY_JWT_ISSUER: control-apidiff --git a/deploy/base/control-plane/grok-llm-proxy.yaml b/deploy/base/control-plane/grok-llm-proxy.yamlindex 0ef0e570c..831653870 100644--- a/deploy/base/control-plane/grok-llm-proxy.yaml+++ b/deploy/base/control-plane/grok-llm-proxy.yaml@@ -18,7 +18,6 @@ data:GROK_LLM_PROXY_RUNTIME_PORT: "8080"GROK_LLM_PROXY_ADMIN_PORT: "8081"GROK_LLM_PROXY_PROBE_PORT: "9090"- GROK_LLM_PROXY_MAX_BODY_BYTES: "1048576"GROK_LLM_PROXY_MAX_STREAM_DURATION_MS: "300000"GROK_LLM_PROXY_MAX_DEADLINE_MS: "300000"GROK_LLM_PROXY_JWT_ISSUER: control-apidiff --git a/grok-llm-proxy/src/config.ts b/grok-llm-proxy/src/config.tsindex 92f8d3996..c266547c8 100644--- a/grok-llm-proxy/src/config.ts+++ b/grok-llm-proxy/src/config.ts@@ -1,3 +1,5 @@+import { DEFAULT_MAX_BODY_BYTES } from './requestLimits.js'+export type GrokLlmProxyConfig = {runtimePort: numberadminPort: number@@ -75,7 +77,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): GrokLlmProxyComaxBodyBytes: requiredPositiveInt('GROK_LLM_PROXY_MAX_BODY_BYTES',env.GROK_LLM_PROXY_MAX_BODY_BYTES,- 1_048_576+ DEFAULT_MAX_BODY_BYTES),maxStreamDurationMs: requiredPositiveInt('GROK_LLM_PROXY_MAX_STREAM_DURATION_MS',diff --git a/grok-llm-proxy/src/requestLimits.ts b/grok-llm-proxy/src/requestLimits.tsindex ba22dd3b7..f0cc6d4bd 100644--- a/grok-llm-proxy/src/requestLimits.ts+++ b/grok-llm-proxy/src/requestLimits.ts@@ -1,5 +1,18 @@import { LIMITS as CONTRACT_LIMITS } from '@clerum/grok-provider-attempt-contract'+/**+ * #731 — room for the runtime envelope around the contract-capped `request`:+ * the execution ticket (a few KB by its claim bounds), the request hash, the+ * deadline and the JSON keys. 16 KiB is several times that.+ */+export const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024++/**+ * The default body limit, derived from the contract so the proxy never refuses,+ * as a 413, a request the contract accepts.+ */+export const DEFAULT_MAX_BODY_BYTES = CONTRACT_LIMITS.maxRequestBodyBytes + ENVELOPE_ALLOWANCE_BYTES+export const STREAM_LIMITS = {maxConcurrentStreams: 8,maxQueuedRequests: 16,diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex e9ff67041..640fbe173 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.390",+ "version": "0.1.391","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.390",+ "version": "0.1.391","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 727b96eab..86cf2d996 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.390",+ "version": "0.1.391","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/codexSubscription.ts b/mcp-host/src/llm/codexSubscription.tsindex 1d52c4cdb..01c588543 100644--- a/mcp-host/src/llm/codexSubscription.ts+++ b/mcp-host/src/llm/codexSubscription.ts@@ -232,7 +232,9 @@ export class CodexSubscriptionProvider implements SingleTurnProvider {...(providerDispatched !== undefined ? { providerDispatched } : {}),}}- if (code === 'request_limit_exceeded') {+ // `payload_too_large` is the proxy's 413 for an envelope over its body+ // limit: the same size refusal of this conversation, one hop later (#731).+ if (code === 'request_limit_exceeded' || code === 'payload_too_large') {return {code: LlmErrorCode.ContextLengthExceeded,retryable: false,diff --git a/mcp-host/src/llm/grokSubscription.ts b/mcp-host/src/llm/grokSubscription.tsindex 84749c958..ef286fbfd 100644--- a/mcp-host/src/llm/grokSubscription.ts+++ b/mcp-host/src/llm/grokSubscription.ts@@ -252,7 +252,13 @@ export class GrokSubscriptionProvider implements SingleTurnProvider {// transport refused a tool call whose arguments overran its size budget.// Treating it as an outage would retry the identical oversized call and,// being failover-eligible, spend a second provider on it.- if (code === 'request_limit_exceeded' || code === 'tool_call_arguments_exceeded') {+ // `payload_too_large` is the proxy's 413 for an envelope over its body+ // limit: the same size refusal of this conversation, one hop later (#731).+ if (+ code === 'request_limit_exceeded' ||+ code === 'tool_call_arguments_exceeded' ||+ code === 'payload_too_large'+ ) {return {code: LlmErrorCode.ContextLengthExceeded,retryable: false,