[WRONG BRANCH] fix(openai-chat): bound Moonshot schema inlining bytes - #355
[WRONG BRANCH] fix(openai-chat): bound Moonshot schema inlining bytes#355luvs01 wants to merge 1 commit into
Conversation
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab7f684bfc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const normalized = normalizeMoonshotSchemaNode(rooted, rooted, { | ||
| activeRefs: new Set<string>(), | ||
| inlineSizeCache: new WeakMap<Record<string, unknown>, number>(), | ||
| remainingExpansions: MOONSHOT_MAX_REF_EXPANSIONS, | ||
| remainingInlineBytes: MOONSHOT_MAX_INLINED_SCHEMA_BYTES, |
There was a problem hiding this comment.
Share the byte allowance across the whole tool catalog
The allowance is initialized inside normalizeMoonshotToolParameters, so toolsToChatFormat grants a fresh 1 MiB amplification budget to every tool. Because the inbound tool arrays have no aggregate count or output-size limit, a catalog containing many individually small schemas can still exhaust memory while constructing and serializing the final request; for example, I reproduced a 128-tool, 3.36 MB catalog expanding to about 82 MB. Allocate the budget once per request/catalog and pass it through each normalization, or enforce an aggregate serialized-output cap.
Useful? React with 👍 / 👎.
Motivation
$defspropertiesmap into many sibling-bearing$refnodes could multiply serialized output and exhaust process memory.$ref-with-siblings semantics (conjunction forrequired/properties, node-narrowing otherwise) while making inlining resource-bounded and safe.Description
MOONSHOT_MAX_INLINED_SCHEMA_BYTES(1 MiB) and an iterative estimatorserializedJsonBytesUpToto bound how many bytes of a referenced schema may be inlined. (src/adapters/openai-chat.ts)remainingInlineBytesandinlineSizeCacheso large referenced targets are measured once and charged before being copied, and reuse cached sizes for repeated references. (src/adapters/openai-chat.ts)$refinstead of duplicating the large map, and keep the existing depth/node/expansion guards. (src/adapters/openai-chat.ts)propertiesdefinition referenced many times and asserts that emitted output stays bounded and that some references remain as bare$ref. (tests/moonshot-tool-schema.test.ts)structure/10_adapter-registry.md)Testing
bun test tests/moonshot-tool-schema.test.ts, which passed (17 tests, 0 failures).bun run typecheck, which completed without type errors.bun run privacy:scan, which passed.bun run testwas not used for acceptance here because unrelated, pre-existing management/auth tests timed out/failed in this environment; the change was validated by the focused tests above.Codex Task