Skip to content

ConcurrencyConfig.maxConcurrent has no effect #417

@patrick-chinchill

Description

@patrick-chinchill

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

  1. Create a Chat with concurrency: { strategy: "concurrent", maxConcurrent: 2 } and a slow onMessage handler (e.g. 500ms sleep).
  2. Drive 10 messages at the same thread concurrently via chat.processMessage(...).
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions