fix: route llama.cpp log fallback to stderr instead of stdout#609
Open
andreinknv wants to merge 1 commit into
Open
fix: route llama.cpp log fallback to stderr instead of stdout#609andreinknv wants to merge 1 commit into
andreinknv wants to merge 1 commit into
Conversation
When no JS logger is registered, or a registered logger throws, the addon's log callback falls back to writing llama.cpp's output directly. That fallback sent every non-error line (warn / info / debug) to stdout. For an embedder whose stdout is a data channel that is corruption: the `load:` / `init:` / `llama_*` model-load chatter gets interleaved into a CLI's results, or — worse — into an MCP / stdio server's JSON-RPC stream. Library diagnostics belong on stderr regardless of level. Both fallback sites (addonCallJsLogCallback and addonLlamaCppLogCallback) now write all llama.cpp log output to stderr. Error-level lines already went there; this moves only the non-error lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What
When the addon's llama.cpp log callback has no JS logger to delegate to —
either none was registered yet, or a registered logger threw — it falls
back to writing the log line directly. That fallback sent every
non-error line (warn / info / debug) to stdout; only error-level
lines went to stderr.
This routes all llama.cpp log output to stderr in both fallback sites
(
addonCallJsLogCallbackandaddonLlamaCppLogCallback).Why
For an embedder whose stdout is a data channel, the current behavior
corrupts output:
load: …,init: …,llama_*: …model-load chatter interleaved into thoseresults — dozens of
init: embeddings required but some input tokens were not marked as outputs -> overridinglines per run for anembeddings workload.
non-JSON log lines on it are protocol corruption.
Library diagnostics belong on stderr regardless of level — that's the
standard contract, and what llama.cpp itself defaults to. The fallback
only fires when the JS logger is unavailable, so this changes nothing for
consumers with a working logger; it just makes the no-logger fallback
safe.
Change
Both fallback blocks previously did
if (level == error) stderr; else stdout;. Since both branches now target stderr, I collapsed each to asingle
fputs(…, stderr). If you'd prefer to keep the explicit levelcheck for readability, happy to restore it — the only intended behavior
change is non-error → stderr.
Testing
Verified with an embeddings workload that previously interleaved ~120
init:lines into stdout: stdout is now clean and the lines appear onstderr.
Touches only
llama/addon/globals/addonLog.cpp. No JS / API change.