HKUDS/Vibe-Trading · error · ValueError

local connection {existing.id} already uses profile {existin

Error message

local connection {existing.id} already uses profile {existing.profile_id}

What it means

Raised by ConnectionStore.ensure when you try to ensure a local trading connection exists but a connection with the same id is already stored under a different profile. The store is immutable per id: once a connection is bound to a profile (paper, live-readonly, live), re-ensuring it with a different profile_id is rejected rather than silently rebinding it.

Source

Thrown at agent/src/trading/connections.py:233

        Args:
            connection_id: Identifier to resolve or create.
            profile_id: Read-only profile the connection must use.
            label: Human-readable name used only when creating.

        Returns:
            The existing or newly created connection.

        Raises:
            ValueError: If an existing connection with that id uses a
                different profile, or creation fails validation.
        """
        try:
            existing = self.get(connection_id)
        except ValueError:
            return self.create(connection_id, profile_id, label)
        if existing.profile_id != str(profile_id or "").strip().lower():
            raise ValueError(
                f"local connection {existing.id} already uses profile {existing.profile_id}"
            )
        return existing

    def delete(self, connection_id: str) -> None:
        """Delete a connection and any secrets stored for it.

        Args:
            connection_id: Identifier of the connection to remove.

        Raises:
            ValueError: If no stored connection has that id.
        """
        connection = self.get(connection_id)
        fields = credential_fields(connection.profile_id)
        self.credentials.delete(connection.id, fields)
        self._write([row for row in self.list() if row.id != connection.id])

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Delete or rename the existing connection first (store.delete(connection_id)) then ensure again with the new profile
  2. Update the stored connection entry in the connections settings file so its profile_id matches the one you are ensuring
  3. If the existing profile is actually correct, pass that same profile_id to ensure instead of a new one
  4. Add a pre-check: read the existing connection and surface a confirmation prompt to the user before rebinding

Example fix

// before
store.ensure("alpaca", "live-readonly")  # was created as "paper" -> ValueError

// after
try:
    store.ensure("alpaca", "live-readonly")
except ValueError:
    store.delete("alpaca")
    store.ensure("alpaca", "live-readonly")
Defensive patterns

Strategy: validation

Validate before calling

existing = None
try:
    existing = store.get(connection_id)
except ValueError:
    pass
if existing is not None and existing.profile_id != str(profile_id or "").strip().lower():
    # decide: delete-and-recreate, or keep existing
    ...

Try / catch

try:
    conn = store.ensure(connection_id, profile_id)
except ValueError as exc:
    if "already uses profile" in str(exc):
        store.delete(connection_id)
        conn = store.ensure(connection_id, profile_id)
    else:
        raise

Prevention

When it happens

Trigger: Calling ensure(connection_id, profile_id, ...) where get(connection_id) succeeds and existing.profile_id != the normalized new profile_id (whitespace-trimmed, lowercased). Typically happens when the user switches a settings profile and the app re-runs parse_settings/_settings_store which call ensure for the same connection id.

Common situations: Switching an agent from paper to live (or to live-readonly) without deleting or renaming the prior local connection; stale connections.json entries from an earlier setup; concurrent setup flows registering the same id with different defaults.

Related errors


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