{"record":{"id":"5039d1e8398355e3","repo":"PrefectHQ/fastmcp","slug":"the-horizon-host-changed-during-login","errorCode":null,"errorMessage":"The Horizon host changed during login","messagePattern":"The Horizon host changed during login","errorType":"exception","errorClass":"StateFileError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/cli/deploy/command.py","lineNumber":225,"sourceCode":"            try:\n                requested_configuration = configuration_store.set_api_origin(\n                    host,\n                    credentials=credentials,\n                )\n            except ValueError:\n                _fail(\n                    \"login\",\n                    \"invalid_host\",\n                    \"The Horizon host must be an HTTP origin.\",\n                    json_output=json_output,\n                )\n\n        configuration, credential = _load_session_snapshot(credentials)\n        if (\n            requested_configuration is not None\n            and configuration.api_origin != requested_configuration.api_origin\n        ):\n            raise StateFileError(\"The Horizon host changed during login\")\n\n        async def device_authorization():\n            approval_status: Status | None = None\n\n            def show_challenge(challenge: DeviceAuthorization) -> None:\n                nonlocal approval_status\n                emit_device_challenge(challenge, json_output=json_output)\n                approval_status = start_device_approval_status(json_output=json_output)\n\n            try:\n                async with HorizonClient(configuration.api_origin) as client:\n                    return await authorize_device(\n                        client,\n                        metadata=_device_metadata(),\n                        on_challenge=show_challenge,\n                        open_browser=not json_output and _can_open_browser(),\n                        browser_opener=webbrowser.open,\n                    )","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/cli/deploy/command.py#L207-L243","documentation":"During `fastmcp deploy` login, login() compares the api_origin of the configuration loaded from an existing session snapshot against the host the user requested. If they differ, StateFileError('The Horizon host changed during login') is raised to prevent overwriting credentials tied to a different host.","triggerScenarios":"Running login while the stored credentials file points at a different Horizon api_origin than the requested one (e.g. a --host flag or env var changed between sessions).","commonSituations":"Switching between staging and production Horizon instances; a teammate-shared credentials file; a proxy URL change; setting/unsetting a HORIZON_HOST-style environment variable.","solutions":["Point login back at the original host, or explicitly delete/move the existing credentials file first","Re-run login with the correct --host matching your stored session","Back up the credentials file, remove it, and log in fresh to the new host"],"exampleFix":"// before\nlogin(host=\"staging.horizon.example\")  # stored creds are for prod -> StateFileError\n// after\nrm ~/.fastmcp/horizon-credentials.json\nlogin(host=\"staging.horizon.example\")","handlingStrategy":"validation","validationCode":"from fastmcp.cli.deploy.command import _load_session_snapshot\nconfig, _ = _load_session_snapshot(credentials)\nif config is not None and config.api_origin != requested_host:\n    # delete or back up the old credentials before logging in to a new host\n    credentials.unlink()","typeGuard":null,"tryCatchPattern":"from fastmcp.cli.deploy.command import StateFileError\ntry:\n    await login(host=host)\nexcept StateFileError as e:\n    if \"host changed\" in str(e):\n        credentials.unlink(missing_ok=True)\n        await login(host=host)","preventionTips":["Keep one Horizon host per machine or per profile; don't mix envs","Set the host explicitly (flag/env) so it doesn't drift between runs","Back up and remove credentials when intentionally switching hosts"],"tags":["cli","state-file","host-mismatch"],"backgroundTag":"state-file-host-mismatch","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}