Persist strategy change to DB when restarting an existing run

When start_strategy is called with a new strategy on an active run,
update strategy_config in DB before building engine config so the
new strategy is used both now and on future resumes/restarts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thigazhezhilan J 2026-06-01 10:47:14 +05:30
parent dd2b9480d3
commit 5dce19c7d8

View File

@ -571,6 +571,12 @@ def start_strategy(req, user_id: str):
}
if engine_external:
return {"status": "already_running", "run_id": running_run_id}
# If caller explicitly passes a strategy, update the saved config so
# both the engine and future resumes use the new strategy.
req_strategy = getattr(req, "strategy_name", None) if req is not None else None
if req_strategy and req_strategy != running_cfg.get("strategy"):
running_cfg["strategy"] = req_strategy
save_strategy_config(running_cfg, user_id, running_run_id)
engine_config = _build_engine_config(user_id, running_run_id, req)
if engine_config:
try: