Skip to content

[Communication] PR4: CommsNode and Mailbox Simplification and Compatibility - #234

Closed
Joseph0120 wants to merge 7 commits into
joseph/communication_delay_PR3from
joseph/communication_delay_PR4
Closed

[Communication] PR4: CommsNode and Mailbox Simplification and Compatibility#234
Joseph0120 wants to merge 7 commits into
joseph/communication_delay_PR3from
joseph/communication_delay_PR4

Conversation

@Joseph0120

Copy link
Copy Markdown
Collaborator

No description provided.

@stacklane-pr-stack-visualizer

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request simplifies the communication system by refactoring CommsNode to delegate active state tracking to CommsManager instead of managing its own termination state. Corresponding updates were made to AgentBase, IADS, and Mailbox to register and check node activity via CommsManager. Feedback focuses on the complete deletion of the MailboxTests suite, which significantly reduces test coverage and should instead be updated to match the new design, as well as adding a safety check for SimManager.Instance in Mailbox.Send to prevent potential null reference exceptions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread Assets/Tests/EditMode/MailboxTests.cs Outdated
Comment thread Assets/Scripts/Communication/Mailbox.cs
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 59a065bf-49bf-41f5-a375-c8d3eb73d0b1

📥 Commits

Reviewing files that changed from the base of the PR and between eebe3c2 and 85bbe8f.

📒 Files selected for processing (1)
  • Assets/Scripts/IADS/IADS.cs

📝 Walkthrough

Walkthrough

Communication node registration is now null-safe and centralized through CommsManager methods for adding, removing, and checking nodes. Simulation lifecycle handling retains nodes until simulation end. IADS registers nodes only when a manager exists. Mailbox send and delivery paths require active sender and receiver nodes, skip inactive queued receivers, and change OnMessageDelivered to provide only the delivered Message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: tryuan99

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 pull request description was provided, so there is no substantive summary to evaluate. Add a brief description of the behavior changes and affected communication components.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main communication-related changes to CommsNode, Mailbox, and compatibility handling.
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 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_PR4

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.

Caution

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

⚠️ Outside diff range comments (2)
Assets/Scripts/IADS/IADS.cs (1)

48-51: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Check CommsManager.Instance for null.

In RegisterSimulationStarted and OnDestroy, you correctly null-check CommsManager.Instance before accessing it. However, in Start(), Instance is accessed directly. Depending on Unity's script execution order, CommsManager might not be fully initialized or could be missing from the scene, which would throw a NullReferenceException.

Apply the same null-check pattern here for safety and consistency.

🛡️ Proposed fix for consistent validation
     // Create a communication node for the IADS.
     CommsNode = new CommsNode(Configs.AgentType.Iads);
-    CommsManager.Instance.AddNode(CommsNode);
+    CommsManager commsManager = CommsManager.Instance;
+    if (commsManager != null) {
+      commsManager.AddNode(CommsNode);
+    }
   }
🤖 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/IADS/IADS.cs` around lines 48 - 51, Update Start() to guard
the CommsManager.Instance access with the same null-check pattern used in
RegisterSimulationStarted and OnDestroy, while preserving CommsNode creation and
registration when the manager exists.
Assets/Scripts/Managers/CommsManager.cs (1)

32-36: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Unsubscribe from SimManager events to prevent memory leaks.

CommsManager subscribes to events on SimManager.Instance but does not unsubscribe. If CommsManager is ever destroyed (e.g., during a scene transition or manual removal), it will cause a "Lapsed Listener" memory leak and potential missing reference exceptions since SimManager holds onto the delegates. Furthermore, the use of an anonymous lambda (() => _nodes.Clear()) makes unsubscription impossible.

Convert the lambda to a named method and implement OnDestroy() to safely clean up all three listeners.

🐛 Proposed fix to ensure lifecycle safety
   private void Start() {
-    SimManager.Instance.OnSimulationEnded += () => _nodes.Clear();
+    SimManager.Instance.OnSimulationEnded += ClearNodes;
     SimManager.Instance.OnNewInterceptor += RegisterNewAgent;
     SimManager.Instance.OnNewLauncher += RegisterNewAgent;
   }
+
+  private void ClearNodes() => _nodes.Clear();
+
+  private void OnDestroy() {
+    if (SimManager.Instance != null) {
+      SimManager.Instance.OnSimulationEnded -= ClearNodes;
+      SimManager.Instance.OnNewInterceptor -= RegisterNewAgent;
+      SimManager.Instance.OnNewLauncher -= RegisterNewAgent;
+    }
+  }
🤖 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/Managers/CommsManager.cs` around lines 32 - 36, Update
CommsManager.Start to subscribe a named handler instead of the anonymous () =>
_nodes.Clear() lambda, then add OnDestroy to unsubscribe that handler and
RegisterNewAgent from all three SimManager.Instance events. Keep the handler’s
existing _nodes.Clear behavior unchanged.
🤖 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.

Outside diff comments:
In `@Assets/Scripts/IADS/IADS.cs`:
- Around line 48-51: Update Start() to guard the CommsManager.Instance access
with the same null-check pattern used in RegisterSimulationStarted and
OnDestroy, while preserving CommsNode creation and registration when the manager
exists.

In `@Assets/Scripts/Managers/CommsManager.cs`:
- Around line 32-36: Update CommsManager.Start to subscribe a named handler
instead of the anonymous () => _nodes.Clear() lambda, then add OnDestroy to
unsubscribe that handler and RegisterNewAgent from all three SimManager.Instance
events. Keep the handler’s existing _nodes.Clear behavior unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b3b2a9fd-155c-4c5b-9634-d241bac7a545

📥 Commits

Reviewing files that changed from the base of the PR and between 969509b and 8c7b742.

📒 Files selected for processing (7)
  • Assets/Scripts/Agents/AgentBase.cs
  • Assets/Scripts/Communication/CommsNode.cs
  • Assets/Scripts/Communication/Mailbox.cs
  • Assets/Scripts/IADS/IADS.cs
  • Assets/Scripts/Managers/CommsManager.cs
  • Assets/Tests/EditMode/MailboxTests.cs
  • Assets/Tests/EditMode/MailboxTests.cs.meta
💤 Files with no reviewable changes (2)
  • Assets/Tests/EditMode/MailboxTests.cs.meta
  • Assets/Tests/EditMode/MailboxTests.cs

@Joseph0120 Joseph0120 changed the title [Communication] PR4 [Communication] PR4: CommsNode and Mailbox Simplification and Compatibility Jul 22, 2026
@Joseph0120
Joseph0120 requested a review from tryuan99 July 22, 2026 05:43
Comment thread Assets/Scripts/Agents/AgentBase.cs Outdated
Comment thread Assets/Scripts/Communication/CommsNode.cs
Comment thread Assets/Scripts/IADS/IADS.cs Outdated
@Joseph0120
Joseph0120 force-pushed the joseph/communication_delay_PR4 branch from ec703bb to 136b6f0 Compare July 22, 2026 07:21

@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: 4

🤖 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 171-176: Update IsNodeActive to return false when the supplied
CommsNode is terminated, preserving the existing null and CommsManager
membership checks. Ensure terminated receivers are rejected before they can be
queued and reported as delivered.
- Line 9: Update all subscribers of Mailbox.OnMessageDelivered, especially the
subscription in MailboxTests, to use a single Message parameter matching the
Action<Message> event contract; alternatively, restore the previous event
signature if two-parameter callbacks must remain supported.

In `@Assets/Scripts/IADS/IADS.cs`:
- Around line 61-64: Update IADS.Start() to safely handle a missing CommsManager
before registering CommsNode, matching the null-check already used in
RegisterSimulationStarted. Preserve registration when CommsManager.Instance is
available and avoid calling AddNode on a null manager.
- Around line 61-64: Update the IADS initialization flow around
CommsManager.Instance and AddNode so CommsNode registration occurs after
CommsManager’s simulation-start handler clears _nodes. Enforce an explicit
execution order or defer registration until the clear has completed, ensuring
CommsNode is not immediately removed.
🪄 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: 7a5b4f7d-2ecc-45c9-93f2-9d1bc8fc6570

📥 Commits

Reviewing files that changed from the base of the PR and between 8c7b742 and 136b6f0.

📒 Files selected for processing (3)
  • Assets/Scripts/Communication/Mailbox.cs
  • Assets/Scripts/IADS/IADS.cs
  • Assets/Scripts/Managers/CommsManager.cs

Comment thread Assets/Scripts/Communication/Mailbox.cs
Comment thread Assets/Scripts/Communication/Mailbox.cs
Comment thread Assets/Scripts/IADS/IADS.cs
@Joseph0120
Joseph0120 force-pushed the joseph/communication_delay_PR4 branch from b6cb9d4 to eebe3c2 Compare July 23, 2026 16:38

@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: 1

🤖 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/IADS/IADS.cs`:
- Around line 61-64: Guard the initial communications registration in
IADS.Start() by checking CommsManager.Instance before calling
AddNode(CommsNode), matching the existing null-safe registration logic. Ensure
startup proceeds without throwing when no CommsManager exists.
🪄 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 Plus

Run ID: e8cdc031-331d-4e58-87a2-60306f1c8beb

📥 Commits

Reviewing files that changed from the base of the PR and between 136b6f0 and eebe3c2.

📒 Files selected for processing (3)
  • Assets/Scripts/Communication/Mailbox.cs
  • Assets/Scripts/IADS/IADS.cs
  • Assets/Scripts/Managers/CommsManager.cs

Comment thread Assets/Scripts/IADS/IADS.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