fix: preserve telegram proxy on gateway restart after doctor (#546)

Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
Lingxuan Zuo
2026-03-21 17:09:08 +08:00
committed by GitHub
Unverified
parent e10ff3a1fb
commit 56701d823c
11 changed files with 122 additions and 5 deletions

View File

@@ -3,11 +3,22 @@ import { resolveProxySettings, type ProxySettings } from './proxy';
import { logger } from './logger';
import { withConfigLock } from './config-mutex';
interface SyncProxyOptions {
/**
* When true, keep an existing channels.telegram.proxy value if proxy is
* currently disabled in ClawX settings.
*/
preserveExistingWhenDisabled?: boolean;
}
/**
* Sync ClawX global proxy settings into OpenClaw channel config where the
* upstream runtime expects an explicit per-channel proxy knob.
*/
export async function syncProxyConfigToOpenClaw(settings: ProxySettings): Promise<void> {
export async function syncProxyConfigToOpenClaw(
settings: ProxySettings,
options: SyncProxyOptions = {},
): Promise<void> {
return withConfigLock(async () => {
const config = await readOpenClawConfig();
const telegramConfig = config.channels?.telegram;
@@ -17,11 +28,17 @@ export async function syncProxyConfigToOpenClaw(settings: ProxySettings): Promis
}
const resolved = resolveProxySettings(settings);
const preserveExistingWhenDisabled = options.preserveExistingWhenDisabled !== false;
const nextProxy = settings.proxyEnabled
? (resolved.allProxy || resolved.httpsProxy || resolved.httpProxy)
: '';
const currentProxy = typeof telegramConfig.proxy === 'string' ? telegramConfig.proxy : '';
if (!settings.proxyEnabled && preserveExistingWhenDisabled && currentProxy) {
logger.info('Skipped Telegram proxy sync because ClawX proxy is disabled and preserve mode is enabled');
return;
}
if (!nextProxy && !currentProxy) {
return;
}