ResultChunkAssembler holds chunk state in a plain mutableMapOf() at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:13 and exposes accept as a non-suspend function at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:16. The class KDoc at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:9 does not mention thread safety, and the README example at README.md:171 constructs one assembler and calls accept from a flow collect { … } block where it is easy to imagine sharing the instance across coroutines. Two coroutines calling accept for the same resultId concurrently can corrupt the buffers map.
Fix prompt: Add a one-line KDoc stating "Not thread-safe — use one assembler per result stream and call accept from a single coroutine." Optionally back the map with a Mutex and make accept suspend if the use case actually warrants concurrent assembly. Add a small unit test asserting the single-coroutine contract — or, if the synchronized version is implemented, a stress test that hammers accept from multiple coroutines and verifies the assembled output.
ResultChunkAssemblerholds chunk state in a plainmutableMapOf()atlib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:13and exposesacceptas a non-suspend function atlib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:16. The class KDoc atlib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:9does not mention thread safety, and the README example atREADME.md:171constructs one assembler and callsacceptfrom a flowcollect { … }block where it is easy to imagine sharing the instance across coroutines. Two coroutines callingacceptfor the sameresultIdconcurrently can corrupt thebuffersmap.Fix prompt: Add a one-line KDoc stating "Not thread-safe — use one assembler per result stream and call
acceptfrom a single coroutine." Optionally back the map with aMutexand makeacceptsuspend if the use case actually warrants concurrent assembly. Add a small unit test asserting the single-coroutine contract — or, if the synchronized version is implemented, a stress test that hammersacceptfrom multiple coroutines and verifies the assembled output.