Repository navigation
fix(sse): count gate/combo-rejected requests in per-api-key usage - #6698
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema (reportado via suporte, 2026-07-08)
Uma API key do OmniRoute exibia "zero requisições" apesar de ter recebido tráfego real.
Causa-raiz: requests rejeitadas antes de
handleChatCore— rejeição de pipeline-gate (provider circuit breaker OPEN / model cooldown) ou combo com todos os alvos exaustos — davam short-circuit emsrc/sse/handlers/chat.tsgravando apenas uma linha emcall_logs(visível em/dashboard/logs). Elas nunca alcançavampersistFailureUsage, então nenhuma linha emusage_historyera criada — e o contador de uso por API key (getApiKeyUsageRows, que lêusage_history) nunca incrementava. Uma key cujo tráfego foi inteiramente rejeitado por gate/breaker aparecia zerada.Fix
Ambos os caminhos de rejeição passam a chamar
recordRejectedRequestUsage(), que grava:call_logs(visibilidade em/dashboard/logs— inalterada), eusage_historyatribuída à API key comsuccess:false, espelhando a semântica dopersistFailureUsagedo caminho de falha pós-executor.Os campos
apiKeyId/apiKeyNamejá estavam em escopo nos dois callsites, mas eram descartados.Arquivos
src/sse/handlers/rejectedRequestUsage.ts(novo) — helper que grava as duas tabelas.src/sse/handlers/chat.ts— os dois branches de rejeição (combo exausto + pipeline-gate) usam o helper.tests/unit/rejected-request-usage.test.ts(novo) — regression guard.Validação (Hard Rule #18 — TDD)
usage_historycomapi_key_id+success:false(antes: ausente).18/18testes verdes (2 novos + 16 de usage relacionados). Lint 0 erros. Typecheck dos arquivos alterados limpo.