Files
UnbiasedStrata/frontend/tests/data
Robert KarlandClaude Fable 5.1 cd3be94f42 frontend: a control token's text inside a message is text (USTRAT-14)
The rendered prompt was tokenized whole with specials parsed, so "<|image_pad|>" in a
document an agent read became the image pad token and the engine refused the request
("the prompt has more images than the embeddings file"); "<|im_end|>" in a tool
result ended a turn. Upstream's Python server marked these literals before the template
rendered (#537, #554); the C++ front end lost that with the server's removal.

frontend/literals.hpp: the texts of the vocabulary's control tokens and marker-like
added tokens (<think>, <tool_call>, [gMASK]) are swapped for private-use marks in the
messages and tools before oaicompat_chat_params_parse renders the template, swapped
back after, and the spans they covered are tokenized as text: parse_special off, and an
added token the tokenizer matches regardless is split until none is left. Media parts
are not scanned. An assistant message keeps a leading whole <think>...</think> block
as the model's markers (clients that send reasoning inline), as upstream did. A mark
that a template's tojson(ensure_ascii=True) escaped as a surrogate pair is read too.
A request without literals renders and tokenizes exactly as before.

mtmd's logger wrote every level to stderr, its debug line add_text() among them: the
whole rendered prompt once per request into the journal. It now goes through the
common log, where debug lines need the server's verbosity raised.

Tests: frontend/tests/literals_test.cpp (no model; nlohmann json, the interface
common_json copies) in make test; e2e.sh runs a third fake-engine server with upstream's
Qwen3 template (frontend/tests/data/qwen3-chat-template.jinja) and checks
usage.prompt_tokens against the prompt tokenized by hand with the literals as text, for
user content, a tool description and an assistant history message.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-19 23:35:32 -07:00
..