#14689: onboard: set per-channel DM scope by default for multi-channel setups
commands
stale
size: S
## What
This PR makes channel onboarding safer for shared inbox scenarios by setting a DM-isolated session scope during setup.
### Change
In `setupChannels` (`src/commands/onboard-channels.ts`):
- If `session.dmScope` is **unset**
- and user selected **2+ DM-capable channels**
- onboarding now sets `session.dmScope = "per-channel-peer"`
- interactive mode: asks for confirmation (default: yes)
- non-interactive/skip-confirm mode: applies automatically
## Why
Many first-time multi-channel setups leave `dmScope` unset and later run into DM context bleed/cross-channel continuity surprises.
The core behavior (`dmScope=main` when unset) is documented, but onboarding currently only warns; it does not apply a safe default.
This PR keeps backward compatibility for existing configs and only affects onboarding-generated config when `dmScope` is not explicitly set.
## Scope and compatibility
- ✅ No change for users who already set `session.dmScope`
- ✅ No change for single-channel DM onboarding
- ✅ No core routing behavior change
- ✅ Existing deployments remain untouched
## Validation
- Ran targeted test suite:
- `corepack pnpm -s vitest src/commands/onboard-channels.test.ts`
## Related
- Closes #14688
- Related context: #10172, #7861, #14117
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change introduces a new onboarding step in `setupChannels` that, when `session.dmScope` is unset and the user selects 2+ DM-capable channels, prompts (or auto-applies in `skipConfirm` mode) setting `session.dmScope` to `"per-channel-peer"` to isolate DM session history per channel+sender.
The logic is implemented as `maybeConfigureDmScopeIsolation()` and is invoked at the end of channel selection, after optional DM policy configuration. This keeps core routing behavior unchanged and only affects onboarding-generated config defaults.
<h3>Confidence Score: 3/5</h3>
- This PR is mostly safe, but it may apply an incorrect dmScope default for multi-account channels during onboarding.
- The change is localized and preserves existing behavior when dmScope is already set, but the onboarding default is hard-coded to per-channel-peer despite the codebase recommending per-account-channel-peer for multi-account channels, which can lead to account-level DM context mixing.
- src/commands/onboard-channels.ts
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7868: Default DM sessions to per-channel scope (avoid webchat contention)
by Smile232323 · 2026-02-03
80.1%
#19403: feat(slack): add dm.threadSession option for per-message thread ses...
by Vasiliy-Bondarenko · 2026-02-17
74.8%
#9051: fix(sessions): respect dmScope config in CLI agent commands
by benleavett · 2026-02-04
74.7%
#13580: fix(telegram): skip updateLastRoute when dmScope isolates DM sessions
by lailoo · 2026-02-10
74.4%
#20078: feat(session): Add channelGroups config(optional config) for shared...
by demarlik01 · 2026-02-18
73.5%
#11659: fix: Clarify session.dmScope is global in security audit warning
by veast · 2026-02-08
72.2%
#13057: feat(matrix): add sessionScope=room to route sessions by roomId
by spengrah · 2026-02-10
70.3%
#17865: Refactor: centralize dm/group policy resolution
by iyoda · 2026-02-16
69.8%
#19435: fix(slack): properly handle group DM (MPIM) events
by Utkarshbhimte · 2026-02-17
69.6%
#21778: Nostr: enforce inbound DM policy and command authorization
by chansuke · 2026-02-20
69.1%