hermes - ✅(Solved) Fix Hook loader mis-registers scalar HOOK.yaml events values character-by-character [1 pull requests, 1 participants]

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…
GitHub stats
NousResearch/hermes-agent#11902Fetched 2026-04-18 05:58:24
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Error Message

Invalid manifests with scalar events: should be rejected with a clear error, or normalized into a one-item list.

Root Cause

Bug Description

The hook loader accepts a scalar events: value from HOOK.yaml and iterates it character-by-character. Because discover_and_load() does not validate that events is a list, a manifest like events: agent:start registers handlers for 'a', 'g', ':', etc. instead of for the single agent:start event.

PR fix notes

PR #11944: fix(hooks): reject scalar manifest events

Description (problem / solution / changelog)

Summary

  • reject invalid scalar events: declarations in HOOK.yaml
  • require events to be a list of non-empty strings before registering handlers
  • add regression coverage so malformed manifests no longer register character-by-character event keys

Verification

  • source venv/bin/activate && pytest -q tests/gateway/test_hooks.py::TestDiscoverAndLoad::test_skips_scalar_events_manifest tests/gateway/test_hooks.py

Closes #11902

Changed files

  • gateway/hooks.py (modified, +6/-0)
  • tests/gateway/test_hooks.py (modified, +16/-0)

Code Example

name: demo
   events: agent:start
RAW_BUFFERClick to expand / collapse

Bug Description

The hook loader accepts a scalar events: value from HOOK.yaml and iterates it character-by-character. Because discover_and_load() does not validate that events is a list, a manifest like events: agent:start registers handlers for 'a', 'g', ':', etc. instead of for the single agent:start event.

Affected Files / Lines

  • gateway/hooks.py:100-124

Why this is a bug

HOOK.yaml declares event names, but the loader currently accepts invalid schema and silently mis-registers the hook. This makes a typo / schema mistake fail in a confusing way instead of being rejected clearly.

Minimal Reproduction

  1. Create a hook directory with:
    name: demo
    events: agent:start
  2. Add a valid handler.py with async def handle(...).
  3. Run HookRegistry().discover_and_load().
  4. Inspect registry._handlers.keys().

Observed in repo-local repro:

  • HOOK_KEYS [':', 'a', 'e', 'g', 'gateway:startup', 'n', 'r', 's', 't']

Expected Behavior

Invalid manifests with scalar events: should be rejected with a clear error, or normalized into a one-item list.

Actual Behavior

The loader silently registers the hook under single-character event keys.

Suggested Investigation Direction

Validate that events is a sequence of strings before iterating. A regression test for scalar events: would prevent this from recurring.

extent analysis

TL;DR

Validate the events value in HOOK.yaml to ensure it's a list before iterating over it to fix the silent mis-registration of hooks.

Guidance

  • Check the events value in HOOK.yaml and modify the discover_and_load() function in gateway/hooks.py to validate that events is a list.
  • If events is a scalar, either reject it with a clear error or normalize it into a one-item list.
  • Add a regression test to prevent similar issues in the future by testing the loader with a scalar events: value.
  • Verify the fix by running the minimal reproduction steps and checking that registry._handlers.keys() contains the expected event keys.

Example

if not isinstance(events, list):
    if isinstance(events, str):
        events = [events]  # normalize scalar to list
    else:
        raise ValueError("Invalid events type")

Notes

This fix assumes that the events value should always be a list of strings. If other types are valid, additional validation may be necessary.

Recommendation

Apply workaround: Validate and normalize the events value to ensure it's a list, as this will prevent silent mis-registration of hooks and provide clear error messages for invalid manifests.

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 - ✅(Solved) Fix Hook loader mis-registers scalar HOOK.yaml events values character-by-character [1 pull requests, 1 participants]