← Back to PRs

#22121: fix: resolve cross-context messaging policy from agent defaults

by AIflow-Labs open 2026-02-20 18:50 View on GitHub →
size: M
## 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