Skip to content

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

TypeScript

docs(subscriptions): state the V2 envelope bound and the Grok authorize 413 (#739)

Alfredo Lopez341a8b03b357
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.md
index 458df79cc..1380567bc 100644
--- a/docs/architecture/codex-subscription-transport-contract.md
+++ b/docs/architecture/codex-subscription-transport-contract.md
@@ -49,9 +49,13 @@ header dimensions; it does not decode pixels or prove image decodability.
The fixtures contain independently decoded 2x2 PNG/JPEG images.
V1 keeps the `maxRequestBodyBytes` request ceiling (8 MiB, #731); its envelope
-adds a 16 KiB allowance on the proxy and on the authorizer. V2 has a 24 MiB
-ceiling for the complete serialized request and HTTP envelope, including
-base64, history and the signed execution ticket. V2 text, tools and other
+adds a 16 KiB allowance (`ENVELOPE_ALLOWANCE_BYTES`, exported by both contract
+packages and imported by both proxies, the control-api authorizer and the Host
+authorizer). V2 has a 24 MiB ceiling for the complete serialized request and
+HTTP envelope, including base64, history and the signed execution ticket, with
+no allowance on top: the authorize route's JSON parser, the gateway's
+`client_max_body_size` and `buildCodexProxyEnvelope` all hold the whole V2
+envelope to `maxVisualRequestBodyBytes`. The ticket is about 3.5 KB of it. V2 text, tools and other
non-image fields remain bounded to `maxRequestBodyBytes`, measured with only
image data blanked in a temporary size projection; the actual request and its
hash are not modified. The two caps are not additive: a V2 request carrying a
diff --git a/docs/architecture/grok-subscription-transport-contract.md b/docs/architecture/grok-subscription-transport-contract.md
index bc0003c6e..ae533a9f3 100644
--- a/docs/architecture/grok-subscription-transport-contract.md
+++ b/docs/architecture/grok-subscription-transport-contract.md
@@ -251,7 +251,7 @@ Stable codes: `insufficient_scope`, `no_grant`, `model_not_allowed`,
`provider_unavailable`, `origin_denied`, `ticket_invalid`, `ticket_replayed`,
`request_hash_mismatch`, `client_upgrade_required`, `tool_call_limit_exceeded`,
`tool_call_arguments_exceeded`, `invalid_tool_arguments`,
-`request_limit_exceeded` (Host-side only).
+`request_limit_exceeded` (Host-side only), `payload_too_large`.
- `tool_call_limit_exceeded`: the upstream response carried more than
`maxToolCalls` tool calls. The proxy returns HTTP 422 whose body is the code
@@ -300,12 +300,9 @@ Stable codes: `insufficient_scope`, `no_grant`, `model_not_allowed`,
- `request_limit_exceeded` (Host-side only): the turn carries too much. The
Host raises it before authorization — so no provider attempt is spent — and
maps it to `LLM_CONTEXT_LENGTH_EXCEEDED`, not retryable, which the UI shows
- as "Conversation Too Long". The Host also raises it when the authorize call
- gets an HTTP 413 with no JSON error code: that response comes from the
- workflow-approval gateway's `client_max_body_size`, in front of
- control-api, and no provider attempt is spent either. The Grok proxy does
- not yet forward an upstream context-window refusal; unlike Codex, the Grok
- upstream's code for it has not been recorded.
+ as "Conversation Too Long". The Grok proxy does not yet forward an upstream
+ context-window refusal; unlike Codex, the Grok upstream's code for it has
+ not been recorded.
Four of the contract's `limit` refusals mean this, and the Host classifies on
the refusal message because `hashCanonicalGrokRequest` returns
@@ -352,6 +349,15 @@ Stable codes: `insufficient_scope`, `no_grant`, `model_not_allowed`,
them a context-length failure would invite a compaction loop that cannot
converge.
+- `payload_too_large`: an envelope over a body limit, one hop after the Host's
+ own check. The authorize hop raises it for every HTTP 413, whether
+ control-api answered `payload_too_large` or the workflow-approval gateway's
+ `client_max_body_size`, in front of control-api, answered with no JSON error
+ code (`ProviderAttemptAuthorizer`). The Host's own whole-body check before
+ authorize raises it too, and so does the proxy's 413, with or without a
+ JSON body. The Host maps it to `LLM_CONTEXT_LENGTH_EXCEEDED`, not
+ retryable. No provider attempt is spent when authorize refused it.
+
`grok_proxy_attempt_failures_total{code}` counts failed attempts. Its label
allowlist is `ATTEMPT_ERROR_STATUS` in `grok-llm-proxy/src/server.ts` — the
same table that maps a code to its HTTP status — not the list above. The table