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

Closed
opened 2026-11-07 15:30:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1803
Author: @gt50
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: repetition


📝 Commits (2)

  • c5ce86b serve: an opt-in guard for a repeated phrase (repeat_stop_period), and name repetition stops (stop_cause)
  • 20baf99 serve: stop_cause only with repeat_stop_period set; the repetition error names no unmerged option

📊 Changes

5 files changed (+159 additions, -6 deletions)

View changed files

📝 docs/DETAILS.md (+10 -0)
📝 serve/server.py (+51 -2)
📝 serve/structured.py (+19 -2)
📝 serve/test_server.py (+44 -2)
📝 serve/test_structured.py (+35 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1803 **Author:** [@gt50](https://github.com/gt50) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `repetition` --- ### 📝 Commits (2) - [`c5ce86b`](https://github.com/Niko1221/Strata/commit/c5ce86b038f9cf100f7a1021479640d8de3ff3dc) serve: an opt-in guard for a repeated phrase (repeat_stop_period), and name repetition stops (stop_cause) - [`20baf99`](https://github.com/Niko1221/Strata/commit/20baf99f8134c0d12c92892ab606c838d45e84c7) serve: stop_cause only with repeat_stop_period set; the repetition error names no unmerged option ### 📊 Changes **5 files changed** (+159 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -0) 📝 `serve/server.py` (+51 -2) 📝 `serve/structured.py` (+19 -2) 📝 `serve/test_server.py` (+44 -2) 📝 `serve/test_structured.py` (+35 -0) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3684
No description provided.