fix: handle whitespace between <tool_call> tag and JSON in Hermes handler#88
Merged
leehack merged 2 commits intoleehack:mainfrom Mar 17, 2026
Merged
fix: handle whitespace between <tool_call> tag and JSON in Hermes handler#88leehack merged 2 commits intoleehack:mainfrom
leehack merged 2 commits intoleehack:mainfrom
Conversation
…dler
The Hermes handler's parse() failed to extract tool calls when there
was whitespace (space or newline) between <tool_call> and the JSON
object, e.g. `<tool_call> {"name":...}` or `<tool_call>\n{"name":...}`.
Root cause: _openRegex group(3) captures leading whitespace as part of
the match (e.g., ` {"name"`). When computing jsonStart, the offset
pointed to the whitespace character instead of '{', causing
extractLeadingJsonValue() to return null and the entire tool call to
fall back as plain content.
Fix: skip leading whitespace after computing jsonStart to find the
actual '{' before calling _extractJsonObjectRange(). This is consistent
with how Granite, Mistral, and Magistral handlers already handle
whitespace before their extractLeadingJsonValue() calls.
03c7a49 to
48fbe60
Compare
leehack
approved these changes
Mar 16, 2026
Owner
|
Thanks for the contribution, @ipmsteven! It seems there's a very minor issue. Would you mind fixing the formatting? I can merge it as soon as that's addressed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #88 +/- ##
==========================================
- Coverage 77.23% 76.90% -0.34%
==========================================
Files 67 67
Lines 8338 8368 +30
==========================================
- Hits 6440 6435 -5
- Misses 1898 1933 +35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
formatting issue should be fixed now 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse()failing to extract tool calls when whitespace (space/newline) exists between<tool_call>and the JSON object<tool_call>\n{"name":...}\n</tool_call>Root Cause
_openRegexgroup(3) captures leading whitespace as part of the match (e.g.,{"name"). When computingjsonStart, the offset pointed to the whitespace character instead of{, causingextractLeadingJsonValue()to returnnulland the entire tool call to fall back as plain content.Fix
Skip leading whitespace after computing
jsonStartto find the actual{before calling_extractJsonObjectRange(). This is consistent with how Granite, Mistral, and Magistral handlers already handle whitespace before theirextractLeadingJsonValue()calls.Test plan