fix(advice): keep the advice when the reply is over-long

The review found a way to store the model's WORKING instead of its
advice.

The advice is at the END of the reply, so the length cap was cutting
from the front - which took the advice off and left only the working.
That is worse than no advice at all, because it looks like advice: the
brew sees a full paragraph of the model thinking about their beer, and
nothing about what to do.

Reproduced:

    input len: 2515 -> final len: 1199
    advice present? False
    TAIL: 'padding padding padding padding padding'

Two changes:

- The length cap keeps the END of the reply and cuts at a sentence
  boundary near the end, so the advice survives.
- The stripper now also catches a reply that is entirely working - no
  marker phrase, and no paragraph that reads like advice - instead of
  only catching one that says "let me think".

    input: 2515 -> stripped: 2515 -> final: 1199
    advice present? True

A short reply is untouched.

171 tests (up from 169).
This commit is contained in:
2026-11-09 17:36:13 +10:00
parent cf08b751e4
commit b414240bb5
2 changed files with 59 additions and 1 deletions
+27
View File
@@ -258,6 +258,33 @@ def test_a_reply_that_starts_with_the_advice_is_untouched():
assert brew_advice._strip_reasoning(reply) == reply
def test_an_over_long_reply_keeps_the_advice_at_the_end():
"""The advice is at the END of the reply, so a plain truncation from
the front would cut it off and leave only the model's working.
That is worse than no advice at all, because it looks like advice.
"""
working = (
"I need to work through what this reading means. The original gravity "
"is 1.055 and the current reading is 1.030. " + ("padding " * 260) +
"Leave the fermenter alone, take another reading in three days and "
"only then consider repitching."
)
final = brew_advice._trim_advice(working)
assert len(final) <= brew_advice.MAX_ADVICE_CHARS
assert "Leave the fermenter alone" in final, (
"the advice was cut off and only the model's working was left"
)
def test_a_short_reply_is_not_trimmed():
"""The trim must not touch a reply that already fits."""
reply = "The gravity looks fine for day nine. Give it three more days."
assert brew_advice._trim_advice(reply) == reply
def test_the_advice_is_truncated():
"""A runaway reply must not fill the reading document."""
long_text = "x" * 5000