Skip to content

fix(telegram): prioritize topic-level requireMention over activation override#49980

Merged
steipete merged 1 commit intoopenclaw:mainfrom
Panniantong:fix/telegram-topic-require-mention
May 4, 2026
Merged

fix(telegram): prioritize topic-level requireMention over activation override#49980
steipete merged 1 commit intoopenclaw:mainfrom
Panniantong:fix/telegram-topic-require-mention

Conversation

@Panniantong
Copy link
Copy Markdown
Contributor

Summary

Per-topic requireMention override is ignored in Telegram forum supergroups — group-level setting always wins.

Fixes #49864

Root Cause

In bot-message-context.ts, the requireMention resolution chain used firstDefined() with this order:

const requireMention = firstDefined(
    activationOverride,          // from /activate /deactivate session state
    topicConfig?.requireMention, // topic-level config — NEVER REACHED
    groupConfig?.requireMention, // group-level config
    baseRequireMention,          // channel default
);

activationOverride (persisted from /activate or /deactivate commands) was evaluated before topicConfig?.requireMention, so any persisted activation state would override explicit per-topic config.

Fix

Reorder firstDefined() so topic config is evaluated first:

const requireMention = firstDefined(
    topicConfig?.requireMention,  // topic config always wins
    activationOverride,           // then runtime activation
    groupConfig?.requireMention,
    baseRequireMention,
);

Testing

Added 4 new tests in a dedicated test file:

  1. Topic requireMention=false overrides group requireMention=true
  2. Topic config overrides activationOverride
  3. Group-level requireMention still works when no topic config
  4. activationOverride still works when no topic config

All 4 tests pass.

Made-with: Claude Code (Claude Opus 4.6)

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S labels Mar 18, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 18, 2026

Greptile Summary

This PR fixes a bug in Telegram forum supergroups where per-topic requireMention configuration was silently ignored whenever an activation state (/activate or /deactivate) had been set, because activationOverride appeared first in the firstDefined() chain. The fix is a two-line reorder that moves topicConfig?.requireMention to the head of the chain, giving it the highest priority.

Key changes:

  • bot-message-context.ts: Swaps the order of topicConfig?.requireMention and activationOverride in the firstDefined() call (lines 255–260). Semantically, this means that once a topic has an explicit requireMention value configured, /activate and /deactivate commands will have no effect for that topic — a deliberate and clearly-intended trade-off.
  • bot-message-context.topic-require-mention.test.ts: Adds four new tests covering topic-overrides-group, topic-overrides-activation, group-only, and activation-only scenarios. The test suite is missing the symmetric case where topicConfig.requireMention=true should resist an activationOverride=false (i.e., /activate cannot bypass an explicit topic restriction).

Confidence Score: 5/5

  • Safe to merge — the change is a minimal, well-understood two-line reorder with direct test coverage for the bugfix.
  • The fix is surgically small (two lines swapped), the root cause analysis in the PR description is accurate, three of the four priority-chain positions are already covered by tests, and no other logic is affected. The one missing test (topic=true beats activationOverride=false) is a coverage gap rather than an indication of incorrect implementation.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/telegram/src/bot-message-context.topic-require-mention.test.ts
Line: 96-111

Comment:
**Missing inverse priority test case**

The four tests only verify that `topicConfig.requireMention=false` wins over various higher-priority items. There's no test covering the symmetric case: `topicConfig.requireMention=true` overriding `activationOverride=false` (i.e., a user running `/activate` in a topic that has `requireMention=true` configured).

With the new ordering, the `/activate` command should be silently ignored for that topic, and a message without a `@mention` should still be dropped (return `null`). It would be worth adding a test to confirm this behavior is intentional and doesn't regress:

```typescript
it("topic requireMention=true overrides activationOverride=false (/activate ignored)", async () => {
  const ctx = await buildTelegramMessageContextForTest({
    message: buildForumMessage(),
    // activationOverride=false → /activate was run (meaning requireMention=false)
    resolveGroupActivation: () => false,
    resolveGroupRequireMention: () => false,
    resolveTelegramGroupConfig: () => ({
      groupConfig: { requireMention: false },
      topicConfig: { requireMention: true },
    }),
  });

  // Topic says requireMention=true; /activate override should not bypass it.
  expect(ctx).toBeNull();
});
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(telegram): prior..."

Comment on lines +96 to +111
it("activationOverride still works when no topic config is present", async () => {
const ctx = await buildTelegramMessageContextForTest({
message: buildForumMessage(),
// activationOverride=false → requireMention=false (from /activate)
resolveGroupActivation: () => false,
resolveGroupRequireMention: () => true,
resolveTelegramGroupConfig: () => ({
groupConfig: { requireMention: true },
topicConfig: undefined,
}),
});

// No topic config, but activation override says requireMention=false →
// message should be processed.
expect(ctx).not.toBeNull();
});
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 Missing inverse priority test case

The four tests only verify that topicConfig.requireMention=false wins over various higher-priority items. There's no test covering the symmetric case: topicConfig.requireMention=true overriding activationOverride=false (i.e., a user running /activate in a topic that has requireMention=true configured).

With the new ordering, the /activate command should be silently ignored for that topic, and a message without a @mention should still be dropped (return null). It would be worth adding a test to confirm this behavior is intentional and doesn't regress:

it("topic requireMention=true overrides activationOverride=false (/activate ignored)", async () => {
  const ctx = await buildTelegramMessageContextForTest({
    message: buildForumMessage(),
    // activationOverride=false → /activate was run (meaning requireMention=false)
    resolveGroupActivation: () => false,
    resolveGroupRequireMention: () => false,
    resolveTelegramGroupConfig: () => ({
      groupConfig: { requireMention: false },
      topicConfig: { requireMention: true },
    }),
  });

  // Topic says requireMention=true; /activate override should not bypass it.
  expect(ctx).toBeNull();
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/telegram/src/bot-message-context.topic-require-mention.test.ts
Line: 96-111

Comment:
**Missing inverse priority test case**

The four tests only verify that `topicConfig.requireMention=false` wins over various higher-priority items. There's no test covering the symmetric case: `topicConfig.requireMention=true` overriding `activationOverride=false` (i.e., a user running `/activate` in a topic that has `requireMention=true` configured).

With the new ordering, the `/activate` command should be silently ignored for that topic, and a message without a `@mention` should still be dropped (return `null`). It would be worth adding a test to confirm this behavior is intentional and doesn't regress:

```typescript
it("topic requireMention=true overrides activationOverride=false (/activate ignored)", async () => {
  const ctx = await buildTelegramMessageContextForTest({
    message: buildForumMessage(),
    // activationOverride=false → /activate was run (meaning requireMention=false)
    resolveGroupActivation: () => false,
    resolveGroupRequireMention: () => false,
    resolveTelegramGroupConfig: () => ({
      groupConfig: { requireMention: false },
      topicConfig: { requireMention: true },
    }),
  });

  // Topic says requireMention=true; /activate override should not bypass it.
  expect(ctx).toBeNull();
});
```

How can I resolve this? If you propose a fix, please make it concise.

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 28, 2026

Codex review: needs maintainer review before merge.

Summary
The branch reorders Telegram requireMention resolution to prefer explicit topic settings over persisted activation state, adds targeted precedence tests, and adds a changelog entry.

Reproducibility: yes. Source inspection gives a high-confidence path: current main resolves activationOverride before topicConfig?.requireMention, and the inbound body gate drops unmentioned group messages when that resolved value is true.

Next step before merge
No repair job is needed because the current head already includes the previously requested changelog entry and inverse regression test; the remaining path is normal PR merge gating.

Security
Cleared: The diff only changes Telegram mention-precedence logic, tests, and changelog text, with no dependency, workflow, secret, install, release, or downloaded-code surface.

Review details

Best possible solution:

Land this focused Telegram plugin patch after normal CI or changed-gate validation, keeping the explicit topic config precedence and closing the linked #49864 through the PR.

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

Yes. Source inspection gives a high-confidence path: current main resolves activationOverride before topicConfig?.requireMention, and the inbound body gate drops unmentioned group messages when that resolved value is true.

Is this the best way to solve the issue?

Yes. Moving topicConfig?.requireMention ahead of activationOverride is the narrowest maintainable fix because topic config is already resolved before gating and docs already define topic-level overrides.

What I checked:

Likely related people:

  • steipete: GitHub commit metadata links this handle to the original topic requireMention support, the Telegram session activation override behavior, and repeated recent maintenance in the Telegram message-context path. (role: introduced behavior and recent maintainer; confidence: high; commits: 1011640a1310, 4bd7ca305a92, 550b9466969a; files: extensions/telegram/src/bot-message-context.ts, extensions/telegram/src/bot-core.ts, extensions/telegram/src/bot.create-telegram-bot.test.ts)
  • kesor: Commit history credits this handle with adding Telegram per-topic agent routing and docs, which is adjacent to the topic config surface involved in this precedence fix. (role: topic-routing feature contributor; confidence: medium; commits: 58bc9a241b7e; files: extensions/telegram/src/bot-message-context.ts, extensions/telegram/src/bot-message-context.topic-agentid.test.ts, docs/channels/telegram.md)
  • obviyus: Recent history includes tightening Telegram topic-agent docs and fallback tests, plus adjacent Telegram topic/cache work in the same plugin area. (role: adjacent test/docs maintainer; confidence: medium; commits: f74a04e4ba99, c91d3d4537f3, 4f92b1fbb0b5; files: extensions/telegram/src/bot-message-context.ts, extensions/telegram/src/bot-core.ts, docs/channels/telegram.md)

Remaining risk / open question:

  • No local test command was run because this review was constrained to read-only inspection; normal CI or the changed gate should still run before merge.

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

Re-review progress:

@steipete steipete force-pushed the fix/telegram-topic-require-mention branch from e84f7bf to e911455 Compare May 4, 2026 21:43
@steipete steipete merged commit a7b665c into openclaw:main May 4, 2026
102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Per-topic requireMention override is ignored — group-level setting always wins

2 participants