← Back to PRs

#8357: fix(gateway): preserve accountId across gateway restarts

by alfredo-feat-volky open 2026-02-03 22:48 View on GitHub →
gateway stale
## Summary This PR fixes a bug where message delivery uses the wrong account after a gateway restart when the session has a valid accountId. **⚠️ Impact scope:** This bug only affects **multi-account deployments** (e.g., multiple Discord bot tokens, multiple Telegram bots, or mixed channel accounts). Single-account setups are unaffected because the default fallback is always correct. ## Problem The server-restart-sentinel.ts was correctly resolving accountId but failing to pass it to agentCommand, causing the agent to wake up with an undefined accountId. This caused downstream channel logic to fall back to the "default" account. **When this breaks:** - You have multiple Discord bot applications (different tokens) configured - Session was using bot account "work-bot" - After restart, message gets sent from "personal-bot" (default) instead - Wrong bot identity, or delivery fails if default lacks permissions **Why some users don't see it:** - Single bot/account → default fallback is always correct - Same bot on multiple guilds → still one account, no fallback issue ## Fix - Updated gateway/server-restart-sentinel.ts to pass `accountId: origin?.accountId` to agentCommand. ## Greptile Overview ### Greptile Summary Updates the gateway restart sentinel wake-up path to propagate the resolved accountId into agentCommand, so post-restart message delivery runs under the correct account instead of falling back to a default account configuration. This aligns scheduleRestartSentinelWake with other announce/send flows that already carry origin?.accountId through to agent execution, and matches the existing use of accountId when resolving outbound targets in this same function. ### Confidence Score: 5/5 - This PR is safe to merge with minimal risk. - The change is a single-field propagation (accountId) into an existing command invocation, and the value is already used earlier in the same function when resolving the outbound target; passing it through improves consistency without altering control flow. - No files require special attention Context used: - Context from dashboard - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from dashboard - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))

Most Similar PRs