Skip to content

Read an agent's membership only before it says something (CHOO-3667) - #1247

Closed
abeldantas wants to merge 1 commit into
admin-mention-checksfrom
lazy-member-check
Closed

abeldantas wants to merge 1 commit into
admin-mention-checksfrom
lazy-member-check

Conversation

@abeldantas

Copy link
Copy Markdown
Collaborator

After a message commits, the router read the membership of every agent the message was addressed to before running what the message left that agent to do, so that an agent taken out of the room in the meantime says nothing there. For a connected agent there is nothing to say, only a report to make.

In this PR we ask whether the agent is still a member only before a refusal or an offline notice is posted, or its cloud machine woken (Delivery.checks_membership, AgentRecipient._after_message). Other work a row leaves an agent, such as a greeting, still asks first.

In a local run of the load harness (200 agents behind 10 controllers, 2 processes, 5 msg/s), that was 3 transactions per message, one per addressed agent, and they are gone.

Stack (merge order)

  1. Post the tagged-agent heads-up from the writing process, and skip it when only room agents are tagged (CHOO-3667) #1222
  2. This PR ← you are here

After a message commits, the router read the membership of every agent
it was addressed to, so that one removed from the room in the meantime
says nothing there. A connected agent has nothing to say about a message
addressed to it, so the read is now made only before a refusal or an
offline notice is posted, or a cloud machine woken. In our load test
that was one transaction per addressed agent, about three per message.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified, and the changes and corresponding tests address the intended reduction in unnecessary membership reads.

No open issues 🎉

What changed in this PR

This pull request reduces unnecessary post-commit membership reads for messages addressed to connected agents while preserving checks before refusals, offline notices, and cloud-machine wake-ups.

Changes:

  • Adds Delivery.checks_membership to control deferred membership validation.
  • Updates post-commit recipient handling to check membership only when follow-up work may produce output or wake a machine.
  • Updates routing and protocol tests.
  • Documents the behavior in the changelog.
File Description
core/​tests/​switch_core/​delivery/​test_router_sessions.py Verifies connected addressed agents avoid an extra membership read.
core/​tests/​switch_core/​delivery/​test_no_session_reply_threading.py Updates the recipient test double for deferred membership validation.
core/​tests/​switch_core/​bridges/​agent/​protocol/​test_controller_presence.py Updates controller-presence test setup for the new membership helper.
core/​switch_core/​delivery/​router.py Propagates deferred membership-check behavior into post-commit work.
core/​switch_core/​delivery/​recipient.py Defers membership checks until notices, refusals, or machine wake-ups may occur.
CHANGELOG.md Documents the reduced membership-read behavior.

Review effort: Lite

@abeldantas

Copy link
Copy Markdown
Collaborator Author

Combined into #1307 with the other scaling PRs.

@abeldantas abeldantas closed this Nov 2, 2026
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.

2 participants