Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
docs: explain undeclared bodies and why the gauge skips image parts
Alfredo Lopez826e7ec586bd
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.tsindex 75110a0f8..226acca78 100644--- a/codex-llm-proxy/src/server.ts+++ b/codex-llm-proxy/src/server.ts@@ -135,9 +135,12 @@ function boundedErrorHandler(err: unknown, _req: Request, res: Response, _next:* the shared byte budget, so the bodies in memory are bounded by bytes rather* than by the stream gate's request count. A `Transfer-Encoding` body is* refused with 411 instead of being read unbounded; a non-numeric- * `Content-Length` is refused with 400. Bodies over the limit go to `parse`- * without a reservation: on the admin app express.json answers 413 from the- * header without buffering them, and on the runtime app+ * `Content-Length` is refused with 400. A request with neither header has no+ * body under HTTP/1.1 (RFC 9112 §6.3): `parse` reads nothing, and bytes sent+ * after its headers are parsed as the next request, which Node answers 400.+ * Bodies over the limit go to `parse` without a reservation: on the admin app+ * express.json answers 413 from the header without buffering them, and on the+ * runtime app* `selectTransportBudget` either answers 413 or admits them through the visual* gate. A granted body must be read and parsed within `readDeadlineMs` of the* grant, or it is answered 408 `request_timeout`, its reservation released and@@ -310,8 +313,9 @@ export function createProxyApps(// above the ordinary cap can be a visual envelope. Those bodies take the// 2-wide gate (the image bytes stay resident for the ChatGPT stream). Every// smaller body, including every valid V1, stays on the ordinary parser and- // later the 8-wide stream gate. A missing length cannot be upgraded: it is- // parsed at the ordinary cap, so a chunked caller cannot occupy a visual slot.+ // later the 8-wide stream gate. A missing length cannot be upgraded: body+ // admission already refused a chunked body with 411, and a request with+ // neither header has no body, so only a declared length takes a visual slot.const selectTransportBudget = (req: GatedRequest, res: Response, next: NextFunction): void => {const declared = contentLengthBytes(req)if (declared !== null && declared > config.maxVisualBodyBytes) {diff --git a/grok-llm-proxy/src/server.ts b/grok-llm-proxy/src/server.tsindex bd7a6ce6c..162541b28 100644--- a/grok-llm-proxy/src/server.ts+++ b/grok-llm-proxy/src/server.ts@@ -115,8 +115,10 @@ function boundedErrorHandler(err: unknown, _req: Request, res: Response, _next:* the shared byte budget, so the bodies in memory are bounded by bytes rather* than by the stream gate's request count. A `Transfer-Encoding` body is* refused with 411 instead of being read unbounded; a non-numeric- * `Content-Length` is refused with 400. Bodies over the limit go to `parse`- * without a reservation, so express.json answers 413 from the header without+ * `Content-Length` is refused with 400. A request with neither header has no+ * body under HTTP/1.1 (RFC 9112 §6.3): `parse` reads nothing, and bytes sent+ * after its headers are parsed as the next request, which Node answers 400.+ * Bodies over the limit go to `parse` without a reservation, so express.json answers 413 from the header without* buffering them. A granted body must be read and parsed within* `readDeadlineMs` of the grant, or it is answered 408 `request_timeout`, its* reservation released and its connection closed. Otherwise the reservation isdiff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 4fa2d45b5..661c329b3 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.435",+ "version": "0.1.436","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.435",+ "version": "0.1.436","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 3b64c7700..6333755e4 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.435",+ "version": "0.1.436","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/tokenizer/heuristic.ts b/mcp-host/src/core/tokenizer/heuristic.tsindex 93edeae3f..d5ead051b 100644--- a/mcp-host/src/core/tokenizer/heuristic.ts+++ b/mcp-host/src/core/tokenizer/heuristic.ts@@ -27,6 +27,14 @@* decides the tier from this heuristic and uses an exact counter only to record* the delta. It is exact nowhere — it ignores `contentParts` and* provider-specific framing.+ *+ * Ignoring `contentParts` is deliberate. Their text is also in `content`, which+ * is counted. Their image bytes are not tokens: providers price an image by its+ * dimensions, and `bytes / 4` would read one 3 MiB image as ~1M tokens, forcing+ * a truncation that cannot remove it, because the image sits in the protected+ * tail. Image bytes are bounded by their own budgets instead: the contract+ * measures `maxRequestBodyBytes` without them and caps them through+ * `maxVisualRequestBodyBytes` and `VISUAL_LIMITS`.*/import type { ChatMessage, ToolDefinition } from '../types'