Skip to content

Commit 1600efa

Browse files
anandgupta42claude
andcommitted
fix: [#834] address re-review — gate refuse-branch telemetry to transition only
Reviewer N1: every refused call fired `doom_loop_detected` telemetry. A runaway agent that hammers todowrite after refusal would produce ~9,000+ events per session — pure noise. The warn branch already fires once (`===` semantics); the refuse branch was using `>=`, firing repeatedly. Fix: gate the telemetry call to `decision.count === TODOWRITE_REFUSE_THRESHOLD` so it fires exactly once on the transition into refusal. Subsequent refused calls return the same refusal output but emit no telemetry. Also renamed the test "counter survives reset and starts fresh" to "counter is cleared by _resetTodoWriteCounters and starts fresh" — the old name was the opposite of what the test verifies. Validation - typecheck pass - 12 todowrite tests pass - Marker check pass Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 6cb296b commit 1600efa

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎packages/opencode/src/tool/todo.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ export const TodoWriteTool = Tool.define("todowrite", {
119119
const decision = recordTodoWriteCall(ctx.sessionID)
120120

121121
if (decision.action === "refuse") {
122-
Telemetry.track({
123-
type: "doom_loop_detected",
124-
timestamp: Date.now(),
125-
session_id: ctx.sessionID,
126-
tool_name: "todowrite",
127-
repeat_count: decision.count,
128-
})
122+
// Fire telemetry ONLY on the transition into refusal (first call at
123+
// the threshold), not on every subsequent refused call. Without this
124+
// gate, a runaway agent that keeps hammering todowrite after refusal
125+
// produces ~9,000+ doom_loop_detected events per session — pure
126+
// telemetry noise. The transition fires once; subsequent refusals
127+
// remain silent. Mirrors the `===` symmetry of the warn branch.
128+
if (decision.count === TODOWRITE_REFUSE_THRESHOLD) {
129+
Telemetry.track({
130+
type: "doom_loop_detected",
131+
timestamp: Date.now(),
132+
session_id: ctx.sessionID,
133+
tool_name: "todowrite",
134+
repeat_count: decision.count,
135+
})
136+
}
129137
return {
130138
title: `todowrite blocked: ${decision.count} calls this session`,
131139
output:

‎packages/opencode/test/tool/todowrite-loop.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe("recordTodoWriteCall: counter mechanics", () => {
3838
expect(_getTodoWriteCount("session-b")).toBe(1)
3939
})
4040

41-
test("counter survives reset and starts fresh", () => {
41+
test("counter is cleared by _resetTodoWriteCounters and starts fresh", () => {
42+
// Renamed from "counter survives reset" which was misleading — the
43+
// reset clears the counter, it doesn't survive.
4244
recordTodoWriteCall("session-a")
4345
recordTodoWriteCall("session-a")
4446
expect(_getTodoWriteCount("session-a")).toBe(2)

0 commit comments

Comments
 (0)