Skip to content

fix(gateway): clear stale status for disabled platforms on startup - #63101

Open
mudrii wants to merge 1 commit into
NousResearch:mainfrom
mudrii:fix/gateway-disabled-platform-status
Open

fix(gateway): clear stale status for disabled platforms on startup#63101
mudrii wants to merge 1 commit into
NousResearch:mainfrom
mudrii:fix/gateway-disabled-platform-status

Conversation

@mudrii

@mudrii mudrii commented Jul 12, 2026

Copy link
Copy Markdown

What does this PR do?

Prevents gateway_state.json from reporting a platform as connected, paused, or failed after that platform has been explicitly disabled for the current gateway run.

The startup path now reconciles disabled platforms to a clean state="disabled" record and clears stale error metadata before connecting enabled adapters.

Related Issue

N/A — reproduced during a gateway state audit.

Type of Change

  • 🐛 Bug fix
  • ✅ Tests

Changes Made

  • Add disabled-platform reconciliation to write_runtime_status.
  • Reconcile every explicitly disabled platform during gateway startup.
  • Preserve enabled platform entries and current-call platform updates.
  • Clear stale error code/message fields and create missing disabled entries.
  • Add behavior tests using isolated temporary Hermes homes.

How to Test

  1. Run ./scripts/run_tests.sh tests/gateway/test_status.py.
  2. Confirm 98 tests pass with zero failures.

Checklist

Code

  • I've read the Contributing Guide.
  • My commit message follows Conventional Commits.
  • I searched for existing PRs and found no duplicate.
  • This PR contains only the gateway status reconciliation fix and tests.
  • I've run the entire pytest tests/ -q suite locally; repository-wide collection requires optional ACP/messaging dependencies not present in the minimal dev environment. The canonical changed-file suite passes.
  • I've added tests for the changed behavior.
  • Tested on macOS.

Documentation & Housekeeping

  • Documentation update: N/A; no user-facing setting changed.
  • cli-config.yaml.example: N/A.
  • CONTRIBUTING.md / AGENTS.md: N/A.
  • Cross-platform impact considered; the implementation uses existing atomic status-file helpers.
  • Tool descriptions/schemas: N/A.

A platform explicitly disabled in the current config could retain a
prior run's connected/paused/fatal entry (with stale error metadata)
in gateway_state.json. The startup connect loop skips disabled
platforms with `continue`, so nothing overwrote those entries and
`hermes status`/readiness probes reported a turned-off platform as
live.

write_runtime_status gains a `disabled_platforms` argument that
reconciles each named platform to a clean state=disabled record with
error_code/error_message cleared, without touching enabled platforms
or a platform updated in the same call. Gateway startup collects the
disabled platforms from config and reconciles them before the connect
loop runs.
Copilot AI review requested due to automatic review settings July 12, 2026 09:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the gateway’s runtime status persistence so gateway_state.json no longer reports stale “connected/paused/fatal” statuses for platforms that are explicitly disabled in the current gateway run. It does this by reconciling disabled platforms to a clean state="disabled" record early in startup and by extending write_runtime_status() to support that reconciliation.

Changes:

  • Extend gateway.status.write_runtime_status() with a disabled_platforms argument to mark disabled platforms as disabled and clear stale error metadata.
  • Reconcile all explicitly disabled platforms during GatewayRunner.start() before connecting enabled adapters.
  • Add regression tests covering disabled-platform reconciliation, preservation of enabled entries, missing-entry creation, and coexistence with per-platform updates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
gateway/status.py Adds disabled-platform reconciliation support to write_runtime_status().
gateway/run.py Calls disabled-platform reconciliation during gateway startup before adapter connects.
tests/gateway/test_status.py Adds tests for disabled-platform reconciliation behaviors and edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gateway/status.py
Comment on lines +856 to +872
if disabled_platforms is not _UNSET:
# Reconcile every explicitly-disabled platform to a clean "disabled"
# record for this run, clearing stale connection/error metadata a prior
# run may have left behind. Never touch a platform that was updated in
# THIS call (e.g. an enabled platform mid-connect) — the explicit
# `platform=` argument wins.
now = _utc_now_iso()
for name in disabled_platforms or []:
if name == platform:
continue
payload["platforms"][name] = {
"state": "disabled",
"error_code": None,
"error_message": None,
"updated_at": now,
}

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

Copy link
Copy Markdown
Contributor

Thanks for tracing the stale-state path; current main does still skip disabled platform configs at gateway/run.py:7141-7145, so the underlying fix is needed.

Problems

  • PR gateway/status.py:866 writes through payload["platforms"] without confirming it is a dict. _read_json_file() accepts any top-level JSON object (gateway/status.py:439-455), while setdefault preserves an existing list (gateway/status.py:813). With "platforms": [], reconciliation raises and the startup handler at PR gateway/run.py:7054-7055 suppresses it. This matches the existing Copilot review comment.
  • The new tests invoke write_runtime_status() directly (tests/gateway/test_status.py:704-806), so they do not exercise the startup collection/call introduced at PR gateway/run.py:7046-7053.

Suggested changes

  • Normalize a non-dict payload["platforms"] to {} before writing, and add coverage for that valid-but-malformed nested record.
  • Add an async startup regression test with a disabled PlatformConfig, stale persisted platform state, and a temporary HERMES_HOME.

Automated hermes-sweeper review.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 15, 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:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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.

4 participants