Skip to content

fix(hooks): avoid implicit hook delivery targets - #100486

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
coolmanns:kan/kan-192-hook-delivery-target-binding
Jul 29, 2026
Merged

vincentkoc merged 6 commits into
openclaw:mainfrom
coolmanns:kan/kan-192-hook-delivery-target-binding

Conversation

@coolmanns

@coolmanns coolmanns commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where direct /hooks/agent callers could submit an incomplete delivery target and have the detached run consult unrelated session delivery state or fail only after the request was accepted.

Why This Change Was Made

Direct hook delivery is now normalized before scheduling:

  • no channel and no to schedules completion-only work;
  • exactly one destination coordinate returns HTTP 400 before dispatch;
  • malformed or blank to returns HTTP 400;
  • deliver: false schedules completion-only work and clears supplied destination data;
  • a concrete channel plus non-empty to becomes the explicit announce target.

The prepared delivery fact is carried into the isolated CronJob; later runtime layers do not rediscover webhook intent. Existing mapped-hook configuration keeps its shipped channel: "last" and partial-target behavior, so this PR does not introduce a mapping migration.

The maintainer rewrite also removes two unrelated CLI-test commits from the PR diff and preserves @coolmanns as co-author.

User Impact

Direct webhook callers get deterministic validation and cannot accidentally announce into an unrelated prior conversation. Existing hook mappings retain their current delivery semantics.

Evidence

Exact head: 7d6169a51c0d44151bef2d9f26f3ba5cdba6614e

  • Net PR surface is hook-only: 8 files, +450/-22.
  • 45 focused Gateway hook tests passed on the patch-identical maintainer GWT.
  • 133 broader Gateway and cron delivery tests passed on the same reviewed patch.
  • After exact-head CI identified a dead test-only export and one formatting mismatch, the helper was made module-private and formatted with oxfmt; all 27 focused helper tests passed and final full-branch autoreview remained clean at 0.91 confidence.
  • The tests cover direct and mapped request matrices, malformed recipients, deliver: false destination clearing, normalized scheduler payloads, and the actual CronJob handoff.
  • Targeted oxlint, docs inventory, and git diff --check passed.
  • Fresh autoreview reported no actionable findings at 0.94 confidence.
  • Exact-head hosted CI and the repository real-behavior workflow are running and remain required before merge.
  • Blacksmith Testbox was unavailable because the local client was not authenticated; trusted-source focused proof used the documented local fallback.
  • Release-note context is captured here; root CHANGELOG.md remains release-owned.

@clawsweeper

clawsweeper Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 10:46 AM ET / 14:46 UTC.

ClawSweeper review

What this changes

This PR validates direct /hooks/agent delivery coordinates before scheduling, passes a prepared completion-only or announce delivery fact into the cron job, and documents the direct-hook contract while retaining mapped-hook semantics.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The patch appears to correctly bind direct hook delivery before detached work is accepted, preventing the cron layer from consulting unrelated session delivery state. It deliberately changes accepted direct channel-only requests into immediate HTTP 400 responses, so keep this PR open for explicit maintainer confirmation of that compatibility choice and a current-main rebase before merge.

Priority: P1
Reviewed head: 7d6169a51c0d44151bef2d9f26f3ba5cdba6614e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-tested gateway/cron boundary repair with sufficient proof, pending an explicit compatibility decision and merge-head refresh.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR carries the repository proof: sufficient label, its exact-head Real behavior proof workflow completed successfully, and the supplied evidence covers the direct and mapped request matrices plus CronJob handoff.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR carries the repository proof: sufficient label, its exact-head Real behavior proof workflow completed successfully, and the supplied evidence covers the direct and mapped request matrices plus CronJob handoff.
Evidence reviewed 6 items Direct-hook boundary: The branch adds a delivery-normalization step that treats omitted coordinates as completion-only, rejects partial or blank coordinates before dispatch, and only creates announce delivery for a concrete channel plus recipient.
Prepared fact reaches the detached owner: The gateway cron-job creator now consumes the prepared delivery value instead of rebuilding it from separate request fields; the accompanying test asserts that the isolated CronJob receives that value.
Mapped hooks remain intentionally separate: Mapped hooks continue to construct their established delivery form, while the documentation distinguishes mapped channel: "last" behavior from the stricter direct endpoint contract.
Findings None None.
Security None None.

How this fits together

The Gateway accepts authenticated hook requests and schedules isolated agent work as cron jobs. Delivery intent must be decided at the HTTP boundary so the detached runner either announces to an explicit destination or produces a completion-only result without inheriting prior-session recipients.

flowchart LR
  A[Webhook caller] --> B[Gateway hook endpoint]
  B --> C[Validate delivery coordinates]
  C --> D[Prepared delivery fact]
  D --> E[Detached cron job]
  E --> F[Isolated agent run]
  F --> G[Completion event or explicit announcement]
Loading

Decision needed

Question Recommendation
Should direct /hooks/agent requests that specify only a concrete channel be intentionally migrated from accepted asynchronous work to an immediate HTTP 400, while mapped hooks retain their established partial-target behavior? Approve explicit direct targets: Keep the immediate HTTP 400 for channel-only or recipient-only direct requests, preserving the safer no-implicit-recipient boundary.

Why: This prevents session-derived recipient selection, but it also changes an existing public webhook request outcome and cannot be inferred solely from code correctness.

Before merge

  • Resolve merge risk (P1) - Direct callers that previously supplied only a concrete channel will receive HTTP 400 rather than an accepted asynchronous run; this is a deliberate API compatibility change that needs explicit owner acceptance.
  • Resolve merge risk (P1) - The branch is behind current main; merge after rebasing and refreshing the focused direct/mapped hook and cron-delivery evidence against the exact merge head.
Agent review details

Security

None.

PR surface

Source +78, Tests +335, Docs +11. Total +424 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 97 19 +78
Tests 3 337 2 +335
Docs 2 12 1 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 446 22 +424

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Confirm the direct-hook migration before merge (recommended)
    Obtain explicit owner acceptance that direct partial delivery becomes a synchronous HTTP 400, then rebase and refresh the focused delivery matrix on the merge head.
  2. Keep a compatibility contract for partial direct requests
    If accepted channel-only direct hooks must remain supported, define a non-session-derived behavior and add focused tests before merging.
  3. Pause the API change
    Close or defer this branch if maintainers do not want to change direct webhook caller outcomes without a broader compatibility plan.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Confirm the intentional direct-hook partial-target HTTP 400 compatibility change, then rebase onto current main and rerun the focused hook and cron delivery matrix on the exact merge head.

Technical review

Best possible solution:

Approve the fail-before-scheduling contract only if maintainers intend to retire accepted partial direct delivery, then rebase onto current main and retain the direct-versus-mapped matrix tests and documentation as the canonical compatibility contract.

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

Yes, source-reproducible: the old boundary rebuilt announce delivery from independently normalized request fields, whereas this branch binds the direct request to a prepared delivery fact before CronJob scheduling. The provided focused Gateway and cron tests cover the relevant coordinate matrix, but this read-only review did not execute a current-main runtime reproduction.

Is this the best way to solve the issue?

Yes, conditionally: normalizing direct webhook delivery at the Gateway boundary is the narrowest owner boundary because later detached layers should not rediscover request intent. The remaining question is whether the intentional HTTP 400 migration for partial direct requests is the approved public contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR affects a live Gateway hook workflow where an existing caller can change from accepted asynchronous execution to an immediate failure.
  • merge-risk: 🚨 compatibility: Direct /hooks/agent callers that supply only one delivery coordinate receive a new HTTP 400 response.
  • merge-risk: 🚨 message-delivery: The patch changes whether a detached hook run becomes completion-only, fails before dispatch, or announces to a channel.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR carries the repository proof: sufficient label, its exact-head Real behavior proof workflow completed successfully, and the supplied evidence covers the direct and mapped request matrices plus CronJob handoff.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR carries the repository proof: sufficient label, its exact-head Real behavior proof workflow completed successfully, and the supplied evidence covers the direct and mapped request matrices plus CronJob handoff.

Evidence

What I checked:

  • Direct-hook boundary: The branch adds a delivery-normalization step that treats omitted coordinates as completion-only, rejects partial or blank coordinates before dispatch, and only creates announce delivery for a concrete channel plus recipient. (src/gateway/hooks.ts:272, 7d6169a51c0d)
  • Prepared fact reaches the detached owner: The gateway cron-job creator now consumes the prepared delivery value instead of rebuilding it from separate request fields; the accompanying test asserts that the isolated CronJob receives that value. (src/gateway/server/hooks.ts:170, 7d6169a51c0d)
  • Mapped hooks remain intentionally separate: Mapped hooks continue to construct their established delivery form, while the documentation distinguishes mapped channel: "last" behavior from the stricter direct endpoint contract. (src/gateway/server/hooks-request-handler.ts:366, 7d6169a51c0d)
  • Compatibility change needs an owner decision: The previous ClawSweeper review identifies the concrete behavior change: existing direct callers that provide only a concrete channel move from an accepted asynchronous request to an immediate HTTP 400. The PR documentation now describes that fail-before-scheduling behavior. Public docs: docs/automation/cron-jobs.md. (docs/automation/cron-jobs.md:534, 7d6169a51c0d)
  • Review-head provenance: The current branch head was produced by the hook-delivery maintainer rewrite; the latest commit formats the same internal helper after the earlier binding commits. (src/gateway/hooks.ts:272, 7d6169a51c0d)
  • Related work is distinct: The merged detached-session repair addresses persisted transcript initialization, while this PR addresses webhook delivery normalization; the merged PR explicitly describes the separation. (src/gateway/server/hooks.ts:170, 02f7c7ada366)

Likely related people:

  • vincentkoc: Authored the six commits on the current PR head, including the hook-delivery binding and subsequent narrowing/internalization work; also assigned and force-pushed the maintained branch. (role: recent area contributor; confidence: high; commits: 9846c012749f, 14a37e99f6f8, e14598a494a5; files: src/gateway/hooks.ts, src/gateway/server/hooks.ts, src/gateway/server/hooks-request-handler.ts)
  • coolmanns: Opened the PR and is credited as co-author on the maintained hook-delivery commits; their report and earlier repair notes define the direct-hook privacy scenario. (role: original problem contributor; confidence: medium; commits: 9846c012749f, 14a37e99f6f8; files: src/gateway/hooks.test.ts, src/gateway/server-http.hooks-delivery.test.ts)

Rank-up moves

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

  • Record owner acceptance of the direct partial-target HTTP 400 contract.
  • Rebase onto current main and refresh focused direct/mapped hook and cron-delivery proof on the exact merge head.

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 (3 earlier review cycles)
  • reviewed 2026-07-05T23:09:40.025Z sha b4f8d45d769d44df1aece8fb27ee04daa4435446 :: needs real behavior proof before merge. :: [P2] Preserve validation for partial explicit targets
  • reviewed 2026-07-12T05:00:51.558Z sha 775912b4480c012d688aca2d1a30465fa467bfc0 :: needs real behavior proof before merge. :: [P2] Document channel-only hooks as fail-closed, not disabled
  • reviewed 2026-07-29T12:58:51.149Z sha 20597ec :: needs maintainer review 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. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 5, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared July 5, 2026 23:12 Inactive
@coolmanns

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Author update: preserve partial delivery intent without inheriting session recipients

Exact head: eedc06e6c9a50745cd2efc53d82c91d5f28a3c56

Repair

  • Rebases/merges current main and resolves the stale Gateway/cron test conflicts.
  • Truly targetless hooks and to-only hooks with channel: last use delivery.mode: none, so they cannot select the main session channel/account.
  • A concrete channel remains announce even when to is missing, so the cron delivery resolver—not the Gateway predicate—returns the fail-closed validation/refusal result.
  • Explicit channel + to remains direct announce delivery.
  • Direct and mapped hook paths share the same dispatch predicate.

TDD evidence

  • RED before repair: direct and mapped channel-only hooks both produced { mode: "none" } instead of announce.
  • RED before final hardening: bare to: "123456" with normalized channel: "last" produced announce; it now produces none.
  • Shared-main privacy proof seeds lastChannel: "telegram" and lastTo: "sensitive-recipient"; resolveDeliveryTarget returns ok:false, to:undefined, and the shared-main refusal without exposing the recipient.

Verification on pushed behavior

  • node scripts/test-projects.mjs src/gateway/server.hooks.test.ts src/cron/isolated-agent/delivery-target.test.ts → 110 passed (54 Gateway across both projects + 56 cron resolver).
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo → pass.
  • Path-scoped git diff --check → pass.
  • Final committed branch autoreview against origin/main → patch correct, no findings, confidence 0.89.

The previously requested redacted live Gateway transcript remains outstanding; the changed direct/mapped and resolver contracts are covered deterministically above.

@clawsweeper

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

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 28, 2026
@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@vincentkoc
vincentkoc force-pushed the kan/kan-192-hook-delivery-target-binding branch from 775912b to 2bf23a9 Compare July 29, 2026 06:46
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 29, 2026
@vincentkoc
vincentkoc force-pushed the kan/kan-192-hook-delivery-target-binding branch 4 times, most recently from f12d91c to b2ab65e Compare July 29, 2026 07:46
@vincentkoc
vincentkoc force-pushed the kan/kan-192-hook-delivery-target-binding branch from b2ab65e to 9846c01 Compare July 29, 2026 08:39
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Jul 29, 2026
@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: 🧂 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. labels Jul 29, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Jul 29, 2026
@clawsweeper clawsweeper Bot removed the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jul 29, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer decision: accept the explicit direct-hook delivery contract.

Direct /hooks/agent requests with only one delivery coordinate now fail with HTTP 400 before scheduling. Requests with no destination remain completion-only, concrete channel plus to values announce to that destination, and mapped hooks retain their shipped partial-target and last behavior.

This is the intended compatibility boundary for this PR.

@vincentkoc
vincentkoc merged commit 819961a into openclaw:main Jul 29, 2026
125 of 128 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* fix(gateway): bind hook delivery before scheduling

Co-authored-by: Sascha Kuhlmann <[email protected]>

* test(cli): make stderr tail fixture deterministic

* test(cli): allow loaded runners to start

* fix(gateway): narrow hook delivery binding

Co-authored-by: Sascha Kuhlmann <[email protected]>

* fix(gateway): keep hook delivery normalization internal

* style(gateway): format hook delivery helper

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M stale Marked as stale due to inactivity status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants