Skip to content

fix(grammars): restore backslash escaping in llama31 grammar fixture - #11242

Merged
mudler merged 1 commit into
masterfrom
fix/llama31-grammar-fixture-escaping
Jul 30, 2026
Merged

fix(grammars): restore backslash escaping in llama31 grammar fixture#11242
mudler merged 1 commit into
masterfrom
fix/llama31-grammar-fixture-escaping

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Problem

master is red. The tests workflow fails on both tests-linux and tests-apple with a single spec:

[FAIL] JSON schema grammar tests JSON [It] generates a valid grammar from JSON schema
pkg/functions/grammars/llama31_schema_test.go:70

It is deterministic (all 5 --flake-attempts fail) and currently blocks every open PR, including the update/LLAMA_VERSION, update/IK_LLAMA_VERSION, update/CRISPASR_VERSION and update/AUDIO_CPP_VERSION dependency bumps, none of which touch this code.

Root cause

#11041 (37f2087f9) rewrote the testllama31inputResult1 fixture and un-escaped the backslashes inside its Go raw-string literal:

-		[^"\\] |
-		"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
+		[^"\] |
+		"\\" (["\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])

In a backtick literal those are literal characters, so the expectation changed from [^"\\] to [^"\]. The fixture is compared line-by-line via ContainSubstring against the grammar built from PRIMITIVE_RULES in pkg/functions/grammars/bnf_rules.go, which is unchanged since May and still emits the doubled form. The expectation therefore can never match.

The sibling json_schema_test.go still carries the correct [^"\\], which is why only this one spec fails.

Fix

Restore the four fixture lines to their pre-#11041 form. The cyclic $ref and depth-limit specs added by #11041 are untouched and still pass, so the security fix in that PR is fully preserved.

The fixture is now byte-identical to its pre-#11041 state (verified with git diff 37f2087f9^ -- pkg/functions/grammars/llama31_schema_test.go).

How this reached master

gh pr checks 11041 shows only the DCO check ever reported on that PR. Its test runs were cancelled during the CI purge, so it merged without the tests gate.

Verification

$ go test ./pkg/functions/...
ok  github.com/mudler/LocalAI/pkg/functions
ok  github.com/mudler/LocalAI/pkg/functions/grammars   # 29/29 specs
ok  github.com/mudler/LocalAI/pkg/functions/peg

gofmt -l and go vet clean. Test-only change, no user-facing behaviour, so no docs update applies.

PR #11041 rewrote the testllama31inputResult1 fixture and un-escaped the
backslashes inside its Go raw-string literal, turning `[^"\\]` into
`[^"\]` and `["\\/bfnrt]` into `["\/bfnrt]`. The fixture is compared
line-by-line against the grammar built from PRIMITIVE_RULES in
bnf_rules.go, which is unchanged and still emits the doubled form, so
"generates a valid grammar from JSON schema" fails on every platform.

Restore the four fixture lines to their pre-#11041 form. The cyclic $ref
and depth specs added by that PR are untouched.

The regression reached master because only the DCO check ever reported
on #11041; its test runs were cancelled during the CI purge.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude Code:claude-opus-5[1m] [Bash] [Edit]
@mudler
mudler merged commit 82487e6 into master Jul 30, 2026
1 of 22 checks passed
@mudler
mudler deleted the fix/llama31-grammar-fixture-escaping branch July 30, 2026 21:53
@localai-bot localai-bot added the bug Something isn't working label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants