Browse Source

fix(proxy): remove duplicate cache TTL call and cache endpoint policy in local var

- Remove redundant first applyCacheTtlOverrideToMessage call (lines 1905-1917)
  that duplicated the post-Anthropic-overrides call (lines 2025-2036)
- Cache session.getEndpointPolicy() in local variable in error handling path
  to avoid repeated accessor calls

Addresses: gemini-code-assist and coderabbitai review comments
ding113 1 week ago
parent
commit
40b030df61
1 changed files with 3 additions and 16 deletions
  1. 3 16
      src/app/v1/_lib/proxy/forwarder.ts

+ 3 - 16
src/app/v1/_lib/proxy/forwarder.ts

@@ -1622,7 +1622,8 @@ export class ProxyForwarder {
             }
 
             // Raw passthrough endpoints: no circuit breaker, no provider switch, no retry
-            if (!session.getEndpointPolicy().allowRetry) {
+            const endpointPolicy = session.getEndpointPolicy();
+            if (!endpointPolicy.allowRetry) {
               logger.debug(
                 "ProxyForwarder: raw passthrough endpoint error, skipping circuit breaker and provider switch",
                 {
@@ -1630,7 +1631,7 @@ export class ProxyForwarder {
                   providerName: currentProvider.name,
                   statusCode,
                   error: proxyError.message,
-                  policyKind: session.getEndpointPolicy().kind,
+                  policyKind: endpointPolicy.kind,
                 }
               );
               // Throw immediately: no retry, no provider switch
@@ -1902,20 +1903,6 @@ export class ProxyForwarder {
     } else {
       // --- STANDARD HANDLING ---
       if (!session.getEndpointPolicy().bypassForwarderPreprocessing) {
-        if (
-          resolvedCacheTtl &&
-          (provider.providerType === "claude" || provider.providerType === "claude-auth")
-        ) {
-          const applied = applyCacheTtlOverrideToMessage(session.request.message, resolvedCacheTtl);
-          if (applied) {
-            logger.info("ProxyForwarder: Applied cache TTL override to request", {
-              providerId: provider.id,
-              providerName: provider.name,
-              cacheTtl: resolvedCacheTtl,
-            });
-          }
-        }
-
         // Codex 供应商级参数覆写(默认 inherit=遵循客户端)
         if (provider.providerType === "codex") {
           const { request: overridden, audit } = applyCodexProviderOverridesWithAudit(