Skip to content

[Communication] PR5: Route Agents With Mailbox - #235

Open
Joseph0120 wants to merge 11 commits into
joseph/communication_delay_PR4from
joseph/communication_delay_PR5
Open

[Communication] PR5: Route Agents With Mailbox#235
Joseph0120 wants to merge 11 commits into
joseph/communication_delay_PR4from
joseph/communication_delay_PR5

Conversation

@Joseph0120

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Joseph0120
Joseph0120 requested a review from tryuan99 July 22, 2026 05:44
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Joseph0120, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cf15c1bb-7de4-4020-b506-4d4db3af4982

📥 Commits

Reviewing files that changed from the base of the PR and between b4dc1ef and bdf2d42.

📒 Files selected for processing (4)
  • Assets/StreamingAssets/Configs/Simulations/5_swarms_100_ucav.pbtxt
  • Assets/Tests/EditMode/CommsNodeTests.cs.meta
  • Assets/Tests/EditMode/MailboxTests.cs
  • Assets/Tests/EditMode/MailboxTests.cs.meta
📝 Walkthrough

Walkthrough

The communication layer now delivers queued messages directly to active receivers and explicitly handles nodes without subscribers. Interceptor assignment and reassignment propagation has moved from events to CommsNode messages. IADS handles assignment requests, selects viable launcher targets, and sends responses. Interceptor registration configures message receivers, lifecycle cleanup unsubscribes handlers, and Mailbox latency behavior is covered by an EditMode test.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: daniellovell, tryuan99

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided, so the change intent cannot be assessed from author notes. Add a brief PR description summarizing the mailbox-based routing and related interceptor/comms changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: routing agent communication through the mailbox.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch joseph/communication_delay_PR5

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Assets/Scripts/Communication/Mailbox.cs (1)

139-143: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Resolve the acknowledged PDR defect before merge.

Line 139 states packet-loss behavior is incorrect whenever PacketDeliveryRatio != 1.0, so configured lossy links currently have undefined simulation behavior. Define the intended drop/retry semantics and add deterministic coverage for PDR 0, 1, and an intermediate value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Assets/Scripts/Communication/Mailbox.cs` around lines 139 - 143, Fix the
packet-loss handling in the mailbox send path around PacketDeliveryRatio so PDR
0 always drops, PDR 1 always delivers, and intermediate values apply the
intended deterministic drop/retry semantics before enqueueing into the priority
queue. Remove the acknowledged TODO and add deterministic coverage for all three
PDR cases, including the expected retry behavior for lossy links.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Assets/Scripts/Communication/Mailbox.cs`:
- Around line 93-99: Update the message delivery loop in Mailbox so
_messageBuffer is cleared even when pending.Receiver.Receive(pending.Message)
throws. Ensure cleanup occurs before propagating the exception, preventing
previously processed messages from being redelivered on the next frame.

In `@Assets/Tests/EditMode/MailboxTests.cs`:
- Around line 45-58: Update the Mailbox test setup around the sender and
receiver CommsNode instances to register both nodes with CommsManager before
calling _mailbox.Send. Ensure the corresponding teardown unregisters both nodes,
preserving fixture isolation and preventing CommsManager state from affecting
the test outcome.

---

Outside diff comments:
In `@Assets/Scripts/Communication/Mailbox.cs`:
- Around line 139-143: Fix the packet-loss handling in the mailbox send path
around PacketDeliveryRatio so PDR 0 always drops, PDR 1 always delivers, and
intermediate values apply the intended deterministic drop/retry semantics before
enqueueing into the priority queue. Remove the acknowledged TODO and add
deterministic coverage for all three PDR cases, including the expected retry
behavior for lossy links.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 55225490-dca1-4c97-a022-1803cc3879a9

📥 Commits

Reviewing files that changed from the base of the PR and between ec703bb and b4dc1ef.

📒 Files selected for processing (7)
  • Assets/Scripts/Communication/CommsNode.cs
  • Assets/Scripts/Communication/Mailbox.cs
  • Assets/Scripts/IADS/IADS.cs
  • Assets/Scripts/Interceptors/CarrierBase.cs
  • Assets/Scripts/Interceptors/IInterceptor.cs
  • Assets/Scripts/Interceptors/InterceptorBase.cs
  • Assets/Tests/EditMode/MailboxTests.cs
💤 Files with no reviewable changes (1)
  • Assets/Scripts/Interceptors/IInterceptor.cs

Comment on lines +93 to +99
foreach (PendingMessage pending in _messageBuffer) {
if (!IsNodeActive(pending.Receiver)) {
continue;
}
pending.Receiver.Receive(pending.Message);
}
_messageBuffer.Clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear the due-message buffer when a receiver throws.

If Receive throws at Line 97, _messageBuffer.Clear() is skipped. The next frame re-delivers every already-buffered message, causing duplicate assignment/reassignment handling.

Proposed fix
-    foreach (PendingMessage pending in _messageBuffer) {
-      if (!IsNodeActive(pending.Receiver)) {
-        continue;
+    try {
+      foreach (PendingMessage pending in _messageBuffer) {
+        if (!IsNodeActive(pending.Receiver)) {
+          continue;
+        }
+        pending.Receiver.Receive(pending.Message);
       }
-      pending.Receiver.Receive(pending.Message);
+    } finally {
+      _messageBuffer.Clear();
     }
-    _messageBuffer.Clear();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
foreach (PendingMessage pending in _messageBuffer) {
if (!IsNodeActive(pending.Receiver)) {
continue;
}
pending.Receiver.Receive(pending.Message);
}
_messageBuffer.Clear();
try {
foreach (PendingMessage pending in _messageBuffer) {
if (!IsNodeActive(pending.Receiver)) {
continue;
}
pending.Receiver.Receive(pending.Message);
}
} finally {
_messageBuffer.Clear();
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Assets/Scripts/Communication/Mailbox.cs` around lines 93 - 99, Update the
message delivery loop in Mailbox so _messageBuffer is cleared even when
pending.Receiver.Receive(pending.Message) throws. Ensure cleanup occurs before
propagating the exception, preventing previously processed messages from being
redelivered on the next frame.

Comment on lines +45 to +58
var sender = new CommsNode(Configs.AgentType.Iads);
var receiver = new CommsNode(Configs.AgentType.ShoreBattery);
int receivedCount = 0;
Message receivedMessage = null;
receiver.OnMessageReceived += message => {
receivedCount++;
receivedMessage = message;
};

var target = new FixedHierarchical(position: Vector3.one);
var messageToSend = new AssignTargetResponseMessage(sender, receiver, target);

SetPrivateProperty(_simManager, "ElapsedTime", 0f);
_mailbox.Send(messageToSend);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Register the test nodes with CommsManager.

Mailbox.Send drops messages when CommsManager.Instance exists and either node is unregistered. This test currently passes only when no manager exists, so fixture state can turn it into a false pass or failure. Explicitly add both nodes before Send and remove them during teardown.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Assets/Tests/EditMode/MailboxTests.cs` around lines 45 - 58, Update the
Mailbox test setup around the sender and receiver CommsNode instances to
register both nodes with CommsManager before calling _mailbox.Send. Ensure the
corresponding teardown unregisters both nodes, preserving fixture isolation and
preventing CommsManager state from affecting the test outcome.

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