Skip to content

AI-assisted: Gateway hook event routing respects target agent session#80

Open
BingqingLyu wants to merge 2 commits into
mainfrom
pr-39046-vincentkoc-code-fix-hook-system-events-routing
Open

AI-assisted: Gateway hook event routing respects target agent session#80
BingqingLyu wants to merge 2 commits into
mainfrom
pr-39046-vincentkoc-code-fix-hook-system-events-routing

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Problem: Hook completion and error system events were always enqueued to the default agent main session, even when the hook ran against another agent.
  • Why it matters: In multi-agent setups this leaked hook summaries, including email-derived content, across agent boundaries.
  • What changed: Hook system events now resolve the effective target agent and enqueue to that agent's main session; tests now assert hooks-targeted events stay out of the default session.
  • What did NOT change (scope boundary): Hook execution, delivery behavior, and wake-hook routing were not otherwise changed.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

Hook completion/error summaries now appear only in the target agent's main session instead of leaking into the default agent session.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (Yes)
  • If any Yes, explain risk + mitigation:
    This reduces data exposure by scoping hook-generated system events to the intended agent session. No broader data access was added.

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 / pnpm workspace
  • Model/provider: N/A
  • Integration/channel (if any): Hook gateway endpoints
  • Relevant config (redacted): multi-agent config with default main agent and hooks agent

Steps

  1. Configure hooks with a target agentId of hooks.
  2. Trigger /hooks/agent with a non-delivered hook run.
  3. Inspect queued system events for agent:main:main and agent:hooks:main.

Expected

  • The hook summary is queued only in the target agent's main session.

Actual

  • Before this change it was queued in the default agent's main session.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: explicit agentId: "hooks", agent-scoped request sessionKey, allowed-agent enforcement, wake hooks still landing in the default main session.
  • Edge cases checked: fallback to default agent for unknown target agent IDs.
  • What you did not verify: live Gmail hook traffic against a real multi-agent deployment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert the two commits in this PR.
  • Files/config to restore: src/gateway/server/hooks.ts and src/gateway/server.hooks.test.ts
  • Known bad symptoms reviewers should watch for: hook summaries not appearing in the target agent session, or wake hooks no longer reaching the default main session.

Risks and Mitigations

  • Risk: Hook runs that infer the effective agent from session key could misroute if the session key parsing changes elsewhere.
    • Mitigation: regression coverage now checks both explicit-agent and agent-scoped session-key flows.

AI-assisted: yes. Fully tested locally for the targeted hook suite and validated with pnpm build.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Hook completion events leak cross-agent email content to default agent session

2 participants