{"record":{"id":"b07fdcf92c7c3882","repo":"HKUDS/Vibe-Trading","slug":"too-many-running-benches-wait-for-one-to-finish","errorCode":null,"errorMessage":"too many running benches; wait for one to finish","messagePattern":"too many running benches; wait for one to finish","errorType":"http","errorClass":"HTTPException","httpStatus":429,"severity":"error","filePath":"agent/src/api/alpha_routes.py","lineNumber":517,"sourceCode":"        \"\"\"Queue a background bench job and return a job_id.\"\"\"\n        # Cheap period parse pre-check so we 400 here instead of letting the\n        # worker fail asynchronously.\n        from src.tools.alpha_bench_tool import _parse_period\n\n        try:\n            _parse_period(payload.period)\n        except ValueError as exc:\n            raise HTTPException(status_code=400, detail=f\"invalid period: {exc}\")\n\n        # Concurrency cap. We peek at the semaphore counter rather than\n        # ``acquire(block=False)`` so the actual acquire happens inside the\n        # worker (after the 202 is returned). _value is a CPython\n        # implementation detail but it's been stable since 3.0 and asyncio's\n        # own ``locked()`` uses it.\n        sem = _get_bench_semaphore()\n        # ``locked()`` returns True iff the counter is 0; defensive check.\n        if sem.locked() or getattr(sem, \"_value\", MAX_CONCURRENT_BENCHES) <= 0:\n            raise HTTPException(\n                status_code=429,\n                detail=\"too many running benches; wait for one to finish\",\n            )\n\n        _prune_old_jobs()\n\n        job_id = uuid.uuid4().hex\n        with _JOBS_LOCK:\n            ALPHA_BENCH_JOBS[job_id] = {\n                \"job_id\": job_id,\n                \"status\": \"queued\",\n                \"zoo\": payload.zoo,\n                \"universe\": payload.universe,\n                \"period\": payload.period,\n                \"top\": payload.top,\n                \"created_at\": _now_iso(),\n                \"progress\": {\"n_done\": 0, \"n_total\": 0, \"current_alpha_id\": None},\n                \"result\": None,","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/api/alpha_routes.py#L499-L535","documentation":"After int coercion, limit must lie in 1..MAX_RESULT_ROWS inclusive. Zero, negatives, and values above the cap raise this ValueError, bounding result-set size and page size against the read-only snapshot.","triggerScenarios":"Calling execute(..., limit=0), limit=-1, or limit=100000 exceeding MAX_RESULT_ROWS. Note limit=0 is a common 'no limit' convention elsewhere but is rejected here — the minimum is 1.","commonSituations":"API gateway defaulting limit=0 to mean unlimited; pagination math producing 0 on the last empty page; user-supplied page size of 9999 from a UI dropdown; copying limits tuned for another tool with a different cap.","solutions":["Clamp before calling: limit=max(1, min(int(raw), MAX_RESULT_ROWS))","Treat 0/unlimited as the cap: limit = MAX_RESULT_ROWS if raw in (0, None) else raw","Import MAX_RESULT_ROWS from the module instead of hardcoding the cap"],"exampleFix":"# before\nexecute(action='universe', limit=0)  # meant 'unlimited'\n# after\nfrom agent.src.tools.taiwan_stock_data_tool import MAX_RESULT_ROWS\nexecute(action='universe', limit=MAX_RESULT_ROWS)","handlingStrategy":"validation","validationCode":"from agent.src.tools.taiwan_stock_data_tool import MAX_RESULT_ROWS\nlimit = max(1, min(int(raw_limit), MAX_RESULT_ROWS)) if raw_limit else MAX_RESULT_ROWS","typeGuard":null,"tryCatchPattern":"try:\n    tool.execute(action='universe', limit=limit)\nexcept ValueError as e:\n    if 'between 1 and' in str(e):\n        result = tool.execute(action='universe', limit=MAX_RESULT_ROWS)\n    else:\n        raise","preventionTips":["Clamp user-supplied limits to 1..MAX_RESULT_ROWS before calling","Import the cap constant rather than hardcoding it so it tracks updates"],"tags":["python","validation","limit-out-of-range"],"backgroundTag":"input-limit-exceeded","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}