Skip to content

Think on the harness: messengers through Think's Chat SDK Chat (C4, part 2) - #3360

Merged
mattzcarey merged 3 commits into
mainfrom
slim/deliveries-channels-c4-chat
Nov 27, 2026
Merged

mattzcarey merged 3 commits into
mainfrom
slim/deliveries-channels-c4-chat

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

The harness-backed Think's messengers take their webhooks through Think's own Chat SDK Chat, so they answer what Think answers. That covers respondTo, mentions found in a burst, subscriptions, bursts joined into one prompt with speaker labels, messengerConcurrency, and the thread lock held through the turn. Each event the Chat routes joins the harness's default session through Channels.forHarness, and the reply is still sent by the messenger's Chat SDK Channel as a delivery run.

Follows #3347 (C4, part 1); this is part 2:

  • Think's Chat construction and its handlers move out of ThinkMessengerRuntime into createMessengerChat(), which both classes call. Nothing is copied, and the released class behaves as before.
  • The Chat keeps its state on Think's ThinkMessengerStateAgent sub-agents, so the release's chat_sdk_state_* rows (subscriptions, locks, queued messages) are read as they are. CHANNELS.md's storage rule asks for that.
  • Each answered event keeps part 1's rules: the reply goes only to the asking thread (asker), and the handler returns once Channels settled the turn and the deliveries' first attempts ended.
  • The ChannelGateway from part 1 is gone from this path. The gateway hands each message to its own turn, which would split a burst and drop the thread lock that Think holds through a turn. Think's dedupe key (idempotencyKeyForEvent) is the operation id.
  • chatSdkChannel({ initialize }) (internal) is for an adapter a Chat already owns. The Channel sends through the Chat's initialization and takes no webhooks of its own.
  • messengerConcurrency is a field on the harness-backed class, read when the first webhook arrives.

Validation:

  • messengers.test.ts on the harness-backed Think goes from 86 of 115 to 94 of 116 (441 of 1313 in total, 0 class-only) (pnpm test:harness). The bursts, the queue strategy, mixed senders, subscribed and unsubscribed threads, the skipped mention and the lock TTL tests now pass, plus a new case: a group speaker gets the messenger's channelSpeakerLabel, on both classes. The 22 left are recovery, the queue drains behind a reply and the reply texts (later parts).
  • messengers.test.ts and telegram-messenger.test.ts on Think pass, as do the channels unit tests, plus a new case for initialize. The Telegram replay (messenger-replay.test.ts, 3 cases including a reset mid-answer) passes on both classes.

Cost: no released class changes. Per answered message the harness-backed class now does what Think does in Chat SDK state: the thread lock and the dedupe key, on the state sub-agent. Channels adds its surface KV row, its response stream and one delivery run per surface, deleted once delivered.

Probe (reviewer): the same as #3347, on slim-rv-2-… with this head. Also send a burst of three updates to one private chat in one webhook: one turn, one sent message, and a prompt with the three lines in order. Then send a group update that mentions the bot followed by an unmentioned one in the same webhook: answered once, and the thread is subscribed.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6291305

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 6291305

@agent-think

agent-think Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (1900d09b → 62913059, workflow run)

@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4-chat branch from 6e5cd08 to 3868cb7 Compare November 27, 2026 03:48
@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4 branch from 6f2ad82 to 1eaf3f1 Compare November 27, 2026 04:55
@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4-chat branch from 3868cb7 to c94262d Compare November 27, 2026 04:59
@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4 branch from 573e0d2 to 993bdef Compare November 27, 2026 05:57
Base automatically changed from slim/deliveries-channels-c4 to main November 27, 2026 06:24
@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4-chat branch from 98442b4 to 5769996 Compare November 27, 2026 06:31
@mattzcarey
mattzcarey force-pushed the slim/deliveries-channels-c4-chat branch from 5769996 to ff8e8ce Compare November 27, 2026 06:35
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 06:44
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey merged commit 8795607 into main Nov 27, 2026
35 of 37 checks passed
@mattzcarey
mattzcarey deleted the slim/deliveries-channels-c4-chat branch November 27, 2026 07:15
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