Skip to content

fix/telegram-context-controls#83633

Closed
MetaRed0401 wants to merge 9 commits into
openclaw:mainfrom
MetaRed0401:fix/telegram-context-controls
Closed

fix/telegram-context-controls#83633
MetaRed0401 wants to merge 9 commits into
openclaw:mainfrom
MetaRed0401:fix/telegram-context-controls

Conversation

@MetaRed0401

@MetaRed0401 MetaRed0401 commented May 18, 2026

Copy link
Copy Markdown

Summary

  • Problem: Telegram DM context assembly used a hardcoded recent history limit of 10, and the Conversation Context block was injected without a config-level control.
  • Why it matters: Telegram DM could include prior user messages in the current agent input, unlike the expected behavior observed in Discord DM where only the current user message is delivered.
  • What changed: Added Telegram configuration options to control DM history injection and Conversation Context injection.
  • What did NOT change (scope boundary): Existing behavior is preserved by default. If the new options are not set, the previous hardcoded history limit of 10 remains the default, and Conversation Context injection remains enabled.

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

Real behavior proof (required for external PRs)

External contributors must show after-fix evidence from a real OpenClaw setup. Unit tests, mocks, lint, typechecks, snapshots, and CI are supplemental only. Screenshots are encouraged even for CLI, console, text, or log changes; terminal screenshots and copied live output count. Be mindful of private information like IP addresses, API keys, phone numbers, non-public endpoints, or other private details when providing evidence.

  • Behavior or issue addressed:

    • Telegram DM context assembly could inject prior recent messages and the Conversation Context block into the current agent input.
    • The recent DM history limit was hardcoded to 10.
    • There was no config-level control to disable the Conversation Context block.
  • Real environment tested:

    • OS: Linux Host
    • OpenClaw version: main as of 2026-05-17
    • Runtime/container: Host runtime, built locally from source
    • Integration/channel: Telegram DM
    • Relevant config:
      • channels.telegram.dmRecentLimit: 0
      • channels.telegram.conversationContext: false
  • Exact steps or command run after this patch:

    1. Built OpenClaw locally from the patched source.
    2. Started OpenClaw with Telegram DM configured.
    3. Set channels.telegram.dmRecentLimit to 0.
    4. Set channels.telegram.conversationContext to false.
    5. Sent a Telegram DM message to the agent.
    6. Verified that only the current user message was delivered, matching the expected behavior observed in Discord DM.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):

    • Screenshot attached to this PR.
  • Observed result after fix:

    • Telegram DM delivered only the current user message.
    • Previous Telegram DM history was not injected.
    • The Conversation Context block was not injected.
    • This matches the expected behavior observed in Discord DM.
  • What was not tested:

    • Telegram group/channel behavior was not manually verified.
    • Non-Telegram integrations were not manually verified beyond the Discord DM comparison.
  • Before evidence (optional but encouraged):

    • Screenshot attached if available.

Root Cause (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause:

    • Telegram DM context assembly used a hardcoded recent history limit of 10 and always injected the Conversation Context block.
  • Missing detection / guardrail:

    • There was no config-level guardrail to tune or disable Telegram DM history/context injection.
  • Contributing context (if known):

    • The original behavior is preserved by default.
    • This PR follows the existing implementation rule and only exposes configuration controls for operators.

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write N/A.

  • Coverage level that should have caught this:

    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file:

    • Context/config assembly tests for Telegram DM history and conversation context behavior.
  • Scenario the test should lock in:

    • Default config preserves the existing recent DM history limit of 10.
    • channels.telegram.dmRecentLimit: 0 disables Telegram DM history injection.
    • channels.telegram.conversationContext: false disables Conversation Context injection.
    • Configured behavior applies without changing other channel defaults.
  • Why this is the smallest reliable guardrail:

    • The behavior is determined at the Telegram DM context assembly/config boundary, so validating that boundary is enough to catch regressions without requiring a full Telegram network E2E test.
  • Existing test that already covers this (if any):

    • None known.
  • If no new test is added, why not:

    • Manual verification was performed against a real Telegram DM setup. Automated coverage should be added at the Telegram DM context assembly/config boundary where this behavior is determined.

User-visible / Behavior Changes

Existing defaults are unchanged.

New Telegram config options allow operators to:

  • configure Telegram DM history injection with channels.telegram.dmRecentLimit
  • disable Telegram Conversation Context injection with channels.telegram.conversationContext: false

No migration is required. Existing deployments keep the same behavior unless the new config options are explicitly set.

Diagram (if applicable)

Before:
[Telegram DM user message]
  -> [Telegram DM context assembly]
  -> [hardcoded 10 recent DM messages + Conversation Context injected]
  -> [agent input]

After:
[Telegram DM user message]
  -> [Telegram DM context assembly]
  -> [Telegram config checked]
  -> [configured DM history + optional Conversation Context injection]
  -> [agent input]

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): Yes
  • If any Yes, explain risk + mitigation:
    • The amount of Telegram DM history and conversation context injected into the agent input is now configurable.
    • Defaults preserve existing behavior.
    • Operators can reduce injected context by setting channels.telegram.dmRecentLimit.
    • Operators can disable the Conversation Context block with channels.telegram.conversationContext: false.

Repro + Verification

Environment

  • OS: Linux Host
  • Runtime/container: Host runtime, built locally from source
  • Model/provider: N/A
  • Integration/channel (if any): Telegram DM
  • Relevant config (redacted):
    • channels.telegram.dmRecentLimit: 0
    • channels.telegram.conversationContext: false

Steps

  1. Build OpenClaw locally from the patched source.
  2. Start OpenClaw with Telegram DM configured.
  3. Set channels.telegram.dmRecentLimit to 0.
  4. Set channels.telegram.conversationContext to false.
  5. Send a Telegram DM message to the configured agent.
  6. Compare the resulting agent input with the expected Discord DM behavior.

Expected

  • Telegram DM should deliver only the current user message when channels.telegram.dmRecentLimit: 0.
  • Telegram DM should not inject the Conversation Context block when channels.telegram.conversationContext: false.
  • The result should match the expected Discord DM behavior where only the current user message is delivered.

Actual

  • OpenClaw built successfully from patched source.
  • With channels.telegram.dmRecentLimit: 0, Telegram DM history was not injected.
  • With channels.telegram.conversationContext: false, the Conversation Context block was not injected.
  • Telegram DM input contained only the current user message, matching the expected Discord DM behavior.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:

    • Built OpenClaw from patched source.
    • Sent a real Telegram DM to the configured agent.
    • Verified channels.telegram.dmRecentLimit: 0 disables Telegram DM history injection.
    • Verified channels.telegram.conversationContext: false disables the Conversation Context block.
    • Verified the resulting Telegram DM behavior matches Discord DM behavior where only the current user message is delivered.
    • Verified that leaving the new options unset preserves the original default behavior, including the previous history limit of 10.
  • Edge cases checked:

    • Missing config uses existing defaults.
    • The previous hardcoded limit of 10 remains the default.
    • Setting channels.telegram.dmRecentLimit: 0 disables Telegram DM history injection.
    • Setting channels.telegram.conversationContext: false disables the Conversation Context block.
  • What you did not verify:

    • Telegram group/channel behavior.
    • All non-Telegram integrations.

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.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): Yes
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps:
    • No migration is required.
    • Existing deployments keep the same behavior unless the new config options are explicitly set.
    • If the new options are not set, Telegram DM history continues to use the previous default limit of 10 and Conversation Context injection remains enabled.

Risks and Mitigations

  • Risk:

    • Operators may set a larger Telegram DM history limit than necessary, increasing token usage or exposing more prior conversation context to the model.
    • Mitigation:
      • Existing default remains 10.
      • Operators can reduce the value or set it to 0 when Telegram DM history injection is not desired.
  • Risk:

    • Disabling Telegram Conversation Context injection may reduce continuity for some Telegram DM conversations.
    • Mitigation:
      • The setting is opt-in.
      • Existing behavior remains enabled by default.

AI Assistance Disclosure

AI-assisted: Used Codex for implementation assistance and ChatGPT for PR wording/review planning. I manually reviewed the code, built OpenClaw locally, and verified the behavior in a real Telegram DM setup.

스크린샷 2026-05-18 231144 스크린샷 2026-05-18 231151

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram size: M proof: supplied External PR includes structured after-fix real behavior proof. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

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

Close as superseded: the Telegram DM duplicate-context problem is real, but a newer clean, proof-positive PR now tracks the narrower default-behavior fix while this branch is conflicted and adds broader public config semantics.

Canonical path: Follow #89855 for the default duplicate-DM context fix, and open a fresh product-approved config PR only if maintainers still want public Telegram context controls afterward.

So I’m closing this here and keeping the remaining discussion on #89855 and #87566.

Review details

Best possible solution:

Follow #89855 for the default duplicate-DM context fix, and open a fresh product-approved config PR only if maintainers still want public Telegram context controls afterward.

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

Yes. Source inspection shows current main and v2026.6.6 still build Telegram chat-window context with recentLimit: 10, and the PR screenshots show the before/after prompt-content behavior for the opt-out path.

Is this the best way to solve the issue?

No, this branch is no longer the best landing path. The newer clean PR fixes the default persistent-DM duplication at the session-aware boundary without adding public config keys, while this PR is conflicted and broader than needed.

Security review:

Security review cleared: No concrete security or supply-chain regression was found; the relevant concern is the intentional prompt-data exposure boundary, handled as merge risk.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • sweetcornna: Authored the newer open, clean, proof-sufficient PR that closes the canonical Telegram DM duplicate-context issue without adding the broader config surface. (role: canonical follow-up implementer; confidence: high; commits: d68002acdcaa; files: extensions/telegram/src/bot-message-context.session.ts, extensions/telegram/src/bot-message-context.prompt-context.test.ts, extensions/telegram/src/bot-message-context.test-harness.ts)
  • jalehman: Authored and merged the current-main session-accessor refactor that touched the Telegram handler and is one reason this older branch is now conflicting. (role: recent area contributor; confidence: medium; commits: f1b8827d20c8; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot.ts, extensions/telegram/src/bot-deps.ts)
  • ragesaq: Current blame on the Telegram prompt-context builder and untrusted-context forwarding lines points to this recent rewrite of the same affected code path. (role: current prompt-context line author; confidence: medium; commits: a15427d605fe; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-context.session.ts)
  • obviyus: The same blame sample shows Ayaan Zaidi as committer for the current prompt-context rewrite, making this a useful routing signal for the current behavior. (role: current prompt-context committer; confidence: medium; commits: a15427d605fe; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-context.session.ts)

Codex review notes: model internal, reasoning high; reviewed against f1b8827d20c8.

@MetaRed0401

Copy link
Copy Markdown
Author

Small correction: I used the wrong config option name in the PR description.

The correct option is:

  • channels.telegram.dmRecentLimit

I updated the PR description to match the actual implementation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 18, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared May 18, 2026 14:35 Inactive
@openclaw-mantis

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis did not generate before/after GIFs because this PR does not have a clean Telegram-visible before/after proof in the standard Mantis run.

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-83633/run-26040135946-1/index.json

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@MetaRed0401

MetaRed0401 commented May 18, 2026

Copy link
Copy Markdown
Author

Addressed the default-contract mismatch in docs.

The runtime behavior was already preserving compatibility:

  • unset channels.telegram.dmRecentLimit preserves the previous default of 10
  • channels.telegram.dmRecentLimit: 0 explicitly disables Telegram DM recent context injection

This follow-up only corrects the documented default to match runtime behavior.

Validation:

  • Documentation-only change
  • No runtime code changed
  • No test behavior changed
  • git diff --check passed

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 18, 2026
@MetaRed0401

Copy link
Copy Markdown
Author

Security boundary note:

This PR does not add new permissions, network calls, token handling, or command/tool execution surface.

The only data-access behavior changed is that Telegram DM context injection can now be reduced or disabled by config. Defaults preserve the previous behavior.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 19, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels May 19, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 21, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Mossy Patch Peep

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: sniffs out flaky tests.
Image traits: location status garden; accessory proof snapshot camera; palette sunrise gold and clean white; mood bright-eyed; pose curling around a status light; shell paper lantern shell; lighting warm desk-lamp glow; background quiet workflow signs.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Mossy Patch Peep in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly carries PR A's core remaining behavior fix for duplicate Telegram DM context and is the better/current canonical landing path. PR A's broader public config controls are intentionally not part of the canonical fix and, per the source report, would require a separate product-approved proposal rather than independent review of PR A. Covering PR: fix(telegram): avoid duplicate dm chat window context #89855.

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

Labels

channel: telegram Channel integration: telegram docs Improvements or additions to documentation merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant