hermes - 💡(How to fix) Fix [Bug] Hindsight memory provider re-initialized repeatedly, causing retain_every_n_turns counter to reset [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

The Hindsight memory provider plugin is being re-initialized dozens of times during a single CLI session, which resets _turn_counter to 0 each time. This makes retain_every_n_turns > 1 practically unusable — the counter never reaches the configured threshold.

Root Cause

Each agent_init creates a new AIAgent instance via run_agent.py, which in turn creates a new MemoryManager and loads a fresh HindsightMemoryProvider. The _turn_counter (used for retain_every_n_turns modulus check) is initialized to 0 in __init__ and has no persistence mechanism, so every re-initialization loses accumulated turns.

The code in the Hindsight plugin at sync_turn() actually handles accumulation correctly — it appends each turn to _session_turns and sends all accumulated turns on the Nth trigger — but the counter reset prevents it from ever reaching N.

Log snippet:

15:10:10 → Hindsight initialized
15:10:10 → Hindsight initialized  (0.14s later!)
15:10:42 → agent_init
15:10:51 → Hindsight initialized
15:10:51 → Hindsight initialized  (0.14s later again)

Fix Action

Fixed

Code Example

15:10:10Hindsight initialized
15:10:10Hindsight initialized  (0.14s later!)
15:10:42 → agent_init
15:10:51Hindsight initialized
15:10:51Hindsight initialized  (0.14s later again)
RAW_BUFFERClick to expand / collapse

Description

The Hindsight memory provider plugin is being re-initialized dozens of times during a single CLI session, which resets _turn_counter to 0 each time. This makes retain_every_n_turns > 1 practically unusable — the counter never reaches the configured threshold.

Evidence

  • Hindsight plugin initialized 124 times in one session (logged at INFO level)
  • Multiple agent_init events on the same MainThread within seconds of each other
  • "Unclosed client session" errors for each orphaned aiohttp session
  • With retain_every_n_turns=3, retain never fires because counter resets before reaching 3

Root Cause

Each agent_init creates a new AIAgent instance via run_agent.py, which in turn creates a new MemoryManager and loads a fresh HindsightMemoryProvider. The _turn_counter (used for retain_every_n_turns modulus check) is initialized to 0 in __init__ and has no persistence mechanism, so every re-initialization loses accumulated turns.

The code in the Hindsight plugin at sync_turn() actually handles accumulation correctly — it appends each turn to _session_turns and sends all accumulated turns on the Nth trigger — but the counter reset prevents it from ever reaching N.

Log snippet:

15:10:10 → Hindsight initialized
15:10:10 → Hindsight initialized  (0.14s later!)
15:10:42 → agent_init
15:10:51 → Hindsight initialized
15:10:51 → Hindsight initialized  (0.14s later again)

Expected Behavior

  • _turn_counter should persist across agent re-initializations within the same session, OR
  • The provider should not be re-created unless the session actually changes, OR
  • The counter should be persisted to disk (e.g. ~/.hermes/hindsight/counter.json)

Environment

  • Hermes Agent: latest (git install)
  • Hindsight plugin: 0.7.1 client / 0.6.2 API
  • Mode: local_external (Docker-hosted Hindsight)
  • Platform: CLI (also reproduces on Feishu gateway)
  • OS: WSL2 Ubuntu 22.04

Related

  • #15497 Hindsight provider can submit retain work during interpreter shutdown
  • #6672 Notify memory providers on in-chat session switches

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug] Hindsight memory provider re-initialized repeatedly, causing retain_every_n_turns counter to reset [1 pull requests]