Repository navigation
fix: keep a separate agent session for each person in a thread - #319
Conversation
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
…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
left a comment
There was a problem hiding this comment.
🧵 @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.
| own_session = session_store.get_session( | ||
| context.channel_id, event["thread_ts"], context.user_id | ||
| ) | ||
| if own_session is None: |
There was a problem hiding this comment.
🔐 praise: Gating thread replies on own_session also keeps results fetched with someone else's user token out of the conversation. Great catch!
|
Thanks @zimeg for the review and for testing it live with two people in one thread! 🙇 |
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/, andpydantic-ai/.Testing
tests/test_store.pyshowing two people in the same thread get separate sessions, and atest_message.pytest showing a thread reply from someone without their own session does not run the agent.ruff check .,ruff format --check ., andpytestpass in all three projects.Notes