Skip to content

[Communication] PR6: InterceptorBase.cs now supports mailbox.#218

Open
Joseph0120 wants to merge 3 commits intojoseph/communication_delay_PR5from
joseph/communication_delay_PR6
Open

[Communication] PR6: InterceptorBase.cs now supports mailbox.#218
Joseph0120 wants to merge 3 commits intojoseph/communication_delay_PR5from
joseph/communication_delay_PR6

Conversation

@Joseph0120
Copy link
Copy Markdown
Collaborator

Files Modified:
InterceptorBase.cs

Description:
Replaced all ?.Invoke to SendRequest function calls at the bottom.

Added SendRequest Functions: SendAssignRequestToParent(IInterceptor subInterceptor), SendReassignRequestToParent(IHierarchical target), SendAssignTargetToSub(IInterceptor subInterceptor, IHierarchical target)

These SendRequest functions then call on SendMessage(Message message) that sends message into the mailbox.

When recieving messages it handles with OnMessage(Message message). OnMessage "opens/unpack" the messages and read and executes the information contained by the message envelopes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Warning

Rate limit exceeded

@Joseph0120 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 54 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 54 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c866f295-ac04-4206-9bf7-5f8709d6c8ff

📥 Commits

Reviewing files that changed from the base of the PR and between 2223dc0 and 9f5782b.

📒 Files selected for processing (1)
  • Assets/Scripts/Interceptors/InterceptorBase.cs
📝 Walkthrough

Walkthrough

This PR adds three new Unity metadata files for script assets and refactors InterceptorBase.cs to implement a mailbox-based messaging system for agent coordination. The refactoring replaces direct event invocations (OnAssignSubInterceptor and OnReassignTarget) with structured message types: AssignSubInterceptorRequestMessage, ReassignTargetRequestMessage, and AssignTargetMessage. New properties NodeType and CommsParent are added, along with a message handler to process incoming messages and route them to corresponding assignment and reassignment methods.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • daniellovell
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% 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 title clearly and specifically describes the main change: InterceptorBase.cs now supports mailbox-based messaging, which is the primary focus of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the replacement of event invocations with mailbox-based request functions and message handling.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch joseph/communication_delay_PR6

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.

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

stacklane-pr-stack-visualizer bot commented Apr 1, 2026

🧱 Stack PR · Part 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 transitions the InterceptorBase class from an event-driven model to a mailbox-based messaging system for target assignments. Key changes include the introduction of a CommsParent property, message-sending helper methods, and an OnMessage handler to process incoming requests. Review feedback identifies significant logic issues in the AssignSubInterceptor method, specifically regarding incorrect capacity checks and the handling of target reassignment requests, alongside minor syntax errors like double semicolons.

if (subInterceptor.CapacityRemaining <= 0) {
return;
}
if (subInterceptor == null || subInterceptor.Capacity <= 0) { return; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The check has been changed from CapacityRemaining to Capacity. Capacity represents the total potential capacity of the interceptor, whereas CapacityRemaining represents its current availability. If an interceptor is already at full capacity (i.e., CapacityRemaining <= 0), it should not be assigned more work. Using Capacity here could lead to an infinite loop of target requests if the interceptor is full but has a non-zero total capacity.

    if (subInterceptor == null || subInterceptor.CapacityRemaining <= 0) { return; }

Comment on lines 116 to 125
if (target != null) {
SendAssignTargetToSub(subInterceptor, target);
} else {
SendAssignRequestToParent(subInterceptor);
}
// Evaluate the new target and decide whether to continue searching for other targets.
if (!subInterceptor.EvaluateReassignedTarget(target)) {
// Propagate the sub-interceptor target assignment to the parent interceptor above.
OnAssignSubInterceptor?.Invoke(subInterceptor);
SendReassignRequestToParent(target);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The updated logic in AssignSubInterceptor has a few issues:

  1. If target is null, it sends an assignment request to the parent (line 119) but then proceeds to call SendReassignRequestToParent(null) at line 124 (which is a no-op but redundant).
  2. If a non-null target is rejected by the sub-interceptor (line 122), the original behavior of requesting a new target for that sub-interceptor is lost, as it only sends a reassignment request for the target.
  3. There is a mix of synchronous state modification (subInterceptor.EvaluateReassignedTarget) and asynchronous messaging (SendAssignTargetToSub).

To maintain the original behavior while correctly handling the new mailbox communication, consider this refactoring:

    if (target != null) {
      SendAssignTargetToSub(subInterceptor, target);
    }
    // Evaluate the new target and decide whether to continue searching for other targets.
    if (!subInterceptor.EvaluateReassignedTarget(target)) {
      // Propagate the sub-interceptor target assignment to the parent interceptor above.
      SendAssignRequestToParent(subInterceptor);
      SendReassignRequestToParent(target);
    }


// Request a new target from the parent interceptor.
OnAssignSubInterceptor?.Invoke(interceptor);
SendAssignRequestToParent(interceptor);;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Detected a double semicolon at the end of the line.

    SendAssignRequestToParent(interceptor);

if (interceptor.IsReassignable) {
// Request a new target from the parent interceptor.
OnAssignSubInterceptor?.Invoke(interceptor);
SendAssignRequestToParent(interceptor);;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Detected a double semicolon at the end of the line.

      SendAssignRequestToParent(interceptor);

@Joseph0120 Joseph0120 changed the title [Communication] InterceptorBase.cs now supports mailbox. [Communication] PR6: InterceptorBase.cs now supports mailbox. Apr 1, 2026
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: 3

🤖 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/Interceptors/InterceptorBase.cs`:
- Line 287: The call to SendAssignRequestToParent(interceptor) in class
InterceptorBase contains a duplicate semicolon creating an empty statement; edit
the method containing that call (look for SendAssignRequestToParent(interceptor)
in InterceptorBase.cs) and remove the extra trailing semicolon so the line reads
a single statement terminated by one semicolon, then rebuild to ensure no
warnings remain.
- Line 313: Remove the stray duplicate semicolon after the call to
SendAssignRequestToParent(interceptor) in InterceptorBase (the extra ";" should
be deleted so the line reads SendAssignRequestToParent(interceptor);); also scan
the other occurrence of SendAssignRequestToParent calls (the one noted similarly
earlier) and ensure no extra semicolons remain to keep consistent formatting.
- Around line 399-419: The AssignTargetMessage branch in OnMessage calls
EvaluateReassignedTarget(assignTarget.PayloadData.Target) twice causing
side-effects on HierarchicalAgent.Target and incorrect RequestReassignment
logic; change the code to call EvaluateReassignedTarget once, store its boolean
result in a local variable (e.g., accepted) and use that for the conditional
RequestReassignment(this) decision, and also fix the comment typo "recieving" to
"receiving". Ensure you update the OnMessage method's AssignTargetMessage case
and use the stored result rather than re-invoking EvaluateReassignedTarget.
🪄 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: bc71fed2-5750-40d8-952b-6888e10e6003

📥 Commits

Reviewing files that changed from the base of the PR and between cfb9e96 and 2223dc0.

📒 Files selected for processing (4)
  • Assets/Scripts/Agents/Messaging/Mailbox.cs.meta
  • Assets/Scripts/Agents/Messaging/PendingMessage.cs.meta
  • Assets/Scripts/IADS/IadsCommsAgent.cs.meta
  • Assets/Scripts/Interceptors/InterceptorBase.cs


// Request a new target from the parent interceptor.
OnAssignSubInterceptor?.Invoke(interceptor);
SendAssignRequestToParent(interceptor);;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove duplicate semicolon.

There's a double semicolon (;;) at the end of this line, which creates an unnecessary empty statement.

Proposed fix
-    SendAssignRequestToParent(interceptor);;
+    SendAssignRequestToParent(interceptor);
📝 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
SendAssignRequestToParent(interceptor);;
SendAssignRequestToParent(interceptor);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Assets/Scripts/Interceptors/InterceptorBase.cs` at line 287, The call to
SendAssignRequestToParent(interceptor) in class InterceptorBase contains a
duplicate semicolon creating an empty statement; edit the method containing that
call (look for SendAssignRequestToParent(interceptor) in InterceptorBase.cs) and
remove the extra trailing semicolon so the line reads a single statement
terminated by one semicolon, then rebuild to ensure no warnings remain.

if (interceptor.IsReassignable) {
// Request a new target from the parent interceptor.
OnAssignSubInterceptor?.Invoke(interceptor);
SendAssignRequestToParent(interceptor);;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove duplicate semicolon.

Same issue as line 287 - there's a double semicolon.

Proposed fix
-      SendAssignRequestToParent(interceptor);;
+      SendAssignRequestToParent(interceptor);
📝 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
SendAssignRequestToParent(interceptor);;
SendAssignRequestToParent(interceptor);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Assets/Scripts/Interceptors/InterceptorBase.cs` at line 313, Remove the stray
duplicate semicolon after the call to SendAssignRequestToParent(interceptor) in
InterceptorBase (the extra ";" should be deleted so the line reads
SendAssignRequestToParent(interceptor);); also scan the other occurrence of
SendAssignRequestToParent calls (the one noted similarly earlier) and ensure no
extra semicolons remain to keep consistent formatting.

Comment on lines +399 to +419
// Execution happens here after recieving and reading message. PayloadData is read and handled.
protected override void OnMessage(Message message) {
if (message == null) {
return;
}
switch (message) {
case AssignSubInterceptorRequestMessage assignRequest:
AssignSubInterceptor(assignRequest.PayloadData.SubInterceptor);
break;
case ReassignTargetRequestMessage reassignRequest:
ReassignTarget(reassignRequest.PayloadData.Target);
break;
case AssignTargetMessage assignTarget:
EvaluateReassignedTarget(assignTarget.PayloadData.Target);
// EvaluateReassignedTarget. If it is false then bounce back: send a RequestReassignment upwards.
if (!EvaluateReassignedTarget(assignTarget.PayloadData.Target)) {
RequestReassignment(this);
}
break;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical bug: EvaluateReassignedTarget is called twice.

In the AssignTargetMessage case, EvaluateReassignedTarget is invoked twice:

  1. Line 412: Called unconditionally (modifies HierarchicalAgent.Target if accepted)
  2. Line 414: Called again in the if condition

The first call may accept and assign the target, causing the second call to always return false (since the target is now current). This leads to unnecessary RequestReassignment calls and potentially incorrect behavior.

Also, minor typo on line 399: "recieving" → "receiving".

Proposed fix
-  // Execution happens here after recieving and reading message. PayloadData is read and handled.
+  // Execution happens here after receiving and reading message. PayloadData is read and handled.
   protected override void OnMessage(Message message) {
     if (message == null) {
       return;
     }
     switch (message) {
       case AssignSubInterceptorRequestMessage assignRequest:
         AssignSubInterceptor(assignRequest.PayloadData.SubInterceptor);
         break;
       case ReassignTargetRequestMessage reassignRequest:
         ReassignTarget(reassignRequest.PayloadData.Target);
         break;
       case AssignTargetMessage assignTarget:
-        EvaluateReassignedTarget(assignTarget.PayloadData.Target);
-        // EvaluateReassignedTarget. If it is false then bounce back: send a RequestReassignment upwards.
-        if (!EvaluateReassignedTarget(assignTarget.PayloadData.Target)) {
+        // If target is rejected, bounce back: send a RequestReassignment upwards.
+        if (!EvaluateReassignedTarget(assignTarget.PayloadData.Target)) {
           RequestReassignment(this);
         }
         break;
     }
   }
📝 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
// Execution happens here after recieving and reading message. PayloadData is read and handled.
protected override void OnMessage(Message message) {
if (message == null) {
return;
}
switch (message) {
case AssignSubInterceptorRequestMessage assignRequest:
AssignSubInterceptor(assignRequest.PayloadData.SubInterceptor);
break;
case ReassignTargetRequestMessage reassignRequest:
ReassignTarget(reassignRequest.PayloadData.Target);
break;
case AssignTargetMessage assignTarget:
EvaluateReassignedTarget(assignTarget.PayloadData.Target);
// EvaluateReassignedTarget. If it is false then bounce back: send a RequestReassignment upwards.
if (!EvaluateReassignedTarget(assignTarget.PayloadData.Target)) {
RequestReassignment(this);
}
break;
}
}
// Execution happens here after receiving and reading message. PayloadData is read and handled.
protected override void OnMessage(Message message) {
if (message == null) {
return;
}
switch (message) {
case AssignSubInterceptorRequestMessage assignRequest:
AssignSubInterceptor(assignRequest.PayloadData.SubInterceptor);
break;
case ReassignTargetRequestMessage reassignRequest:
ReassignTarget(reassignRequest.PayloadData.Target);
break;
case AssignTargetMessage assignTarget:
// If target is rejected, bounce back: send a RequestReassignment upwards.
if (!EvaluateReassignedTarget(assignTarget.PayloadData.Target)) {
RequestReassignment(this);
}
break;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Assets/Scripts/Interceptors/InterceptorBase.cs` around lines 399 - 419, The
AssignTargetMessage branch in OnMessage calls
EvaluateReassignedTarget(assignTarget.PayloadData.Target) twice causing
side-effects on HierarchicalAgent.Target and incorrect RequestReassignment
logic; change the code to call EvaluateReassignedTarget once, store its boolean
result in a local variable (e.g., accepted) and use that for the conditional
RequestReassignment(this) decision, and also fix the comment typo "recieving" to
"receiving". Ensure you update the OnMessage method's AssignTargetMessage case
and use the stored result rather than re-invoking EvaluateReassignedTarget.

@Joseph0120 Joseph0120 force-pushed the joseph/communication_delay_PR6 branch from 2223dc0 to 9f5782b Compare April 1, 2026 06:08
@Joseph0120 Joseph0120 requested a review from tryuan99 April 1, 2026 06:16
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