Skip to content

Telegram Bot listener times out with TUN disabled; proxy environment variables restore message reception #5091

Open

Description

@Xiaoliang-Fan

What happened

Summary

Telegram Bot credential verification succeeds, but the message listener fails to start when TUN mode is disabled, despite a working HTTP proxy being configured in Maka's network settings.

I send messages to the Bot from my phone, and Maka runs on my Mac. The affected connection is between Maka on the Mac and Telegram—not the phone's connection.

Observed behavior:

  • TUN enabled: The Bot works.
  • TUN disabled, normal Maka launch, UI proxy enabled: Telegram listener startup fails with Fetch timeout.
  • TUN disabled, explicit proxy test using curl: The Telegram API domain responds successfully.
  • TUN disabled, Maka launched with proxy environment variables: Maka successfully receives messages sent to the Bot.

The network settings explicitly state that the proxy applies only to AI model requests. This may therefore be a missing Telegram proxy configuration path rather than a defect in the existing model proxy feature.

Actual Behavior

Credential verification succeeds. The notification says, translated from Chinese:

Telegram credentials verified. Credential check passed. This does not mean the message send/receive service has started.

Starting the Telegram service then produces:

Telegram did not enter the listening state after startup. See logs for runtime details.

Relevant logs:

[2026-09-09T07:43:20.697Z] WARN [bots:telegram] timeout: Fetch timeout
[2026-09-09T07:43:26.184Z] WARN [bots:telegram] connection_failed: Fetch timeout
[2026-09-09T07:43:26.192Z] WARN [bots:telegram] bot_connection_failed: Fetch timeout

Neither 401 Unauthorized nor 409 Conflict appears in the provided logs.

Expected Behavior

Please provide a supported way to configure Telegram Bot proxy access through Maka's UI, either by:

  1. Adding a dedicated Telegram proxy setting; or
  2. Adding an explicit option for Bot connections to reuse the existing proxy configuration.

The configured proxy should cover the relevant Telegram operations, including credential verification, listener startup, ongoing message reception, and outgoing messages.

If model and Bot proxy settings are intentionally separate, the Telegram settings should explain this and provide actionable configuration instructions.

Users should not need to enable TUN or maintain a custom command-line launcher to use a Bot through an otherwise working local proxy.

Additional Diagnostic Context

Report capture time: 2026-09-09T07:43:39.167Z.

The same report contains the following entries, but their relationship to the Telegram failure has not been established:

[2026-09-09T07:43:09.730Z] ERROR [runtime-host] Direct peer is unavailable: Error: Invalid peer reachability directRoutes

[2026-09-09T07:43:10.686Z] ERROR (node:31497) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.

[2026-09-09T07:43:11.134Z] ERROR Error occurred in handler for 'sessions:observe': Error: Session observation ended before it became ready

Runtime Host diagnostic summary:

Recent local Runtime Host process exits (0)
<none captured>

Runtime Host
Diagnostics unavailable: No Runtime Host authority was associated with this error

Questions for the Maintainers

  • Do credential verification and message listening use different networking implementations or proxy configurations?
  • What is the supported way to configure a Telegram proxy in this version?
  • Could connection errors indicate whether the failing connection is direct or proxied, with credentials redacted?

User Impact

The working command-line workaround requires maintaining proxy settings separately from Maka's UI and does not automatically apply to subsequent normal launches from the Dock. This is cumbersome for users unfamiliar with terminal commands.

How to reproduce

Preconditions

  • A local HTTP proxy is available at 127.0.0.1:7890.
  • The proxy client remains running throughout the tests.
  • TUN mode is disabled.
  • A Telegram Bot is configured in Maka.
  • The issue was observed in an environment where normal listener startup fails without TUN, while explicit proxy access to Telegram succeeds.

Reproduction Steps

  1. Fully quit Maka.
  2. Keep the local proxy client running, with TUN disabled.
  3. Launch Maka normally, without explicitly supplying proxy environment variables.
  4. Open Settings → General → Network and configure:
    • Proxy server: Enabled.
    • Protocol: HTTP/HTTPS.
    • Address: 127.0.0.1.
    • Port: 7890.
    • Proxy authentication: Disabled.
  5. The proxy bypass field displays metaso.cn, baidu.com. Do not manually add Telegram domains to the bypass list.
  6. Run Telegram Bot credential verification.
  7. Observe that credential verification succeeds.
  8. Start the Telegram service.
  9. Observe the listener startup failure and Fetch timeout logs.

The network settings description states that the proxy applies only to AI model requests.

Control Test: Verify the Proxy Without TUN

With TUN still disabled, run:

/usr/bin/curl \
  --proxy http://127.0.0.1:7890 \
  --noproxy "" \
  --connect-timeout 10 \
  --max-time 20 \
  -I https://api.telegram.org

Observed response:

HTTP/1.1 200 Connection established

HTTP/2 302
server: nginx/1.30.0
location: https://core.telegram.org/bots

This confirms that the local proxy can establish an HTTPS connection to the Telegram API domain without TUN.

This test does not use a Bot Token and does not validate authenticated Bot API calls or sustained long polling.

Workaround Test: Launch Maka With Proxy Environment Variables

  1. Fully quit Maka.
  2. Keep TUN disabled and the proxy client running.
  3. Launch Maka using:
env \
  HTTP_PROXY=http://127.0.0.1:7890 \
  HTTPS_PROXY=http://127.0.0.1:7890 \
  NODE_USE_ENV_PROXY=1 \
  /Applications/Maka.app/Contents/MacOS/Maka
  1. Restart the Telegram connection in Maka.
  2. Send a message to the Bot from the phone.

Observed result: Maka successfully receives the message.

Verification limits:

  • All three environment variables were supplied together; they were not tested individually.
  • Incoming message reception was confirmed. Full reply delivery and long-term stability were not documented.
  • This workaround only applies to this launch; it does not persist the environment variables for normal launches from the Dock.

Comparison

Configuration Observed result
TUN enabled Bot works
TUN disabled; normal launch; UI proxy enabled Listener startup fails with Fetch timeout
TUN disabled; curl explicitly uses the local proxy Telegram domain responds over HTTPS
TUN disabled; launch with proxy environment variables Incoming Bot message reception succeeds

These observations are consistent with the listener not using the UI-configured proxy during a normal launch, but the exact implementation-level cause has not been established.

Environment

Item Value
Maka version 0.2.0-dev.25.20260908
Build packaged
Update channel nightly
Operating system macOS
OS version reported by diagnostics darwin 25.6.0
Architecture arm64 (Apple Silicon)
Electron 43.4.1
Chrome 150.0.7871.224
Node 24.18.1
UI locale zh-CN
Proxy protocol configured in Maka HTTP/HTTPS
Local proxy address 127.0.0.1
Local proxy port 7890
Proxy authentication Disabled
Proxy client name and version Not recorded

Maka runs on the Mac, while messages are sent to the Telegram Bot from a phone.

The local proxy client remains running with TUN disabled during the failing case and the successful environment-variable workaround. Enabling TUN also allows the Bot to work.

Logs, screenshots, or additional context

No response

Activity

  1. added
    bug
    on Sep 9, 2026
  2. ying-hua commented on Sep 10, 2026

    @ying-hua
    Contributor

    take

  3. ying-hua commented on Sep 10, 2026

    @ying-hua
    Contributor

    I reproduced this on Windows 11 and traced it to a concrete code defect. The short version: setActiveProxy has no production caller anywhere in the repository, so the bot proxy seam is dead code and every bot request goes direct regardless of what is configured in the UI.

    Root cause

    proxiedFetch decides whether to use a proxy dispatcher by reading module state:

    https://github.com/apache/maka/blob/84255571b/packages/runtime/src/bots/proxied-fetch.ts#L42-L46

    That state is only ever written by setActiveProxy, and on main the only match outside tests is the declaration itself:

    $ git grep -n "setActiveProxy" upstream/main -- '*.ts' | grep -v __tests__
    upstream/main:packages/runtime/src/network/active-proxy-state.ts:24:export function setActiveProxy(proxy: ProxySettings | null): void {

    So resolveActiveProxy() returns null in production, the if (proxy && ...) branch is never entered, dispatcher stays undefined, and the request is made direct. Enabling TUN works because TUN intercepts at the network-stack level and needs no application-level cooperation.

    Reproduction

    Rather than driving the UI, I exercised the real compiled seam directly, so the result does not depend on any Telegram credential. Environment: Windows 11, Clash with TUN off and system proxy on at 127.0.0.1:7897. HTTP_PROXY/HTTPS_PROXY were explicitly stripped from the child process to match a normal desktop launch.

    import { proxiedFetch } from '.../packages/runtime/dist/bots/proxied-fetch.js';
    import { setActiveProxy } from '.../packages/runtime/dist/network/active-proxy-state.js';
    
    // A: production state — setActiveProxy is never called
    setActiveProxy(null);
    await proxiedFetch('https://api.telegram.org/', { method: 'GET', timeoutMs: 10_000 });
    
    // B: identical, except the seam is populated
    setActiveProxy({ enabled: true, type: 'http', host: '127.0.0.1', port: 7897,
                     bypassList: ['localhost', '127.0.0.1', '::1', '*.local'] });
    await proxiedFetch('https://api.telegram.org/', { method: 'GET', timeoutMs: 10_000 });

    Result:

    env HTTPS_PROXY = (unset)
    active proxy = null
    A. production state (setActiveProxy never called): FAILED in 10017ms -> Fetch timeout
    active proxy = {"enabled":true,"type":"http","host":"127.0.0.1","port":7897,...}
    B. after setActiveProxy(127.0.0.1:7897): HTTP 200 in 2453ms
    

    Case A is the shipped behaviour. The error string is Fetch timeout — verbatim what the reporter's log shows — and the 10s elapsed time matches TELEGRAM_REQUEST_TIMEOUT_MS = 10_000. Case B differs only by populating the seam, and succeeds in 2.4s.

    Scope

    This is not Telegram-specific. Every production proxiedFetch call site is affected on main:

    • packages/runtime/src/bots/telegram-bridge.ts
    • packages/runtime/src/bots/discord-bridge.ts
    • packages/runtime/src/bots/qq-bridge.ts
    • packages/runtime/src/bots/dingtalk-bridge.ts
    • packages/runtime/src/bots/wechat-bridge.ts
    • packages/runtime/src/bots/bot-test.ts (credential verification)
    • apps/desktop/src/main/bot-onboarding-main.ts
    • apps/desktop/src/main/qq-bot-scan-login.ts

    packages/runtime/src/connection-effect-fetch.ts also falls back to proxiedFetch, but only when no transport is injected; the Host injects one, so the model path is not affected in practice.

    Separately, getEnvWithProxy in packages/runtime/src/network/proxy-env.ts also has zero production callers — a second proxy seam that appears to have been written but never wired.

    Model requests are genuinely unaffected because they take a different route: connection-effect-coordinator.ts calls resolveNetworkProxyExecution() Host-side and passes the resolved proxy explicitly into createProxiedFetchTransport(proxy). So the settings copy saying the proxy applies only to AI model requests is an accurate description of what is implemented today.

    Why the credential check appeared to pass

    testTelegram uses the same proxiedFetch with the same 10s timeout as the listener (bot-test.ts:151), so by the code it should fail alongside it. I could not find an architectural reason for the asymmetry; my guess is environmental or timing (e.g. TUN not fully torn down at that moment). It does not change the diagnosis either way.

    Proposed fix, and one question for maintainers

    Network proxy policy lives in RuntimePolicy and is resolved Host-side with its secret, but BotRegistry is constructed in the desktop client process (apps/desktop/src/main/runtime-host-boot.ts), and the local Host is a separate spawned process. That is the actual architectural gap: bots run on the client, where the resolved proxy is simply not reachable — the protocol only exposes network-proxy.test.

    I'd like to add a network-proxy.resolve operation to the Host protocol, have HostNetworkProxyCoordinator serve it by reusing the existing resolveNetworkProxyExecution() + toProxySettings(), and have desktop main apply the result via setActiveProxy at boot and whenever network settings change.

    Two things I'd like a steer on before I send the PR:

    1. This sends the proxy password across the Host↔client boundary. SECURITY.md explicitly calls out proxiedFetch, so I want to confirm this is acceptable rather than assume it.
    2. For a remote Host the semantics are wrong: the bots run on the local machine but would inherit the remote machine's proxy policy. I plan to gate the application so the resolved proxy is only used when the active Host profile is local. Happy to change that if you'd rather see a dedicated client-side bot proxy setting instead (option 1 in the original report).

    I've claimed the issue and can have the patch up quickly once the direction is confirmed.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions