{"record":{"id":"8242e23489c61845","repo":"alibaba/spring-ai-alibaba","slug":"error-8242e2","errorCode":null,"errorMessage":"模型配置不存在: ","messagePattern":"模型配置不存在: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/client/ChatClientFactoryDelegate.java","lineNumber":85,"sourceCode":"        return createChatClient(modelConfigId, userParameters, null,null);\n    }\n    \n    public ChatClient createChatClient(Long modelConfigId, Map<String, Object> userParameters, Map<String, String> observationMetadata){\n        return createChatClient(modelConfigId, userParameters, null, observationMetadata);\n    }\n    \n    public ChatClient createChatClient(Long modelConfigId, Map<String, Object> userParameters, List<Advisor> advisors, Map<String, String> observationMetadata) {\n        // 优先从桥接服务查找（从Manager层查询）\n        ModelConfigDO config = modelConfigBridgeService.findById(modelConfigId);\n        \n        // 如果桥接服务中找不到，尝试从ModelConfigRepository查找（保持向后兼容）\n        if (config == null) {\n            log.debug(\"桥接服务中未找到模型配置 id={}，尝试从 ModelConfigRepository 查找\", modelConfigId);\n            config = modelConfigRepository.findById(modelConfigId);\n        }\n        \n        if (config == null) {\n            throw new RuntimeException(\"模型配置不存在: \" + modelConfigId);\n        }\n        \n        if (config.getStatus() != 1) {\n            throw new RuntimeException(\"模型配置已禁用: \" + modelConfigId);\n        }\n\n        String provider = config.getProvider().toLowerCase();\n        log.info(\"创建模型客户端，提供商: {}, 模型: {}\", provider, config.getModelName());\n        \n        ChatClientFactory factory = chatClientFactories.get(provider);\n        if (factory == null) {\n            // 如果找不到对应的 provider factory，默认使用 OpenAI\n            log.warn(\"未找到提供商 {} 对应的工厂，使用默认的 OpenAI 工厂\", provider);\n            factory = chatClientFactories.get(OpenAiChatClientFactory.OPEN_AI_PROVIDER);\n            if (factory == null) {\n                throw new UnsupportedOperationException(\"不支持的模型提供商: \" + config.getProvider() + \"，且默认的 OpenAI 工厂也不可用\");\n            }\n        }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/client/ChatClientFactoryDelegate.java#L67-L103","documentation":"ChatClientFactoryDelegate.createChatClient first looks up the model config in a bridging service, then falls back to modelConfigRepository.findById. If both return null, it throws this RuntimeException because a ChatClient cannot be built without a model configuration record for the given id.","triggerScenarios":"Calling createChatClient(modelConfigId, ...) with an id that exists neither in the bridge service nor the repository — e.g., a stale modelConfigId from a deleted session, or a config file that failed to load/validate (see errors 440-442).","commonSituations":"Sessions persisted before the model config was removed; YAML model file edited/renumbered so old ids no longer exist; repository failed to load due to a validation error earlier; case/format mismatch in the id passed by the caller.","solutions":["Verify the modelConfigId exists: check the models YAML file or the model config store for an entry with that id","Re-create or re-point the session/request to a valid existing model config id","Check startup logs for FileModelConfigRepository load failures (apiKey/duplicate id/name validation) that would leave the repository empty","If configs are managed in the admin UI, confirm the model config was not deleted or disabled by another user"],"exampleFix":"// before\nchatClientFactoryDelegate.createChatClient(999L, params, metadata); // id never existed\n// after\nLong id = modelConfigRepository.findByName(\"qwen-max\").getId();\nchatClientFactoryDelegate.createChatClient(id, params, metadata);","handlingStrategy":"try-catch","validationCode":"// Java: check existence before creating the client\nif (modelConfigRepository.findById(modelConfigId) == null) {\n    throw new IllegalStateException(\"Resolve a valid modelConfigId first: \" + modelConfigId);\n}","typeGuard":"boolean configExists(ModelConfigDO c) { return c != null; }","tryCatchPattern":"try {\n    client = delegate.createChatClient(modelConfigId, params, metadata);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"模型配置不存在\")) {\n        // re-resolve or recreate the model config before retrying\n    }\n}","preventionTips":["Resolve model ids by name at call time instead of caching raw ids across restarts","Confirm model config file loaded successfully at startup (watch for validation errors 440-442)","Log the modelConfigId in requests to speed up stale-id diagnosis"],"tags":["not-found","model-config","lookup"],"backgroundTag":"entity-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}