#22182: fix(msteams): prevent false auto-restart loop after successful startup
channel: discord
channel: msteams
channel: whatsapp-web
agents
size: S
Cluster:
Fix Microsoft Teams Plugin Issues
## Summary
Fixes a lifecycle bug in the Microsoft Teams channel where the provider task resolved immediately after startup, which the channel manager interpreted as an exit and then auto-restarted.
## Root cause
`msteamsPlugin.gateway.startAccount` returned the startup result from `monitorMSTeamsProvider` right away. In the channel manager, resolving `startAccount` means "channel exited", which triggered restart attempts and duplicate port binds (`EADDRINUSE`).
## Changes
- In `extensions/msteams/src/channel.ts`:
- await `monitorMSTeamsProvider(...)`
- keep `startAccount` alive until `abortSignal` fires
- perform shutdown on abort
- In `extensions/msteams/src/monitor.ts`:
- remove internal abort listener shutdown hook
- keep shutdown ownership in `startAccount` lifecycle handling
## Why this works
The channel manager now sees the msteams account task as long-lived (running) instead of immediately completed, so it no longer triggers the auto-restart loop after a successful boot.
## Validation
- `pnpm install --frozen-lockfile --ignore-scripts`
- `pnpm vitest run extensions/msteams/src/channel.directory.test.ts`
## AI assistance
AI-assisted implementation.
Testing depth: lightly tested (targeted local tests for touched area).
Fixes #22169
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed lifecycle bug where MS Teams channel provider resolved immediately after startup, causing the channel manager to interpret completion as an exit and trigger auto-restart loops with `EADDRINUSE` errors.
## Changes
- **`extensions/msteams/src/channel.ts`**: modified `startAccount` to await `monitorMSTeamsProvider`, keep the task alive until abort signal fires, and handle shutdown when aborted
- **`extensions/msteams/src/monitor.ts`**: removed internal abort listener that called `shutdown()`, moving shutdown ownership to the `startAccount` lifecycle
## How it works
The channel manager treats a resolved `startAccount` promise as "channel exited" (see `src/gateway/server-channels.ts:203-215`), which triggers the auto-restart logic. By keeping `startAccount` alive until the abort signal fires, the channel manager now correctly sees the MS Teams account as a long-running task instead of a completed one.
<h3>Confidence Score: 4/5</h3>
- Safe to merge with minor consideration for edge case handling
- The fix correctly addresses the root cause by aligning MS Teams with the channel manager's lifecycle expectations. The implementation follows the same pattern used in other channel extensions (zalo, zalouser) where a promise is kept alive until abort. The check `if (!ctx.abortSignal.aborted)` before creating the promise prevents a race condition where the signal might already be aborted. However, there's a theoretical edge case: if `monitorMSTeamsProvider` throws an error, the promise will reject before reaching the abort handler setup, but this is acceptable since errors are caught by the channel manager's error handling (line 204-208 in server-channels.ts).
- No files require special attention
<sub>Last reviewed commit: 52f5f77</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22605: fix(msteams): keep provider promise pending until abort to stop aut...
by OpakAlex · 2026-02-21
89.4%
#20455: fix(msteams): prevent EADDRINUSE restart loop
by taradtke · 2026-02-18
87.5%
#13089: fix(msteams): alias team config under channel conversation IDs for ...
by BradGroux · 2026-02-10
80.6%
#23226: fix(msteams): proactive messaging, EADDRINUSE fix, tool status, ada...
by TarogStar · 2026-02-22
78.6%
#23621: fix(LINE): keep startAccount promise alive to prevent auto-restart ...
by ttakanawa · 2026-02-22
78.5%
#20554: fix(googlechat): prevent infinite restart loop in startAccount
by Gitjay11 · 2026-02-19
77.6%
#21790: fix(msteams): deliver thread replies via continueConversation to su...
by BinHPdev · 2026-02-20
75.6%
#22184: fix(msteams): resolve EADDRINUSE double-start by awaiting port binding
by harshang03 · 2026-02-20
75.4%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
74.8%
#10902: fix(msteams): fix inline pasted image downloads
by jlian · 2026-02-07
74.8%