HKUDS/Vibe-Trading · error · HTTPException
invalid period: {exc}
Error message
invalid period: {exc} What it means
The limit parameter is coerced with int(value); if that raises TypeError (None) or ValueError ('abc', '1.5', ''), this ValueError is raised. String digits like '60' are accepted, as are floats that truncate cleanly, so the failure is specifically about non-numeric input.
Source
Thrown at agent/src/api/alpha_routes.py:507
# -----------------------------------------------------------------------
# POST /alpha/bench
# -----------------------------------------------------------------------
@app.post(
"/alpha/bench",
status_code=202,
dependencies=[Depends(require_auth)],
)
async def kick_off_bench(payload: BenchRequest) -> dict[str, Any]:
"""Queue a background bench job and return a job_id."""
# Cheap period parse pre-check so we 400 here instead of letting the
# worker fail asynchronously.
from src.tools.alpha_bench_tool import _parse_period
try:
_parse_period(payload.period)
except ValueError as exc:
raise HTTPException(status_code=400, detail=f"invalid period: {exc}")
# Concurrency cap. We peek at the semaphore counter rather than
# ``acquire(block=False)`` so the actual acquire happens inside the
# worker (after the 202 is returned). _value is a CPython
# implementation detail but it's been stable since 3.0 and asyncio's
# own ``locked()`` uses it.
sem = _get_bench_semaphore()
# ``locked()`` returns True iff the counter is 0; defensive check.
if sem.locked() or getattr(sem, "_value", MAX_CONCURRENT_BENCHES) <= 0:
raise HTTPException(
status_code=429,
detail="too many running benches; wait for one to finish",
)
_prune_old_jobs()
job_id = uuid.uuid4().hex
with _JOBS_LOCK:View on GitHub (pinned to 80ffdda44c)
Solutions
- Coerce before calling: limit=int(raw or 60)
- Whitelist the raw value: use a pydantic/marshmallow IntField or json-schema type integer at the tool boundary
- Default missing values explicitly rather than passing None: kwargs.get('limit', 60)
Example fix
# before
execute(action='universe', limit=request.args.get('limit')) # '' or 'fifty'
# after
try:
limit=int(request.args.get('limit', 60))
except (TypeError, ValueError):
limit=60
execute(action='universe', limit=limit) Defensive patterns
Strategy: validation
Validate before calling
try:
limit = int(value)
except (TypeError, ValueError):
limit = 60 # sensible default
else:
if not 1 <= limit <= MAX_RESULT_ROWS:
limit = min(max(limit, 1), MAX_RESULT_ROWS) Type guard
def is_int_like(v) -> bool:
try:
int(v); return True
except (TypeError, ValueError):
return False Try / catch
try:
tool.execute(action='universe', limit=raw)
except ValueError as e:
if 'limit must be an integer' in str(e):
result = tool.execute(action='universe', limit=60)
else:
raise Prevention
- Coerce limit to int at the boundary; never pass raw strings/None
- Declare limit as JSON schema type integer with default
When it happens
Trigger: Calling execute(..., limit='fifty'), limit=None, limit='', or limit=[50]. Numeric strings '50' and floats 50.0 succeed; '50.5' raises because int('50.5') fails.
Common situations: LLM tool call emitting the schema default as a string word; config/env vars delivering empty strings; passing a pandas/numpy scalar whose str() is not plain digits; upstream form field not coerced to int.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- invalid alpha_id
- alpha_id not found
- too many running benches; wait for one to finish
- invalid job_id
- job {job_id} not found
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/e175704c40815911.
Report an issue: GitHub.