Skip to content

Post into the most recent of several matching group chats - #22

Merged
Sekers merged 3 commits into
developfrom
fix/group-chat-reuse
Sep 30, 2026
Merged

Sekers merged 3 commits into
developfrom
fix/group-chat-reuse

Conversation

@Sekers

@Sekers Sekers commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Summary

When the sender already has more than one group chat with exactly the same members, Send-ScriptMessage -ChatType Group posts into the least recent one. The chats are sorted most recent first, but the match loop never stops, so the last match wins. The bug is in 1.1.1.

This stops at the first match, so the message goes to the most recent chat:

  • With Chat.Read (or Chat.ReadWrite): the chat with the latest message.
  • With only Chat.ReadBasic: the chat most recently created, renamed, or given different members. That sort uses LastUpdatedDateTime, which posting a message doesn't change, and Chat.ReadBasic can't read lastMessagePreview.

The change also adds two tests, which fail on the old loop and pass now; a Fixed entry under [Unreleased]; and Research_Notes/Microsoft-Graph-Behavior.md section 9, with the measurements and what they leave unverified.

Live testing, with delegated permissions, sending messages only to three accounts I control:

  • A second group chat created with the same members is a new chat, not the existing one.
  • Posting messages doesn't change a chat's LastUpdatedDateTime.
  • Expanding lastMessagePreview with only Chat.ReadBasic fails with 403.
  • A delegated sign-in carries every permission already granted to the app, so the Chat.ReadBasic sort applies only when the app has no Chat.Read grant.
  • With this change and only Chat.ReadBasic granted, the message went to the more recently created chat, as intended. The Chat.Read path was run live only before the change, when it picked the older chat; with the change it's covered by the new test.

Release classification

  • Major: breaks the public contract (an existing script or configuration file can stop working)
  • Minor: adds backward-compatible functionality
  • Patch: a backward-compatible fix
  • None: no user-visible change (tests, CI, or contributor documentation only)

Checklist

  • Targets develop, or main for a hotfix
  • CHANGELOG.md has an entry in the right section under [Unreleased] (added if missing), or the change is not user-visible
  • .\Tests\Invoke-Tests.ps1 passes
  • Contains no real tenant names, email domains, secrets, or configuration files
  • Any live Microsoft Graph testing is described above, and sent messages and files only to accounts you control

When more than one group chat has exactly the sender and the recipients
as members, Send-ScriptMessage_MicrosoftGraph posts into the least
recent one. The chats are sorted most recent first, but the match loop
never stops, so the last match wins.

Stop at the first match. With Chat.Read the most recent chat is the one
with the latest message; with only Chat.ReadBasic it is the one most
recently created, renamed, or given different members, because Graph
does not change LastUpdatedDateTime when a message is posted. Correct
the comment that said otherwise.

Measured against a tenant on 2026-09-30: Graph creates a second group
chat with the same members rather than returning the first, and posting
leaves LastUpdatedDateTime alone. Chat.ReadBasic cannot expand
lastMessagePreview, so that sort is the best it allows, and a delegated
sign-in carries every permission already granted to the app, so the
Chat.ReadBasic sort applies only when the app has no Chat.Read grant.
See Research_Notes/Microsoft-Graph-Behavior.md section 9.
The Chat.ReadBasic sub-bullet of the group chat entry says messages
"don't count" and describes the permission grant in terms the reader
has to work out.

Say plainly which chat each permission picks, and state the case where
both permissions are granted directly.
Section 9 says a recipient given by an alias never matches an existing
group chat. A chat member is named by users('<address>'), which takes a
user ID or UPN, so a true alias more likely fails when the chat is
created; the case that never matches is a UPN that differs from the
primary email.

Describe the UPN case, note that matching on userId would avoid it, and
mark the alias case as a likely creation failure.
@Sekers
Sekers merged commit 32282b7 into develop Sep 30, 2026
4 checks passed
@Sekers
Sekers deleted the fix/group-chat-reuse branch September 30, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant