fix(gateway): skip home-channel shutdown ping when idle (#20103) - #20126
fix(gateway): skip home-channel shutdown ping when idle (#20103)#20126briandevans wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces noisy gateway shutdown notifications by skipping the home-channel broadcast on plain shutdown when there are no active sessions, while preserving the existing /restart behavior (home channels still get pinged even when idle).
Changes:
- Add an early-return in
GatewayRunner._notify_active_sessions_of_shutdown()to skip home-channel shutdown notifications whenactive == {}and_restart_requestedis false. - Add tests to ensure (a) idle plain shutdown does not ping home channels and (b) shutdown with at least one active session still pings both the active chat and the home channel.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
gateway/run.py |
Adds an idle + non-restart guard to suppress home-channel shutdown broadcasts when nothing is running. |
tests/gateway/test_restart_notification.py |
Adds regression tests for idle-skip behavior and confirms home-channel notifications still occur when sessions are active. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
50de65a to
0cb924f
Compare
|
Rebased onto current |
0cb924f to
403f7ed
Compare
…#20103) `_notify_active_sessions_of_shutdown` unconditionally broadcast a "your current task will be interrupted" warning to every configured home channel, even when no session was active. For deployments with a daily systemd-timed reboot of an idle gateway this produced a spurious ping in every home channel with nothing actually being interrupted. Skip the home-channel loop when both: * `active == {}` — no running agents to interrupt * `_restart_requested` is False — not a user-initiated /restart The /restart path still broadcasts even when idle because ops watchers explicitly opt into it and an existing test (`test_restart_notifies_home_channel_even_without_active_sessions`) codifies that behaviour. Mirrors the symmetric startup gate at `_send_home_channel_startup_notifications`, which only fires when /restart was pending. Tests: two new cases in tests/gateway/test_restart_notification.py covering the idle-skip and the active-still-notified regression guard, and the existing 5-test home-channel/restart suite is unchanged. Fixes NousResearch#20103 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
403f7ed to
83ef455
Compare
|
Closing to keep the queue clean — branch is several hundred commits behind |
Summary
/restart./restartbehaviour: home channels are still notified even when idle (existing test enshrines this for ops-watcher heartbeat reasons)._send_home_channel_startup_notifications(gateway/run.py:3332), which only fires when/restartwas pending.The bug
_notify_active_sessions_of_shutdownbroadcasts\"⚠️ Gateway shutting down — Your current task will be interrupted.\"to every configured home channel unconditionally. For deployments with a daily systemd-timed reboot of an idle gateway, this produced a spurious daily ping in every home channel — there was no task to interrupt, so the warning carried no signal.The reporter (#20103) hits this on a Weixin home-channel deployment with a 4 AM systemd reboot.
The fix
In
gateway/run.py:_notify_active_sessions_of_shutdown, after the active-session loop and before the home-channel loop, skip the home-channel broadcast when:active == {}(no running agents) andself._restart_requestedis False (plain shutdown, not/restart)The
/restartpath is intentionally preserved because:tests/gateway/test_restart_resume_pending.py::test_restart_notifies_home_channel_even_without_active_sessions) explicitly asserts the home channel is notified even with no active sessions on/restart./restartis user-initiated; ops watchers depend on the heartbeat to know the gateway will be back.This matches the issue reporter's recommended Option A: a one-shot guarded early-return, no new config knobs.
Test plan
tests/gateway/test_restart_notification.py:test_plain_shutdown_skips_home_channel_when_idle— assertsadapter.sendis not called when_restart_requested=Falseand_running_agents={}.test_shutdown_still_pings_home_channel_when_active— asserts the home channel is still notified when at least one session is active in a different chat (regression guard for the home-channel loop entry).test_restart_notifies_home_channel_even_without_active_sessionsstill passes — the/restartpath is unchanged.tests/gateway/test_restart_notification.py(23),tests/gateway/test_gateway_shutdown.py,tests/gateway/test_shutdown_cache_cleanup.py,tests/gateway/test_restart_drain.py,tests/gateway/test_restart_resume_pending.py— 114 passed.test_plain_shutdown_skips_home_channel_when_idleto fail with the exact bug behaviour (`adapter.send` called once with the home-channel ping); restoring the fix passes both tests.Related