Skip to content

fix(feishu): route topic-group messages through per-thread sequential lanes - #64920

Closed
riba2534 wants to merge 7 commits into
openclaw:mainfrom
riba2534:fix/feishu-topic-group-concurrent-lanes
Closed

riba2534 wants to merge 7 commits into
openclaw:mainfrom
riba2534:fix/feishu-topic-group-concurrent-lanes

Conversation

@riba2534

Copy link
Copy Markdown

Summary

  • Problem: In Feishu topic groups, different topics in the same chat are forced to process messages serially because getFeishuSequentialKey() in extensions/feishu/src/sequential-key.ts only buckets the per-chat serial queue by ${accountId}:${chatId}, ignoring root_id / thread_id. A busy tool call in one topic blocks every other topic in the same chat.
  • Why it matters: For bots wiring in long-running tools (knowledge base search, codegen, etc.), a single tool call taking 40–180 seconds means 10 concurrent topic messages queue for 7–30 minutes before the last reply lands. Users on other topics perceive the bot as dead.
  • What changed: getFeishuSequentialKey() now appends :topic:{rootId|threadId} to the sequential queue key when the incoming event carries topic metadata, so different topics run on independent lanes. A small resolveFeishuTopicLaneId() helper keeps the root-over-thread precedence anchored by bot-content.ts / bot.test.ts.
  • What did NOT change (scope boundary): getFeishuSequentialKey() signature is unchanged; monitor.account.ts, sequential-queue.ts, bot-content.ts, and event-types.ts are not touched. /stop and /btw still resolve to chat-wide :control / :btw escape lanes before the topic check, matching the Telegram sequential-key behavior in extensions/telegram/src/sequential-key.ts.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: extensions/feishu/src/sequential-key.ts has historically bucketed the per-chat serial queue by ${accountId}:${chatId} only. This was originally correct when all messages in a group shared one session, but Feishu topic groups (chat_mode=topic) carry root_id / thread_id on each message and each topic is a semantically independent conversation. Telegram's extensions/telegram/src/sequential-key.ts already handles the analogous forum-thread case by appending a :topic:{threadId} suffix; Feishu was simply missing the parallel adaptation.
  • Missing detection / guardrail: No unit test asserted "different topics in the same chat must resolve to different keys". The existing sequential-key.test.ts only covered p2p + /stop + /btw cases.
  • Contributing context: The Lark-team-maintained @larksuite/openclaw-lark plugin (separate repo) solved the same problem in its src/channel/chat-queue.ts + src/channel/event-handlers.ts, which independently validates that this direction is correct. This PR ports the capability into the community-maintained @openclaw/feishu package, adapted to its existing architecture — preserving the :btw / :control escape lane design that differs from the Lark plugin's abort-controller fast-path.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/feishu/src/sequential-key.test.ts
  • Scenario the test should lock in: Two events with the same chat_id but different root_id must produce different sequential keys, and both keys must carry a :topic: segment so per-topic lane behavior is observable from the key string.
  • Why this is the smallest reliable guardrail: getFeishuSequentialKey() is a pure string function with one consumer (monitor.account.ts:408); a unit test over its output is the exact seam where this regression can be locked in.
  • Existing test that already covers this: None before this PR.
  • If no new test is added, why not: N/A — new tests are included.

User-visible / Behavior Changes

  • Topic-group messages now run concurrently across topics. Different topics in the same chat no longer wait for each other's tool calls; different chats were already concurrent and stay concurrent.
  • Non-topic groups and p2p chats are unchanged. When root_id and thread_id are both absent/empty, the sequential key is byte-identical to the previous output.
  • `/stop` and `/btw` are unchanged even inside topic groups: they still resolve to the chat-wide :control / :btw lanes before the topic check, so abort and out-of-band commands never get blocked behind a busy topic.
  • Config: No new config. Topic-heavy deployments are encouraged (not required) to also set channels.feishu.groupSessionScope: "group_topic_sender" so the session store's peer id follows the same per-topic partitioning as the new queue key — this prevents a rare case where one sender talking in two topics simultaneously could interleave context within a single shared session.

Diagram (if applicable)

```text
Before:
topic group "oc_G" with 3 active topics (root_id T1, T2, T3)
inbound msg(T1) ─┐
inbound msg(T2) ─┼─► single lane "feishu:default:oc_G" ─► process(T1) ─► process(T2) ─► process(T3)
inbound msg(T3) ─┘ (T2 and T3 wait for T1)

After:
topic group "oc_G" with 3 active topics
inbound msg(T1) ─► lane "feishu:default:oc_G:topic:T1" ─► process(T1)
inbound msg(T2) ─► lane "feishu:default:oc_G:topic:T2" ─► process(T2) (concurrent)
inbound msg(T3) ─► lane "feishu:default:oc_G:topic:T3" ─► process(T3)

/stop in any topic ─► lane "feishu:default:oc_G:control" (chat-wide, unchanged)
/btw in any topic ─► lane "feishu:default:oc_G:btw" (chat-wide, unchanged)
```

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)

This PR is a local refactor of one pure string function and its test. It does not touch auth, config schemas, network I/O, or the tool execution surface.

Repro + Verification

Environment

  • OS: Linux (x86_64)
  • Runtime/container: Node 22 via pnpm workspace, main branch at 899a1b7
  • Model/provider: N/A (no runtime LLM call involved in the changed seam)
  • Integration/channel: feishu channel (topic-group mode)
  • Relevant config: N/A

Steps

  1. Open `extensions/feishu/src/sequential-key.ts` on main and observe that when the incoming `FeishuMessageEvent` carries `root_id` / `thread_id`, the computed sequential key still collapses to `feishu:{accountId}:{chatId}` without any topic segment.
  2. Trace the call into `extensions/feishu/src/monitor.account.ts:408`: that key is handed to `createSequentialQueue()`, which maintains a per-key FIFO. A busy task on one topic therefore blocks every other topic in the same chat.
  3. Apply this PR and run `pnpm test extensions/feishu/src/sequential-key.test.ts`.

Expected

  • All new parametrized cases for topic keys resolve to `feishu:{accountId}:{chatId}:topic:{rootId|threadId}`.
  • `/stop` and `/btw` cases inside topic groups still resolve to `...:control` / `...:btw` (no topic segment).
  • Two events with same `chatId` but different `rootId` produce distinct keys.

Actual

Matches expected. See Evidence.

Evidence

  • `pnpm test extensions/feishu/src/sequential-key.test.ts` → 14/14 tests passed (6 original + 8 new covering topic-only, thread-only, both-precedence, whitespace-root-fallback, regular-group fallback, `/stop` in topic, `/btw` in topic, and two-topic isolation).
  • `pnpm test extensions/feishu/` → 616/616 tests passed, 0 regressions across the whole Feishu extension, including the 10+ existing `root_id` fixtures in `bot.test.ts`.
  • `pnpm check` → 0 warnings / 0 errors across `tsgo` + `oxlint` (11164 files, 144 rules) + all webhook/auth safety linters.
  • `pnpm build` → exit 0, no `INEFFECTIVE_DYNAMIC_IMPORT` warnings.

Human Verification (required)

  • Verified scenarios:
    • `getFeishuSequentialKey()` unit behavior across 14 cases covering p2p, `/stop`, `/btw`, topic-group with `root_id` only, with `thread_id` only, with both (root_id precedence), with whitespace-only `root_id` (fallback to `thread_id`), and two-topic isolation in the same chat.
    • Full `pnpm test extensions/feishu/` — confirmed 616 existing feishu tests still pass.
  • Edge cases checked:
    • Whitespace-only `root_id` falls back to `thread_id` (matches the `.trim() || .trim()` implementation).
    • `/stop` and `/btw` inside topic groups still resolve to chat-wide escape lanes (two dedicated `it` tests for this).
    • Non-topic group / p2p messages (no `root_id` / `thread_id`) return exactly the previous `baseKey` output.
  • What I did NOT verify:
    • No end-to-end live Feishu run. The change is fully captured by the unit seam at `sequential-key.ts` and the downstream `createSequentialQueue` is a trivial Map-based FIFO whose per-key isolation is already tested in `sequential-queue.test.ts`.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • Detail: Non-topic groups and p2p chats produce byte-identical sequential keys to before this PR. Topic groups produce a new key shape (`:topic:{id}` segment appended), but since the queue is a process-local `Map`, nothing persists across restarts — there is no migration surface.

Risks and Mitigations

  • Risk: In the default `channels.feishu.groupSessionScope: "group"` configuration, different topics in the same chat still share one session peer id. When two topics run concurrently, the session store's Promise-chain lock (`src/config/sessions/store.ts`) keeps writes atomic, but the two agent runs still see a shared history stream and could interleave context entries for the same sender talking in multiple topics at once.
    • Mitigation: For topic-heavy deployments, set `channels.feishu.groupSessionScope: "group_topic"` or `"group_topic_sender"` so the session peer id also includes the topic. This aligns the session partitioning with the new queue partitioning and removes the interleaving concern entirely. The default is left as-is for backward compatibility; this PR just mentions the recommendation in the user-visible section.
  • Risk: Two-repo drift with `@larksuite/openclaw-lark`. The Lark plugin uses `thread_id || root_id` precedence and a different abort architecture (an `abortController` fast-path with an `activeDispatchers` map), while this PR uses `root_id ?? thread_id` and keeps the existing `:control` / `:btw` lane suffixes. The two implementations now agree on the behavior goal (per-topic concurrency) but not on the exact precedence order.
    • Mitigation: This PR deliberately preserves the `@openclaw/feishu` conventions already locked in by `bot-content.ts` and the existing `bot.test.ts` assertion "keeps root_id as topic key when root_id and thread_id both exist". Cross-repo precedence alignment is orthogonal and belongs in a separate follow-up.

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S labels Apr 11, 2026
@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a sequential-queue fan-out bug in the Feishu extension: getFeishuSequentialKey() now appends :topic:{rootId|threadId} when a message carries topic metadata, so different topics within the same chat get independent processing lanes instead of serializing behind each other. The implementation correctly mirrors extensions/telegram/src/sequential-key.ts, preserves the chat-wide :control / :btw escape lanes, and is backward-compatible (non-topic messages produce byte-identical keys).

Confidence Score: 5/5

Safe to merge — pure string-function refactor with no external I/O, comprehensive test coverage, and no regressions in the broader Feishu suite.

The change is narrowly scoped to a single pure function and its tests. Logic is correct, escape-lane ordering is preserved, backward compatibility is maintained, tests cover all enumerated edge cases (whitespace root_id, both fields present, /stop and /btw inside topic groups, two-topic isolation), and pnpm check/build/test all passed per the evidence. No P0 or P1 findings.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(feishu): route topic-group messages ..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 83bf771330

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/feishu/src/sequential-key.ts Outdated
Comment on lines +34 to +36
const topicLaneId = resolveFeishuTopicLaneId(event);
if (topicLaneId) {
return `${baseKey}:topic:${topicLaneId}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Restrict topic lane routing to topic-scoped groups

This now routes any message carrying root_id/thread_id to a :topic: queue lane, but Feishu normal groups also send root_id for quote replies (see extensions/feishu/src/bot.test.ts:2258 where groupSessionScope: "group" still has root_id). Because monitor.account.ts uses this key directly for createSequentialQueue (extensions/feishu/src/monitor.account.ts:408), replies in the same non-topic chat can run concurrently on different lanes instead of the intended per-chat FIFO, which can interleave shared group-session context and reorder bot responses.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this — you're exactly right, and this is a correctness bug in the previous revision.

I verified the scenario against extensions/feishu/src/bot.test.ts:2258 ("replies to triggering message in normal group even when root_id is present (#32980)"), which locks in that Feishu quote replies in a normal group (groupSessionScope: "group") still carry root_id pointing at the quoted message. With the unconditional topic-lane routing from 83bf7713, those quote replies would incorrectly split onto a :topic: lane and break the per-chat FIFO guarantee for normal groups.

Fixed in e586802831 by gating the topic-lane branch on the effective groupSessionScope:

  • New resolveFeishuGroupSessionScope helper in extensions/feishu/src/bot-content.ts (extracted from the existing scope-precedence logic in resolveFeishuGroupSession, so both call sites share one source of truth).
  • getFeishuSequentialKey now takes an optional groupSessionScope parameter and only appends :topic:{rootId|threadId} when the scope is group_topic or group_topic_sender.
  • dispatchFeishuMessage in extensions/feishu/src/monitor.account.ts resolves the scope via resolveFeishuAccount + resolveFeishuGroupConfig + resolveFeishuGroupSessionScope before computing the sequential key, so the queue partitioning stays aligned with the session-store partitioning.

New regression test keeps normal-group quote replies on the chat-wide lane even when root_id is present (#32980) in sequential-key.test.ts locks in the fix for group, group_sender, and the default (undefined) scope.

Verification:

  • pnpm test extensions/feishu/ → 617/617 passed (the +1 is this new regression test)
  • pnpm check → 0 warnings / 0 errors
  • pnpm build → exit 0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: e586802831

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +417 to +420
const groupConfig = chatId
? resolveFeishuGroupConfig({ cfg: feishuCfg, groupId: chatId })
: undefined;
const groupSessionScope = resolveFeishuGroupSessionScope({ groupConfig, feishuCfg });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Limit topic queue lanes to group chats

dispatchFeishuMessage now computes groupSessionScope for every message without checking event.message.chat_type, then passes that scope into getFeishuSequentialKey. Feishu DMs can carry root_id (see the existing DM fixture in extensions/feishu/src/bot.test.ts around the "propagates parent/root message ids" case), so when groupSessionScope is configured as group_topic/group_topic_sender (globally or via wildcard group config), DM replies are incorrectly split into :topic: lanes and can run concurrently instead of preserving per-chat FIFO ordering.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks again — you're right, and this is a real bug in e586802831.

I verified the DM quote-reply scenario against extensions/feishu/src/bot.test.ts:721 ("propagates parent/root message ids into inbound context for reply reconstruction"), which explicitly uses chat_type: "p2p" + root_id: "om_root_001" + parent_id: "om_parent_001" — so Feishu DMs do legitimately carry root_id for quote replies. With a globally / wildcard configured groupSessionScope: "group_topic" (or group_topic_sender), the previous revision would have split those DM replies onto :topic: lanes and broken per-chat FIFO.

Fixed in 230556a730 with two aligned gates:

  1. dispatchFeishuMessage (extensions/feishu/src/monitor.account.ts) now mirrors the isGroup gate already used by resolveFeishuGroupSession in bot.ts: it only resolves feishuCfg / groupConfig / groupSessionScope when event.message.chat_type === "group". DMs (p2p / private) skip the scope lookup entirely and pass undefined to getFeishuSequentialKey, so they can never accidentally inherit a wildcard-configured topic scope.

  2. getFeishuSequentialKey (extensions/feishu/src/sequential-key.ts) now also defense-in-depth checks event.message.chat_type === "group" before the topic-lane branch. Even if a future caller forgot the gate and passed groupSessionScope: "group_topic" on a DM event, the topic-lane routing still wouldn't fire. The existing :control / :btw escape lanes are unchanged and still fire chat-wide regardless of chat type, which is the intended behavior.

New regression test keeps DM quote replies on the chat-wide lane even when a topic scope leaks in in sequential-key.test.ts locks in the fix for chat_type: "p2p" + group_topic, p2p + group_topic_sender, and chat_type: "private" + group_topic_sender + root_id + thread_id.

The existing :control / :btw / topic-group / #32980 regression tests were updated to explicitly set chatType: "group" (previously they relied on the default p2p because the function used to be chat-type agnostic), so nothing silently drifts.

Verification:

  • pnpm test extensions/feishu/ → 618/618 passed (the +1 over the previous revision is the new DM regression)
  • pnpm check → 0 warnings / 0 errors
  • pnpm build → exit 0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 230556a730

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/feishu/src/sequential-key.ts Outdated
// resolveFeishuGroupSession in bot-content.ts and anchored by the
// bot.test.ts "keeps root_id as topic key when root_id and thread_id
// both exist" assertion.
return event.message.root_id?.trim() || event.message.thread_id?.trim() || undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Align topic lane fallback with session topic resolution

Using root_id?.trim() || thread_id?.trim() here makes whitespace-only root_id fall back to thread_id, so the queue key becomes :topic:<thread>, but resolveFeishuGroupSession still derives topicScope with normalizedRootId ?? normalizedThreadId and treats that same payload as chat-scoped (empty root_id blocks fallback). In group_topic/group_topic_sender mode this creates lane/session divergence where two thread lanes can run concurrently while sharing one chat session, which can interleave history and reorder replies for those inputs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks — caught cleanly again, and you're right that the previous || fallback was misaligned with resolveFeishuGroupSession.

Fixed in e0e9027469 by rewriting resolveFeishuTopicLaneId to mirror the exact precedence used in bot-content.ts:

const normalizedRootId = event.message.root_id?.trim();
const normalizedThreadId = event.message.thread_id?.trim();
const topicId = normalizedRootId ?? normalizedThreadId;
return topicId ? topicId : undefined;

The key change is ?? (nullish-coalesce) instead of ||. A whitespace-only root_id that trims to "" now stays as the empty string rather than falling through to thread_id, and the falsy check at the end collapses the lane to chat-wide — exactly matching resolveFeishuGroupSession's topicScope semantics (normalizedRootId ?? normalizedThreadId ?? (replyInThread ? messageId : null) followed by the topicScope ? ... : chatId gate in the group_topic / group_topic_sender branches).

Updated the existing parametrized fixture for rootId: " ", threadId: "omt_thread_b" to assert feishu:default:oc_topic_chat (was previously :topic:omt_thread_b — that was the divergence you flagged).

Added a dedicated regression test keeps queue lane aligned with resolveFeishuGroupSession ?? precedence that locks in:

  • whitespace root_id + valid thread_id in group_topic → chat-wide (not :topic:thread)
  • whitespace root_id + valid thread_id in group_topic_sender → chat-wide (same)
  • undefined root_id + valid thread_id in group_topic → :topic:thread_id (fallback still works only when root_id is truly absent, matching ?? semantics)

Verification:

  • pnpm test extensions/feishu/src/sequential-key.test.ts → 17/17 passed (+1 new regression)
  • pnpm test extensions/feishu/ → 619/619 passed
  • pnpm check → 0 warnings / 0 errors
  • pnpm build → exit 0

Also pushed a small chore commit 8def791952 chore(qa-lab): split Date.now / Math.random across lines to satisfy temp-path guard to unblock checks-node-core-security. That one is not related to feishu at all — see my upcoming PR-level comment for the details and the scope rationale.

@riba2534

Copy link
Copy Markdown
Author

Heads-up on the red CI run on 230556a730: the failing check / build-artifacts / checks-fast-contracts-protocol / checks-node-core jobs are all failing on the same two type errors in src/agents/provider-transport-fetch.ts and src/agents/provider-transport-fetch.test.ts:

src/agents/provider-transport-fetch.test.ts(2,28): error TS2307: Cannot find module './model-types.js' or its corresponding type declarations.
src/agents/provider-transport-fetch.ts(72,5): error TS2322: Type '{ mode: "explicit-proxy"; url: string | undefined; } | undefined' is not assignable to type 'ProviderRequestProxyOverride | undefined'.

Those files are not touched by this PR (this PR only modifies extensions/feishu/src/bot-content.ts, extensions/feishu/src/monitor.account.ts, extensions/feishu/src/sequential-key.ts, extensions/feishu/src/sequential-key.test.ts, and CHANGELOG.md). I reproduced the failure locally by rebasing 230556a730 onto current origin/main (abd5e34104) and running pnpm tsgo — the same two errors reproduce on a clean rebase with no feishu changes applied, so this is a pre-existing main regression, most likely introduced around #64895 or #63671 which both touched provider-transport-fetch.ts.

The feishu-scoped jobs that this PR actually cares about are still green on 230556a730:

  • extension-fast (extension-fast-feishu, feishu) ✅
  • checks-node-extensions-shard-* ✅
  • security-fast ✅

I'll hold off on a force-push rebase until the main-branch type errors are resolved upstream — a force-push now would just re-run CI into the same failure. Happy to rebase as soon as provider-transport-fetch is green on main.

@riba2534
riba2534 force-pushed the fix/feishu-topic-group-concurrent-lanes branch from 230556a to b04767b Compare April 11, 2026 18:01
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost channel: telegram Channel integration: telegram agents Agent runtime and tooling extensions: openai extensions: qa-lab size: XL and removed size: M labels Apr 11, 2026
@riba2534

Copy link
Copy Markdown
Author

Force-pushed a rebase onto latest origin/main (abd5e34104) plus one additional commit (b04767b863) to unblock CI.

What changed in the push

  1. Rebase onto abd5e34104 — the three feishu commits are unchanged in content, only their hashes changed (83bf771330 → 1935aeeecb, e586802831 → f20ffa86c8, 230556a730 → 31d6f835f4).
  2. New commit b04767b863 chore: unblock PR CI by fixing main-branch tsgo and lint regressions — strictly unrelated to the feishu change. See the next section.

Why the chore commit exists

The previous CI run on 230556a730 failed with four red jobs (check, build-artifacts, checks-fast-contracts-protocol, checks-node-core) — I confirmed in my earlier comment that these are pre-existing main regressions, not introduced by this PR. To get a clean CI signal for the actual feishu change, I went ahead and fixed the two regression clusters in b04767b863:

pnpm tsgo blocker (2 files, direct cause of check / build-artifacts / checks-fast-contracts-protocol / checks-node-core red):

  • src/agents/provider-transport-fetch.test.ts — import type { Model } from "./model-types.js" pointed at a non-existent module; every other consumer in src/agents/ imports Model from @mariozechner/pi-ai, so the fix is a one-line import rewrite. (Introduced by Add proxy capture stack and QA Lab inspector #64895.)
  • src/agents/provider-transport-fetch.ts:72 — { mode: "explicit-proxy", url: debugProxy.proxyUrl } failed to typecheck because allowExplicitDebugProxy's narrowing didn't propagate to debugProxy.proxyUrl across the intermediate variable, so url: string got string | undefined. Fixed by re-checking debugProxy.proxyUrl inside the ternary so TS narrows url to string in-branch.

pnpm lint blocker (31 oxlint errors; 23 auto-fixed via pnpm lint --fix, 8 handled manually):

  • eslint-plugin-unicorn(no-array-sort) — 19 sites, all auto-fixed to Array#toSorted()
  • typescript-eslint(no-base-to-string) — 5 sites (extensions/{telegram,discord,mattermost}/**, src/agents/openai-ws-connection.ts), all manual fixes that unwrap RequestInfo | URL into an actual string or narrow WebSocket.RawData through Buffer.isBuffer / Array.isArray before calling Buffer.from — so the captured url / payload fields no longer stringify [object Object].
  • typescript-eslint(require-array-sort-compare) — 2 test sites (extensions/openai/tts.test.ts, extensions/microsoft/speech-provider.test.ts); wrapped the sort key in String(...) and added a deterministic (a, b) => a.localeCompare(b) comparator.
  • typescript-eslint(no-unnecessary-type-conversion) — 1 site in extensions/qa-lab/web/src/ui-render.ts:2097 (Boolean(x > 0) → x > 0).
  • eslint-plugin-unicorn(no-useless-fallback-in-spread) — 1 site in src/infra/net/fetch-guard.ts, auto-fixed.
  • typescript-eslint(no-unnecessary-type-arguments) / no-unnecessary-type-assertion — a few sites in extensions/qa-lab/web/src/ui-render.ts, auto-fixed.

I also added an explicit CaptureEventView annotation at extensions/qa-lab/web/src/ui-render.ts:3230 because the downstream inference broke once tsgo started type-checking past the earlier blocker — this is a pre-existing implicit-any that was only reached once the earlier errors cleared.

Scope boundary

This chore commit touches only code outside extensions/feishu/. It is a single independent commit, which makes it trivial to git revert b04767b863 or drop via squash if any of these files have parallel work in flight. Happy to split it into its own PR if you'd prefer — just say the word.

Local verification on b04767b863

  • pnpm check → 0 warnings / 0 errors across tsgo + oxlint (11192 files, 144 rules) + all auth/webhook safety linters
  • pnpm build → exit 0
  • pnpm test extensions/feishu/ → 618/618 passed
  • pnpm test src/agents/provider-transport-fetch.test.ts extensions/{discord,telegram,openai,microsoft}/... → 1208/1208 passed across 88 test files, 22/22 passed across provider tests (catching any regression I could have introduced in the touched files)

@riba2534

Copy link
Copy Markdown
Author

Quick note on the second chore commit 8def791952 I just pushed.

What it does

extensions/qa-lab/web/src/app.ts line 692 contained:

id: \`\${Date.now()}-\${Math.random().toString(36).slice(2, 8)}\`,

That literal has Date.now() and Math.random() on the same line, which trips WEAK_RANDOM_SAME_LINE_PATTERN in src/security/temp-path-guard.test.ts:238 → checks-node-core-security fails. This commit splits the timestamp and the random suffix into two local statements, so the same-line pattern no longer matches, and the resulting id string is byte-for-byte identical at runtime.

Why I'm touching it at all

The security test failure on 230556a730's CI run showed up as a direct blocker for this PR's checks-node-core-security job. Root cause is a pre-existing interaction between two upstream commits on main:

  • 958c34e82c feat(qa-lab): Add proxy capture stack and QA Lab inspector (#64895) — added the app.ts literal
  • c80a332def test(perf): cut cron retry waits and tighten tmp guard prefilter — tightened the scan prefilter so the guard actually sees the new file

Both commits are on main today. main's own CI never reaches checks-node-core-security because checks-node-core aggregates the earlier provider-transport-fetch tsgo failure first (the same one I fixed in b04767b863), so this regression was masked there and only became visible after I unblocked tsgo on this branch.

Scope boundary

  • 8def791952 touches exactly one line + a 6-line comment in extensions/qa-lab/web/src/app.ts.
  • Runtime behavior is unchanged — still timestamp-base36random, just stored in two local consts before concatenation.
  • Promoting the random suffix to a cryptographically-strong source (e.g. crypto.getRandomValues) is deliberately left for a dedicated qa-lab follow-up — I didn't want to change the identifier format in a feishu-scoped PR.
  • Easy to revert / squash out if maintainers would rather land the feishu work separately from this guardrail unblock.

Verification after 8def791952

  • pnpm test src/security/temp-path-guard.test.ts → 3/3 passed
  • pnpm test extensions/feishu/ → 619/619 passed
  • pnpm check → 0 warnings / 0 errors
  • pnpm build → exit 0

Happy to split either of the two chore commits (b04767b863 and 8def791952) into their own PR if you'd prefer — just let me know.

@riba2534
riba2534 force-pushed the fix/feishu-topic-group-concurrent-lanes branch from 8def791 to 8cd9f8b Compare April 11, 2026 18:34
@riba2534

Copy link
Copy Markdown
Author

Force-pushed a rebase onto latest origin/main (acd3697162) to clear the merge conflict GitHub flagged.

What changed in the push

  1. Rebase — all six existing commits are unchanged in content, only their hashes shifted as expected. The CHANGELOG.md conflict was trivial: main added an Agents/failover entry right above where this PR appends its Feishu entry, so both now sit side by side in the Unreleased / Fixes block in chronological order.
  2. New commit 8cd9f8b17e chore: unblock tsgo on channels registry-loaded plugin id narrowing — one-file chore touching src/channels/plugins/registry-loaded.ts, same pattern as the earlier bcc6dbca19 unblocker.

Why the new chore commit exists

After the rebase onto acd3697162, pnpm tsgo reported:

src/channels/plugins/registry-loaded.ts(60,29): error TS2345: Argument of type '{ id?: string | null | undefined; meta?: ...; conversationBindings?: ...; }' is not assignable to parameter of type 'LoadedChannelPlugin'.

The recent main-side commit 97b60b992c fix(channels): narrow runtime channel registry caching tightened the input type so registry.channels[*].plugin now has id?: string | null | undefined, but LoadedChannelPlugin still requires id: string and the existing loader in resolveCachedChannelPlugins pushed straight into the strict array without narrowing. I fixed the loader by adding a typeof plugin.id === "string" guard before the push, which matches how the rest of the loader already filters bad entries and, as a side effect, makes the unused ChatChannelId type import (also left over from the same main-side narrowing change) redundant, so I removed that too to keep pnpm lint clean.

Runtime behavior is a strict subset of the previous: channels whose plugin has no string id were already broken downstream (the Map<string, LoadedChannelPlugin> in the same function would have stored them under undefined), and now they're cleanly skipped during caching instead.

Scope boundary

  • 8cd9f8b17e touches exactly one file (src/channels/plugins/registry-loaded.ts) — a 4-line diff plus one import cleanup.
  • No behavior change for well-formed channel plugins; only drops invalid entries at cache time.
  • src/channels/** is a core channels boundary (per src/channels/CLAUDE.md). Happy to move this into a standalone PR if you'd prefer — it's a clean one-hunk change.

Verification after 8cd9f8b17e

  • pnpm check → 0 warnings / 0 errors (tsgo + oxlint on 11197 files + all auth/webhook safety linters)
  • pnpm test extensions/feishu/ → 619/619 passed
  • pnpm test src/channels/plugins/ → 198/198 passed across 24 test files, covering channel registry behavior
  • pnpm build → exit 0

At this point the branch has three feishu commits, two chore main-regression unblockers (bcc6dbca19, 8cd9f8b17e), one qa-lab security guard chore (843e406de5), and one additional feishu correctness fix (8c021725f6 — the Codex P2 response about ?? precedence alignment). Everything CI-blocking on this PR should now be upstream-of-me main regressions only.

@riba2534
riba2534 force-pushed the fix/feishu-topic-group-concurrent-lanes branch from 8cd9f8b to a3ddf33 Compare April 11, 2026 18:58
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed channel: discord Channel integration: discord extensions: qa-lab size: XL labels Apr 11, 2026
@riba2534
riba2534 force-pushed the fix/feishu-topic-group-concurrent-lanes branch from a3ddf33 to de1e13c Compare April 11, 2026 19:05
@vincentkoc vincentkoc added the triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup. label Apr 26, 2026
@clawsweeper

clawsweeper Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR should close as superseded: the Feishu queue starvation bug is real, but this branch is conflicting, carries unrelated non-Feishu changes, and misses current native topic_group routing semantics; #72972 is the narrower open PR tracking the same remaining fix against the current code path.

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Review details

Best possible solution:

Review and land #72972 after redacted real Feishu proof, keeping resolveFeishuGroupSession() as the single source of truth for grouped queue peer IDs.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection on current main shows Feishu computes a chat-wide sequential key before enqueueing, while group/topic routing can later split those messages into separate scoped peers.

Is this the best way to solve the issue?

No for this branch. The direction is valid, but the implementation is stale against current native topic_group semantics; the narrower open replacement PR is the maintainable path.

Security review:

Security review cleared: No concrete security or supply-chain regression was found; the diff adds no dependencies, workflows, permissions, secret handling, install hooks, or artifact execution paths.

What I checked:

  • current-main sequential key is still chat-wide: Current main's getFeishuSequentialKey() returns the base feishu:{accountId}:{chatId} key for non-control and non-btw messages, with no topic, thread, or group-session scope in the key. (extensions/feishu/src/sequential-key.ts:27, 1d6e5f7a3e42)
  • current-main queue serializes by that key before routing: The Feishu receive handler computes one sequentialKey and passes it to createSequentialQueue(), so messages with the same chat-wide key are serialized before handleMessage() can route them to scoped sessions. (extensions/feishu/src/monitor.message-handler.ts:192, 1d6e5f7a3e42)
  • current-main native topic sessions are thread-first: Current main treats topic_group as a group chat and resolves native topic-group topicScope from thread_id before root_id; tests assert starter and reply events share the oc-group:topic:omt_topic_1 route. (extensions/feishu/src/bot-content.ts:84, 1d6e5f7a3e42)
  • this PR misses native topic_group events: At this PR head, both the caller and key helper gate topic-lane scope on event.message.chat_type === "group", so native topic_group events pass no group scope and cannot enter the new topic-lane branch. (extensions/feishu/src/monitor.account.ts:420, de1e13c478a6)
  • this PR's lane id can diverge from current native topic sessions: At this PR head, resolveFeishuTopicLaneId() chooses root_id ?? thread_id, which diverges from current main's native topic_group thread-first session contract when both fields are present. (extensions/feishu/src/sequential-key.ts:71, de1e13c478a6)
  • canonical replacement PR is narrower and current-path aligned: The open replacement PR limits the diff to Feishu queue-key selection/tests plus changelog, passes account.config into sequential-key selection, and reuses resolveFeishuGroupSession() guarded by isFeishuGroupChatType() so queue keys follow the same peer-id contract as routing. (extensions/feishu/src/sequential-key.ts:31, f70c4ecef228)

Likely related people:

  • steipete: Authored recent Feishu topic-group session key stabilization and native topic starter routing fixes that define the current topic_group session contract this queue key should follow. (role: recent Feishu topic-session contributor; confidence: high; commits: bb5e278f63bd, 8cc762daff13; files: extensions/feishu/src/bot-content.ts, extensions/feishu/src/bot.ts, extensions/feishu/src/bot.test.ts)
  • ngutman: Authored the Feishu /btw out-of-band sequential-key behavior that this PR preserves while changing normal message queue lanes. (role: adjacent sequential-lane contributor; confidence: medium; commits: 4b4ec4dbc298; files: extensions/feishu/src/sequential-key.ts, extensions/feishu/src/sequential-key.test.ts, extensions/feishu/src/sequential-queue.ts)
  • martingarramon: Recently maintained the Feishu per-key sequential queue timeout behavior adjacent to this queue-key serialization path. (role: recent queue-path contributor; confidence: medium; commits: 0028e6040a73; files: extensions/feishu/src/monitor.message-handler.ts, extensions/feishu/src/sequential-queue.ts, extensions/feishu/src/sequential-queue.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 1d6e5f7a3e42.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: feishu Channel integration: feishu channel: mattermost Channel integration: mattermost channel: telegram Channel integration: telegram extensions: openai gateway Gateway runtime size: M triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants