Skip to content

fix(gateway): ensure undici env proxy dispatcher after startup#63490

Closed
bowenluo718 wants to merge 1 commit intoopenclaw:mainfrom
bowenluo718:fix/gateway-undici-env-proxy-dispatcher
Closed

fix(gateway): ensure undici env proxy dispatcher after startup#63490
bowenluo718 wants to merge 1 commit intoopenclaw:mainfrom
bowenluo718:fix/gateway-undici-env-proxy-dispatcher

Conversation

@bowenluo718
Copy link
Copy Markdown

Summary

Describe the problem and fix in 2–5 bullets:

If this PR fixes a plugin beta-release blocker, title it fix(<plugin-id>): beta blocker - <summary> and link the matching Beta blocker: <plugin-name> - <summary> issue labeled beta-blocker. Contributors cannot label PRs, so the title is the PR-side signal for maintainers and automation.

  • Problem:
  • Why it matters:
  • What changed:
  • What did NOT change (scope boundary):

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause:
  • Missing detection / guardrail:
  • Contributing context (if known):

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write N/A.

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file:
  • Scenario the test should lock in:
  • Why this is the smallest reliable guardrail:
  • Existing test that already covers this (if any):
  • If no new test is added, why not:

User-visible / Behavior Changes

List user-visible changes (including defaults/config).
If none, write None.

Diagram (if applicable)

For UI changes or non-trivial logic flows, include a small ASCII diagram reviewers can scan quickly. Otherwise write N/A.

Before:
[user action] -> [old state]

After:
[user action] -> [new state] -> [result]

Security Impact (required)

  • New permissions/capabilities? (Yes/No)
  • Secrets/tokens handling changed? (Yes/No)
  • New/changed network calls? (Yes/No)
  • Command/tool execution surface changed? (Yes/No)
  • Data access scope changed? (Yes/No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS:
  • Runtime/container:
  • Model/provider:
  • Integration/channel (if any):
  • Relevant config (redacted):

Steps

Expected

Actual

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
  • Edge cases checked:
  • What you did not verify:

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No)
  • Config/env changes? (Yes/No)
  • Migration needed? (Yes/No)
  • If yes, exact upgrade steps:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk:
    • Mitigation:

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Apr 9, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 9, 2026

Greptile Summary

This PR adds a call to ensureGlobalUndiciEnvProxyDispatcher() during gateway startup in startGatewayServer, ensuring the undici global dispatcher is switched to EnvHttpProxyAgent early in the process when an env proxy is configured. Previously, this bootstrapping only happened lazily, per caller (e.g., in provider-openai-codex-oauth.ts, minimax-vlm.ts, and per-attempt in attempt.ts), meaning gateway-level HTTP traffic prior to the first agent run could bypass the configured proxy. The placement after the async startup maintenance steps is intentional.

Confidence Score: 5/5

Safe to merge; the change is minimal, idempotent, and well-tested by existing coverage.

Only finding is a P2 suggestion to pair the call with ensureGlobalUndiciStreamTimeouts for timeout consistency during the startup-to-first-run window. This does not block merge — the agent-run path already applies timeouts correctly, and the window without timeouts is narrow and likely idle.

No files require special attention.

Vulnerabilities

No security concerns identified. The change routes outbound undici traffic through the env-configured proxy at gateway startup rather than only per-caller; this is a consistency improvement, not a new attack surface.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server.impl.ts
Line: 597-598

Comment:
**Missing `ensureGlobalUndiciStreamTimeouts` companion call**

The `EnvHttpProxyAgent` installed here has no timeout options set (`bodyTimeout`, `headersTimeout`). In `attempt.ts`, both functions are always called together — `ensureGlobalUndiciEnvProxyDispatcher()` then `ensureGlobalUndiciStreamTimeouts()` — so the agent-run path is fine. However, any gateway-level undici traffic that occurs between startup and the first agent run will go through a proxy dispatcher with no explicit stream timeouts. If that window is expected to be idle, this is acceptable; otherwise, consider pairing the calls here the same way `attempt.ts` does.

```suggestion
  // Ensure the env-based proxy dispatcher runs after startup so outbound traffic uses a consistent network profile.
  ensureGlobalUndiciEnvProxyDispatcher();
  ensureGlobalUndiciStreamTimeouts();
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(gateway): ensure undici env proxy di..." | Re-trigger Greptile

Comment thread src/gateway/server.impl.ts Outdated
Comment on lines +597 to +598
// Ensure the env-based proxy dispatcher runs after startup so outbound traffic uses a consistent network profile.
ensureGlobalUndiciEnvProxyDispatcher();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing ensureGlobalUndiciStreamTimeouts companion call

The EnvHttpProxyAgent installed here has no timeout options set (bodyTimeout, headersTimeout). In attempt.ts, both functions are always called together — ensureGlobalUndiciEnvProxyDispatcher() then ensureGlobalUndiciStreamTimeouts() — so the agent-run path is fine. However, any gateway-level undici traffic that occurs between startup and the first agent run will go through a proxy dispatcher with no explicit stream timeouts. If that window is expected to be idle, this is acceptable; otherwise, consider pairing the calls here the same way attempt.ts does.

Suggested change
// Ensure the env-based proxy dispatcher runs after startup so outbound traffic uses a consistent network profile.
ensureGlobalUndiciEnvProxyDispatcher();
// Ensure the env-based proxy dispatcher runs after startup so outbound traffic uses a consistent network profile.
ensureGlobalUndiciEnvProxyDispatcher();
ensureGlobalUndiciStreamTimeouts();
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server.impl.ts
Line: 597-598

Comment:
**Missing `ensureGlobalUndiciStreamTimeouts` companion call**

The `EnvHttpProxyAgent` installed here has no timeout options set (`bodyTimeout`, `headersTimeout`). In `attempt.ts`, both functions are always called together — `ensureGlobalUndiciEnvProxyDispatcher()` then `ensureGlobalUndiciStreamTimeouts()` — so the agent-run path is fine. However, any gateway-level undici traffic that occurs between startup and the first agent run will go through a proxy dispatcher with no explicit stream timeouts. If that window is expected to be idle, this is acceptable; otherwise, consider pairing the calls here the same way `attempt.ts` does.

```suggestion
  // Ensure the env-based proxy dispatcher runs after startup so outbound traffic uses a consistent network profile.
  ensureGlobalUndiciEnvProxyDispatcher();
  ensureGlobalUndiciStreamTimeouts();
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been revised according to the feedback.

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 26, 2026

Closing this as implemented after Codex automated review.

Current main already implements PR #63490's central gateway env-proxy bootstrap. startGatewayServer now calls a gateway network bootstrap helper at startup, the helper installs the Undici env proxy dispatcher, regression tests cover direct gateway startup with HTTPS_PROXY, and the changelog records the fix under #71833. The account-id hunk from #63490 is also already present on main.

Best possible solution:

Close #63490 as implemented on current main. Keep the maintained gateway startup bootstrap in src/gateway/server-network-runtime.ts/src/gateway/server.impl.ts; any separate decision to apply global Undici stream timeouts at gateway startup should be tracked as a distinct issue because current main keeps timeout tuning on the embedded-attempt path.

What I checked:

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against d54d2d6b9b8a; fix evidence: commit d54d2d6b9b8a.

@clawsweeper clawsweeper Bot closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant