Skip to content

[PR2] Added IADS Proxy - #211

Closed
Joseph0120 wants to merge 5 commits into
PisterLab:masterfrom
Joseph0120:joseph/comm_delay_PR2
Closed

Joseph0120 wants to merge 5 commits into
PisterLab:masterfrom
Joseph0120:joseph/comm_delay_PR2

Conversation

@Joseph0120

Copy link
Copy Markdown
Collaborator

File Changed:
IadsCommsAgent.cs

Description:
IadsCommsAgent.cs is an IADS Proxy for supporting mailbox message sending and receiving.

@stacklane-pr-stack-visualizer

stacklane-pr-stack-visualizer Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

🧱 Stack PR · Base of stack

Stack Structure:

@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 introduces a messaging system for inter-agent communication, including message envelopes, payloads, and a latency management table. Feedback focuses on improving the robustness of the LatencyTable using a dictionary, fixing documentation typos, and refactoring IadsCommsAgent to address Liskov Substitution Principle violations and remove redundant serialized fields.

Comment on lines +15 to +36
public sealed class LatencyTable {
private readonly float[,] _latency;

// creates empty _latency array with defaultSeconds seconds each
public LatencyTable(float defaultSeconds = 0f) {
int n = Enum.GetValues(typeof(CommsNode)).Length;
_latency = new float[n, n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
_latency[i, j] = defaultSeconds;
}
}
}

public void Set(CommsNode from, CommsNode to, float seconds) {
_latency[(int) from, (int) to] = Mathf.Max(0f, seconds);
}

public float Get(CommsNode from, CommsNode to) {
return _latency[(int) from, (int) to];
}
} No newline at end of file

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 current implementation of LatencyTable is fragile because it uses an array indexed by casting the CommsNode enum to an integer. This assumes that enum values are contiguous and start at 0. If the enum is modified in the future (e.g., adding non-contiguous values or changing the start index), this will lead to an IndexOutOfRangeException. Using a Dictionary with a tuple key is a more robust and maintainable approach that avoids these assumptions.

public sealed class LatencyTable {
    private readonly System.Collections.Generic.Dictionary<(CommsNode, CommsNode), float> _latency = new();
    private readonly float _defaultSeconds;

    public LatencyTable(float defaultSeconds = 0f) {
        _defaultSeconds = defaultSeconds;
    }

    public void Set(CommsNode from, CommsNode to, float seconds) {
        _latency[(from, to)] = Mathf.Max(0f, seconds);
    }

    public float Get(CommsNode from, CommsNode to) {
        return _latency.TryGetValue((from, to), out float seconds) ? seconds : _defaultSeconds;
    }
}

Comment on lines +3 to +6
/* 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) */

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

Correcting several typos in the documentation comments ('envolope' -> 'envelope', 'Reciever' -> 'Receiver', 'interntionally' -> 'intentionally') to improve readability and maintain professional standards.

/* 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) */


/* IADS Proxy for supporting mailbox message sending and recreceiving. */

public class IadsCommsAgent : MonoBehaviour, IAgent {

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

Implementing the full IAgent interface while throwing NotSupportedException for the majority of its members is a violation of the Liskov Substitution Principle. This suggests that the IAgent interface may be too broad, combining messaging identity with physical simulation capabilities. Consider refactoring the interface hierarchy to separate these concerns, allowing proxy agents to implement only the relevant subset of functionality.

Comment on lines +12 to +53
[SerializeField]
private Vector3 _velocity = Vector3.zero;

[SerializeField]
private Vector3 _acceleration = Vector3.zero;

[SerializeField]
private Vector3 _accelerationInput = Vector3.zero;

public HierarchicalAgent HierarchicalAgent {
get => _hierarchicalAgent;
set => _hierarchicalAgent = value;
}

public Configs.StaticConfig StaticConfig { get; set; }
public Configs.AgentConfig AgentConfig { get; set; }
public IMovement Movement { get; set; }
public IController Controller { get; set; }
public ISensor Sensor { get; set; }
public IAgent TargetModel { get; set; }

public Vector3 Position {
get => transform.position;
set => transform.position = value;
}

public Vector3 Velocity {
get => _velocity;
set => _velocity = value;
}

public float Speed => _velocity.magnitude;

public Vector3 Acceleration {
get => _acceleration;
set => _acceleration = value;
}

public Vector3 AccelerationInput {
get => _accelerationInput;
set => _accelerationInput = value;
}

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

The serialized fields _velocity, _acceleration, and _accelerationInput are redundant for a 'comms-only' proxy agent. Since this agent does not participate in physical simulation and its movement-related methods throw NotSupportedException, these fields should be removed to avoid confusion in the Unity Inspector and reduce memory overhead. The properties should return Vector3.zero and 0f directly.

  public HierarchicalAgent HierarchicalAgent {
    get => _hierarchicalAgent;
    set => _hierarchicalAgent = value;
  }

  public Configs.StaticConfig StaticConfig { get; set; }
  public Configs.AgentConfig AgentConfig { get; set; }
  public IMovement Movement { get; set; }
  public IController Controller { get; set; }
  public ISensor Sensor { get; set; }
  public IAgent TargetModel { get; set; }

  public Vector3 Position {
    get => transform.position;
    set => transform.position = value;
  }

  public Vector3 Velocity {
    get => Vector3.zero;
    set { }
  }

  public float Speed => 0f;

  public Vector3 Acceleration {
    get => Vector3.zero;
    set { }
  }

  public Vector3 AccelerationInput {
    get => Vector3.zero;
    set { }
  }

@Joseph0120 Joseph0120 closed this Mar 31, 2026
@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a complete messaging system for inter-agent communication. It adds an IMessagePayload marker interface and three concrete payload types (AssignSubInterceptorRequestPayload, AssignTargetPayload, ReassignTargetRequestPayload). A MessageType enum and abstract Message base class define the messaging contract, with three sealed message implementations for specific inter-agent commands. A LatencyTable class models network latency via an n×n matrix indexed by a three-node CommsNode enum (IADS, Carrier, Interceptor). A PendingMessage struct combines messages with delivery timestamps. The new IadsCommsAgent component implements IAgent as a communications-only proxy that delegates position and motion properties to a HierarchicalAgent while throwing NotSupportedException for unsupported simulation operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • daniellovell
🚥 Pre-merge checks | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title '[PR2] Added IADS Proxy' refers only to IadsCommsAgent.cs, but the changeset includes 6 new files: IMessagePayload interface, LatencyTable with CommsNode enum, Message base class with three message types, three message payload classes, PendingMessage struct, and IadsCommsAgent. The title only covers the final component and misses the bulk of infrastructure. Revise the title to reflect the complete scope, such as 'Add messaging framework and IADS communications proxy' or 'Implement inter-agent messaging system with latency table and IADS proxy'.
Description check ⚠️ Warning The description states only that 'IadsCommsAgent.cs is an IADS Proxy' but the changeset adds five other critical files: message interface, latency table, message base class, payload types, and pending message struct. The description omits the majority of changes and is incomplete. Expand the description to document all new components, including the messaging framework (Message, MessagePayload types), latency table, and their roles in the inter-agent communication system.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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