Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,21 +516,18 @@ export const layer = Layer.effect(
: value.providerMetadata,
}))

const parts = yield* MessageV2.parts(ctx.assistantMessage.id).pipe(
const msgs = yield* MessageV2.filterCompactedEffect(ctx.sessionID).pipe(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure of this, but I think filterCompactedEffect() loads all messages for the session, so it might be better to query the last X number of messages instead:

yield* MessageV2.page({
  sessionID: ctx.sessionID,
  limit: DOOM_LOOP_MESSAGES,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other concern I had when trying to implement a similar fix here is a scenario where an agent might be re-running a test with edits between to fix it.

  1. Edit
  2. BASH : run test
  3. Edit
  4. BASH : run test
  5. Edit
  6. BASH : run test

In this scenario you may not want the doom loop to trigger as there are parts between the matching tool calls.

Effect.provideService(Database.Service, database),
)
const recentParts = parts.slice(-DOOM_LOOP_THRESHOLD)
const matchingParts = msgs.flatMap((m) => m.parts).filter(
(part) =>
part.type === "tool" &&
part.tool === value.name &&
part.state.status !== "pending" &&
JSON.stringify(part.state.input) === JSON.stringify(input),
)

if (
recentParts.length !== DOOM_LOOP_THRESHOLD ||
!recentParts.every(
(part) =>
part.type === "tool" &&
part.tool === value.name &&
part.state.status !== "pending" &&
JSON.stringify(part.state.input) === JSON.stringify(input),
)
) {
if (matchingParts.length < DOOM_LOOP_THRESHOLD) {
return
}

Expand Down
Loading