Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(contracts): export the envelope allowance from the contracts (#739)
Alfredo Lopez84a4a8c1e608
diff --git a/codex-llm-proxy/src/requestLimits.ts b/codex-llm-proxy/src/requestLimits.tsindex df6618220..aeb32075f 100644--- a/codex-llm-proxy/src/requestLimits.ts+++ b/codex-llm-proxy/src/requestLimits.ts@@ -1,11 +1,13 @@-import { LIMITS as CONTRACT_LIMITS } from '@clerum/llm-provider-attempt-contract'+import {+ ENVELOPE_ALLOWANCE_BYTES as CONTRACT_ENVELOPE_ALLOWANCE_BYTES,+ 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.+ * #731 — room for the runtime envelope around the contract-capped `request`.+ * The contract owns the value, shared with control-api and mcp-host.*/-export const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+export const ENVELOPE_ALLOWANCE_BYTES = CONTRACT_ENVELOPE_ALLOWANCE_BYTES/*** The default body limit, derived from the contract so the proxy never refuses,diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 8c7473d69..800bf8de6 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.624",+ "version": "0.1.625","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.624",+ "version": "0.1.625","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 33e6ea007..e3a554297 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.624",+ "version": "0.1.625","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/llmProviderAttemptAuthorizer.ts b/control-api/src/services/llmProviderAttemptAuthorizer.tsindex a17fe1942..f18657141 100644--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts@@ -5,6 +5,7 @@ import {parseGrokCompletionRequestV1,} from '@clerum/grok-provider-attempt-contract'import {+ ENVELOPE_ALLOWANCE_BYTES,LIMITS,buildCodexProxyEnvelope,computeCodexPolicyHash,@@ -162,9 +163,11 @@ const MAX_AUTHORIZE_BODY_DEPTH = Math.max(LIMITS.maxNestingDepth, GROK_LIMITS.ma* itself is held to maxRequestBodyBytes by the contract parser, so a request* at the cap is never refused for its envelope. The gateway's* client_max_body_size on this route is the larger of the cap plus this- * allowance and the V2 visual envelope (#660).+ * allowance and the V2 visual envelope (#660). The contract owns the value,+ * shared with both proxies and mcp-host; the Grok contract exports the same+ * one.*/-export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = ENVELOPE_ALLOWANCE_BYTES/*** Reject an over-deep body before anything serializes it. Iterative, so andiff --git a/grok-llm-proxy/src/requestLimits.ts b/grok-llm-proxy/src/requestLimits.tsindex f6467b90c..61e34caa7 100644--- a/grok-llm-proxy/src/requestLimits.ts+++ b/grok-llm-proxy/src/requestLimits.ts@@ -1,11 +1,13 @@-import { LIMITS as CONTRACT_LIMITS } from '@clerum/grok-provider-attempt-contract'+import {+ ENVELOPE_ALLOWANCE_BYTES as CONTRACT_ENVELOPE_ALLOWANCE_BYTES,+ 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.+ * #731 — room for the runtime envelope around the contract-capped `request`.+ * The contract owns the value, shared with control-api and mcp-host.*/-export const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+export const ENVELOPE_ALLOWANCE_BYTES = CONTRACT_ENVELOPE_ALLOWANCE_BYTES/*** The default body limit, derived from the contract so the proxy never refuses,diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 1dc4ddb34..aae464852 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.427",+ "version": "0.1.428","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.427",+ "version": "0.1.428","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 0603a6bd6..64bb8592f 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.427",+ "version": "0.1.428","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/providerAttemptAuthorizer.ts b/mcp-host/src/llm/providerAttemptAuthorizer.tsindex 4fca9c452..9c3f27ea7 100644--- a/mcp-host/src/llm/providerAttemptAuthorizer.ts+++ b/mcp-host/src/llm/providerAttemptAuthorizer.ts@@ -1,4 +1,5 @@import {+ ENVELOPE_ALLOWANCE_BYTES,LIMITS,parseAuthorizeAttemptResponse,requestBodyLimitBytes,@@ -8,12 +9,11 @@ export const AUTHORIZE_PATH = '/api/v1/mcp-host/llm/provider-attempts/authorize'/*** Room for the authorize envelope around the contract-capped `request`: ids,- * revisions, hashes and recipe names, a few hundred bytes in practice. It- * equals control-api's `AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES`- * (`llmProviderAttemptAuthorizer.ts`), so a request control-api would accept- * is never refused here for its envelope (#739).+ * 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).*/-export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = ENVELOPE_ALLOWANCE_BYTESexport class CodexAuthorizeError extends Error {constructor(diff --git a/packages/grok-provider-attempt-contract/index.cjs b/packages/grok-provider-attempt-contract/index.cjsindex fbaa8535a..2c6fc29a2 100644--- a/packages/grok-provider-attempt-contract/index.cjs+++ b/packages/grok-provider-attempt-contract/index.cjs@@ -46,6 +46,14 @@ const LIMITS = Object.freeze({maxNestingDepth: 64,})+// Room for the runtime envelope around a request held to+// `maxRequestBodyBytes`: the execution ticket (a few KB by its claim bounds),+// the request hash, the deadline, and the ids and revisions of the authorize+// body. 16 KiB is several times that. The Grok proxy imports it, and it must+// equal the Codex contract's value, which control-api and mcp-host share+// across both providers; an mcp-host test compares the two.+const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+// Deepest free-form tree root inside a request: request > messages[] >// message > toolCalls[] > call > arguments. A request that nests deeper than// this cannot pass the per-tree check, so the whole-request guard (which runs@@ -677,6 +685,7 @@ module.exports = {PROVIDER_ID,TICKET_TYP,LIMITS,+ ENVELOPE_ALLOWANCE_BYTES,TRANSPORT_PROTOCOL_VERSION,COMPLETIONS_ORIGIN,CATALOG_ORIGIN,diff --git a/packages/grok-provider-attempt-contract/index.d.ts b/packages/grok-provider-attempt-contract/index.d.tsindex d19f413d8..100227c55 100644--- a/packages/grok-provider-attempt-contract/index.d.ts+++ b/packages/grok-provider-attempt-contract/index.d.ts@@ -24,6 +24,13 @@ export declare const LIMITS: {readonly maxNestingDepth: 64}+/**+ * Room for the runtime envelope around a request held to+ * `LIMITS.maxRequestBodyBytes`. Equal to the Codex contract's value, which+ * control-api and mcp-host share across both providers.+ */+export declare const ENVELOPE_ALLOWANCE_BYTES: 16384+export type ContractResult<T> =| { ok: true; value: T }| { ok: false; code: string; message: string }diff --git a/packages/llm-provider-attempt-contract/index.cjs b/packages/llm-provider-attempt-contract/index.cjsindex 193796831..46133cb32 100644--- a/packages/llm-provider-attempt-contract/index.cjs+++ b/packages/llm-provider-attempt-contract/index.cjs@@ -49,6 +49,15 @@ const LIMITS = Object.freeze({maxNestingDepth: 64,})+// Room for the runtime envelope around a request held to+// `maxRequestBodyBytes`: the execution ticket (a few KB by its claim bounds),+// the request hash, the deadline, and the ids and revisions of the authorize+// body. 16 KiB is several times that. Both proxies, the control-api authorizer+// and the mcp-host authorizer import it, so a request one layer accepts is+// never refused by the next for its envelope. A V2 envelope is bounded by+// `maxVisualRequestBodyBytes` as a whole and gets no allowance on top of it.+const ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+// Deepest free-form tree root inside a request: request > messages[] >// message > toolCalls[] > call > arguments. A request that nests deeper than// this cannot pass the per-tree check, so the whole-request guard (which runs@@ -1008,6 +1017,7 @@ module.exports = {PROVIDER_ID,TICKET_TYP,LIMITS,+ ENVELOPE_ALLOWANCE_BYTES,VISUAL_LIMITS,requestBodyLimitBytes,measureNonImageAuthorizeBytes,diff --git a/packages/llm-provider-attempt-contract/index.d.ts b/packages/llm-provider-attempt-contract/index.d.tsindex a08539820..746f1dc1d 100644--- a/packages/llm-provider-attempt-contract/index.d.ts+++ b/packages/llm-provider-attempt-contract/index.d.ts@@ -40,6 +40,14 @@ export declare const LIMITS: {readonly maxNestingDepth: 64}+/**+ * Room for the runtime envelope around a request held to+ * `LIMITS.maxRequestBodyBytes`. The single source for both proxies, the+ * control-api authorizer and the mcp-host authorizer. A V2 envelope is bounded+ * by `LIMITS.maxVisualRequestBodyBytes` as a whole.+ */+export declare const ENVELOPE_ALLOWANCE_BYTES: 16384+/*** Conservative local safety/product budgets for V2 image parts. These are* deliberately not upstream facts: the frozen ChatGPT endpoint is not