Skip to content

Preserve keyword-named tool properties during schema inlining - #1783

Open
VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/tool-schema-property-names
Open

VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/tool-schema-property-names

Conversation

@VIOLETee0

Copy link
Copy Markdown

Problem / Why

The local-reference inliner treats every object as a schema. Inside a properties map, it therefore removes ordinary tool argument names definitions and $defs. A tool with those required fields and additionalProperties: false reaches the model with a schema that rejects its valid arguments. These keys are instance property names at that position, per the JSON Schema properties contract.

Changes

Walk properties as a name-to-schema map: preserve each name and apply the existing reference resolution to its value. Add one direct regression covering the affected fields and an ordinary referenced-field control.

Verification

  • Regression: 0 pass / 1 fail on unmodified main, then 1 pass / 0 fail.
  • Entire provider suite: 42 pass / 0 fail.
  • An injected-fetch probe captures the real provider request; Ajv 8.17.1 rejects valid arguments against the original captured schema and accepts them against the patched one. No external model request is made.
  • Provider and SDK typechecks pass with installed native TypeScript 7.0.2. Frozen-lockfile install reports no changes; ESLint reports 0 errors / 4 resolver warnings.
  • Whole-file Prettier still reports pre-existing source differences; no new formatting differences were introduced. SDK/binary builds remain blocked by the existing declaration-generator ts.sys error, so binary smoke was not run.

Scope / Tradeoffs

Source-audit fix, with no existing issue claimed. Changes are limited to the properties map boundary. Existing reference lookup, cycle handling and removal of definition containers at schema positions are retained. This is not a general JSON Schema traversal rewrite.

@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch and a clean, minimal fix. The bug is real: the visit function's blanket if (key === '$defs' || key === 'definitions') continue at the bottom of the loop strips these keys regardless of whether they're schema-level containers or legitimate property names inside a properties map. Your fix correctly special-cases the properties map so its children are treated as name→schema pairs rather than being subject to the same keyword-stripping logic, which matches the JSON Schema spec you cite.

The diff is small, isolated to inlineLocalSchemaRefs, and includes a regression test that fails on main and passes with the patch — exactly what's wanted here. The test also includes a reasonable control case (name resolved via $ref) to confirm normal ref resolution still works alongside the fix.

One thing worth double-checking before this lands: nested properties maps (e.g. a property whose schema itself has a properties object one level down) — your visit(child, refStack) call without isPropertyMap for non-properties keys should naturally reset to schema-mode, but it would strengthen the PR to add a test with a nested object property to confirm recursion depth is handled correctly, since that's exactly the kind of case that silently breaks with this sort of fix.

Overall this is a correct, narrowly scoped bug fix with a regression test, which is exactly what this repo should want to port by hand.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Dec 2, 2026

This branch has not been deployed

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

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants