Skip to content

chat: fix whitespace problems once and for all#24624

Merged
pwilkin merged 3 commits into
masterfrom
fix-whitespace-parser-probs
Jun 15, 2026
Merged

chat: fix whitespace problems once and for all#24624
pwilkin merged 3 commits into
masterfrom
fix-whitespace-parser-probs

Conversation

@pwilkin

@pwilkin pwilkin commented Jun 14, 2026

Copy link
Copy Markdown
Member

Overview

I finally got around to checking the problems with whitespace parsing and I think this fixes most issues.

Additional information

Removed spaces from all JSON parsers, removed space trimming from mapper (which was causing the error described in #23602 ).

Requirements

@pwilkin pwilkin requested review from a team and ggerganov as code owners June 14, 2026 20:42
@pwilkin pwilkin requested review from CISC and aldehir and removed request for a team and ggerganov June 14, 2026 20:42
@github-actions github-actions Bot added the testing Everything test related label Jun 14, 2026
Comment thread common/peg-parser.cpp
Comment on lines 1273 to 1277
common_peg_parser common_peg_parser_builder::double_quoted_string() {
return rule("double-quoted-string", [this]() {
return sequence({literal("\""), string_content('"'), literal("\""), space()});
return sequence({literal("\""), string_content('"'), literal("\"")});
});
}

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.

Need to make sure the json-to-grammar rules align with this, which is the only reason I had the space in there.

@pwilkin pwilkin Jun 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, but the key point is, this is just resolving ambiguity. Since both the array and object parsers already have enclosing whitespaces, this leaves just straight out constants. And having a constant have a space at the end was producing a parsing ambiguity that actually caused an error with <number><newline>, because the newline got consumed as part of the number and wasn't available to be consumed as part of the marker (and I stopped stripping the newlines from markers so it wasn't valid).

I first wanted to go with a new parser space_no_newline(), but realized that I can just remove the extra space() from there and the result would be the same. The only place this potentially mattered was the json-schema-to-grammar for pure json-schema output, which had wrapping spaces that I had to add directly to the parser.

@github-actions github-actions Bot added examples python python script changes labels Jun 14, 2026
@aldehir

aldehir commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Oh my. Ok, save off the diff and let's work the JSON schema in a separate PR.

@pwilkin

pwilkin commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

Aight, reverted.

@pwilkin

pwilkin commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

@ggml-org/maintainers need 1 more approval please

@pwilkin pwilkin added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jun 14, 2026
@pwilkin pwilkin merged commit a6dff71 into master Jun 15, 2026
23 of 26 checks passed
@sdroege

sdroege commented Jun 15, 2026

Copy link
Copy Markdown

This reproducibly breaks (some) tool calls when used from maki with qwen3.6 27B (didn't test others yet). Reverting just this commit makes it work again.

API error (500): Failed to parse input at pos 527: <tool_call>\n<function=write>\n<parameter=content>\n[...]\n</parameter>\n<parameter=path>\n/path/to/file\n</parameter>\n<parameter=path>\n/path/to/file\n</parameter>\n</function>\n</tool_call>

Specifically read tool calls were working fine but not write, which might be because the content was a C source file with lots of indentation and other whitespace.

I can create an issue with more info if needed and also include what goes over the OpenAI API

@pwilkin

pwilkin commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

@sdroege yes, please do so - best option would be to also include the newly available "save prompts to directory" server option and provide the prompts.

am17an pushed a commit to am17an/llama.cpp that referenced this pull request Jun 20, 2026
* chat: fix whitespace problems once and for all

* Purge trailing spaces from grammar generation

* Revert "Purge trailing spaces from grammar generation"

This reverts commit b0827ec.
papamoose pushed a commit to papamoose/llama.cpp that referenced this pull request Jun 27, 2026
* chat: fix whitespace problems once and for all

* Purge trailing spaces from grammar generation

* Revert "Purge trailing spaces from grammar generation"

This reverts commit b0827ec.
adrianhoehne pushed a commit to adrianhoehne/llama.cpp that referenced this pull request Jul 5, 2026
* chat: fix whitespace problems once and for all

* Purge trailing spaces from grammar generation

* Revert "Purge trailing spaces from grammar generation"

This reverts commit 76efdaabb1fa6fda939646f1fca5358c34583a43.
adromir pushed a commit to adromir/llama-cpp-turboquant that referenced this pull request Jul 8, 2026
* chat: fix whitespace problems once and for all

* Purge trailing spaces from grammar generation

* Revert "Purge trailing spaces from grammar generation"

This reverts commit b0827ec.

(cherry picked from commit a6dff71)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. python python script changes testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants