Skip to content

feat(gateway): Add gateway startup auto-resume from recent session history#9328

Open
Jiawen-lee wants to merge 1 commit into
NousResearch:mainfrom
Jiawen-lee:feat/startup-session-auto-resume
Open

feat(gateway): Add gateway startup auto-resume from recent session history#9328
Jiawen-lee wants to merge 1 commit into
NousResearch:mainfrom
Jiawen-lee:feat/startup-session-auto-resume

Conversation

@Jiawen-lee

@Jiawen-lee Jiawen-lee commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

…story

What does this PR do?

This PR adds startup session recovery for the messaging gateway so Hermes can resume recent conversational context after a restart.

Today, if the gateway restarts and a new session is created, the agent starts fresh even though recent context still exists in state.db. This breaks continuity and forces the user to restate context. This PR fixes that by loading the most recent resumable non-infrastructure session from state.db, extracting the last N user/assistant turns, and seeding that history into the first truly new empty gateway session after startup.

I implemented this by rewriting the new session transcript once at startup recovery time instead of using prefill_messages. That approach fits the existing load_transcript() -> conversation_history flow and avoids re-injecting the same history on every API call.

Related Issue

Fixes #9286

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added startup recovery helpers in hermes_state.py to:
    • find the latest resumable root session
    • load the last N user/assistant text messages in chronological order
  • Added gateway config support in gateway/config.py for:
    • gateway.auto_resume_last_session
    • gateway.auto_resume_message_limit
  • Added default config entries in hermes_cli/config.py
  • Added one-time startup recovery seeding in gateway/run.py
  • Added tests in tests/gateway/test_startup_resume.py
  • Extended DB coverage in tests/test_hermes_state.py

How to Test

  1. Add this to ~/.hermes/config.yaml:
gateway:
  auto_resume_last_session: true
  auto_resume_message_limit: 40
  1. Start the gateway, send a few messages on a messaging platform, then stop and restart the gateway.

  2. Send a message that creates a new session and confirm Hermes still has the recent prior context.

  3. Confirm recovery only happens once and does not keep injecting old history into later fresh sessions.

  4. Run targeted tests:

source venv/bin/activate
python -m pytest tests/test_hermes_state.py tests/gateway/test_startup_resume.py tests/gateway/test_status_command.py -q

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

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 type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Auto-resume session context from state.db on Gateway startup

2 participants