Skip to content

Commit bff47ed

Browse files
PierrunoYTclaude
andcommitted
test(task): pin the reasoning loop detector's length and repetition thresholds
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 078965f commit bff47ed

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/core/task/__tests__/ReasoningLoopDetector.spec.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("ReasoningLoopDetector", () => {
1414
expect(detected).toBe(true)
1515
})
1616

17-
it("does not flag repeated short phrases or ordinary long reasoning", () => {
17+
it("does not flag ordinary long reasoning made of distinct lines", () => {
1818
const detector = new ReasoningLoopDetector()
1919
const reasoning = Array.from(
2020
{ length: 40 },
@@ -24,4 +24,33 @@ describe("ReasoningLoopDetector", () => {
2424

2525
expect(detector.add(reasoning)).toBe(false)
2626
})
27+
28+
it("does not flag a short phrase repeated a few times", () => {
29+
const detector = new ReasoningLoopDetector()
30+
31+
expect(detector.add("Let me read the files.\n".repeat(10))).toBe(false)
32+
})
33+
34+
// A cycle of `length` characters that is not periodic itself, so only its own length can match.
35+
const cycleOf = (length: number) =>
36+
Array.from({ length: 200 }, (_, index) => `w${index} `)
37+
.join("")
38+
.slice(0, length)
39+
40+
// MIN_PATTERN_LENGTH is 80 and REQUIRED_REPETITIONS is 5.
41+
it.each([
42+
{ length: 80, repetitions: 5, flagged: true },
43+
{ length: 80, repetitions: 4, flagged: false },
44+
{ length: 81, repetitions: 5, flagged: true },
45+
{ length: 81, repetitions: 4, flagged: false },
46+
{ length: 79, repetitions: 5, flagged: false },
47+
// 9 repeats hold only 4.5 copies of the doubled 158-character cycle, which is still below the threshold.
48+
{ length: 79, repetitions: 9, flagged: false },
49+
// 10 repeats are 5 copies of the doubled cycle, so a short cycle is still caught once it persists.
50+
{ length: 79, repetitions: 10, flagged: true },
51+
])("flags a $length-character cycle repeated $repetitions times: $flagged", ({ length, repetitions, flagged }) => {
52+
const detector = new ReasoningLoopDetector()
53+
54+
expect(detector.add(cycleOf(length).repeat(repetitions))).toBe(flagged)
55+
})
2756
})

0 commit comments

Comments
 (0)