fix: queue env-enabled platforms for background reconnect after fatal error - #71285
Closed
lowband wants to merge 1 commit into
Closed
fix: queue env-enabled platforms for background reconnect after fatal error#71285lowband wants to merge 1 commit into
lowband wants to merge 1 commit into
Conversation
… error Platforms enabled via .env (e.g. TELEGRAM_BOT_TOKEN) are not present in config.yaml's gateway.platforms dict. When such a platform hits a retryable fatal error (e.g. 10 consecutive network failures), _handle_adapter_fatal_error looked up self.config.platforms.get(platform) which returned None, so the platform was never queued into _failed_platforms. The background reconnect watcher therefore never tried to recover it, and the gateway stayed alive but deaf until manual restart. The existing 'stranded' guard (added in a prior commit) exits the gateway so the service manager can restart it — but this is a workaround that converts a transient outage into a restart loop, losing in-process state. This fix addresses the root cause: when platform_config is None, build a minimal PlatformConfig from the env vars that were used to start the adapter originally (via PLATFORM_TOKEN_ENV_NAMES), so the reconnect watcher can recover the platform without a full gateway restart.
Contributor
|
Closing. The premise — that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Platforms enabled via
.env(e.g.TELEGRAM_BOT_TOKEN) are not present inconfig.yaml'sgateway.platformsdict. When such a platform hits a retryable fatal error (e.g. 10 consecutive network failures during a proxy outage),_handle_adapter_fatal_error_implcallsself.config.platforms.get(adapter.platform)which returnsNone, so the platform is never queued into_failed_platforms. The background reconnect watcher therefore never tries to recover it.Observed behavior: Gateway process stays alive (other platforms still connected), but Telegram adapter is deaf. Messages sent from Telegram are silently dropped until manual gateway restart. In the reported case, the outage lasted 1h47m before the user noticed and restarted manually.
Root Cause
The existing
strandedguard (added in a prior commit to mitigate this) exits the gateway so the service manager restarts it. But this is a workaround, not a root-cause fix: it converts a transient outage into a restart loop, losing in-process state (active sessions, cron context, etc.) every time.Fix
When
platform_configisNone, build a minimalPlatformConfigfrom the same env vars that were used to start the adapter originally, using the existingPLATFORM_TOKEN_ENV_NAMESmapping:The fallback reads
PLATFORM_TOKEN_ENV_NAMES[platform](e.g.TELEGRAM_BOT_TOKEN) and{PLATFORM}_HOME_CHANNELfromos.environ, constructs aPlatformConfig(token=..., home_channel=..., enabled=True). This lets the reconnect watcher recover the platform without a full gateway restart.Testing
Unit tests verify:
_build_env_fallback_platform_configcorrectly constructsPlatformConfigfrom env varsNonewhen env vars are absent (no false queueing)_failed_platformsconfig.platformshas no Telegram entry, retryable fatal error → platform correctly queuedScope
config.yamlPLATFORM_TOKEN_ENV_NAMES)strandedguard remains as a safety net for any edge case the fallback doesn't cover