fix: clear delivery routing state when creating isolated cron sessions (#27778)

* fix: clear delivery routing state when creating isolated cron sessions

When `resolveCronSession()` creates a new session (forceNew / isolated),
the `...entry` spread preserves `lastThreadId`, `lastTo`, `lastChannel`,
and `lastAccountId` from the prior session. This causes announce-mode
cron deliveries to post as thread replies instead of channel top-level
messages when `delivery.to` matches the channel of a prior conversation.

Clear delivery routing metadata on new session creation so isolated
cron sessions start with a clean delivery state.

Closes #27751

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)

* fix: also clear deliveryContext to prevent lastThreadId repopulation

normalizeSessionEntryDelivery (called on store writes) repopulates
lastThreadId from deliveryContext.threadId. Clearing only the last*
fields is insufficient — deliveryContext must also be cleared when
creating a new isolated session.

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
This commit is contained in:
Mitsuyuki Osabe
2026-03-01 02:09:12 +09:00
committed by GitHub
parent daa418895e
commit e1df1c60b8
2 changed files with 101 additions and 0 deletions

View File

@@ -65,6 +65,19 @@ export function resolveCronSession(params: {
sessionId,
updatedAt: params.nowMs,
systemSent,
// When starting a fresh session (forceNew / isolated), clear delivery routing
// state inherited from prior sessions. Without this, lastThreadId leaks into
// the new session and causes announce-mode cron deliveries to post as thread
// replies instead of channel top-level messages.
// deliveryContext must also be cleared because normalizeSessionEntryDelivery
// repopulates lastThreadId from deliveryContext.threadId on store writes.
...(isNewSession && {
lastChannel: undefined,
lastTo: undefined,
lastAccountId: undefined,
lastThreadId: undefined,
deliveryContext: undefined,
}),
};
return { storePath, store, sessionEntry, systemSent, isNewSession };
}