fix(lm-studio): recognize wrapped HTTP 400 grammar parse failures - #71279
Closed
bestail wants to merge 1 commit into
Closed
fix(lm-studio): recognize wrapped HTTP 400 grammar parse failures#71279bestail wants to merge 1 commit into
bestail wants to merge 1 commit into
Conversation
Recognize LM Studio sampler errors using the "failed to parse grammar" wording, including SDK-wrapped HTTP 400 exceptions without a structured status code. Route them through the existing llama.cpp schema recovery path so unsupported pattern/format constraints are stripped before a single retry.
Collaborator
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.
Summary
failed to parse grammarpredict request returned 400llama_cpp_grammar_patternrecovery pathpattern/formatkeys and retries onceProblem
LM Studio can surface llama.cpp JSON-schema-to-grammar failures in either of these forms:
or, after SDK wrapping:
The second form has no structured
status_code, so Hermes currently classifies it asunknown. The first form has HTTP 400 but does not match the phrases recognized by the existing llama.cpp grammar recovery classifier. As a result, Hermes performs a generic retry without removing unsupported schema constraints, and the same request can fail again.Root cause
The existing classifier recognizes:
error parsing grammarjson-schema-to-grammarunable to generate parser ... templateIt does not recognize LM Studio's
failed to parse grammarwording. It also requires a structured HTTP 400 status, while LM Studio's SDK wrapper may expose 400 only in the exception text.Fix
Extend the existing llama.cpp grammar condition to accept:
status_code == 400, orstatus_code is Nonewhen the normalized message containspredict request returned 400and recognize
failed to parse grammaras another llama.cpp grammar failure phrase.The condition still requires a recognized grammar-specific phrase, so unrelated wrapped HTTP 400 errors are not routed into schema recovery.
Test plan
RED was observed before changing production code:
format_errorunknownpatternandformatGREEN after rebasing onto the latest
origin/mainand rerunning the combined relevant suites:Additional checks:
origin/main(95a566b1e769cca26dfa441c1ff963ec03bdc7d6) before final verificationgit diff --checkpassedScope and risk
The production change is limited to one existing error-classification branch. Cloud-provider behavior is unchanged unless an error simultaneously contains a recognized llama.cpp grammar phrase and either a structured HTTP 400 or LM Studio's wrapped
predict request returned 400marker.