Skip to content

Telegram: specific forum topic becomes permanent inbound black hole after stuck-session recovery #91564

Closed

Description

@wangwllu

Summary

A specific Telegram forum topic (thread_id=905 in our case) becomes a permanent inbound black hole: Telegram pushes updates to the bot, OpenClaw acks them off the long-poll queue, but no Inbound message ... log line ever appears for that thread and the agent never sees the message. Other topics in the same chat continue to work normally. Outbound to the same thread keeps working.

This is reproducible across multiple gateway restarts and survives session-store deletion. We have not found a way to recover the affected thread without abandoning it.

Environment

  • OpenClaw 2026.6.1 (commit 2e08f0f)
  • macOS 26.4 (arm64), Node 26.0.0
  • Telegram provider: polling mode, isolated polling ingress
  • Forum group is_forum: true, bot is status: member
  • Affected thread: message_thread_id=905
  • Other threads in the same group (topic:17, topic:13, direct chat): unaffected

What works

  • Outbound to topic 905: openclaw message send --thread-id 905 ... succeeds, message arrives in the Telegram client.
  • Inbound to other topics in the same chat (e.g. topic 17): works end-to-end, agent replies normally.
  • Inbound to direct chat: works.
  • Bot membership / permissions: getChatMember returns status: member for the group.
  • Telegram side: getUpdates?offset=-N returns [] after the user posts → confirms OpenClaw acked the update off Telegram's queue.

What is broken

For thread 905 specifically:

  1. User sends a message in topic 905.
  2. Telegram queues the update for the bot.
  3. OpenClaw polling acks it (Telegram side queue drains to []).
  4. No Inbound message telegram:group:...:topic:905 ... log line is written.
  5. Agent never receives the message; user never gets a reply.

This persists through:

  • 5+ openclaw gateway restart cycles
  • Clearing claudeCliSessionId / cliSessionIds / cliSessionBindings for topic 905 in sessions.json
  • Resetting status: "failed" → unset on the session row
  • Deleting the entire topic 905 entry from sessions.json and the underlying transcript JSONL
  • Sending an explicit bot mention in topic 905

Suspicious log evidence

(All chat ids / user ids / bot username redacted as -100XXXXXXXXXX, 5XXXXXXX62, REDACTED_BOT.)

1. Stale lane guard (around the time the black hole started)

2026-06-09T08:49:04 [telegram] [diag] timed out spooled update 939635924 had no active reply fence on lane telegram:-100XXXXXXXXXX:topic:905; keeping the lane guarded until the handler stops.
2026-06-09T08:49:09 [telegram] [diag] timed out spooled update 939635924 did not stop within 5s after reply abort; keeping lane telegram:-100XXXXXXXXXX:topic:905 guarded.

After this line, no further inbound for topic:905 is ever logged. The guard is supposed to be in-process state (activeSpooledUpdateHandlersByLane Map in monitor-polling.runtime-*.js), so it should clear on restart — but the black hole survives every restart.

2. Mismatched session key format

2026-06-09T00:11:24 [ws] ⇄ res ✗ sessions.resolve 8ms errorCode=INVALID_REQUEST errorMessage=No session found: telegram:-100XXXXXXXXXX:905

The key telegram:-100XXXXXXXXXX:905 is missing the topic: segment that real session keys use (agent:main:telegram:group:-100XXXXXXXXXX:topic:905). Some caller is constructing the wrong key and silently failing the resolve. Possibly related to the inbound dispatcher dropping the update before logging it.

3. Repeated topic:905 session resets prior to today

The agent transcript directory shows topic:905 has been auto-reset 3 times in 24 hours:

  • c0ffbf21-...-topic-905.jsonl.reset.2026-06-08T13-05-18.913Z
  • d8243339-...-topic-905.jsonl.reset.2026-06-08T23-56-15.247Z
  • And again today (manual delete). Suggests this thread has chronic instability.

4. Stuck-session recovery right before the black hole started

2026-06-09T08:02:26 [diagnostic] stalled session: sessionId=d8243339-... sessionKey=agent:main:telegram:group:-100XXXXXXXXXX:topic:905 state=processing age=371s queueDepth=1 reason=active_work_without_progress classification=stalled_agent_run activeWorkKind=embedded_run
2026-06-09T08:02:26 [diagnostic] stuck session recovery: sessionId=d8243339-... sessionKey=agent:main:telegram:group:-100XXXXXXXXXX:topic:905 age=371s action=abort_embedded_run aborted=true drained=true
2026-06-09T08:02:26 [diagnostic] stuck session recovery outcome: status=aborted action=abort_embedded_run sessionId=d8243339-... sessionKey=agent:main:telegram:group:-100XXXXXXXXXX:topic:905

A stuck session recovery aborted the embedded run for topic:905 shortly before the black hole began. Hypothesis: the recovery path leaves residual state somewhere persistent (not the in-process Map) that causes future inbound updates for this exact (chatId, thread_id) to be dropped.

Repro shape

  1. Have a Telegram forum group where one topic accumulates a stuck session that gets recovered via abort_embedded_run + the timed-out-spooled-handler path.
  2. After recovery, send any user message to that topic.
  3. Observe: Telegram acks the update, no Inbound message ... log line, agent never receives. Other topics in the same chat continue to work.

Workaround

Users have to abandon the affected thread and create a new one in the same forum group. Even fully removing the session entry + transcript + multiple gateway restarts does not restore inbound to the original thread.

Asks for the maintainer

  1. Where is the persistent state that survives sessions.json deletion + restart and keys off (chatId, thread_id) to drop inbound updates for one specific topic? That's the mystery.
  2. The sessions.resolve call using telegram:<chatId>:905 (without topic:) — what's the caller? It's a hint that some component constructs session keys without the thread segment.
  3. Should abort_embedded_run recovery clear all persisted lane state for that thread, including any dedup / claim / message-cache entries that might key off thread_id alone?

Happy to provide more raw log slices, sqlite plugin-state dumps, or attempt patches if guided.

Activity

  1. clawsweeper commented on Jun 9, 2026

    @clawsweeper
    Contributor

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

    Current main now makes polling acknowledgement depend on durable ingress admission, preserves forum-topic lanes, and replays durable work across restart; the reported permanent silent-loss behavior is therefore implemented against on main.

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

    Review details

    Best possible solution:

    Keep the current durable-before-ack and restart-replay design, and report any recurrence from a current release with the ingress diagnostic and durable-queue state.

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

    Yes, source coverage now exercises the decisive boundary: the worker cannot advance its offset until the parent commits the durable spool entry, including topic-lane handling and restart replay.

    Is this the best way to solve the issue?

    Yes: durable admission before acknowledgement plus lane-aware restart replay repairs the owning ingress boundary rather than attempting to repair deleted session state downstream.

    Security review:

    Security review: This issue does not propose a patch or identify a security boundary concern.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • clawSean: Current-main commit c02e393 updated the polling, durable ingress, topic-lane, and related recovery-test surfaces. (role: recent Telegram ingress contributor; confidence: medium; commits: c02e39345bf6; files: extensions/telegram/src/polling-session.ts, extensions/telegram/src/telegram-ingress-drain.ts, extensions/telegram/src/telegram-ingress-spool.ts)

    Codex review notes: model internal, reasoning high; reviewed against ce06e7924e88; fix evidence: commit c02e39345bf6, main fix timestamp 2026-08-05T14:42:51+05:30.

  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on Jun 9, 2026
  3. kesslerio commented on Jun 11, 2026

    @kesslerio
    Contributor

    Corroborating report — same black hole on 2026.6.1, slightly different trigger, also survives manual session repair

    Environment: OpenClaw 2026.6.1 (2e08f0f) in Docker (Node 22.21.1, Linux), Telegram polling mode with isolated polling ingress, forum supergroup, bot status: member, privacy mode off (can_read_all_group_messages: true).

    One forum topic (redacted, topic:A) became an inbound black hole with the exact signature described in the OP:

    • getWebhookInfo shows pending_update_count: 0 right after the user posts → updates are being acked off the queue
    • no Inbound message ...:topic:A log line is ever written; the agent never sees the message
    • outbound to topic A keeps working (openclaw message send --target ...:topic:A → delivered, outbound send ok ... threadId=A logged)
    • other topics in the same group work fully end-to-end (inbound → agent run → delivery)
    • driving the agent directly at the topic's session (openclaw agent --session-key agent:<id>:telegram:group:<chat>:topic:A --deliver) works fine — the breakage is isolated to inbound dispatch for that (chatId, threadId) lane

    Trigger timeline in our case: a long (~2.5h) agent run on that topic's session was interrupted by a gateway restart; on boot we saw removed stale session lock ... (recycled-pid) followed by resumed interrupted main session: ...topic:A (with pending payload). A few hours later a manual stuck-session repair was performed (cleared a session model override in sessions.json, another gateway restart, killed a leftover codex app-server process). After that restart the topic never delivered inbound again. It survives subsequent restarts; the sessions.json entry is intact and healthy (status=done, no overrides, correct deliveryContext).

    New datapoints beyond the OP:

    1. One message did get through the dead topic: a short /id command, which the user most likely sent as a reply to one of the bot's own messages in that topic. It produced a normal Inbound message ...topic:A line and was answered in-topic. Fresh non-reply messages — including explicit @botname mention text — continue to be silently dropped. So replies-to-bot (and/or slash commands) appear to bypass whatever is guarding the lane; that asymmetry may help locate the guarded code path (reply fence vs. fresh-message ingestion?).
    2. We also went hunting for the persistent guard state and came up empty: all sqlite stores under the state root db/ (auth.db, doctor.db, usage.db, watchdog.db, webhooks.db) contain no per-thread guard/dedup rows; the ingress spool dir is empty (no stuck .processing claims); the thread-bindings-<account>.json store is empty; the update-offset file only carries lastUpdateId. The "what persists across restarts" mystery stands.

    Workaround confirmed on our side as well: abandoning the thread and moving the topic config to a freshly created forum topic. Happy to provide redacted log slices if useful.

  4. vortexopenclaw commented on Jun 14, 2026

    @vortexopenclaw
    Contributor

    Problem summary: this looks related to #93040, but I would not close this issue as a duplicate yet.

    #93040 covers the in-process guarded-lane part of this failure family: after a spooled Telegram update times out and the old handler ignores abort, the timed-out update is marked failed, the lane guard is released after the abort grace window, and isolated ingress restarts so a later same-lane update can drain.

    The extra evidence here points at a second question that #93040 may not fully answer:

    • this report survives full gateway restarts
    • one forum topic stays broken while neighboring topics work
    • replies to the bot or slash-command-shaped messages may bypass the broken fresh-message path
    • the observed session key shape without an explicit topic: segment still looks worth checking against topic binding/routing state

    Suggested next step: keep #91564 open after #93040 unless maintainers can confirm the PR also fixes the persistent post-restart topic black-hole case. The clean split is: #93040 for the timeout/release/restart recovery path, this issue for any persistent topic routing or binding state that remains after process restart.

  5. vortexopenclaw commented on Jun 14, 2026

    @vortexopenclaw
    Contributor

    @clawsweeper re-review

  6. added
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    and removed
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    on Jun 21, 2026
  7. 13 remaining items

  8. added
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    on Jul 27, 2026
  9. added
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    and removed
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    on Aug 5, 2026
  10. self-assigned this
    on Aug 6, 2026
  11. vincentkoc commented on Aug 6, 2026

    @vincentkoc
    Member

    Closing this as already fixed on current main. Correction to the earlier automated review: the fix is a current-main ingress/recovery chain, not solely commit c02e39345bf6.

    Current Telegram polling now acknowledges an update only after the parent has committed it through ingressMonitor.admit; a failed durable admission returns a failed acknowledgement instead of advancing consumption. Forum messages retain canonical telegram:<chat>:topic:<thread> lane identity, and persisted claims are recovered and replayed across polling, isolated-ingress, and account restarts. The final owner-boundary update is included in c02e39345bf6, #95830; the durable-before-offset and topic-lane regressions were introduced earlier in 1126ffba7ffe and remain green.

    Focused verification on current main:

    • Telegram ingress worker and spool mapping: 14/14 tests passed, including durable-before-offset acknowledgement and per-topic lane derivation.
    • Polling restart recovery: 3/3 focused tests passed for crash-before-adoption replay, restart-claim recovery before later same-lane work, and orphaned-claim recovery across account restart.

    This repairs the reported persistent post-restart topic black hole at the ingress owner. #91456 remains open because its in-process DM timeout/guard behavior is a distinct failure mode. The fix is current-main-only; no version release tag contains c02e39345bf6 yet.

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

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.close:already-fixedclaw-marshal labelimpact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions