Skip to content

fix(app): add doom loop detector to prevent repetitive tool calls#2368

Merged
tusharmath merged 31 commits intomainfrom
doom-loop-detector
Mar 11, 2026
Merged

fix(app): add doom loop detector to prevent repetitive tool calls#2368
tusharmath merged 31 commits intomainfrom
doom-loop-detector

Conversation

@amitksingh1490
Copy link
Copy Markdown
Contributor

@amitksingh1490 amitksingh1490 commented Feb 8, 2026

Here is a conversation. dump demonstrating dooms loop detection
2026-02-08_19-36-42-dump.html

@github-actions github-actions Bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Feb 8, 2026
Comment thread crates/forge_app/src/orch.rs Outdated
Err(err) => ToolResult::new(tool_call.name.as_str())
.call_id(tool_call.call_id.clone())
.failure(err),
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are errors that we want to propagate back to the agent, and sometimes there are errors that we want to show to the user. In this case that nuance is getting missed.

@github-actions
Copy link
Copy Markdown

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions Bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Feb 24, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 7, 2026

PR closed after 10 days of inactivity.

@github-actions github-actions Bot closed this Mar 7, 2026
@tusharmath tusharmath reopened this Mar 8, 2026
@github-actions github-actions Bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Mar 8, 2026
Comment thread crates/forge_app/src/orch.rs Outdated
Comment on lines +161 to +163
forge_domain::HandleOperation::AgentError(err) => {
vec![anyhow::anyhow!("{}", err)]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Converting Arc<anyhow::Error> to string and back loses the original error type, backtrace, and error chain. This makes debugging difficult in production when doom loop errors occur. The conversion anyhow::anyhow!("{}", err) only preserves the Display output.

Fix by cloning the Arc or using anyhow::Error::msg:

forge_domain::HandleOperation::AgentError(err) => {
    vec![(*err).clone()]
}

This preserves the full error context for proper error reporting.

Suggested change
forge_domain::HandleOperation::AgentError(err) => {
vec![anyhow::anyhow!("{}", err)]
}
forge_domain::HandleOperation::AgentError(err) => {
vec![(*err).clone()]
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this suggestion won't compile

Comment thread crates/forge_app/src/hooks/doom_loop.rs Outdated
Some((tool_name, count))
}

fn extract_tool_signatures(&self, conversation: &Conversation) -> Vec<(ToolName, String)> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fn extract_tool_signatures(&self, conversation: &Conversation) -> Vec<(ToolName, String)> {
fn extract_tool_signatures(&self, conversation: &Conversation) -> Vec<(ToolName, ToolCallArguments)> {

Comment thread crates/forge_app/src/hooks/doom_loop.rs Outdated
pub fn detect_from_conversation(
&self,
conversation: &Conversation,
) -> Option<(ToolName, usize)> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) -> Option<(ToolName, usize)> {
) -> Option<usize> {

Can just return the index.

@tusharmath tusharmath enabled auto-merge (squash) March 11, 2026 12:28
@tusharmath tusharmath changed the title feat(app): add doom loop detector to prevent repetitive tool calls fix(app): add doom loop detector to prevent repetitive tool calls Mar 11, 2026
@github-actions github-actions Bot added the type: fix Iterations on existing features or infrastructure. label Mar 11, 2026
@tusharmath tusharmath merged commit d1e0547 into main Mar 11, 2026
9 checks passed
@tusharmath tusharmath deleted the doom-loop-detector branch March 11, 2026 12:31
@tusharmath tusharmath removed the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Mar 11, 2026
tusharmath added a commit that referenced this pull request Mar 13, 2026
…2368)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: ForgeCode <noreply@forgecode.dev>
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants