Repository navigation
fix(ts): let emailState set the body budget, as Python does (#589 parity) - #713
Conversation
…shorM#589 parity) emailState cleaned the body with cleanEmailBody's default budget and gave no way to change it, so every state body stopped at 3000 characters. Python's email_state takes max_chars for this (NandhaKishorM#589): for a long message the last paragraphs, which can hold the actual request or the phishing ask, were cut before the model saw them, including through the windowed long-state scan that exists to read past one window. Add maxChars as the last parameter, defaulting to 3000, and pass it to cleanEmailBody. It is last so existing positional calls keep their meaning, and it is ignored when clean is false, as in Python. This is a parity fix; it makes no prediction-accuracy claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bruce-Yii
left a comment
There was a problem hiding this comment.
This matches Python on the points that matter, and I confirmed them by running email_state on main: the default budget is 3000, max_chars=8000 widens the body to the full 5027 characters, clean=False returns the body whole, and the keyword is ignored when clean=False. The TS matches on all four, the default is unchanged so existing callers are untouched, and the new test does go red on main.
Two things to close out.
The positional order diverges, and the #589 leak is still reachable. Python has max_chars as the fifth parameter; here it is sixth, after extra. That is the right call for backwards compatibility, but the consequence is that a port of the Python call shape does nothing, silently:
emailState("s", body, null, true, 8000) // body still 3000, no error
emailState("s", body, null, true, { max_chars: 8000 }) // keys include "max_chars", body still 3000The second line is the bug #589 removed, and it survives because max_chars is not a named parameter here — so a caller following the Python documentation reaches for extra and gets an injected state field and an uncut budget, which is exactly the combination from the issue. A JSDoc line on emailState spelling out the TS order, and warning that max_chars belongs in the new parameter rather than in extra, would close it.
Only one of the four new assertions discriminates. Against main, emailState("s", body).body is already 3000, long already has no max_chars key, and clean=false already returns body identically. Only expect(long.body).toContain("wire the money") fails. Since 8000 exceeds the body length, nothing is actually cut, so the suite never shows the budget being applied. A bound case would:
expect(emailState("s", body, null, true, {}, 4000).body).toHaveLength(4000);and a case for the extra leak above would pin it so a future change cannot reintroduce it unnoticed.
|
Passed checks and merged. Thank you @Divit-aggarwal! It ships in 0.3.22. |
What
emailStatetakes a new last parameter,maxChars(default3000), and passes it tocleanEmailBody. This matches Python'semail_state(..., max_chars=)from #589.Why
emailStatecleaned the body with the default budget and gave no way to change it, so every state body stopped at 3000 characters. For a long message the last paragraphs, which can hold the real request or the phishing ask, were cut before the model saw them. That includes the windowed long-state scan, which exists to read past one window. Puttingmax_charsintoextraonly added a field to the model's input.It is the last parameter so existing positional calls keep their meaning, and it is ignored when
cleanis false, as in Python.How it was verified
The two Python commands are the CI gates; no Python was changed. The new test fails on
mainand passes with this change.Scope
emailStateand its testRelated: #589 (the Python change).
Written with Claude Code; I've reviewed the change and re-run the verification myself.
🤖 Generated with Claude Code