Self-hosted AI workspace.
Python
fix: _extract_skill_json crashes on a truthy non-string teacher response (#1630)
Afonso Coutinho88fd0f7e68f8
diff --git a/src/teacher_escalation.py b/src/teacher_escalation.pyindex 3de033582..56b8ce632 100644--- a/src/teacher_escalation.py+++ b/src/teacher_escalation.py@@ -327,7 +327,7 @@ def _extract_skill_json(teacher_response: str) -> Optional[Dict[str, Any]]:treated as "teacher declined to write a skill", per the promptcontract."""- if not teacher_response:+ if not isinstance(teacher_response, str) or not teacher_response:return Noneimport jsonm = re.search(r"```(?:json)?\s*\n(\{[\s\S]*?\})\s*\n```", teacher_response)diff --git a/tests/test_extract_skill_json_nonstring.py b/tests/test_extract_skill_json_nonstring.pynew file mode 100644index 000000000..4a6dc53c6--- /dev/null+++ b/tests/test_extract_skill_json_nonstring.py@@ -0,0 +1,19 @@+"""Regression: _extract_skill_json must tolerate a non-string response.++The `if not teacher_response` guard only handled falsy values; a truthy+non-string (e.g. a number or list from an unexpected LLM client) reached+`re.search(..., teacher_response)` and raised TypeError. Non-strings now+return None (treated as "no skill"), matching the documented contract.+"""+from src.teacher_escalation import _extract_skill_json+++def test_non_string_returns_none():+ assert _extract_skill_json(123) is None+ assert _extract_skill_json(["x"]) is None+ assert _extract_skill_json(None) is None+++def test_valid_json_block_parsed():+ resp = "sure:\n```json\n{\"name\": \"x\"}\n```\n"+ assert _extract_skill_json(resp) == {"name": "x"}