Skip to content

Commit 8d6ad73

Browse files
s.anastasiouDavide Cifarelli
authored andcommitted
fix(server): empty --chat-template-file falls back to hardcoded template
The usage text added in the previous commit promised: --chat-template-file <path> Load a Jinja chat template file. Overrides the hardcoded Qwen3/Laguna renderer. Empty or missing falls back to the hardcoded template. … but the CLI parser was aborting startup with `return 1` whenever the file length was <= 0, contradicting the "empty falls back" half of the promise. Behavior change: when --chat-template-file points at a 0-byte file we now log a warning and leave ServerConfig::chat_template_src empty, so http_server.cpp's chat handler falls through to render_chat_template() (the hardcoded QWEN3/LAGUNA path) as documented. Non-empty files are unchanged; short-read errors still abort. This makes scripted launches resilient to a transient empty template file (e.g. a half-written sed pipe, a checked-out-but-not-populated template path) — the server starts and serves with the hardcoded template instead of refusing to come up. Identified by cubic.
1 parent 469f6e6 commit 8d6ad73

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

dflash/src/server/server_main.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,25 @@ int main(int argc, char ** argv) {
161161
long n = std::ftell(f);
162162
std::fseek(f, 0, SEEK_SET);
163163
if (n <= 0) {
164+
// The usage text promises "Empty or missing falls back to the
165+
// hardcoded template." Honor that: log a warning and leave
166+
// chat_template_src empty so http_server.cpp falls through to
167+
// the hardcoded QWEN3/LAGUNA renderer, instead of aborting
168+
// startup.
164169
std::fclose(f);
165-
std::fprintf(stderr, "[server] --chat-template-file: empty file '%s'\n", path);
166-
return 1;
167-
}
168-
sconfig.chat_template_src.resize((size_t)n);
169-
size_t got = std::fread(sconfig.chat_template_src.data(), 1, (size_t)n, f);
170-
std::fclose(f);
171-
if (got != (size_t)n) {
172-
std::fprintf(stderr, "[server] --chat-template-file: short read on '%s'\n", path);
173-
return 1;
170+
std::fprintf(stderr, "[server] --chat-template-file: '%s' is empty, "
171+
"falling back to hardcoded template\n", path);
172+
} else {
173+
sconfig.chat_template_src.resize((size_t)n);
174+
size_t got = std::fread(sconfig.chat_template_src.data(), 1, (size_t)n, f);
175+
std::fclose(f);
176+
if (got != (size_t)n) {
177+
std::fprintf(stderr, "[server] --chat-template-file: short read on '%s'\n", path);
178+
return 1;
179+
}
180+
sconfig.chat_template_path = path;
181+
std::fprintf(stderr, "[server] loaded chat template from %s (%ld bytes)\n", path, n);
174182
}
175-
sconfig.chat_template_path = path;
176-
std::fprintf(stderr, "[server] loaded chat template from %s (%ld bytes)\n", path, n);
177183
} else if (std::strcmp(argv[i], "--kv-cache-dir") == 0 && i + 1 < argc) {
178184
sconfig.disk_cache_dir = argv[++i];
179185
} else if (std::strcmp(argv[i], "--kv-cache-budget") == 0 && i + 1 < argc) {

0 commit comments

Comments
 (0)