Skip to content

fix(core): break agent loop on permission rejection with feedback#33623

Open
Haohao-end wants to merge 1 commit into
anomalyco:devfrom
Haohao-end:permission-rejection-loop
Open

fix(core): break agent loop on permission rejection with feedback#33623
Haohao-end wants to merge 1 commit into
anomalyco:devfrom
Haohao-end:permission-rejection-loop

Conversation

@Haohao-end

Copy link
Copy Markdown

Issue for this PR

Closes #28793

Type of change

  • Bug fix

What does this PR do?

When a user rejects a tool call with a feedback message, the permission system throws CorrectedError (carrying the user's reason in .feedback). This is a separate class from RejectedError (plain rejection, no message).

The loop-break checks in both the V1 processor and V2 session runner only caught RejectedError and Question.RejectedError, missing CorrectedError entirely. So ctx.blocked was never set, the agent loop kept running, and the parent re-delegated the same command indefinitely — infinite loop.

Changes:

  • packages/opencode/src/session/processor.ts — added PermissionV1.CorrectedError to the instanceof check so the V1 loop breaks on rejection-with-feedback.
  • packages/core/src/session/runner/llm.ts — extended the V2 halt check (renamed isQuestionRejectedisHalted) to also match PermissionV2.RejectedError and PermissionV2.CorrectedError.

CorrectedError.message already includes the feedback text, so errorMessage() picks it up and the reason reaches the model as part of the tool-error result. The missing piece was the loop-break itself.

How did you verify your code works?

  • bun typecheck passes for both packages/core and packages/opencode.
  • Configured a primary agent with bash: "deny" and a subagent with bash access. Rejected a delegated bash command with a reason in the permission prompt. The agent loop now halts immediately instead of retrying indefinitely.

Screenshots / recordings

N/A — logic change, no UI impact.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a potentially related PR:

Related PR:

Why it might be related:
This PR addresses a similar issue with permission rejection feedback but appears to be focused on the V1 opencode layer, while #33623 is the current PR fixing both V1 processor and V2 session runner. #31861 may have been a partial fix or related investigation. Check if it's been merged/superseded or if there are any overlapping changes that should be coordinated.

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.

Subagent does not receive user rejection reason from bash permission prompt

1 participant