Skip to content

fix(telegram): replies are lost when the HTTP proxy refuses the tunnel - #140388

Merged
obviyus merged 1 commit into
openclaw:mainfrom
Hekzory:fix/telegram-proxy-tunnel-not-started
Sep 9, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
Hekzory:fix/telegram-proxy-tunnel-not-started

Conversation

@Hekzory

@Hekzory Hekzory commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #126246

What Problem This Solves

Fixes an issue where durably queued Telegram replies are abandoned when an HTTP proxy refuses the CONNECT tunnel before the request reaches Telegram. The failed reply is treated as an ambiguous send, so recovery refuses to replay it after connectivity returns.

Why This Change Was Made

The Telegram transport marks Undici's exact refused-tunnel and proxy-connection error shapes as requests that did not start. Its existing retry and durable recovery paths then handle the unsent reply. The classification applies to transport-owned explicit and environment proxy dispatchers, preserves the original error cause, and lets caller cancellation take precedence. Ambiguous sends retain their existing no-replay protection.

User Impact

Durably queued replies can recover from a temporary proxy refusal and arrive once after the same proxy becomes healthy.

Evidence

  • Real Telegram Test Server turns reproduced the lost queued reply on pinned main through both explicit and environment proxy settings. The original intent entered unknown_after_send; recovery refused blind replay and retained its existing permanent failure record.
  • Independent candidate captures through both proxy settings kept the original intent pending with safe retries across Gateway restart, then delivered its original reply exactly once after proxy restoration. The original intent was positively acknowledged by its recovery owner and removed under the existing success policy; no retained completed row is claimed.
  • Candidate caller-abort and secure-proxy hostname-mismatch controls passed through both proxy modes. The committed generic-abort and direct-dispatcher controls passed.
  • A real accepted-CONNECT/TLS-reset control retained ambiguity and refused replay after restart and restoration, with no recipient reply. A direct-send control preserved the original reply target and native quote.
  • Candidate: 124 focused tests passed across the Telegram fetch/error files and real proxy/queue loopback file. The new marker and loopback regression cases fail on unchanged main for the intended missing-marker and single-attempt reasons.
  • Exact Undici 8.10.2 proxy contracts were inspected. Candidate formatting, focused boundary checks, and runtime build passed. The hosted pipeline passed for this exact head.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 4:58 PM ET / 20:58 UTC (Revision 9).

ClawSweeper review

What this changes

The Telegram plugin marks refused or failed proxy tunnels as unsent requests so existing retries and durable recovery can preserve queued replies.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still misclassifies refused proxy tunnels, and the supplied before/after observations support recovery without duplicate delivery. No blocking patch defect was found.

Priority: P1
Reviewed head: b234946c640c1276a5d5bbf98f055b0286fe987e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant live recovery observations and negative controls; no actionable correctness defect was found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured PR body records real Telegram Test Server turns through both proxy modes: transport-classified refusals remain retryable across Gateway restart and the original reply arrives once after restoration; accepted-tunnel resets remain ambiguous. The real-client loopback regression supplements these live observations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body records real Telegram Test Server turns through both proxy modes: transport-classified refusals remain retryable across Gateway restart and the original reply arrives once after restoration; accepted-tunnel resets remain ambiguous. The real-client loopback regression supplements these live observations.
Evidence reviewed 8 items Introduced classification preserves the transport boundary: The classifier requires a transport-owned proxy dispatcher and either the exact refused-CONNECT message with UND_ERR_ABORTED or UND_ERR_PRX_CONN. Caller cancellation is checked first; caller-provided dispatchers bypass this classification.
Dependency contract directly verified: The patch imports Undici and explicitly relies on its proxy error contract. Verified nodejs/undici v8.10.2 resolves to this commit: non-200 CONNECT produces the exact RequestAbortedError before endpoint TLS starts; a tunnel-establishment socket failure produces ProxyConnectionError. Secure-proxy hostname mismatch has a separate error code.
Existing retry and queue contract reused: TelegramRequestNotStartedError already feeds safe non-idempotent retries and becomes PlatformMessageNotDispatchedError. Recovery retains partial-send evidence instead of treating a later unsent request as permission to replay an already-delivered batch; no queue schema, retention policy, or public plugin API is added.
Findings None None.
Security None None.

How this fits together

Telegram’s transport sends queued replies through a configured proxy and reports whether a request could have reached Telegram. The delivery queue uses that distinction to retry unsent messages while preserving protection against replaying ambiguous sends.

flowchart TD
  A[Queued Telegram reply] --> B[Telegram transport]
  B --> C[Proxy tunnel]
  C --> D{Tunnel opened?}
  D -->|No| E[Existing safe retry and recovery]
  D -->|Yes| F[Telegram API request]
  F --> G[Delivery receipt or ambiguous outcome]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +55, Tests +293. Total +348 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 58 3 +55
Tests 2 293 0 +293
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 351 3 +348

Review metrics

None.

Technical review

Best possible solution:

Keep unsent-request classification in the transport that owns the proxy, using existing recovery while retaining ambiguity safeguards for requests that may have reached Telegram.

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

Yes: refusing CONNECT before a durable Telegram send exposes the missing classification in current source, corroborated by the contributor’s before/after observations. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: the patch records proven non-delivery at the transport owner and reuses existing retry and recovery contracts without broadening ambiguous-send replay.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c3f242fe0a79.

Labels

Label justifications:

  • P1: A temporary proxy refusal can strand queued Telegram replies instead of allowing delivery after connectivity returns.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body records real Telegram Test Server turns through both proxy modes: transport-classified refusals remain retryable across Gateway restart and the original reply arrives once after restoration; accepted-tunnel resets remain ambiguous. The real-client loopback regression supplements these live observations.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records real Telegram Test Server turns through both proxy modes: transport-classified refusals remain retryable across Gateway restart and the original reply arrives once after restoration; accepted-tunnel resets remain ambiguous. The real-client loopback regression supplements these live observations.

Evidence

What I checked:

  • Introduced classification preserves the transport boundary: The classifier requires a transport-owned proxy dispatcher and either the exact refused-CONNECT message with UND_ERR_ABORTED or UND_ERR_PRX_CONN. Caller cancellation is checked first; caller-provided dispatchers bypass this classification. (extensions/telegram/src/fetch.ts:858, b234946c640c)
  • Dependency contract directly verified: The patch imports Undici and explicitly relies on its proxy error contract. Verified nodejs/undici v8.10.2 resolves to this commit: non-200 CONNECT produces the exact RequestAbortedError before endpoint TLS starts; a tunnel-establishment socket failure produces ProxyConnectionError. Secure-proxy hostname mismatch has a separate error code. (lib/dispatcher/proxy-agent.js:229, 5e541e0b9df7)
  • Existing retry and queue contract reused: TelegramRequestNotStartedError already feeds safe non-idempotent retries and becomes PlatformMessageNotDispatchedError. Recovery retains partial-send evidence instead of treating a later unsent request as permission to replay an already-delivered batch; no queue schema, retention policy, or public plugin API is added. (extensions/telegram/src/network-errors.ts:33, b234946c640c)
  • Recorded after-fix behavior and regression coverage: The supplied complete PR body, captured under sourceRevision 5b4d05355f84ab7b89a56f47ca48b46b95523a47b12795f8ecb91a1639ee6a49, records Telegram Test Server observations through explicit and environment proxies: the original intent remains pending across restart and delivers once after restoration. It also records caller-abort, hostname-mismatch, accepted-CONNECT/TLS-reset, and direct-send controls. The introduced loopback regression exercises the real Telegram plugin, proxy client, and durable recovery owner across database reopen. These are contributor-recorded observations; this read-only review did not execute the tests or live scenario. (test/telegram-outbound-permanent-rejection-loopback.test.ts:287, b234946c640c)
  • Still necessary on fetched main and latest release: The fetched main has no changes from the pinned PR base in either production file and therefore lacks the introduced classifier. Inspection of v2026.9.3 also found the original catch path without tunnel classification. The related-PR search established no merged replacement for this specific behavior. (extensions/telegram/src/fetch.ts:815, c3f242fe0a79)
  • Feature-history routing: Current-main history identifies prior work on pre-dispatch custody and proxy transport by steipete. The GitHub commit endpoint confirms the relevant custody patch and author login. Some local blame/show queries could not load historical blobs; REST inspection supplied the relevant patch instead. (extensions/telegram/src/network-errors.ts:18, 2e86f7cc958a)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (8 earlier review cycles)
  • reviewed 2026-09-06T19:29:16.655Z sha 1f56c551c92901c326eedd2653facc1607cf8b5d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T19:55:08.713Z sha ccdd9ccf10bb382a50b7ae9105fd2e3086e997a0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T20:04:08.878Z sha 8201ebb2987ca7bc0bcbe13abb91421979c150a2 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T12:20:31.528Z sha c57fea11071ce6970f85ce2f65eb548ebad0d99c :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T12:34:19.004Z sha 70bce69f2c7bb7efb1f61f64510b0f8b73eb1408 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T16:46:38.575Z sha 521cfe3f05ba377d6010649ad9bba7c2853ce494 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T17:11:31.764Z sha b234946 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T17:51:09.721Z sha b234946 :: needs maintainer review before merge. :: none

@Hekzory
Hekzory force-pushed the fix/telegram-proxy-tunnel-not-started branch 5 times, most recently from 70bce69 to 521cfe3 Compare September 8, 2026 16:40
undici's ProxyAgent reports a non-200 CONNECT reply as a generic
RequestAbortedError (UND_ERR_ABORTED) and a socket failure while the
tunnel is opening as ProxyConnectionError (UND_ERR_PRX_CONN). Both fire
before the TLS session to api.telegram.org exists, so the request never
reached Telegram, but the Telegram send path treated them as an unknown
post-send failure: one attempt, then the durable queue parked the reply
as unknown_after_send and never replayed it.

The Telegram transport owns its proxy dispatchers, so it now surfaces
both shapes as TelegramRequestNotStartedError with the original error as
cause. The existing no-send contract does the rest: the send runner
retries in-process and rethrowTelegramSendError hands the durable queue a
PlatformMessageNotDispatchedError, so the reply is replayed on the
recovery schedule. Direct dispatchers and generic aborts keep their
ambiguous, no-retry handling.
@Hekzory
Hekzory force-pushed the fix/telegram-proxy-tunnel-not-started branch from 521cfe3 to b234946 Compare September 8, 2026 17:05
@obviyus obviyus self-assigned this Sep 9, 2026
@obviyus
obviyus merged commit cb1b3be into openclaw:main Sep 9, 2026
197 checks passed
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Hekzory!

Proof: Real Telegram Test Server turns recovered the original queued reply exactly once after proxy restoration and Gateway restart through both explicit and environment proxy settings. Abort, certificate, accepted-tunnel reset, and native reply controls passed, along with 124 focused tests and exact-head CI.

  • Bug: A refused proxy tunnel could permanently strand a queued reply even though Telegram received no request.
  • Fix: The Telegram transport supplies its existing request-not-started marker for the dependency's proven pre-tunnel failures.
Before After
Refused CONNECT becomes ambiguous and the original reply is not recovered. The original intent remains retryable across restart and is acknowledged after one recovered reply.
Accepted-tunnel failure remains ambiguous. Ambiguous sends retain their no-blind-replay protection.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
openclaw#140388)

Classify transport-proven proxy tunnel failures through Telegram's existing request-not-started error so queued replies remain safely retryable. Preserve caller cancellation and ambiguous-send protection.

Verified real Telegram Test Server recovery across Gateway restart through explicit and environment proxies, discriminating abort/TLS controls, native reply context, and focused regression tests.

Co-authored-by: Ayaan Zaidi <[email protected]>
LibraHo added a commit to LibraHo/openclaw that referenced this pull request Oct 21, 2026
…irs for 8.35-D

Adapt official PRs openclaw#140388, openclaw#156842, openclaw#168738, openclaw#169010, openclaw#165444, openclaw#164633 and openclaw#169029 to the existing synchronous 2026.8.35 custom queue and plugin baseline. Preserve prior A/B/C repairs, UI, locked dependencies, database schemas, configuration and build customizations.

Canonical build source: 7fdcb8a1f5b9cec7c1e9d66bc8ae551a38f0ed70
Verified complete source tree: 6511c79
Upstream base: 713ba57

Selected regression boundaries: 247 tests passed; core and plugin production typechecks passed; bounded P0 autoreview scoped-clean. Broader Windows cleanup/symlink EPERM limits are recorded in local verification. No live Telegram-group test or full repository-green claim.

Saved ordinary inbound final text permits one retry after typed ambiguous transport failure, at most two total sends, with possible duplicate after a lost acknowledgement. Media, controls and accepted partial/identityless evidence remain excluded. This does not grant all cron/invest completion paths replay permission.

Candidate build only; no production deployment or memory reset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

2 participants