Skip to content

fix(gateway): resolve Feishu thread reply failures (error 99992402) - #37322

Open
sunguangran wants to merge 1 commit into
NousResearch:mainfrom
sunguangran:fix/feishu-thread-reply
Open

fix(gateway): resolve Feishu thread reply failures (error 99992402)#37322
sunguangran wants to merge 1 commit into
NousResearch:mainfrom
sunguangran:fix/feishu-thread-reply

Conversation

@sunguangran

Copy link
Copy Markdown

What does this PR do?

When the Hermes gateway replies to a message inside a Feishu topic/thread, two issues cause delivery failures:

  1. Error 99992402 — Feishu rejects post-type messages sent via the reply endpoint in certain thread contexts. The existing code only caught _POST_CONTENT_INVALID_RE patterns but not this specific error code, so the fallback to text type was never triggered.

  2. Missing thread root resolution — Feishu does not support receive_id_type=thread_id on the im.v1.message.create endpoint. When a thread message arrives with a thread_id but no explicit reply_to_message_id, the gateway has no way to route the reply into the thread. The original code attempted to use thread_id as receive_id directly, which silently fails or posts to the wrong location.

This PR adds:

  • Error code 99992402 detection alongside the existing post-content-invalid regex, triggering the same posttext fallback path.
  • A new _resolve_thread_root() helper that calls im.v1.message.list with container_id_type=thread to find the root message of a thread, then uses the reply API to post into the correct thread context.

Related Issue

N/A — discovered in production with Feishu topic-based group chats.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • gateway/platforms/feishu.py:
    • Added 99992402 to the error detection in the post-send try/except block, so the posttext fallback triggers on this error code too.
    • Added 99992402 to the response-level fallback detection (when the API returns an error in the response body rather than raising).
    • Added 99992402 to the retry-loop error detection in _feishu_send_with_retry.
    • Added _resolve_thread_root(thread_id) method that queries im.v1.message.list to find the root message of a Feishu thread (the message with no parent_id).
    • In _send_message_to_chat(), when thread_id is present but no reply_to_message_id is available, calls _resolve_thread_root() to resolve the thread root and uses the reply API.
    • Removed the fallback path that tried to use thread_id as receive_id with receive_id_type=thread_id (unsupported by Feishu API).

How to Test

  1. Set up a Feishu group with topics/threads enabled.
  2. Send a message inside a topic thread that triggers the gateway to reply.
  3. Before this fix: reply either fails with error 99992402 or posts to the main chat instead of the thread.
  4. After this fix: reply lands correctly inside the topic thread.

Tested on macOS 15 with Feishu Open Platform API v1.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've tested on my platform: macOS 15

Documentation & Housekeeping

  • I've updated relevant documentation — N/A
  • I've updated cli-config.yaml.example — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact — N/A (Feishu-specific code path, no Windows/macOS impact)
  • I've updated tool descriptions/schemas — N/A

Screenshots / Logs

Before fix — error 99992402 in logs:

[Feishu] API error: code=99992402 msg="invalid message type in thread"

After fix — thread root resolved and reply succeeds:

[Feishu] Resolved thread root omt_xxx → om_xxx, sending reply

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter labels Jun 2, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing the Feishu thread-delivery failure. The underlying bug remains on current main: plugins/platforms/feishu/adapter.py:4623-4651 still emits receive_id_type="thread_id" for an anchorless threaded send, and plugins/platforms/feishu/adapter.py:1913-1936 does not recognize 99992402 for the post-to-text fallback.

Problems

  • The patch targets gateway/platforms/feishu.py, but commit 560010547 migrated the active adapter to plugins/platforms/feishu/adapter.py; this needs a conflict-aware salvage rather than a direct apply.
  • The PR adds no regression tests. Current tests/gateway/test_stream_consumer_thread_routing.py:180-240 explicitly asserts the invalid thread_id receive type, so that expectation must be replaced.
  • Preserve current feishu_user_id: routing at plugins/platforms/feishu/adapter.py:4636-4650 when adapting the create fallback.

Suggested changes

  • Re-target the active plugin adapter and add tests for exception/response 99992402 fallback plus anchorless thread routing.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants