fix(parsing): strip trailing EOS token from body_text after tool/reasoning parsing for code agent rl#2049
Open
none0663 wants to merge 1 commit into
Open
fix(parsing): strip trailing EOS token from body_text after tool/reasoning parsing for code agent rl#2049none0663 wants to merge 1 commit into
none0663 wants to merge 1 commit into
Conversation
…S token from assistant text
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.
Problem
parse_model_outputleaks<|im_end|>into thetextfield in two cases:tool_parser=None(XML regex fallback): the tail after</tool_call>is preserved as-is, so<|im_end|>ends up intexthas_tool_callis false so the body isreturned unchanged regardless of which
tool_parseris set —<|im_end|>always leaks here.
which causes
many times
tool_parser=qwen3_coderalready strips<|im_end|>on tool turns bydiscarding everything after the tool_call block, but that does not help for
text-only turns.
reasoning_parserhas no effect on EOS stripping in eithercase.
Fix
Add a
_strip_trailing_eosstep that runs onbody_textafter both tool andreasoning parsing are complete, covering all turn types uniformly.
_resolve_eos_token(tokenizer)readstokenizer.eos_tokenwhen available,falling back to the hardcoded
<|im_end|>default._strip_trailing_eos(text, eos_token)removes exactly one trailing EOS token.tokenizerparameter is threaded throughparse_model_output(default
Nonefor backward compatibility) and passed in from both callsites:
slime/agent/adapters/openai.pyandslime/agent/adapters/anthropic.py.Test
sandbox/test_parsing.pycovers all five parser combinations and can be runwith or without sglang (cases that need it are skipped gracefully).
Output before this fix:
Result
tool_parser=None<|im_end|>❌tool_parser=qwen3_codertool_parser<|im_end|>❌Notes
tool_parser, soqwen3_coder's existing behaviour isunchanged — it becomes a no-op when the token is already gone.
where the token appears in actual content.