From fd2a2c5a7c0f7137ea848bf14a3627a8a1d6c317 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 10 Jan 2026 21:21:32 +0000 Subject: [PATCH] Delete run_state.py and update documentation after migration Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- DATA_TO_WORKFLOW_MIGRATION.md | 48 ++++++++++++++++- backend/autometabuilder/data/run_state.py | 64 ----------------------- 2 files changed, 46 insertions(+), 66 deletions(-) delete mode 100644 backend/autometabuilder/data/run_state.py diff --git a/DATA_TO_WORKFLOW_MIGRATION.md b/DATA_TO_WORKFLOW_MIGRATION.md index 077b1d3..6221f3f 100644 --- a/DATA_TO_WORKFLOW_MIGRATION.md +++ b/DATA_TO_WORKFLOW_MIGRATION.md @@ -102,12 +102,14 @@ Updated `packages/web_server_bootstrap/workflow.json` to orchestrate everything: **Total: 18 files, ~650 lines of imperative code deleted** +**Update (Jan 2026): 19 files, ~715 lines deleted** (including `run_state.py`) + ## Files Remaining in data/ Only essentials that don't affect the core architecture: - `__init__.py` - Thin wrapper for backward compatibility (delegates to plugins) -- `run_state.py` - Bot execution state (could be pluginized in future) +- ~~`run_state.py` - Bot execution state (could be pluginized in future)~~ **✅ MIGRATED** → `control.start_bot`, `control.get_bot_status`, `control.reset_bot_state` plugins - `workflow_graph.py` - Workflow visualization (could be pluginized in future) - `navigation_items.json` - Static navigation data - `ui_assets.json` - Static UI assets @@ -164,7 +166,14 @@ Only essentials that don't affect the core architecture: - `web.start_server` - Start HTTP server - `web.build_context` - Build API context object -**Total: 34 plugins** (24 data + 6 routes + 4 server) +### Control Plugins (4) + +- `control.switch` - Conditional branching +- `control.start_bot` - Start bot execution in background thread +- `control.get_bot_status` - Get current bot execution status +- `control.reset_bot_state` - Reset bot execution state + +**Total: 38 plugins** (24 data + 6 routes + 4 server + 4 control) ## Benefits Achieved @@ -223,3 +232,38 @@ All objectives from the problem statement have been achieved: - ✅ Deleted old cruft - ✅ Think declaratively - defined WHAT in workflow.json - ✅ Orchestrate, don't implement - let workflow assemble components + +## Additional Migration: Run State (Jan 2026) + +### Phase 4: Migrate Run State Management + +**Problem**: `data/run_state.py` contained bot execution state management that wasn't part of the workflow plugin system. + +**Solution**: Created 3 new control plugins: + +1. **`control.start_bot`** - Start bot execution in background thread + - Moved `start_bot()` and `_run_bot_task()` functions + - Maintains global state for bot process and config + - Handles mock mode and MVP stopping + +2. **`control.get_bot_status`** - Get current bot execution status + - Returns `is_running`, `config`, and `process` information + - Used by `web.route_context` for status API endpoint + +3. **`control.reset_bot_state`** - Reset bot execution state + - Cleans up bot process and configuration + - Available for manual state management + +**Updated Plugins**: +- `web.route_run` - Now uses `control.start_bot` plugin instead of importing from `data.run_state` +- `web.route_context` - Now uses `control.get_bot_status` plugin to check bot status + +**Files Deleted**: +- ✅ `data/run_state.py` - All functionality migrated to control plugins + +**Benefits**: +- Bot execution state management is now part of the workflow plugin system +- Can be composed with other workflow plugins +- Testable in isolation +- Follows the same declarative pattern as other plugins + diff --git a/backend/autometabuilder/data/run_state.py b/backend/autometabuilder/data/run_state.py deleted file mode 100644 index dc4e0ae..0000000 --- a/backend/autometabuilder/data/run_state.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Run state helpers for long-lived bot executions.""" -from __future__ import annotations - -import os -import subprocess -import sys -import threading -import time -from typing import Dict - -from ..roadmap_utils import is_mvp_reached - -bot_process = None -mock_running = False -current_run_config: Dict[str, object] = {} - - -def _reset_run_state() -> None: - global bot_process, current_run_config - bot_process = None - current_run_config = {} - - -def run_bot_task(mode: str, iterations: int, yolo: bool, stop_at_mvp: bool) -> None: - global bot_process, mock_running, current_run_config - current_run_config = { - "mode": mode, - "iterations": iterations, - "yolo": yolo, - "stop_at_mvp": stop_at_mvp, - } - - if os.environ.get("MOCK_WEB_UI") == "true": - mock_running = True - time.sleep(5) - mock_running = False - _reset_run_state() - return - - try: - cmd = [sys.executable, "-m", "autometabuilder.main"] - if yolo: - cmd.append("--yolo") - if mode == "once": - cmd.append("--once") - if mode == "iterations" and iterations > 1: - for _ in range(iterations): - if stop_at_mvp and is_mvp_reached(): - break - bot_process = subprocess.Popen(cmd + ["--once"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - bot_process.wait() - else: - bot_process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - bot_process.wait() - finally: - _reset_run_state() - - -def start_bot(mode: str = "once", iterations: int = 1, yolo: bool = True, stop_at_mvp: bool = False) -> bool: - if bot_process is not None or mock_running: - return False - thread = threading.Thread(target=run_bot_task, args=(mode, iterations, yolo, stop_at_mvp), daemon=True) - thread.start() - return True