Skip to content

PRG-05: Channel routing bundle (from #338 #342 #344)#368

Closed
nap-liu wants to merge 3 commits intodataelement:mainfrom
nap-liu:prg/05-channel-routing__from-p338-p342-p344
Closed

PRG-05: Channel routing bundle (from #338 #342 #344)#368
nap-liu wants to merge 3 commits intodataelement:mainfrom
nap-liu:prg/05-channel-routing__from-p338-p342-p344

Conversation

@nap-liu
Copy link
Copy Markdown

@nap-liu nap-liu commented Apr 10, 2026

This regrouped PR combines the original changes from:\n- #338 dingtalk-user-matching\n- #342 channel-session-reset\n- #344 cross-channel-user-merge\n\nScope: channel identity/session routing behavior.

nap.liu and others added 3 commits April 10, 2026 11:28
…centralized token management

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dcoded limits

Remove redundant history[-ctx_size:] slicing in _call_agent_llm since
all callers already truncate history via SQL .limit(ctx_size). The
remaining channel handlers (websocket, dingtalk, discord, slack, wecom,
teams, discord_gateway, wecom_stream) already use
agent.context_window_size with DEFAULT_CONTEXT_WINDOW_SIZE=100 fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Thanks for putting this bundle together. The problems it targets are valid, especially channel session reset and DingTalk identity matching, but I do not think this PR is safe to merge as-is because it mixes several behavioral changes and has a few concrete risks.

Main concerns:

  1. Feishu /new / /reset can create the new P2P session under the agent creator instead of the actual sender. In the Feishu text flow, the command is handled before channel_user_service.resolve_channel_user() runs, so handle_channel_command() receives creator_id as user_id. Normal Feishu P2P sessions are later attributed to platform_user_id, so this can create ownership churn or incorrect session ownership after a reset.

  2. handle_channel_command() finds the old session using only agent_id + external_conv_id, without checking source_channel. Today the external IDs are prefixed, so this may not fail immediately, but the command handler should still include source_channel to avoid accidental cross-channel archival if ID formats change.

  3. The DingTalk token manager changes the token acquisition path from the existing oapi.dingtalk.com/gettoken style to api.dingtalk.com/v1.0/oauth2/accessToken, and then reuses that token for oapi.dingtalk.com/topapi/v2/user/get. This needs explicit verification against DingTalk APIs before replacing the existing helper, because it may break user-detail lookup or existing send-message calls that depend on get_dingtalk_access_token().

  4. The DingTalk unionid enrichment still does not appear to participate in the primary OrgMember lookup. resolve_channel_user() continues to call _find_org_member() with external_user_id=sender_staff_id, while the real unionid only lives in extra_info. Existing org-sync records that are only matchable by real unionid may still be missed.

  5. Removing the second history truncation inside _call_agent_llm() weakens a shared safety guard. It may be true that current callers already apply SQL limits, but _call_agent_llm() is shared channel infrastructure. Keeping the defensive truncation is safer unless there is test coverage proving every caller always passes bounded history.

Recommendation: please split this bundle into smaller PRs: one for channel /new / /reset, one for DingTalk identity matching, and one for DingTalk token caching. The reset PR should resolve the actual platform user before creating the new session, and the identity PR should wire DingTalk unionid into both OrgMember lookup and identifier backfill paths.

@nap-liu
Copy link
Copy Markdown
Author

nap-liu commented Apr 15, 2026

Closing this bundle per maintainer preference for focused single-concern PRs. The individual PRs remain open for review:

@nap-liu nap-liu closed this Apr 15, 2026
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.

2 participants