HKUDS/Vibe-Trading · error · HTTPException
invalid job_id
Error message
invalid job_id
What it means
The optional market filter for the universe action is normalized (strip/lower) and must be exactly 'twse' or 'tpex'. Any other value raises this ValueError before the SQL conditions are built — there is no 'all markets' via a sentinel string; omit market entirely for unfiltered output.
Source
Thrown at agent/src/api/alpha_routes.py:575
job["_finished_at"] = time.time()
task = asyncio.create_task(_runner())
_RUNNING_TASKS.add(task)
task.add_done_callback(_RUNNING_TASKS.discard)
return {"status": "ok", "job_id": job_id}
# -----------------------------------------------------------------------
# GET /alpha/bench/{job_id}/stream
# -----------------------------------------------------------------------
@app.get(
"/alpha/bench/{job_id}/stream",
dependencies=[Depends(require_event_stream_auth)],
)
async def stream_bench(job_id: str, request: Request) -> StreamingResponse:
"""SSE: progress / result / done / error until the job terminates."""
if not _JOB_ID_RE.fullmatch(job_id or ""):
raise HTTPException(status_code=400, detail="invalid job_id")
with _JOBS_LOCK:
if job_id not in ALPHA_BENCH_JOBS:
raise HTTPException(status_code=404, detail=f"job {job_id} not found")
return _job_event_stream(ALPHA_BENCH_JOBS, job_id, request, _result_for_wire)
# -----------------------------------------------------------------------
# POST /alpha/compare
# -----------------------------------------------------------------------
@app.post(
"/alpha/compare",
status_code=202,
dependencies=[Depends(require_auth)],
)
async def kick_off_compare(payload: CompareRequest) -> dict[str, Any]:
"""Queue a background head-to-head comparison and return a job_id."""
from src.tools.alpha_bench_tool import _parse_period
View on GitHub (pinned to 80ffdda44c)
Solutions
- Use only 'twse' or 'tpex' (case-insensitive), or omit market to get both markets
- Map aliases before calling: market={'otc':'tpex','taiex':'twse'}.get(raw.lower(), raw.lower())
- Validate against the set at your API boundary: {'twse','tpex'}
Example fix
# before execute(action='universe', market='OTC') # after execute(action='universe', market='tpex')
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'twse', 'tpex'}
market = (raw or '').strip().lower() or None
if market is not None and market not in ALLOWED:
raise ValueError(f"market must be one of {sorted(ALLOWED)}, got {market!r}") Type guard
def is_valid_market(m) -> bool:
return m is None or str(m).strip().lower() in {'twse', 'tpex'} Try / catch
try:
tool.execute(action='universe', market=market)
except ValueError as e:
if 'market must be twse or tpex' in str(e):
result = tool.execute(action='universe') # unfiltered fallback
else:
raise Prevention
- Normalize case and validate against the enum at the boundary
- Omit market entirely when you want both exchanges
When it happens
Trigger: Calling execute(action='universe', market='TW') , 'taiex', 'otc', 'NYSE', or 'twse ' (handled by strip) — anything outside the two-element set fails. Mixed-case like 'TWSE' is fine due to .lower().
Common situations: Assuming OTC/over-the-counter aliases for TPEX; passing exchange codes from a US-market integration; LLM guessing 'taiwan' as the market name; upstream enum drifting from the tool's.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- job {job_id} not found
- invalid alpha_id
- alpha_id not found
- invalid period: {exc}
- too many running benches; wait for one to finish
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/cc5dc6efd6fb9bff.
Report an issue: GitHub.