Skip to content

fix(announce): preserve threadId in subagent announce for Telegram DM topics#52824

Closed
Lukavyi wants to merge 1 commit into
openclaw:mainfrom
Lukavyi:fix/topic-announce-threadid
Closed

fix(announce): preserve threadId in subagent announce for Telegram DM topics#52824
Lukavyi wants to merge 1 commit into
openclaw:mainfrom
Lukavyi:fix/topic-announce-threadid

Conversation

@Lukavyi

@Lukavyi Lukavyi commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #52217 — subagent completion announce was delivering to the main Telegram DM chat instead of the originating topic because threadId was lost during the announce delivery pipeline.

  • Swap conversationId priority in resolveSubagentCompletionOrigin: prefer to-derived chat ID over threadId for bound-route lookups, so bindings match the conversation (chat) rather than the topic thread inside it
  • Defensive threadId guard in resolveAnnounceOrigin: ensure the requester's threadId (captured at spawn time) is never overridden by a stale session entry lastThreadId
  • Telegram observability: add message_thread_id to sendMessage ok log lines for easier diagnosis
  • 3 regression tests: direct path (no entry threadId), queue path (stale entry threadId), and no-spurious-injection scenario

Test plan

  • pnpm test -- src/agents/subagent-announce.format.e2e.test.ts — 73 tests pass (including 3 new)
  • pnpm test -- src/utils/delivery-context.test.ts — 9 tests pass
  • pnpm check — all lint/format checks pass
  • Manual: spawn subagent from Telegram DM topic, verify completion announce lands in the same topic

… topics (openclaw#52217)

Two fixes to prevent threadId loss during subagent announce delivery:

1. Swap conversationId priority in resolveSubagentCompletionOrigin to prefer
   the chat-level ID from `to` over threadId, so bound-route lookups match
   the conversation rather than the topic thread inside it.

2. Add defensive guard in resolveAnnounceOrigin ensuring the requester's
   threadId (captured at spawn) is never overridden by a stale session
   entry threadId during the merge.

Also adds message_thread_id to Telegram sendMessage log lines for
observability, and three regression tests covering direct, queue, and
no-thread scenarios.

Closes openclaw#52217
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram agents Agent runtime and tooling size: S labels Mar 23, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 29, 2026
@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already preserves requester thread IDs for subagent completion announces and has regression coverage for stale Telegram topic session entries; the remaining PR-only logging change is diagnostic and does not justify keeping this stale branch open.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the current-main implementation and close this obsolete branch; any desired Telegram sendMessage success-log thread suffix should be tracked as a separate observability cleanup.

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

Yes. The current-main source and regression test show the reported route shape: Telegram captures chat target and thread separately, and stale session threadId is overridden by the requesterOrigin threadId during announce delivery.

Is this the best way to solve the issue?

No for merging this PR as-is. Current main already solves the user-visible delivery bug in the refactored announce path, while this stale branch still changes an older file shape and its logging suffix would be misleading after threadless fallback.

Security review:

Security review cleared: The PR diff only touches announce routing, Telegram success logging, and tests; it does not change dependencies, workflows, permissions, secrets, package resolution, or artifact execution.

What I checked:

Likely related people:

  • sfuminya: Merged PR fix: preserve requester route for subagent completion delivery #72806 is the closest current-main requester-route completion-delivery fix and is credited in the changelog for preserving requester delivery across bound child agents. (role: introduced related behavior; confidence: high; commits: b8fbd240b7f9; files: src/agents/subagent-spawn.ts, src/agents/subagent-announce-delivery.ts, CHANGELOG.md)
  • Vincent Koc: Local blame on the current-main extracted announce delivery/origin files points to Vincent Koc in the available history, and the active changelog has recent adjacent subagent completion entries credited to @vincentkoc. (role: recent maintainer; confidence: medium; commits: 03d04c243b86; files: src/agents/subagent-announce-delivery.ts, src/agents/subagent-announce-origin.ts, extensions/telegram/src/bot/delivery.send.ts)
  • Lukavyi: The PR author also appears in prior shipped Telegram topic/thread routing changelog entries and authored the linked Telegram DM-topic report, making them useful context for this behavior even though the current fix is on main. (role: adjacent Telegram topic contributor; confidence: medium; files: CHANGELOG.md, extensions/telegram/src/bot-message-context.session.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 06056926a099; fix evidence: commit 06056926a099, main fix timestamp 2026-05-04T13:39:23-07:00.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 30, 2026
@clawsweeper clawsweeper Bot closed this May 4, 2026
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: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Subagent announce delivers to wrong Telegram DM topic (stale threadId)

1 participant