Skip to content

Commit ff3ad2d

Browse files
fix(processor): detect doom loops across messages instead of within current message
Count repeated identical tool calls across the full (compaction-filtered) message history rather than only the trailing parts of the current assistant message, so a doom loop is detected even when the repeats span multiple assistant messages. Ported from anomalyco#32089 (adapted for the Effect layer). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 8940efc commit ff3ad2d

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎packages/opencode/src/session/processor.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,20 @@ const layer = Layer.effect(
350350
: value.providerMetadata,
351351
}))
352352

353-
const parts = yield* MessageV2.parts(ctx.assistantMessage.id).pipe(
353+
const msgs = yield* MessageV2.filterCompactedEffect(ctx.sessionID).pipe(
354354
Effect.provideService(Database.Service, database),
355355
)
356-
const recentParts = parts.slice(-DOOM_LOOP_THRESHOLD)
357-
358-
if (
359-
recentParts.length !== DOOM_LOOP_THRESHOLD ||
360-
!recentParts.every(
356+
const matchingParts = msgs
357+
.flatMap((m) => m.parts)
358+
.filter(
361359
(part) =>
362360
part.type === "tool" &&
363361
part.tool === value.name &&
364362
part.state.status !== "pending" &&
365363
JSON.stringify(part.state.input) === JSON.stringify(input),
366364
)
367-
) {
365+
366+
if (matchingParts.length < DOOM_LOOP_THRESHOLD) {
368367
return
369368
}
370369

0 commit comments

Comments
 (0)