Skip to content

Use structured output for Copilot responses - #23170

Merged
sergiou87 merged 3 commits into
developmentfrom
sergiou87-copilot-structured-output
Nov 12, 2026
Merged

sergiou87 merged 3 commits into
developmentfrom
sergiou87-copilot-structured-output

Conversation

@sergiou87

@sergiou87 sergiou87 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Closes #22958

Description

Copilot models can return malformed JSON or wrap otherwise valid JSON in Markdown, causing errors such as "Copilot returned invalid JSON for commit message generation." This requests schema-backed responses instead of relying on prompt instructions alone.

  • Pass per-message SDK responseSchema for assisted commit planning, ordinary commit-message generation, and conflict resolution, including existing fallback turns and every conflict chunk/retry.
  • Use strict-provider-compatible response shapes: nested assisted outcomes, empty strings for absent message bodies, and separately typed string-enum/null alternatives for conflict actions.
  • Consume the final matching root response after run completion, rather than an intermediate or child response. Preserve reasoning streaming, cancellation, deadlines, error handling, and cleanup.
  • Keep existing parsers, semantic validation, snapshot/change ownership checks, canonical Git-tree validation, conflict path/hunk validation, and reassembly authoritative. No schema-free retries or model downgrades.

Structured-output support still depends on the model and endpoint. Unsupported routes remain explicit failures. Local integration tests do not establish hosted-model enforcement; successful hosted Claude Haiku inference after the nullable-action fix remains unverified.

Validation

Validation covers the source now committed as 0b9efe19d84245d3d628afd946eb4effea0f9996.

Command Result
npm test -- app/test/unit/copilot-response-schema-test.ts app/test/unit/copilot-assisted-commit-sdk-test.ts app/test/unit/copilot-conflict-resolution-test.ts app/test/unit/stores/copilot-store-test.ts Passed: 151 tests
npm run lint:fix Passed
npm run lint Passed
node_modules/.bin/tsc --noEmit -p tsconfig.json Passed
npm run build:dev Passed; development app packaged
node_modules/.bin/markdownlint docs/technical/copilot-structured-output.md --config .markdownlint.js --rules .markdownlint-rules.js Passed
git diff --check Passed

Full unit/UI suite:

export GIT_CONFIG_PARAMETERS="${GIT_CONFIG_PARAMETERS:+$GIT_CONFIG_PARAMETERS }'safe.bareRepository=all'"
npm test

Passed: 3,426 tests, 2 skipped. The process-local Git override allows the suite's synthetic bare repositories; no Git configuration files were changed.

The shipped SDK/runtime was exercised with a local synthetic provider on OpenAI Chat Completions, OpenAI Responses, and native Anthropic Messages. Coverage includes actual native schema forwarding, stop-hook corrections, intermediate/unrelated/child responses, failed and aborted runs, validation retries, cancellation, deadlines, and cleanup.

  • Manual validation
  • Adversarial review with several models

Screenshots

Not applicable: no UI changes. Automated request/lifecycle tests provide the relevant evidence.

Team-authored review

Evidence: See Validation.

Review path: needs-deep-review. Review response-origin correlation, completion/error races, and teardown in copilot-operation.ts and runConflictResolutionTurn. These responses feed conflict resolutions that can replace file contents, so accepting an incorrect or superseded response risks losing changes. Existing validation and apply paths remain unchanged.

Release notes

Notes: [Fixed] Reduce response-format failures when generating commit messages and resolving conflicts with Copilot - #22958

Use separate string-enum and null branches for conflict actions to avoid Claude schema rejection. Restrict enums to scalar strings and add regression coverage for all valid actions. Document the compatibility issue and unverified hosted inference.
@sergiou87 sergiou87 added the needs-deep-review Requires in-depth human code review of affected paths; agent review is not sufficient. label Nov 11, 2026
Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Conflict-resolution changes can replace file contents and warrant deeper human review of SDK event ordering and teardown, while hosted-provider enforcement and validation with committed dependencies remain unverified.

No open issues 🎉

What changed in this PR

This PR addresses malformed Copilot JSON responses reported in #22958 by adding schema-backed output to GitHub Desktop’s commit-message generation, assisted commit planning, and conflict resolution.

Changes:

  • Supplies feature-specific response schemas on every request, including existing fallback and retry paths, while preserving application-level validation.
  • Updates event-driven completion handling to select the final matching root response and reject failed or aborted runs.
  • Adds schema, lifecycle, and local SDK integration coverage, plus documentation of provider compatibility and verification limits.
File Description
docs/​technical/​copilot-structured-output.md Documents schemas, completion handling, and provider limitations.
docs/​technical/​assisted-commit-planning.md Explains the structured response envelope.
app/​test/​unit/​stores/​copilot-store-test.ts Tests schema forwarding, conflict retries, and cleanup.
app/​test/​unit/​stores/​copilot-assisted-commit-test.ts Verifies schemas accompany assisted planning requests.
app/​test/​unit/​stores/​assisted-commit-run-test.ts Updates planning fixtures and asserts schema usage.
app/​test/​unit/​copilot-response-schema-test.ts Tests schema contracts and preserved semantic validation.
app/​test/​unit/​copilot-operation-test.ts Tests response correlation, completion ordering, and cancellation.
app/​test/​unit/​copilot-assisted-commit-sdk-test.ts Exercises native schema forwarding through local synthetic providers.
app/​test/​helpers/​copilot-assisted-commit.ts Updates mock responses and correlated lifecycle events.
app/​src/​lib/​stores/​copilot-store.ts Integrates schemas and shared conflict-response waiting.
app/​src/​lib/​copilot-operation.ts Defines schema types and correlated final-response handling.
app/​src/​lib/​copilot-conflict-resolution.ts Adds the conflict schema and nullable-action prompt guidance.
app/​src/​lib/​copilot-commit-message.ts Defines the commit-message response schema.
app/​src/​lib/​copilot-assisted-commit.ts Adds the assisted schema, envelope parser, and matching prompts.

Review effort: Balanced

Review feedback: F2 from the adversarial review of
#23170.

The existing parser searched for Markdown fences before parsing the complete
response. A schema-valid JSON description containing a fenced example caused
it to parse escaped inner string content and reject a valid commit message.
This defect predates the structured-output changes.

Remove legacy fence extraction and parse the complete response directly.
Markdown-wrapped responses are now rejected without a fallback, as requested.
Keep object, title and description validation and omitted-body normalization
unchanged.

Add regression cases for JSON, shell and plain fences inside descriptions and
for rejecting outer Markdown wrappers. Document the bare-JSON-only contract.
Both regression tests failed before the fix and passed afterward.

Validation:
- npm test -- app/test/unit/copilot-commit-message-test.ts app/test/unit/copilot-response-schema-test.ts app/test/unit/stores/copilot-store-test.ts app/test/unit/copilot-assisted-commit-sdk-test.ts: 79 passed.
- npm test: 3428 passed, 2 skipped, using a process-local
  safe.bareRepository=all override for the existing synthetic bare fixtures.
- npm run lint:fix and npm run lint: passed.
- node_modules/.bin/tsc --noEmit -p tsconfig.json: passed.
- npm run build:dev: passed.
- Markdown lint for the updated technical document and git diff --check: passed.

Validation used the existing local dugite 3.3.2 pin. Those unrelated manifest
and lockfile edits are intentionally excluded from this commit.
@sergiou87
sergiou87 marked this pull request as ready for review November 11, 2026 16:18
@sergiou87
sergiou87 requested a review from a team as a code owner November 11, 2026 16:18
@sergiou87
sergiou87 requested a review from BagToad November 11, 2026 16:18
@sergiou87
sergiou87 merged commit 4d2dfa2 into development Nov 12, 2026
23 checks passed
@sergiou87
sergiou87 deleted the sergiou87-copilot-structured-output branch November 12, 2026 08:19
@niik niik mentioned this pull request Nov 16, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-deep-review Requires in-depth human code review of affected paths; agent review is not sufficient.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot returned invalid JSON for commit message generation

3 participants