Skip to content

fix: feishu streaming cards, structured errors, and migration robustness#444

Merged
yaojin3616 merged 2 commits intomainfrom
fix/feishu-and-migration
Apr 20, 2026
Merged

fix: feishu streaming cards, structured errors, and migration robustness#444
yaojin3616 merged 2 commits intomainfrom
fix/feishu-and-migration

Conversation

@yaojin3616
Copy link
Copy Markdown
Collaborator

@yaojin3616 yaojin3616 commented Apr 20, 2026

Summary

  • Feishu 流式卡片:新增 _build_streaming_card 构建飞书交互卡片,支持 thinking 展示和工具状态滚动
  • 结构化错误处理:引入 FeishuAPIError,保留 HTTP 状态码、错误码、log_id 等字段,提供用户友好的错误消息
  • 迁移健壮性add_participants 迁移兼容无 username 列的数据库环境
  • 会话权限修复:Agent 创建者现可查看/管理该 Agent 下所有用户的会话(原仅限 admin 角色)
  • 清理废弃参数:移除 send_feishu_message 工具中的 open_id 参数,统一使用 user_id

Test plan

  • 飞书 webhook 触发流式回复,验证卡片正常渲染
  • 飞书 API 错误时返回结构化错误信息
  • 在无 username 列的数据库上运行 add_participants 迁移
  • Agent 创建者可访问 scope=all 会话列表
  • 运行 backend/tests/test_chat_sessions_api.py 全部通过

- Add streaming interactive card builder and tool-error helpers in feishu.py
- Introduce FeishuAPIError with structured fields and user-friendly messages
- Fix add_participants migration to handle missing username column
- Refactor chat session permissions: agent creator can view/manage all sessions
- Remove deprecated open_id param from send_feishu_message tool (use user_id)
- Expand chat session API tests
Copy link
Copy Markdown

@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: 0a53c2a9ba

ℹ️ 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".

Comment on lines 116 to 121
if resp.status_code >= 400:
logger.warning(
f"[Feishu] {stage} HTTP failure "
f"(http_status={resp.status_code}, message_id={message_id}, body={str(data)[:300]})"
)
raise RuntimeError(f"Feishu {stage} HTTP {resp.status_code}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Raise on HTTP-level Feishu API failures

The resp.status_code >= 400 branch now only logs and falls through, so _parse_api_response may return as if successful when Feishu responds with an HTTP error payload that lacks a nonzero code (or unexpectedly includes code: 0). In that case callers like send_message and patch_message do not get a FeishuAPIError, which drops HTTP error context and can mis-handle provider outages as normal responses. This is a regression from the previous behavior that raised immediately on HTTP failures.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it's nesesary

Combine both approaches: check for identities table first (new schema
where username moved to identities), fall back to users.username column
(old schema), then fall back to display_name only.
Copy link
Copy Markdown

@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: 3bcb39dde8

ℹ️ 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".

Comment on lines 4039 to 4040
resp = await _try_send(config.app_id, config.app_secret, target_member.external_id, "user_id")
if resp.get("code") == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore open_id fallback when user_id delivery fails

_send_feishu_message now always delivers with receive_id_type="user_id" and no longer retries open_id. In this codebase, Feishu org sync still pulls members with user_id_type=open_id and stores that value into external_id (see org_sync_adapter comments around that mapping), so many existing members will carry an open_id-shaped identifier. With this change, those recipients now hard-fail sends even though open_id is present and used to be a working fallback, which breaks proactive Feishu messaging for tenants without employee_id scope/re-sync.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

no need

@yaojin3616 yaojin3616 merged commit e7028da into main Apr 20, 2026
@yaojin3616 yaojin3616 deleted the fix/feishu-and-migration branch April 23, 2026 09:43
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