Skip to content

Stop agents retrying the same failing fix: roll back and retry on another provider (#391) - #1672

Merged
currentbits merged 3 commits into
mainfrom
coder/thrash-detector-interrupt-same-error-ret-e35b3e
Oct 18, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/thrash-detector-interrupt-same-error-ret-e35b3e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

When an agent keeps retrying the same broken fix, Solenta now steps in instead of letting the run burn tokens: it stops the run, rolls the worktree back to the last green checkpoint, hands the task to a different provider, and posts a plain-language note saying what happened. Closes #391.

Changes

  • Detection: the same command failing with the same error 3 times, with a code edit before each retry, counts as thrashing. A re-run with no edit in between isn't a new attempt, and a different error restarts the count. It watches finished tool calls for every provider (they all close through noteToolSpan) and the verify loop.
  • Recovery: stop the run (an orchestrator's workers keep running), then restoreCheckpoint to the last checkpoint where verify passed (lastGreenSha, now recorded on each pass). With no verify command it uses the last finished turn; if verify has never passed it skips the rollback. Then it switches to the first installed provider that differs from the current one (quota failover order first) and retries with the original request plus an account of what kept failing.
  • One shot per problem: a second thrash before a turn lands green stops the thread and explains, with no further switching. Three identical verify failures now take this path instead of ending in a plain "failed".

Verification

  • electron/test/thrash.test.js: tracker unit cases, plus two real-runner cases with a fake Claude CLI:
    • in-run loop on npm test: stopped, worktree reset to the checkpoint, the run's stray file gone, provider switched to a fake OpenCode, retry prompt carries the original request
    • verify loop: three identical failures hand off
  • After rebasing on current main: thrash, verify-gate, quota-wait, otel-runner, checkpoints, claude and ipc-seam suites pass 91/91.
  • Full test:electron locally (before the rebase): 38 failures, all from machine load. Several other worktrees were running their suites at the same time, and the files that hung here also hung there on branches without this change. Run alone, every failing file passes, and the same set passes 194/194 on a clean checkout of the base commit. CI is the real check.

Notes for reviewers

  • This changes your files on its own. It runs git reset --hard on the thread worktree. Uncommitted edits are saved in a safety commit first, recoverable with git reflog (the event message says so), and there is no setting to turn it off. Asking before acting, like OpenCode's doom_loop approve/reject, would be a follow-up if wanted.
  • The error match is heuristic: it compares the first three error-looking lines, with timestamps, durations and ids stripped. A failure that was already there before the agent started, and keeps recurring while it edits other files, can trigger it.
  • Remote threads: on ssh/WSL there's no rollback (listCheckpoints is local), and a provider installed only on the remote machine won't be picked.
  • The tracker is in memory, so an app restart clears the counts.

claude-opus-5-5 via Claude Code

🤖 Generated with Claude Code

…ther provider (#391)

Thrash detector: when the same command fails with the same error three
times, with a code edit before each retry (tool calls or the verify loop),
stop the run, reset the worktree to the last verified-green checkpoint,
switch to a different installed provider and retry with a plain-language
explanation. One automatic recovery per problem; a second hit stops and
explains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a00d7c7a92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread electron/thrash.js
Comment on lines +137 to +139
noteSuccess(threadId) {
const s = threads.get(threadId);
if (s) s.recovered = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear prior failures after a green turn

When a verification command fails twice and a subsequent fix passes, noteSuccess resets only the recovery flag while retaining the command's failure count and edit mark. If the same command fails once during a later task after another edit, noteFailure immediately reports a third attempt and triggers rollback/provider switching even though the previous problem was resolved. Clear the tracked keys when a turn lands green so the next failure starts a new sequence.

Useful? React with 👍 / 👎.

Comment thread electron/runner-thrash.js
Comment on lines +118 to +120
const green = thread.lastGreenSha
? list.find((c) => c.sha === thread.lastGreenSha)
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate the green checkpoint when the verify command changes

When a user changes verifyCommand after an earlier command passed, setVerifyCommand updates only the command, leaving lastGreenSha intact. Three failures of the new command therefore cause this code to reset the worktree to a checkpoint that was only proven by the old command, even if the new command has never passed; associate the SHA with the command or clear it whenever the command changes.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T20:47:55.481418Z a00d7c7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits enabled auto-merge (squash) October 18, 2026 21:01
Two Date.now() calls could straddle a millisecond on slow CI, so the
tool_result never matched its tool_use and the edit never counted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@currentbits
currentbits merged commit 9372bee into main Oct 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thrash detector: interrupt same-error retry loops with rollback and a provider switch

1 participant