Skip to content

fix(honcho): preserve memory when backend rejects conclusions - #26484

Open
atmigtnca wants to merge 1 commit into
NousResearch:mainfrom
atmigtnca:fix/honcho-memory-fallback
Open

fix(honcho): preserve memory when backend rejects conclusions#26484
atmigtnca wants to merge 1 commit into
NousResearch:mainfrom
atmigtnca:fix/honcho-memory-fallback

Conversation

@atmigtnca

Copy link
Copy Markdown

What does this PR do?

Fixes two Honcho memory reliability failures seen in normal Hermes sessions:

  1. sync_turn now normalizes structured/multimodal message content before calling sanitize_context, so image/audio/list-style provider payloads do not raise TypeError: expected string or bytes-like object, got 'list' and drop the whole turn.
  2. honcho_conclude now preserves explicit durable facts in the target peer card when a self-hosted Honcho backend can store/search raw messages but rejects conclusion creation because backend LLM credentials are missing.

The fallback keeps the same observer/target relationship used by the normal conclusion path and deduplicates the fact before appending it to the peer card.

Related Issue

No linked GitHub issue.

Related open PRs found while checking for duplicates:

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

  • plugins/memory/honcho/__init__.py
    • Add _content_to_text() to coerce strings, dicts, and OpenAI-style content lists into safe text before Honcho ingest.
    • Preserve text parts and replace media parts with compact placeholders such as [image attachment] and [audio attachment].
  • plugins/memory/honcho/session.py
    • Track the observer peer used for conclusion creation.
    • If the conclusion API rejects the write, append the fact to the observer's target peer card as a fallback.
  • tests/honcho_plugin/test_session.py
    • Add regression coverage for multimodal sync_turn normalization.
    • Add regression coverage for conclusion-to-peer-card fallback behavior.

How to Test

  1. python -m pytest tests/honcho_plugin/test_session.py -q -o 'addopts='
  2. git diff --check
  3. python -m compileall -q plugins/memory/honcho tests/honcho_plugin
  4. python -m ruff check plugins/memory/honcho/__init__.py plugins/memory/honcho/session.py tests/honcho_plugin/test_session.py

Full-suite note: I also attempted scripts/run_tests.sh for CI parity. It reached 93% before the 600s local command timeout and had unrelated failures outside this Honcho change area, so this PR reports the focused checks above rather than claiming a full-suite pass.

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: Ubuntu Linux 6.8.0-39-generic / Python 3.11.15

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

Screenshots / Logs

$ python -m pytest tests/honcho_plugin/test_session.py -q -o 'addopts='
117 passed in 3.66s

$ git diff --check && python -m compileall -q plugins/memory/honcho tests/honcho_plugin
# no output

$ python -m ruff check plugins/memory/honcho/__init__.py plugins/memory/honcho/session.py tests/honcho_plugin/test_session.py
All checks passed!

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

The sync_turn multimodal normalization part of this PR overlaps with #22768 (sync_turn crashes on list input from image-bearing messages). The conclusion fallback to peer cards overlaps with #17124 (fallback to durable peer cards for profiles).

Related: #22768, #17124, #23022, #24270.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating two real Honcho reliability concerns. The conclusion fallback remains relevant, but this branch needs targeted salvage against current main.

Problems

  • The multimodal portion is already handled before every provider sync: run_agent.py:3396-3407 flattens both payloads, and tests/run_agent/test_memory_sync_interrupted.py:245-268 covers an image-bearing turn. The new plugin-local formatter would duplicate that behavior with different markers.
  • plugins/memory/honcho/session.py:1123 in this diff enters the peer-card fallback for every conclusions_scope.create() exception. The PR describes a missing backend LLM credential specifically; an unknown or ambiguous write failure should not be converted into a successful durable write.
  • The new test's ordered _get_or_create_peer side effect asserts writes to user_peer, but current card writes use the shared observer/target contract in plugins/memory/honcho/session.py:1247-1256.

Suggested changes

  • Keep the conclusion fallback only; use get_peer_card() / set_peer_card() and a peer-ID-aware test asserting the assistant observer and user target.
  • Limit fallback to the verified unsupported conclusion/credential rejection mode, and retain failure for other exceptions.

Automated hermes-sweeper review.

logger = logging.getLogger(__name__)


def _content_to_text(content: Any) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current main already normalizes normal completed turns before any provider receives them (run_agent.py:3396-3407), with a shared regression test. Please drop this plugin-local formatter and its duplicate test rather than maintain a second, differently formatted multimodal boundary.

return False
# Self-hosted Honcho deployments may store/search raw messages but
# reject conclusion writes when the backend LLM/OpenAI key is not
# configured. In that case, preserve the user's explicit durable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback runs for every conclusion-create exception, including transport and ambiguous post-write failures, but the stated use case is the known missing-backend-LLM-credential rejection. Please gate the fallback to that confirmed failure mode; otherwise return False so an uncertain conclusion is not reported as saved.

mgr._get_or_create_peer = MagicMock(side_effect=[assistant_peer, user_peer, user_peer])

ok = mgr.create_conclusion(session.key, "User prefers Korean casual tone")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordered mock returns user_peer for the fallback lookup/write even though this mode uses the assistant as observer. Use a peer-ID-aware side effect and assert assistant_peer.get_card(target=user_peer_id) plus assistant_peer.set_card(..., target=user_peer_id) to match the existing observer-target write contract.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users area/memory Memory subsystem: store, providers, sync, background reviews labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/memory Memory subsystem: store, providers, sync, background reviews comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants