Skip to content

fix(antigravity): preserve local schema refs - #488

Open
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-465-ref-safety
Open

fix(antigravity): preserve local schema refs#488
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-465-ref-safety

Conversation

@testikun

@testikun testikun commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #465. Antigravity removed $defs during tool conversion and $ref during provider sanitization, leaving referenced result-contract properties as {} in the outbound schema.

Value

Direct Subagent and Workflow structured-output contracts remain visible to the model while unsupported Cloud Code Assist keywords are still removed.

Approach

  • Expand same-document JSON Pointer references before the existing CCA sanitizer.
  • Reject external, unresolved, recursive, too-deep, too-large, or over-node-limit references before sending a request.
  • Preserve sibling keywords and existing no-reference behavior.
  • Add provider-chain regression tests and a design/ablation record.

Validation

  • node --test --experimental-strip-types tests/extensions/ai-providers/antigravity.test.ts passed: 39/39.
  • bun run check passed: config contract, discipline ledger, Web build/typecheck, format, lint, and TypeScript typecheck.
  • Ablation: without expansion the issue fixture produces an empty referenced property; without bounds expansion could be unbounded.
  • Real provider/model smoke: not run; tests use the existing local conversion and mocked transport boundaries.

Impact

  • User-visible behavior: Antigravity model tool declarations retain expressible local result constraints.
  • Model-visible context/tools: structured schemas sent to Antigravity are more faithful.
  • Runtime/lifecycle: request preparation now fails closed for unsupported references.
  • Persisted config/data: none.
  • Compatibility/risk: schemas without references retain existing behavior; expansion is bounded.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 8, 2026
@JS-banana

JS-banana commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

hi,Preserving structured output contracts in CCA tool declarations is a valuable fix.

Sharing two observations regarding traversal overhead and node/byte accounting in expandLocalSchemaRefs:

1. Repeated subtree serialization in visit

In visit:

bytes += Buffer.byteLength(JSON.stringify(value) ?? "");
  • Because JSON.stringify(value) is executed at every node during the recursive walk, every subtree is serialized repeatedly down to the leaf nodes. For a schema with depth $D$ and node count $N$, this produces $O(N \times D)$ serialization overhead.
  • bytes accumulates the sum of every serialized intermediate subtree rather than the byte length of the schema itself (for instance, a schema of ~4 KB can accumulate >20 KB in bytes).
  • This traversal runs in convertTools for all registered tools on each turn, regardless of whether a schema contains $ref.

2. Double traversal of target and MAX_SCHEMA_REF_NODES (512)

In $ref expansion:

const target = visit(pointer(ref), depth + 1, ref) as Record<string, unknown>;
active.delete(ref);
const siblings = Object.fromEntries(
  Object.entries(object).filter(([key]) => key !== "$ref"),
);
return visit({ ...target, ...siblings }, depth + 1, path);
  • target is fully traversed and counted by visit(pointer(ref)).
  • Passing { ...target, ...siblings } into return visit(...) traverses the entire target subtree a second time, incrementing nodes and bytes again for every field.
  • Along with the initial traversal of $defs from the root, the effective node count for referenced types is multiplied. In practice, a schema with ~50–60 fields and 1–2 $ref usages can exceed MAX_SCHEMA_REF_NODES (512) due to the repeated counting and fail closed before sending the request.

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(antigravity): 工具 Schema 转换静默删除 $ref 结果约束

2 participants