Skip to content

fix(hooks): route mapped wakes to configured sessions - #116109

Merged
vincentkoc merged 1 commit into
mainfrom
fix-hook-wake-routing-64556
Jul 29, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix-hook-wake-routing-64556

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Closes #64556

What Problem This Solves

Fixes an issue where users configuring agentId or sessionKey on a mapped action: "wake" hook would receive a successful response, but the event was silently queued for the default main session instead of the configured agent and session.

Why This Change Was Made

Mapped wake routing now carries the configured target through the existing hook agent/session policy, canonicalizes the event queue key and heartbeat target together, and preserves the legacy default-main behavior for untargeted mappings.

Custom session keys remain restricted to immediate wakes because deferred heartbeat routing cannot safely drain arbitrary custom-session queues. Explicit templated session keys that render empty fail closed instead of falling through to the main session.

User Impact

Multi-agent hook mappings can reliably wake the configured agent and deliver the event to the configured session. Invalid or policy-disallowed targets return an error instead of silently routing elsewhere.

Evidence

  • Exact head: 2cfdf501c32d1a647b28ce657c3ffa31c07f540d.
  • 90 focused hook mapping, request-handler, and Gateway tests passed.
  • Regression coverage includes per-agent routing, custom sessions, global session scope, target policy, deferred wake rejection, transform overrides, and empty templated-session rejection for both wake and agent actions.
  • Targeted formatting, type-aware oxlint, and git diff --check passed.
  • Fresh exact-head autoreview reported no actionable findings (0.88 confidence).
  • Release-note context is captured here; CHANGELOG.md remains release-owned.

@vincentkoc
vincentkoc marked this pull request as ready for review July 29, 2026 22:28
@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Jul 29, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 6:48 PM ET / 22:48 UTC.

ClawSweeper review

What this changes

Routes mapped gateway-hook wake events to their configured agent and session, validates those targets under hook policy, and adds regression coverage for targeted, global, deferred, and invalid mappings.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer-authored PR open for human merge review. Current main still silently routes mapped wake events to the default main session; the patch carries configured targets through policy and canonical session resolution, but it deliberately changes existing mapped configurations from silent fallback to targeted delivery or an error, which needs maintainer acceptance.

Priority: P2
Reviewed head: 43d88a0b693f7ade8a821100daa5c5040031a0c6
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with aligned regression coverage and no discrete correctness finding; compatibility acceptance, not patch quality, is the remaining merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR nevertheless reports focused routing coverage and a successful proof workflow.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR nevertheless reports focused routing coverage and a successful proof workflow.
Evidence reviewed 5 items Current-main behavior: Current main wires mapped wake actions to a dispatcher that resolves resolveMainSessionKeyFromConfig() unconditionally, so configured mapping targets cannot determine the queued wake session.
Proposed routing boundary: The PR extends mapped wake actions with agent/session metadata, validates mapping policy before dispatch, and canonicalizes the event and heartbeat targets together instead of retaining the default-main-only dispatch behavior.
Regression coverage: The branch adds focused mapping and gateway-server coverage for configured wake routing, global session scope, empty templated session keys, policy enforcement, and deferred custom-session rejection.
Findings None None.
Security None None.

How this fits together

Gateway hooks accept external HTTP events, apply configured mappings, then either enqueue a wake event or start an isolated agent run. This PR changes the wake branch so the event queue key and heartbeat target reflect the mapping's configured agent/session rather than always defaulting to the main session.

flowchart LR
  A[External hook request] --> B[Hook mapping]
  B --> C[Target and policy validation]
  C --> D[Canonical session resolution]
  D --> E[System event queue]
  D --> F[Heartbeat target]
  E --> G[Configured agent session]
  F --> G
Loading

Decision needed

Question Recommendation
Should existing mapped wake configurations with agentId or sessionKey switch from silent default-main delivery to targeted delivery or a policy error on upgrade? Accept corrected routing: Merge the patch so configured mapped wake targets control both queued delivery and the heartbeat target, with invalid targets returning explicit errors.

Why: The code repair is narrow and matches the schema's apparent intent, but deployed configurations may have unknowingly relied on the previous fallback; accepting the corrected routing semantics is a maintainer product and compatibility decision.

Before merge

  • Resolve merge risk (P1) - Existing mappings that set agentId or sessionKey will no longer silently fall back to main-session delivery: they will instead route to the configured target or return a policy error. Maintainers should explicitly accept that correction for deployed configurations before merge.
  • Resolve merge risk (P1) - The patch changes both event queue placement and heartbeat targeting; the existing focused tests cover the stated paths, but release behavior should preserve the documented untargeted default-main mapping.
  • Complete next step (P2) - A maintainer must decide whether correcting previously ignored mapped wake targets is the intended upgrade contract before this PR can merge.
Agent review details

Security

None.

PR surface

Source +98, Tests +88. Total +186 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 109 11 +98
Tests 3 112 24 +88
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 221 35 +186

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Accept the corrected upgrade semantics (recommended)
    Merge after a gateway owner explicitly accepts that configured mapped wakes now deliver to their stated session or fail visibly under policy instead of silently landing in main.
  2. Add an upgrade compatibility plan
    Pause for a documented migration or opt-in design if maintainers need to preserve legacy fallback behavior for existing hook configurations.

Technical review

Best possible solution:

Merge only after maintainers accept targeted delivery and explicit policy errors as the correct upgrade behavior for previously misrouted wake mappings, while preserving the untouched default-main path for mappings without a target.

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

Yes, from source: current main always resolves mapped wake dispatch to the configured default main session, while the linked report supplies a concrete mapped agentId/sessionKey request path. I did not execute a live gateway run in this read-only review.

Is this the best way to solve the issue?

Yes, technically: carrying the configured mapping target through existing hook policy and canonical session-key resolution is narrower and safer than adding a parallel routing path. The remaining question is whether maintainers accept the corrected upgrade semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5141a3593c4c.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This fixes a real but bounded multi-agent hook-routing defect rather than an emergency availability or security failure.
  • merge-risk: 🚨 message-delivery: Merging changes which configured agent/session receives mapped wake events, replacing silent delivery to the default main session.
  • merge-risk: 🚨 session-state: The patch changes the canonical session key used for queued events and the heartbeat that consumes them.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR nevertheless reports focused routing coverage and a successful proof workflow.

Evidence

What I checked:

  • Current-main behavior: Current main wires mapped wake actions to a dispatcher that resolves resolveMainSessionKeyFromConfig() unconditionally, so configured mapping targets cannot determine the queued wake session. (src/gateway/server/hooks.ts:270, 5141a3593c4c)
  • Proposed routing boundary: The PR extends mapped wake actions with agent/session metadata, validates mapping policy before dispatch, and canonicalizes the event and heartbeat targets together instead of retaining the default-main-only dispatch behavior. (src/gateway/server/hooks-request-handler.ts:442, 43d88a0b693f)
  • Regression coverage: The branch adds focused mapping and gateway-server coverage for configured wake routing, global session scope, empty templated session keys, policy enforcement, and deferred custom-session rejection. (src/gateway/server.hooks.test.ts:504, 43d88a0b693f)
  • Linked bug ownership: The PR explicitly targets the remaining open report describing successful hook requests being silently delivered to agent:main:main rather than the configured target. (43d88a0b693f)
  • Review continuity: The latest ClawSweeper review at the same head reported no discrete patch findings and identified the intentional upgrade-semantic change as the remaining human merge decision. (43d88a0b693f)

Likely related people:

  • vincentkoc: Authored the current bounded routing repair, refreshed it on current main, and is assigned to this maintainer-authored PR; broader merged-history ownership could not be established from the available read-only inspection path. (role: current repair author and assigned PR owner; confidence: medium; commits: 43d88a0b693f; files: src/gateway/hooks-mapping.ts, src/gateway/server/hooks-request-handler.ts, src/gateway/server/hooks.ts)

Rank-up moves

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

  • Obtain explicit gateway-owner acceptance of the changed upgrade behavior for existing targeted wake mappings.

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 (2 earlier review cycles)
  • reviewed 2026-07-29T22:33:17.193Z sha 2cfdf50 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T22:43:13.543Z sha 43d88a0 :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

Exact-head refresh: 43d88a0b693f7ade8a821100daa5c5040031a0c6

The branch is rebased onto current main with the same bounded wake-mapping contract.

Fresh proof:

  • 90/90 focused wake mapping, hook admission, and Gateway routing tests pass.
  • oxfmt, type-aware oxlint, and git diff --check pass.
  • Fresh full-branch autoreview is clean (0.86).

The fix keeps untargeted wake behavior unchanged, canonicalizes mapped agent/session targets, applies hook policy before admission, rejects empty templated session keys, and rejects custom-session next-heartbeat delivery.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 29, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 29, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: activating an already configured, policy-allowed hook wake agentId / sessionKey target is the intended upgrade behavior. Silently falling back to the main session is the bug; a target rejected by current hook policy should fail instead of being redirected to main.

The branch remains narrow to wake routing, with 90 focused tests, formatting, type-aware oxlint, git diff --check, and a clean fresh autoreview at exact head 43d88a0b693f7ade8a821100daa5c5040031a0c6. Exact-head CI is still finishing.

@vincentkoc
vincentkoc merged commit fc95d71 into main Jul 29, 2026
128 of 132 checks passed
@vincentkoc
vincentkoc deleted the fix-hook-wake-routing-64556 branch July 29, 2026 22:56
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: hooks.mappings[].agentId and sessionKey silently ignored for action="wake"

1 participant