Skip to content

fix(hooks): preserve accountId in /hooks/agent dispatch (closes #43866) - #46124

Closed
Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/43866
Closed

Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/43866

Conversation

@Br1an67

@Br1an67 Br1an67 commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: /hooks/agent silently drops accountId from payloads, causing multi-account channel delivery to fail silently (caller gets success but message never sent).
  • Why it matters: All users calling /hooks/agent with multi-account WhatsApp or any channel requiring accountId are affected.
  • What changed: Added accountId to HookAgentPayload type and threaded it through normalization into CronJob delivery config.
  • What did NOT change (scope boundary): Cron job creation path, normal message delivery.

Change Type

  • Bug fix

Scope

  • Gateway / orchestration
  • Cron / scheduling

Linked Issue/PR

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Steps

  1. Configure two WhatsApp connections with distinct accountId values
  2. POST /hooks/agent with accountId field
  3. Check if message is delivered to correct connection

Expected

  • accountId preserved, correct connection used

Actual (before fix)

  • accountId dropped, delivery fails silently

Evidence

  • Failing test/log before + passing after

Human Verification

  • Verified scenarios: pnpm build + pnpm check + pnpm test all passing
  • Edge cases checked: missing accountId (backward compatible), single-account setup
  • What you did NOT verify: runtime end-to-end with actual WhatsApp

Compatibility / Migration

  • Backward compatible? Yes (accountId is optional)
  • Migration needed? No

Failure Recovery

  • How to disable/revert: revert this commit

Risks and Mitigations

None


This PR was AI-assisted (fully tested with pnpm build/check/test).

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Mar 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6196656969

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server/hooks.ts Outdated
Comment on lines +73 to +75
...(value.accountId
? { delivery: { mode: "announce" as const, accountId: value.accountId } }
: {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve deliver=false when accountId is provided

Adding job.delivery unconditionally when accountId is present changes delivery semantics for /hooks/agent: requests with deliver: false now still request announce delivery, because resolveCronDeliveryPlan treats any job.delivery.mode === "announce" as delivery requested and ignores payload.deliver. In practice, a caller that explicitly disables delivery but includes accountId (for routing context) will still send outbound messages, which is a behavioral regression and can leak outputs to channels unexpectedly.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a real bug where accountId was silently dropped from /hooks/agent payloads, preventing multi-account channel routing (e.g. WhatsApp with multiple connections). The fix correctly adds accountId to HookAgentPayload, parses it in normalizeAgentPayload, and threads it into the CronJob's delivery config so resolveCronDeliveryPlan picks it up via its job.delivery.accountId path.

Key findings:

  • The type addition and normalization in src/gateway/hooks.ts are clean and follow existing patterns.
  • The server-side wiring in src/gateway/server/hooks.ts has one edge-case behavioral issue: the new delivery block hardcodes mode: "announce", which causes resolveCronDeliveryPlan to skip the payload.deliver field entirely (since hasDelivery is now true). A caller who sends deliver: false alongside accountId will still get delivery — contradicting their explicit intent. In practice this is unlikely (why provide accountId if you don't want delivery?), but it is a correctness regression worth guarding against.

Confidence Score: 3/5

  • Safe to merge for the primary use-case; has a minor behavioral edge case when deliver: false and accountId are combined.
  • The core fix is correct — accountId is now preserved and routed through resolveCronDeliveryPlan as intended. The one issue is that hardcoding mode: "announce" in the new delivery block overrides deliver: false when accountId is present. This is a narrow edge case but represents a real behavioral change from pre-fix behavior. The PR is otherwise well-scoped, backward-compatible, and follows codebase patterns.
  • src/gateway/server/hooks.ts — the mode: "announce" override when accountId is present.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server/hooks.ts
Line: 73-75

Comment:
**`deliver: false` silently ignored when `accountId` is present**

The spread unconditionally sets `delivery.mode = "announce"` whenever `accountId` is provided. In `resolveCronDeliveryPlan`, once `hasDelivery` is `true` the `payload.deliver` field is completely bypassed and `requested` is always `true` (`requested: resolvedMode === "announce"`).

This means a caller who sends `{ deliver: false, accountId: "x", channel: "whatsapp" }` will still get delivery after this fix, silently contradicting their explicit `deliver: false` intent.

A safer approach respects the original `deliver` flag:

```suggestion
      ...(value.accountId
        ? {
            delivery: {
              mode: value.deliver !== false ? ("announce" as const) : ("none" as const),
              accountId: value.accountId,
            },
          }
        : {}),
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 6196656

Comment thread src/gateway/server/hooks.ts Outdated
Comment on lines +73 to +75
...(value.accountId
? { delivery: { mode: "announce" as const, accountId: value.accountId } }
: {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deliver: false silently ignored when accountId is present

The spread unconditionally sets delivery.mode = "announce" whenever accountId is provided. In resolveCronDeliveryPlan, once hasDelivery is true the payload.deliver field is completely bypassed and requested is always true (requested: resolvedMode === "announce").

This means a caller who sends { deliver: false, accountId: "x", channel: "whatsapp" } will still get delivery after this fix, silently contradicting their explicit deliver: false intent.

A safer approach respects the original deliver flag:

Suggested change
...(value.accountId
? { delivery: { mode: "announce" as const, accountId: value.accountId } }
: {}),
...(value.accountId
? {
delivery: {
mode: value.deliver !== false ? ("announce" as const) : ("none" as const),
accountId: value.accountId,
},
}
: {}),
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server/hooks.ts
Line: 73-75

Comment:
**`deliver: false` silently ignored when `accountId` is present**

The spread unconditionally sets `delivery.mode = "announce"` whenever `accountId` is provided. In `resolveCronDeliveryPlan`, once `hasDelivery` is `true` the `payload.deliver` field is completely bypassed and `requested` is always `true` (`requested: resolvedMode === "announce"`).

This means a caller who sends `{ deliver: false, accountId: "x", channel: "whatsapp" }` will still get delivery after this fix, silently contradicting their explicit `deliver: false` intent.

A safer approach respects the original `deliver` flag:

```suggestion
      ...(value.accountId
        ? {
            delivery: {
              mode: value.deliver !== false ? ("announce" as const) : ("none" as const),
              accountId: value.accountId,
            },
          }
        : {}),
```

How can I resolve this? If you propose a fix, please make it concise.

…law#43866)

HookAgentPayload was missing the accountId field, causing
normalizeAgentPayload() to silently drop it. Multi-account channel
delivery (especially WhatsApp) would fail because the delivery target
couldn't identify the correct connection.

Added accountId to HookAgentPayload and threaded it through
dispatchAgentHook into the CronJob delivery config.

Co-authored-by: Copilot <[email protected]>
@Br1an67

Br1an67 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing to manage active PR count. Will reopen when slot is available.

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

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /hooks/agent silently drops accountId — hook dispatch bypasses cron normalization pipeline

1 participant