Free Web accounts 429 when duration exceeds 6s, which then rotates
accounts without changing the payload. Add a Grok Web setting
(freeVideoDurationCap, default 6) and clamp duration for free-tier
accounts at the Web adapter so retries are not wasted.
Codex/OpenAI Responses tools often send a root oneOf/anyOf whose
branches are $ref or nested unions. xAI/Build grammar requires a
root object or a root union of inline objects. Lift only the root
union, keep property $ref/$defs, and fail locally if the result is
still illegal.
Also treat streamed 400 JSON as ClassifyUpstreamHTTPError instead of
copyStream, so invalid-argument is request-scoped and does not rotate
accounts. Compatibility warning is function_parameters_root_normalized.
Doom-loop aborts were wrapped as a generic stream read failure, so audits
and SSE trailers reported upstream_stream_interrupted. Keep the sentinel
distinct so a model repeating the same delta is not mixed with a transport
cut.
Idle must only run while Read is waiting on Build. ConvertResponseStream
uses an unbuffered pipe, so a slow Anthropic client can block the
translator and stop those Reads; the old background timer then killed a
live summary stream as upstream_stream_idle_timeout. Client write
deadline still bounds how long we can leave upstream unread.
Encrypted reasoning is portable across accounts, so the server cache key
is session+plane only. Injected items drop content:null; xAI treats that
extra key as a modified compaction blob and 400s.
Emit summary or raw as soon as the first source arrives and drop the
other, so Claude Code is not starved while a reasoning item is still
open. Forward encrypted_content as signature_delta the moment it
appears. Native Responses SSE is already a passthrough.
Client compaction items without the g2a_compact_v1 prefix are treated as
upstream original state and sent to Build unchanged. Compact blob decode
rejections are returned to the client instead of being recovered as
opaque reasoning. Gateway-owned g2a blobs still expand locally.
After a 2xx SSE handoff, a client hangup is client_stream_interrupted and keeps the upstream status. upstream_stream_interrupted is only for an upstream cut. Pre-header 499 request_canceled is unchanged.
A timeout or lock on GetCredentialMaterial used to abort the whole
selector as no available accounts. Treat those per-account failures
like a stale claim so the rest of the pool can still be used. Request
cancellation still stops selection. Missing credentials still invalidate
the routing snapshot.
Compaction-blob 400s recovered inside the Build adapter were returned as
200 with no audit attempts. Record each hidden upstream call (stage +
what the retry did) on the successful response.
Pinned conversation acquire treated a missing/disabled owning account as
an empty pool (upstream_unavailable) even when other accounts existed.
Return upstream_pinned_account_unavailable, skip bot-flag scheduling
exclusion for pinned acquire, and persist the selection failure plus
owning account id on the audit row.
When the first account returns 429 and the next account's 2xx stream
later fails, diagnostics previously kept only the 429 row. Always
append a response_stream attempt for the handed-off account unless
one is already present.
Encrypted_content can clear the byte floor while usage still bills hundreds
of reasoning tokens against a few visible tokens. Treat that fast dump as
missing thinking even before the hold deadline.
A reasoning item start plus visible tokens at the deadline is not late
ciphertext. Treat it as missing thinking and rotate, matching the TUI
dump after 30s.
Do not skip missing-thinking intercept on previous_response_id or hosted
tools. TUI always declares those. First attempt stays pinned; withhold
unpins and rotates. Compaction with no reasoning is held unless the
gateway set skipQualityHold.
Non-empty ciphertext is not proof of reasoning. HasThinking now requires
encrypted_content / Anthropic signature to meet max(256B, 4 bytes per
usage reasoning token). A hold-expired short greeting billed as heavy
thinking, or a barely-over-floor flush in under a second, is withheld.
Recommended requestRetry values stay 30s / minOutput 8 / 6 attempts /
fail_closed / 12h / 15m idle, plus the new floor knobs. enabled remains
false so stock installs do not intercept.
Same-account recovery now strips ciphertext while rewriting readable
summaries as developer messages, continues to session reset when the
stripped retry still returns 400, and only rotates accounts after
reasoning_recovery_failed. Drop Diagnostic substring matching so
unrelated 400s do not scan the account pool.
In multi-account pools, server-side encrypted compaction blobs and reasoning states can fail to decode when a session drifts across accounts or upstream nodes, causing xAI to return HTTP 400 ("Could not decode the compaction blob").
Previously, isRetryable(400) evaluated to false in the gateway service, treating all 400 responses as non-retryable client errors. When provider reasoning recovery failed on the active account, the gateway immediately propagated the 400 to the client instead of attempting other healthy accounts in the candidate pool.
Fixes:
1. Gateway failover: Recognize reasoning_recovery_failed in isRetryableResponse so the gateway excludes the failing account and attempts the next candidate within the request attempt loop.
2. Reasoning recovery: Completely strip all reasoning items and convert compaction items to compatibility boundary messages during downgrade retries.
3. History normalization: Convert unencrypted reasoning items without portable content to developer boundary messages.
4. Error markers: Add compaction decode patterns to reasoningDecodeFailureMarkers.
Tested:
- Added TestRecoverReasoningDecodeFailureCompactionBlob
- Updated TestReasoningWithoutEncryptedContentBecomesBoundary
- All backend packages pass (go test ./...)