diff --git a/plugin/src/channel-plugin-api.ts b/plugin/src/channel-plugin-api.ts index 7093a98..f9a1bd6 100644 --- a/plugin/src/channel-plugin-api.ts +++ b/plugin/src/channel-plugin-api.ts @@ -135,10 +135,7 @@ export function buildPilotChannelPlugin(deps: BuildPilotPluginDeps): PilotChanne accountId: string; }) => { deps.logger.info("pilot channel: account changed, reloading", { accountId }); - const acct = lifecycle.getAccount(accountId); - if (acct) { - await acct.transport.stop(); - } + await lifecycle.stopAccount(accountId); await lifecycle.startAll(nextCfg); }, onAccountRemoved: async ({ accountId }: { accountId: string }) => { diff --git a/plugin/src/lifecycle.ts b/plugin/src/lifecycle.ts index 547b449..a33fe92 100644 --- a/plugin/src/lifecycle.ts +++ b/plugin/src/lifecycle.ts @@ -275,6 +275,19 @@ export class PilotLifecycle { return this.accounts.get(accountId)?.outbox; } + /** Stop a single account and remove it from the live map. */ + async stopAccount(accountId: string): Promise { + const state = this.accounts.get(accountId); + if (!state) return; + try { + if (state.drainTimer) clearInterval(state.drainTimer); + state.pipeline.stop(); + await state.transport.stop(); + } finally { + this.accounts.delete(accountId); + } + } + async stopAll(): Promise { const tasks: Promise[] = []; for (const [id, state] of this.accounts) {