#16194: fix: route exec approvals to explicit targets regardless of sessionFilter
stale
size: M
trusted-contributor
Cluster:
Session Management Enhancements
## Summary
This PR fixes a bug where exec approval requests were not being forwarded to Telegram (or other explicit targets) when `sessionFilter` was configured but did not match the originating session key.
The `sessionFilter` configuration was incorrectly blocking ALL forwarding when the session key didn't match, even when explicit targets were configured with `mode: "targets"` or `mode: "both"`. This fix separates the concerns:
- `sessionFilter` now only affects session-based forwarding (mode: `"session"` or `"both"`)
- Explicit targets (mode: `"targets"` or `"both"`) are always used regardless of `sessionFilter`
- `agentFilter` still applies to all modes as intended
## Changes
- Modified `shouldForward()` to remove the `sessionFilter` check (it was blocking all forwarding unnecessarily)
- Added new `sessionMatchesFilter()` helper function
- Updated `handleRequested()` to check `sessionMatchesFilter()` only when resolving session targets
- Added 5 new test cases covering the sessionFilter behavior
## Testing
- All existing tests pass (5 original tests + 5 new tests = 10 total in exec-approval-forwarder.test.ts)
- Related tests in exec-approvals.test.ts and exec-approval.test.ts also pass
## Configuration Example
With this fix, the following configuration will now work correctly:
```json
{
"approvals": {
"exec": {
"enabled": true,
"mode": "targets",
"targets": [{ "channel": "telegram", "to": "@user" }]
}
}
}
```
Previously, if `sessionFilter` was set (even to a different value), explicit targets would be ignored.
Fixes openclaw/openclaw#16184
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a bug where `sessionFilter` in exec approval forwarding config was incorrectly blocking ALL forwarding (including explicit targets) when the session key didn't match. The fix separates `sessionFilter` from the global `shouldForward` gate and moves it to only gate session-based target resolution, so explicit targets (`mode: "targets"` or `mode: "both"`) are always forwarded regardless of `sessionFilter`.
- Extracted `sessionMatchesFilter()` helper from `shouldForward()` to isolate session-specific filtering logic
- Applied `sessionMatchesFilter()` only in the `mode === "session" || mode === "both"` branch of `handleRequested()`
- `agentFilter` continues to apply globally to all forwarding modes, consistent with prior behavior
- Added 5 new test cases covering all mode/filter combinations
- Note: the exported `shouldForwardExecApproval()` function no longer checks `sessionFilter`, though it has no current external callers
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it fixes a clear bug with clean logic separation and thorough test coverage.
- The change is well-scoped, correctly separates sessionFilter from global forwarding, and maintains backward compatibility. The 5 new tests cover all key mode/filter combinations. The only minor concern is that the exported shouldForwardExecApproval now has different semantics (no longer checks sessionFilter), but it has no current external callers. The core logic refactoring is straightforward and easy to verify.
- No files require special attention. The changes in `src/infra/exec-approval-forwarder.ts` are clean and well-tested.
<sub>Last reviewed commit: 9ed2b8e</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16685: Fix cli agents/approvals/discord routing edge cases
by craftowen · 2026-02-15
78.8%
#6850: fix: support direct channel:account:peer format in session key extr...
by toboto · 2026-02-02
76.0%
#17132: fix: filter out invalid session entries with empty sessionFile
by Limitless2023 · 2026-02-15
75.6%
#22469: fix(gateway): avoid stale whatsapp labels on direct sessions
by loganprit · 2026-02-21
75.6%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
75.4%
#16102: Fix: Telegram Inline Button Support for Exec Approvals (builds on #...
by RoguePhoenix117 · 2026-02-14
75.3%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
75.1%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
74.8%
#15888: fix: store relative session file paths instead of absolute
by devAnon89 · 2026-02-14
74.8%
#21466: Copilot/fix forwarded message visibility
by stnguyen90 · 2026-02-20
74.6%