Skip to content

fix(gateway): preserve message before stale-code restart#19238

Closed
ai-ag2026 wants to merge 1 commit into
NousResearch:mainfrom
ai-ag2026:fix/gateway-stale-code-preserve-message
Closed

fix(gateway): preserve message before stale-code restart#19238
ai-ag2026 wants to merge 1 commit into
NousResearch:mainfrom
ai-ag2026:fix/gateway-stale-code-preserve-message

Conversation

@ai-ag2026

Copy link
Copy Markdown
Contributor

Summary

Preserve the authorized user message that triggers the gateway stale-code self-check before requesting a restart.

Problem

The stale-code self-check added for #17648 correctly detects when a long-running gateway survived an update and should restart before dispatching into stale imports.

However, the check currently returns a retry-after-restart notice without persisting the triggering message. For polling/event platforms such as Telegram, the update has already been consumed by the time _handle_message() returns. The gateway restarts, but the user's actual request is gone and the platform will not replay it.

Observed class: after a WebUI/Hermes update, Telegram messages received during the stale-code restart path were acknowledged with the restart notice but never delivered to the agent after restart.

Change

  • Run the stale-code check after auth/plugin gates, so unauthorized input is not persisted.
  • Before requesting restart, get/create the session entry, append the triggering user message to the transcript, and mark the session resume_pending with reason stale_code_restart.
  • Extend the resume note so the next turn answers the preserved message first.
  • Add a regression test proving the stale-code path persists the message and marks resume-pending before restart.

Tests

python -m py_compile gateway/run.py tests/gateway/test_stale_code_self_check.py
python -m pytest tests/gateway/test_stale_code_self_check.py tests/gateway/test_restart_resume_pending.py -q
# 69 passed

Refs #17648.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 3, 2026
@ai-ag2026 ai-ag2026 force-pushed the fix/gateway-stale-code-preserve-message branch from 8b981cd to c0943df Compare May 4, 2026 06:27
@ai-ag2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current upstream main and force-pushed with lease.

Local targeted verification after rebase:

python -m pytest tests/gateway/test_stale_code_self_check.py -q -o 'addopts='
# '13

No code changes beyond the rebase.

@ai-ag2026

Copy link
Copy Markdown
Contributor Author

Closing this one rather than rebasing it further.

The branch is now stale/conflicting against current main, and I don't want to add review noise for a recovery path that upstream has continued to evolve. I preserved the local patch and test artifacts on my side for reference, but I am retiring this PR.

Thanks for the previous review bandwidth.

@ai-ag2026 ai-ag2026 closed this May 5, 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 P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants