Skip to content

fix(config): reject non-positive explorer_sync_interval / trainer_sync_interval - #626

Open
Linxiushen wants to merge 1 commit into
agentscope-ai:mainfrom
Linxiushen:fix-sync-interval-overrides-positive
Open

Linxiushen wants to merge 1 commit into
agentscope-ai:mainfrom
Linxiushen:fix-sync-interval-overrides-positive

Conversation

@Linxiushen

Copy link
Copy Markdown

Problem

SynchronizerConfigValidator asserts that synchronizer.sync_interval is positive, but the two per-role overrides that default to it, explorer_sync_interval and trainer_sync_interval, have no range check. Setting either to 0 passes that validator and then crashes further down the validator chain:

File "trinity/common/config_validator.py", line 895, in validate
    if config.explorer.eval_interval % config.synchronizer.explorer_sync_interval != 0:
ZeroDivisionError: integer modulo by zero

Reachability, stated plainly: the two fields are not mentioned in the docs or in any example config (they are only described in a comment in config.py), so a user has to know about them from the dataclass. Once used, 0 is an easy mistake for "sync every step". The consequence is a confusing traceback at config time instead of a clear validation error; there is no wrong numeric result.

Fix

Add the same positivity assertions the validator already uses for sync_interval, placed right after the two set_if_none calls so that inherited values are checked too:

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."

Any configuration with positive values is unaffected. I ran all 74 YAML files under examples/ and tests/template through the validator chain before and after the change: outcomes and the resolved interval values are identical (none of them set these fields).

Test

test_sync_interval_overrides_must_be_positive in tests/common/config_test.py, one subtest per field. Without the fix both subtests fail with the ZeroDivisionError above; with it they pass with the expected AssertionError.

Placed next to test_multinode_vllm_requires_full_node_occupancy rather than at the end of the class, to avoid a textual conflict with the test that #613 adds at the end.

pre-commit pins (black 23.7.0, isort 5.12.0, flake8 6.1.0) pass on both files.


This fix was developed with AI assistance (Claude); the change and the test were reviewed and verified locally before submission.

…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.
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