TencentCloud/TencentDB-Agent-Memory · error

Upstream request failed

Error message

Upstream request failed

What it means

The OpenAI-style handler.ts forwardWithRetry mirrors the Anthropic one: when the final retry attempt fails (excluding rate-limit errors that must propagate), the cause is logged via pipe.error('RETRY_FORWARD', ...) and a generic Error('Upstream request failed') is thrown. The generic message intentionally hides the underlying timeout/network detail from callers.

Source

Thrown at MemoryProxy/src/handler.ts:426

      };
      if (forwardTimeoutMs > 0) {
        retryFetchOpts.signal = AbortSignal.timeout(forwardTimeoutMs);
      }
      upstreamResp = await fetch(target.retryTarget.url, retryFetchOpts);
      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/chat/completions (OpenAI compat). */
export async function handleChatCompletions(
  c: Context,
  config: ProxyConfig,

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Read the RETRY_FORWARD log entry emitted just before the throw to identify timeout vs network error
  2. Increase forwardTimeoutMs if timeouts occur on long generations
  3. Verify egress connectivity/proxy settings from the proxy host to the upstream provider
  4. Enable longer/backoff retry or circuit-breaking upstream failover if available

Example fix

// before
throw new Error("Upstream request failed");
// after
throw new Error("Upstream request failed", { cause: retryErr }); // preserve timeout/network detail for callers
Defensive patterns

Strategy: retry

Validate before calling

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

Type guard

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

Try / catch

try {
  return await forwardWithRetry(req, pipe);
} catch (e) {
  if (isUpstreamRequestFailed(e) && !isRateLimitExceededError(e)) {
    await backoff(retryCount++);
    return forwardWithRetry(req, pipe);
  }
  throw e;
}

Prevention

When it happens

Trigger: Every forward attempt to the upstream LLM provider failed within the retry loop — final attempt threw (network error, reset, or TimeoutError after forwardTimeoutMs), or returned a retryable failure that then exhausted attempts.

Common situations: Provider outage, aggressive forwardTimeoutMs for slow completions, corporate proxy blocking egress, upstream 5xx storms exhausting the retry budget.

Related errors


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