Bug Description
The maxConcurrent field on ConcurrencyConfig is documented as "Max concurrent handlers per thread (concurrent strategy). Default: Infinity." but nothing in the "concurrent" strategy path actually reads it. Setting it to a number has no effect.
Probably worth rejecting maxConcurrent paired with a non-"concurrent" strategy at construction too, since it's currently silently ignored for those.
I ran into this while porting to Python at chinchill-ai/chat-sdk-python (synced to 4.26.0). The Python fix uses asyncio.Semaphore: Chinchill-AI/chat-sdk-python#60.
Steps to Reproduce
- Create a Chat with
concurrency: { strategy: "concurrent", maxConcurrent: 2 } and a slow onMessage handler (e.g. 500ms sleep).
- Drive 10 messages at the same thread concurrently via
chat.processMessage(...).
- Count handler invocations in flight.
or with grep, you can see nothing checks the value:
$ grep -rn maxConcurrent packages/chat/src --include='*.ts' | grep -v .test.ts
packages/chat/src/chat.ts:260: maxConcurrent: Number.POSITIVE_INFINITY,
packages/chat/src/chat.ts:269: maxConcurrent: concurrency.maxConcurrent ?? Number.POSITIVE_INFINITY,
packages/chat/src/chat.ts:279: maxConcurrent: Number.POSITIVE_INFINITY,
packages/chat/src/types.ts:694: maxConcurrent?: number;
Expected Behavior
At most maxConcurrent handlers per thread in flight at once, matching the docstring. With maxConcurrent: 2 and 10 concurrent messages, peak in-flight should be 2.
Actual Behavior
All 10 handlers dispatch immediately. handleConcurrent at chat.ts:2013 calls dispatchToHandlers with no bounding:
private async handleConcurrent(adapter, threadId, message): Promise<void> {
await this.dispatchToHandlers(adapter, threadId, message);
}
Code Sample
Chat SDK Version
4.26.0
Node.js Version
No response
Platform Adapter
No response
Operating System
None
Additional Context
No response
Bug Description
The
maxConcurrentfield onConcurrencyConfigis documented as"Max concurrent handlers per thread (concurrent strategy). Default: Infinity."but nothing in the"concurrent"strategy path actually reads it. Setting it to a number has no effect.Probably worth rejecting
maxConcurrentpaired with a non-"concurrent"strategy at construction too, since it's currently silently ignored for those.I ran into this while porting to Python at chinchill-ai/chat-sdk-python (synced to 4.26.0). The Python fix uses
asyncio.Semaphore: Chinchill-AI/chat-sdk-python#60.Steps to Reproduce
concurrency: { strategy: "concurrent", maxConcurrent: 2 }and a slow onMessage handler (e.g. 500ms sleep).chat.processMessage(...).or with grep, you can see nothing checks the value:
Expected Behavior
At most
maxConcurrenthandlers per thread in flight at once, matching the docstring. WithmaxConcurrent: 2and 10 concurrent messages, peak in-flight should be 2.Actual Behavior
All 10 handlers dispatch immediately. handleConcurrent at chat.ts:2013 calls dispatchToHandlers with no bounding:
Code Sample
Chat SDK Version
4.26.0
Node.js Version
No response
Platform Adapter
No response
Operating System
None
Additional Context
No response