Skip to content

[WRONG BRANCH] fix(openai-chat): bound Moonshot schema inlining bytes - #355

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-moonshot-request-amplification
Draft

[WRONG BRANCH] fix(openai-chat): bound Moonshot schema inlining bytes#355
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-moonshot-request-amplification

Conversation

@luvs01

@luvs01 luvs01 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a request-amplification DoS where inlining a large $defs properties map into many sibling-bearing $ref nodes could multiply serialized output and exhaust process memory.
  • Preserve the chosen Moonshot $ref-with-siblings semantics (conjunction for required/properties, node-narrowing otherwise) while making inlining resource-bounded and safe.

Description

  • Add a serialized-byte budget MOONSHOT_MAX_INLINED_SCHEMA_BYTES (1 MiB) and an iterative estimator serializedJsonBytesUpTo to bound how many bytes of a referenced schema may be inlined. (src/adapters/openai-chat.ts)
  • Track per-normalization state with remainingInlineBytes and inlineSizeCache so large referenced targets are measured once and charged before being copied, and reuse cached sizes for repeated references. (src/adapters/openai-chat.ts)
  • When the inlining budget would be exceeded, preserve a Moonshot-compatible bare $ref instead of duplicating the large map, and keep the existing depth/node/expansion guards. (src/adapters/openai-chat.ts)
  • Add a focused regression test that constructs a 10k-entry boolean properties definition referenced many times and asserts that emitted output stays bounded and that some references remain as bare $ref. (tests/moonshot-tool-schema.test.ts)
  • Update the adapter registry decision note to document the new serialized-byte budget and its rationale. (structure/10_adapter-registry.md)

Testing

  • Ran the focused Moonshot suite with bun test tests/moonshot-tool-schema.test.ts, which passed (17 tests, 0 failures).
  • Ran typecheck with bun run typecheck, which completed without type errors.
  • Ran the privacy check with bun run privacy:scan, which passed.
  • Attempting the full repository bun run test was 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

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(openai-chat): bound Moonshot schema inlining bytes [WRONG BRANCH] fix(openai-chat): bound Moonshot schema inlining bytes Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3f6a8b4d-611c-4d18-86cf-a8d9eea9f795


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions
github-actions Bot marked this pull request as draft August 28, 2026 04:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 1276 to +1280
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant