贡献 / #1803

#1803 serve: opt-in guard for a repeated phrase (repeat_stop_period), and name repetition stops (stop_cause)

open · @gt50 · 0 评论 · 去 GitHub 看

Setup & installServer & APIAMD / HIPDocumentationWindows

说明

## Title
Issue: relates to #606 and #728

## Summary
Two things about replies Strata ends because they repeat:
- **Opt-in:** a guard for a short phrase repeated back to back.
- **Always:** the stop is named.

Split out of #1789 (which now only carries the Windows AMD images), as AGENTS.md asks: one change per PR, a new feature opt-in.

## What changed
- **`serve/server.py`, `"repeat_stop_period": N`** (opt-in; default 1 = only #606's one-token rule):
  - a run of `repeat_stop_tokens` tokens that repeats with a period of 2..N tokens ends the reply like #606;
  - O(N) per token;
  - seen on a scanned page: `[unclear] ` written until `max_tokens` ran out (12,000 tokens, 229 s), which the one-token rule never sees;
  - 16 is a good value.
- **`choices[0].stop_cause`:** a reply ended by either guard (or by #728's `reasoning_loop_recovery: "stop"`) keeps `finish_reason: "length"` and adds Strata's own `"stop_cause": "repetition"` / `"reasoning_loop"`. On the OpenAI chat API, streamed and not.
- **`serve/structured.py`:** a structured answer ended that way fails with a message that says the reply repeated itself, instead of "increase the output budget", which a larger `max_tokens` cannot fix. Responses API too.
  - Seen with a one-field `json_schema` on a scanned rent roll: the model wrote the escaped newline 256 times, #606 stopped it, and the client was told to raise the budget.
- **Docs:** `docs/DETAILS.md`.

## Extra Notes
- **Default path:** with the default `repeat_stop_period` 1, the guard code is skipped. Replies that end normally, or at `max_tokens`, are unchanged. `stop_cause` and the new message appear only when #606 or #728 already end a reply, which are replies that were already cut short.
- **Tests:**
  - `serve/test_server.py` `RepeatStop`: off by default, a phrase ended with period 16, period 1, a long varied reply runs to its end;
  - `serve/test_structured.py`: the message, `stop_cause` streamed and not, and no cause for a real budget stop.
  - All `serve` and setup test files pass on `main` 61b3fb5d (1158 tests; rebased).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

本站相关内容

相关页面的快捷入口。