HKUDS/Vibe-Trading · error · ValueError

unknown sort {v!r}; expected one of {sorted(_VALID_SORTS)}

Error message

unknown sort {v!r}; expected one of {sorted(_VALID_SORTS)}

What it means

scaffold_connector refuses to overwrite: it resolves destination/<connector-id> and raises ValueError if that directory already exists, before creating anything. This prevents clobbering an existing connector with a fresh scaffold.

Source

Thrown at agent/src/api/alpha_routes.py:216

                out.append(aid)
        if len(out) < 2:
            raise ValueError("need at least 2 distinct alpha_ids to compare")
        return out

    @field_validator("universe")
    @classmethod
    def _universe_known(cls, v: str) -> str:
        if v not in _BENCH_UNIVERSES:
            raise ValueError(
                f"unknown universe {v!r}; expected one of {sorted(_BENCH_UNIVERSES)}"
            )
        return v

    @field_validator("sort")
    @classmethod
    def _sort_known(cls, v: str) -> str:
        if v not in _VALID_SORTS:
            raise ValueError(f"unknown sort {v!r}; expected one of {sorted(_VALID_SORTS)}")
        return v


# ---------------------------------------------------------------------------
# Bench worker (runs in a thread; LLM-free, pandas-heavy)
# ---------------------------------------------------------------------------


def _make_progress_cb(
    job_id: str, jobs: dict[str, dict[str, Any]] = ALPHA_BENCH_JOBS
) -> Callable[[int, int, str], None]:
    """Return an on_progress closure that updates the job entry in-place."""

    def _cb(n_done: int, n_total: int, alpha_id: str) -> None:
        with _JOBS_LOCK:
            job = jobs.get(job_id)
            if job is None:
                return

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pick a different connector id or a different destination directory
  2. If the existing directory is disposable, delete or rename it first
  3. If it's an existing project, open it instead of re-scaffolding

Example fix

# before
scaffold_connector("acme-broker", Path("./connectors"))  # ValueError: exists

# after
from pathlib import Path
target = Path("./connectors/acme-broker")
if target.exists():
    shutil.rmtree(target)  # only if disposable
scaffold_connector("acme-broker", Path("./connectors"))
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def scaffold_target_free(destination: Path, connector_id: str) -> bool:
    return not (destination.expanduser().resolve() / connector_id.strip().lower()).exists()

Try / catch

try:
    scaffold_connector(cid, dest)
except ValueError as e:
    if "already exists" in str(e):
        print(f"skipping scaffold, exists: {e}")  # idempotent scripts
    else:
        raise

Prevention

When it happens

Trigger: Running connector init twice for the same id in the same destination; a previous scaffold (or manually created folder) with the same name exists.

Common situations: Re-running a setup script that scaffolds on every run; retrying after an interrupted init left the directory behind; forgetting a scaffold from an earlier session.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/ed87e59e59d92bd2. Report an issue: GitHub.