Skip to content

Retain rejected output and repair failure context - #338

Open
robgruen wants to merge 3 commits into
mainfrom
dev/robgruen/failure-payloads
Open

robgruen wants to merge 3 commits into
mainfrom
dev/robgruen/failure-payloads

Conversation

@robgruen

@robgruen robgruen commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Companion to microsoft/TypeChat#457, which addresses microsoft/TypeChat#116 for TypeScript and Python.

  • Add shared FailureInfo to failed Result<T> instances and TypeChatException, keeping rejected output separate from the typed success Value.
  • Retain parsed rejected JSON as an independent JsonElement, raw validator InputText, and original model ResponseText. Honor configured JSON depth, comment, and trailing-comma rules rather than reparsing rejected input with looser settings.
  • Retain rejected constraint instances and program inputs, including when validators are used directly.
  • Preserve explicit null/falsy values, custom failure metadata and subclasses, and the latest useful candidate when a repair returns malformed output or encounters an expected transport failure.
  • Enrich HTTP, I/O, response JSON-decoding, and nested TypeChat exceptions during repair through Exception.Data[FailureInfo.ExceptionDataKey], then rethrow the original exception. Initial transport failures, cancellation, and programming exceptions remain unchanged.
  • Keep typed success values, existing error messages, configurable repair limits, diagnostic events, and the bounded repair prompt window unchanged. No full attempt history is retained.
  • Document the additive API and sensitive-output handling. This is a standalone PR against main, with no unmerged PR dependencies.

API

var failure = Result<MyType>.Error(message).WithFailure(new FailureInfo
{
    Value = rejected,
    ResponseText = originalResponse
});

FailureInfo.HasValue distinguishes unavailable data from an explicit null, false, zero, or empty string. WithFailure returns a shallow copy and preserves existing payloads and custom metadata rather than mutating a reusable validator result.

The existing throwing translation API is preserved. Callers can inspect TypeChatException.Failure; Response continues to expose the original response. Candidate data may precede the latest response text when a repair cannot be parsed.

Validation

  • All 206 .NET unit tests passed; core netstandard2.0 and referencing projects built successfully.
  • Regressions cover JSON/constraint/program validators, value-type result conversion, payload availability, cloned JSON lifetime, custom subclasses, successful/failed/malformed/multiple repairs, transport failures, cancellation, and cross-request isolation.
  • Exact parser-option regressions cover MaxDepth = 1, disallowed comments, and disallowed trailing commas.
  • Scoped dotnet format whitespace --verify-no-changes passed.
  • git diff --check passed.

SourceLink audit remediation

Commit 0f18283 removes the redundant SourceLink.GitHub 8.0.0 package reference that overrode SDK-integrated SourceLink and pulled in the audited Microsoft.Build.Tasks.Git 8.0.0 package (GHSA-23fw-v26w-5fgq). Microsoft recommends serviced SDKs because there is no patched 8.0 NuGet release. The repository now uses SourceLink supplied by .NET SDK 8+, documents the fixed SDK requirement, and keeps transitive NuGet auditing enabled without suppressions.

Validation of the remediation:

  • Full solution Release build with /warnaserror: 0 warnings and 0 errors.
  • All 206 Release unit tests passed on rerun.
  • The vulnerable SourceLink/Build.Tasks.Git NuGet chain is absent from all 19 restored projects.
  • Actual SourceLink custom-debug records and GitHub commit mappings remain embedded in all five library PDBs.

The two prior spell-check findings were corrected in d1221af. All PR checks now pass on the remediation commit, including both .NET 8 CI build/test matrix jobs, CodeQL, and TypeChat.NET CI.

Add untyped FailureInfo to validator results and translation exceptions, preserve custom metadata and the latest useful candidate across repairs, and retain strict parser and cancellation behavior. Add focused regression coverage and document the additive failure-context API.

Co-authored-by: Copilot <[email protected]>
robgruen and others added 2 commits October 12, 2026 19:14
Rename the two test methods flagged by the repository spelling check without changing their coverage or behavior.

Co-authored-by: Copilot <[email protected]>
Remove the redundant SourceLink.GitHub 8.0.0 reference that overrides SDK-integrated SourceLink and pulls in Microsoft.Build.Tasks.Git 8.0.0. Document the fixed SDK requirement, retain transitive NuGet auditing, and preserve embedded source-debugging metadata.

Co-authored-by: Copilot <[email protected]>

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