Skip to content

fix(feishu): serialize card.data to JSON string for approval/update-prompt responses#42465

Open
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/feishu-card-data-json
Open

fix(feishu): serialize card.data to JSON string for approval/update-prompt responses#42465
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/feishu-card-data-json

Conversation

@liuhao1024

@liuhao1024 liuhao1024 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Serializes card.data to a JSON string in both _handle_approval_card_action and _handle_update_prompt_card_action callbacks. The Feishu API requires card.data to be a JSON string, but both handlers were passing raw Python dicts, causing error 200340 when users click approval or update-prompt buttons on interactive cards.

Related Issue

Fixes #38305, Fixes #10251, Fixes #10073, Fixes #8246, Fixes #13924

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/feishu.py: Wrap card.data assignments in _handle_approval_card_action (line 2639) and _handle_update_prompt_card_action (line 2696) with json.dumps(ensure_ascii=False) so the Feishu API receives a JSON string instead of a Python dict.
  • tests/gateway/test_feishu_approval_buttons.py: Update 6 test assertions to verify card.data is a str (via isinstance check) and parse it with json.loads() before accessing dict keys.

How to Test

  1. pytest tests/gateway/test_feishu_approval_buttons.py -v — all 38 tests pass
  2. On a live Feishu bot: trigger an exec approval → click "Approve" or "Deny" → card should update without error 200340
  3. Trigger a /update prompt → click "Yes" or "No" → card should update without error 200340

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 run pytest tests/gateway/test_feishu_approval_buttons.py -v and all 38 tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A (Feishu platform adapter, no OS-specific behavior)
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: gateway/platforms/feishu.py_handle_approval_card_action, _handle_update_prompt_card_action, _build_resolved_approval_card, _build_resolved_update_prompt_card
  • Callers of _build_resolved_approval_card: 1 (line 2639)
  • Callers of _build_resolved_update_prompt_card: 1 (line 2696)
  • Blast radius: LOW — only affects Feishu card callback responses, no other callers
  • Related patterns: PR fix(feishu): serialize approval callback card data to JSON string #10256 attempted the same fix but targeted stale line numbers (line 1909 vs current 2639). This PR applies the fix to the current codebase and also covers the _handle_update_prompt_card_action handler that fix(feishu): serialize approval callback card data to JSON string #10256 missed.

…rompt responses

Feishu API expects card.data to be a JSON string, but
_build_resolved_approval_card() and _build_resolved_update_prompt_card()
return dicts. The raw dict assignment causes error 200340 when users
click approval or update-prompt buttons on interactive cards.

Fix: wrap both assignments with json.dumps(ensure_ascii=False).

Fixes NousResearch#38305
@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 9, 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 type/bug Something isn't working

Projects

None yet

2 participants