Repository navigation
Description
Summary
Extensions that register api.on("message_sending", ...) — the documented seam for
inspecting/rewriting/cancelling outbound messages — are silently never invoked on the
main agent-reply delivery paths for channels that supply their own
dispatcherOptions.beforeDeliver. Telegram does, so on Telegram every direct
conversational agent reply bypasses all plugin message_sending hooks. No error or
log indicates the bypass; the plugin loads and registers normally.
This defeats safety/guard extensions (content filters, DLP, compliance rewrites)
without any observable failure.
Mechanism (three independent layers)
Verified in 2026.5.26 dist; layer 1 re-verified in 2026.6.1.
- Channel
beforeDelivershadows the plugin-hook seam.- 2026.5.26
dispatch-*.js:
const configuredBeforeDeliver = params.dispatcherOptions.beforeDeliver ?? buildMessageSendingBeforeDeliver(finalized);
The Telegram bot bundle passes a no-opbeforeDeliver: async (payload) => payload
on both its agent-reply dispatch and native-command delivery paths, so the??
never reachesbuildMessageSendingBeforeDeliver— the function that runs plugin
message_sendinghooks (cancel- and rewrite-capable). - 2026.6.1
dispatch-*.js: reworked to
combineBeforeDeliverHooks(...), but whenparams.dispatcherOptions.beforeDeliver
is set it composes ONLYreplyPayloadBeforeDeliverwith it —
buildMessageSendingBeforeDeliverlives solely in theglobalBeforeDeliver
branch used when the channel supplies nothing. The Telegram no-ops are still
present. Same net effect.
- 2026.5.26
- Stream-finalized (draft/preview) agent finals bypass delivery hooks entirely.
The preview-finalized path emits only the internalmessage:sentevent and never
traversesdeliverReplies, so even a restored seam in layer 1 would not cover
streamed finals. - Remaining
message_sendingcall sites fail silent. The in-deliverRepliesand
outbound-queue sites are guarded by
getGlobalHookRunner()?.hasHooks("message_sending")with optional chaining — a
null runner or empty registry skips with no diagnostic.
Reproduction
- Install a minimal extension:
api.on("message_sending", (p) => { console.log("MS-HOOK", p?.content?.slice(0,20)); }) - Confirm the extension loads (registration log line appears at gateway start).
- Send any DM to a Telegram-connected agent and receive its conversational reply.
- Observe: reply is delivered;
MS-HOOKnever logs. An internal-registry
message:senthook (hooks.internal.entries) DOES fire for the same send,
confirming the send traversed the instrumented path.
Impact
- Any guard/filter extension relying on
message_sendingis silently inert for
channel agent replies — the highest-volume outbound class. - Because registration succeeds and there is no bypass diagnostic, operators have no
signal that their safety layer is offline. We ran ~12 days before catching it via
unrelated instrumentation.
Suggested fixes (any subset helps)
- Compose channel-supplied
beforeDeliverWITHbuildMessageSendingBeforeDeliver
(the 2026.6.1combineBeforeDeliverHooksshape makes this a one-line change). - Run plugin
message_sending(or an equivalent) on the preview-finalized path
before the visible final is committed. - Emit a one-time startup warning when
message_sendinghooks are registered but a
channel supplies an overridingbeforeDeliver— make the bypass observable.
Environment
openclaw 2026.5.26 (npm), reproduced against 2026.6.1 dist; Telegram channel;
extensions registered via plugins.allow + plugins.entries.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 12, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 26, 2026, 2:11 PM ET / 18:11 UTC.
Summary
Keep this issue open. Current main contains a merged partial repair for normal routed replies, but its own merge context explicitly leaves provider-owned finalization paths outside that change; the remaining Telegram preview-finalized path is still tracked by an open draft candidate and needs a maintainer decision on the exact pre-send boundary.
Reproducibility: no. end-to-end run was performed in this read-only review, but the remaining behavior is source-reproducible: merged current-main routing handles normal replies while provider-owned preview finalization remains outside that route.
Root-cause cluster
Relationship:
canonicalCanonical: #92374
Summary: This issue remains the canonical report for the missing pre-send guard on channel agent replies; current main fixed only the normal routed slice, while the open candidate targets the outstanding provider-finalized path.
Members:
partial_overlap: fix(channels): run outbound hooks on routed agent replies #113448 - Merged current-main work restores the hook on normal routed replies but intentionally excludes provider-owned finalization.fixed_by_candidate: fix(plugins): run message_sending on all channel agent-reply deliveries (#92374) #93216 - Open draft candidate attempts the remaining configured-delivery and preview-finalization coverage, but is not yet a safe landing path.adjacent_distinct: [Bug]: Telegram partial-stream finalization lacks clear delivery-mode observability (sent vs preview-finalized vs canceled) #49889 - It concerns observability of Telegram preview finalization rather than the pre-send guard’s invocation guarantee.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Ways to help us reproduce this
Maintainer decision needed
message_sendingguard, or should the repository first define a broader public provider-finalization hook contract?Why: Current main deliberately leaves provider-owned finalization outside the shared route, while the open candidate changes exactly-once and streaming visibility semantics; the permanent boundary cannot be chosen safely from a bug report alone.
Next step
A merged partial repair and an open complete-scope candidate already exist; maintainer selection of the provider-finalization boundary is required before another repair branch is appropriate.
Security
Needs attention: The unresolved path can bypass a cancellation and rewrite boundary used by safety plugins, so the remaining provider-finalization behavior needs explicit security-boundary review.
Review details
Best possible solution:
Keep the merged normal-routed-reply coverage and land a narrow follow-up that invokes the same guard exactly once at each provider-owned finalization boundary, with documented cancellation and rewrite behavior for streamed replies.
Do we have a high-confidence way to reproduce the issue?
No end-to-end run was performed in this read-only review, but the remaining behavior is source-reproducible: merged current-main routing handles normal replies while provider-owned preview finalization remains outside that route.
Is this the best way to solve the issue?
Yes for the direction, but not for any unchanged open branch: preserve the merged routed-reply fix and add an exactly-once provider-finalizer repair after the maintainer selects the ownership boundary.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against c16c0dbef4bc.
Label changes
Label changes:
clawsweeper:needs-product-decision: Current issue advisory state selects this label.Label justifications:
P1: The remaining path can silently bypass a safety-critical pre-send hook on ordinary channel agent replies.impact:security: Registered filtering, DLP, or compliance plugins can be inactive without an error when this path bypassesmessage_sending.impact:message-loss: The missing cancellation or rewrite gate can let an unintended outbound reply reach a channel.Evidence reviewed
Security concerns:
src/channels/turn/lifecycle.ts:240A provider-owned finalization path that bypasses
message_sendingcan deliver content that installed filtering or compliance plugins were expected to inspect, rewrite, or cancel.Confidence: 0.91
What I checked:
message_sendingcoverage for normal routed replies, but its merge description says provider-owned finalization remains outside the common route and that this issue should remain open for the remaining slice. (src/channels/turn/lifecycle.ts:240, c9bbf1d97386)src/channels/plugins/index.ts:374, f716e102771d)src/channels/turn/lifecycle.ts:240, b474f429f7f6)Likely related people:
src/channels/turn/lifecycle.ts,src/channels/plugins/index.ts)src/channels/turn/lifecycle.ts)src/channels/turn/lifecycle.ts,src/channels/plugins/index.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.4 remaining items
chrismclarnon-ep commentedon Jul 29, 2026
Real-world reproduction evidence — OpenClaw 2026.6.9, Telegram DM channel
We are running OpenClaw 2026.6.9 (
c645ec4) with a dedicated Telegram DM channel as our primary interface. We built a minimal proof plugin specifically to verify #92374 against our live install. Results confirm the bypass is fully reproducible and present in 2026.6.9.Plugin
Plain ESM, no build step required:
Plugin manifest (
openclaw.plugin.json) setsactivation.onStartup: true. Registered viaplugins.entriesinopenclaw.json.Observed result
HOOK_FIREDnever appears. The plugin registered successfully on 8 gateway starts across a ~40-minute active session window. During that window, multiple conversational agent replies were delivered to the Telegram DM channel (confirmed via Telegram receipt). Zero invocations of themessage_sendinghandler were logged.This is a clean reproduction of the bypass: plugin loads, hook registers, gateway confirms it, Telegram agent replies deliver — and the hook is never called.
Environment
c645ec4)plugins.entries+plugins.allowinopenclaw.jsonImpact we experience
Because
message_sendingis permanently bypassed on this channel:Ask
New fix PR — the suffix re-entry defect identified by ClawSweeper at
extensions/telegram/src/lane-delivery-text-deliverer.ts:445needs to be addressed before merge. The three options ClawSweeper outlined (fix suffix re-entry / accept duplicate / split dispatcher from streaming) are all viable directions.We can provide Telegram Desktop screen recordings showing delivery of agent replies with no hook invocation, if that strengthens the proof requirement. Happy to run additional test variants (long streamed reply, short reply, cron-triggered reply) on request.
This is a P1 for anyone running safety/DLP/guard plugins on Telegram — the bypass is invisible (no error, hook registers normally), so operators have no signal their safety layer is offline.
cc @vincentkoc @joshavant @amknight
openclaw-barnacle commentedon Jul 29, 2026
Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd
vincentkoc commentedon Jul 29, 2026
Fixed on current
mainand inv2026.7.2-beta.5by:outbound modifying hooks on routed channel replies.
provider previews from exposing content before rewrite/cancellation.
The provider-owned Telegram delivery funnel now runs rewrite/cancellation
before native send, and modifying hooks suppress provider-visible previews.
Ordering, cancellation, no-double-hook, and preview-safety coverage are in the
landed changes.
v2026.7.1remains affected; users need the newer beta or alater stable release.
chrismclarnon-ep commentedon Jul 31, 2026
Fix Incomplete for Telegram DM Path — Confirmed on v2026.7.2-beta.5 (31-07-2026)
TL;DR: PRs #113448 and #114822 landed in
v2026.7.2-beta.5, butmessage_sendingandreply_payload_sendinghooks still do not fire on the Telegram Direct Message agent-reply path. We have confirmed this with a live proof plugin and exact source evidence. Requesting this be treated as a release blocker before the next stable version ships.Environment
2026.7.2-beta.5(ee929db)gate-livefire-sentinel— minimal ESM plugin,activation.onStartup: true, registersapi.registerHook("reply_payload_sending", handler)andapi.registerHook("message_sending", handler)What We Tested
We built a proof plugin (
gate-livefire-sentinel) specifically to live-fire test this issue afterv2026.7.2-beta.5shipped. The plugin:register()line to a proof log on every startupHOOK_FIREDline on every handler invocation[sentinel-hook-fired ✓]to any reply containingZZMUTATEZZ(mutate test)ZZCANCELZZ(cancel test)Test procedure: Send
ZZMUTATEZZas a plain Telegram DM inbound message → natural agent reply cycle → observe whether proof log containsHOOK_FIREDand whether the Telegram reply has[sentinel-hook-fired ✓]appended.Result on
reply_payload_sending:register()fires correctly on every gateway startup ✅HOOK_FIREDnever appears in the proof log ❌[sentinel-hook-fired ✓]appended ❌Result on
message_sending(previously tested onv2026.6.9and re-confirmed onv2026.7.2-beta.5):Root Cause — Updated and More Precise
After the initial comment, we traced the full delivery path in more detail. This updates and sharpens the root cause.
Step 1 —
deliverRepliesalready runsmessage_sendinghooks correctly.Confirmed in
delivery-Ba4AgTnb.js:This is correct —
deliverRepliesIS hook-aware. If the DM path calleddeliverReplies, our hook would fire.Step 2 — The Telegram DM path never reaches
deliverReplies.The DM path goes through
runTelegramDispatchTurn→runChannelInboundEventwith this delivery closure:params.reply.deliveris a per-turn closure constructed by the ingress drain factory. It does not calldeliverReplies. It bypasses the hook-aware delivery path entirely.Step 3 — The kernel fast-paths on
deliverWithProviderMessageSendingwithout going through the hook runner.kernel-BxP091Wr.jsline 837 detectsdeliverWithProviderMessageSendingon the delivery object and fast-paths, bypassingapplyRoutedDirectMessageSending()— the function that would otherwise applyreply_payload_sendinghooks.Combined effect: Two independent bypass mechanisms, both active on the Telegram DM path:
deliverWithProviderMessageSendingpresence → kernel fast-paths, skippingreply_payload_sendingparams.reply.deliver→ raw closure, notdeliverReplies, skippingmessage_sendingNeither hook fires. The hook runner holds both registrations (
hasHooksreturnstruefor both), but there is no attachment point on this path for either.What the Fix Actually Needs to Do
The fix is more specific than "add
appendBeforeDeliverto the dispatcher." The real requirement is:The Telegram DM delivery closure (
params.reply.deliver) must route throughdeliverReplies(or a hook-aware equivalent) rather than bypassing it.Specifically, either:
Option A: Replace the raw
params.reply.deliverclosure inrunTelegramDispatchTurnwith a call todeliverReplies(which is already hook-aware). This is the minimal change —deliverRepliesalready has the full hook machinery; it just needs to be on the DM path.Option B: Wrap the
deliverWithProviderMessageSendingfast-path inkernel-BxP091Wr.jsto explicitly runrunMessageSendingandrunReplyPayloadSendingbefore handing off — making the fast-path hook-aware rather than hook-bypassing.Option C: Remove the
deliverWithProviderMessageSendingproperty from the Telegram DM delivery object, letting the kernel fall through toapplyRoutedDirectMessageSending()— which does applyreply_payload_sending. This is the smallest surface change and least likely to break anything else.Option C is the lowest-risk path: the
deliverWithProviderMessageSendingfast-path appears to have been added as an optimisation, but it silently disables the hook contract. Removing it from the DM path restores correct hook behavior with minimal code change.Why This Matters
The Telegram DM path is the primary production agent-reply path for a large class of OpenClaw deployments. Without a working pre-delivery hook on this path, plugin authors cannot:
The hook contract is documented. Plugins registering
message_sendingandreply_payload_sendingare given no indication that these hooks are silently dead on the most common delivery path.Suggested Priority
We are requesting this be treated as a release blocker for the next stable version. The fix in
v2026.7.2-beta.5resolved the issue for some paths but left the Telegram DM path — arguably the most common production path — broken with two independent bypass mechanisms active simultaneously.We are happy to test a fix branch against our live Telegram DM setup and confirm the proof plugin fires correctly.
Reproducer
Add to
openclaw.jsonplugins.entries, restart, sendZZMUTATEZZas a Telegram DM. Expected: reply has[sentinel-hook-fired ✓]appended. Actual onv2026.7.2-beta.5: no mutation, noHOOK_FIREDlog entry.Note:
deliverRepliesindelivery-Ba4AgTnb.jsalready callsrunMessageSendingcorrectly —hasHooks("message_sending")returnstrue. The bug is that the Telegram DM path never reachesdeliverReplies./cc @vincentkoc — updated with more precise root cause. The two bypass mechanisms active on the DM path are independent; Option C (remove
deliverWithProviderMessageSendingfrom the DM delivery object) is likely the lowest-risk fix.fix(plugins): run message_sending on all channel agent-reply deliveri…