mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 16:02:12 +00:00
fix: 保留推理恢复后的限流响应
This commit is contained in:
1 parent
ca8b2474bf
commit
454692cdcd
2 files changed
+42
No files matched your search
@@ -96,6 +96,13 @@ func (a *Adapter) recoverReasoningDecodeFailure(
|
||||
a.logReasoningRecovery(request, base, "encrypted_content", "recovered", retry.StatusCode, nil)
|
||||
return retry, retryURL, reasoningRecoveryOutcome{encryptedContentDowngraded: true}
|
||||
}
|
||||
if retry.StatusCode == http.StatusTooManyRequests {
|
||||
// 去除失效密文后得到的 429 是当前账号的真实上游状态。保留它,
|
||||
// 让网关进行账号冷却和切换,不能回退成已无效的初始解码 400。
|
||||
_ = original.Body.Close()
|
||||
a.logReasoningRecovery(request, base, "encrypted_content", "rate_limited", retry.StatusCode, nil)
|
||||
return retry, retryURL, reasoningRecoveryOutcome{encryptedContentDowngraded: true}
|
||||
}
|
||||
sameDecodeFailure, inspectErr := responseHasReasoningDecodeFailure(retry)
|
||||
if inspectErr != nil || !sameDecodeFailure {
|
||||
a.logReasoningRecovery(request, base, "encrypted_content", "retry_rejected", retry.StatusCode, inspectErr)
|
||||
|
||||
@@ -245,6 +245,41 @@ func TestRecoverReasoningDecodeFailureEscalatesFromOpaqueStripToSessionReset(t *
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoverReasoningDecodeFailurePreservesRateLimitAfterOpaqueStrip(t *testing.T) {
|
||||
adapter, encrypted := newReasoningRecoveryTestAdapter(t)
|
||||
var calls atomic.Int32
|
||||
adapter.http.Transport = roundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
switch calls.Add(1) {
|
||||
case 1:
|
||||
return jsonHTTPResponse(request, http.StatusBadRequest, `{"error":"Could not decode the compaction blob. Ensure it is unmodified from the compact response."}`), nil
|
||||
case 2:
|
||||
data, _ := io.ReadAll(request.Body)
|
||||
if strings.Contains(string(data), `"encrypted_content"`) {
|
||||
t.Fatalf("rate-limit recovery body still contains encrypted content: %s", data)
|
||||
}
|
||||
return jsonHTTPResponse(request, http.StatusTooManyRequests, `{"error":{"message":"rate limited"}}`), nil
|
||||
default:
|
||||
t.Fatalf("unexpected call %d", calls.Load())
|
||||
return nil, nil
|
||||
}
|
||||
})
|
||||
|
||||
response, err := adapter.ForwardResponse(t.Context(), provider.ResponseResourceRequest{
|
||||
Credential: account.Credential{ID: 1, Provider: account.ProviderBuild, EncryptedAccessToken: encrypted},
|
||||
Method: http.MethodPost, Path: "/responses", Model: "grok-4.5", PromptCacheKey: "session-1",
|
||||
Body: []byte(`{"model":"grok-4.5","input":[{"type":"reasoning","summary":[],"encrypted_content":"opaque"},{"role":"user","content":"continue"}]}`),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
body, _ := io.ReadAll(response.Body)
|
||||
warnings := response.Header.Get("X-Grok2API-Compatibility-Warnings")
|
||||
if calls.Load() != 2 || response.StatusCode != http.StatusTooManyRequests || !strings.Contains(string(body), "rate limited") || !strings.Contains(warnings, "reasoning_encrypted_content_downgraded") || strings.Contains(warnings, "reasoning_recovery_failed") {
|
||||
t.Fatalf("calls=%d status=%d warnings=%q body=%s", calls.Load(), response.StatusCode, warnings, body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoverReasoningDecodeFailureDoesNotResetStoredResponseChain(t *testing.T) {
|
||||
adapter, encrypted := newReasoningRecoveryTestAdapter(t)
|
||||
var calls atomic.Int32
|
||||
|
||||
Reference in new issue
Block a user