Skip to content

Consolidate stall-watchdog's repetition detector into subagent/repetition.ts - #562

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-6939-consolidate-the-duplicate-repetition-detector
Aug 23, 2026
Merged

Consolidate stall-watchdog's repetition detector into subagent/repetition.ts#562
TheGreatAxios merged 2 commits into
mainfrom
cl-6939-consolidate-the-duplicate-repetition-detector

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

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.ts carried 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 over detectSequencePeriod), duplicating a detector that conceptually belongs next to src/subagent/repetition.ts's existing degenerate-repetition guard.

  • Moved the constants, doc comments, and the wrapper function into src/subagent/repetition.ts, renamed to detectTailCharLoop / TailCharLoopCheck (constants keep the CHAR_ prefix) so it reads clearly next to that module's pre-existing detectRepetition (a different, KMP + digit-folding detector for streamed model text) rather than shadowing its name.
  • src/tui/stall-watchdog.ts no longer re-exports anything for this — the old detectRepetition / RepetitionCheck names are gone from that file entirely.
  • The two real consumers now import detectTailCharLoop directly from src/subagent/repetition.js: src/tui/turn-state.ts and src/tui/stall-watchdog.test.ts. Verified with grep that nothing still imports the old names from stall-watchdog.js.
  • src/util/period-detection.ts (the generic detectSequencePeriod primitive) is untouched — it's the shared engine detectTailCharLoop delegates 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-existing detectRepetition (used by run.ts/summarizer.ts) and the newly-added detectTailCharLoop (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 --stat main...branch: +22 insertions, -31 deletions across src/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 --noEmit clean
  • bun run check — 5277 pass, 0 fail

…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.
@linear-code

linear-code Bot commented Aug 23, 2026

Copy link
Copy Markdown

CL-6939

…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.
@TheGreatAxios
TheGreatAxios merged commit 2369021 into main Aug 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant