Skip to content

fix(opencode): doom_loop permission false-triggers on parallel/same-batch tool calls and non-failure statuses #725

Closed

Description

@agenteinstinct1-max

Observed

In a TUI session, two Invalid tool call: websearch repairs (websearch exists and has been loaded — call it again, the deferred-tool retry path in packages/opencode/src/session/llm.ts experimental_repairToolCall) were immediately followed by the doom_loop permission prompt ("Continue after repeated failures"). The user had to unblock a session that was not in a loop.

Source-qualified causal conditions (dev-vibecoded @ 3d4c83f)

packages/opencode/src/session/processor.ts, tool-call case, DOOM_LOOP_THRESHOLD = 3:

const recentParts = parts.slice(-DOOM_LOOP_THRESHOLD)
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))) {
  return
}
yield* permission.ask({ permission: "doom_loop", ... })

Three structural problems vs the stated intent (the inline comment says "three identical failures", ref #186):

  1. No failure requirement: the check accepts any status !== "pending" — successful calls, and calls that never executed (e.g. invalid repair placeholders), count toward "repeated failures".
  2. No batch/step distinction: parallel tool calls from the SAME assistant step (one fan-out, zero intervening model turns) are indistinguishable from the same call repeated across three separate no-progress iterations. A single batch of 3 identical calls trips the guard mid-batch.
  3. Lazy-load retry interacts: the deferred-tool repair explicitly instructs an identical retry ("call it again"). The retry is the designed recovery, yet its identical name+input is exactly what the guard counts.

The intended protection (stop a sequential, no-progress, repeated-failure loop) is correct and must be preserved.

Fix directions (no bypass, no heuristic weakening)

  • Count only tool executions that actually ran and produced an outcome; exclude invalid repair placeholders.
  • Require repetitions across distinct generation steps (intervening assistant output), not members of one parallel batch.
  • Keep the identical name+input comparison, the threshold, and the doom_loop permission with its countdown semantics (feat(permission): auto-deny permission prompts after a countdown #186) for true loops.
  • Deterministic tests: (a) 3 identical calls in one batch → no prompt; (b) same call failing across 3 separate steps → prompt fires; (c) deferred-tool repair followed by its instructed retry → no prompt from the repair pair.

Found via user report with a session screenshot (kept private); description here is source-verified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions