Skip to content

fix #87299: [Bug]: Spurious "Something went wrong" and Codex app-server failures in large Telegram direct sessions#89930

Closed
zhangguiping-xydt wants to merge 2 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-87299
Closed

fix #87299: [Bug]: Spurious "Something went wrong" and Codex app-server failures in large Telegram direct sessions#89930
zhangguiping-xydt wants to merge 2 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-87299

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix Telegram direct-session fallback handling so a late dispatch/cleanup error does not send the generic visible failure reply after a final answer was already delivered, suppressed, or queued.
  • Keep Telegram status reactions aligned with the same final-response boundary, so an already-successful visible turn is not reclassified as an error.
  • Scope: this PR addresses the Telegram duplicate-fallback half of [Bug]: Spurious "Something went wrong" and Codex app-server failures in large Telegram direct sessions #87299 only; it does not claim to fix the separate Codex app-server client-closed incident.
  • Why it matters / User impact: Telegram users should not see a successful final answer followed by a confusing generic failure message in the same direct chat.

Refs #87299

Root Cause

  • Root cause: Telegram dispatch treated a later dispatchError as enough to send the generic failure fallback, even when the dispatch boundary already knew that a final response had reached the user or was queued for delivery.
  • Why this is root-cause fix: The fallback decision now uses the Telegram dispatch boundary's delivery state plus the dispatcher queuedFinal result before considering dispatchError. The generic fallback still sends when no final response was delivered/suppressed/queued, but it is suppressed for the duplicate-message path after a successful final response.

Real behavior proof

  • Behavior or issue addressed: Telegram direct-session users should receive the final answer without a second generic Something went wrong while processing your request. Please try again. message when a later dispatch/cleanup warning is recorded.
  • Real environment tested:
    • Existing live Telegram smoke proof in the PR body was run on macOS Darwin 25.5.0 with Node 24.15.0, local OpenClaw dev gateway, worktree SHA a5505616a4, Telegram bot @moongpbot, and model deepseek/deepseek-v4-flash.
    • Current-head local verification was rerun on this daily-fix Linux worktree at a5505616a438b61f92700672083b4f1f9feac71e.
    • The Mantis Telegram Desktop Proof workflow also ran on current head and is the remaining external proof blocker.
  • Exact steps or command run after this patch:
    # Existing live Telegram smoke proof already in the PR discussion/body:
    TOKEN=$(security find-generic-password -a openclaw-daily -s openclaw-telegram-bot-token -w)
    DEEPSEEK_KEY=$(security find-generic-password -a openclaw-daily -s openclaw-deepseek-api-key -w)
    export TELEGRAM_BOT_TOKEN="$TOKEN" DEEPSEEK_API_KEY="$DEEPSEEK_KEY"
    export OPENCLAW_HOME="/Users/zhangguiping/daily_pr_work/proofs/openclaw-issue-87299-evidence/home"
    export OPENCLAW_STATE_DIR="/Users/zhangguiping/daily_pr_work/proofs/openclaw-issue-87299-evidence/state"
    export OPENCLAW_CONFIG_PATH="/Users/zhangguiping/daily_pr_work/proofs/openclaw-issue-87299-evidence/state/openclaw.json"
    export OPENCLAW_DISABLE_BONJOUR=1 OPENCLAW_GATEWAY_PORT=19072
    node scripts/run-node.mjs --dev gateway
    # Sent Telegram DM to @moongpbot: please reply with exactly: openclaw proof ok
    
    # Current-head local verification rerun from TASK_WORKTREE:
    node scripts/run-vitest.mjs extensions/telegram/src/bot-message-dispatch.test.ts
    pnpm exec oxfmt --check --threads=1 extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts
    npx oxlint --deny=warn --ignore-path=.oxlintignore extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts
    git diff --check
  • Evidence after fix:
    2026-06-04T02:09:10.779+08:00 [gateway] agent model: deepseek/deepseek-v4-flash (thinking=high, fast=off)
    2026-06-04T02:09:10.779+08:00 [gateway] http server listening (1 plugin: telegram; 1.5s)
    2026-06-04T02:09:10.880+08:00 [gateway] gateway ready
    2026-06-04T02:09:12.421+08:00 [telegram] [default] starting provider (@moongpbot)
    2026-06-04T02:09:13.820+08:00 [telegram][diag] isolated polling ingress started spool=/Users/zhangguiping/daily_pr_work/proofs/openclaw-issue-87299-evidence/state/telegram/ingress-spool-default
    2026-06-04T02:10:08.951+08:00 [telegram] Inbound message telegram:8903163841 -> @moongpbot (direct, 45 chars)
    2026-06-04T02:10:12.516+08:00 [telegram/send] telegram outbound send ok accountId=default chatId=8903163841 messageId=16 operation=sendMessage deliveryKind=text chunkCount=1
    Telegram observed reply: openclaw proof ok
    
    Current-head local verification:
    - bot-message-dispatch Vitest shard passed: 1 file, 105 tests.
    - oxfmt passed for the changed Telegram files.
    - oxlint passed for the changed Telegram files.
    - git diff --check passed with no output.
    
  • Observed result after fix: The patched live Telegram gateway accepted a direct message and sent the requested final reply without an observed generic fallback afterward. The focused regression tests prove the forced late-dispatch-error-after-final path at the Telegram dispatch boundary.
  • What was not tested: No live Telegram run in this environment forced the exact late-dispatch-error-after-final path. Normal live Telegram DM delivery was tested, and the forced late-error path is covered by dispatch-boundary regression tests.
  • Known proof gap / external blocker: The live Telegram smoke proof covers normal direct-message delivery, not the exact forced path where a final reply is delivered and a later dispatch error is injected. The current-head Mantis Telegram Desktop Proof job failed because the proof agent reported that it could not find a supported runner/config input to trigger that late post-answer delivery error. This remaining exact-path live proof requires either a richer Telegram/Mantis harness that can force the late dispatch error, or maintainer acceptance of the dispatch-boundary regression tests plus live smoke proof.

Regression Test Plan

  • Coverage level: focused Telegram dispatch regression test plus live Telegram smoke proof.
  • Target test file: extensions/telegram/src/bot-message-dispatch.test.ts.
  • Scenario locked in: a final visible Telegram reply is delivered and a later dispatcher error occurs; the chat receives only the final answer, no generic fallback, and the status reaction remains done.
  • Additional scenario locked in: a final reply is already queued and the dispatcher warning callback fires; no generic fallback reply is emitted.
  • Why this is the smallest reliable guardrail: the tests sit at the Telegram dispatch boundary that owns fallback delivery and directly assert the externally visible reply/status effects without changing provider, gateway, public config, schema, migration, or non-Telegram channel behavior.

Verification

  • node scripts/run-vitest.mjs extensions/telegram/src/bot-message-dispatch.test.ts
    • Passed on current head: 1 Vitest shard, 1 file, 105 tests.
  • pnpm exec oxfmt --check --threads=1 extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts
    • Passed: all matched files use the correct format.
  • npx oxlint --deny=warn --ignore-path=.oxlintignore extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts
    • Passed with no diagnostics.
  • git diff --check
    • Passed with no output.
  • Remote current-head status for a5505616a438b61f92700672083b4f1f9feac71e:
    • daily-fix pr-final-status reported FAIL=1 PENDING=0 PASS=128 SKIPPED=27.
    • The only failing check is Run agentic native Telegram proof, attributed to the exact-path Mantis capture limitation above.

Review findings addressed

  • RF-001: Not fixed by a code change; disclosed as an external proof gap. No redacted forced-path live Telegram artifact is available because the current Mantis/native proof setup could not trigger the late post-answer dispatch error.
  • RF-002: Partially addressed with current-head local verification and explicit proof disclosure. The exact late-dispatch-error path remains covered by dispatch-boundary regression tests, not live forced Telegram capture.
  • RF-003: Disclosed. The supplied live proof shows normal successful Telegram DM delivery; it does not show the exact delivered-final-plus-late-dispatch-error path.
  • RF-004: Addressed by narrowing the PR body from closing syntax to Refs #87299 and stating that this PR covers only the Telegram duplicate-fallback half, not the Codex app-server client-closed half.
  • RF-005: Maintainer judgment still requested. The chosen boundary is delivered, suppressed, or queued final reply because those are the dispatch owner facts that mean the user either already received or is scheduled to receive the final response.
  • RF-006: Acknowledged. There is no remaining narrow automated code repair; the only remaining blocker is exact-path live proof or maintainer acceptance of the existing regression tests plus live smoke proof.

Merge risk

  • Risk labels considered: merge-risk: 🚨 message-delivery.
  • Risk explanation: This changes visible Telegram fallback/status behavior, so the blast radius is user-visible message delivery. The code scope is limited to Telegram dispatch fallback/status handling plus focused tests.
  • Fix classification: Root-cause bug fix for the Telegram duplicate message-delivery path.
  • Why acceptable: Existing fallback behavior remains for turns with no delivered, suppressed, or queued final response. The change only prevents a duplicate generic fallback after the dispatch boundary already has final-response evidence.
  • Out of scope: This PR does not change Telegram auth/setup policy, provider routing, model routing, public config, schema, migration, protocol, fallback text, non-Telegram channel behavior, or Codex app-server behavior.
  • Related open PR scan: daily-fix prework did not find a related open PR covering the same Telegram direct-session message-delivery contract.
  • Patch quality notes: The production change stays inside the Telegram dispatch owner boundary and does not add fallback text, broad guards, dependencies, or unrelated behavior. The regression tests cover both delivered-final and queued-final duplicate-fallback cases.
  • Maintainer-ready confidence: High for code and regression coverage; blocked for merge readiness until exact-path live proof is supplied or maintainers accept the disclosed proof gap.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 3, 2026
@clawsweeper

clawsweeper Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 3, 2026, 9:45 PM ET / 01:45 UTC.

Summary
The PR changes Telegram dispatch fallback/status handling so final delivered, suppressed, or queued replies suppress a later generic error fallback, with focused dispatch tests.

PR surface: Source +4, Tests +43. Total +47 across 2 files.

Reproducibility: yes. by source inspection: current main sends the generic Telegram fallback whenever dispatchError is set, even if delivery state already recorded a visible final response. I did not run a live current-main Telegram repro in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger 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:

  • [P2] Add redacted forced-path Telegram logs, terminal output, recording, or a linked artifact showing final delivery followed by a late dispatch error without the generic fallback.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR has normal live Telegram logs, but the changed late-error-after-final path still needs redacted exact-path logs, terminal output, recording, or an artifact; update the PR body after adding proof, or ask a maintainer to comment @clawsweeper re-review if it does not rerun.

Risk before merge

  • [P1] The supplied live proof covers a normal Telegram DM, not the forced delivered-final-plus-late-dispatch-error path changed by the patch.
  • [P2] Merging changes visible Telegram fallback/status behavior, so maintainers need to accept delivered, suppressed, or queued final response as the boundary for suppressing the generic error.
  • [P2] The linked issue also includes a separate Codex app-server client-closed incident; this PR should remain scoped to the Telegram duplicate-fallback half.

Maintainer options:

  1. Add exact-path Telegram proof (recommended)
    Ask for redacted logs, terminal output, recording, or an artifact showing final Telegram delivery followed by a late dispatch error without the generic fallback.
  2. Accept the disclosed proof gap
    Maintainers may intentionally accept the unit-forced path plus ordinary live Telegram smoke proof if the late error cannot be forced in current live tooling.
  3. Pause until the proof harness can inject the error
    If exact-path proof is required and current Mantis cannot trigger it, keep the PR open until a richer Telegram diagnostic harness can exercise that condition.

Next step before merge

  • [P1] The remaining blocker is contributor exact-path proof or maintainer acceptance of the disclosed proof gap, not a narrow automated code repair.

Security
Cleared: The diff only changes Telegram dispatch logic and colocated tests; no secrets, dependency, workflow, package, or code-execution surface is touched.

Review details

Best possible solution:

Land the Telegram fallback fix with focused tests after exact-path proof or explicit maintainer acceptance, while leaving the linked Codex app-server path separate.

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

Yes by source inspection: current main sends the generic Telegram fallback whenever dispatchError is set, even if delivery state already recorded a visible final response. I did not run a live current-main Telegram repro in this read-only review.

Is this the best way to solve the issue?

Yes for the Telegram duplicate-fallback half: the dispatch boundary already owns delivered, suppressed, and queued-final facts, so this is the narrow maintainable location. It is not the full solution for the separate Codex app-server client-closed incident in the linked issue.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against d54addcd284f.

Label changes

Label changes:

  • remove mantis: telegram-visible-proof: Current Telegram visible-proof status is not_needed.

Label justifications:

  • P2: This is a focused Telegram duplicate-message delivery bug fix with limited blast radius.
  • merge-risk: 🚨 message-delivery: The PR intentionally changes when Telegram sends or suppresses visible fallback messages and terminal status reactions.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR has normal live Telegram logs, but the changed late-error-after-final path still needs redacted exact-path logs, terminal output, recording, or an artifact; update the PR body after adding proof, or ask a maintainer to comment @clawsweeper re-review if it does not rerun.
Evidence reviewed

PR surface:

Source +4, Tests +43. Total +47 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 6 +4
Tests 1 43 0 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 53 6 +47

What I checked:

  • Repository policy applied: Root AGENTS.md, extensions/AGENTS.md, and the Telegram maintainer note were read; Telegram behavior changes need source review plus real Telegram proof when they touch transport or visible reply behavior. (AGENTS.md:1, d54addcd284f)
  • Current main fallback behavior: Current main sends the generic Telegram failure fallback for non-room events whenever dispatchError is set, regardless of whether deliverySummary.delivered is already true, and marks any dispatchError as status error. (extensions/telegram/src/bot-message-dispatch.ts:2208, d54addcd284f)
  • Delivery state contract: Telegram marks deliveryState delivered from durable, normal, preview-finalized, and lane text delivery paths, so deliverySummary.delivered is the dispatch-owned visible-delivery fact this fallback decision should use. (extensions/telegram/src/bot-message-dispatch.ts:1435, d54addcd284f)
  • Dispatcher queued-final contract: The reply dispatcher returns queuedFinal only through DispatchFromConfigResult, and finalizeDispatchResult reconciles queuedFinal against final cancelled/failed counts before Telegram consumes it. (src/auto-reply/dispatch.ts:414, d54addcd284f)
  • PR diff behavior: The PR introduces hasFinalBeforeFallback from delivered, suppressed, or queued final state, blocks fallback when that signal exists, and only marks status error for dispatch errors before any final signal. (extensions/telegram/src/bot-message-dispatch.ts:2205, a5505616a438)
  • Regression coverage: The PR adds tests for delivered-final-plus-thrown-cleanup and queued-final-plus-error-callback cases, both asserting that no extra generic fallback is emitted and status stays done for the delivered-final case. (extensions/telegram/src/bot-message-dispatch.test.ts:3820, a5505616a438)

Likely related people:

  • steipete: Current checkout blame attributes the existing Telegram fallback/status block to e993e1c, and path history also shows recent Telegram helper and reply-dispatcher work by this person. (role: recent area contributor; confidence: high; commits: e993e1c334c6, d5736710a9d8, 27dde7a4d69b; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/lane-delivery-state.ts, src/auto-reply/reply/reply-dispatcher.ts)
  • jmao0001: GitHub path history shows e4993ec changed the same Telegram dispatch/test files for preview/final delivery duplication shortly before this PR. (role: recent adjacent contributor; confidence: medium; commits: e4993ec00f05; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/bot-message-dispatch.test.ts)
  • takhoffman: The recent streamed-final isolation commit in the same Telegram dispatch surface records this person as the approver in the squash metadata, making them a useful routing candidate for this behavior. (role: adjacent reviewer/approver; confidence: medium; commits: 07006943dea5; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/bot-message-dispatch.test.ts)
  • piersonr: Recent plugin SDK reply payload hook work changed the shared dispatcher path whose queuedFinal and delivery counts are part of this PR's correctness boundary. (role: reply-dispatch contract contributor; confidence: medium; commits: b474f429ee4b; files: src/auto-reply/dispatch.ts, src/auto-reply/reply/reply-dispatcher.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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 3, 2026
@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jun 3, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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.

1 participant