Telegram: skip global dispatcher replacement when autoSelectFamily is disabled#26890
Telegram: skip global dispatcher replacement when autoSelectFamily is disabled#26890MarkShawn2020 wants to merge 3 commits intoopenclaw:mainfrom
Conversation
… is enabled Replacing the global dispatcher unconditionally (even with autoSelectFamily=false) swaps in a bare Agent that discards any configuration the original default dispatcher carried. This breaks other HTTP clients in the same process — notably LLM provider fetches (e.g. Anthropic API) which return HTTP 403 after the dispatcher swap. Only replace the dispatcher when autoSelectFamily is explicitly true, which is the only case where the workaround is actually needed. Fixes openclaw#23600 Related: openclaw#25682, openclaw#25676 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
src/telegram/fetch.ts
Outdated
| autoSelectDecision.value === true && | ||
| autoSelectDecision.value !== appliedGlobalDispatcherAutoSelectFamily |
There was a problem hiding this comment.
redundant comparison on line 51 - autoSelectDecision.value is already true from line 50
| autoSelectDecision.value === true && | |
| autoSelectDecision.value !== appliedGlobalDispatcherAutoSelectFamily | |
| if (autoSelectDecision.value === true) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/fetch.ts
Line: 50-51
Comment:
redundant comparison on line 51 - `autoSelectDecision.value` is already `true` from line 50
```suggestion
if (autoSelectDecision.value === true) {
```
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
The test expectation at line 174 ( Prompt To Fix With AIThis is a comment left during a code review.
Path: src/telegram/fetch.ts
Line: 171-189
Comment:
test will fail - expects dispatcher to be called twice when changing from `true` to `false`, but the new logic only replaces dispatcher when `autoSelectFamily === true`
The test expectation at line 174 (`expect(setGlobalDispatcher).toHaveBeenCalledTimes(2)`) will fail because the second call with `autoSelectFamily: false` will no longer trigger `setGlobalDispatcher()`. Update this test to verify that the dispatcher is NOT replaced when switching to `false`.
How can I resolve this? If you propose a fix, please make it concise. |
The test now verifies that switching from autoSelectFamily=true to false does NOT replace the global dispatcher a second time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@MarkShawn2020 I see the intent here (avoid replacing the global dispatcher with a bare agent when One behavior concern: once Could we either (a) restore the previous dispatcher when disabled, or (b) explicitly document this sticky behavior and add a regression test for true -> false transitions? |
Address review feedback: when autoSelectFamily switches from true to false, restore the original global dispatcher instead of leaving the replacement sticky for the process lifetime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@bmendonca3 Great catch — updated in 33991d9. Now the original dispatcher is saved via |
|
The
Neither touches telegram or the global dispatcher logic. |
|
This pull request has been automatically marked as stale due to inactivity. |
Summary
autoSelectFamilyis explicitlytruefalse), swapping in a bareAgentthat discards the original dispatcher's configurationRoot Cause
setGlobalDispatcher(new Agent({connect: {autoSelectFamily, ...}}))creates a minimal Agent with only theautoSelectFamilyconnect option. The original default dispatcher may carry additional state/configuration that other HTTP clients depend on. Replacing it unconditionally causes those clients to fail.Reproduction
channels.telegram.proxy)auth.profiles.anthropic:defaultwithtype: api_key)[agent/embedded] embedded run agent end: isError=true error=HTTP 403 forbidden: Request not allowedFix
Only call
setGlobalDispatcher()whenautoSelectFamily === true(the IPv4 fallback workaround). Whenfalseornull, the default dispatcher is left untouched.Test plan
pnpm buildpassespnpm test—src/telegram/fetch.test.ts)Fixes #23600
Related: #25682, #25676
🤖 Generated with Claude Code
Greptile Summary
Prevents unintended global undici dispatcher replacement when
autoSelectFamilyisfalseornull, fixing HTTP 403 errors in LLM provider API calls. The previous implementation unconditionally replaced the dispatcher (even withfalse), discarding the original dispatcher's configuration. Now only replaces when explicitlytrueto preserve the IPv4 fallback workaround while protecting other HTTP clients in the process.autoSelectFamily === true(src/telegram/fetch.ts:50)truein Agent config (src/telegram/fetch.ts:51-57)truevalue (src/telegram/fetch.ts:62-63)Test Impact: The test at
src/telegram/fetch.test.ts:171-189("updates global dispatcher when autoSelectFamily decision changes") expectssetGlobalDispatcherto be called twice when switching fromtruetofalse, but with this change it will only be called once. This test needs to be updated to match the new behavior.Confidence Score: 3/5
Last reviewed commit: 7ad40a1
(2/5) Greptile learns from your feedback when you react with thumbs up/down!