From 3ff9e0101deb241ec90de987f82c1f92006f9472 Mon Sep 17 00:00:00 2001 From: Leegenux Date: Wed, 1 Apr 2026 18:27:22 +0800 Subject: [PATCH] fix(skill_utils): add type check for metadata field in extract_skill_conditions When PyYAML is unavailable or YAML frontmatter is malformed, the fallback parser may return metadata as a string instead of a dict. This causes AttributeError when calling .get("hermes") on the string. Added explicit type checks to handle cases where metadata or hermes fields are not dicts, preventing the crash. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- agent/skill_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/agent/skill_utils.py b/agent/skill_utils.py index c11bc5e2d..9f54eb0fd 100644 --- a/agent/skill_utils.py +++ b/agent/skill_utils.py @@ -230,7 +230,13 @@ def get_all_skills_dirs() -> List[Path]: def extract_skill_conditions(frontmatter: Dict[str, Any]) -> Dict[str, List]: """Extract conditional activation fields from parsed frontmatter.""" - hermes = (frontmatter.get("metadata") or {}).get("hermes") or {} + metadata = frontmatter.get("metadata") + # Handle cases where metadata is not a dict (e.g., a string from malformed YAML) + if not isinstance(metadata, dict): + metadata = {} + hermes = metadata.get("hermes") or {} + if not isinstance(hermes, dict): + hermes = {} return { "fallback_for_toolsets": hermes.get("fallback_for_toolsets", []), "requires_toolsets": hermes.get("requires_toolsets", []),