fix: add controller config validation and clear error messages (#2907)#3003
fix: add controller config validation and clear error messages (#2907)#3003maobaolong merged 1 commit intoLMCache:devfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances configuration validation by adding descriptive error messages to assertions in the worker and implementing a validation block in the config module for controller-related settings. Feedback suggests replacing assert statements with explicit ValueError exceptions to prevent validation from being optimized away in production. It is also recommended to ensure that the worker ports list is not empty, rather than only checking if it is null.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8f66498. Configure here.
|
Thanks for the thorough review! I've adopted all suggestions in the latest force-push: worker.py (4 changes): Replaced all config.py (1 change, per @maobaolong's request): Changed Tests: Added |
When enable_controller=True but required config fields are missing, _validate_config() now raises ValueError with clear messages instead of silently passing and crashing later with an empty AssertionError. Also added descriptive messages to bare assert statements in worker.py as defense-in-depth. Fixes LMCache#2907 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Yiyang Liu <yiyangliu@microsoft.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com>
|
@ApostaC @DongDongJu Friendly ping this has 1 approval from @sammshen (LGTM). Could one of you do a second review? All feedback from @maobaolong has been addressed. Thanks! |
maobaolong
left a comment
There was a problem hiding this comment.
LGTM @ianliuy Thanks for this improvement.
…he#2907) (LMCache#3003) fix: add controller config validation and descriptive error messages When enable_controller=True but required config fields are missing, _validate_config() now raises ValueError with clear messages instead of silently passing and crashing later with an empty AssertionError. Also added descriptive messages to bare assert statements in worker.py as defense-in-depth. Fixes LMCache#2907 Signed-off-by: Yiyang Liu <yiyangliu@microsoft.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…he#2907) (LMCache#3003) fix: add controller config validation and descriptive error messages When enable_controller=True but required config fields are missing, _validate_config() now raises ValueError with clear messages instead of silently passing and crashing later with an empty AssertionError. Also added descriptive messages to bare assert statements in worker.py as defense-in-depth. Fixes LMCache#2907 Signed-off-by: Yiyang Liu <yiyangliu@microsoft.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Summary
Fixes #2907 LMCache emits an empty error message when
enable_controller=Truebut required config fields are missing.Root Cause
Two interacting bugs:
Missing validation in
_validate_config(): Whenenable_controller=True, no validation was performed for required controller fields (lmcache_instance_id,controller_pull_url,controller_reply_url,lmcache_worker_ports). Config silently passed withNonevalues, causing a runtime failure deep in the worker init.Bare
assertstatements inworker.py: Checks likeassert config.controller_pull_url is not NoneraiseAssertionErrorwith an empty string when they fail, resulting in the confusing": ."in the error log.Changes
lmcache/v1/config.pyif self.enable_controller:validation block in_validate_config()raise ValueError(...)and a clear messagelmcache_worker_portsalso rejects empty lists (not justNone)enable_p2pvalidation in the same methodlmcache/v1/cache_controller/worker.pyassertstatements with explicitif/raise ValueErrorchecksValueErrorinstead ofassertto ensure validation is not bypassed bypython -Otests/v1/test_config.pyValueErrorlmcache_worker_portslistValueErrorenable_controller=Falsewith missing fields no errorBefore / After
Before:
After (at config creation time):
Testing
if self.enable_controller:block is never entered whenenable_controller=False)