chat: share submit concurrency controller in agents/chat#1395
Merged
Conversation
Extract the latest/merge/drop/debounce admission state machine into a SubmitConcurrencyController exported from agents/chat. AIChatAgent semantics (including the merge persistence rewrite) are preserved. Think now uses the same controller, so an overlapping submit is still detected while an accepted request is between admission and turn queue registration. Additional fixes: - Think now captures the turn generation immediately after admission and threads it into _turnQueue.enqueue, so a clear that lands between admission and queue registration cannot run a stale turn. - Pending-enqueue tracking is bound to a release function tied to the controller's reset epoch, so a release from a pre-reset submit can no longer erase a post-reset submit's marker and let a third submit slip through as non-overlapping. - Debounce cancellation correctly resolves all in-flight waiters instead of overwriting a single timer slot. - Replace the brittle 40 ms sleep in the AIChatAgent drop tests with an "active turn" barrier so the second submit is provably overlapping before assertion. Made-with: Cursor
🦋 Changeset detectedLatest commit: aed549e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Merged
threepointone
added a commit
that referenced
this pull request
Apr 26, 2026
Add a new section summarizing four post-#1384 maintenance PRs (#1393–#1396) and their effects on the multi-session assistant plan. Notes include facet bootstrap via explicit FacetStartupOptions.id (#1393) which removes the storage write/setName shim and makes MyAssistant.name resolve natively; the new beforeStep hook and TurnConfig.output passthrough (#1394); SubmitConcurrencyController being moved into agents/chat (#1395); and message-reconciler moved into agents/chat with Think now reconciling incoming messages (#1396). Clarifies that the chat-shared-layer has been incrementally hoisted into agents/chat and highlights the lack of a vitest+workers harness for examples/assistant, recommending a minimal test harness before hoisting useAgentChat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SubmitConcurrencyControllerexported fromagents/chat.AIChatAgentsemantics (including the merge persistence rewrite) are preserved.Thinknow uses the same controller, so an overlapping submit is still detected while an accepted request is between admission and turn queue registration.Thinkclear/epoch race: capture the turn generation immediately after admission and thread it into_turnQueue.enqueue, so a clear landing between admission and queue registration cannot run a stale turn.AIChatAgentdrop tests with an "active turn" barrier so the second submit is provably overlapping before assertion. Adds equivalent barriers to theThinkconcurrency tests.Test plan
npx vitest --run -c src/chat/__tests__/vitest.config.ts src/chat/__tests__/submit-concurrency.test.ts(new unit tests for controller — pending-enqueue, supersession, post-reset isolation, idempotent release, debounce cancellation)npx vitest --project workers --run src/tests/message-concurrency.test.ts --sequence.shuffle falseinpackages/ai-chatnpx vitest --run -c src/tests/vitest.config.ts src/tests/client-tools.test.ts -t "Think — messageConcurrency" --sequence.shuffle falseinpackages/thinknpm run typecheckReadLintsclean on touched filesMade with Cursor