Skip to content

fix(ai-providers): harden CCA schema projection with safe literal handling - #906

Open
JS-banana wants to merge 1 commit into
openpi-dev:mainfrom
JS-banana:fix/antigravity-const-schema
Open

JS-banana wants to merge 1 commit into
openpi-dev:mainfrom
JS-banana:fix/antigravity-const-schema

Conversation

@JS-banana

@JS-banana JS-banana commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

#905 delivered the const-keyword fix. This PR contains the remaining provider hardening and its unit tests. The Web admission-recovery fixture change already landed in #719.

Problem

Beyond the const-keyword 400 fixed by #905, the CCA schema boundary passes unknown keywords to the server and recursively treats instance data as schemas. That can reject an entire request or silently alter literal values and parameter names. Compacting a literal union must also preserve its constraints: conjunctions, exclusive choices and branch restrictions cannot all be replaced by the same enum union.

Value

Keep tool declarations usable and faithful at OpenPI's existing provider seam, without adopting another provider stack or a general schema-normalization framework.

Approach

  • Extend the legacy unsupported-keyword set with the nine fields identified from oh-my-pi's Google schema implementation, retain description spill for existing liftable constraints, and omit unknown schema keywords through a final allowlist.
  • Collapse only plain, homogeneous anyOf literal alternatives whose value set is unchanged. Preserve allOf, oneOf, mixed types, branch annotations, and additional branch or parent constraints.
  • Infer supported primitive types for bare constants. Retain the const/enum intersection from fix(ai-providers): rewrite const schema literals as enum for Cloud Code Assist #905 and local error for contradictory constraints.
  • Recurse only through schema-valued positions; enum instance objects remain opaque. Build property maps with Object.fromEntries so names such as __proto__ survive.
  • Expand multi-type arrays into alternatives rather than selecting only the first non-null type. Preserve sibling constraints in each alternative and remove type-inapplicable items/properties/required fields.
  • Sanitize each original tool schema once in buildTools; the generic Google pre-pass previously destroyed literal fields before the CCA projection could preserve them. Both existing model routes still use parameters.

Reference reviewed: oh-my-pi@256b3211 schema child classification and type-specific normalization. The projection adopts those boundary principles, rather than claiming exact parity with omp's multi-stage pipeline. Combination semantics follow the JSON Schema contract.

Validation

Replayed the provider hardening commit onto upstream main ffc9c624. The patch is identical to a1587138 according to git range-diff, and git diff --check passed.

  • node --test --experimental-strip-types tests/extensions/ai-providers/antigravity.test.ts: 69 passed.
  • bun run check: passed, including the Web build, formatting, lint, and TypeScript.
  • bun run test with isolated Pi configuration: 2,481 Node tests passed, 8 skipped, 0 failed. All 1,647 UI tests passed.
  • Live smoke on macOS with Pi 1.5.2: loaded the current checkout's provider, subagent, workflow, and setup extensions explicitly and kept normal tools enabled. google-antigravity/gemini-3.8-flash-high replied OK in an ephemeral session. This checks request acceptance with the loaded tool declarations. No model tool call was requested.

Impact

  • User-visible: unsupported schema keywords are omitted instead of being forwarded unchanged.
  • Model-visible: safe literal unions are compacted; instance values, annotations and supported combination constraints are preserved. Multi-type arrays retain all non-null alternatives.
  • Runtime/lifecycle: one source-schema projection; no new tools, provider route, authority, timeout, cache or lifecycle.
  • Persisted configuration/data: none. No dependencies or lockfile changes.
  • Limits: this remains a lossy advertised-schema projection, not a complete CCA validator. The projection omits nullable and removes null from multi-type arrays. $ref/$defs expansion, whole-tool fallback and switching endpoint dialects are out of scope. Non-string enum values and residual oneOf/allOf are structurally preserved but their full server acceptance was not live-tested. Pi still validates the original tool schema.

@JS-banana
JS-banana force-pushed the fix/antigravity-const-schema branch from 7e18c1f to ea4e3e4 Compare November 2, 2026 04:15
@JS-banana JS-banana changed the title fix(ai-providers): align CCA schema sanitization with oh-my-pi (fail-soft gate) fix(ai-providers): harden CCA schema projection with safe literal handling Nov 2, 2026
@JS-banana
JS-banana force-pushed the fix/antigravity-const-schema branch from ea4e3e4 to a158713 Compare November 3, 2026 09:23
@JS-banana
JS-banana force-pushed the fix/antigravity-const-schema branch from 31a58dc to 9b8c3c0 Compare November 11, 2026 09:03

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant