alibaba/spring-ai-alibaba · warning
无法获取 RequestContext 的 workspaceId,将不使用 workspace 过滤
Error message
无法获取 RequestContext 的 workspaceId,将不使用 workspace 过滤: {} What it means
ModelConfigParser.checkAndGetModelConfigInfo attempts to read the workspaceId from RequestContextHolder.getRequestContext() to scope the model lookup; if obtaining the context throws, it logs this warning and proceeds WITHOUT workspace filtering. Model resolution then searches across all workspaces, which can resolve an unintended model or leak cross-workspace configs.
Solutions
- Propagate the RequestContext to the worker thread (context-propagating executor or explicit pass-through)
- Pass workspaceId explicitly to the model lookup instead of relying on the request context holder
- In tests, set up a RequestContext in the holder before invoking the parser
- If cross-workspace resolution is unacceptable, treat the missing context as an error rather than a warning
Example fix
// before
RequestContext ctx = RequestContextHolder.getRequestContext(); // throws on async thread
// after
RequestContext ctx = contextSupplier.get();
if (ctx == null) { throw new IllegalStateException("workspaceId required for model lookup"); } Defensive patterns
Strategy: fallback
Validate before calling
RequestContext ctx = RequestContextHolder.getRequestContext(); if (ctx == null || ctx.getWorkspaceId() == null) { throw new IllegalStateException("workspaceId unavailable"); } Try / catch
try { parse(config); } catch (MissingWorkspaceException e) { resolveWithExplicitWorkspaceId(wsId, config); } Prevention
- Propagate RequestContext into async threads and pools
- Pass workspaceId explicitly where possible
- Set up request context in tests
- Fail fast when workspace scoping is mandatory
When it happens
Trigger: Calling checkAndGetModelConfigInfo outside a request-scoped context (async thread, scheduler, startup code, tests) where RequestContextHolder.getRequestContext() throws or is unavailable.
Common situations: Invoking model resolution from @Async methods or thread pools where the request context is not propagated; unit/integration tests without a mocked RequestContext; background jobs resolving model configs.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- DefaultWorkspaceNotFound
- Failed to initialize shell session
- INVALID_REQUEST
- MCP Server [ ] not found!
- MISSING_PARAMS
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/18c95ee946d5b5dd.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/utils/ModelConfigParser.java:69
try {
modelConfigInfo = parseModelConfig(modelConfig);
validateModelConfig(modelConfigInfo);
// 验证模型配置是否存在
// 首先尝试从 ModelConfigRepository (YAML 文件) 查找
boolean exists = modelConfigRepository.existsById(modelConfigInfo.getModelId());
if (!exists) {
// 如果 ModelConfigRepository 中不存在,尝试从 ModelManager (数据库) 查找
// 安全地获取 workspaceId
String workspaceId = null;
try {
RequestContext context = RequestContextHolder.getRequestContext();
if (context != null) {
workspaceId = context.getWorkspaceId();
}
} catch (Exception e) {
log.warn("无法获取 RequestContext 的 workspaceId,将不使用 workspace 过滤: {}", e.getMessage());
}
ModelEntity modelEntity = null;
// 1. 首先尝试通过 modelId (Long) 作为 ModelEntity 的 id 查找
if (modelConfigInfo.getModelId() != null) {
modelEntity = modelManager.findModelByIdOrName(modelConfigInfo.getModelId(), workspaceId);
}
// 2. 如果通过 modelId 找不到,尝试通过 modelName 查找
if (modelEntity == null) {
String modelName = (String) modelConfigInfo.getParameter("modelName");
if (StringUtils.hasText(modelName)) {
modelEntity = modelManager.findModelByIdOrName(modelName, workspaceId);
}
}
// 3. 如果还是找不到,抛出异常View on GitHub (pinned to f82da0b50f)