fix(rlm): honor odd truncation limits - #69
Draft
isaacbmiller wants to merge 1 commit into
Draft
Conversation
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.
1. Issue / repro
Both RLM truncation paths promise a character limit but violate it when the limit is odd.
On
main, both retain the full six-character value:The second result is especially misleading: it says five characters were omitted while displaying all six.
2. Why this is the root cause
Both implementations split the limit in half and reuse the floor-divided value for the head and tail:
For every positive odd limit, this retains
limit - 1source characters. At limit1,halfis zero and Python'svalue[-0:]is the complete string, so the cap fails entirely.3. How we know the fix addresses the root cause
The regression cases cover both odd-number behaviors in both truncators:
1: retain exactly the final character, never the complete value;5: retain two head characters and three tail characters.The exact limit-
1assertions fail on untouchedmainat24ec85de4, where the observed preview is...abcdef. All four cases pass here.4. Why this is the concise fix
The configured limit is divided once, and the remainder goes to the tail:
That is the complete production change, applied at the two existing truncation sites. It does not introduce a helper, change marker text, validate new inputs, or alter prompt formatting.
5. Context needed to validate the change
The limit counts retained source characters; the existing
...or omission message is additional formatting. RLM intentionally preserves both the beginning and end of long values and outputs. Giving the odd remainder to the tail retains one more trailing character, where exception details and final results commonly appear.6. What the fix does in the code
1and limit-5regressions forREPLVariablepreviews.REPLEntryoutput.Compatibility boundaries and downsides
1,000and10,000).1intentionally stops exposing the full value/output. Any snapshot relying on the buggy output will change.REPLEntry.format_outputline for Markdown-fence safety. The changes are semantically independent, but if fix(rlm): protect history from nested fences stanfordnlp/dspy#9801 lands first this branch needs one trivial rebase conflict resolution.Validation
uv run --frozen pytest -q tests/predict/test_rlm.py::TestREPLTypes --deno—15 passeduv run --frozen pytest -q tests/predict/test_rlm.py --deno—113 passed, 2 skipped1assertion against untouchedmain— fails and prints the completeabcdef; passes here