`@chat-adapter/web` always names itself `web`, so two web adapters share thread IDs

Open
#1,179 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, backend

Research direction

Read packages/adapter-web/src/adapter.ts, especially the WebAdapter name and thread ID methods cited in the issue, then trace how Chat resolves adapter keys from thread ID prefixes. Check the adapter's existing tests for naming and thread ID behavior. Done when separate web adapters produce IDs that chat.thread() can resolve independently, including IDs returned by threadIdFor.

Written by the indexing model from the issue text.

Description

Bug Description

WebAdapter hard-codes name = "web" and the web: thread ID prefix. Chat resolves a thread by the part of its ID before the first colon and looks that up in the keys of adapters. So a web adapter registered under any key other than web gets thread IDs that chat.thread() can't resolve. Two web adapters, say a support chat and a sales chat, also get the same thread ID for the same user and conversation, so they share subscriptions, locks, and history.

threadIdFor doesn't help, because decodeThreadId throws for any prefix other than web:.

Steps to Reproduce
  1. Register two web adapters under the keys support and sales.
  2. Send the same conversation ID from the same user to each webhook.
  3. Look at thread.id in the handler, then call chat.thread(thread.id).
Expected Behavior

Each adapter has its own name and thread prefix, and chat.thread() resolves its thread IDs.

Actual Behavior

Both handlers see web:u1:c1. chat.thread("web:u1:c1") throws Adapter "web" not found for thread ID "web:u1:c1". With threadIdFor returning sales:u1:c1, decodeThreadId throws Invalid web thread id: sales:u1:c1.

Code Sample
import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";
import { createWebAdapter } from "@chat-adapter/web";

const getUser = () => ({ id: "u1" });
const support = createWebAdapter({ userName: "bot", getUser });
const sales = createWebAdapter({ userName: "bot", getUser });
const chat = new Chat({ userName: "bot", state: createMemoryState(), adapters: { support, sales } });
await chat.initialize();

chat.onDirectMessage(async (thread) => console.log(thread.id)); // "web:u1:c1" for both

for (const key of ["support", "sales"] as const) {
  const body = { id: "c1", messages: [{ id: `m-${key}`, role: "user", parts: [{ type: "text", text: "hi" }] }] };
  await chat.webhooks[key](new Request("https://app.example/api/chat", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }));
}

chat.thread("web:u1:c1"); // Adapter "web" not found for thread ID "web:u1:c1"
Chat SDK Version

4.45.0

Node.js Version

24.21.0

Platform Adapter

Other

Operating System

Linux

Additional Context

A name option on createWebAdapter, defaulting to "web", would fix it. The adapter would use it for name, the default threadIdFor, encodeThreadId, and decodeThreadId. We do this today by overriding name and wrapping both thread ID methods. I can open a PR if you want it.

Dominant language
TypeScript
Stars
2.5k
Forks
355
Avg merge
2d 15h
Merged PRs (30d)
42

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/chat

All issues in vercel/chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.