#17395: fix(discord): default dm config for sub-accounts to prevent silent crash
channel: discord
gateway
size: XS
Cluster:
Signal and Discord Fixes
## Summary
Fixes #17394 — Adding a Discord sub-account without an explicit `dm` block crashes the entire Discord plugin silently, killing all bot connections including the primary account.
## Root Cause
`mergeDiscordAccountConfig()` in `src/discord/accounts.ts` does a shallow merge of base + account config. When a sub-account omits `dm` and the base's `dm` doesn't get inherited, `merged.dm` is `undefined`. Downstream code doesn't guard against this, causing a silent crash.
## Changes
### 1. Default DM config (`src/discord/accounts.ts`)
- Added `DEFAULT_DM_CONFIG` (`{ enabled: true, policy: "pairing" }`) applied when neither base nor account provides a `dm` block
- Safe fallback that doesn't change behavior for existing configs
### 2. Warning log (`src/discord/monitor/provider.ts`)
- Logs a warning when no DM config is found, pointing operators to the correct config path
### 3. Error isolation (`src/gateway/server-channels.ts`)
- Wrapped per-account startup in try/catch so one failing account cannot take down others
- Failed accounts get `running: false` status with the error message logged
## Testing
Reproduced the crash by configuring a Discord sub-account without a `dm` block. After this fix:
- Sub-account without `dm` starts successfully with default pairing policy
- Warning is logged directing the operator to add explicit config
- If a sub-account fails for any reason, other accounts continue running
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a critical bug where Discord sub-accounts without explicit `dm` configuration would crash the entire Discord plugin, taking down all bot connections. The fix applies a safe default (`dm.policy="pairing"`) when neither base nor account config provides DM settings, adds a helpful warning to guide operators, and wraps per-account startup in try-catch to isolate failures.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix correctly addresses the root cause (undefined dm config in shallow merge), uses a safe default that matches existing behavior (pairing policy), and adds critical error isolation. The changes are well-scoped and backward-compatible.
- No files require special attention
<sub>Last reviewed commit: 3746003</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
83.1%
#13652: fix(discord): ensure default bot loads when multiple accounts are con…
by metav · 2026-02-10
77.4%
#14789: fix: per-account dmPolicy ignored in checkInboundAccessControl
by croll83 · 2026-02-12
77.3%
#20967: fix(discord): report connected state so health-monitor can restart ...
by who96 · 2026-02-19
76.3%
#22557: fix(discord): coerce exec approval approver IDs to string to preven...
by zwffff · 2026-02-21
75.9%
#17513: fix(discord): respect groupPolicy in channel config fallback (#4555)
by aronchick · 2026-02-15
75.7%
#22965: fix(discord): pass accountId to ack reaction calls for named accounts
by arosstale · 2026-02-21
75.5%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
75.5%
#17254: fix(discord): intercept text-based slash commands instead of forwar...
by robbyczgw-cla · 2026-02-15
75.1%
#21463: fix(discord): prevent WebSocket death spiral + fix numeric channel ID…
by akropp · 2026-02-20
74.0%