LLMUnity icon indicating copy to clipboard operation
LLMUnity copied to clipboard

Invalid Operation Exception

Open Draco18s opened this issue 3 months ago • 0 comments

Describe the bug

I'm unsure why this occurs, as it is inconsistent (I suspect some threading bs).

My code is already structured to make no more than one request to an AI at once (as an external web service doesn't allow multiple requests at the same time) via IEnumerator yielding. But it seems like when the code moves from one "chat agent" to the next (a chat agent in this context being a bundle of context that are all distinct from each other and requests to the LLM are based on this context) the error occurs, but not all the time.

It seems related to how LLMUnity is dealing with StreamWrappers. Ah yes most likely it is. DestroyStreamWrapper is called from within an async method; LLM.cs:796.

InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <321eb2db7c6d43ea8fc39b54eaca3452>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <321eb2db7c6d43ea8fc39b54eaca3452>:0)
LLMUnity.LLM.Update () (at Assets/LLMUnity/Runtime/LLM.cs:613)

Steps to reproduce

?

LLMUnity version

2.5.2

Operating System

Windows

Draco18s avatar Sep 14 '25 19:09 Draco18s