Skip to content

chat: share submit concurrency controller in agents/chat#1395

Merged
threepointone merged 1 commit into
mainfrom
submit-concurrency-controller
Apr 26, 2026
Merged

chat: share submit concurrency controller in agents/chat#1395
threepointone merged 1 commit into
mainfrom
submit-concurrency-controller

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Apr 26, 2026

Summary

  • 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.
  • Fix a Think clear/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.
  • Bind pending-enqueue tracking 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.
  • Resolve all in-flight debounce waiters on cancel (the previous single-timer slot could be overwritten by an interleaving caller).
  • Replace the brittle 40ms sleep in the AIChatAgent drop tests with an "active turn" barrier so the second submit is provably overlapping before assertion. Adds equivalent barriers to the Think concurrency 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 false in packages/ai-chat
  • npx vitest --run -c src/tests/vitest.config.ts src/tests/client-tools.test.ts -t "Think — messageConcurrency" --sequence.shuffle false in packages/think
  • npm run typecheck
  • ReadLints clean on touched files

Made with Cursor


Open in Devin Review

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 26, 2026

🦋 Changeset detected

Latest commit: aed549e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch
@cloudflare/think Patch

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 26, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1395

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1395

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1395

hono-agents

npm i https://pkg.pr.new/hono-agents@1395

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1395

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1395

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1395

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1395

commit: aed549e

@threepointone threepointone merged commit 63cfae6 into main Apr 26, 2026
2 checks passed
@threepointone threepointone deleted the submit-concurrency-controller branch April 26, 2026 21:07
@github-actions github-actions Bot mentioned this pull request Apr 26, 2026
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.
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.

1 participant