fix(gateway): clear stale platform status when adapter creation fails - #88305
Open
sclife2003 wants to merge 1 commit into
Open
fix(gateway): clear stale platform status when adapter creation fails#88305sclife2003 wants to merge 1 commit into
sclife2003 wants to merge 1 commit into
Conversation
The gateway records per-platform runtime status in gateway_state.json, which the status and monitor surfaces read. When _create_adapter() returns None the startup loop logs a warning and continues without touching that platform's stored status, so a platform that connected in a previous life keeps its "connected" flag once its adapter stops building -- a platform that is entirely down still reads as up. Write a failed/adapter_unavailable status on that path so the stored state matches reality. gateway_health already classifies "failed" as a fatal platform state, so health surfaces report it as down.
sclife2003
force-pushed
the
patch/clear-stale-platform-status
branch
from
August 17, 2026 09:38
ab8a6e5 to
53cfca0
Compare
18 tasks
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.
What does this PR do?
In the platform startup loop, every path keeps
gateway_state.jsonup to date except one._update_platform_runtime_status()is called in 16 places ingateway/run.py, and the block right after this one setsconnectingbefore the adapter connects. But when_create_adapter()returnsNone, the loop logs a warning and goes straight tocontinue:Nothing writes that platform's entry on this path, so the last value it reported stays there. If the platform connected on an earlier run it keeps reporting
connectedfor as long as the adapter keeps failing to build, and the timestamp is the only hint anything is stale — the status and monitor surfaces show a platform that is entirely down as up.Any adapter-creation failure lands here: a missing optional dependency, an enabled platform with no plugin registered, a credential the adapter rejects. I noticed it when a dependency install left
discord.pyuninstalled — the gateway came up with webhook only andChannel directory built: 0 target(s), while the status file still said Discord wasconnectedwith a five-day-old timestamp.This sets
failed/adapter_unavailablethere so the branch maintains status like the rest of the loop does.Related Issue
None that I could find. I searched open and closed issues and PRs, and grepped the tree for
adapter_unavailable, before writing this.Type of Change
Changes Made
gateway/run.py: set the platform status tofailedin theif not adapter:branch, beforecontinue.How to Test
gateway_state.jsonshows"state": "connected".No adapter available for <platform>, but the status file still saysconnectedwith the oldupdated_at."state": "failed","error_code": "adapter_unavailable", and a currentupdated_at.gateway_health.pyalready hasfailedin_FATAL_PLATFORM_STATES, so the health surfaces pick it up without any change there.Testing
Tested on Windows 11, Python 3.11.15.
tests/gateway/test_runner_startup_failures.py,test_adapter_startup_secret_scope.py,test_gateway_platform_event_hook.py— 116 passed.tests/gateway/: identical results with and without this change — 71 failed, 5670 passed, 30 skipped, 2 xfailed in both runs. No regression from this patch.The 71 failures are pre-existing on Windows and unrelated to this change (systemd notify,
os.setsidfallbacks, and similar unix-only paths). I ran the same suite on unpatchedmainto confirm the counts match. Happy to share the failure list separately if that is useful — it looked like it might be worth its own issue.tests/gateway/test_teams.pywas excluded from both runs: it fails at collection because theteamsextra is not installed in my environment, which is unrelated to this change.Happy to rename the state or reword the error message if you'd rather it read differently.