Skip to content

fix(telegram): keep group history always on#99143

Merged
obviyus merged 2 commits into
mainfrom
codex/fix-ambient-window
Jul 2, 2026
Merged

fix(telegram): keep group history always on#99143
obviyus merged 2 commits into
mainfrom
codex/fix-ambient-window

Conversation

@obviyus

@obviyus obviyus commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #99142

What Problem This Solves

Ambient group mode (unmentionedInbound: "room_event") runs blind: 74% of room-event turns in a production deployment carried zero conversation context, so the model judged isolated fragments and over-replied. Two mechanisms cause this in extensions/telegram: PR #89547's includeGroupHistoryContext default (mention-only) gates the pending group-history window off for exactly the unmentioned traffic ambient mode exists to observe, and the window lifecycle destructively wipes on every non-room-event turn and on room-event delivery — unrecoverable, since room events are deliberately not session-persisted. The window also never contained user_request messages or the bot's own sends, so even populated windows omitted the conversation happening with the bot.

Why This Change Was Made

Maintainer decision (discussed among maintainers): remove what #89547 added rather than re-default it. The option shipped 2.5 weeks ago (v2026.6.10), conflates prompt-context filtering with ambient-mode viability, and its default silently blinded ambient rooms; historyLimit (including 0 to disable) remains the single knob. The window becomes a rolling window: all group inbound (both event kinds) is recorded at one site, the bot's own outbound sends are recorded self-labeled via an account-scoped recorder registered by the monitor, and the legacy "messages since your last reply" semantics for addressed turns are preserved non-destructively by selecting entries after the last self-entry instead of clearing. Room-event turns receive the full rolling window including the bot's own posts so the model can self-regulate reply frequency. Per the retired-key policy, openclaw doctor --fix strips includeGroupHistoryContext from existing configs — "none" maps to historyLimit: 0 to preserve the privacy intent, and an account-level "recent" under a root "none" pins the account's pre-migration effective limit. The ambient invariants are pinned in extensions/telegram/AGENTS.md so history-gating regressions of this class get caught in review.

User Impact

Ambient-mode agents see recent room activity again and stop treating lone fragments as direct requests — the dominant cause of "the bot chimes in constantly" reports. requireMention deployments keep their existing prompt-history behavior (bounded by historyLimit, watermarked at the bot's last reply). Configs still carrying includeGroupHistoryContext get a doctor warning and a clean --fix migration; no startup break.

Evidence

  • Production diagnosis: 48h transcript tally — 87 room-event turns, 74% zero-context, 6 of 10 unprompted chimes on zero-context turns; pending-window prompt markers dropped to zero after the deployment that first shipped the mention-only default.
  • Regression tests (default config, ambient mode): consecutive silent room events see each other; window survives user_request turns; watermark fold contains only post-reply entries while room events get the full window including self entries; doctor strips the retired key with the "none"historyLimit: 0 mapping; config carrying the retired key does not brick startup.
  • pnpm tsgo:extensions; node scripts/run-vitest.mjs over the 8 touched Telegram test files (502 tests); oxlint clean; pnpm config:channels:check; repo autoreview (branch mode) clean; combined-tree validation with the two sibling PRs: both tsgo lanes + 16 test files + Linux Testbox prompt-snapshot and changed-lanes gates.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram size: XL maintainer Maintainer-authored PR labels Jul 2, 2026
@obviyus obviyus self-assigned this Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 2, 2026, 12:20 PM ET / 16:20 UTC.

Summary
The PR removes Telegram includeGroupHistoryContext, makes group history an always-on rolling window bounded by historyLimit, records inbound and bot outbound group messages, and updates doctor migration, docs, scoped policy, and tests.

PR surface: Source +84, Tests +360, Docs -5, Generated 0, Other 0. Total +439 across 24 files.

Reproducibility: yes. at source level: current main defaults Telegram group history to mention-only, gates pending history on recent, and clears the window after delivery paths. I did not run a live Telegram deployment repro in this read-only review.

Review metrics: 1 noteworthy metric.

  • Telegram config/default surfaces: 1 option removed, 1 doctor migration added, 1 effective prompt-context behavior changed. This matters before merge because the PR retires a shipped Telegram privacy mode and changes upgrade behavior for prior group-history configs.

Stored data model
Persistent data-model change detected: migration/backfill/repair: docs/channels/ambient-room-events.md, migration/backfill/repair: docs/channels/telegram.md, migration/backfill/repair: extensions/telegram/src/doctor-contract.ts, serialized state: extensions/telegram/AGENTS.md, unknown-data-model-change: extensions/telegram/src/doctor-contract.ts, unknown-data-model-change: extensions/telegram/src/doctor.test.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99142
Summary: This PR is the candidate history-window fix for the canonical Telegram ambient-room issue; sibling PRs cover prompt posture and notice leaks, while the earlier merged history-control PR is regression provenance.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Preserve explicit mention-only upgrade behavior, or add visible maintainer approval and focused tests documenting the intentional widening.
  • [P1] Add redacted real Telegram proof, preferably a short Telegram Desktop recording or runtime logs showing ambient context is retained while historyLimit: 0 stays disabled.

Proof guidance:

  • [P1] Needs real behavior proof before merge: No after-fix real Telegram proof was found in the PR body or comments; tests, CI, and production diagnosis are supplemental but do not prove the changed behavior on this latest head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Mantis proof suggestion
Native Telegram proof would materially help verify the visible ambient group behavior and disabled-history boundary before merge. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify ambient group turns retain recent group context while historyLimit: 0 stays disabled.

Risk before merge

  • [P1] Explicit includeGroupHistoryContext: "mention-only" configs can be migrated into always-on recent group history, widening which unmentioned Telegram group messages enter model context.
  • [P1] The PR removes a shipped Telegram config/default and privacy-sensitive prompt-context boundary, so maintainers need visible upgrade-policy approval or a preserving migration before merge.
  • [P1] The PR body lists production diagnosis and tests, but the latest head still lacks after-fix real Telegram proof in the PR body or comments.
  • [P1] The branch base predates current main and the merged sibling ambient-room PRs, so the combined Telegram behavior should be refreshed before landing.

Maintainer options:

  1. Preserve Explicit Mention-Only (recommended)
    Keep an upgrade path for explicit mention-only configs, or add focused tests and visible maintainer approval documenting the intentional widening before retiring the key.
  2. Accept The Widened Context
    Maintainers may intentionally accept always-on group history for prior mention-only users, but the compatibility and privacy tradeoff should be recorded before merge.
  3. Hold For Coordinated Ambient Review
    Pause landing until this branch is rebased with the merged sibling ambient PRs and reviewed as one Telegram room-event behavior change.

Next step before merge

  • [P1] Manual review is needed because the PR has a protected maintainer label, changes a shipped Telegram config/privacy contract, and still needs real behavior proof; ClawSweeper should not queue a competing fix PR.

Security
Needs attention: No dependency or supply-chain issue was found, but the config migration changes a privacy-sensitive Telegram group prompt-context boundary.

Review findings

  • [P1] Preserve explicit mention-only history settings — extensions/telegram/src/doctor-contract.ts:162
Review details

Best possible solution:

Land a coordinated Telegram ambient-history fix only after explicit mention-only upgrade behavior is preserved or visibly approved, the branch is refreshed on current main, and real Telegram proof shows ambient context retention while disabled history stays disabled.

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

Yes, at source level: current main defaults Telegram group history to mention-only, gates pending history on recent, and clears the window after delivery paths. I did not run a live Telegram deployment repro in this read-only review.

Is this the best way to solve the issue?

No, not as currently written. The Telegram-local rolling window is the right layer, but the migration is not the safest fix until explicit mention-only privacy intent is preserved or visibly accepted by maintainers.

Full review comments:

  • [P1] Preserve explicit mention-only history settings — extensions/telegram/src/doctor-contract.ts:162
    This migration only preserves none; an explicit includeGroupHistoryContext: "mention-only" config is dropped and becomes always-on recent group history. That silently widens group messages sent to model context for operators who chose the shipped privacy mode, so keep a compatibility path or require visible maintainer approval plus focused upgrade tests before retiring it.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR targets an active Telegram ambient-room regression affecting real group-agent behavior and changes a shipped privacy-sensitive config contract.
  • merge-risk: 🚨 compatibility: A shipped Telegram config key is removed and existing explicit/default group-history behavior can change during upgrade.
  • merge-risk: 🚨 security-boundary: The migration can widen which unmentioned Telegram group messages enter model context for users who previously selected mention-only.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: No after-fix real Telegram proof was found in the PR body or comments; tests, CI, and production diagnosis are supplemental but do not prove the changed behavior on this latest head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR changes Telegram group reply-context behavior in a way a short Telegram Desktop proof can demonstrate.
Evidence reviewed

PR surface:

Source +84, Tests +360, Docs -5, Generated 0, Other 0. Total +439 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 13 348 264 +84
Tests 6 475 115 +360
Docs 3 12 17 -5
Config 0 0 0 0
Generated 1 5 5 0
Other 1 1 1 0
Total 24 841 402 +439

Security concerns:

  • [medium] Retired mode widens group context — extensions/telegram/src/doctor-contract.ts:162
    Explicit mention-only configs are removed rather than preserved, so previously limited group chatter can enter model context after upgrade.
    Confidence: 0.88

What I checked:

Likely related people:

  • mmaps: Authored the merged Telegram group-history control PR that added includeGroupHistoryContext and the mention-only default now being retired. (role: introduced behavior; confidence: high; commits: 32af1c069727; files: extensions/telegram/src/group-history-context.ts, extensions/telegram/src/bot-message-context.session.ts, extensions/telegram/src/bot-message-dispatch.ts)
  • eleqtrizit: Merged the shipped history-control PR and left maintainer-visible compatibility/security rationale for that default, so they are useful provenance for the config contract. (role: merger and reviewer; confidence: medium; commits: 32af1c069727; files: extensions/telegram/src/group-history-context.ts, src/config/types.telegram.ts)
  • obviyus: Opened the canonical issue and authored this PR plus merged sibling ambient-room PRs, making them the current owner for the coordinated fix set beyond merely proposing this branch. (role: current fix-set owner and recent area contributor; confidence: high; commits: 05a8b315fff5, e08102820e06, 4d5dac183683; files: extensions/telegram/src/bot-message-context.session.ts, extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/doctor-contract.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added 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 Jul 2, 2026
@obviyus
obviyus force-pushed the codex/fix-ambient-window branch from c70ffdf to 506af8f Compare July 2, 2026 15:52
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 2, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 Jul 2, 2026
@obviyus
obviyus force-pushed the codex/fix-ambient-window branch from 506af8f to 05a8b31 Compare July 2, 2026 16:11
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jul 2, 2026
@obviyus
obviyus merged commit dad7768 into main Jul 2, 2026
104 of 106 checks passed
@obviyus
obviyus deleted the codex/fix-ambient-window branch July 2, 2026 16:23
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 maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ambient group mode runs blind: room-event turns get no room context, over-reply, and leak notices

1 participant