Skip to content

fix(ai): make ADR-0033 blueprint authoring work with OpenAI structured outputs#1547

Merged
xuyushun441-sys merged 1 commit into
mainfrom
fix/adr-0033-blueprint-openai-strict
Jun 2, 2026
Merged

fix(ai): make ADR-0033 blueprint authoring work with OpenAI structured outputs#1547
xuyushun441-sys merged 1 commit into
mainfrom
fix/adr-0033-blueprint-openai-strict

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

What & why

Two bugs found by a live end-to-end run of the ADR-0033 loop in Studio (chat → blueprint → draft → review → publish) against a real model — OpenAI gpt-5.5 via the Vercel AI Gateway. Both were invisible to the existing unit tests (they validate the Zod schema directly and never round-trip through OpenAI's strict JSON-schema check or a multi-turn conversation).

1. propose_blueprint failed against OpenAI strict structured outputs

SolutionBlueprintSchema uses .optional() fields and a free-form seedData z.record. OpenAI's strict structured outputs (what generateObject uses through the gateway) require every property in required and reject open additionalProperties, so the call errored:

Invalid schema for response_format 'SolutionBlueprint': … 'required' … must include every key in properties. Missing 'label'.

…and the agent silently fell back to free-text — the blueprint→draft path never ran on OpenAI models.

Fix: add SolutionBlueprintStrictSchema — a strict-compatible mirror (optional → nullable, no z.record) used only as the generateObject output contract. The lenient SolutionBlueprintSchema (and every existing consumer/test) is unchanged; the blueprint tools stripNulls the values the strict contract emits so downstream stays clean.

2. Tool-only assistant turns failed to persist → context loss

ai_messages.content is required, but an assistant turn that only emits a tool call has no text. The insert failed, the turn was dropped, and the next turn was rebuilt without it — so after the user confirmed, the agent re-proposed instead of applying. Fix: ObjectQLConversationService.addMessage now synthesizes a readable placeholder from the tool names ((called propose_blueprint)) + a defensive non-empty fallback.

Verification

  • Live e2e (Studio + gpt-5.5): propose → "确认" → apply_blueprint drafts 8 artifacts (objects/views/app, self-correcting a dashboard) → chat "查看 8 项变更" → designer generic DraftReviewPanel diff → PublishGET /meta/object/project returns the live object, ?state=draft → 404 (promoted). 0 schema errors, 0 persist failures in the log post-fix.
  • Unit: new strict-schema tests (spec) + propose-uses-strict/strips-nulls + apply-tolerates-nulls (service-ai) + tool-only-turn-persists (conversation). Full suites green: service-ai 463, spec ai 138. New files tsc-clean.

🤖 Generated with Claude Code

…d outputs

Two bugs found via a live Studio e2e run against a real model (OpenAI via the
Vercel AI Gateway), both missed by unit tests:

1. propose_blueprint failed under OpenAI strict structured outputs.
   SolutionBlueprintSchema uses optional fields + a z.record seedData; strict
   mode requires every property in `required` and rejects open
   additionalProperties. Add SolutionBlueprintStrictSchema (optional→nullable,
   no z.record) as the generateObject output contract only; keep the lenient
   schema for validation; strip the nulls the strict contract emits.

2. Tool-only assistant turns failed to persist (ai_messages.content required),
   dropping the turn and losing context so the agent re-proposed instead of
   applying. addMessage now stores a tool-name placeholder + a defensive
   non-empty fallback.

Adds unit tests for both. Verified end-to-end in Studio: propose → confirm →
batch-draft objects/views/dashboards/app → review/diff → publish.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 2, 2026 2:22pm

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests protocol:ai tooling size/xl labels Jun 2, 2026
@xuyushun441-sys xuyushun441-sys merged commit 06f2bbb into main Jun 2, 2026
15 of 16 checks passed
@xuyushun441-sys xuyushun441-sys deleted the fix/adr-0033-blueprint-openai-strict branch June 2, 2026 14:49
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 protocol:ai size/xl tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants