Skip to content

[Bug]: Memory nudge never triggers when smart model routing is enabled #8506

@BukeLy

Description

@BukeLy

Bug Description

When smart_model_routing is enabled, the background memory review (_spawn_background_review) never triggers in gateway mode. The _turns_since_memory counter resets to 0 on every message because smart routing causes agent cache misses.

Root Cause

The turn counter _turns_since_memory lives on the AIAgent instance. In gateway mode, smart routing alternates between cheap and strong models, changing the config signature each time. This causes the agent cache to miss (_agent_config_signature differs), creating a fresh AIAgent whose __init__ resets _turns_since_memory = 0.

With nudge_interval: 3, the counter goes: 0→1, 0→1, 0→1, ... instead of 0→1→2→3 (trigger!).

Call Chain

Message 1 (simple → cheap model, sig=A):
  new AIAgent → _turns_since_memory = 0 → run_conversation → += 1 → saved as 1

Message 2 (complex → strong model, sig=B):
  cache miss → new AIAgent → _turns_since_memory = 0 ← RESET!
  → run_conversation → += 1 → saved as 1 (should be 2)

Impact

  • Memory nudge never fires → _spawn_background_review never runs
  • Agent says "记得了" (remembered) but never calls the memory tool
  • User information is lost across sessions

Reproduction

  1. Enable smart_model_routing with a cheap local model and a strong cloud model
  2. Set memory.nudge_interval: 3
  3. Send 10+ messages alternating simple ("你好") and complex ("帮我查天气")
  4. Check ~/.hermes/memories/USER.md — never updated
  5. Check logs — no _spawn_background_review activity

Environment

  • Hermes Agent v0.8.0
  • Gateway mode with BlueBubbles (iMessage)
  • Smart routing: local Qwen 9B (cheap) + SiliconFlow MiniMax-M2.5 (strong)
  • nudge_interval: 3

Suggested Fix

Persist _turns_since_memory at the GatewayRunner level (per session_key) so it survives agent cache misses. Restore on agent creation, save after run_conversation completes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliverytool/memoryMemory tool and memory providerstype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions