{"record":{"id":"cc3655b155c60e32","repo":"HKUDS/Vibe-Trading","slug":"invalid-kind-token-r-must-match-id-re-patte","errorCode":null,"errorMessage":"invalid {kind} {token!r}: must match {_ID_RE.pattern}","messagePattern":"invalid (.+?) (.+?): must match (.+?)","errorType":"validation","errorClass":"RegistryError","httpStatus":null,"severity":"error","filePath":"agent/src/factors/registry.py","lineNumber":144,"sourceCode":"\n\nclass SkipAlpha(Exception):\n    \"\"\"Raised when an alpha's preconditions (sector, columns) are not met.\"\"\"\n\n\nclass RegistryError(Exception):\n    \"\"\"Raised on registry-level configuration errors.\"\"\"\n\n\n@dataclass(frozen=True, slots=True)\nclass _LoadError:\n    alpha_id: str\n    reason: str\n\n\ndef _validate_id_token(token: str, kind: str) -> None:\n    if not _ID_RE.fullmatch(token):\n        raise RegistryError(f\"invalid {kind} {token!r}: must match {_ID_RE.pattern}\")\n\n\ndef load_alpha_meta_from_py(path: Path) -> AlphaMeta:\n    \"\"\"AST-extract the ``__alpha_meta__`` dict literal from a zoo module.\n\n    No import is performed — purely static parsing. Raises ``RegistryError`` on\n    malformed metadata.\n    \"\"\"\n    size = path.stat().st_size\n    if size > _MAX_PY_BYTES:\n        raise RegistryError(f\"{path.name}: {size}B exceeds {_MAX_PY_BYTES}B cap\")\n\n    source = path.read_text(encoding=\"utf-8\")\n    tree = ast.parse(source, filename=str(path))\n\n    meta_node: ast.expr | None = None\n    for stmt in tree.body:\n        if not isinstance(stmt, ast.Assign):","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/registry.py#L126-L162","documentation":"_validate_id_token enforces that alpha/theme identifiers match _ID_RE (a restricted identifier pattern). Tokens with spaces, uppercase, special characters, or empty strings raise RegistryError.","triggerScenarios":"Registering an alpha with id like 'My Alpha!', 'alpha#1', or '' in __alpha_meta__, or a theme token failing the same regex during scan/register.","commonSituations":"Auto-generating ids from filenames or display names with spaces/uppercase, hand-written metadata with friendly-looking names, or copy-pasted ids from another system with different id rules.","solutions":["Rename the id to match _ID_RE (typically lowercase snake_case/kebab-case alphanumerics)","Generate ids programmatically: re.sub(r'[^a-z0-9_-]', '', name.lower())","Check the pattern printed in the error message and conform to it"],"exampleFix":"# before\n__alpha_meta__ = {'alpha_id': 'Momentum Fast!', ...}\n# after\n__alpha_meta__ = {'alpha_id': 'momentum_fast', ...}","handlingStrategy":"validation","validationCode":"import re\n_ID_RE = re.compile(r'[a-z0-9][a-z0-9_-]*')  # mirror library pattern\nassert _ID_RE.fullmatch(alpha_id), f'bad id: {alpha_id!r}'","typeGuard":"def is_valid_id(token: str) -> bool:\n    return bool(_ID_RE.fullmatch(token))","tryCatchPattern":"try:\n    registry.register(path)\nexcept RegistryError as e:\n    if 'must match' in str(e): fix_id_and_retry(path)","preventionTips":["Generate ids: re.sub(r'[^a-z0-9_-]+', '_', name.lower()).strip('_')","Never hand-type display names as ids"],"tags":["registry","identifier-validation","factor-spec"],"backgroundTag":"invalid-identifier-format","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}