"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(scheduled-research): reject job ids the delete route cannot accept (#980)
Pham Van Ngoan15959c51e5f0
diff --git a/agent/src/api/scheduled_routes.py b/agent/src/api/scheduled_routes.pyindex 22169802a..18809f5e1 100644--- a/agent/src/api/scheduled_routes.py+++ b/agent/src/api/scheduled_routes.py@@ -6,6 +6,7 @@ Mounted by ``agent/api_server.py`` via ``register_scheduled_routes(app, ...)``.from __future__ import annotationsimport logging+import reimport sys as _sysimport timeimport uuid@@ -26,6 +27,11 @@ logger = logging.getLogger(__name__)_SCHEDULED_RESEARCH_SCHEDULER_ENV = "VIBE_TRADING_ENABLE_SCHEDULER"_SCHEDULED_RESEARCH_TRUE_VALUES = {"1", "true", "yes", "on"}+# Mirrors ``_SAFE_PATH_PARAM_RE`` in src/api/helpers.py, which the delete route+# enforces on the job id. Kept in sync so a job can never be created under an+# id the delete route refuses.+_SAFE_JOB_ID_RE = re.compile(r"^[A-Za-z0-9_-]{1,128}$")+# ---------------------------------------------------------------------------# Module-level state@@ -111,7 +117,12 @@ class CreateScheduledRunRequest(BaseModel):"""Request body for POST /scheduled-runs."""id: Optional[str] = Field(- None, description="Job id; auto-generated UUID when omitted"+ None,+ description=(+ "Job id; auto-generated UUID when omitted. Must match the id rule "+ "the delete route enforces: letters, digits, '_' and '-', 1-128 "+ "characters."+ ),)prompt: str = Field(..., min_length=1, description="Research prompt or backtest description"@@ -266,6 +277,18 @@ def register_scheduled_routes(from src.scheduled_research.executor import next_due+ # A job whose id the delete route rejects can never be cancelled+ # through the API, so the id is held to that same rule at creation+ # rather than at first attempted delete.+ if request.id is not None and not _SAFE_JOB_ID_RE.fullmatch(request.id):+ raise HTTPException(+ status_code=422,+ detail=(+ "job id must be 1-128 characters of letters, digits, "+ "'_' or '-'"+ ),+ )+try:validate_schedule(request.schedule)validate_timezone(request.timezone)diff --git a/agent/tests/test_scheduled_routes.py b/agent/tests/test_scheduled_routes.pyindex f73a0eec6..55b6c5656 100644--- a/agent/tests/test_scheduled_routes.py+++ b/agent/tests/test_scheduled_routes.py@@ -320,3 +320,42 @@ def test_create_interval_with_timezone_keeps_immediate_first_fire(assert response.status_code == 201assert before <= response.json()["next_run_at"] <= after+++def test_create_rejects_ids_the_delete_route_would_refuse(+ client: TestClient, store: ScheduledResearchJobStore+):+ for bad_id in ("my scan.v1", "a/b", "café", "x" * 129):+ response = client.post(+ "/scheduled-runs",+ json={"id": bad_id, "prompt": "scan", "schedule": "60000"},+ )+ assert response.status_code == 422, bad_id+ assert "job id" in response.json()["detail"]+ assert store.get(bad_id) is None+++def test_created_job_is_always_deletable(+ client: TestClient, store: ScheduledResearchJobStore+):+ created = client.post(+ "/scheduled-runs",+ json={"prompt": "scan", "schedule": "60000"},+ )+ assert created.status_code == 201+ job_id = created.json()["id"]++ assert client.delete(f"/scheduled-runs/{job_id}").status_code == 204+ assert store.get(job_id) is None+++def test_create_accepts_ids_within_the_id_rule(+ client: TestClient, store: ScheduledResearchJobStore+):+ for good_id in ("daily-scan", "scan_2026", "A" * 128):+ response = client.post(+ "/scheduled-runs",+ json={"id": good_id, "prompt": "scan", "schedule": "60000"},+ )+ assert response.status_code == 201, good_id+ assert client.delete(f"/scheduled-runs/{good_id}").status_code == 204