Skip to content

fix(telegram): preserve direct-message topics in config and cron writeback - #127010

Merged
steipete merged 2 commits into
mainfrom
steipete/fix-telegram-direct-topic-writeback
Aug 21, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/fix-telegram-direct-topic-writeback

Conversation

@steipete

@steipete steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Telegram users sending to a channel Direct Messages topic through a username or t.me target would lose the topic after chat-ID resolution, while config and cron writeback could also overwrite unrelated direct-topic or unthreaded destinations for the same channel.

Why This Change Was Made

Telegram writeback maintained a duplicate target matcher that considered forum thread IDs but ignored channel Direct Messages topic IDs, and its resolved-target formatter dropped the direct-topic suffix. Preserve that suffix at the Telegram-owned writeback boundary and reuse the existing canonical Telegram target matcher for both config and cron persistence, removing the obsolete duplicate matching path. This completes the topic routing introduced in #120916 and reuses the canonical target identity from #126625. A test-only, table-driven cron UI cleanup also repairs the existing current-main max-lines regression introduced in #126945, which otherwise fails the required hosted merge gate.

User Impact

Resolved Telegram Direct Messages destinations retain their original topic, and only the intended config default or scheduled cron delivery target is updated. Ordinary unthreaded targets, explicit forum topics, shorthand forum topics, unrelated accounts, and neighboring channel Direct Messages topics remain unchanged.

Release note: Telegram: preserve channel Direct Messages topic scope while resolving and persisting config and scheduled delivery targets.

Evidence

  • Regression provenance: replacing only the branch production file with the exact current-main implementation caused four failures in the new owner-boundary cases: direct-topic config, direct-topic cron, unthreaded config, and unthreaded cron. The failure showed -100123 replacing -100123:direct-topic:77 and incorrectly rewriting neighboring destinations; restoring the branch fixed all four.
  • node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts extensions/telegram/src/threading-tool-context.test.ts extensions/telegram/src/transport-payload.test.ts extensions/telegram/src/send-mutation-targets.test.ts extensions/telegram/src/topic-conversation.test.ts extensions/telegram/src/session-conversation.test.ts — 6 files passed; 101 tests passed. Coverage includes config/cron writeback, sibling target matching, conversation persistence, message mutations, and actual grammY/Bot API JSON and multipart payload construction.
  • node scripts/run-vitest.mjs ui/src/pages/cron/view.test.ts — 1 file passed; 42 cron UI tests passed, preserving enabled/disabled/loading scheduler coverage.
  • node --import tsx scripts/run-oxlint-shards.mts --only=core --split-core --core-stripe=5/5 --threads=1 — first reproduced the existing current-main eslint(max-lines) failure, then passed after consolidating three duplicate scheduler tests into one table-driven case.
  • node scripts/check-changed.mjs — the original Telegram-only diff passed all changed extension and extension-test gates, including formatting, production/test typechecks, extension lint, plugin boundaries, database-first guards, zero runtime import cycles, and 2 files / 5 plugin-doctor tests. After the required UI-test repair expanded scope, the rerun passed every preceding guard and failed only because this linked worktree's shared dependency tree lacks current-main @panzoom/panzoom and current pako types; its single permitted pnpm install refused to purge the shared installation without a TTY. Exact-head hosted CI performs the complete clean dependency/typecheck proof.
  • git diff --check origin/main...HEAD — passed.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex — clean for the CI-repair test change.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --engine codex — clean; no accepted/actionable findings.
  • Production: +15/-37 (net -22); tests/test support: +82/-37 (net +45).
  • Build: not required; this is an intra-plugin static owner-boundary change with no package, lazy-loader, generated-artifact, or public SDK boundary changes, and the changed gate verified zero runtime import cycles.
  • Proof gap: no authenticated live Telegram bot/account or consenting live channel Direct Messages recipient was supplied. The transport suite verifies the real grammY request serialization against a mocked Telegram Bot API; it is not claimed as live-channel proof.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Aug 21, 2026
@steipete
steipete marked this pull request as ready for review August 21, 2026 04:39
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 1:13 AM ET / 05:13 UTC.

ClawSweeper review

What this changes

Preserve Telegram Direct Messages topic identity when resolving username or t.me targets and writing the result to existing config defaults or cron delivery targets; consolidate three cron UI tests into one table-driven case.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this active: the patch is a focused Telegram-owned fix with no code-level finding, but it still needs the required real Telegram topic proof before merge.

Priority: P2
Reviewed head: 2bd366a6d32146ba0a8ed37edc959d75d45345cc

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 6 items Current-main defect: Current main builds its writeback key from chat identity plus only messageThreadId, so a direct-message topic is treated as unthreaded; it also resolves that target without retaining a direct-topic suffix.
Owner-boundary repair: The branch preserves directMessagesTopicId in the resolved target and delegates matching to the existing Telegram semantic matcher, which compares chat, forum-topic, and direct-topic identity.
Caller and sibling contract: The outbound send path parses a target, resolves its base chat ID, and passes the original target to writeback; the shared matcher keeps direct-message and forum topic identities distinct.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127010-hHONTe/target$ node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts
node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts
[test] starting test/vitest/vitest.extension-telegram.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127010-hHONTe/target

 ✓  extension-telegram  extensions/telegram/src/targets.test.ts (49 tests) 7445ms

 Test Files  1 passed (1)
      Tests  49 passed (49)
   Start at  05:14:46
   Duration  8.95s (transform 7.09s, setup 1.14s, import 208ms, tests 7.45s, environment 0ms)

[test] passed 1 Vitest shard in 14.98s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127010-hHONTe/target$ node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts



































Assertions:

  • PASS expect_output: targets.test.ts

How this fits together

Telegram send operations resolve a user-facing target into a numeric chat ID, then persist that destination for config defaults and scheduled jobs. Those persisted values later determine the chat and topic used for delivery.

flowchart LR
  A[User-facing Telegram target] --> B[Target parser]
  B --> C[Chat ID resolution]
  C --> D[Topic-aware writeback]
  D --> E[Config default]
  D --> F[Cron delivery target]
  E --> G[Telegram message delivery]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - This writeback changes persisted delivery destinations; mocked coverage cannot prove that a resolved Direct Messages topic reaches the same topic through the live Telegram flow.
  • Complete next step (P2) - This active maintainer PR needs live Telegram proof and normal exact-head merge validation rather than a repair-lane handoff.
Agent review details

Security

None.

PR surface

Source +45, Tests -22. Total +23 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 90 45 +45
Tests 1 7 29 -22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 97 74 +23

Review metrics

Metric Value Why it matters
Production versus test delta production +15/-37 (net -22); tests/test support +82/-37 (net +45) The fix removes the duplicate production matcher while adding boundary cases for each target scope and persistence surface.
Persisted target contract 0 config keys added; 1 existing target matcher replaced The PR changes selection and formatting of existing persisted targets without adding a new operator setting or migration.

Mantis proof suggestion

Telegram Desktop can directly demonstrate that a resolved and persisted Direct Messages target delivers to the selected topic rather than its channel base. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify that resolving and persisting a channel Direct Messages topic target keeps a later delivery in that same topic.

Merge-risk options

Maintainer options:

  1. Add topic-scoped live proof (recommended)
    Capture a redacted bot-to-bot or Telegram Desktop run showing that resolving a Direct Messages topic target preserves its scope through persistence and a later delivery.

Technical review

Best possible solution:

Land the Telegram-owned matcher reuse after a redacted live Telegram proof confirms resolution, config/cron persistence, and subsequent delivery remain scoped to the selected Direct Messages topic.

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

Yes—current main’s match key omits direct-message topic identity at extensions/telegram/src/target-writeback.ts:41, while the branch’s focused config and cron cases define the failing path.

Is this the best way to solve the issue?

Yes—the patch repairs the Telegram persistence owner and reuses the established semantic matcher instead of retaining a second, incomplete target-equivalence implementation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster. Replaced prior rating: 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: The bug can misroute a bounded class of Telegram config or scheduled deliveries but has no evidence of a broad runtime outage.
  • merge-risk: 🚨 message-delivery: Persisted config and cron target identity controls the Telegram topic used by later outbound messages.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster. Replaced prior rating: 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The stored destination controls visibly which Telegram Direct Messages topic receives later output, so a short Telegram Desktop proof is useful.

Evidence

What I checked:

  • Current-main defect: Current main builds its writeback key from chat identity plus only messageThreadId, so a direct-message topic is treated as unthreaded; it also resolves that target without retaining a direct-topic suffix. (extensions/telegram/src/target-writeback.ts:41, df8fedcc00dc)
  • Owner-boundary repair: The branch preserves directMessagesTopicId in the resolved target and delegates matching to the existing Telegram semantic matcher, which compares chat, forum-topic, and direct-topic identity. (extensions/telegram/src/target-writeback.ts:31, 2bd366a6d321)
  • Caller and sibling contract: The outbound send path parses a target, resolves its base chat ID, and passes the original target to writeback; the shared matcher keeps direct-message and forum topic identities distinct. (extensions/telegram/src/send-outbound.ts:106, 2bd366a6d321)
  • Regression coverage: The table-driven owner tests exercise config and cron independently for direct-message topics, explicit and shorthand forum topics, and unthreaded targets, asserting that neighboring targets are not rewritten. (extensions/telegram/src/target-writeback.test-shared.ts:296, 2bd366a6d321)
  • Feature history: History shows merged Direct Messages topic routing work and the later canonical semantic matcher, making this an extension of the same target-identity boundary rather than a new parallel abstraction. (extensions/telegram/src/normalize.ts:63, 08d926d3a5b3)
  • Release-source limitation: The latest release tag resolves locally, but its target file is a missing promisor object and the configured remote was unreachable; no claim about release inclusion is made. (0790d9f593ad)

Likely related people:

  • steipete: Recent merged history covers Telegram Direct Messages topic routing and adjacent target preparation, and the current PR extends that work at the persistence boundary. (role: recent feature owner; confidence: high; commits: d7133e7df6f5, 92bacda20699; files: extensions/telegram/src/target-writeback.ts, extensions/telegram/src/targets.ts)
  • obviyus: The merged target-identity work in fix(telegram): recognize current-source message targets #126625 introduced the semantic matcher this patch correctly reuses. (role: canonical matcher contributor; confidence: high; commits: 08d926d3a5b3; files: extensions/telegram/src/normalize.ts, extensions/telegram/src/channel.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-21T04:45:43.723Z sha 25062c8008c84ecc41ee67f1c57a554cbf456095 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/fix-telegram-direct-topic-writeback branch from 25062c8 to 2bd366a Compare August 21, 2026 05:07
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 21, 2026
@steipete

steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for reviewed head 2bd366a6d32146ba0a8ed37edc959d75d45345cc:

  • Root cause and owner: Telegram writeback used a duplicate chat/forum-thread matcher that ignored channel Direct Messages topic identity, and its formatter dropped the direct-topic suffix. The Telegram-owned repair preserves that suffix and delegates config/cron matching to the existing canonical target matcher.
  • Red-before/green-after: restoring the exact pre-fix production implementation made four owner-boundary regressions fail: direct-topic config, direct-topic cron, unthreaded config, and unthreaded cron. The repaired owner preserves the selected destination and leaves neighboring targets unchanged.
  • node scripts/run-vitest.mjs extensions/telegram/src/targets.test.ts extensions/telegram/src/threading-tool-context.test.ts extensions/telegram/src/transport-payload.test.ts extensions/telegram/src/send-mutation-targets.test.ts extensions/telegram/src/topic-conversation.test.ts extensions/telegram/src/session-conversation.test.ts — 6 files / 101 tests passed on the final rebase.
  • node scripts/run-vitest.mjs ui/src/pages/cron/view.test.ts — 1 file / 42 tests passed.
  • node --import tsx scripts/run-oxlint-shards.mts --only=core --split-core --core-stripe=5/5 --threads=1 — reproduced the existing current-main max-lines failure introduced in fix(ui): follow active scheduler trigger capability #126945, then passed after a test-only table-driven consolidation.
  • git diff --check origin/main...HEAD — passed.
  • node scripts/check-changed.mjs — the original Telegram scope passed its complete formatting, production/test typecheck, lint, boundary, and architecture plan. The expanded local UI rerun exposed missing current-main UI dependencies in the linked worktree's shared install; the one authorized install safely refused to purge that shared directory. A later final-head Telegram-scoped rerun passed safety, formatting, plugin contracts, dead-code scans, and both typecheck lanes before its slow lint subprocess was terminated with exit 143. Exact-head hosted CI below completed all required clean-install gates successfully.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex — clean for the CI repair.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --engine codex — clean for the complete final branch; no accepted/actionable findings.
  • node scripts/watch-pr-ci.mjs 127010 2bd366a6d32146ba0a8ed37edc959d75d45345cc — GREEN; exact-head successful hosted CI run: https://github.com/openclaw/openclaw/actions/runs/32449388486. The earlier run https://github.com/openclaw/openclaw/actions/runs/32447698803 failed only on the now-repaired current-main cron test max-lines regression and its aggregate gate.
  • Production: +15/-37 (net -22). Tests/test support: +82/-37 (net +45). No CHANGELOG.md change.
  • ClawSweeper rank-up disposition: fix the failed check / wait for exact-head CI — completed, exact-head CI is green; add live Telegram/Desktop proof — skipped because no authenticated test bot or consenting live channel Direct Messages recipient was supplied. Real grammY JSON/multipart request serialization and config/cron owner-boundary behavior are covered, but are not represented as live-channel proof. No unresolved review conversations.
  • Hosted Testbox/native preparation: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 127010 completed successfully without changing or pushing the reviewed head. The mandatory native hosted/Testbox gate selected exact-head evidence (GATES_MODE=hosted_exact_or_recent_parent, selection exact-head): CI run 32449388486, https://github.com/openclaw/openclaw/actions/runs/32449388486, and Workflow Sanity run 32449388526, https://github.com/openclaw/openclaw/actions/runs/32449388526. Dedicated Blacksmith Testbox, ARM Testbox, and Build Artifacts Testbox workflows were classified not applicable by the repository-owned guard; no separate Testbox lease was created.

@steipete
steipete merged commit 6f52e9f into main Aug 21, 2026
141 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

app: web-ui App: web-ui channel: telegram Channel integration: telegram maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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