fix: an enhancer rewrite with no real words (a non-chat encoder answered with 400 commas) is a failed rewrite, so the typed prompt is kept and the reason is said; found on a real GPU

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
digital-garbage
2026-10-15 15:59:16 +03:00
co-authored by Claude Sonnet 5.5
parent ac5b9b0fc8
commit 2b8a81390d
2 changed files with 13 additions and 0 deletions
@@ -373,5 +373,11 @@ def enhance(clip, text, *, system="", reference_text="", chat="", **sampling):
if not out:
return original, (status if "failed" in status or "unavailable" in status
else "the model returned nothing; prompt unchanged"), info
visible = "".join(out.split())
if not re.search(r"[^\W\d_]{2,}", out) or sum(c.isalpha() for c in visible) < len(visible) // 4:
# Seen on a real GPU: an encoder that is not a chat model answered with 400 commas, and that WAS sent
# on to the video model, which then made something unrelated to the prompt.
return original, ("the model wrote no usable words (" + out[:20].replace("\n", " ")
+ "...); prompt unchanged. This text encoder may not be a chat model"), info
info.update(after=out, ok=True)
return out, f"{status}; prompt {len(original)} -> {len(out)} chars", info
@@ -143,6 +143,13 @@ def test_every_failure_returns_the_original_prompt(clip):
assert out == "a fox" and not info["ok"] and status
@pytest.mark.parametrize("answer", [",,,,,,,,,,,,,,,,,,,,", "... --- !!!", "1234 5678", "x ,,,,,,,,,,,,,,,,,,,, ,,,,,"])
def test_an_answer_with_no_words_is_a_failure_not_a_prompt(answer):
"""A text encoder that is not a chat model answered with 400 commas; the run used them as the prompt."""
out, status, info = en().enhance(FakeClip(answer), "a red fox in the snow")
assert out == "a red fox in the snow" and not info["ok"] and "no usable words" in status
def test_an_empty_prompt_is_skipped_not_sent():
clip = FakeClip()
out, status, _ = en().enhance(clip, " ")