Skip to content

fix: skip discussion tool when already in a topic - #146

Merged
lishuceo merged 1 commit into
mainfrom
fix/skip-discussion-tool-in-existing-thread
Mar 12, 2026
Merged

fix: skip discussion tool when already in a topic#146
lishuceo merged 1 commit into
mainfrom
fix/skip-discussion-tool-in-existing-thread

Conversation

@lishuceo

Copy link
Copy Markdown
Owner

Summary

  • When a user @mentions the bot inside an existing Feishu topic (话题), the bot was creating a new discussion thread instead of replying in the existing topic
  • Root cause: discussionMcp tool was unconditionally injected into the Chat Agent, even when eventThreadId was already present
  • Fix: only inject discussionMcp when eventThreadId is absent (message is in main chat, not in a topic)

Test plan

  • In a Feishu group, create a topic, then @bot in the topic — should reply in-thread without creating a new discussion card
  • In main chat area, @bot with a complex question — should still be able to create a discussion thread via the tool

🤖 Generated with Claude Code

When a user @mentions the bot inside an existing Feishu topic (话题),
the bot should reply in that topic instead of creating a new discussion
thread. Previously, the discussionMcp tool was unconditionally injected
into the Chat Agent, allowing it to call start_discussion_thread even
when eventThreadId was already present — resulting in duplicate threads.

Now, discussionMcp is only created and injected when eventThreadId is
absent (i.e., the message is in the main chat, not in a topic).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 12, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 42s —— View job


Review of PR #146

  • Check for previous review comments — none found
  • Read changed file and diff
  • Analyze changes
  • Post review

✅ Approved — Clean, minimal fix that correctly addresses the bug.

Analysis:

The change conditionally skips discussionMcp creation when eventThreadId is present (i.e., the message is already inside a topic thread). Two parts work together:

  1. Line 1749-1757: discussionMcp is set to null when eventThreadId exists, avoiding unnecessary MCP server creation.
  2. Line 1788: The spread ...(discussionMcp ? { additionalMcpServers: ... } : {}) cleanly omits the property when null, which is safe because executor.ts:117 declares additionalMcpServers as optional and the usage at executor.ts:425 is guarded by an if check.

Verified:

  • eventThreadId is consistently used throughout the function to distinguish topic vs. main-chat context (session keys, reply targets, conversation storage) — this change follows the same established pattern
  • No resource leaks — createDiscussionMcpServer is simply not called, so nothing needs cleanup
  • No impact on the main-chat flow — when eventThreadId is absent, behavior is identical to before

No issues found. LGTM.

@lishuceo
lishuceo merged commit c670560 into main Mar 12, 2026
4 of 5 checks passed
@lishuceo
lishuceo deleted the fix/skip-discussion-tool-in-existing-thread branch March 12, 2026 05:17
lishuceo added a commit that referenced this pull request Apr 8, 2026
When a user @mentions the bot inside an existing Feishu topic (话题),
the bot should reply in that topic instead of creating a new discussion
thread. Previously, the discussionMcp tool was unconditionally injected
into the Chat Agent, allowing it to call start_discussion_thread even
when eventThreadId was already present — resulting in duplicate threads.

Now, discussionMcp is only created and injected when eventThreadId is
absent (i.e., the message is in the main chat, not in a topic).

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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