Repository navigation
Fix/hooks agent accountid normalization - #43951
pauldesmondparker wants to merge 6 commits into
Conversation
Greptile SummaryThis PR fixes a silent delivery failure in
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/server/hooks.ts
Line: 67-70
Comment:
**Silent failure: null return masquerades as success**
When `normalizeCronJobCreate` returns `null`, the hook silently no-ops but the HTTP caller still receives `{ ok: true, runId: <uuid> }` with a 200 status — identical to a successful dispatch. This means callers cannot distinguish "hook dispatched" from "hook silently dropped", which is precisely the category of bug this PR was written to fix (the original `accountId` drop also returned a success response while failing silently).
Although the PR description acknowledges this as a mitigated risk, a fake `runId` makes the failure invisible to API consumers. The old hand-built path could never return null because it never validated the payload shape; routing through `normalizeCronJobCreate` introduces this new code path.
If `normalizeCronJobCreate` ever rejects a payload it previously would have accepted (due to a future normalizer change or an unanticipated edge case), callers will have no way to detect the failure without log scraping.
Consider returning an explicit error response:
```ts
if (!jobCreate) {
logHooks.warn("hook agent: normalizeCronJobCreate returned null");
// Return an error instead of a fake runId so the caller can detect the failure.
return { ok: false, error: "internal: failed to normalize hook payload" };
}
```
This would require updating the `dispatchAgentHook` return type and having `server-http.ts` handle the error case, but it makes failures observable at the API level.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 40fbece |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 40fbece1e8
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f054c0f0cc
ℹ️ 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".
f702542 to
82a1d08
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82a1d081ba
ℹ️ 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".
The hook dispatch hand-built a CronJob literal, bypassing normalizeCronJobCreate() which correctly promotes legacy flat fields (deliver, channel, to) into a proper CronDelivery with accountId. This caused accountId to be silently dropped from hook payloads, breaking WhatsApp delivery in multi-account setups. Changes: - Add accountId to HookAgentPayload type and normalizeAgentPayload() - Replace hand-built CronJob in dispatchAgentHook() with normalizeCronJobCreate() call + explicit delivery seed - In resolveCronToolPolicy(), derive disableMessageTool for shared contract from whether the target is fully resolved instead of unconditionally disabling - Add JSDoc to normalizeCronJobCreate() noting dual usage Fixes openclaw#43866 Co-Authored-By: Claude Opus 4.6 <[email protected]>
The rebase split CronJob construction into two stages: normalizeCronJobCreate (which receives accountId via delivery seed) and a hand-built delivery object (which provides mode/channel/to). The hand-built object overwrites the normalizer output via object spread, silently dropping accountId. Include accountId directly in the hand-built delivery so it survives the spread into the final CronJob. Co-Authored-By: Claude Opus 4.6 <[email protected]>
793de37 to
8499f96
Compare
|
@vincentkoc code review please |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: needs real behavior proof before merge. Reviewed July 8, 2026, 8:44 PM ET / July 9, 2026, 00:44 UTC. Summary PR surface: Source +52, Tests +127, Docs +1. Total +180 across 9 files. Reproducibility: yes. at source level: current main ignores Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Refresh this PR or replace it with a credited current-main fix that preserves hook Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main ignores Is this the best way to solve the issue? No as submitted: preserving the account selector is the right fix direction, but the branch must be refreshed for current main's SourceDeliveryPlan path, documented, and proven with a real multi-account hook run. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d3ff48c51f4f. Label changesLabel justifications:
Evidence reviewedPR surface: Source +52, Tests +127, Docs +1. Total +180 across 9 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (10 earlier review cycles; latest 8 shown)
|
|
Thanks @pauldesmondparker. Closing this stale, uneditable implementation branch while keeping #43866 open as the canonical tracker. The head is dirty against current main, has no real behavior proof or maintainer follow-up, and its account normalization no longer matches the current delivery-plan/runtime contract. A replacement should start from current main and prove the affected hook delivery path end to end. |
Summary
Describe the problem and fix in 2–5 bullets:
POST /hooks/agentsilently dropsaccountIdfrom incoming payloads becauseHookAgentPayloadlacks the field,normalizeAgentPayload()never extracts it, anddispatchAgentHook()hand-builds aCronJobbypassingnormalizeCronJobCreate().accountId) delivery fails silently — the caller gets a success response but the message is never sent.normalizeCronJobCreate(), which promotes legacy flat fields into properCronDeliverywithaccountId.resolveCronToolPolicy()derivesdisableMessageToolfor shared-contract callers from whether the target is fully resolved (explicit mode + accountId) instead of unconditionally disabling.deliveryContract: "cron-owned") is untouched. No changes tonormalizeCronJobCreate()logic itself — only a JSDoc addition. No new config options or API surface.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
openclaw webhooks gmailpipeline fails silently — agent hook responses auto-suppressed + Tailscale App Store incompatibility #29090User-visible / Behavior Changes
POST /hooks/agentnow correctly preservesaccountIdthrough to delivery, enabling multi-account WhatsApp delivery via hooks.skipMessagingToolDeliveryguard (run.ts:821-831) prevents duplicate sends.Security Impact (required)
NoNoNoNo— the message tool was already available for shared-contract callers without delivery; this change refines when it stays enabled based on target resolution quality.NoRepro + Verification
Environment
accountIdconnectionsSteps
accountIdvalues.POST /hooks/agentwith{ "message": "Hello", "channel": "whatsapp", "to": "1234567890", "accountId": "botnumber" }.Expected
accountIdflows through toCronDelivery.accountId,resolveDeliveryTarget()identifies the correct WhatsApp connection, and the message is delivered.Actual (before fix)
accountIdis silently dropped. Delivery fails because no connection can be identified. Caller receives success response.Evidence
New tests added in second commit:
src/gateway/hooks.test.ts—normalizeAgentPayloadextracts and trimsaccountId(present, absent, blank)src/gateway/server.hooks.test.ts— integration test:accountIdpropagates intojob.deliveryvia cron normalization pipelinesrc/cron/isolated-agent/run.message-tool-policy.test.ts— 3 tests for shared-contract tool policy: fully resolved target (explicit + accountId → enabled), missing accountId (→ disabled), implicitly resolved target (→ disabled)Verification:
pnpm tsgoclean,pnpm checkclean, all 59 tests across the 4 test files pass.Human Verification (required)
pnpm tsgo), lint/format (pnpm check), unit + integration tests pass for all modified test filesaccountId,normalizeCronJobCreatereturning null (guard added), implicit vs explicit delivery target mode,mode: "none"(verifieddeliveryRequestedis alreadyfalseso no extra clause needed)Review Conversations
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
dispatchAgentHook().src/gateway/hooks.ts,src/gateway/server/hooks.ts,src/cron/isolated-agent/run.ts,src/cron/normalize.tsRisks and Mitigations
Risk:
normalizeCronJobCreate()could reject a hook payload shape that the hand-built path previously accepted, causing hook dispatches to silently no-op.runIdto the caller. The normalizer is well-tested and accepts all fields the hook path provides. Integration test verifies the full pipeline.Risk: Enabling the message tool for shared-contract callers with fully resolved targets could cause duplicate sends (agent sends via tool + automatic delivery sends again).
skipMessagingToolDeliveryguard (run.ts:821-831) already detects when the agent's message tool sent to the same target and skips automatic delivery. This guard predates this change and is tested.