Skip to content

[Communication] PR1: Added Base Files for Mailbox#212

Open
Joseph0120 wants to merge 9 commits intomasterfrom
joseph/communication_delay_PR1
Open

[Communication] PR1: Added Base Files for Mailbox#212
Joseph0120 wants to merge 9 commits intomasterfrom
joseph/communication_delay_PR1

Conversation

@Joseph0120
Copy link
Copy Markdown
Collaborator

Files Added:

iMessagePayload.cs -> Interface for MessagePayload

LatencyTable.cs -> Creates table that keeps track of the delay between every agent. Table is n * n sized, n is the size of CommsNode.

Message.cs -> Message is a base envolope for message sending. It always carries Sender, Reciever, Type, and Payload.
This file wraps the payload data with transport metadata. It interntionally layers and splits the
payload and the transportation data. Mailbox only focuses on transportation (enqueue, latency,
and delivery timing)

MessagePayload.cs -> MessagePayload defines different types of new payload objects. Payload is carried by
Message envolopes. Concrete payload content lives in here and are only read explicitly
by receivers.

PendingMessage.cs -> This is the mailbox's internal queue item. It stores the Message object
and DeliverAt into the priority queue and pops the message when DeliverAt
time has reached.

@stacklane-pr-stack-visualizer
Copy link
Copy Markdown

stacklane-pr-stack-visualizer bot commented Mar 31, 2026

🧱 Stack PR · Base of stack (9 PRs total)

Stack Structure:

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a messaging framework for agents, including structures for message payloads, latency tracking, and a pending message queue. I have reviewed the implementation and suggest the following improvements: address the potential fragility of using enum casts as array indices in the LatencyTable, optimize the LatencyTable initialization loop to avoid unnecessary iterations when the default value is zero, refactor the message system to use a generic Message class to reduce boilerplate, and implement IComparable in the PendingMessage struct to better support priority queue operations.

Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs
Comment thread Assets/Scripts/Agents/Messaging/Message.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/PendingMessage.cs Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Adds a new inter-agent messaging subsystem: an empty IMessagePayload interface; message envelope types (Message, MessageType) and three concrete messages (AssignSubInterceptorRequestMessage, AssignTargetMessage, ReassignTargetRequestMessage); three payload classes implementing IMessagePayload; a PendingMessage readonly struct with delivery timestamp and ordering; a CommsNode enum and LatencyTable for directed latency values. Constructors validate non-null references and LatencyTable clamps negative latencies. Several Unity .meta files were added for the new source files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding foundational files for a mailbox/messaging system.
Description check ✅ Passed The description is clearly related to the changeset, explaining the purpose of each new file in detail.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch joseph/communication_delay_PR1

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Assets/Scripts/Agents/Messaging/LatencyTable.cs`:
- Around line 19-27: The LatencyTable constructor assigns defaultSeconds
directly producing negative values unlike the Set() method; update the
constructor for LatencyTable to clamp defaultSeconds (use Mathf.Max(0f,
defaultSeconds)) before filling the _latency[,] array so all initial entries
match the non-negative enforcement used by Set().

In `@Assets/Scripts/Agents/Messaging/Message.cs`:
- Line 3: Update the class/file comment for Message (the top-line comment above
the Message class) to correct the typos: change "envolope" to "envelope" and
"Reciever" to "Receiver", so the comment reads something like "Message is a base
envelope for message sending. It always carries Sender, Receiver, Type, and
Payload." Ensure you only change the comment text associated with the Message
definition and preserve the original punctuation and casing for identifiers
Sender, Receiver, Type, and Payload.
- Around line 12-15: Fix typos in the class/file comment for Message: replace
"envolope" with "envelope", "Reciever" with "Receiver", "interntionally" with
"intentionally", and "interntionally layers" -> "intentionally layers"; ensure
the sentence reads clearly (e.g., "Message is a base envelope for message
sending. It always carries Sender, Receiver, Type, and Payload. This file wraps
the payload data with transport metadata. It intentionally layers and splits the
payload and the transportation data. Mailbox only focuses on transportation
(enqueue, latency, and delivery timing)"). Update the block comment above the
Message definition accordingly.
- Around line 17-29: Add a short XML doc comment to the Message class describing
how terminated agents are handled: state that Message stores raw IAgent
references (Sender and Receiver) and that consumers or the mailbox are
responsible for checking IAgent.IsTerminated or subscribing to
IAgent.OnTerminated before delivering/processing messages to avoid operating on
terminated agents; mention that Message itself does not automatically remove or
null out references on termination. Update the summary for the Message
constructor and the Sender/Receiver properties (in the Message class) to
reference IAgent.IsTerminated and OnTerminated so maintainers know where to
implement termination checks.

In `@Assets/Scripts/Agents/Messaging/MessagePayload.cs`:
- Around line 3-5: Fix the spelling typo in the class/file comment for
MessagePayload: change "envolopes" to "envelopes" in the top block comment that
describes MessagePayload and payload carriage by Message envelopes so the
comment reads correctly and remains clear for future readers.

In `@Assets/Scripts/Agents/Messaging/PendingMessage.cs`:
- Around line 3-5: Fix the spelling mistake in the class comment for the mailbox
queue item in PendingMessage.cs by changing "internaal" to "internal" (the
comment describing the mailbox's internal queue item that stores the Message
object and DeliverAt for the PendingMessage class/struct).
🪄 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: b899f98e-8555-4c43-ad9d-ef0b685d1c1e

📥 Commits

Reviewing files that changed from the base of the PR and between e8ddb89 and 589802e.

📒 Files selected for processing (10)
  • Assets/Scripts/Agents/Messaging.meta
  • Assets/Scripts/Agents/Messaging/IMessagePayload.cs
  • Assets/Scripts/Agents/Messaging/IMessagePayload.cs.meta
  • Assets/Scripts/Agents/Messaging/LatencyTable.cs
  • Assets/Scripts/Agents/Messaging/LatencyTable.cs.meta
  • Assets/Scripts/Agents/Messaging/Message.cs
  • Assets/Scripts/Agents/Messaging/Message.cs.meta
  • Assets/Scripts/Agents/Messaging/MessagePayload.cs
  • Assets/Scripts/Agents/Messaging/MessagePayload.cs.meta
  • Assets/Scripts/Agents/Messaging/PendingMessage.cs

Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs
Comment thread Assets/Scripts/Agents/Messaging/Message.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/Message.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/Message.cs
Comment thread Assets/Scripts/Agents/Messaging/MessagePayload.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/PendingMessage.cs Outdated
Copy link
Copy Markdown
Member

@tryuan99 tryuan99 left a comment

Choose a reason for hiding this comment

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

  1. Please address or resolve the AI PR review before requesting a review.
  2. Add newlines to all files.
  3. Comment style in this repo is // Some comment that starts with capital letter and ends with a period.
  4. Run pre-commit install and make sure that clang-format is enabled before each commit.

Comment thread Assets/Scripts/Agents/Messaging/IMessagePayload.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs Outdated
Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs
Comment thread Assets/Scripts/Agents/Messaging/PendingMessage.cs Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Assets/Scripts/Agents/Messaging/LatencyTable.cs`:
- Line 51: The exception message is wrong: update the
ArgumentOutOfRangeException thrown for the parameter named node to reference
CommsNode (e.g., "Unknown CommsNode" or "Unknown CommsNode type.")—modify the
throw statement that currently reads throw new
ArgumentOutOfRangeException(nameof(node), node, "Unknown Interceptor Type."); so
it accurately mentions CommsNode (keep nameof(node) and node arguments
unchanged).
🪄 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: 3040908b-ff3c-49ff-bdfc-7edfab1fba8e

📥 Commits

Reviewing files that changed from the base of the PR and between 589802e and 6861d67.

📒 Files selected for processing (5)
  • Assets/Scripts/Agents/Messaging/IMessagePayload.cs
  • Assets/Scripts/Agents/Messaging/LatencyTable.cs
  • Assets/Scripts/Agents/Messaging/Message.cs
  • Assets/Scripts/Agents/Messaging/MessagePayload.cs
  • Assets/Scripts/Agents/Messaging/PendingMessage.cs

Comment thread Assets/Scripts/Agents/Messaging/LatencyTable.cs
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