TencentCloud/TencentDB-Agent-Memory · error

Upstream request failed

Error message

Upstream request failed

What it means

forwardWithRetry in the Anthropic handler gives up forwarding the request to the upstream provider after exhausting the retry loop. When the final retry attempt itself fails (and it is not a rate-limit error that must propagate), it logs the underlying cause (timeout duration or the retry error) and throws a generic Error('Upstream request failed'), deliberately discarding the original error's identity from the caller.

Source

Thrown at MemoryProxy/src/anthropicHandler.ts:509

        method: "POST",
        headers: retryHeaders,
        body: JSON.stringify(originalBody),
        signal: AbortSignal.timeout(forwardTimeoutMs),
      });
      if (upstreamResp.ok) {
        pipe.info("RETRY_SUCCESS", `Retry returned ${upstreamResp.status}`);
      } else {
        pipe.error("RETRY_FAILED", `Retry returned ${upstreamResp.status}`);
      }
      return { resp: upstreamResp, retried: true };
    } catch (retryErr: unknown) {
      if (isRateLimitExceededError(retryErr)) throw retryErr;
      if (retryErr instanceof DOMException && retryErr.name === "TimeoutError") {
        pipe.error("RETRY_FORWARD", `Timeout after ${forwardTimeoutMs / 1000}s`);
      } else {
        pipe.error("RETRY_FORWARD", retryErr);
      }
      throw new Error("Upstream request failed");
    }
  }

  if (forwardFailed && !shouldRetry) {
    throw new Error("Upstream request failed");
  }

  if (!upstreamResp) {
    throw new Error("No upstream response available");
  }

  return { resp: upstreamResp, retried: false };
}

/** Main handler for POST /v1/messages (Anthropic Messages API). */
export async function handleAnthropicMessages(
  c: Context,
  config: ProxyConfig,

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Check the logs for the RETRY_FORWARD entry immediately preceding this error to see the real cause (timeout vs network error)
  2. Increase forwardTimeoutMs if the last attempt was a timeout on large payloads
  3. Verify upstream endpoint reachability from the proxy host (curl the upstream URL)
  4. Inspect isRateLimitExceededError coverage — genuine 429s should propagate rather than be masked by this generic error

Example fix

// before
throw new Error("Upstream request failed");
// after
const cause = retryErr instanceof DOMException && retryErr.name === "TimeoutError"
  ? `timeout after ${forwardTimeoutMs / 1000}s`
  : String(retryErr);
throw new Error(`Upstream request failed: ${cause}`, { cause: retryErr });
Defensive patterns

Strategy: retry

Validate before calling

const upstreamOk = await fetch(upstreamBaseUrl, { method: 'HEAD', signal: AbortSignal.timeout(3000) }).then(r => r.ok || r.status < 500).catch(() => false);
if (!upstreamOk) throw new Error('upstream unreachable before forwarding');

Type guard

function isUpstreamFailure(e: unknown): boolean {
  return e instanceof Error && e.message === 'Upstream request failed';
}

Try / catch

try {
  return await forwardWithRetry(req, pipe);
} catch (e) {
  if (isUpstreamFailure(e)) {
    // check pipe logs for RETRY_FORWARD cause; back off and requeue once
    await sleep(1000);
    return forwardWithRetry(req, pipe);
  }
  throw e;
}

Prevention

When it happens

Trigger: All forward attempts to the Anthropic upstream failed: network errors, connection refused, timeouts (TimeoutError after forwardTimeoutMs), 5xx responses consumed by retry logic, or fetch throwing mid-body on the last attempt — with the failure occurring inside the retry loop.

Common situations: Upstream provider outage or degraded region; forwardTimeoutMs too small for large requests; DNS/proxy misconfiguration in the runtime; rate-limit errors interleaved with other failures.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/e5bc7cc25052b31e. Report an issue: GitHub.