Skip to content

feat(chat): add burst concurrency strategy (vercel/chat#495)#114

Merged
patrick-chinchill merged 2 commits into
mainfrom
claude/port-queue-debounce-concurrency
May 29, 2026
Merged

feat(chat): add burst concurrency strategy (vercel/chat#495)#114
patrick-chinchill merged 2 commits into
mainfrom
claude/port-queue-debounce-concurrency

Conversation

@patrick-chinchill
Copy link
Copy Markdown
Collaborator

Ports the new burst concurrency strategy from upstream commit b75eedb (vercel/chat#495). Part of the 0.4.29 sync wave (tracking #98, alpha #108).

Summary

  • burst is a hybrid of debounce and queue:
    • Idle thread: the first message waits debounce_ms before dispatching. Messages arriving during the window are queued; when the window elapses, the handler is invoked once with the latest message and the earlier burst messages exposed via context.skipped.
    • Busy thread: messages arriving while a handler is running drain identically to queue -- the latest dispatched, the rest in context.skipped.
  • Honors max_queue_size + on_queue_full (queue semantics) and debounce_ms (debounce semantics).
  • Existing drop / queue / debounce / concurrent behavior is unchanged.

Distinct semantics

Strategy Idle burst of 3 rapid messages
queue Handler called 2x: msg1 immediately, then drain of msg3 with [msg2] skipped
debounce Handler called 1x with msg3, earlier messages silently dropped (no context)
burst Handler called 1x with msg3, [msg1, msg2] in context.skipped

Files changed

  • src/chat_sdk/types.py -- extend ConcurrencyStrategy literal, update docstrings
  • src/chat_sdk/chat.py -- add burst branch in dispatch + _handle_queue_or_debounce
  • tests/test_chat_faithful.py -- new TestConcurrencyBurst class (6 tests)
  • docs/UPSTREAM_SYNC.md -- update strategy list reference

Test plan

  • uv run ruff check src/ tests/ scripts/ -- clean
  • uv run ruff format --check src/ tests/ scripts/ -- 197 files formatted
  • uv run python scripts/audit_test_quality.py -- no new warnings
  • uv run pytest tests/ --tb=short -q -- 4042 passed, 3 skipped
  • All 6 burst tests pass (TestConcurrencyBurst)

Refs: #98, #108
Upstream: vercel/chat#495 (b75eedb)

https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj

Port the new `burst` concurrency strategy from upstream commit b75eedb
(0.4.29 sync wave). `burst` is a hybrid of `debounce` and `queue`:

- On an idle thread the first message waits `debounce_ms` instead of
  dispatching immediately. Messages that arrive during the window are
  queued, and when the window elapses the handler is invoked once with
  the latest message; the earlier burst messages are exposed via
  `context.skipped`.
- After the handler finishes, any messages that arrived while it was
  running drain identically to `queue` -- the latest is dispatched with
  the rest in `context.skipped`.

This is distinct from `debounce` (which silently drops earlier messages
in the burst with no context) and from `queue` (which dispatches the
first message immediately without coalescing).

Honors `max_queue_size` + `on_queue_full` (queue semantics) and
`debounce_ms` (debounce semantics). Existing strategies are unchanged.

Implementation notes:
- `ConcurrencyStrategy` literal extended to include `"burst"`.
- `Chat.handle_incoming_message` dispatches `burst` through the existing
  `_handle_queue_or_debounce` path.
- New branch in `_handle_queue_or_debounce`: enqueue self with
  `max_queue_size`, sleep `debounce_ms`, extend lock, then `_drain_queue`.
- Lock-busy fall-through reuses the queue path -- `effective_max =
  max_queue_size` and `on_queue_full` is honored (previously gated by
  `strategy != "debounce"`, which already lets burst through).

Tests: 6 new tests in `TestConcurrencyBurst` (`tests/test_chat_faithful.py`)
mirror the 5 upstream tests in `chat.test.ts` plus 2 tests that pin the
distinct semantics vs `queue` and vs `debounce`.

Refs: #98, #108
Upstream: vercel/chat#495 (b75eedb)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@patrick-chinchill, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 30 minutes and 15 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca299fd7-5bd7-4f18-9c20-896009c17352

📥 Commits

Reviewing files that changed from the base of the PR and between a0d8816 and ebcb877.

📒 Files selected for processing (4)
  • docs/UPSTREAM_SYNC.md
  • src/chat_sdk/chat.py
  • src/chat_sdk/types.py
  • tests/test_chat_faithful.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the 'burst' concurrency strategy in the Python Chat SDK, matching the TypeScript SDK's behavior. The 'burst' strategy waits for a debounce window before invoking the handler, allowing messages that arrive during this window to coalesce into a single dispatch where earlier messages are stored in the skipped context. The changes update the documentation, types, configuration classes, and core message handling logic, and introduce a comprehensive suite of tests to validate the new strategy's behavior. There are no review comments, so we have no feedback to provide.

# No handler call yet -- still inside the burst window
assert received_messages == []

await task
)

release_second_handler.set()
await first_task

assert await state.queue_depth("slack:C123:1234.5678") == 2

await first_task
create_test_message("burst-vs-queue-3", "Hey @slack-bot c"),
)

await task
create_test_message("burst-vs-deb-2", "Hey @slack-bot b"),
)

await task
@patrick-chinchill patrick-chinchill marked this pull request as ready for review May 29, 2026 00:42
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebcb877f57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/chat_sdk/chat.py
{"thread_id": thread_id, "lock_key": lock_key},
)
return
await self._drain_queue(lock, adapter, thread_id, lock_key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve mention routing for collapsed burst turns

When an idle burst starts with an @-mention but the latest message in the burst does not repeat the mention, this call drains only the latest message into _dispatch_to_handlers. Mention detection then runs on that latest message alone, so an unsubscribed thread never reaches on_mention and the whole turn is silently dropped (e.g. "Hey @slack-bot" followed within debounce_ms by "what time is it?"). Burst needs to carry the mention/routing signal from skipped messages or otherwise dispatch the collapsed turn as a mention.

Useful? React with 👍 / 👎.

@patrick-chinchill patrick-chinchill merged commit d87e3b1 into main May 29, 2026
8 checks passed
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