Files
grok2api/backend/internal/application
carfeii 6ea58d3a89 fix(voice-ws): observe request timeout and bill confirmed STT duration regardless of transport outcome
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.
2026-10-05 18:21:45 +08:00
..