fix(tools): guard against catastrophic content loss in background review patches - #55665
Conversation
…iew patches The background review agent can call skill_manage(patch) on a skill it has not read via skill_view. When the model hallucinates old_string from the conversation transcript alone, fuzzy matching may find a partial match and the replacement silently deletes most of the file (observed: 807 lines -> 186 lines, issue NousResearch#55647). Add a content-loss guard in _patch_skill: when called from a background review context, reject patches that would shrink the file by more than 50%. The error message instructs the agent to read the skill first with skill_view before making targeted patches. Fixes NousResearch#55647
Competing with #55657 for the same bug (#55647). This PR adds a >50%-shrink content-loss guard in |
|
Closing in favor of #55906 (merged), which fixes the root cause of #55647 with a read-before-write invariant: the background-review fork must Your >50%-shrink guard was a reasonable backstop, but it can't catch sub-50% corruption and the arbitrary ceiling would also reject legitimate large condensations. The invariant approach supersedes it. Thanks for jumping on this fast. |
Summary
Adds a content-loss guard in
_patch_skillto prevent the background review agent from silently corrupting skills via hallucinated patches.Problem (P1 #55647)
The background review agent can call
skill_manage(patch)on a skill it has not read viaskill_view. When the model hallucinatesold_stringfrom the conversation transcript alone, fuzzy matching may find a partial match and the replacement silently deletes most of the file. Observed: 807 lines → 186 lines in a real session.Fix
When
_patch_skillis called from a background review context (is_background_review()), reject patches that would shrink the target file by more than 50%. The error message instructs the agent to read the skill first withskill_viewbefore making targeted patches.Changes
tools/skill_manager_tool.py: Add content-loss guard after size validation in_patch_skill(26 lines added)Fixes #55647