Skip to content

fix(honcho): guard against empty api_key in Honcho client construction - #61670

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-61661-honcho-empty-api-key
Closed

fix(honcho): guard against empty api_key in Honcho client construction#61670
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-61661-honcho-empty-api-key

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the honcho_conclude tool failure when the resolved api_key is None or an empty string. In this case, the Honcho SDK receives an empty Authorization header (Bearer with no value), causing write operations (e.g., honcho_conclude) to fail with AuthenticationError: Invalid API key.

The root cause: plugins/memory/honcho/client.py:_build() always passes api_key to the SDK constructor, even when it's empty. This breaks LAN/VPN self-hosted instances where the user configures an empty or missing key and expects the SDK to fall back to environment variable lookup.

The fix: only pass api_key to the SDK constructor when effective_api_key is non-empty. This allows the SDK to fall back to its own HONCHO_API_KEY environment variable lookup when the resolved key is missing.

Related Issue

Fixes #61661

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/client.py: Guard against empty api_key in Honcho client construction (lines 903-910). Changed from unconditional api_key in kwargs to conditional: only set kwargs["api_key"] when effective_api_key is truthy.

How to Test

  1. Configure Honcho for a self-hosted instance with a non-loopback base URL (e.g., http://192.168.2.112:8000).
  2. Set apiKey: "local" in the host block in ~/.hermes/honcho.json.
  3. Start a Hermes session and call honcho_conclude with a test fact.
  4. Observed result after fix: the tool succeeds and outputs ✅ honcho_conclude saved conclusion (or similar success indicator).

Before the fix, the tool fails with ⚡ honcho_conclude [Failed to save conclusion.] and the Honcho server logs show AuthenticationError: Invalid API key. After the fix, the SDK correctly reads HONCHO_API_KEY from the environment and writes succeed.

Regression test: the existing test_honcho_client_config.py suite (8 tests) all pass, confirming the fix doesn't break the normal config resolution flow.

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 (ran tests/test_honcho_client_config.py: 8 passed)
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS (Apple Silicon)

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

When config.api_key is None or empty string, the Honcho SDK receives
an empty Authorization header (Bearer with no value), causing
write operations (e.g., honcho_conclude) to fail with
"AuthenticationError: Invalid API key".

The fix: only pass api_key to the SDK constructor when it is non-empty.
This allows the SDK to fall back to its own environment variable lookup
(HONCHO_API_KEY) when the resolved key is missing.

Fixes NousResearch#61661
@alt-glitch alt-glitch added type/bug Something isn't working tool/memory Memory tool and memory providers comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have labels Jul 9, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused investigation. This automated hermes-sweeper review is closing the PR because the proposed change does not affect the reported path.

  • In current plugins/memory/honcho/client.py:443-447, the reported host-block apiKey: "local" resolves to a truthy key; at :889 and :903-913, this PR would still pass the same api_key="local" value.
  • The pinned honcho-ai==2.0.1 constructor already resolves api_key or os.getenv("HONCHO_API_KEY") (.venv/lib/python3.11/site-packages/honcho/client.py:225-242), so omitting an empty argument does not change its fallback behavior. Its HTTP client only emits Authorization for a truthy key (honcho/http/client.py:319-329).
  • The linked issue discussion points to the distinct host-block baseUrl / defaultHost resolution work in fix(honcho): read base_url and defaultHost from honcho.json host blocks #61675; this PR does not address those paths.

@teknium1 teknium1 closed this Jul 10, 2026
@teknium1 teknium1 added the sweeper:incoherent Sweeper: insufficient/incoherent to action label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:incoherent Sweeper: insufficient/incoherent to action 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.

honcho_conclude tool sends empty API key — AuthenticationError: Invalid API key

3 participants