Repository navigation
Conversation
Automated review summaryTriage: bug | Recommendation: ready-for-maintainer Findings
Conventions
This PR adds a validate_search_space() check that rejects empty/malformed hyperparameter search spaces with a clear 400, plus a _fail_tuning_session() helper so a bad search space in the background tuning loop now marks the session FAILED instead of crashing the thread and leaving it stuck RUNNING forever — a real and well-tested fix for a genuine bug, with solid unit, HTTP, and regression test coverage. One ordering issue in the router: validate_search_space() is called after generate_grid_combinations() already ran for the GRID strategy, so the new clearer error can be preempted by the pre-existing grid-size check on invalid input — move the validation call before the n_trials/grid-combination computation. PR title, description, and single commit are all clean and Conventional-Commits compliant with no hygiene issues. Generated by |
Malformed or empty search spaces caused silent user-facing failures:
- Random search with a dict spec missing min/max, or with an empty list,
raised KeyError/ValueError inside the background tuning thread. The
exception propagated out of asyncio.to_thread with no handler, leaving
the session stuck in RUNNING with no completion event.
- Grid search with an empty list value produced a zero-trial session that
was immediately marked COMPLETED without doing any work.
- Grid search with only continuous (dict) params produced a single useless
{} trial.
Fix:
- Add TuningService.validate_search_space() and call it in start_tuning so
invalid search spaces return a clear 400 before a session is created.
- Validate defensively at the top of run_tuning_loop and mark the session
FAILED + emit a tuning_complete event if an invalid row is reached, so a
session can never be left stuck in RUNNING.
Add unit + HTTP regression tests covering validation and the FAILED path.
bd26f95 to
de04db3
Compare
Summary
Fixes #406. Malformed or empty
search_spacepayloads toPOST /api/v1/model/tuning/{model_name}caused silent failures: sessions either got stuck inRUNNINGforever (background thread crashed with no handler, no completion event) or completed a zero-trial session with no work done.Changes
app/services/tuning_service.pyTuningService.validate_search_space(search_space, strategy)which raisesAppException(400)for: empty search space, empty list values, malformed dict specs (missing/non-numericmin/max,min >= max,log_uniformwithmin <= 0), unsupported spec types, and grid search with no discrete (list) parameter._fail_tuning_session()helper that marks a sessionFAILED, setscompleted_at, and emits atuning_completeevent.run_tuning_loopnow validates the search space defensively at startup and marks the sessionFAILEDinstead of crashing the background thread and leaving it stuck inRUNNING.app/routers/tuning.pystart_tuningnow callsvalidate_search_spacebefore creating the session, returning a clear400for invalid payloads.tests/test_tuning.py400for empty search space, empty list value, malformed dict spec, and continuous-only grid.run_tuning_loopmarks a malformed sessionFAILED(not stuckRUNNING).Testing
uv run pytest tests/test_tuning.py— 39 passeduv run pytest tests/test_tuning_integration.py— 3 passeduv run ruff check .anduv run ruff format --check .clean