Consolidate stall-watchdog's repetition detector into subagent/repetition.ts - #562
Merged
TheGreatAxios merged 2 commits intoAug 23, 2026
Merged
Conversation
…tion.ts stall-watchdog.ts carried its own char-level tail-repetition detector (constants + a thin wrapper over detectSequencePeriod), duplicating a detector that already lived in subagent/repetition.ts under a different name and shape. Moved detectCharRepetition (with its constants and rationale comments) into subagent/repetition.ts; stall-watchdog.ts now re-exports it as detectRepetition/RepetitionCheck for its existing callers. No threshold values changed. The two detectors solve the same "is the tail looping" question with genuinely different algorithms (KMP + normalization for streamed model text vs. a plain per-char search with a distinct-chars floor for the TUI's live buffer) so they were kept as separate functions rather than merged into one, per CL-6939 / CL-6790.
…directly Removed the RepetitionCheck/detectRepetition compatibility re-exports from stall-watchdog.ts — with only two consumers (turn-state.ts and stall-watchdog.test.ts) an alias for an internal module wasn't earning its keep. Both now import directly from subagent/repetition.js. Renamed the moved function to detectTailCharLoop (TailCharLoopCheck) so it reads clearly next to subagent/repetition.ts's existing detectRepetition (the KMP + digit-folding detector for streamed model text) rather than shadowing its name. Threshold values (8 / 24 / 2000 / 8) unchanged. CL-6939 / CL-6790.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of CL-6939 (item 3 only) and CL-6790 — neither issue should auto-close on this merge.
Summary
CL-6939 / CL-6790:
src/tui/stall-watchdog.tscarried its own char-level tail-repetition detector (four constants —REPETITION_MIN_PERIOD,REPETITION_MIN_REPEATS,REPETITION_MAX_PERIOD_CAP,REPETITION_MIN_DISTINCT_CHARS— plus a thin wrapper overdetectSequencePeriod), duplicating a detector that conceptually belongs next tosrc/subagent/repetition.ts's existing degenerate-repetition guard.src/subagent/repetition.ts, renamed todetectTailCharLoop/TailCharLoopCheck(constants keep theCHAR_prefix) so it reads clearly next to that module's pre-existingdetectRepetition(a different, KMP + digit-folding detector for streamed model text) rather than shadowing its name.src/tui/stall-watchdog.tsno longer re-exports anything for this — the olddetectRepetition/RepetitionChecknames are gone from that file entirely.detectTailCharLoopdirectly fromsrc/subagent/repetition.js:src/tui/turn-state.tsandsrc/tui/stall-watchdog.test.ts. Verified with grep that nothing still imports the old names fromstall-watchdog.js.src/util/period-detection.ts(the genericdetectSequencePeriodprimitive) is untouched — it's the shared enginedetectTailCharLoopdelegates to, same as before.No threshold value changed. Every constant (8, 24, 2000, 8) carries over unchanged.
Not merged into one function:
subagent/repetition.ts's pre-existingdetectRepetition(used byrun.ts/summarizer.ts) and the newly-addeddetectTailCharLoop(used by the TUI) solve the same "is the tail looping" question with genuinely different algorithms — normalize + KMP + optional digit-folding for streamed model text vs. a plain per-character search with a distinct-chars floor for the TUI's live buffer. Keeping them as two functions in one module avoids retuning either to match the other, per the standing no-threshold-retuning rule.Net line delta: -9 (
git diff --statmain...branch:+22 insertions, -31 deletionsacrosssrc/subagent/repetition.ts,src/tui/stall-watchdog.ts,src/tui/stall-watchdog.test.ts,src/tui/turn-state.ts).Test plan
bun test src/tui/stall-watchdog.test.ts src/subagent/repetition.test.ts src/tui/turn-state.test.ts— 99 pass, all existing coverage preserved (no tests deleted)bunx tsc --noEmitcleanbun run check— 5277 pass, 0 fail