# NousResearch/hermes-agent · Background review isolation and hindsight retain fixes

## Open now

- Nothing open on GitHub.

These issues and PRs address bugs where background review processes incorrectly shared session context with the main agent loop, and fix destructive or unsafe behavior in hindsight memory retention. The work involves isolating background review forks and replacing unsafe retain operations with safer alternatives.

## TL;DR

- 5 member(s): 0 open issue(s), 2 closed issue(s), 0 open PR(s), 1 merged PR(s), 2 PR(s) closed without merging.
- A fix was merged to main in PR #27190. Verify it addresses your case.
- **Recommended:** read PR #27190 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `unresolved`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_PARTIAL`): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text.
- Members outside that structural core may belong to a different underlying problem.
- Pairwise link density `0.34`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #47268: \[Bug\]: Background review shares session context with main loop, causing premature stop (11-77 char responses)
- #55816: fix(hindsight): hindsight_retain destructive overwrite, misleading description, and Background Review abuse

## Prior & competing PRs

- **#27190: fix(run_agent): isolate background review fork from external memory plugins**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`; implication `superseded`
  - files: `run_agent.py`, `tests/run_agent/test_background_review.py`
  - fix hunks:
  - `run_agent.py`

    ```diff
    @@ -4386,6 +4386,21 @@ def _bg_review_auto_deny(command, description, **kwargs):
                         # owns the loop and the agent-loop tools dispatch.
                         if _parent_api_mode == "codex_app_server":
                             _parent_api_mode = "codex_responses"
    +                    # skip_memory=True keeps the review fork from
    +                    # touching external memory plugins (honcho, mem0,
    +                    # supermemory, etc.).  Without it, the fork's
    +                    # __init__ rebuilds its own _memory_manager from
    +                    # config, scoped to the parent's session_id, and
    +                    # run_conversation() then leaks the harness prompt
    +                    # into the user's real memory namespace via three
    +                    # ingestion sites: on_turn_start (cadence + turn
    +                    # message), prefetch_all (recall query), and
    +                    # sync_all (harness prompt + review output recorded
    +                    # as a (user, assistant) turn pair).  Built-in
    +                    # MEMORY.md / USER.md state is re-bound from the
    +                    # parent below so memory(action="add") writes from
    +                    # the review still land on disk; the review just
    +                    # has zero side effects on external providers.
                         review_agent = AIAgent(
                             model=self.model,
                             max_iterations=16,
    ```

    ```diff
    @@ -4397,6 +4412,7 @@ def _bg_review_auto_deny(command, description, **kwargs):
                             api_key=[redacted:secret-assignment]"api_key") or None,
                             credential_pool=[redacted:secret-assignment] "_credential_pool", None),
                             parent_session_id=self.session_id,
    +                        skip_memory=True,
                         )
                         review_agent._memory_write_origin = "background_review"
                         review_agent._memory_write_context = "background_review"
    ```
  - `tests/run_agent/test_background_review.py`

    ```diff
    @@ -193,3 +193,51 @@ def close(self):
         assert captured_bg_callback[0].startswith("💾 Self-improvement review:"), (
             captured_bg_callback[0]
         )
    +
    +
    +def test_background_review_fork_skips_external_memory_plugins(monkeypatch):
    +    """The background review fork must NOT touch external memory plugins.
    +
    +    Without skip_memory=True on the fork constructor, AIAgent.__init__
    +    rebuilds its own _memory_manager from config, scoped to the parent's
    +    session_id.  The review fork's run_conversation() then leaks the
    +    harness prompt into the user's real memory namespace via three
    +    ingestion sites: on_turn_start (cadence + turn message),
    +    prefetch_all (recall query), and sync_all (harness prompt + review
    +    output recorded as a (user, assistant) turn pair).  The fix is a
    +    single kwarg on the fork constructor — this test guards it.
    +    """
    +    captured_kwargs: dict = {}
    +
    +    class FakeReviewAgent:
    +        def __init__(self, **kwargs):
    +            captured_kwargs.update(kwargs)
    +            self._session_messages = []
    +
    +        def run_conversation(self, **kwargs):
    +            pass
    +
    +        def shutdown_memory_provider(self):
    +            pass
    +
    +        def close(self):
    +            pass
    +
    +    monkeypatch.setattr(run_agent_module, "AIAgent", FakeReviewAgent)
    +    monkeypatch.setattr(run_agent_module.threading, "Thread", ImmediateThread)
    +
    +    agent = _bare_agent()
    +
    +    AIAgent._spawn_background_review(
    +        agent,
    +        messages_snapshot=[{"role": "user", "content": "hello"}],
    +        review_memory=True,
    +    )
    +
    +    assert captured_kwargs.get("skip_memory") is True, (
    +        "Background review fork must be constructed with skip_memory=True "
    +        "so AIAgent.__init__ does not rebuild a _memory_manager wired to "
    +        "external plugins (honcho, mem0, supermemory, ...).  Without this "
    +        "the fork leaks harness prompts into the user's real memory "
    +        "namespace via on_turn_start / prefetch_all / sync_all."
    +    )
    ```
- **#47364: fix(agent): stop bg-review from sharing parent session_id (#47268)**. closed without merge
  - maintainer direction: category `uncategorized`; implication `needs_llm`; refs `#47268`
- **#55819: fix(hindsight): replace destructive aretain_batch with safe file-based retain**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `4ece521bcf37401686e73f1d08ebaa87caaae05a`, `#27190`

## Fix status

- Merged to main in PR #27190 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-05-17`.
- Subsystem: `agent`
