← Back to PRs

#4693: fix: keep main session displayName on outbound sends

by ManojINaik open 2026-01-30 14:30 View on GitHub →
## Summary - prevent outbound DM sends that resolve to the main session key from overwriting origin metadata, which was flipping `sessions_list` displayName to the last recipient - keep delivery context updates (`lastTo`, `lastChannel`, `lastAccountId`, `lastThreadId`) so routing remains accurate - leave per-peer session behavior unchanged so labels continue to reflect their peer ## Context Outbound sends call `ensureOutboundSessionEntry`, which previously used the inbound metadata pipeline even when DM scope collapsed to the main session key. That path derives the origin label from `ctx.From`, so the main session’s displayName became the last recipient. The fix skips origin updates for main-session routes and only persists delivery context in that case. ## Testing - Not run (not requested) Closes #4683 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates `ensureOutboundSessionEntry` (`src/infra/outbound/outbound-session.ts`) to avoid updating origin-derived session metadata when an outbound DM route collapses to the agent’s main session key. For those “main-session” routes it now only persists delivery context (via `updateLastRoute`) so routing fields like `lastTo/lastChannel/lastAccountId/lastThreadId` remain accurate, while preventing the main session `displayName` from being overwritten by the most recent recipient. Per-peer session behavior continues to use the inbound metadata pipeline (`recordSessionMetaFromInbound`). <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge; it’s a small, targeted behavior change in session metadata writes. - Change is narrowly scoped to `ensureOutboundSessionEntry` and only alters behavior when the outbound route collapses to the agent main session key. It uses existing store primitives (`updateLastRoute`) and keeps the previous behavior for non-main session routes. Main remaining risk is silent failure of session-store writes due to swallowed errors, which can mask operational issues. - src/infra/outbound/outbound-session.ts <!-- greptile_other_comments_section --> **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)) <!-- /greptile_comment -->

Most Similar PRs