Repository navigation
fix(email): email_state swallowed max_chars into the model's input - #589
Merged
NandhaKishorM merged 1 commit intoSep 27, 2026
Merged
Conversation
`clean_email_body` takes `max_chars` and `email_state` called it with none, so every state body stopped at 3000 characters. `email_state` ends in `**extra`, which merges keywords into the state that `serialize_state` renders into the model's input, so the call a reader reaches for -- `email_state(subject, body, max_chars=8000)` -- neither raised the budget nor failed: it added a `max_chars` field to what the checkpoint reads. The cap is invisible for a state that fits one window, but `predict_long` scans a state in windows precisely to read past one, so for a long message the last paragraphs -- on a phished invoice, the phishing -- were cut before the model saw them. `max_chars` is now an explicit parameter after `clean`, so existing positional calls keep their meaning and the default stays 3000.
Owner
|
Thanks @aashish254, merged. It ships in 0.3.21. |
NandhaKishorM
pushed a commit
that referenced
this pull request
Sep 29, 2026
…ity) 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 (#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>
NandhaKishorM
added a commit
that referenced
this pull request
Sep 29, 2026
fix(ts): let emailState set the body budget, as Python does (#589 parity)
4 tasks done
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.
What
clean_email_body(body, max_chars=3000)takes a budget.email_state, the helper that calls it,called it with no argument -- and ends in
**extra, which merges unknown keywords into the statedictionary that
serialize_staterenders into the model's input.So the call a reader of
docs/reference/helpers.mdreaches for,email_state(subject, body, max_chars=8000), did two things at once: it left the body cut at 3000characters, and it added a
"max_chars": 8000field to what the checkpoint reads. No error, nowarning, and the state now describes a budget the caller never asked the model about.
The cost is not cosmetic.
email_stateis the documented way to prepare an email, and 3000characters is where the body stops -- so the last paragraphs of a long message never reach
predict_long, the API that exists precisely to read past one window's worth. On a phishedinvoice, that is the sentence that matters.
Change
laya/email.py:email_state(..., clean=True, max_chars=3000, **extra)forwards the budget toclean_email_body, placed aftercleanso an existing positional call keeps its meaning. Itsdocstring -- the text
docs/reference/helpers.mdrenders -- now names the budget, says when toraise it, says
clean=Falsepasses the body whole, and says the remaining**extrakeywords becomemodel input.
No new constant: both defaults stay literal, because a signature is the documentation here (griffe
prints
max_chars: int = 3000, not a name), andtests/test_email.pycompares the two defaultsinstead.
Measured
laya-bench/probe_email_state_max_chars.pyon a 7175-character body whose request is in the lastparagraph, English checkpoint, cpu. Before =
4066d5d(laya-bench/email_state_max_chars_before.log),after = this branch (
…_after.log). Decisions are compared at the level the model commits to:label for a
choice,probability >= 0.5for anoul, rounded integer for ascore.email_state("Billing", BODY, max_chars=8000):['body', 'max_chars', 'subject']['body', 'subject']predict_longanswersis_phishing=False is_spam=Falseis_phishing=True is_spam=Trueusage.input_tokensThe capped row, for reference, is
is_phishing=False is_spam=Falseat 4901 tokens -- so before thischange the "widening" call bought 35 tokens of injected field and no extra email. The after row now
matches the hand-cleaned reference (
clean_email_body(body, max_chars=8000)assembled into a stateby hand): same decisions, same 13611 tokens.
What did not move, which matters as much as what did:
predict(one window) gives the same answers for the capped and the widened body on both trees(
single-window path: short != wide : False), because a 512-token state was never going to readparagraph forty -- the cap costs an answer exactly on the long-document path;
categorystayedbillingandurgency/needs_replystayed put in all five rows. Two of thepreset's five questions flip; this fixes the budget, not the checkpoint's category sense.
Tests
python tests/test_email.py: 105 → 115 passed (both measured). The ten new checks cover the defaultcut, the raised cut keeping the late request,
max_charsreachingclean_email_bodyunchanged,max_charsnot appearing as a state field,clean=Falsepassing the body whole, the positionalorder, and the two signatures agreeing on the default.
Gate check (
laya-bench/mutate_email_state_budget_gate.py, restored after every variant --restored: True):m4 is the one that keeps this honest: reverting to the shipped signature is caught by the
state-field check, not just by the budget checks.
Other gates on this tree:
ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120→
All checks passed!;python -m compileall -q laya/ tests/;tests/test_packaging.py→ 43passed;
tests/test_hooks_api.py→ 131 passed;zensical build --strict --clean→No issues found, and the builtsite/reference/helpers/index.htmlnow carriesmax_chars: int = 3000inboth signatures (one occurrence before, four mentions of
max_charsafter).Overlap
Two open PRs touch
laya/email.py: #503 (@PerryLink) and #468 (@lloyd-aloysius), both insideclean_email_body's marker lists (roughly lines 15-160). This change is inemail_state(line 198)and its call of
clean_email_body, so the hunks are ~40 lines apart; both of them also append totests/test_email.py, so whoever lands last takes a tail conflict there. Neither changes the bodybudget, and #468's symptom (a device footer eating the request) is different from this one (a
length cap sitting before the request) -- though both are "the request never reached the model", so
it is worth reading the two together.