toStrictJsonSchema: RangeError: Maximum call stack size exceeded on cyclic $ref inside anyOf/allOf/oneOf
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- nodejs, typescript
调研方向
从 src/lib/transform.ts 中的 isNullable 开始,追踪跟随 $ref 以及递归处理 allOf、anyOf 和 oneOf 时 seenRefs 的处理方式。检查 toStrictJsonSchema 的现有测试,并为每种分支类型中的循环引用添加测试覆盖。完成标准是这些情况都能返回布尔值,且不会导致栈溢出。
由索引模型根据 Issue 内容生成。
描述
Confirm this is a Node library issue and not an underlying OpenAI API issue
- This is an issue with the Node library
Describe the bug
When toStrictJsonSchema() checks whether an optional object property is nullable via isNullable(), a cyclic $ref nested inside anyOf, allOf, or oneOf causes RangeError: Maximum call stack size exceeded instead of returning true or false.
Root cause:
In src/lib/transform.ts (isNullable), seenRefs is tracked when following $ref, but seenRefs is omitted when recursing into allOf, anyOf, and oneOf branches (isNullable(variant, root)). Passing seenRefs to those recursive calls (isNullable(variant, root, seenRefs)) lets cyclic branches terminate conservatively (false) without overflowing the call stack.
To Reproduce
- Call
toStrictJsonSchema()(orzodResponseFormat()/standardSchemaResponseFormat()) with an optional property whose schema references a cyclic$refinsideanyOf,allOf, oroneOf. - Observe
RangeError: Maximum call stack size exceededatisNullableinsrc/lib/transform.ts.
Code snippets
import { toStrictJsonSchema } from "openai/lib/transform";
toStrictJsonSchema({
type: "object",
$defs: {
Node: {
anyOf: [{ $ref: "#/$defs/Node" }, { type: "null" }],
},
},
properties: {
next: { $ref: "#/$defs/Node" },
},
});
OS
macOS
Node version
v22.23.3
Library version
openai v7.69.0
- 主要语言
- TypeScript
- 星标
- 11.3k
- 派生
- 1.6k
- 平均合并
- 19 小时 41 分钟
- 30 天内合并 PR
- 110
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-node 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-node#3195 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 58/100
openai/openai-node#2962 · 2 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-node 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 92/100
Techiebutler/freeframe#687 ·
维护者通常 1 天内回复
-
enhancement from-app needs-triage
难度 2/5 1-3 小时 新手友好度 67/100
nightly-labs/openbot#23050 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
OHDSI/Data2Evidence#3846 ·
维护者通常 3 天内回复
-
frontend: EditorDialog: Save & Apply on an empty or comment-only document reports success and applies nothing可能已有人在做 @shubhamrai9122-creator 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
kubernetes-sigs/headlamp#9086 ·
维护者通常 1 天内回复
-
bug rust SDK & CLI & REST API
难度 2/5 1-3 小时 新手友好度 75/100
boxlite-ai/boxlite#3292 ·
维护者通常 1 天内回复