Stale tool call states cleared on agent cancellation
Cancelled agents now properly clear their in-flight tool calls, preventing confusing UI states where actions appeared available after reload.
When an agent run gets cancelled or encounters an error while a tool call (such as a human-in-the-loop approval prompt) is still pending, the UI previously showed that tool call as still waiting for input — even after the user reloaded the page. The tool call looked active but was effectively dead.
This fix ensures that when an agent run terminates in a cancelled or error state, all in-flight tool calls have their loading indicator cleared. The isLoading flag is now set to false on every pending tool call when a run finishes, gets cancelled, or when an individual agent completes. A snapshot is also saved after cancellation to persist this cleaned-up state across reloads.
The change lives in the agent run reducer and the instance AI service. State that previously could persist with phantom tool calls now accurately reflects what the user can actually do.
View Original GitHub Description
Summary
If you cancel the message generation while there's a HITL prompt (or other tool call) in progress we don't mark the tool calls cancelled, meaning they remain there visible as if they could be approved, even after reload.
This also fixes that.
Related Linear tickets, Github issues, and Community forum posts
<!-- Include links to **Linear ticket** or Github issue or Community forum post. Important in order to close *automatically* and provide context to reviewers. https://linear.app/n8n/issue/ --> <!-- Use "closes #<issue-number>", "fixes #<issue-number>", or "resolves #<issue-number>" to automatically close issues when the PR is merged. -->Review / Merge checklist
- PR title and summary are descriptive. (conventions) <!-- **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** -->
- Docs updated or follow-up ticket created.
- Tests included. <!-- A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. -->
- PR Labeled with
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)