Skip to content

fix(opencode): keep doom-loop guard to real failures across steps (Refs #725) - #746

Closed
agenteinstinct1-max wants to merge 2 commits into
dev-vibecodedfrom
arena/f91f6cac-silvercode
Closed

agenteinstinct1-max wants to merge 2 commits into
dev-vibecodedfrom
arena/f91f6cac-silvercode

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Refs #725 (draft — intentionally using Refs rather than a closing keyword so #725 is not auto-closed)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Refs #725. Replaces the closed #728 draft on a fresh branch and incorporates the review fixes on top of the doom-loop guard rework in packages/opencode/src/session/processor.ts.

Previously, processor.ts checked parts.slice(-DOOM_LOOP_THRESHOLD) for status !== "pending" tool parts, which false-triggered doom_loop on parallel sibling calls within one generation step, successful calls, and experimental_repairToolCall's "invalid" deferred-tool placeholder.

Changes in packages/opencode/src/session/processor.ts:

  • Count only finished (completed / error) tool executions and exclude the reserved literal "invalid" repair placeholder (llm.ts strips "invalid" from activeTools and uses it only for experimental_repairToolCall).
  • Build the DOOM_LOOP_THRESHOLD - 1 evidence window from distinct generation steps (step-start boundaries), newest-first, rather than raw execution slots: sibling calls fanned out in one step do not self-trigger within that batch, while a failing batch repeated across three steps still trips the guard instead of displacing cross-step evidence.
  • Page backward from a cursor strictly before ctx.assistantMessage and memoize the prior-turn execution steps once per process() attempt, avoiding current-message duplication, repeated DB reads per step, and fixed history-count truncation across tool-less turns.
  • Skip synthetic continuation user messages (FINISH_NUDGE, REVIEW_STAGNATION_NUDGE, auto-compaction/subtask continuations) while stopping at real user messages, and remove the fail-open catchCause and index < 0 early-return paths.

How did you verify your code works?

Added deterministic Effect tests in packages/opencode/test/session/processor-effect.test.ts (stubbing Permission.Service and LLM.Service) covering:

  1. 3 identical failing calls fanned out in a single batch -> 0 asks.
  2. Identical failing single call repeated across 3 steps -> 1 doom_loop ask on step 3.
  3. Identical failing 2-call batch repeated across 3 steps -> 0 asks on steps 1–2, 1 doom_loop ask on step 3.
  4. Identical successful (completed) calls repeated across 3 steps -> 0 asks.
  5. Deferred-tool "invalid" repair placeholders (within one step and across steps) followed by the instructed retry -> 0 asks.
  6. An "invalid" placeholder between real failures neither counts as a failure nor breaks a genuine 3-step failure streak.
  7. An intervening completed call breaks the failure streak until two new consecutive failing steps precede the next retry.
  8. Synthetic user nudges and >6 intervening tool-less messages preserve the streak within the active user turn, while a real user message resets it.

Validation

  • bun test test/session/processor-effect.test.ts -t "doom loop" (packages/opencode): 8 pass, 0 fail (30 expect() calls)
  • bun test --timeout 30000 test/session/processor-effect.test.ts (packages/opencode): 38 pass, 0 fail (191 expect() calls)
  • bun test --timeout 30000 test/session (packages/opencode): 838 pass, 8 skip, 1 todo, 0 fail (2635 expect() calls across 36 files)
  • NODE_OPTIONS="--max-old-space-size=3000" bun turbo typecheck --concurrency=1: 17/17 packages pass (0 errors, including full tsc --noEmit in packages/opencode)
  • ./node_modules/.bin/oxlint packages/opencode/src/session/processor.ts packages/opencode/test/session/processor-effect.test.ts: 0 errors, no new warnings (11 pre-existing warnings)

Screenshots / recordings

N/A — backend session processor logic only (no UI changes).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant