{"record":{"id":"4c4b0cb18a2f8b78","repo":"Hmbown/CodeWhale","slug":"model-uses-but-this-client-is-bound","errorCode":null,"errorMessage":"{} model {:?} uses {:?}, but this client is bound to {:?}; resolve a new model route before sending","messagePattern":"(.+?) model (.+?) uses (.+?), but this client is bound to (.+?); resolve a new model route before sending","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/client.rs","lineNumber":1860,"sourceCode":"        {\n            return Ok((request, self.route_limits));\n        }\n\n        let candidate = match self.resolve_model_route(&request.model) {\n            Ok(candidate) => candidate,\n            Err(error) if model_aware || self.api_provider == ApiProvider::OpencodeGo => {\n                return Err(error);\n            }\n            Err(_) => {\n                // A fixed-protocol gateway may legitimately accept an id that\n                // is newer than our offline catalog. Preserve the caller's\n                // model, but fail closed on limits instead of reusing the\n                // bound default model's envelope.\n                return Ok((request, None));\n            }\n        };\n        if candidate.protocol() != self.wire_format {\n            bail!(\n                \"{} model {:?} uses {:?}, but this client is bound to {:?}; resolve a new model route before sending\",\n                self.api_provider.display_name(),\n                request.model,\n                candidate.protocol(),\n                self.wire_format\n            );\n        }\n        request.model = candidate.wire_model_id().as_str().to_string();\n        let route_limits = crate::route_budget::known_route_limits(candidate.limits());\n        Ok((request, route_limits))\n    }\n\n    #[cfg(test)]\n    fn build_http_client(\n        api_key: &str,\n        extra_headers: &HashMap<String, String>,\n        api_provider: ApiProvider,\n        base_url: &str,","sourceCodeStart":1842,"sourceCodeEnd":1878,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client.rs#L1842-L1878","documentation":"Each running client instance is bound to one wire protocol format captured at construction. When a request names a model whose resolved protocol differs from the client's bound wire_format, the client refuses to send rather than silently serializing the request with the wrong envelope; the caller must re-resolve the model route (getting a new client) first.","triggerScenarios":"Sending a request whose `request.model` resolves to a model with a different protocol than the client was constructed with, e.g. switching a session from an Anthropic-protocol model to an OpenAI-protocol model without rebuilding the client.","commonSituations":"Changing models mid-session via a slash command or /model switch while the old client is still bound; a config route change repointing a model to a different provider protocol; session resume where the default model changed.","solutions":["Re-resolve the model route so a client bound to the new model's protocol is constructed, then retry the send.","Switch back to a model whose protocol matches the currently bound client.","If a route change happened mid-session, restart the session or reload config so the client rebuilds with the new wire format."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"fn model_matches_client(client: &Client, request_model: &str, registry: &ModelRegistry) -> bool {\n    registry.resolve(request_model).map(|m| m.protocol == client.wire_format).unwrap_or(false)\n}","typeGuard":"fn is_bound_to(client: &Client, wire: WireFormat) -> bool { client.wire_format == wire }","tryCatchPattern":"match send_result {\n    Err(e) if e.to_string().contains(\"resolve a new model route\") => {\n        let client = route_registry.client_for_model(request.model)?;\n        client.send(request).await?;\n    }\n    r => r?,\n}","preventionTips":["Rebuild/re-resolve the client whenever the active model changes mid-session.","Never cache a client across a model route change.","Add a session invariant test that client.wire_format matches the active model's protocol."],"tags":["protocol","model-routing","state"],"backgroundTag":"invalid-state-transition","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}