Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c6036e4
time system checks
leshy Feb 22, 2026
7daff8b
refactor(system_configurator): split into package with separate modules
leshy Feb 22, 2026
2953877
refactor: remove unitree_clock_sync wrapper, use system_checks directly
leshy Feb 22, 2026
d5bdf2a
refactor: consolidate human-readable formatters into dimos/utils/huma…
leshy Feb 22, 2026
c9c63f8
fix(clock_sync): use ntpdate/sntp instead of systemd for clock fix
leshy Feb 22, 2026
f2c499b
refactor: add human_number() for SI-suffixed number formatting
leshy Feb 22, 2026
41ee2b8
blueprint configurator support
leshy Feb 22, 2026
0a35bb3
clock configurator refactor
leshy Feb 22, 2026
c0b90f9
configurator API comment
leshy Feb 22, 2026
b25ad8d
small fixes
leshy Feb 22, 2026
7f5ee1b
200ms time tolerance
leshy Feb 22, 2026
5386891
small fixes
leshy Feb 22, 2026
8edc995
use typer.confirm and logger instead of input/print in system configu…
leshy Feb 24, 2026
0047c0e
Merge remote-tracking branch 'origin/dev' into ivan/feat/clock-sync-c…
leshy Feb 24, 2026
f1fa5e6
remove markdown paths-ignore from code-cleanup workflow
leshy Feb 24, 2026
5ed6f28
Merge remote-tracking branch 'origin/dev' into ivan/feat/clock-sync-c…
leshy Feb 24, 2026
1389b2c
removed autoconf from cli
leshy Feb 24, 2026
a3bc16a
Merge remote-tracking branch 'origin/dev' into ivan/feat/clock-sync-c…
leshy Feb 26, 2026
449d654
feat(blueprints): separate .configurators() from .requirements()
leshy Feb 26, 2026
2628159
configurators list cleanup
leshy Feb 26, 2026
5613a69
blueprints gen bugfix
leshy Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/code-cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: code-cleanup
on:
pull_request:
paths-ignore:
- '**.md'

permissions:
contents: write
Expand Down
38 changes: 37 additions & 1 deletion dimos/core/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import operator
import sys
from types import MappingProxyType
from typing import Any, Literal, get_args, get_origin, get_type_hints
from typing import TYPE_CHECKING, Any, Literal, get_args, get_origin, get_type_hints

if TYPE_CHECKING:
from dimos.protocol.service.system_configurator.base import SystemConfigurator

from dimos.core.global_config import GlobalConfig, global_config
from dimos.core.module import Module, is_module_type
Expand Down Expand Up @@ -109,6 +112,7 @@ class Blueprint:
default_factory=lambda: MappingProxyType({})
)
requirement_checks: tuple[Callable[[], str | None], ...] = field(default_factory=tuple)
configurator_checks: "tuple[SystemConfigurator, ...]" = field(default_factory=tuple)

@classmethod
def create(cls, module: type[Module], *args: Any, **kwargs: Any) -> "Blueprint":
Expand All @@ -122,6 +126,7 @@ def transports(self, transports: dict[tuple[str, type], Any]) -> "Blueprint":
global_config_overrides=self.global_config_overrides,
remapping_map=self.remapping_map,
requirement_checks=self.requirement_checks,
configurator_checks=self.configurator_checks,
)

def global_config(self, **kwargs: Any) -> "Blueprint":
Expand All @@ -131,6 +136,7 @@ def global_config(self, **kwargs: Any) -> "Blueprint":
global_config_overrides=MappingProxyType({**self.global_config_overrides, **kwargs}),
remapping_map=self.remapping_map,
requirement_checks=self.requirement_checks,
configurator_checks=self.configurator_checks,
)

def remappings(
Expand All @@ -146,6 +152,7 @@ def remappings(
global_config_overrides=self.global_config_overrides,
remapping_map=MappingProxyType(remappings_dict),
requirement_checks=self.requirement_checks,
configurator_checks=self.configurator_checks,
)

def requirements(self, *checks: Callable[[], str | None]) -> "Blueprint":
Expand All @@ -155,6 +162,17 @@ def requirements(self, *checks: Callable[[], str | None]) -> "Blueprint":
global_config_overrides=self.global_config_overrides,
remapping_map=self.remapping_map,
requirement_checks=self.requirement_checks + tuple(checks),
configurator_checks=self.configurator_checks,
)

def configurators(self, *checks: "SystemConfigurator") -> "Blueprint":
return Blueprint(
blueprints=self.blueprints,
transport_map=self.transport_map,
global_config_overrides=self.global_config_overrides,
remapping_map=self.remapping_map,
requirement_checks=self.requirement_checks,
configurator_checks=self.configurator_checks + tuple(checks),
)

def _check_ambiguity(
Expand Down Expand Up @@ -202,6 +220,21 @@ def _all_name_types(self) -> set[tuple[str, type]]:
def _is_name_unique(self, name: str) -> bool:
return sum(1 for n, _ in self._all_name_types if n == name) == 1

def _run_configurators(self) -> None:
from dimos.protocol.service.system_configurator import configure_system, lcm_configurators

configurators = [*lcm_configurators(), *self.configurator_checks]

try:
configure_system(configurators)
except SystemExit:
labels = [type(c).__name__ for c in configurators]
print(
f"Required system configuration was declined: {', '.join(labels)}",
file=sys.stderr,
)
sys.exit(1)

def _check_requirements(self) -> None:
errors = []
red = "\033[31m"
Expand Down Expand Up @@ -461,6 +494,7 @@ def build(
if cli_config_overrides:
global_config.update(**dict(cli_config_overrides))

self._run_configurators()
self._check_requirements()
self._verify_no_name_conflicts()

Expand Down Expand Up @@ -490,13 +524,15 @@ def autoconnect(*blueprints: Blueprint) -> Blueprint:
reduce(operator.iadd, [list(x.remapping_map.items()) for x in blueprints], [])
)
all_requirement_checks = tuple(check for bs in blueprints for check in bs.requirement_checks)
all_configurator_checks = tuple(check for bs in blueprints for check in bs.configurator_checks)

return Blueprint(
blueprints=all_blueprints,
transport_map=MappingProxyType(all_transports),
global_config_overrides=MappingProxyType(all_config_overrides),
remapping_map=MappingProxyType(all_remappings),
requirement_checks=all_requirement_checks,
configurator_checks=all_configurator_checks,
)


Expand Down
14 changes: 4 additions & 10 deletions dimos/protocol/pubsub/benchmark/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
MsgGen,
PubSubContext,
)
from dimos.utils.human import human_bytes

# Message sizes for throughput benchmarking (powers of 2 from 64B to 10MB)
MSG_SIZES = [
Expand Down Expand Up @@ -56,15 +57,6 @@
RECEIVE_TIMEOUT = 1.0


def size_id(size: int) -> str:
"""Convert byte size to human-readable string for test IDs."""
if size >= 1048576:
return f"{size // 1048576}MB"
if size >= 1024:
return f"{size // 1024}KB"
return f"{size}B"


def pubsub_id(testcase: Case[Any, Any]) -> str:
"""Extract pubsub implementation name from context manager function name."""
name: str = testcase.pubsub_context.__name__
Expand All @@ -86,7 +78,9 @@ def benchmark_results() -> Generator[BenchmarkResults, None, None]:


@pytest.mark.tool
@pytest.mark.parametrize("msg_size", MSG_SIZES, ids=[size_id(s) for s in MSG_SIZES])
@pytest.mark.parametrize(
"msg_size", MSG_SIZES, ids=[human_bytes(s, concise=True, decimals=0) for s in MSG_SIZES]
)
@pytest.mark.parametrize("pubsub_context, msggen", testcases, ids=[pubsub_id(t) for t in testcases])
def test_throughput(
pubsub_context: PubSubContext[Any, Any],
Expand Down
50 changes: 9 additions & 41 deletions dimos/protocol/pubsub/benchmark/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any, Generic

from dimos.protocol.pubsub.spec import MsgT, PubSub, TopicT
from dimos.utils.human import human_bytes, human_duration, human_number

MsgGen = Callable[[int], tuple[TopicT, MsgT]]

Expand All @@ -41,33 +42,6 @@ def __len__(self) -> int:
TestData = Sequence[Case[Any, Any]]


def _format_mib(value: float) -> str:
"""Format bytes as MiB with intelligent rounding.

>= 10 MiB: integer (e.g., "42")
1-10 MiB: 1 decimal (e.g., "2.5")
< 1 MiB: 2 decimals (e.g., "0.07")
"""
mib = value / (1024**2)
if mib >= 10:
return f"{mib:.0f}"
if mib >= 1:
return f"{mib:.1f}"
return f"{mib:.2f}"


def _format_iec(value: float, concise: bool = False, decimals: int = 2) -> str:
"""Format bytes with IEC units (Ki/Mi/Gi = 1024^1/2/3)"""
k = 1024.0
units = ["B", "K", "M", "G", "T"] if concise else ["B", "KiB", "MiB", "GiB", "TiB"]

for unit in units[:-1]:
if abs(value) < k:
return f"{value:.{decimals}f}{unit}" if concise else f"{value:.{decimals}f} {unit}"
value /= k
return f"{value:.{decimals}f}{units[-1]}" if concise else f"{value:.{decimals}f} {units[-1]}"


@dataclass
class BenchmarkResult:
transport: str
Expand Down Expand Up @@ -133,11 +107,13 @@ def print_summary(self) -> None:
recv_style = "yellow" if r.receive_time > 0.1 else "dim"
table.add_row(
r.transport,
_format_iec(r.msg_size_bytes, decimals=0),
human_bytes(r.msg_size_bytes, decimals=0),
f"{r.msgs_sent:,}",
f"{r.msgs_received:,}",
f"{r.throughput_msgs:,.0f}",
_format_mib(r.throughput_bytes),
(lambda m: f"{m:.2f}" if m < 1 else f"{m:.1f}" if m < 10 else f"{m:.0f}")(
r.throughput_bytes / 1024**2
),
f"[{recv_style}]{r.receive_time * 1000:.0f}ms[/{recv_style}]",
f"[{loss_style}]{r.loss_pct:.1f}%[/{loss_style}]",
)
Expand Down Expand Up @@ -211,7 +187,7 @@ def val_to_color(v: float) -> int:
return gradient[int(t * (len(gradient) - 1))]

reset = "\033[0m"
size_labels = [_format_iec(s, concise=True, decimals=0) for s in sizes]
size_labels = [human_bytes(s, concise=True, decimals=0) for s in sizes]
col_w = max(8, max(len(s) for s in size_labels) + 1)
transport_w = max(len(t) for t in transports) + 1

Expand All @@ -236,31 +212,23 @@ def val_to_color(v: float) -> int:
def print_heatmap(self) -> None:
"""Print msgs/sec heatmap."""

def fmt(v: float) -> str:
return f"{v / 1000:.1f}k" if v >= 1000 else f"{v:.0f}"

self._print_heatmap("Msgs/sec", lambda r: r.throughput_msgs, fmt)
self._print_heatmap("Msgs/sec", lambda r: r.throughput_msgs, human_number)

def print_bandwidth_heatmap(self) -> None:
"""Print bandwidth heatmap."""

def fmt(v: float) -> str:
return _format_iec(v, concise=True, decimals=1)
return human_bytes(v, concise=True, decimals=1)

self._print_heatmap("Bandwidth (IEC)", lambda r: r.throughput_bytes, fmt)

def print_latency_heatmap(self) -> None:
"""Print latency heatmap (time waiting for messages after publishing)."""

def fmt(v: float) -> str:
if v >= 1:
return f"{v:.1f}s"
return f"{v * 1000:.0f}ms"

self._print_heatmap(
"Latency",
lambda r: r.receive_time,
fmt,
lambda v: human_duration(v, signed=False),
high_is_good=False,
)

Expand Down
29 changes: 4 additions & 25 deletions dimos/protocol/service/lcmservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
import lcm

from dimos.protocol.service.spec import Service
from dimos.protocol.service.system_configurator import (
BufferConfiguratorLinux,
BufferConfiguratorMacOS,
MaxFileConfiguratorMacOS,
MulticastConfiguratorLinux,
MulticastConfiguratorMacOS,
SystemConfigurator,
configure_system,
)
from dimos.protocol.service.system_configurator import configure_system, lcm_configurators
from dimos.utils.logging_config import setup_logger

logger = setup_logger()
Expand All @@ -46,22 +38,9 @@


def autoconf(check_only: bool = False) -> None:
# check multicast and buffer sizes
system = platform.system()
checks: list[SystemConfigurator] = []
if system == "Linux":
checks = [
MulticastConfiguratorLinux(loopback_interface="lo"),
BufferConfiguratorLinux(),
]
elif system == "Darwin":
checks = [
MulticastConfiguratorMacOS(loopback_interface="lo0"),
BufferConfiguratorMacOS(),
MaxFileConfiguratorMacOS(),
]
else:
logger.error(f"System configuration not supported on {system}")
checks = lcm_configurators()
if not checks:
logger.error(f"System configuration not supported on {platform.system()}")
return
configure_system(checks, check_only=check_only)

Expand Down
75 changes: 75 additions & 0 deletions dimos/protocol/service/system_configurator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2026 Dimensional Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""System configurator package — re-exports for backward compatibility."""

import platform

from dimos.protocol.service.system_configurator.base import (
SystemConfigurator,
configure_system,
sudo_run,
)
from dimos.protocol.service.system_configurator.clock_sync import ClockSyncConfigurator
from dimos.protocol.service.system_configurator.lcm import (
IDEAL_RMEM_SIZE,
BufferConfiguratorLinux,
BufferConfiguratorMacOS,
MaxFileConfiguratorMacOS,
MulticastConfiguratorLinux,
MulticastConfiguratorMacOS,
)


# TODO: This is a configurator API issue and inserted here temporarily
#
# We need to use different configurators based on the underlying OS
#
# We should have separation of concerns, nothing but configurators themselves care about the OS in this context
#
# So configurators with multi-os behavior should be responsible for the right per-OS behaviour, and
# not external systems
#
# We might want to have some sort of recursive configurators
#
def lcm_configurators() -> list[SystemConfigurator]:
"""Return the platform-appropriate LCM system configurators."""
system = platform.system()
if system == "Linux":
return [
MulticastConfiguratorLinux(loopback_interface="lo"),
BufferConfiguratorLinux(),
]
elif system == "Darwin":
return [
MulticastConfiguratorMacOS(loopback_interface="lo0"),
BufferConfiguratorMacOS(),
MaxFileConfiguratorMacOS(), # TODO: this is not LCM related and shouldn't be here at all
]
return []


__all__ = [
"IDEAL_RMEM_SIZE",
"BufferConfiguratorLinux",
"BufferConfiguratorMacOS",
"ClockSyncConfigurator",
"MaxFileConfiguratorMacOS",
"MulticastConfiguratorLinux",
"MulticastConfiguratorMacOS",
"SystemConfigurator",
"configure_system",
"lcm_configurators",
"sudo_run",
]
Loading
Loading