Skip to content

fix(feishu): treat bare oc_/ou_ delivery targets as chat_id/open_id - #7

Open
Eva032789 wants to merge 1 commit into
marswaveai:mainfrom
Eva032789:fix/feishu-delivery-target
Open

Eva032789 wants to merge 1 commit into
marswaveai:mainfrom
Eva032789:fix/feishu-delivery-target

Conversation

@Eva032789

Copy link
Copy Markdown

Problem

The outbound delivery path only understood two shapes of delivery target: chat:<chat_id> and user:<open_id>. Anything else was treated as an open_id.

Some delivery paths hand the plugin a bare Feishu id with no prefix. Cron runs redelivered after a restart are one of them: the run's deliveryContext.to reaches the plugin as oc_444a075683cff5b4bbcd49fa869afc87, with no chat: prefix.

resolveReceiver then produced { receiveIdType: "open_id", receiveId: "oc_..." } and Feishu rejected every attempt:

code 99992361  msg "open_id cross app"

Observed on Cola 1.4.5 / plugin 0.2.1: one stuck daily-report run retried after every restart and produced 369 failed sends in a single month — always the same target, always the same error code, never a content problem (replaying the identical text through im/v1/messages with receive_id_type=chat_id succeeds).

Change

resolveReceiver now normalizes the target first, and the id prefix is authoritative:

input resolved as
oc_... chat_id (new — this is the bug)
chat:oc_... chat_id
ou_... / user:ou_... open_id, upgraded to the DM chat_id when the chat map knows it
user:oc_... (mismatched prefix) chat_id — a chat id is never a valid open_id
"" / "chat:" previous fallback, unchanged

normalizeDeliveryTarget is a new exported pure helper so the mapping can be tested on its own. Well-formed chat: / user: targets behave exactly as before; sendMedia shares the same resolver, so it is fixed too.

Tests

plugins/feishu/tests/outbound-send.test.ts covers the bare-chat-id regression, bare open ids, explicit prefixes, a mismatched prefix, empty targets, and DM-map hits/misses.

Gates run locally on this branch (all green): pnpm fmt:check (114 files), pnpm lint, pnpm test — 162 tests in 21 files, including the 9 new ones, pnpm build:registry, plus typecheck and build for plugins/feishu. cola-plugin-feishu bumped to 0.2.2.

Fixes the retry storm described above; after deploying, a redelivered run that previously burned a failed send per attempt delivers normally.

Delivery targets reach the plugin as `chat:<chat_id>`, `user:<open_id>`, or
sometimes as a bare Feishu id. Cron runs redelivered after a restart pass the
raw chat id with no prefix, which the resolver treated as an open_id and Feishu
rejected with `99992361 open_id cross app`.

Treat the id prefix as authoritative (oc_ -> chat, ou_ -> user), keep the
explicit prefixes working, and cover the mapping with tests.
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