Bug: "Channel already exists with a different type" error when multiple StateGraphs share field schemas #387

Open
opened 2026-02-15 18:16:23 -05:00 by yindo · 2 comments
Owner

Originally created by @Abdurihim on GitHub (Dec 13, 2025).

Description

Related to langchain-ai/deepagentsjs#75

When using middleware that adds state fields (like filesystem middleware) in both main agents and subagents, a Channel already exists with a different type error is thrown, even though the channel types are identical.

This issue was originally reported in the deepagentsjs repository where users encountered this error when creating agents with middleware.

Minimal Reproduction Repository

🔗 https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction

This repository provides two reproduction methods:

  1. Real-world scenario: Using deepagents library (reproduces the exact error users encounter)
  2. Standalone test: Pure unit test without external APIs

Steps to Reproduce

Method 1: Using deepagents (recommended)

git clone https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction
cd langgraphjs-issue-1820-reproduction
npm install
cp .env.example .env
# Add your OPENAI_API_KEY to .env
npm run reproduce-deepagents

Method 2: Standalone unit test

npm run reproduce-bug

Error Output

Error: Channel "files" already exists with a different type.
    at StateGraph._addSchema (/node_modules/@langchain/langgraph/src/graph/state.ts:516:19)
    at new StateGraph (/node_modules/@langchain/langgraph/src/graph/state.ts:460:10)
    at new ReactAgent (/node_modules/langchain/src/agents/ReactAgent.ts:205:22)
    at createAgent (/node_modules/langchain/src/agents/index.ts:418:10)
    at getSubagents (deepagents/dist/index.js:884:31)
    at createTaskTool (deepagents/dist/index.js:917:73)
    at createSubAgentMiddleware (deepagents/dist/index.js:953:11)
    at createDeepAgent (deepagents/dist/index.js:1897:3)

Expected Behavior

StateGraph should accept schemas that share the same field schema definitions without throwing errors, since the channel types are identical.

Actual Behavior

StateGraph._addSchema uses identity comparison (!==) to check for channel conflicts. Since getChannelsForSchema creates new channel instances each time it's called, even identical channel types fail the identity check.

Environment

  • @langchain/langgraph: 1.0.4
  • deepagents: 1.3.1
  • langchain: 1.2.0
  • zod: 3.24.1
  • Node.js: 20.x

Impact

This prevents using middleware patterns where state fields are shared between main agents and subagents, which is a common use case in multi-agent systems and is blocking users of deepagentsjs.

Fix

A fix is submitted in #1819

Originally created by @Abdurihim on GitHub (Dec 13, 2025). ## Description Related to langchain-ai/deepagentsjs#75 When using middleware that adds state fields (like filesystem middleware) in both main agents and subagents, a `Channel already exists with a different type` error is thrown, even though the channel types are identical. This issue was originally reported in the deepagentsjs repository where users encountered this error when creating agents with middleware. ## Minimal Reproduction Repository 🔗 **https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction** This repository provides two reproduction methods: 1. **Real-world scenario**: Using `deepagents` library (reproduces the exact error users encounter) 2. **Standalone test**: Pure unit test without external APIs ## Steps to Reproduce ### Method 1: Using deepagents (recommended) ```bash git clone https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction cd langgraphjs-issue-1820-reproduction npm install cp .env.example .env # Add your OPENAI_API_KEY to .env npm run reproduce-deepagents ``` ### Method 2: Standalone unit test ```bash npm run reproduce-bug ``` ## Error Output ``` Error: Channel "files" already exists with a different type. at StateGraph._addSchema (/node_modules/@langchain/langgraph/src/graph/state.ts:516:19) at new StateGraph (/node_modules/@langchain/langgraph/src/graph/state.ts:460:10) at new ReactAgent (/node_modules/langchain/src/agents/ReactAgent.ts:205:22) at createAgent (/node_modules/langchain/src/agents/index.ts:418:10) at getSubagents (deepagents/dist/index.js:884:31) at createTaskTool (deepagents/dist/index.js:917:73) at createSubAgentMiddleware (deepagents/dist/index.js:953:11) at createDeepAgent (deepagents/dist/index.js:1897:3) ``` ## Expected Behavior StateGraph should accept schemas that share the same field schema definitions without throwing errors, since the channel types are identical. ## Actual Behavior `StateGraph._addSchema` uses identity comparison (`!==`) to check for channel conflicts. Since `getChannelsForSchema` creates new channel instances each time it's called, even identical channel types fail the identity check. ## Environment - `@langchain/langgraph`: 1.0.4 - `deepagents`: 1.3.1 - `langchain`: 1.2.0 - `zod`: 3.24.1 - Node.js: 20.x ## Impact This prevents using middleware patterns where state fields are shared between main agents and subagents, which is a common use case in multi-agent systems and is blocking users of deepagentsjs. ## Fix A fix is submitted in #1819
Author
Owner

@r0yfire commented on GitHub (Dec 29, 2025):

This comment adds further investigation and validation for the problem described in this issue. Specifically:

  1. Verifying the root cause described in the issue report using attached Jest tests.
  2. Confirming specific scenarios where this behavior arises and proposing possible direction for mitigation.

Findings from Jest Tests

I've written a series of Jest tests (langgraph-channel-bug.test.ts) to investigate the behavior and verify the root cause. The results align with the observations described in the issue:

  1. Key Issue:

    • The getChannelsForSchema method in @langchain-ai/langgraphjs creates new instances of channels (like BinaryOperatorAggregate or LastValue) every time a schema is processed.
    • As a result, schemas with the same reducer channel (like files) fail an identity check (!==) even though their definitions are functionally identical.
    • This causes the StateGraph._addSchema method to throw the error:
      Error: Channel "files" already exists with a different type.
      
  2. Detailed Test Cases:

    • The attached Jest file validates the following:
      • getChannelsForSchema creates distinct instances for each schema processed (Test 1 and Test 2).
      • This results in a failure when state, input, and output schemas share the same channel (Test 2).
      • The workaround of using the same schema object for all three (state/input/output) prevents the error, as deduplication implicitly occurs when getChannelsForSchema is only called once (Test 3).
      • This issue doesn’t affect LastValue channels, which are explicitly allowed to have duplicates (Test 4).

Reproducing the Issue

I’ve attached the Jest test file as a concrete reproduction case.

langgraph-channel-bug.test.ts

You can run the tests directly using Jest to verify the findings.

It seems using middleware based on withLangGraph exacerbates the problem since middleware naturally generates schemas independently for agents, leading to repeated calls to getChannelsForSchema.

@r0yfire commented on GitHub (Dec 29, 2025): This comment adds further investigation and validation for the problem described in this issue. Specifically: 1. Verifying the root cause described in the issue report using attached Jest tests. 2. Confirming specific scenarios where this behavior arises and proposing possible direction for mitigation. #### Findings from Jest Tests I've written a series of Jest tests (`langgraph-channel-bug.test.ts`) to investigate the behavior and verify the root cause. The results align with the observations described in the issue: 1. **Key Issue**: - The `getChannelsForSchema` method in `@langchain-ai/langgraphjs` creates **new instances** of channels (like `BinaryOperatorAggregate` or `LastValue`) every time a schema is processed. - As a result, schemas with the same reducer channel (like `files`) fail an identity check (`!==`) even though their definitions are functionally identical. - This causes the `StateGraph._addSchema` method to throw the error: ``` Error: Channel "files" already exists with a different type. ``` 2. **Detailed Test Cases**: - The attached Jest file validates the following: - `getChannelsForSchema` creates distinct instances for each schema processed (`Test 1` and `Test 2`). - This results in a failure when state, input, and output schemas share the same channel (`Test 2`). - The workaround of using the same schema object for all three (state/input/output) prevents the error, as deduplication implicitly occurs when `getChannelsForSchema` is only called once (`Test 3`). - This issue doesn’t affect `LastValue` channels, which are explicitly allowed to have duplicates (`Test 4`). #### Reproducing the Issue I’ve attached the Jest test file as a concrete reproduction case. [langgraph-channel-bug.test.ts](https://github.com/user-attachments/files/24372840/langgraph-channel-bug.test.ts) You can run the tests directly using Jest to verify the findings. It seems using middleware based on `withLangGraph` exacerbates the problem since middleware naturally generates schemas independently for agents, leading to repeated calls to `getChannelsForSchema`.
Author
Owner

@killagu commented on GitHub (Jan 4, 2026):

=== causes BinaryOperatorAggregate instances with the same operator to be treated as different objects.

Referencing the Python implementation here:
https://github.com/langchain-ai/langgraph/blob/main/libs/langgraph/langgraph/channels/binop.py#L72

the JavaScript version should also implement an equals method.

I will try to implement a PR following this approach.

@killagu commented on GitHub (Jan 4, 2026): `===` causes BinaryOperatorAggregate instances with the same operator to be treated as different objects. Referencing the Python implementation here: https://github.com/langchain-ai/langgraph/blob/main/libs/langgraph/langgraph/channels/binop.py#L72 the JavaScript version should also implement an equals method. I will try to implement a PR following this approach.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#387