Skip to content

The agent that grows with you

fix(skills): skill_manage error names the key misplaced text arrived in

teknium17d1a5399c1d9
diff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.py
index 720169fb113..d19995c3970 100644
--- a/tests/tools/test_skill_manager_tool.py
+++ b/tests/tools/test_skill_manager_tool.py
@@ -489,6 +489,43 @@ class TestSkillManageDispatcher:
assert "write_file" in err, "must name the escape hatch it is forbidding"
assert "exact" in err.lower()
+ @pytest.mark.parametrize("op, stray_key, destination", [
+ ({"action": "create", "file_content": VALID_SKILL_CONTENT}, "file_content", "'content'"),
+ ({"action": "create", "new_string": VALID_SKILL_CONTENT}, "new_string", "'content'"),
+ ({"action": "patch", "file_content": "body"}, "file_content", "old_string/new_string"),
+ ])
+ def test_misplaced_text_slot_error_names_the_key_it_arrived_in(self, tmp_path, op, stray_key,
+ destination):
+ """#112677 — a batch op whose SKILL.md text sits in another action's key must be told
+ WHICH key it used and where to move it; the bare "X is required" error made a local
+ model replay the identical payload until the tool-loop guardrail tripped. The batch
+ still rolls back (atomicity unchanged), and a plain missing-content op gets no note."""
+ with _skill_dir(tmp_path):
+ _create_skill("my-skill", VALID_SKILL_CONTENT)
+ result = json.loads(skill_manage(action="", name="",
+ operations=[{"name": "my-skill", **op}]))
+ bare = json.loads(skill_manage(action="", name="",
+ operations=[{"name": "other", "action": "create"}]))
+
+ assert result["success"] is False
+ assert f"'{stray_key}'" in result["error"] and destination in result["error"]
+ assert "rolled back" in result["error"]
+ assert bare["success"] is False and "file_content" not in bare["error"]
+
+ def test_write_file_given_content_names_the_reverse_misplacement(self, tmp_path):
+ """#112677 — the reverse direction: create's `content` sent to write_file. Checked on the
+ legacy flat call shape so both entry points share the one hint chokepoint."""
+ with _skill_dir(tmp_path):
+ _create_skill("my-skill", VALID_SKILL_CONTENT)
+ crossed = json.loads(skill_manage(action="write_file", name="my-skill",
+ file_path="references/a.md", content="hello"))
+ ok = json.loads(skill_manage(action="write_file", name="my-skill",
+ file_path="references/a.md", file_content="hello"))
+
+ assert crossed["success"] is False
+ assert "'content'" in crossed["error"] and "'file_content'" in crossed["error"]
+ assert ok["success"] is True
+
def test_full_create_via_dispatcher(self, tmp_path):
"""Foreground create does NOT mark the skill as agent-created.
diff --git a/tools/skill_manager_tool.py b/tools/skill_manager_tool.py
index 8595840e095..03277883a3a 100644
--- a/tools/skill_manager_tool.py
+++ b/tools/skill_manager_tool.py
@@ -724,6 +724,29 @@ _REQUIRED_ARGS = {
("file_path", _MISSING, "file_path is required for 'write_file'. Example: 'references/api-guide.md'"),
("file_content", _IS_NONE, "file_content is required for 'write_file'.")],
"remove_file": [("file_path", _MISSING, "file_path is required for 'remove_file'.")]}
+# Text-slot keys a model confuses (the schema is one flat object): key -> the action that reads it.
+# A 27B model that just used write_file's file_content re-emits it on create/patch and then
+# replays the identical payload when the error only says the right key is "required" — the
+# hint has to name where the text actually landed so the retry can move it.
+_TEXT_SLOT_OWNER = {"content": "create (and a full-rewrite patch)",
+ "new_string": "a targeted patch (with old_string)",
+ "file_content": "write_file"}
+# action -> (text slots it reads, where misfiled text belongs)
+_TEXT_SLOT_FOR = {
+ "create": (("content",), "'content'"),
+ "edit": (("content",), "'content'"),
+ "patch": (("content", "new_string"), "'content' (full rewrite) or old_string/new_string (targeted)"),
+ "write_file": (("file_content",), "'file_content'")}
+
+
+def _misplaced_text_hint(action: str, args: Dict[str, Any]) -> str:
+ """Sentence naming the text-slot key(s) this op carries that ``action`` never reads, or ''."""
+ reads, destination = _TEXT_SLOT_FOR.get(action, ((), ""))
+ stray = [k for k in _TEXT_SLOT_OWNER if k not in reads and args.get(k) is not None]
+ if not stray:
+ return ""
+ carried = " and ".join(f"'{k}' (that key is for {_TEXT_SLOT_OWNER[k]})" for k in stray)
+ return f" Note: this op carries {carried} — move that text to {destination}."
def _record_success(action, name, result, *, file_path, absorbed_into, task_id,
@@ -787,7 +810,7 @@ def skill_manage(
return gate_result
for arg, missing, message in _REQUIRED_ARGS.get(action, ()):
if missing(args[arg]):
- return tool_error(message, success=False)
+ return tool_error(message + _misplaced_text_hint(action, args), success=False)
# Validate before the lock is keyed on the name, so a rejected name never touches .locks/
# (create takes a bare name; the other actions also accept ``category/name``).
if (name_err := _validate_name(name if action == "create" or not name else Path(name).name)) is not None:
@@ -812,6 +835,8 @@ def skill_manage(
result = handler({"name": name, **args})
if isinstance(result, str):
return result # tool_error JSON for argument-shape problems (patch)
+ if not result.get("success") and (hint := _misplaced_text_hint(action, args)):
+ result["error"] = result.get("error", "") + hint
if result.get("success"):
_record_success(
action, name, result, file_path=file_path, absorbed_into=absorbed_into,