Skip to content

fix(approvals): cancel pending approval prompts when agent aborts - #71

Open
imMamdouhaboammar wants to merge 9 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/approval-abort
Open

fix(approvals): cancel pending approval prompts when agent aborts#71
imMamdouhaboammar wants to merge 9 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/approval-abort

Conversation

@imMamdouhaboammar

Copy link
Copy Markdown

Summary

Propagate the active agent AbortSignal into tool-approval middleware and make ApprovalManager cancel displayed or queued requests when a run is aborted.

Root cause

Approval middleware previously received only the tool call and agent context. If the user aborted while an interactive approval was pending, the agent stream could stop but ApprovalManager.askUser() remained unresolved and its current request stayed published to the TUI. The approval prompt therefore continued to occupy the interface until the user answered a request belonging to an already-cancelled run.

Changes

  • expose the active run AbortSignal in beforeToolUse middleware params
  • pass that signal from Agent._act() through _beforeToolUse()
  • make coding approval callbacks accept the optional signal and forward it to askUser
  • make ApprovalManager.askUser() signal-aware
  • reject and remove aborted current or queued approvals with AbortError
  • remove abort listeners after resolution/cancellation
  • advance the approval queue normally and publish null when it becomes empty

Regression coverage

  • current approval cancellation rejects and clears subscriber state
  • queued approval cancellation removes the request before it can become active
  • end-to-end Agent test confirms abort clears the displayed approval and the protected tool is never invoked

This complements tool-level cancellation by ensuring the interactive approval UI is cancelled at the same session boundary.

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.

1 participant