Skip to content

fix: add controller config validation and clear error messages (#2907)#3003

Merged
maobaolong merged 1 commit intoLMCache:devfrom
ianliuy:fix/issue-2907
Apr 14, 2026
Merged

fix: add controller config validation and clear error messages (#2907)#3003
maobaolong merged 1 commit intoLMCache:devfrom
ianliuy:fix/issue-2907

Conversation

@ianliuy
Copy link
Copy Markdown
Contributor

@ianliuy ianliuy commented Apr 12, 2026

Summary

Fixes #2907 LMCache emits an empty error message when enable_controller=True but required config fields are missing.

Root Cause

Two interacting bugs:

  1. Missing validation in _validate_config(): When enable_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 with None values, causing a runtime failure deep in the worker init.

  2. Bare assert statements in worker.py: Checks like assert config.controller_pull_url is not None raise AssertionError with an empty string when they fail, resulting in the confusing ": ." in the error log.

Changes

lmcache/v1/config.py

  • Added if self.enable_controller: validation block in _validate_config()
  • Each required field is individually checked with raise ValueError(...) and a clear message
  • lmcache_worker_ports also rejects empty lists (not just None)
  • Follows the existing pattern used for enable_p2p validation in the same method

lmcache/v1/cache_controller/worker.py

  • Replaced 4 bare assert statements with explicit if/raise ValueError checks
  • Port-count checks now include actual vs expected values in f-strings
  • Uses ValueError instead of assert to ensure validation is not bypassed by python -O

tests/v1/test_config.py

  • Added 7 test cases covering all controller validation paths:
    • Each required field missing individually ValueError
    • Empty lmcache_worker_ports list ValueError
    • Valid config with all fields no error
    • enable_controller=False with missing fields no error

Before / After

Before:

LMCache ERROR: Failed to initialize LMCacheManager components: . System will operate in degraded mode (recompute).

After (at config creation time):

ValueError: controller_pull_url is required when enable_controller=True

Testing

  • 7 new unit tests added and passing
  • Zero impact on correctly-configured setups (if self.enable_controller: block is never entered when enable_controller=False)
  • No existing tests broken

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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

Comment thread lmcache/v1/cache_controller/worker.py Outdated
Comment thread lmcache/v1/cache_controller/worker.py Outdated
Comment thread lmcache/v1/cache_controller/worker.py Outdated
Comment thread lmcache/v1/cache_controller/worker.py Outdated
Comment thread lmcache/v1/config.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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

Comment thread lmcache/v1/config.py
@ianliuy
Copy link
Copy Markdown
Contributor Author

ianliuy commented Apr 13, 2026

Thanks for the thorough review! I've adopted all suggestions in the latest force-push:

worker.py (4 changes): Replaced all assert statements with explicit if/raise ValueError fully agree that config validation should not be optimizable away with python -O.

config.py (1 change, per @maobaolong's request): Changed is None to not self.lmcache_worker_ports so an empty list is also rejected. Updated the error message to: lmcache_worker_ports is required and cannot be empty when enable_controller=True.

Tests: Added test_controller_rejects_empty_worker_ports to cover the new empty-list validation path. All 7 controller validation tests pass.

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>
Copy link
Copy Markdown
Contributor

@sammshen sammshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ianliuy
Copy link
Copy Markdown
Contributor Author

ianliuy commented Apr 14, 2026

@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!

Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @ianliuy Thanks for this improvement.

@maobaolong maobaolong enabled auto-merge (squash) April 14, 2026 08:51
@github-actions github-actions Bot added the full Run comprehensive tests on this PR label Apr 14, 2026
@maobaolong maobaolong merged commit 1f1ab31 into LMCache:dev Apr 14, 2026
39 checks passed
ekaynar pushed a commit to ekaynar/LMCache that referenced this pull request Apr 15, 2026
…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>
ftian1 pushed a commit to ftian1/LMCache that referenced this pull request Apr 20, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LMCache emits empty error message when controller mode is misconfigured

3 participants