mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3229] [Engine] loop guard: early sentence-run detection, medium-effort splice and sampling-raise-only recovery #4511
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4511
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3229
Author: @Yunado
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:loop-guard-v2📝 Commits (5)
8f06864loop guard: catch a young sentence loop and splice medium effort on recovery6714badserve: recover a repeated reasoning on the sampling raise when no effort sentence matchesa62c7daMerge the sampling-raise-only recovery into the guard brancha3bd66eserve: keep the no-splice recovery inside template prompts (serves the suite contract)a9d8234ci: re-run the suite (NoLeakedSampler is a known flaky, see the PR comment)📊 Changes
3 files changed (+203 additions, -24 deletions)
View changed files
📝
docs/DETAILS.md(+15 -8)📝
serve/server.py(+69 -16)➕
tools/loop_guard_test.py(+119 -0)📄 Description
The problem and the result. The opt-in
"reasoning_loop_recovery"guard (#728) misses, or catches too late, or catches and does nothing, in three production shapes:focused_recovery_promptreturns None and the caller (if recover_prompt is not None: break) silently keeps generating: a production loop at low burned 29,476 output tokens withreasoning_recoveries=0while the detector itself reported coverage 1.0.After this change the guard fires on a young sentence run (the same sentence 5 times in a row; sentences under 8 words and 40 characters never count, so repeated code and short lines cannot trigger it), the recovery splices the medium sentence exactly as the xhigh one, and when a template prompt (one whose first turn is a system message) carries no effort sentence at all the resume goes on from the same ids with the sampling raise the resume block already performs (temperature to at least 1.0, presence penalty to at least 1.5), the server window saying "on the sampling raise alone". A prompt without a system message was never a native-effort run and stays without recovery, exactly as
test_missing_native_high_hint_skips_recoverycontracts:focused_recovery_promptconflates the two None shapes, so the caller separates them withprompt_has_system_turn(the same head test the splice itself makes).The approach. The hunks all live inside the guarded block: the sentence-run counter (
reasoning_sentence_run) feeds the same trigger as coverage and the periodic tail;focused_recovery_promptmatches either effort sentence and splices the first occurrence (the xhigh splice stays byte-identical to the old single-sentence algorithm); asplicedflag records which recovery ran and only changes the window line;SYSTEM_HEADis spelled once, built fromIM_END."stop", the default path (both keys off) and requests with images are byte-identical.Validation.
py_compileon serve/server.py;tools/loop_guard_test.py, 19 assertions without a GPU or a model (the medium splice to low, the xhigh splice byte-identical to the old algorithm, the sentence-run firing on the production shape while the coverage look is still under its line, silence on short code pieces, numbered enumerations and interleaved text, a Chinese sentence run counted by characters, the dense-loop coverage regression, and both sides of the system-turn gate: bare recovery allowed with a system turn, recovery stayed skipped without one);python -m unittest serve.test_reasoning_loop_recovery: the suite's 18 recovery tests pass, including the contract test above; two further assertions on a fake tokenizer:focused_recovery_promptreturns None for a low-effort render (the trigger of the no-splice branch) and the xhigh splice is unchanged.Limits. The sentence-run trigger can mistake a deliberately repeated useful sentence for a loop, as the coverage look can; the opt-in keys are unchanged and nothing fires when they are off. At low there is no sentence left to splice down to, so the sampling raise is the only lever; if it does not break the loop the request finishes as "length" as it does today.
Environment:
e88ee39d(v0.2.0-beta-12), Windows 11 Pro, Python 3.12.0, RTX 5090.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.