toStrictJsonSchema: RangeError: Maximum call stack size exceeded on cyclic $ref inside anyOf/allOf/oneOf
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- nodejs, typescript
- Domain
- backend-api-design
Research direction
Start in src/lib/transform.ts at isNullable and trace how seenRefs is handled when following $ref and recursing through allOf, anyOf, and oneOf. Check the existing tests for toStrictJsonSchema and add coverage for a cyclic reference inside each branch type. Done means these cases return a boolean without a stack overflow.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.6k
- Avg merge
- 19h 41m
- Merged PRs (30d)
- 110
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openai/openai-node
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-node#3195 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
openai/openai-node#2962 · 2 comments ·
Maintainers usually reply within 1 day
All issues in openai/openai-node
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
enhancement from-app needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
nightly-labs/openbot#23050 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OHDSI/Data2Evidence#3846 ·
Maintainers usually reply within 3 days
-
frontend: EditorDialog: Save & Apply on an empty or comment-only document reports success and applies nothingPossibly taken @shubhamrai9122-creator claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kubernetes-sigs/headlamp#9086 ·
Maintainers usually reply within 1 day
-
bug rust SDK & CLI & REST API
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
boxlite-ai/boxlite#3292 ·
Maintainers usually reply within 1 day