Skip to content

fix(telegram): catch unhandled rejections in webhook and ingress worker shutdown - #100998

Merged
vincentkoc merged 8 commits into
openclaw:mainfrom
Pick-cat:fix/channel-bugs-batch-2026-07-06
Jul 29, 2026
Merged

vincentkoc merged 8 commits into
openclaw:mainfrom
Pick-cat:fix/channel-bugs-batch-2026-07-06

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram webhook shutdown could stop at the first rejected cleanup step. A failure in bot, server, transport, ingress, status, or diagnostics teardown could skip every later Telegram-owned phase and surface as an unhandled rejection.

Fix

Keep shutdown ownership in startTelegramWebhook() and isolate each fallible teardown phase. Every phase reports its own failure and cleanup continues through the remaining transport, ingress, status, and diagnostics steps.

This is a current-main rewrite of the contributor PR. Contributor credit is preserved with a co-author trailer.

Evidence

Verified head: 142987eacaaee445b7dab2bafc9122a484827bf1

  • Reproduced current-main behavior where one rejected shutdown skipped transport and status cleanup.
  • Production-path harness: rejected shutdown resolves, transport closes, disconnected status publishes, and the phase error is logged.
  • Synchronous server-close failure also continues through bot and status cleanup.
  • Focused Vitest: 1 passed, 36 skipped by filter.
  • Targeted oxfmt, oxlint, git diff --check, signature verification, privacy scan, and fresh autoreview passed.

No configuration, protocol, or public API surface changes.

@openclaw-barnacle openclaw-barnacle Bot added channel: imessage Channel integration: imessage channel: telegram Channel integration: telegram size: M labels Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 29, 2026, 1:16 PM ET / 17:16 UTC.

ClawSweeper review

What this changes

This PR changes Telegram webhook shutdown so failures in one teardown phase are logged and do not prevent later bot, transport, ingress, status, or diagnostics cleanup.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 4 items remain

The shutdown approach is plausible and the supplied diff is focused, but this review cannot reach a merge-ready verdict because the required read-only sandbox failed before it could inspect the full on-disk policy, final-head source context, history, maintainer notes, or the claimed runtime proof. Likely related people: vincentkoc (recent current-head contributor, medium confidence) and Pick-cat (earlier implementation contributor, medium confidence).

Priority: P2
Reviewed head: 142987eacaaee445b7dab2bafc9122a484827bf1

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch appears focused from the supplied diff, but it remains below the merge gate because final-head real-behavior proof and the full lifecycle review were unavailable.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body describes after-fix runtime proof, but this review could not open or compare the evidence with the final head; add or restore an inspectable redacted terminal transcript, logs, or linked artifact showing the injected failure and completed later cleanup, then update the PR body for re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body describes after-fix runtime proof, but this review could not open or compare the evidence with the final head; add or restore an inspectable redacted terminal transcript, logs, or linked artifact showing the injected failure and completed later cleanup, then update the PR body for re-review.
Evidence reviewed 3 items Read-only inspection environment failed: The first required repository-read command could not start: bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted. Therefore this review could not independently inspect AGENTS.md, current main, PR-head source, tests, history, maintainer notes, or artifacts.
Supplied final-head diff: The supplied GitHub context shows the current head isolates server close, bot stop, transport close, ingress drain, status update, and diagnostics stop through a phase wrapper that logs rejected failures; it also adds a bot-stop rejection regression test.
Supplied proof claim requires inspection: The PR body claims a production-path harness and a focused Vitest pass at the current head, but the previous ClawSweeper review says the referenced evidence could not be inspected or compared with the final head, and this review could not access it either.
Findings None None.
Security None None.

How this fits together

Telegram webhook mode owns a local server, bot, transport, ingress monitor, status publishing, and optional diagnostics. Abort signals and explicit stop calls enter the webhook shutdown path, which should release each resource and leave the channel visibly disconnected.

flowchart LR
  A[Abort signal or stop call] --> B[Telegram webhook shutdown]
  B --> C[Isolate teardown phases]
  C --> D[Server and bot cleanup]
  C --> E[Transport and ingress cleanup]
  C --> F[Status and diagnostics cleanup]
  D --> G[Clean channel shutdown]
  E --> G
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body describes after-fix runtime proof, but this review could not open or compare the evidence with the final head; add or restore an inspectable redacted terminal transcript, logs, or linked artifact showing the injected failure and completed later cleanup, then update the PR body for re-review.
  • Resolve merge risk (P1) - Merging without an inspectable final-head runtime transcript leaves the fire-and-forget shutdown contract unverified: failures may still escape or later teardown could still be skipped on an untraced caller path.
  • Resolve merge risk (P1) - The patch changes an availability-sensitive Telegram lifecycle path; the supplied compact diff cannot establish compatibility with startup-failure and abort-listener paths outside the visible hunk.
  • Complete next step (P2) - The immediate action is human review of final-head source and inspectable behavior proof; no concrete mechanical defect can safely be assigned to an automated repair lane from the available evidence.
Agent review details

Security

None.

PR surface

Source +17, Tests +22. Total +39 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 25 8 +17
Tests 1 22 0 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 8 +39

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Verify final-head shutdown proof (recommended)
    Keep the PR open until a reviewer can inspect final-head source and redacted runtime evidence that a rejected phase does not reject shutdown or skip later cleanup.
  2. Pause pending review access
    Pause rather than merge if the final-head lifecycle and proof artifacts cannot be made inspectable, because this patch changes asynchronous channel shutdown behavior.

Technical review

Best possible solution:

Keep one non-rejecting webhook shutdown owner, verify every shutdown caller against the final head, and attach inspectable redacted after-fix terminal output or logs that show an injected teardown rejection is logged while subsequent transport and status cleanup complete.

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

No high-confidence runtime reproduction is available to this review. The supplied diff and PR body describe a clear failure-injection path, but the final-head harness and its observed output could not be inspected after repository access failed.

Is this the best way to solve the issue?

Unclear. Per-phase error isolation is a maintainable shape for a non-rejecting shutdown path, but the required caller, sibling-path, and final-head proof review could not be completed.

AGENTS.md: unclear because the file could not be read completely.

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

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded Telegram channel reliability repair without evidence of an active emergency or data/security impact.
  • merge-risk: 🚨 availability: The modified abort and teardown sequence can affect whether a Telegram webhook releases resources and completes channel shutdown.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • 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 body describes after-fix runtime proof, but this review could not open or compare the evidence with the final head; add or restore an inspectable redacted terminal transcript, logs, or linked artifact showing the injected failure and completed later cleanup, then update the PR body for re-review.

Evidence

What I checked:

  • Read-only inspection environment failed: The first required repository-read command could not start: bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted. Therefore this review could not independently inspect AGENTS.md, current main, PR-head source, tests, history, maintainer notes, or artifacts.
  • Supplied final-head diff: The supplied GitHub context shows the current head isolates server close, bot stop, transport close, ingress drain, status update, and diagnostics stop through a phase wrapper that logs rejected failures; it also adds a bot-stop rejection regression test. (extensions/telegram/src/webhook.ts:529, 142987eacaae)
  • Supplied proof claim requires inspection: The PR body claims a production-path harness and a focused Vitest pass at the current head, but the previous ClawSweeper review says the referenced evidence could not be inspected or compared with the final head, and this review could not access it either. (extensions/telegram/src/webhook.test.ts:920, 142987eacaae)

Likely related people:

  • vincentkoc: The supplied commit history identifies vincentkoc as author of the current-head rewrite that implements the final Telegram webhook shutdown behavior. (role: recent area contributor; confidence: medium; commits: 142987eacaae, c26c5c592aa3; files: extensions/telegram/src/webhook.ts, extensions/telegram/src/webhook.test.ts)
  • Pick-cat: The supplied commit history attributes the preceding shutdown fixes and regression-test work to Pick-cat, and the current-head commit retains co-author credit. (role: earlier implementation contributor; confidence: medium; commits: 476783de8d11, 0f4cca9de448, 4420fac728cf; files: extensions/telegram/src/webhook.ts, extensions/telegram/src/webhook.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach inspectable, redacted after-fix runtime evidence tied to 142987eacaaee445b7dab2bafc9122a484827bf1.
  • Have a reviewer verify the final-head abort, startup-failure, and normal-stop call paths; after proof is updated, a maintainer can comment @clawsweeper re-review if automatic refresh does not occur.

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 (26 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-13T15:24:08.246Z sha 899a1c3af4c6615a7b08b7f60610c9ee32ce13c9 :: needs real behavior proof before merge. :: [P2] Continue final cleanup when transport close rejects
  • reviewed 2026-07-14T10:49:53.980Z sha f459c82723b33f46f53ed22e2c0d1132ff73d74a :: needs real behavior proof before merge. :: [P2] Keep cleanup running after synchronous shutdown failures
  • reviewed 2026-07-14T11:17:17.732Z sha f459c82723b33f46f53ed22e2c0d1132ff73d74a :: needs real behavior proof before merge. :: [P2] Continue cleanup after synchronous shutdown failures
  • reviewed 2026-07-14T23:57:52.310Z sha fb257d414fae0c5cc8572cba602539120e5abc0d :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-15T00:53:43.593Z sha fb257d414fae0c5cc8572cba602539120e5abc0d :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T03:15:27.525Z sha aac474a46e7803ea688ba9f398c70240b86a7555 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T06:13:53.987Z sha b9353f5 :: needs changes before merge. :: [P2] Guard every early teardown phase before continuing
  • reviewed 2026-07-29T17:10:58.269Z sha 142987e :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 6, 2026
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from 76914e9 to 0bcd6e5 Compare July 6, 2026 23:31
@Pick-cat

Pick-cat commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Patch-quality blockers from the previous review have been addressed and CI is green (check-test-types, check-lint, and Real behavior proof all pass). Please re-evaluate.

@clawsweeper

clawsweeper Bot commented Jul 6, 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.

@Pick-cat

Pick-cat commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Force-pushed an updated head (0bcd6e562e) after addressing the review blockers. Please re-evaluate against the current commit.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 6, 2026
@Pick-cat

Pick-cat commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added a real ClickClack gateway reconnect proof using local HTTP/WebSocket servers driving the production function. The script shows abort resolves a pending 60s reconnect delay in ~50ms, plus a raw-setTimeout negative control for comparison.

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 7, 2026
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from 0bcd6e5 to 3e4ead5 Compare July 7, 2026 00:29
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 7, 2026
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from d13b82c to 29b6a1d Compare July 7, 2026 00:47
@Pick-cat

Pick-cat commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased to latest main (head now 29b6a1d556). PR body includes the real ClickClack gateway reconnect proof with local HTTP/WebSocket servers.

@clawsweeper

clawsweeper Bot commented Jul 7, 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.

@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from 29b6a1d to 7122e7c Compare July 7, 2026 00:49
@clawsweeper clawsweeper Bot added 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 Jul 7, 2026
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch 2 times, most recently from 06d4e7f to 470b751 Compare July 11, 2026 07:25
@clawsweeper

clawsweeper Bot commented Jul 14, 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.

@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from dc6452b to 115b318 Compare July 14, 2026 15:24
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Jul 14, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 14, 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:

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 15, 2026
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from fb257d4 to aac474a Compare July 15, 2026 12:15
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 15, 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:

@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Jul 15, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 16, 2026
Pick-cat and others added 6 commits July 18, 2026 13:49
…rd all cleanup

- Wrap entire shutdown() body in outer try/catch so sync throws never
  produce unhandled rejections from fire-and-forget abort listeners.
- bot.stop() rejection is caught and logged; finally block ensures
  closeTransportOnce(), noteWebhookStop(), and stopDiagnosticHeartbeat()
  always execute regardless of bot.stop() outcome.
- closeTransportOnce() rejection is caught independently in the finally
  block so noteWebhookStop() and stopDiagnosticHeartbeat() are not skipped.
- Startup failure path: bot.stop() and closeTransportOnce() get
  .catch(() => undefined) so cleanup rejections never mask the original
  startup error.
- Both abort-listener call sites use consistent void shutdown() since
  the never-reject contract is now internal.
- Ingress worker stop() shares an in-flight stopPromise for idempotency;
  worker.terminate() rejections are observed via .catch(() => undefined).

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
Extract independently guarded shutdown phases so a synchronous
server.close() failure still runs bot.stop, transport close, status,
and diagnostic heartbeat cleanup. Add sync-throw regression coverage
and a loopback real-behavior proof (negative/positive/valid).
Restore curly-safe drain timer clear, stop exporting the unused
shutdown phases interface, and narrow the transport close spy for
tsgo test types.
telegram-reply-fence.ts was deleted on main (f7786a1) during the
core drain refactor. The rebased webhook.ts no longer calls these
functions; remove the dangling import so the module resolves.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@Pick-cat
Pick-cat force-pushed the fix/channel-bugs-batch-2026-07-06 branch from aac474a to b9353f5 Compare July 18, 2026 06:10
@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Jul 18, 2026
vincentkoc and others added 2 commits July 29, 2026 19:06
Keep each fallible Telegram-owned teardown phase independent so an early failure cannot skip transport, ingress, status, or diagnostic cleanup.

Co-authored-by: Pick-cat <[email protected]>
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

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: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L 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.

2 participants