#22121: fix: resolve cross-context messaging policy from agent defaults
size: M
Cluster:
Cron Session Enhancements
## Summary
- Implement cross-context policy resolution precedence across global config, `agents.defaults.tools.message`, and per-agent `tools.message`.
- Apply `agents.defaults.tools.message` and agent tool overrides when evaluating:
- cross-context send denial in `enforceCrossContextPolicy`
- cross-context marker decoration in `buildCrossContextDecoration`
- Thread `agentId` through outbound message execution paths so policy context is resolved consistently for send/poll actions.
- Extend config schema + types so `agents.defaults.tools.message.*` is valid and typed.
- Add UI labels/help entries for new `agents.defaults.tools.message` paths.
- Add regression tests for precedence and schema acceptance in:
- `src/config/config.schema-regressions.test.ts`
- `src/infra/outbound/outbound.test.ts`
## Testing
- `pnpm vitest run src/config/config.schema-regressions.test.ts src/infra/outbound/outbound.test.ts`
## Notes
Closes #22052.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR implements a three-tier policy resolution for cross-context messaging: per-agent `tools.message` > `agents.defaults.tools.message` > global `tools.message`. The core `resolveMessagePolicy` function in `outbound-policy.ts` correctly merges these layers using nullish coalescing, and `agentId` is properly threaded through send/poll execution paths in `message-action-runner.ts`.
- Config schema (`zod-schema.agent-defaults.ts`), types, UI labels, and help entries are all extended to support the new `agents.defaults.tools.message.*` paths.
- Two regression tests verify defaults override global config and per-agent overrides take priority over defaults.
- Schema regression test confirms the new config paths validate correctly.
- `handleBroadcastAction` still reads `broadcast.enabled` directly from global config (`cfg.tools?.message?.broadcast?.enabled`), so the newly-exposed `agents.defaults.tools.message.broadcast.enabled` config path has no runtime effect — this is a gap that should be addressed.
<h3>Confidence Score: 3/5</h3>
- Generally safe to merge, but the broadcast policy gap means one advertised config path is silently ignored at runtime.
- The core cross-context policy resolution is well-implemented with correct precedence logic and consistent agentId threading. However, the broadcast.enabled check in handleBroadcastAction is not wired through the new resolveMessagePolicy, creating a discrepancy between the config surface (schema/types/labels/help all accept agents.defaults.tools.message.broadcast.enabled) and actual runtime behavior (only global config is consulted). Tests cover positive precedence cases but not the negative restriction case or broadcast policy resolution.
- Pay close attention to `src/infra/outbound/message-action-runner.ts` — the `handleBroadcastAction` function at line 304 does not use the new policy resolution chain for `broadcast.enabled`.
<sub>Last reviewed commit: d695d01</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11854: fix: resolve per-agent tools.exec config in pi-tools
by Yida-Dev · 2026-02-08
77.2%
#20806: fix(security): enforce per-agent message send scope in multi-tenant...
by zerone0x · 2026-02-19
76.3%
#3587: fix(message): disable cross-context marker by default (#1782)
by nadesh00 · 2026-01-28
74.7%
#21271: fix(commands): pass channel/capabilities/shell/os to runtime in com...
by evansantos · 2026-02-19
73.8%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
73.6%
#16064: feat: add contact-based tool permissions with verification
by jamiequint · 2026-02-14
73.4%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
73.3%
#23166: fix(agents): restore subagent announce chain from #22223
by tyler6204 · 2026-02-22
73.2%
#4878: fix: string/type handling and API fixes (#4537, #4380, #4373, #4547...
by lailoo · 2026-01-30
73.0%
#21558: config: support agents.list[].thinkingDefault
by Uarmagan · 2026-02-20
73.0%