Skip to content

fix(gateway): clear stale platform status when adapter creation fails - #88305

Open
sclife2003 wants to merge 1 commit into
NousResearch:mainfrom
sclife2003:patch/clear-stale-platform-status
Open

fix(gateway): clear stale platform status when adapter creation fails#88305
sclife2003 wants to merge 1 commit into
NousResearch:mainfrom
sclife2003:patch/clear-stale-platform-status

Conversation

@sclife2003

@sclife2003 sclife2003 commented Aug 17, 2026

Copy link
Copy Markdown

What does this PR do?

In the platform startup loop, every path keeps gateway_state.json up to date except one. _update_platform_runtime_status() is called in 16 places in gateway/run.py, and the block right after this one sets connecting before the adapter connects. But when _create_adapter() returns None, the loop logs a warning and goes straight to continue:

else:
    logger.warning("No adapter available for %s", _pval)
continue

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 connected for 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.py uninstalled — the gateway came up with webhook only and Channel directory built: 0 target(s), while the status file still said Discord was connected with a five-day-old timestamp.

This sets failed / adapter_unavailable there 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py: set the platform status to failed in the if not adapter: branch, before continue.

How to Test

  1. Enable a platform and start the gateway once so it connects. gateway_state.json shows "state": "connected".
  2. Make the adapter fail to build — uninstalling the platform's dependency is the easiest way — then restart the gateway.
  3. Before: the log says No adapter available for <platform>, but the status file still says connected with the old updated_at.
  4. After: "state": "failed", "error_code": "adapter_unavailable", and a current updated_at.

gateway_health.py already has failed in _FATAL_PLATFORM_STATES, so the health surfaces pick it up without any change there.

Testing

Tested on Windows 11, Python 3.11.15.

  • Targeted: tests/gateway/test_runner_startup_failures.py, test_adapter_startup_secret_scope.py, test_gateway_platform_event_hook.py — 116 passed.
  • Full 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.setsid fallbacks, and similar unix-only paths). I ran the same suite on unpatched main to 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.py was excluded from both runs: it fails at collection because the teams extra 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.

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
sclife2003 force-pushed the patch/clear-stale-platform-status branch from ab8a6e5 to 53cfca0 Compare August 17, 2026 09:38
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants