Skip to content

fix(gateway): serialize startup auto-resume before inbound - #46074

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b4d8e026
Jun 14, 2026
Merged

fix(gateway): serialize startup auto-resume before inbound#46074
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b4d8e026

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have been scheduled and completed, preventing duplicate agents for the same session after a restart.

Changes

  • gateway/run.py: adds a startup restore gate, tracks startup auto-resume tasks, waits for their adapter-level processing tasks, then drains queued inbound messages in order.
  • tests/gateway/test_restart_resume_pending.py: covers real inbound queuing during restore and verifies queued messages replay only after the synthetic resume turn finishes.

Validation

Check Result
py_compile gateway/run.py tests/gateway/test_restart_resume_pending.py passed
scripts/run_tests.sh tests/gateway/test_restart_resume_pending.py 70 passed
scripts/run_tests.sh tests/gateway/test_platform_reconnect.py tests/gateway/test_restart_resume_pending.py 100 passed

Fixes #45682.

Infographic

Gateway Restore Gate

@liuhao1024

Copy link
Copy Markdown
Contributor

Verification: LGTM — clean startup-restore serialization

Reviewed the full diff. The race condition is clear: platform adapters start receiving inbound messages as soon as they connect, but restart-interrupted sessions aren't auto-resumed until _schedule_resume_pending_sessions() runs. A user message arriving during the gap competes with the synthetic resume turn for the same session.

The fix introduces a startup-restore gate that:

  1. Sets _startup_restore_in_progress = True before adapter connection
  2. Queues non-internal inbound messages in _handle_message while the gate is active
  3. Waits for all resume tasks to finish via _finish_startup_restore()
  4. Drains the queue before releasing the gate

The asyncio.shield(task) in _run_startup_resume_event correctly waits for the agent turn to complete (not just handle_message returning after spawning the background task). The _hermes_startup_restore_replay marker prevents drain-replayed events from being re-queued.

Test coverage is solid — two async tests covering the gate-queue and wait-then-drain scenarios. The early-exit path (startup failure → _startup_restore_in_progress = False) is also covered in the start() method's error branches.

Also bundled: Telegram rich messages default-on (removes _rich_messages_enabled opt-in gate) + updated platform hint. This is a behavioral change but well-scoped — the rich path already had the latching mechanism (_rich_send_disabled) to handle unsupported bot versions.

@teknium1
teknium1 force-pushed the hermes/hermes-b4d8e026 branch from 9402bd4 to 9dc6804 Compare June 14, 2026 10:05
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-b4d8e026 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10894 on HEAD, 10893 on base (🆕 +1)

🆕 New issues (1):

Rule Count
invalid-assignment 1
First entries
tests/gateway/test_restart_resume_pending.py:1245: [invalid-assignment] invalid-assignment: Object of type `def fake_handle_message(event: MessageEvent) -> CoroutineType[Any, Any, None]` is not assignable to attribute `handle_message` of type `def handle_message(self, event: MessageEvent) -> CoroutineType[Any, Any, None]`

✅ Fixed issues: none

Unchanged: 5725 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1
teknium1 merged commit 10bad2f into main Jun 14, 2026
28 checks passed
@teknium1
teknium1 deleted the hermes/hermes-b4d8e026 branch June 14, 2026 10:21
AIalliAI pushed a commit to AIalliAI/Hermes that referenced this pull request Jun 14, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
Methodician added a commit to Methodician/hermes-agent that referenced this pull request Jul 4, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…rch#46074)

Gateway startup now queues real inbound messages until restart-interrupted auto-resume turns have completed, preventing duplicate agents for the same session after a restart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway restart should serialize auto-resume before accepting inbound messages

2 participants