Skip to content

Skill‑sandbox: Zod claimName expected string, got undefined with AGENT_SANDBOX_ENABLE_VOLUME=false,no request sent to volume‑manager #7664

Description

@royanon

例行检查
[//]: # '方框内填 x 表示打钩'

  • 我已确认目前没有类似 issue
  • 我已完整查看过项目 README,以及项目文档
  • 我使用了自己的 key,并确认我的 key 是可正常使用的
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

你的版本

  • 公有云版本
  • 私有部署版本, 具体版本号: 4.15.7

问题描述, 日志截图,配置文件等
环境:Kubernetes 部署

  • Opensandbox‑server:官方 helm chart,tag sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/server:v0.2.2
  • Volume‑manager image:ghcr.io/labring/fastgpt-agent-volume-manager:v0.3.1

FastGPT Pod 内环境变量(exec 进 pod 执行 env 已确认变量真实存在):
AGENT_SANDBOX_PROVIDER=opensandbox
AGENT_SANDBOX_ENABLE_VOLUME=false
AGENT_SANDBOX_OPENSANDBOX_BASEURL=http://opensandbox-server.opensandbox-system.svc.cluster.local
AGENT_SANDBOX_OPENSANDBOX_VOLUME_MANAGER_URL=http://fastgpt-agent-volume-manager
AGENT_SANDBOX_OPENSANDBOX_VOLUME_MANAGER_TOKEN=xxxxxxxxxxxxxx
AGENT_SANDBOX_OPENSANDBOX_VOLUME_NAME_PREFIX=fastgpt-session

创建 skill‑sandbox 时,FastGPT 本地抛出 Zod 校验错误:claimName expected string, got undefined。日志可见 rawBody: undefined
完全没有向 volume‑manager 发出网络请求,失败发生在 FastGPT 后端进程内部。

实际报错堆栈:

2026-09-04 14:51:19   ERR ai:agent             [Sandbox] Failed to create sandbox: {
  error: Error: volume-manager error: 400 {"error":"Invalid request body","details":[{"expected":"string","code":"invalid_type","path":["claimName"],"message":"Invalid input: expected string, received undefined"}]}
 at o (.next/server/chunks/[root-of-the-server]__12009f0._.js:2:63565)
 at async d (.next/server/chunks/[root-of-the-server]__12009f0._.js:2:64143)
 at async b (.next/server/chunks/[root-of-the-server]__041p67q._.js:1:3192)
 at async F (.next/server/chunks/packages_service_core_ai_sandbox_0cv544u._.js:1:10003)
 at async h (.next/server/chunks/[root-of-the-server]__06xco2v._.js:1:17429)
 at async Module.m [as handler] (.next/server/chunks/[root-of-the-server]__06xco2v._.js:1:19836),
 rawBody: undefined
}

根因分析:

  1. packages/service/common/config/sandbox.ts 使用 IIFE,模块加载时一次性读取 process.env。K8s 存在启动时序问题:Node 模块初始化瞬间,环境变量还未就绪,agentSandboxConfig.openSandbox.volumeNamePrefix 被捕获为 undefined。后续容器 env 已经就绪,但模块缓存的 config 对象不会刷新,永久为 undefined。
  2. packages/service/core/ai/sandbox/skillSandbox.ts skill‑sandbox 创建逻辑缺失 enableVolume 判断守卫。即使关闭 volume,依然无条件调用 createVolume()。Agent‑sandbox 有该守卫,行为正常。
  3. createVolume() 将缓存 config 中原始 undefined 值直接传给 Zod schema 的 claimName 字段,Zod 本地校验失败,没有执行字符串模板拼接、uuid 生成,也无网络请求。

JS 模板字符串 ${undefined}-uuid 会生成字符串 "undefined‑uuid",可以通过 z.string()。报错说明传入 Zod 的是 JS 原生 undefined,没有做插值。

复现步骤

  1. K8s 部署 FastGPT v4.15.7,provider=opensandbox,设置 AGENT_SANDBOX_ENABLE_VOLUME=false,配置好 AGENT_SANDBOX_OPENSANDBOX_VOLUME_NAME_PREFIX
  2. 尝试创建 skill‑sandbox。
  3. 直接触发 Zod claimName expected string, got undefined 错误,无请求到 volume‑manager。

预期结果

  1. skill‑sandbox 应当和 agent‑sandbox 保持一致:当 enableVolume=false,直接跳过 volume‑manager 客户端全部逻辑,不执行 Zod 校验。
  2. 配置不应该只在模块加载瞬间读取 env,应运行时读取,规避 K8s 环境变量注入时序竞态。

相关截图

Image

请求:希望可以在 v4.15.x 分支做向后移植修复:

  1. skillSandbox.ts 添加 enableVolume 判断守卫,volume 关闭时跳过 volume‑manager 调用。
  2. 优化 sandbox config 读取逻辑,避免模块加载时一次性捕获 env,缓解 K8s 时序问题。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions