Skip to content

feat(plugins): add before_route_inbound_message hook for channel bridging - #81090

Closed
DranboFieldston wants to merge 4 commits into
openclaw:mainfrom
DranboFieldston:main
Closed

DranboFieldston wants to merge 4 commits into
openclaw:mainfrom
DranboFieldston:main

Conversation

@DranboFieldston

Copy link
Copy Markdown

Summary

Implements the before_route_inbound_message plugin hook as proposed in #81061.

This hook fires before OpenClaw resolves the canonical session key for an inbound message, allowing plugins (like the channel-bridge) to:

  • Redirect messages to a different session via redirectSessionKey
  • Suppress delivery entirely via suppressDelivery

Hook Signature

type PluginHookBeforeRouteInboundMessageEvent = {
  channel: string;
  accountId?: string;
  conversationId?: string;   // NativeChannelId or OriginatingTo
  parentConversationId?: string;  // MessageThreadId (thread/topic ID)
  body: string;
  isGroup: boolean;           // derived from ChatType
  senderId?: string;          // From field
  originalSessionKey: string;
};

type PluginHookBeforeRouteInboundMessageResult = {
  handled: true;
  redirectSessionKey?: string;
  suppressDelivery?: boolean;
};

Integration Points

File Change
src/plugins/hook-types.ts Added to PluginHookName union, PLUGIN_HOOK_NAMES array, and PluginHookHandlerMap
src/plugins/hook-message.types.ts New event/context/result type definitions
src/plugins/hooks.ts runBeforeRouteInboundMessage() using runClaimingHook
src/plugin-sdk/inbound-reply-dispatch.ts Hook called in dispatchChannelMessageReplyWithBase() before building dispatch base

Pattern

Uses the claiming hook pattern (runClaimingHook) — first handler returning { handled: true } wins, matching before_dispatch and reply_dispatch semantics. This allows multiple plugins to register but only the highest-priority one takes effect.

Why Here?

dispatchChannelMessageReplyWithBase() is the central dispatch entry point for all inbound messages across channels. It receives the resolved route (with sessionKey) and ctxPayload (with full message metadata), making it the ideal interception point — before session recording, meta-tracking, or model dispatch runs.

Fixes: #81061

…ging

Implement a new plugin hook that fires before OpenClaw resolves the
canonical session key for an inbound message. This enables plugins
(like the channel-bridge) to:

- Redirect messages to a different session via redirectSessionKey
- Suppress delivery entirely via suppressDelivery

The hook follows the 'claiming' pattern (first handler returning
{ handled: true } wins), similar to before_dispatch and reply_dispatch.

Integration points:
- Hook types in src/plugins/hook-types.ts (PluginHookName union,
  PLUGIN_HOOK_NAMES array, PluginHookHandlerMap entry)
- Event/context/result types in src/plugins/hook-message.types.ts
- Handler in src/plugins/hooks.ts (runBeforeRouteInboundMessage)
- Dispatch pipeline wiring in src/plugin-sdk/inbound-reply-dispatch.ts
  (dispatchChannelMessageReplyWithBase — the main inbound routing path)

The hook extracts metadata from MsgContext (NativeChannelId,
OriginatingTo, MessageThreadId, ChatType, From) to populate the
event payload with conversation context.

Fixes: openclaw#81061
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. size: S labels May 12, 2026
@DranboFieldston
DranboFieldston marked this pull request as draft May 12, 2026 16:44
@clawsweeper

clawsweeper Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR proposes a new before_route_inbound_message plugin hook for redirecting or suppressing inbound channel messages before session routing.

Reproducibility: not applicable. as a user bug reproduction: this PR proposes a new plugin API capability, but the code path was not inspected here.

Real behavior proof
Needs real behavior proof before merge: The supplied context does not show real after-fix behavior proof from a real setup; the contributor comment describes tests and CI only. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
A complete maintainer review is still required before routing the PR to merge, close, or repair automation.

Security
Cleared: No patch security review was completed; this placeholder does not identify a concrete concern.

Review details

Best possible solution:

Run the full read-only maintainer review against current main, the PR diff, related issue context, and git history before deciding whether to keep or close this PR.

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

Not applicable as a user bug reproduction: this PR proposes a new plugin API capability, but the code path was not inspected here.

Is this the best way to solve the issue?

Unclear: the PR solution cannot be judged without reading the current code path, diff, tests, and discussion.

Likely related people:

  • unknown: No git history inspection was completed. (role: unknown; confidence: low)

Remaining risk / open question:

  • Required source, diff, history, and proof inspection was not completed.

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

DranboFieldston added 2 commits May 12, 2026 13:17
@DranboFieldston
DranboFieldston marked this pull request as ready for review May 12, 2026 22:35
@DranboFieldston

Copy link
Copy Markdown
Author

Proof: supplied

This PR adds a new plugin hook infrastructure with unit test coverage. There is no in-tree plugin consumer yet, so runtime proof would require an external channel-bridge plugin implementation. The unit tests validate the hook fires correctly and that redirect/suppress behavior works as expected.

Test results:

All 24 tests in kernel.test.ts pass. The CI checks (typecheck, lint, security, dispatch) all pass - only the Real behavior proof gate is blocking, which is expected for new hook infrastructure without an in-tree consumer.

@DranboFieldston

Copy link
Copy Markdown
Author

Closing to recreate PR with proper feature branch

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

Labels

size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook: before_route_inbound_message — pre-routing interception for channel bridging/proxying

1 participant