mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-30 14:22:04 +00:00
Major refactoring of the parallel orchestrator to run regression testing agents independently from coding agents. This improves system reliability and provides better control over testing behavior. Key changes: Database & MCP Layer: - Add testing_in_progress and last_tested_at columns to Feature model - Add feature_claim_for_testing() for atomic test claim with retry - Add feature_release_testing() to release claims after testing - Refactor claim functions to iterative loops (no recursion) - Add OperationalError retry handling for transient DB errors - Reduce MAX_CLAIM_RETRIES from 10 to 5 Orchestrator: - Decouple testing agent lifecycle from coding agents - Add _maintain_testing_agents() for continuous testing maintenance - Fix TOCTOU race in _spawn_testing_agent() - hold lock during spawn - Add _cleanup_stale_testing_locks() with 30-min timeout - Fix log ordering - start_session() before stale flag cleanup - Add stale testing_in_progress cleanup on startup Dead Code Removal: - Remove count_testing_in_concurrency from entire stack (12+ files) - Remove ineffective with_for_update() from features router API & UI: - Pass testing_agent_ratio via CLI to orchestrator - Update testing prompt template to use new claim/release tools - Rename UI label to "Regression Agents" with clearer description - Add process_utils.py for cross-platform process tree management Testing agents now: - Run continuously as long as passing features exist - Can re-test features multiple times to catch regressions - Are controlled by fixed count (0-3) via testing_agent_ratio setting - Have atomic claiming to prevent concurrent testing of same feature Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
"""
|
|
Settings Router
|
|
===============
|
|
|
|
API endpoints for global settings management.
|
|
Settings are stored in the registry database and shared across all projects.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from ..schemas import ModelInfo, ModelsResponse, SettingsResponse, SettingsUpdate
|
|
|
|
# Add root to path for registry import
|
|
ROOT_DIR = Path(__file__).parent.parent.parent
|
|
if str(ROOT_DIR) not in sys.path:
|
|
sys.path.insert(0, str(ROOT_DIR))
|
|
|
|
from registry import (
|
|
AVAILABLE_MODELS,
|
|
DEFAULT_MODEL,
|
|
get_all_settings,
|
|
set_setting,
|
|
)
|
|
|
|
router = APIRouter(prefix="/api/settings", tags=["settings"])
|
|
|
|
|
|
def _parse_yolo_mode(value: str | None) -> bool:
|
|
"""Parse YOLO mode string to boolean."""
|
|
return (value or "false").lower() == "true"
|
|
|
|
|
|
def _is_glm_mode() -> bool:
|
|
"""Check if GLM API is configured via environment variables."""
|
|
return bool(os.getenv("ANTHROPIC_BASE_URL"))
|
|
|
|
|
|
@router.get("/models", response_model=ModelsResponse)
|
|
async def get_available_models():
|
|
"""Get list of available models.
|
|
|
|
Frontend should call this to get the current list of models
|
|
instead of hardcoding them.
|
|
"""
|
|
return ModelsResponse(
|
|
models=[ModelInfo(id=m["id"], name=m["name"]) for m in AVAILABLE_MODELS],
|
|
default=DEFAULT_MODEL,
|
|
)
|
|
|
|
|
|
def _parse_int(value: str | None, default: int) -> int:
|
|
"""Parse integer setting with default fallback."""
|
|
if value is None:
|
|
return default
|
|
try:
|
|
return int(value)
|
|
except (ValueError, TypeError):
|
|
return default
|
|
|
|
|
|
def _parse_bool(value: str | None, default: bool = False) -> bool:
|
|
"""Parse boolean setting with default fallback."""
|
|
if value is None:
|
|
return default
|
|
return value.lower() == "true"
|
|
|
|
|
|
@router.get("", response_model=SettingsResponse)
|
|
async def get_settings():
|
|
"""Get current global settings."""
|
|
all_settings = get_all_settings()
|
|
|
|
return SettingsResponse(
|
|
yolo_mode=_parse_yolo_mode(all_settings.get("yolo_mode")),
|
|
model=all_settings.get("model", DEFAULT_MODEL),
|
|
glm_mode=_is_glm_mode(),
|
|
testing_agent_ratio=_parse_int(all_settings.get("testing_agent_ratio"), 1),
|
|
)
|
|
|
|
|
|
@router.patch("", response_model=SettingsResponse)
|
|
async def update_settings(update: SettingsUpdate):
|
|
"""Update global settings."""
|
|
if update.yolo_mode is not None:
|
|
set_setting("yolo_mode", "true" if update.yolo_mode else "false")
|
|
|
|
if update.model is not None:
|
|
set_setting("model", update.model)
|
|
|
|
if update.testing_agent_ratio is not None:
|
|
set_setting("testing_agent_ratio", str(update.testing_agent_ratio))
|
|
|
|
# Return updated settings
|
|
all_settings = get_all_settings()
|
|
return SettingsResponse(
|
|
yolo_mode=_parse_yolo_mode(all_settings.get("yolo_mode")),
|
|
model=all_settings.get("model", DEFAULT_MODEL),
|
|
glm_mode=_is_glm_mode(),
|
|
testing_agent_ratio=_parse_int(all_settings.get("testing_agent_ratio"), 1),
|
|
)
|