Skip to content

fix(tool): correct Windows path handling in write_file and add sessio…#21027

Open
leonard9893 wants to merge 1 commit intoNousResearch:mainfrom
leonard9893:main
Open

fix(tool): correct Windows path handling in write_file and add sessio…#21027
leonard9893 wants to merge 1 commit intoNousResearch:mainfrom
leonard9893:main

Conversation

@leonard9893
Copy link
Copy Markdown

…n state repair for interrupt resilience

Bug 1 (Windows path handling):

  • Add _normalize_windows_path() to detect and convert Unix-style paths (e.g. /Users/zimu/...) to proper Windows paths (C:\Users...) on Windows
  • Add _detect_hardcoded_username() to warn when model generates paths with hardcoded usernames (training-data contamination)
  • Write_file_tool now performs parent directory existence check on Windows
  • Add OS-aware path validation with warnings for wrong platform paths

Bug 2 (Session interrupt tool call loss):

  • Add _validate_and_repair_session_state() to strip orphan tool_calls and trailing tool result messages after session interrupt/resume
  • Fix corrupted message sequences that contain incomplete tool-call patterns (assistant with tool_calls but no matching tool results)
  • Remove terminal tool/function messages so the API doesn't reject

Bug 3 (Tool execution hallucination):

  • Add _detect_tool_call_hallucination() that catches model responses claiming tool execution (e.g. "I've written the file") with zero actual tool_calls — common after session resume
  • On detection, inject a nudge message retrying with actual tool calls instead of accepting the hallucination as the final answer

Closes #20927

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

…n state repair for interrupt resilience

Bug 1 (Windows path handling):
- Add _normalize_windows_path() to detect and convert Unix-style paths
  (e.g. /Users/zimu/...) to proper Windows paths (C:\Users\...) on Windows
- Add _detect_hardcoded_username() to warn when model generates paths
  with hardcoded usernames (training-data contamination)
- Write_file_tool now performs parent directory existence check on Windows
- Add OS-aware path validation with warnings for wrong platform paths

Bug 2 (Session interrupt tool call loss):
- Add _validate_and_repair_session_state() to strip orphan tool_calls
  and trailing tool result messages after session interrupt/resume
- Fix corrupted message sequences that contain incomplete tool-call
  patterns (assistant with tool_calls but no matching tool results)
- Remove terminal tool/function messages so the API doesn't reject

Bug 3 (Tool execution hallucination):
- Add _detect_tool_call_hallucination() that catches model responses
  claiming tool execution (e.g. "I've written the file") with zero
  actual tool_calls — common after session resume
- On detection, inject a nudge message retrying with actual tool calls
  instead of accepting the hallucination as the final answer

Closes NousResearch#20927
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder tool/file File tools (read, write, patch, search) P2 Medium — degraded but workaround exists labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) type/bug Something isn't working

Projects

None yet

2 participants