diff --git a/backend/autometabuilder/workflow/plugins/control/control_get_bot_status/control_get_bot_status.py b/backend/autometabuilder/workflow/plugins/control/control_get_bot_status/control_get_bot_status.py index 5620fc2..4884a90 100644 --- a/backend/autometabuilder/workflow/plugins/control/control_get_bot_status/control_get_bot_status.py +++ b/backend/autometabuilder/workflow/plugins/control/control_get_bot_status/control_get_bot_status.py @@ -1,9 +1,5 @@ """Workflow plugin: get current bot execution status.""" -from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import ( - _bot_process, - _mock_running, - _current_run_config, -) +from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import get_bot_state def run(_runtime, _inputs): @@ -15,8 +11,4 @@ def run(_runtime, _inputs): - config: dict - Current run configuration (empty if not running) - process: object - Bot process object (or None if not running) """ - return { - "is_running": _bot_process is not None or _mock_running, - "config": _current_run_config, - "process": _bot_process, - } + return get_bot_state() diff --git a/backend/autometabuilder/workflow/plugins/control/control_reset_bot_state/control_reset_bot_state.py b/backend/autometabuilder/workflow/plugins/control/control_reset_bot_state/control_reset_bot_state.py index 46c1551..17e7e71 100644 --- a/backend/autometabuilder/workflow/plugins/control/control_reset_bot_state/control_reset_bot_state.py +++ b/backend/autometabuilder/workflow/plugins/control/control_reset_bot_state/control_reset_bot_state.py @@ -1,5 +1,5 @@ """Workflow plugin: reset bot execution state.""" -from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import _reset_run_state +from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import reset_bot_state def run(_runtime, _inputs): @@ -9,5 +9,5 @@ def run(_runtime, _inputs): Dictionary with: - reset: bool - Always True to indicate state was reset """ - _reset_run_state() + reset_bot_state() return {"reset": True} diff --git a/backend/autometabuilder/workflow/plugins/control/control_start_bot/control_start_bot.py b/backend/autometabuilder/workflow/plugins/control/control_start_bot/control_start_bot.py index 2c0f413..2fd720d 100644 --- a/backend/autometabuilder/workflow/plugins/control/control_start_bot/control_start_bot.py +++ b/backend/autometabuilder/workflow/plugins/control/control_start_bot/control_start_bot.py @@ -15,9 +15,29 @@ _current_run_config = {} def _reset_run_state() -> None: """Reset the bot run state.""" - global _bot_process, _current_run_config + global _bot_process, _current_run_config, _mock_running _bot_process = None _current_run_config = {} + _mock_running = False + + +def get_bot_state(): + """Get the current bot state (public interface). + + Returns: + dict: Bot state with keys: is_running, config, process + """ + return { + "is_running": _bot_process is not None or _mock_running, + "config": _current_run_config, + "process": _bot_process, + } + + +def reset_bot_state(): + """Reset the bot state (public interface).""" + _reset_run_state() + def _run_bot_task(mode: str, iterations: int, yolo: bool, stop_at_mvp: bool) -> None: diff --git a/backend/autometabuilder/workflow/plugins/web/web_route_context/web_route_context.py b/backend/autometabuilder/workflow/plugins/web/web_route_context/web_route_context.py index 448344a..920a154 100644 --- a/backend/autometabuilder/workflow/plugins/web/web_route_context/web_route_context.py +++ b/backend/autometabuilder/workflow/plugins/web/web_route_context/web_route_context.py @@ -5,13 +5,19 @@ from autometabuilder.loaders.metadata_loader import load_metadata from autometabuilder.workflow.plugin_loader import load_plugin_callable from autometabuilder.roadmap_utils import is_mvp_reached +# Cache the get_bot_status plugin callable to avoid repeated loading +_get_bot_status_plugin = None + def run(runtime, _inputs): """Create and return the context routes blueprint.""" - # Load the control.get_bot_status plugin - get_bot_status_plugin = load_plugin_callable( - "autometabuilder.workflow.plugins.control.control_get_bot_status.control_get_bot_status.run" - ) + global _get_bot_status_plugin + + # Load the control.get_bot_status plugin once + if _get_bot_status_plugin is None: + _get_bot_status_plugin = load_plugin_callable( + "autometabuilder.workflow.plugins.control.control_get_bot_status.control_get_bot_status.run" + ) context_bp = Blueprint("context", __name__) @@ -34,7 +40,7 @@ def run(runtime, _inputs): packages = load_workflow_packages() # Get bot status from plugin - bot_status = get_bot_status_plugin(runtime, {}) + bot_status = _get_bot_status_plugin(runtime, {}) return { "logs": get_recent_logs(), diff --git a/backend/autometabuilder/workflow/plugins/web/web_route_run/web_route_run.py b/backend/autometabuilder/workflow/plugins/web/web_route_run/web_route_run.py index fc7c515..7ada523 100644 --- a/backend/autometabuilder/workflow/plugins/web/web_route_run/web_route_run.py +++ b/backend/autometabuilder/workflow/plugins/web/web_route_run/web_route_run.py @@ -2,13 +2,19 @@ from flask import Blueprint, jsonify, request from autometabuilder.workflow.plugin_loader import load_plugin_callable +# Cache the start_bot plugin callable to avoid repeated loading +_start_bot_plugin = None + def run(runtime, _inputs): """Create and return the run routes blueprint.""" - # Load the control.start_bot plugin - start_bot_plugin = load_plugin_callable( - "autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot.run" - ) + global _start_bot_plugin + + # Load the control.start_bot plugin once + if _start_bot_plugin is None: + _start_bot_plugin = load_plugin_callable( + "autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot.run" + ) run_bp = Blueprint("run", __name__) @@ -21,7 +27,7 @@ def run(runtime, _inputs): stop_at_mvp = payload.get("stop_at_mvp", False) # Call the control.start_bot plugin - result = start_bot_plugin(runtime, { + result = _start_bot_plugin(runtime, { "mode": mode, "iterations": iterations, "yolo": yolo,