Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-5730 feat(server): expose chat audience without bloating prompts (#6428)
Multica Eve86f255658fcc
diff --git a/server/internal/daemon/execenv/channel_type.go b/server/internal/daemon/execenv/channel_type.goindex 2f07b8cc52..44833cf4b0 100644--- a/server/internal/daemon/execenv/channel_type.go+++ b/server/internal/daemon/execenv/channel_type.go@@ -10,12 +10,59 @@ package execenv// integration packages (integrations/slack, integrations/lark) into its own// build just to read one discriminator. The canonical definitions live with// their adapters — slack.TypeSlack and channel.TypeFeishu — and both sides-// agree on the wire strings below.+// agree on the wire strings below. WeCom keeps its reserved wire discriminator+// here until its adapter lands.const (ChannelTypeSlack = "slack"ChannelTypeFeishu = "feishu"+ ChannelTypeWecom = "wecom")+// Room-shape discriminators, mirroring channel_chat_session_binding.chat_type+// (channel.ChatTypeP2P / channel.ChatTypeGroup). Every adapter persists this+// column, so the shape of a conversation is known off one read whatever the+// platform. Empty means the server did not report one — a web chat, which has+// no binding row, or a server predating the field.+const (+ ChatTypeP2P = "p2p"+ ChatTypeGroup = "group"+)++// ChatAudience is what a run is allowed to say about who can read its replies.+// Three states, because "unknown" is not "private": a web chat carries no+// binding row at all and is 1:1 by construction, but an IM channel whose shape+// the server did not report could be a room of any size, and the one thing the+// copy must not then do is promise a privacy the conversation may not have.+//+// The per-turn chat prompt names the audience once. Keeping classification in+// one function prevents group, direct, and compatibility paths from drifting.+type ChatAudience int++const (+ // ChatAudienceUnknown is deliberately the zero value: uninitialized room+ // context must never turn into a privacy claim.+ ChatAudienceUnknown ChatAudience = iota+ // ChatAudienceDirect — an explicit p2p binding, or the no-channel shape used+ // by web chat. The claim protocol cannot distinguish a deleted binding here.+ ChatAudienceDirect+ // ChatAudienceGroup — a room shared by people the run has not been shown.+ ChatAudienceGroup+)++// AudienceOf classifies a claim's (chat_channel_type, chat_type) pair.+func AudienceOf(channelType, chatType string) ChatAudience {+ switch {+ case chatType == ChatTypeGroup:+ return ChatAudienceGroup+ case chatType == ChatTypeP2P:+ return ChatAudienceDirect+ case channelType == "":+ return ChatAudienceDirect+ default:+ return ChatAudienceUnknown+ }+}+// ChannelDisplayName renders a chat_channel_type for prompt / brief copy.// Unknown types fall through to the raw discriminator rather than a generic// placeholder, so a channel added server-side without a mapping here still@@ -26,6 +73,8 @@ func ChannelDisplayName(channelType string) string {return "Slack"case ChannelTypeFeishu:return "Feishu/Lark"+ case ChannelTypeWecom:+ return "WeCom"default:return channelType}diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex e0086f159f..4fa2fe28a6 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -126,12 +126,12 @@ type TaskContextForEnv struct {ProjectResources []ProjectResourceForEnv // resources attached to the projectChatSessionID string // non-empty for chat tasks// ChatChannelType is the IM platform behind a chat session ("slack",- // "feishu"); empty for a web/mobile chat. The brief reads it for DELIVERY- // policy only: any non-empty value means the reply leaves Multica for an- // external channel, so `multica attachment upload` cannot deliver a file and- // the Output section says text-only instead (MUL-4899). The orthogonal- // history-command policy is Slack-only and lives in the per-turn chat prompt- // (daemon/prompt.go) — the server has no Feishu history reader.+ // "feishu", "wecom"); empty for a web/mobile chat. Any non-empty value+ // means the reply leaves Multica for an external channel, so `multica+ // attachment upload` cannot deliver a file and the Output section says+ // text-only instead (MUL-4899). The orthogonal audience and history policies+ // live in the per-turn chat prompt (daemon/prompt.go) — the server has no+ // history reader for any other channel.ChatChannelType stringAutopilotRunID string // non-empty for autopilot run_only tasksAutopilotID stringdiff --git a/server/internal/daemon/execenv/runtime_config_channel_context_test.go b/server/internal/daemon/execenv/runtime_config_channel_context_test.gonew file mode 100644index 0000000000..24028f16b4--- /dev/null+++ b/server/internal/daemon/execenv/runtime_config_channel_context_test.go@@ -0,0 +1,77 @@+package execenv++import (+ "reflect"+ "strings"+ "testing"+)++// Room audience belongs to the per-turn message, not the cached brief. The+// original implementation added a long `## Conversation Channel` section and+// pinned its full prose, including pointers to conditionally rendered+// `## Task Initiator` / `## Requesting User` sections. Those pins were retired+// because they duplicated platform context and made dangling pointers pass.+// The semantic audience boundaries are pinned in daemon/prompt_test.go instead.+func TestBriefChatWorkflowDoesNotAssertAudience(t *testing.T) {+ t.Parallel()++ out := buildMetaSkillContent("claude", TaskContextForEnv{+ ChatSessionID: "8d154f4b-8a7d-4f10-99ef-c1a16e2e7868",+ ChatChannelType: ChannelTypeSlack,+ AgentID: "9df55bf2-67de-4ae6-803f-4de2fbd45df1",+ AgentName: "Eve",+ })+ if !strings.Contains(out, "**You are in chat mode.**") {+ t.Fatal("chat brief must still identify chat mode")+ }+ for _, retired := range []string{+ "## Conversation Channel",+ "Audience:",+ "messaging you directly",+ "group room",+ "direct room",+ } {+ if strings.Contains(out, retired) {+ t.Errorf("cached brief must not contain per-session audience text %q", retired)+ }+ }+}++// This structural guard prevents a future caller from quietly threading the+// room discriminator back into the cached brief. ChatType remains on daemon.Task+// for BuildPrompt, but the execenv context cannot consume it.+func TestBriefContextExcludesChatType(t *testing.T) {+ t.Parallel()++ if _, ok := reflect.TypeOf(TaskContextForEnv{}).FieldByName("ChatType"); ok {+ t.Fatal("TaskContextForEnv must not carry ChatType; audience is per-turn context")+ }+}++func TestAudienceOf(t *testing.T) {+ t.Parallel()++ if got := ChatAudience(0); got != ChatAudienceUnknown {+ t.Fatalf("zero-value audience = %v, want unknown", got)+ }++ cases := []struct {+ name string+ channelType string+ chatType string+ want ChatAudience+ }{+ {name: "group binding", channelType: ChannelTypeSlack, chatType: ChatTypeGroup, want: ChatAudienceGroup},+ {name: "direct binding", channelType: ChannelTypeFeishu, chatType: ChatTypeP2P, want: ChatAudienceDirect},+ {name: "web chat", want: ChatAudienceDirect},+ {name: "old server", channelType: ChannelTypeSlack, want: ChatAudienceUnknown},+ {name: "future discriminator", channelType: ChannelTypeSlack, chatType: "broadcast", want: ChatAudienceUnknown},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := AudienceOf(tc.channelType, tc.chatType); got != tc.want {+ t.Errorf("AudienceOf(%q, %q) = %v, want %v", tc.channelType, tc.chatType, got, tc.want)+ }+ })+ }+}diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex c3b6a080d2..8456f2a8ee 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -408,8 +408,12 @@ func writeWorkflowHeader(b *strings.Builder) {// post-completion suggestion pass (chat_suggest.go), because an optional// formatting instruction in this brief proved unreliable across providers and// long conversations.+//+// Room shape is run context rather than an agent/provider invariant, so it is+// emitted by daemon.BuildPrompt instead of fragmenting this cached brief across+// group, direct, and unknown-audience chat sessions (MUL-5377, MUL-5442).func writeWorkflowChat(b *strings.Builder) {- b.WriteString("**You are in chat mode.** A user is messaging you directly in a chat window.\n\n")+ b.WriteString("**You are in chat mode.**\n\n")b.WriteString("- Respond conversationally and helpfully to the user's message\n")b.WriteString("- You have full access to the `multica` CLI to look up issues, workspace info, members, agents, etc.\n")b.WriteString("- If asked about issues, use `multica issue list --output json` or `multica issue get <id> --output json`\n")diff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.goindex 2bc41fba1c..3da82ca770 100644--- a/server/internal/daemon/prompt.go+++ b/server/internal/daemon/prompt.go@@ -422,7 +422,18 @@ func buildChatPrompt(task Task) string {var b strings.Builderb.WriteString("You are running as a chat assistant for a Multica workspace.\n")- b.WriteString("A user is chatting with you directly. Respond to their message.\n\n")+ // Audience is per-session context, so keep it out of the cached runtime+ // brief. The compact anchors here preserve the non-inferable boundaries: a+ // group reply is not private to its sender and people not otherwise present+ // in the run context may read it. Unknown never defaults to private.+ switch execenv.AudienceOf(task.ChatChannelType, task.ChatType) {+ case execenv.ChatAudienceGroup:+ b.WriteString("Audience: group room; not private; unseen members may read replies.\n\n")+ case execenv.ChatAudienceUnknown:+ b.WriteString("Audience: unknown.\n\n")+ default:+ b.WriteString("Audience: direct room.\n\n")+ }// Channel awareness (MUL-3871). When the session is backed by an IM channel,// the agent must KNOW it is operating inside that channel — otherwise an ask// like "what did you just talk about" sends it to read Multica instead of thediff --git a/server/internal/daemon/prompt_test.go b/server/internal/daemon/prompt_test.goindex 70a3601443..beafac38ae 100644--- a/server/internal/daemon/prompt_test.go+++ b/server/internal/daemon/prompt_test.go@@ -489,6 +489,67 @@ func TestBuildChatPromptFeishuIgnoresChatInThread(t *testing.T) {}}+// Audience is a per-turn platform fact. Semantic anchors pin the group privacy+// boundary without pinning a full sentence, and the count guard prevents a+// second copy from creeping into another prompt section.+func TestBuildChatPromptAudience(t *testing.T) {+ cases := []struct {+ name string+ task Task+ want []string+ deny []string+ }{+ {+ name: "group",+ task: Task{ChatSessionID: "s", ChatChannelType: execenv.ChannelTypeSlack, ChatType: execenv.ChatTypeGroup, ChatMessage: "hi"},+ want: []string{"Audience: group room", "not private", "unseen members"},+ deny: []string{"Audience: direct", "do not share", "never mention", "avoid discussing"},+ },+ {+ name: "direct channel",+ task: Task{ChatSessionID: "s", ChatChannelType: execenv.ChannelTypeFeishu, ChatType: execenv.ChatTypeP2P, ChatMessage: "hi"},+ want: []string{"Audience: direct room"},+ deny: []string{"Audience: group", "not private", "unseen members"},+ },+ {+ name: "direct web chat",+ task: Task{ChatSessionID: "s", ChatMessage: "hi"},+ want: []string{"Audience: direct room"},+ deny: []string{"Audience: group", "Audience: unknown"},+ },+ {+ name: "channel from an older server",+ task: Task{ChatSessionID: "s", ChatChannelType: execenv.ChannelTypeWecom, ChatMessage: "hi"},+ want: []string{"Audience: unknown"},+ deny: []string{"Audience: group", "Audience: direct", "not private"},+ },+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ out := BuildPrompt(tc.task, "claude")+ if got := strings.Count(out, "Audience:"); got != 1 {+ t.Fatalf("audience fact count = %d, want 1\n--- output ---\n%s", got, out)+ }+ for _, want := range tc.want {+ if !strings.Contains(out, want) {+ t.Errorf("prompt missing audience anchor %q\n--- output ---\n%s", want, out)+ }+ }+ deny := append([]string{}, tc.deny...)+ deny = append(deny, "chatting with you directly")+ for _, deny := range deny {+ if strings.Contains(out, deny) {+ t.Errorf("prompt contains retired/contradictory audience text %q\n--- output ---\n%s", deny, out)+ }+ }+ if !strings.Contains(out, "User message:\nhi") {+ t.Errorf("prompt must still carry the user message\n--- output ---\n%s", out)+ }+ })+ }+}+func TestBuildChatPromptAgentIntro(t *testing.T) {// The proactive self-introduction chat (MUL-4230) has no user message: the// prompt must tell the agent to open the conversation itself, and must NOTdiff --git a/server/internal/daemon/types.go b/server/internal/daemon/types.goindex cea701b7fb..f1b159bb2b 100644--- a/server/internal/daemon/types.go+++ b/server/internal/daemon/types.go@@ -90,6 +90,7 @@ type Task struct {NewCommentsSince string `json:"new_comments_since,omitempty"` // RFC3339 anchor (last run's started_at) the count is measured from; empty on cold startChatSessionID string `json:"chat_session_id,omitempty"` // non-empty for chat tasksChatChannelType string `json:"chat_channel_type,omitempty"` // "slack" when the chat session is backed by an IM channel; empty for a web-only chat. Drives the channel-awareness block in the prompt+ ChatType string `json:"chat_type,omitempty"` // "group" when the channel conversation is a shared room, "p2p" for a 1:1 with the bot. Empty for a web chat or an old server; the per-turn prompt then reports unknown rather than guessing 1:1ChatInThread bool `json:"chat_in_thread,omitempty"` // true when the latest @mention was a thread reply; selects which read command the prompt tells the agent to start withChatMessage string `json:"chat_message,omitempty"` // user message content for chat tasksChatMessageAttachments []ChatAttachmentMeta `json:"chat_message_attachments,omitempty"` // attachments linked to the chat message; agent uses these to `multica attachment download <id>`diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.goindex c191c27af1..ee2541a649 100644--- a/server/internal/handler/agent.go+++ b/server/internal/handler/agent.go@@ -346,6 +346,7 @@ type AgentTaskResponse struct {NewCommentsSince string `json:"new_comments_since,omitempty"` // RFC3339 anchor (last run's started_at) the count is measured from; omitempty so old daemons ignore itChatSessionID string `json:"chat_session_id,omitempty"` // non-empty for chat tasksChatChannelType string `json:"chat_channel_type,omitempty"` // "slack" when the chat session is backed by an IM channel; empty for a web-only chat. Makes the agent channel-aware (read history from the channel, not Multica)+ ChatType string `json:"chat_type,omitempty"` // channel_chat_session_binding.chat_type — "group" for a shared room, "p2p" for a 1:1 with the bot. Lets the per-turn prompt tell the agent who else can read its replies; empty for a web-only chatChatInThread bool `json:"chat_in_thread,omitempty"` // true when the latest @mention was a thread reply; tells the agent to start with `multica chat thread` vs `multica chat history`ChatMessage string `json:"chat_message,omitempty"` // user message for chat tasksChatMessageAttachments []ChatAttachmentMeta `json:"chat_message_attachments,omitempty"` // attachments on the user message — agent calls `multica attachment download <id>` per entrydiff --git a/server/internal/handler/daemon.go b/server/internal/handler/daemon.goindex 9e5c8874d6..84f4721395 100644--- a/server/internal/handler/daemon.go+++ b/server/internal/handler/daemon.go@@ -2138,8 +2138,17 @@ func (h *Handler) buildClaimedTaskResponse(r *http.Request, task *db.AgentTaskQu// endpoints are hardwired to h.SlackHistory (chat_history.go) — there// is no history reader on any other channel, so the flag has nothing// to select between there and must not imply one exists.+ //+ // chat_type rides along on the same row. It is what lets the+ // per-turn prompt tell the agent whether this chat_session is a room+ // shared by many people or a 1:1 with the bot; the prompt used to+ // describe every chat run as a private 1:1 whatever the room. The+ // shared session service writes the column for every channel+ // (channel/engine/session.go), so no channel needs naming here+ // either.if binding, berr := h.Queries.GetChannelChatSessionBindingBySessionAny(r.Context(), cs.ID); berr == nil {resp.ChatChannelType = binding.ChannelType+ resp.ChatType = binding.ChatTypeif binding.ChannelType == string(slack.TypeSlack) {// The latest trigger was a thread reply iff its reply-target// thread (last_thread_id) differs from its own message id (adiff --git a/server/internal/handler/daemon_claim_channel_type_test.go b/server/internal/handler/daemon_claim_channel_type_test.goindex fa1f041b31..cff97c5533 100644--- a/server/internal/handler/daemon_claim_channel_type_test.go+++ b/server/internal/handler/daemon_claim_channel_type_test.go@@ -23,12 +23,20 @@ import (// hardwired to h.SlackHistory (chat_history.go). There is no Feishu reader, so// the flag has nothing to select between and must not imply one exists.-// seedChannelBinding binds sessionID to an IM channel of channelType, creating-// the installation the binding requires. This is the row shape both the Slack-// binder (slack/binding.go) and the Feishu store (lark/channel_store.go) write —-// identical but for channel_type, which is exactly why the claim lookup must not-// hardcode one value.+// seedChannelBinding binds sessionID to a group room on an IM channel of+// channelType, creating the installation the binding requires. This is the row+// shape both the Slack binder (slack/binding.go) and the Feishu store+// (lark/channel_store.go) write — identical but for channel_type, which is+// exactly why the claim lookup must not hardcode one value.func seedChannelBinding(t *testing.T, ctx context.Context, agentID, sessionID, channelType, lastMessageID, lastThreadID string) {+ t.Helper()+ seedChannelBindingOfChatType(t, ctx, agentID, sessionID, channelType, "group", lastMessageID, lastThreadID)+}++// seedChannelBindingOfChatType is seedChannelBinding with the room shape+// (p2p / group) chosen by the caller — the column the claim must report so the+// per-turn prompt can tell the agent whether anyone else is reading.+func seedChannelBindingOfChatType(t *testing.T, ctx context.Context, agentID, sessionID, channelType, chatType, lastMessageID, lastThreadID string) {t.Helper()var installationID stringif err := testPool.QueryRow(ctx, `@@ -41,8 +49,8 @@ func seedChannelBinding(t *testing.T, ctx context.Context, agentID, sessionID, cif _, err := testPool.Exec(ctx, `INSERT INTO channel_chat_session_binding(chat_session_id, installation_id, channel_type, channel_chat_id, chat_type, last_message_id, last_thread_id)- VALUES ($1, $2, $3, $4, 'group', $5, $6)- `, sessionID, installationID, channelType, "C-TEST-"+channelType, lastMessageID, lastThreadID); err != nil {+ VALUES ($1, $2, $3, $4, $5, $6, $7)+ `, sessionID, installationID, channelType, "C-TEST-"+channelType, chatType, lastMessageID, lastThreadID); err != nil {t.Fatalf("seed %s binding: %v", channelType, err)}t.Cleanup(func() {@@ -51,9 +59,16 @@ func seedChannelBinding(t *testing.T, ctx context.Context, agentID, sessionID, c})}+// claimedChatChannel is the channel-awareness slice of a claim response.+type claimedChatChannel struct {+ ChannelType string `json:"chat_channel_type"`+ ChatType string `json:"chat_type"`+ InThread bool `json:"chat_in_thread"`+}+// claimChatChannelFields claims the queued task for runtimeID and returns the// channel-awareness fields the daemon reads off the claim response.-func claimChatChannelFields(t *testing.T, runtimeID string) (channelType string, inThread bool) {+func claimChatChannelFields(t *testing.T, runtimeID string) claimedChatChannel {t.Helper()w := httptest.NewRecorder()req := newDaemonTokenRequest("POST", "/api/daemon/runtimes/"+runtimeID+"/tasks/claim", nil,@@ -65,10 +80,7 @@ func claimChatChannelFields(t *testing.T, runtimeID string) (channelType string,t.Fatalf("ClaimTaskByRuntime: expected 200, got %d: %s", w.Code, w.Body.String())}var resp struct {- Task *struct {- ChatChannelType string `json:"chat_channel_type"`- ChatInThread bool `json:"chat_in_thread"`- } `json:"task"`+ Task *claimedChatChannel `json:"task"`}if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {t.Fatalf("decode claim response: %v", err)@@ -76,7 +88,7 @@ func claimChatChannelFields(t *testing.T, runtimeID string) (channelType string,if resp.Task == nil {t.Fatal("expected a claimed task")}- return resp.Task.ChatChannelType, resp.Task.ChatInThread+ return *resp.Task}func TestClaim_FeishuBoundSessionReportsChannelType(t *testing.T) {@@ -91,11 +103,11 @@ func TestClaim_FeishuBoundSessionReportsChannelType(t *testing.T) {insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)requeueTaskForClaim(t, ctx, sessionID)- channelType, inThread := claimChatChannelFields(t, runtimeID)- if channelType != "feishu" {- t.Errorf("chat_channel_type = %q, want %q — a Feishu session must not look like a web chat", channelType, "feishu")+ claimed := claimChatChannelFields(t, runtimeID)+ if claimed.ChannelType != "feishu" {+ t.Errorf("chat_channel_type = %q, want %q — a Feishu session must not look like a web chat", claimed.ChannelType, "feishu")}- if inThread {+ if claimed.InThread {t.Error("chat_in_thread must stay false on Feishu: it selects between two Slack-only read commands")}}@@ -110,11 +122,11 @@ func TestClaim_SlackBoundSessionStillReportsThreadState(t *testing.T) {insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)requeueTaskForClaim(t, ctx, sessionID)- channelType, inThread := claimChatChannelFields(t, runtimeID)- if channelType != "slack" {- t.Errorf("chat_channel_type = %q, want %q", channelType, "slack")+ claimed := claimChatChannelFields(t, runtimeID)+ if claimed.ChannelType != "slack" {+ t.Errorf("chat_channel_type = %q, want %q", claimed.ChannelType, "slack")}- if !inThread {+ if !claimed.InThread {t.Error("chat_in_thread should be true when last_thread_id differs from last_message_id")}}@@ -138,11 +150,11 @@ func TestClaim_UnlistedChannelBoundSessionReportsChannelType(t *testing.T) {insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)requeueTaskForClaim(t, ctx, sessionID)- channelType, inThread := claimChatChannelFields(t, runtimeID)- if channelType != "wecom" {- t.Errorf("chat_channel_type = %q, want %q — a channel the handler does not name must not look like a web chat", channelType, "wecom")+ claimed := claimChatChannelFields(t, runtimeID)+ if claimed.ChannelType != "wecom" {+ t.Errorf("chat_channel_type = %q, want %q — a channel the handler does not name must not look like a web chat", claimed.ChannelType, "wecom")}- if inThread {+ if claimed.InThread {t.Error("chat_in_thread must stay false off Slack: it selects between two Slack-only read commands")}}@@ -156,15 +168,74 @@ func TestClaim_UnboundSessionReportsNoChannelType(t *testing.T) {insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)requeueTaskForClaim(t, ctx, sessionID)- channelType, inThread := claimChatChannelFields(t, runtimeID)- if channelType != "" {- t.Errorf("chat_channel_type = %q, want empty for a web-only session", channelType)+ claimed := claimChatChannelFields(t, runtimeID)+ if claimed.ChannelType != "" {+ t.Errorf("chat_channel_type = %q, want empty for a web-only session", claimed.ChannelType)}- if inThread {+ if claimed.InThread {t.Error("chat_in_thread must be false for a web-only session")}}+// The room shape rides the same binding row as the channel type and must reach+// the daemon with it. Without it the per-turn prompt has no way to know that one+// chat_session is a room shared by many people, and it described every chat run+// as a private 1:1 — the agent then had no input from which to weigh a wider+// audience. Asserted per channel because the column is written by the shared+// session service for all of them (channel/engine/session.go).+func TestClaim_BoundSessionReportsRoomShape(t *testing.T) {+ if testHandler == nil {+ t.Skip("database not available")+ }+ ctx := context.Background()++ for _, tc := range []struct {+ channelType string+ chatType string+ }{+ {"slack", "group"},+ {"slack", "p2p"},+ {"feishu", "group"},+ {"feishu", "p2p"},+ {"wecom", "group"},+ {"wecom", "p2p"},+ } {+ name := tc.channelType + "/" + tc.chatType+ t.Run(name, func(t *testing.T) {+ agentID, sessionID, runtimeID, _ := setupDirectChatSession(t, ctx, name+" chat")+ seedChannelBindingOfChatType(t, ctx, agentID, sessionID, tc.channelType, tc.chatType, "msg-1", "msg-1")+ insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)+ requeueTaskForClaim(t, ctx, sessionID)++ claimed := claimChatChannelFields(t, runtimeID)+ if claimed.ChannelType != tc.channelType {+ t.Errorf("chat_channel_type = %q, want %q", claimed.ChannelType, tc.channelType)+ }+ if claimed.ChatType != tc.chatType {+ t.Errorf("chat_type = %q, want %q — the prompt cannot describe a room it is not told about", claimed.ChatType, tc.chatType)+ }+ })+ }+}++// A web chat has no binding row, so there is no room shape to report. It comes+// back empty rather than fabricating "p2p": AudienceOf pairs that empty shape+// with an empty channel to infer web direct, while an external channel whose+// shape is empty remains unknown.+func TestClaim_UnboundSessionReportsNoRoomShape(t *testing.T) {+ if testHandler == nil {+ t.Skip("database not available")+ }+ ctx := context.Background()+ agentID, sessionID, runtimeID, _ := setupDirectChatSession(t, ctx, "web chat shape")+ insertChannelChatTask(t, ctx, agentID, runtimeID, sessionID)+ requeueTaskForClaim(t, ctx, sessionID)++ if claimed := claimChatChannelFields(t, runtimeID); claimed.ChatType != "" {+ t.Errorf("chat_type = %q, want empty for a web-only session", claimed.ChatType)+ }+}+// requeueTaskForClaim puts the session's task back in the queue so the claim// endpoint can hand it out (insertChannelChatTask creates it already running).func requeueTaskForClaim(t *testing.T, ctx context.Context, sessionID string) {