Two issues in the voice/STT WebSocket proxy:
1. The established proxy never watched c.Request.Context().Done(), so
server.requestTimeout had no effect on a quiet, already-admitted
session: the account lease, concurrency slot, and upstream connection
stayed open past the configured deadline until a transport error
occurred on either side. Added a watcher that closes the session once
the request context is canceled, extracted as watchRequestTimeout so
it is unit-testable without a real WebSocket upgrade.
2. STT billing was gated on the downstream client closing cleanly
(successful == ErrorCode == ""), even though the cost is already
incurred the moment the upstream sends a confirmed transcript.done
duration. A client that received a complete transcription and then
disconnected abnormally left EstimatedCostInUSDTicks at zero,
understating usage against the key's billing limit. Billing is now
keyed on having a confirmed duration, not on how the transport ended.
Every other account-selection path (text chat, image generation, voice,
voice websocket) threads the requesting client key's AccountScope through
to beginSelectionSessionForKey. The video job's background retry/recovery
worker (runVideoJob) used the unscoped beginSelectionSession instead, so
once the job's originally pinned account failed, the fallback search for a
replacement ignored the client key's provider/tier restrictions entirely.
A client key restricted to e.g. Super-tier accounts could end up consuming
a Free-tier (or wrong-provider) account's quota purely because its pinned
account hit a transient failure, silently widening access beyond what the
key was configured to allow.
media.Job already stores ClientKeyID, so the fix looks up that key and
passes its AccountScope into beginSelectionSessionForKey, matching every
other selection path. Added a regression test
(TestVideoRetryDoesNotEscapeClientKeyAccountScope) that fails against the
prior code (confirmed: the out-of-scope account was used) and passes with
the fix.
xAI's device approval now renders a consent page on accounts.x.ai
containing a hidden consent_token JWT, and POSTs to
auth.x.ai/oauth2/device/approve without it — or without the
Origin/Referer/Sec-Fetch headers a real form submit carries — return
403 'Request could not be verified'. Web→Build conversion failed for
every account.
After the verify 303, GET the consent page, scrape consent_token, and
POST it back with browser-style navigation headers. Verified live
against auth.x.ai: approve now 303s to /oauth2/device/done and the
token endpoint returns access+refresh tokens.
requestRetry still leaked grok-4.6 dumps after the short-usage patch:
fake-enc/burst required visible >= minOutput, plaintext thinking vetoed
the dump detectors, and chat usage.completion inflated visible tokens.
Withhold when reasoning>=80 or ciphertext meets the floor and the visible
flush is <2s. Plaintext thinking still withholds if flush<2s and
reasoning/output >= 0.8. Cipher-only HasThinking waits until visible text
has streamed for 2s, or the stream ends. Visible tokens come from
streamed content only.
Does not enable requestRetry and does not change lab Docker/VERSION
defaults.