Self-describing instance/certificate formats; structured 400 on parse error#217
Open
wrigjl wants to merge 2 commits into
Open
Self-describing instance/certificate formats; structured 400 on parse error#217wrigjl wants to merge 2 commits into
wrigjl wants to merge 2 commits into
Conversation
…arse error
Adds `instanceFormat` and `certificateFormat` to `IProblem` with
default-empty implementations so existing problems compile unchanged.
Populates the fields on SAT3 and CLIQUE.
Introduces `ProblemParseException` and `CertificateParseException`.
SAT3 and CLIQUE constructors throw on malformed instances; SAT3Verifier
and CliqueVerifier throw instead of silently dropping malformed input.
`IVerifier<T>` default impl now unwraps `TargetInvocationException` so
parse exceptions surface with their real type to the controller.
`/ProblemProvider/verify` and `/ProblemProvider/problemInstance` now
return HTTP 400 with a structured body:
{ "error": "instance_parse_error" | "certificate_parse_error",
"problem": "<problem name>",
"expected": "<instanceFormat or certificateFormat verbatim>",
"received": "<the offending input>",
"detail": "<specific reason>" }
The `expected` field comes from the same `instanceFormat`/
`certificateFormat` exposed by `/ProblemProvider/info` — single source
of truth for the format hint.
Backfilling the remaining ~41 problems and extending the
validate-and-throw pattern to their verifiers is the natural follow-up
(tracked in mcpredux TODO.md §1.5).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced May 24, 2026
…ields Adds instanceFormat / certificateFormat declarations with TODO placeholders and inline examples to PROBLEM_Class.txt, and hints in the string-instance constructor that bad inputs should throw ProblemParseException so the controller layer can return a structured 400 instead of an unhandled-exception 500. ProblemVerifier.txt gains a parallel hint in `verify`: throw CertificateParseException on malformed certificate input rather than silently returning false. README.md documents both new fields under "Problem Class" and notes the throw-on-parse-failure expectation under both "Problem Class" and "Verifiers". A generated template now nudges the contributor toward the self-describing, structured-error pattern instead of the older silent-failure default. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
wrigjl
added a commit
to wrigjl/Redux
that referenced
this pull request
May 31, 2026
Ten reduction/verifier classes declared `private string _complexity = ""`
but never exposed it via a public property, producing CS0414 warnings and
silently omitting complexity from API responses. Replaced with:
public string? complexity { get; set; } = null;
Null is an explicit "not specified" sentinel, giving callers a consistent
JSON shape. Also adds the property to the Reduction and Solver scaffolding
templates so new classes get it by default.
Remaining: KarpGraphColorToExactCover.cs and ProblemVerifier.txt are
blocked on PRs ReduxISU#215 and ReduxISU#217 respectively.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two new fields to IProblem and turns parse failures on /verify and /problemInstance into structured 400 responses that quote the expected format back to the caller.
New fields on IProblem (default-implemented as "" so existing problems compile unchanged):
Populated on SAT3 and CLIQUE as a pilot. Other problems return empty strings until backfilled.
Two new exception types in Interfaces/ParseExceptions.cs:
SAT3 and CLIQUE constructors throw ProblemParseException on shape errors instead of silently constructing a half-populated problem object. SAT3Verifier and CliqueVerifier throw CertificateParseException instead of silently dropping malformed assignments (previously, lowercase 'true'/'false' in a SAT3 certificate would parse to an empty true-literal list and the verifier would just return false — no diagnostic).
IVerifier.verify default impl unwraps TargetInvocationException from Activator.CreateInstance so a ProblemParseException thrown from T(string) surfaces with its real type to the controller layer.
POST /ProblemProvider/verify and POST /ProblemProvider/problemInstance now return IActionResult. On parse failure they return HTTP 400 with body:
{ "error": "instance_parse_error" | "certificate_parse_error",
"problem": "",
"expected": "",
"received": "",
"detail": "" }
The "expected" field is the same string exposed by /ProblemProvider/info on instanceFormat/certificateFormat — single source of truth for the format hint. Success responses are unchanged (same JSON-string body, HTTP 200).
Verified live: the canonical SAT3 gut-check certificate "x1=true,x2=true,x3=false,x4=true" now returns 400 with the SAT3 certificateFormat in expected and "assignment 'x1=true' has value 'true'; expected True/False (capitalized) or T/F" in detail.
Backfilling the remaining ~41 problems and extending the validate-and-throw pattern to their verifiers is a natural follow-up.