fix(m0): bound context-test prompt size when tokens are under-reported

The context test re-estimated characters per token from the server's
prompt_tokens after every request. A server that reports a tiny count
made each next prompt grow by orders of magnitude, so the kit tests
reached 8 GB and were killed by the host memory guard. Clamp the
estimate to 0.5-4 characters per token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-09 17:20:01 +09:00
parent 5762a22a67
commit ff9b868e62
2 changed files with 21 additions and 3 deletions

View File

@@ -61,7 +61,9 @@ def test_context(r: StageResult, c: ChatClient, ctx_limit: int) -> None:
row.update(prompt_tokens=(a["usage"] or {}).get("prompt_tokens"), ttft=a["ttft"],
first_sentence=a["first_sentence"], total=a["total"])
if row["prompt_tokens"]:
chars_per_token = len(doc) / row["prompt_tokens"]
# Clamp: a server that under-reports tokens (e.g. counts only the
# uncached part) would otherwise make each next prompt explode.
chars_per_token = min(max(len(doc) / row["prompt_tokens"], 0.5), 4.0)
# Same long prefix, a new question at the end: shows prompt-cache reuse.
msgs2 = msgs[:1] + [{"role": "user", "content": doc + "\n\n위 글에서 가장 많이 나온 낱말 하나만 말해 줘."}]
b = c.chat(msgs2, max_tokens=24, extra=NO_THINK)