Skip to content

fix: Filter out disabled AI Agent tool parents when mapping connected tools#28743

Closed
Dom-Tursini wants to merge 1 commit inton8n-io:masterfrom
Dom-Tursini:fix/ai-tool-parent-node-alignment
Closed

fix: Filter out disabled AI Agent tool parents when mapping connected tools#28743
Dom-Tursini wants to merge 1 commit inton8n-io:masterfrom
Dom-Tursini:fix/ai-tool-parent-node-alignment

Conversation

@Dom-Tursini
Copy link
Copy Markdown

@Dom-Tursini Dom-Tursini commented Apr 20, 2026

Summary

This fixes a tool/source-node desync in getConnectedTools() for AI Agent tool connections when disabled AI tool nodes remain connected.

Previously, toolkitConnections excluded disabled AI tool nodes, while parentNodes still included them. Because the helper correlates both arrays by index, disabling any AI tool node caused later tools to receive the wrong sourceNodeName.

This change filters disabled nodes out of parentNodes so both arrays use the same active-node set and stay index-aligned.

A regression test was added to cover the case where a disabled tool node appears between active tool connections.

How to test:

  1. Create an AI Agent with multiple connected AI tool nodes.
  2. Disable one tool node that is not the last in the connection order.
  3. On the affected code path, later tools are mapped to the wrong sourceNodeName.
  4. Verify with this change that later tools remain mapped to the correct source node.
  5. Run pnpm test -- utils/tests/helpers.test.ts --runInBand in packages/@n8n/nodes-langchain.

Related Linear tickets, Github issues, and Community forum posts

#26356

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 20, 2026

CLA assistant check
All committers have signed the CLA.

@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch from 9f32c74 to 7a6d889 Compare April 20, 2026 19:11
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Architecture diagram
sequenceDiagram
    participant Agent as AI Agent Node
    participant Helper as getConnectedTools()
    participant Context as n8n Workflow Context

    Note over Agent,Context: Tool Connection Mapping Flow

    Agent->>Helper: Invoke tool resolution
    
    Helper->>Context: getInputConnectionData(AiTool)
    Context-->>Helper: toolkitConnections (Active tool objects)

    Helper->>Context: getParentNodes(currentNode, AiTool)
    Context-->>Helper: parentNodes (All connected nodes)

    rect rgb(240, 240, 240)
        Note over Helper: Fix: Prevent index desync
        Helper->>Helper: NEW: Filter out nodes where disabled === true
    end

    loop For each tool in toolkitConnections
        Helper->>Helper: CHANGED: Map tool to parentNode by matching index
        Note right of Helper: Correlation relies on identical list lengths
    end

    Helper-->>Agent: Return tools with correct sourceNodeName metadata
Loading

@n8n-assistant n8n-assistant Bot added the community Authored by a community member label Apr 20, 2026
@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch from 7a6d889 to ec053b8 Compare April 21, 2026 23:52
@Dom-Tursini Dom-Tursini changed the title fix: Filter disabled AI tool parents when mapping connected tools fix: Filter out disabled AI Agent tool parents when mapping connected tools Apr 21, 2026
@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch 2 times, most recently from d0bef14 to 08bee6d Compare April 28, 2026 22:33
@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch 12 times, most recently from e3eeddb to 2fbfe35 Compare May 8, 2026 09:33
@Dom-Tursini Dom-Tursini requested a review from a team as a code owner May 8, 2026 09:33
@Dom-Tursini Dom-Tursini requested a review from schrothbn May 8, 2026 09:33
@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch 2 times, most recently from 86472c8 to 66b1602 Compare May 8, 2026 12:38
@Dom-Tursini Dom-Tursini force-pushed the fix/ai-tool-parent-node-alignment branch from 66b1602 to 4759491 Compare May 10, 2026 21:02
@Dom-Tursini Dom-Tursini reopened this May 10, 2026
@Dom-Tursini
Copy link
Copy Markdown
Author

Closing this as the fix has been merged via #29460 by @schrothbn . I’m glad to see the index-desync I identified here was resolved using the same logic. Hopefully, the regression tests I included here can still be useful for the core team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Authored by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants