Skip to content

fix: resolve activeInterruptEvent global state pollution across threads - #2026

Closed
the-waste-land wants to merge 1 commit into
CopilotKit:mainfrom
the-waste-land:fix/activeInterruptEvent-global-state-pollution
Closed

the-waste-land wants to merge 1 commit into
CopilotKit:mainfrom
the-waste-land:fix/activeInterruptEvent-global-state-pollution

Conversation

@the-waste-land

Copy link
Copy Markdown

What does this PR do?

This PR fixes a global state pollution issue in the LangGraph integration where the activeInterruptEvent variable was shared across all threads, causing concurrent requests from different browser tabs to interfere with each other.

Changes:

  • Convert global activeInterruptEvent to thread-specific state management using Map<threadId, boolean>
  • Prevent incorrect command.resume being added to unrelated thread requests
  • Maintain proper interrupt handling within the same thread while isolating different threads

Problem solved:

  • When one browser tab triggered a LangGraph interrupt but didn't respond, subsequent requests from other tabs would incorrectly include command.resume in the payload
  • This caused 'NoneType' object is not iterable errors on the LangGraph server side
  • Multiple concurrent sessions now work independently without state pollution

Related PRs and Issues

  • Fixes issue with concurrent browser sessions causing LangGraph errors due to global state pollution

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation

@changesets-bot-copilotkit

Copy link
Copy Markdown

⏭️ Changeset Not Required

Latest commit: 76ab2c0

No changes in this PR affected the @copilitkit/* packages. Merging this PR will not cause a version bump for any packages.

Changeset is not required for this PR.

@vercel

vercel Bot commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

@the-waste-land is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

@the-waste-land

Copy link
Copy Markdown
Author

Fix the issue: #1991

@ranst91

ranst91 commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Great contribution! Much appreciated!

@the-waste-land

the-waste-land commented Jun 20, 2025 •

Copy link
Copy Markdown
Author

Great contribution! Much appreciated!

I found there's still an issue when I have two Node.js instances running the CopilotKit runtime.
The CopilotKit runtime should be stateless.
Maybe we should let the browser carry the activeInterruptEvent state, or use Redis to store it.
What do you think?

@the-waste-land

Copy link
Copy Markdown
Author

Maybe we could get the activeInterruptEvent state from the LangGraph thread state.

@ranst91

ranst91 commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

@the-waste-land I wouldn't worry about this too much.
We are slowly moving towards AG-UI LangGraph agent. You can find the core implementation here:
https://github.com/ag-ui-protocol/ag-ui/blob/main/typescript-sdk/integrations/langgraph/src/index.ts

As you can see there, we are not saving the interrupt anywhere, but rather fetching it before calling the stream. This way we can say "hold on, can we even stream or are there any pending interrupt events".

This approach is not exclusive to AG-UI, so it can also be implemented here. It's indeed what you mentioned as "get the activeInterruptEvent state from the LangGraph thread state"

If you see issues with the approach you have implemented, I can look into syncing the two implementations and bringing this concept to "remote-lg-action"

@ranst91

ranst91 commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

#2031 I have created this which follows the AGUI implementation

@the-waste-land

Copy link
Copy Markdown
Author

@the-waste-land I wouldn't worry about this too much. We are slowly moving towards AG-UI LangGraph agent. You can find the core implementation here: https://github.com/ag-ui-protocol/ag-ui/blob/main/typescript-sdk/integrations/langgraph/src/index.ts

As you can see there, we are not saving the interrupt anywhere, but rather fetching it before calling the stream. This way we can say "hold on, can we even stream or are there any pending interrupt events".

This approach is not exclusive to AG-UI, so it can also be implemented here. It's indeed what you mentioned as "get the activeInterruptEvent state from the LangGraph thread state"

If you see issues with the approach you have implemented, I can look into syncing the two implementations and bringing this concept to "remote-lg-action"

Great! Looking forward to the new version.

@the-waste-land
the-waste-land deleted the fix/activeInterruptEvent-global-state-pollution branch June 21, 2025 04:22
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.

2 participants