Skip to content

feat(feishu): prefer thread_id for topic session routing#29788

Merged
Takhoffman merged 3 commits intoopenclaw:mainfrom
songyaolun:pr/feishu-only-v2
Mar 2, 2026
Merged

feat(feishu): prefer thread_id for topic session routing#29788
Takhoffman merged 3 commits intoopenclaw:mainfrom
songyaolun:pr/feishu-only-v2

Conversation

@songyaolun
Copy link
Contributor

@songyaolun songyaolun commented Feb 28, 2026

Summary

  • prefer Feishu thread_id over root_id for topic-scoped session routing
  • keep topicSessionMode legacy behavior while improving topic isolation accuracy
  • force thread-context replies to stay in thread and disable streaming cards in thread contexts to avoid topic drift

Changes

  • parse and carry thread_id from inbound events (FeishuMessageEvent/FeishuMessageContext)
  • centralize group session resolution and use topic-scoped keys based on thread_id first
  • preserve group history isolation by using session peer id as history key
  • add threadReply mode in reply dispatcher to force reply_in_thread and disable streaming in thread contexts
  • update schema comments and add regression tests for thread-id routing and thread reply behavior

Verification

  • pnpm --dir /Users/bytedance/Documents/git_repo/openclaw exec vitest run extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts
  • pnpm --dir /Users/bytedance/Documents/git_repo/openclaw exec oxfmt --check extensions/feishu/src/bot.ts extensions/feishu/src/types.ts extensions/feishu/src/reply-dispatcher.ts extensions/feishu/src/config-schema.ts extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts

Screenshots

  • Origin
image
  • Topic A starts an isolated session
  • Topic B starts a different isolated session
image image image
  • Bot reply stays in the same topic thread UI (attach screenshot)
image image
  • Mainline group chat remains on main session (attach screenshot)
image

Closes #29791

@openclaw-barnacle openclaw-barnacle bot added channel: feishu Channel integration: feishu size: M labels Feb 28, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR enhances Feishu's topic session routing by preferring thread_id over root_id for improved topic isolation accuracy:

  • Added thread_id field to FeishuMessageEvent and FeishuMessageContext types
  • Introduced resolveFeishuGroupSession() function to centralize group session resolution logic
  • Modified topic scope resolution to prioritize thread_id ?? root_id ?? messageId (when applicable)
  • Implemented threadReply mode that forces replies to stay in thread and disables card streaming in thread contexts to maintain thread affinity
  • Updated history isolation to use session peer ID (groupSession?.peerId) instead of just chatId, providing proper history separation for topic-scoped sessions
  • Added comprehensive test coverage for thread_id preference, legacy mode compatibility, and thread reply behavior
  • Updated schema documentation to clarify thread_id preference

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured with centralized logic, comprehensive test coverage for all key behaviors, proper handling of edge cases (empty strings, undefined values), and maintains backward compatibility with legacy topicSessionMode. The changes are incremental and focused on a specific improvement without introducing breaking changes.
  • No files require special attention

Last reviewed commit: cb89f34

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb89f3422d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@songyaolun songyaolun changed the title fix(feishu): prefer thread_id for topic session routing feat(feishu): prefer thread_id for topic session routing Feb 28, 2026
@Takhoffman Takhoffman merged commit f22fc17 into openclaw:main Mar 2, 2026
9 checks passed
@Takhoffman
Copy link
Contributor

PR #29788 - feat(feishu): prefer thread_id for topic session routing (#29788)

Merged after verification.

  • Merge commit: f22fc17
  • Verified: pnpm test -- extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts; pnpm build
  • Autoland updates:
    M CHANGELOG.md
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11b87be1bd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// Prefer root_id first so both turns stay on the same peer key.
const topicScope =
groupSessionScope === "group_topic" || groupSessionScope === "group_topic_sender"
? (normalizedRootId ?? normalizedThreadId ?? (replyInThread ? messageId : null))

Choose a reason for hiding this comment

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

P2 Badge Align debounced grouping with thread_id topic sessions

With inbound debounce enabled (messages.inbound.debounceMs > 0), this new thread_id-based topic routing can still misroute content because the debounce key is still built from root_id only (extensions/feishu/src/monitor.account.ts:309-311). If two text messages from the same sender arrive quickly in different threads that have no root_id, onFlush merges them and dispatches using the last event’s thread metadata, so the earlier thread’s text is routed into the wrong topic/session. Since this change now routes by thread_id (topicScope fallback), the debounce key should use the same root/thread fallback to avoid cross-thread mixing.

Useful? React with 👍 / 👎.

@Takhoffman Takhoffman mentioned this pull request Mar 2, 2026
18 tasks
dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
) thanks @songyaolun

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts
- pnpm build

Co-authored-by: songyaolun <26423459+songyaolun@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
) thanks @songyaolun

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts
- pnpm build

Co-authored-by: songyaolun <26423459+songyaolun@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
) thanks @songyaolun

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts extensions/feishu/src/reply-dispatcher.test.ts
- pnpm build

Co-authored-by: songyaolun <26423459+songyaolun@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support thread-based replies in Feishu plugin

2 participants