From 1e23d145684609c3b9a1ff19e3e54324d6d3e2ba Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sat, 14 Mar 2026 02:19:30 -0700 Subject: [PATCH] fix: log prompt builder skill parsing fallbacks --- agent/prompt_builder.py | 6 ++++-- tests/agent/test_prompt_builder.py | 33 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index e5b3e01a5..e5877ab0d 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -177,7 +177,8 @@ def _parse_skill_file(skill_file: Path) -> tuple[bool, dict, str]: desc = desc[:57] + "..." return True, frontmatter, desc - except Exception: + except Exception as e: + logger.debug("Failed to parse skill file %s: %s", skill_file, e) return True, {}, "" @@ -194,7 +195,8 @@ def _read_skill_conditions(skill_file: Path) -> dict: "fallback_for_tools": hermes.get("fallback_for_tools", []), "requires_tools": hermes.get("requires_tools", []), } - except Exception: + except Exception as e: + logger.debug("Failed to read skill conditions from %s: %s", skill_file, e) return {} diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py index 58f8a0ca8..2a7fda682 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -2,6 +2,7 @@ import builtins import importlib +import logging import sys from agent.prompt_builder import ( @@ -144,6 +145,23 @@ class TestParseSkillFile: assert frontmatter == {} assert desc == "" + def test_logs_parse_failures_and_returns_defaults(self, tmp_path, monkeypatch, caplog): + skill_file = tmp_path / "SKILL.md" + skill_file.write_text("---\nname: broken\n---\n") + + def boom(*args, **kwargs): + raise OSError("read exploded") + + monkeypatch.setattr(type(skill_file), "read_text", boom) + with caplog.at_level(logging.DEBUG, logger="agent.prompt_builder"): + is_compat, frontmatter, desc = _parse_skill_file(skill_file) + + assert is_compat is True + assert frontmatter == {} + assert desc == "" + assert "Failed to parse skill file" in caplog.text + assert str(skill_file) in caplog.text + def test_incompatible_platform_returns_false(self, tmp_path): skill_file = tmp_path / "SKILL.md" skill_file.write_text( @@ -440,6 +458,21 @@ class TestReadSkillConditions: conditions = _read_skill_conditions(tmp_path / "missing.md") assert conditions == {} + def test_logs_condition_read_failures_and_returns_empty(self, tmp_path, monkeypatch, caplog): + skill_file = tmp_path / "SKILL.md" + skill_file.write_text("---\nname: broken\n---\n") + + def boom(*args, **kwargs): + raise OSError("read exploded") + + monkeypatch.setattr(type(skill_file), "read_text", boom) + with caplog.at_level(logging.DEBUG, logger="agent.prompt_builder"): + conditions = _read_skill_conditions(skill_file) + + assert conditions == {} + assert "Failed to read skill conditions" in caplog.text + assert str(skill_file) in caplog.text + class TestSkillShouldShow: def test_no_filter_info_always_shows(self):