Skip to content

fix(feishu): serialize approval callback card data to JSON string#10256

Open
stephenlzc wants to merge 2 commits into
NousResearch:mainfrom
stephenlzc:fix/feishu-approval-card-200340
Open

fix(feishu): serialize approval callback card data to JSON string#10256
stephenlzc wants to merge 2 commits into
NousResearch:mainfrom
stephenlzc:fix/feishu-approval-card-200340

Conversation

@stephenlzc

Copy link
Copy Markdown

Summary

Fixes the Feishu (Lark) command approval card buttons failing with error code 200340.

Problem

When a dangerous command triggered the ⚠️ Command Approval Required interactive card in Feishu, clicking any button (Allow Once, Session, Always, Deny) resulted in a Feishu client error:

Something went wrong. Please try again later
code: 200340

The agent thread remained blocked, and the command was never resolved.

Root Cause

_handle_approval_card_action() in gateway/platforms/feishu.py built a CallBackCard and assigned a Python dict to card.data:

card.data = self._build_resolved_approval_card(choice=choice, user_name=user_name)

However, the Feishu API expects card.data to be a JSON string. The Lark SDK serialized the dict as a nested JSON object, which Feishu rejected with error 200340.

Fix

Wrapped the card dict in json.dumps(..., ensure_ascii=False) before assigning to card.data, matching how outgoing interactive cards are already handled in send_exec_approval():

card.data = json.dumps(
    self._build_resolved_approval_card(choice=choice, user_name=user_name),
    ensure_ascii=False,
)

Tests

Updated tests/gateway/test_feishu_approval_buttons.py to assert that:

  • response.card.data is a str (not a dict).
  • The card content is correct after json.loads().

All 18 Feishu approval-button tests pass.

Related Issue

Fixes #10251

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • Added/updated tests

The Feishu API expects CallBackCard.data to be a JSON string, not a
Python dict. When _handle_approval_card_action() assigned a dict to
card.data, the Lark SDK serialized it as a nested object, causing
Feishu to reject the card action response with error code 200340.

Fix by wrapping the resolved card dict in json.dumps(..., ensure_ascii=False),
matching how outgoing interactive cards are already handled in
send_exec_approval().

Also updated test assertions to verify card.data is a string and to
json.loads() it before inspecting contents.

Fixes NousResearch#10251
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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feishu command approval card buttons fail with error code 200340

2 participants