{"record":{"id":"0cb8d8e785f9a3bc","repo":"HKUDS/Vibe-Trading","slug":"local-connection-profile-does-not-match-the-reques","errorCode":null,"errorMessage":"local connection profile does not match the requested plugin","messagePattern":"local connection profile does not match the requested plugin","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/service.py","lineNumber":59,"sourceCode":"\ndef _local_plugin_call(\n    profile: TradingProfile,\n    operation: str,\n    overrides: dict[str, Any],\n    *args: Any,\n    **kwargs: Any,\n) -> dict[str, Any]:\n    \"\"\"Call a read operation on a user-installed local connector adapter.\"\"\"\n    from src.trading.connections import ConnectionStore, credential_fields\n    from src.trading.local_plugins import load_adapter, plugin_by_profile_id\n\n    connection_id = str(overrides.get(\"connection_id\") or \"\").strip().lower()\n    if not connection_id:\n        raise ValueError(\"local connector plugins require a connection_id\")\n    store = ConnectionStore()\n    connection = store.get(connection_id)\n    if connection.profile_id != profile.id:\n        raise ValueError(\"local connection profile does not match the requested plugin\")\n    plugin = plugin_by_profile_id(profile.id)\n    adapter = load_adapter(plugin)\n    function = getattr(adapter, operation, None)\n    if not callable(function):\n        return _unsupported(profile, operation)\n    credentials = store.credentials.load(connection.id, credential_fields(profile.id))\n    return function(\n        *args,\n        credentials=credentials,\n        config=dict(profile.config),\n        **kwargs,\n    )\n\n\ndef check_connection(profile_id: str | None = None, **overrides: Any) -> dict[str, Any]:\n    \"\"\"Check a connector profile without mutating broker state.\"\"\"\n    profile = profile_by_id(profile_id)\n    if profile.transport == \"local_tws\":","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/service.py#L41-L77","documentation":"This error is thrown by _local_plugin_call when routing a trading operation to a local connector plugin. Before invoking the plugin adapter, the service verifies that the resolved connection (looked up via connection_id from the overrides) belongs to the same connector profile that the plugin was resolved from. If connection.profile_id differs from profile.id, the call is rejected because the plugin would operate with another profile's credentials/settings.","triggerScenarios":"Calling any of check_connection, get_account, get_positions, get_open_orders, get_quote, or get_history with overrides whose connection_id points to a ConnectionStore connection created under a different profile than the plugin being invoked (e.g. mixing a paper-connection id with a live profile, or a connection made for a different broker adapter).","commonSituations":"Stale connection ids persisted from a previous profile configuration, copying connection ids between environments (paper vs live), renaming/recreating connector profiles so old connections keep pointing at old profile ids, or passing the wrong connection_id in multi-broker setups.","solutions":["Verify the connection_id in overrides corresponds to a connection whose profile_id matches the plugin's profile (print store.get(connection_id).profile_id and compare to profile.id)","If the profile was recreated or renamed, create a new connection under the current profile and use its connection_id","Audit ConnectionStore contents and delete/prune connections that reference defunct profile ids","Ensure your broker/environment routing logic passes a connection_id from the same profile family as the requested plugin"],"exampleFix":"# before\nresult = service.get_account(profile, \"get_account\", {\"connection_id\": \"old-paper-conn\"})\n\n# after\nstore = ConnectionStore()\nconn = store.get(\"my-connection\")\nassert conn.profile_id == profile.id, f\"connection belongs to {conn.profile_id}, plugin is {profile.id}\"\nresult = service.get_account(profile, \"get_account\", {\"connection_id\": conn.id})","handlingStrategy":"validation","validationCode":"from agent.src.trading.service import plugin_by_profile_id\nfrom agent.src.trading.store import ConnectionStore\n\ndef assert_connection_matches(profile, overrides):\n    cid = str(overrides.get(\"connection_id\") or \"\").strip().lower()\n    if not cid:\n        raise ValueError(\"connection_id required for local plugins\")\n    conn = ConnectionStore().get(cid)\n    if conn.profile_id != profile.id:\n        raise ValueError(f\"connection {cid} belongs to profile {conn.profile_id}, expected {profile.id}\")\n    return conn","typeGuard":"def connection_matches_profile(store, connection_id: str, profile) -> bool:\n    try:\n        return store.get(connection_id).profile_id == profile.id\n    except KeyError:\n        return False","tryCatchPattern":null,"preventionTips":["Always source connection_id from the same profile object you pass to the trading call","Regenerate connections whenever a connector profile is recreated or its id changes","Periodically prune ConnectionStore entries whose profile_id no longer resolves"],"tags":["trading","connector","profile-mismatch","validation"],"backgroundTag":"configuration-mismatch","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}