From 7769a34c82553ba473bbb431658c0b73de823f09 Mon Sep 17 00:00:00 2001 From: Linxiushen <1787979356@qq.com> Date: Mon, 21 Sep 2026 21:13:48 +0800 Subject: [PATCH] fix(config): reject non-positive `explorer_sync_interval` / `trainer_sync_interval` SynchronizerConfigValidator asserts that `sync_interval` is positive, but the two per-role overrides that default to it, `explorer_sync_interval` and `trainer_sync_interval`, had no range check. Setting either to 0 passed validation and then crashed later in IntervalConfigValidator with `ZeroDivisionError: integer modulo by zero` (config_validator.py:895), instead of failing with a clear message. Add the same positivity assertions right after the two set_if_none calls, so inherited values are checked as well. Configurations with positive values are unaffected; none of the shipped example configs set these fields. --- tests/common/config_test.py | 10 ++++++++++ trinity/common/config_validator.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/tests/common/config_test.py b/tests/common/config_test.py index 3ed9c797b7e..a1c8a31d42e 100644 --- a/tests/common/config_test.py +++ b/tests/common/config_test.py @@ -135,6 +135,16 @@ def test_multinode_vllm_requires_full_node_occupancy(self): with self.assertRaisesRegex(ValueError, "to be a multiple of"): config.check_and_update() + def test_sync_interval_overrides_must_be_positive(self): + for field in ("explorer_sync_interval", "trainer_sync_interval"): + with self.subTest(field=field): + config = get_template_config() + config.synchronizer.sync_interval = 4 + setattr(config.synchronizer, field, 0) + + with self.assertRaisesRegex(AssertionError, f"`{field}` must be positive"): + config.check_and_update() + def test_load_default_config(self): config = get_template_config() config.buffer.batch_size = 8 diff --git a/trinity/common/config_validator.py b/trinity/common/config_validator.py index abc38b1332f..551e17af388 100644 --- a/trinity/common/config_validator.py +++ b/trinity/common/config_validator.py @@ -868,6 +868,12 @@ def validate(self, config: Config) -> None: config.synchronizer, "explorer_sync_interval", config.synchronizer.sync_interval ) set_if_none(config.synchronizer, "trainer_sync_interval", config.synchronizer.sync_interval) + assert ( + config.synchronizer.explorer_sync_interval > 0 + ), "`explorer_sync_interval` must be positive." + assert ( + config.synchronizer.trainer_sync_interval > 0 + ), "`trainer_sync_interval` must be positive." class IntervalConfigValidator(ConfigValidator):