HKUDS/Vibe-Trading · error · ValueError
invalid local connection id: {connection_id or '?'}
Error message
invalid local connection id: {connection_id or '?'} What it means
Raised while parsing a persisted connection entry whose id fails the _ID_RE format check after trimming and lowercasing. Connection ids must be machine-friendly identifiers (the regex typically allows lowercase alphanumerics, digits, hyphens/underscores), so ids with spaces, symbols, or empty values are rejected.
Source
Thrown at agent/src/trading/connections.py:306
def _parse(raw: object) -> TradingConnection:
"""Validate one registry row.
Args:
raw: Decoded registry row.
Returns:
The validated connection.
Raises:
ValueError: If the row is not an object, carries an invalid id or
label, names an unknown or ineligible profile, or claims a
credential reference that does not match its transport.
"""
if not isinstance(raw, dict):
raise ValueError("each local connection must be an object")
connection_id = str(raw.get("id") or "").strip().lower()
if not _ID_RE.fullmatch(connection_id):
raise ValueError(f"invalid local connection id: {connection_id or '?'}")
profile_id = str(raw.get("profile_id") or "").strip().lower()
profile = profile_by_id(profile_id)
if not is_portfolio_connection_profile(profile):
raise ValueError(
f"connection profile is not eligible for read-only portfolios: {profile_id}"
)
label = str(raw.get("label") or profile.label).strip()
if (
not label
or len(label) > 80
or any(ord(character) < 32 for character in label)
):
raise ValueError(
"connection label must contain 1 to 80 printable characters"
)
expected_ref = _credential_reference(profile.id, connection_id)
credential_ref = str(raw.get("credential_ref") or expected_ref)
if (View on GitHub (pinned to 80ffdda44c)
Solutions
- Set the id to a lowercase slug: letters, digits, hyphen/underscore only (e.g. "alpaca-paper")
- Ensure id is non-empty after stripping whitespace
- If unsure of the exact regex, read _ID_RE in connections.py and match your id against it
- Regenerate the entry via store.create() which validates/normalizes ids for you
Example fix
// before
{"id": "Alpaca Main!", "profile_id": "paper"}
// after
{"id": "alpaca-main", "profile_id": "paper"} Defensive patterns
Strategy: validation
Validate before calling
import re
ID_RE = re.compile(r"[a-z0-9][a-z0-9_-]*") # mirror _ID_RE from connections.py
def valid_connection_id(value: str) -> bool:
return bool(ID_RE.fullmatch(value.strip().lower())) and bool(value.strip()) Type guard
def is_valid_connection_id(value: object) -> bool:
return (
isinstance(value, str)
and bool(value.strip())
and all(32 < ord(c) < 127 for c in value)
and value == value.strip().lower()
) Try / catch
try:
store.save(entries)
except ValueError as exc:
if str(exc).startswith("invalid local connection id"):
# re-generate ids as slugs and retry
... Prevention
- Generate ids programmatically as lowercase slugs
- Validate ids in UI forms before persisting
- Keep labels in the label field, never in id
When it happens
Trigger: A settings entry with "id": "", "id": null, or an id containing characters outside _ID_RE (e.g. "Alpaca Main!", "alpaca/props", trailing emoji) hits the fullmatch check in _parse during list() or save().
Common situations: Hand-editing the settings file with a human-readable label in the id field; upstream tools writing unslugified names; copy-pasting ids with invisible whitespace or unicode characters; an empty id after whitespace-only input.
Related errors
- connection label must contain 1 to 80 printable characters
- 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/7eb958c78c3f43ad.
Report an issue: GitHub.