Skip to content

fix: keep a separate agent session for each person in a thread - #319

Merged
mwbrooks merged 6 commits into
mainfrom
mwbrooks-fix-thread-session-per-user
Nov 17, 2026
Merged

mwbrooks merged 6 commits into
mainfrom
mwbrooks-fix-thread-session-per-user

Conversation

@mwbrooks

@mwbrooks mwbrooks commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

This pull request keeps each person's conversation with Casey separate in a channel thread. Until now sessions were keyed by channel and thread, so anyone who replied in a thread Casey was part of continued the conversation of the person who started it. That included results Casey fetched from the Slack MCP Server with the first person's user token.

Sessions are now keyed by channel, thread, and user. In a channel thread, Casey replies to follow-ups only from people who have their own session there. Anyone else starts their own conversation by mentioning @Casey. DMs and issue submissions from App Home are unchanged: an issue submission's session belongs to the person who submitted it. The README now explains who Casey replies to in a thread.

The change is in claude-agent-sdk/, openai-agents-sdk/, and pydantic-ai/.

Testing

  • Added tests that a second person's @-mention starts their own session, a reply stores its session under the person who sent it, and an issue submission stores it under the submitter.
  • Added tests/test_store.py showing two people in the same thread get separate sessions, and a test_message.py test showing a thread reply from someone without their own session does not run the agent.
  • The new tests fail without this change and pass with it, in all three projects.
  • ruff check ., ruff format --check ., and pytest pass in all three projects.

Notes

A thread reply that @-mentions the agent fires both app_mention and message, so the agent ran twice and posted two replies. The message listener now leaves those replies to app_mention.
Sessions were keyed by channel and thread, so anyone replying in a channel thread resumed the session of the person who started it, including results Casey fetched with that person's user token. Sessions are now keyed by channel, thread, and user. Casey auto-replies in a thread only to people with their own session, and others start one with an @mention.
…le-reply' into mwbrooks-fix-thread-session-per-user

# Conflicts:
#	claude-agent-sdk/tests/test_message.py
#	openai-agents-sdk/tests/test_message.py
#	pydantic-ai/tests/test_message.py
Base automatically changed from mwbrooks-fix-thread-mention-double-reply to main November 17, 2026 00:00
…ession-per-user

# Conflicts:
#	claude-agent-sdk/listeners/events/message.py
#	claude-agent-sdk/tests/test_message.py
#	openai-agents-sdk/listeners/events/message.py
#	openai-agents-sdk/tests/test_message.py
#	pydantic-ai/listeners/events/message.py
#	pydantic-ai/tests/test_message.py

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧵 @mwbrooks LGTM! Keeping each person's conversation separate in a thread is a great fix, and it matches bolt-python-starter-agent#285 nicely.

🧪 The new tests for a second person's mention and an issue submission's submitter are a nice addition, and ruff check ., ruff format --check ., and pytest pass locally in all three projects. I also ran openai-agents-sdk with two people in one channel thread: each of us kept our own conversation, and a reply from someone without one got no answer until they mentioned Casey.

Comment on lines +45 to +48
own_session = session_store.get_session(
context.channel_id, event["thread_ts"], context.user_id
)
if own_session is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔐 praise: Gating thread replies on own_session also keeps results fetched with someone else's user token out of the conversation. Great catch!

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @zimeg for the review and for testing it live with two people in one thread! 🙇

@mwbrooks
mwbrooks merged commit a84239f into main Nov 17, 2026
8 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-fix-thread-session-per-user branch November 17, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants