Skip to content

[Bug]: Codex provider usage ignores proxy env and reports fetch failed #78714

@TnzGit

Description

@TnzGit

Bug type

Behavior bug (incorrect provider usage state)

Summary

On OpenClaw 2026.5.5, Codex provider usage fails with fetch failed in an environment where direct Node fetch() to chatgpt.com times out, but HTTP_PROXY / HTTPS_PROXY is configured and a proxy-aware fetch succeeds.

The failing path appears to be loadProviderUsageSummary() selecting plain fetch for provider usage snapshots instead of preferring the existing proxy-aware fetch helper from environment proxy settings.

Environment

  • OpenClaw: 2026.5.5 (b1abf9d)
  • OS: Ubuntu 24.04.4 LTS, Linux 6.17.0-22-generic, x86_64
  • Node.js: v22.22.2
  • Install: npm global via nvm
  • Provider: openai-codex OAuth
  • Proxy: local HTTP proxy configured through HTTP_PROXY / HTTPS_PROXY / lowercase variants

Steps to reproduce

  1. Run OpenClaw with an openai-codex OAuth profile.
  2. Use a network where direct Node fetch to https://chatgpt.com/backend-api/wham/usage times out, but an HTTP proxy is available and configured in env.
  3. Run:
openclaw status --usage --json
  1. Or open the Control UI usage/provider quota surface.

Expected behavior

openclaw status --usage --json should use the configured proxy path for Codex usage fetches and return Codex quota windows, for example:

{
  "provider": "openai-codex",
  "displayName": "Codex",
  "windows": [
    { "label": "5h", "usedPercent": 2 },
    { "label": "Week", "usedPercent": 22 }
  ],
  "plan": "..."
}

Actual behavior

Before a local patch, the usage payload consistently returned:

{
  "provider": "openai-codex",
  "displayName": "Codex",
  "windows": [],
  "error": "fetch failed"
}

Evidence

Direct Node fetch tried to connect directly and timed out:

{
  "ok": false,
  "name": "TypeError",
  "message": "fetch failed",
  "causeName": "AggregateError",
  "errors": [
    { "code": "ETIMEDOUT", "address": "103.56.16.112" },
    { "code": "ENETUNREACH", "address": "2001::80f2:f03b" }
  ]
}

The same URL succeeds when routed through OpenClaw's proxy-aware helper:

import { makeProxyFetch } from "openclaw/dist/plugin-sdk/fetch-runtime.js";

const fetchFn = makeProxyFetch("http://127.0.0.1:7890");
const res = await fetchFn("https://chatgpt.com/backend-api/wham/usage");
console.log(res.status); // 401 without auth, proving the network path works

Using the packaged helper directly also works:

const fetchFn = resolveProxyFetchFromEnv(process.env);
const res = await (fetchFn ?? fetch)("https://chatgpt.com/backend-api/wham/usage");
console.log(res.status); // 401 without auth

Local fix confirmation

In the packaged 2026.5.5 bundle, provider-usage-BIeUuUeN.js had:

const fetchFn = resolveFetch(opts.fetch);

I locally patched it to prefer env proxy fetch:

import { i as resolveProxyFetchFromEnv } from "./proxy-fetch-CSerR6bC.js";

const fetchFn = opts.fetch ?? resolveProxyFetchFromEnv(env) ?? resolveFetch();

After restarting the gateway, the same command returned Codex usage windows and plan data:

{
  "provider": "openai-codex",
  "displayName": "Codex",
  "windows": [
    { "label": "5h", "usedPercent": 2 },
    { "label": "Week", "usedPercent": 22 }
  ],
  "plan": "..."
}

Suspected root cause

src/infra/provider-usage.load.ts / the packaged provider-usage runtime appears to resolve the fetch function with:

resolveFetch(opts.fetch)

This misses the already available proxy-aware path for provider usage requests when the operator relies on proxy env vars and direct Node fetch cannot reach chatgpt.com.

Suggested fix

Make provider usage loading proxy-aware by default, for example:

const fetchFn = opts.fetch ?? resolveProxyFetchFromEnv(env) ?? resolveFetch();

Alternatively, ensure this usage path reliably bootstraps the same env-proxy Undici dispatcher used by other provider/runtime network paths before fetchCodexUsage() is called.

Related but distinct issues checked

This report is narrower: Codex provider usage is implemented, auth is valid, and the failure disappears when provider-usage uses the env proxy fetch helper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions