You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(reward-penalties): share one malformed-think-tag predicate between the echo and capture paths #5008
The two are kept in sync only by test_malformed_think_tag_parity (6 turn patterns x with/without IDs) in tests/unit/experience/test_capture_reward_penalties.py.
Proposal
Have apply_reward_penalties call has_malformed_think_tag (or one shared ID predicate plus one text predicate) per (user, assistant) turn, so both paths run the same rules and the parity test can go. Gym's message-level has_malformed_thinking flag stays an echo-only extra check.
Fix the case below in the shared predicate.
Missed case: a spelled-out </think> in a thinking-off turn
Reported by terrykong in #4776 (comment). With tag IDs known and thinking off, the ID check expects 0 close tags, but the text check only fails on more than 1. A model that writes </think> from ordinary tokens passes both:
new prompt (carry): ... <think></think> empty pair → thinking off
model wrote: "Answer" "</" "think" ">" no tag token, just text pieces
decoded text: "Answer</think>"
ID check: expect 0 open, 0 close; generation has 0 open IDs, 0 close IDs → passes
text check: "<think>" 0 times → passes; "</think>" 1 time, fails only on > 1 → passes
result: not penalized
Both paths behave this way (has_malformed_think_tag returns False on this input; echo step 4b has the same > 1 rule).
Suggested rule: when the IDs are known, compare the decoded close-tag count with the count the ID check expects (0 or 1); keep > 1 only when the IDs are unknown. The counts line up because has_malformed_think_tag decodes with skip_special_tokens=False, so a real close-tag token also shows up in the text.
I'm working on this — sharing one malformed-think-tag predicate between the echo path (apply_reward_penalties) and the capture path (has_malformed_think_tag), and fixing the spelled-out </think> miss in thinking-off turns. I will open a PR with the refactor and regression tests.
Activity
four1er commentedon Nov 23, 2026
I'm working on this — sharing one malformed-think-tag predicate between the echo path (
apply_reward_penalties) and the capture path (has_malformed_think_tag), and fixing the spelled-out</think>miss in thinking-off turns. I will open a PR with the refactor and regression tests.