fix(agents): parse prompt_tokens/completion_tokens in CLI usage for llama.cpp compatibility (#77992)#78085
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed May 31, 2026, 1:17 AM ET / 05:17 UTC. Summary PR surface: Source +7, Tests +37. Total +44 across 2 files. Reproducibility: yes. at source level: feed the CLI JSONL parser a result event with Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the alias fallback after contributor-supplied real llama.cpp/OpenAI-compatible CLI proof, or after a maintainer records an explicit proof override with equivalent local proof. Do we have a high-confidence way to reproduce the issue? Yes, at source level: feed the CLI JSONL parser a result event with Is this the best way to solve the issue? Yes, the PR's narrow fallback in shared CLI usage parsing is a maintainable fix for the reported field-name mismatch. A future cleanup could route CLI parsing through AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 51dee73a5d3e. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +7, Tests +37. Total +44 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
byungskers
left a comment
There was a problem hiding this comment.
This is a great compatibility fix for llama.cpp and other OpenAI-compatible local providers. The fallback chain for usage fields is well-structured — prioritizing the modern input/output fields first while gracefully falling back to prompt/completion_tokens. The test case with the detailed comment explaining the issue is especially helpful for future maintainers.
…t for llama.cpp (openclaw#77992) llama.cpp and other OpenAI-compatible local providers return usage as { prompt_tokens, completion_tokens } instead of { input_tokens, output_tokens }. The toCliUsage() function in cli-output.ts only accepted input_tokens / output_tokens (and their camelCase aliases), so llama.cpp usage was silently dropped and context display showed "?/131k" for all llama.cpp users. Add prompt_tokens and completion_tokens as fallback keys for totalInput and output respectively in toCliUsage(). Both parseCliJson and parseCliJsonl go through this function, so the fix covers all CLI output parsing paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1eae9bc to
383946f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
Summary
toCliUsage()incli-output.tsonly recognizedinput_tokens/output_tokens(and camelCase aliases) from CLI runner output. llama.cpp and other OpenAI-compatible local providers returnprompt_tokens/completion_tokensinstead, which are the standard OpenAI field names.?/131kfor all llama.cpp, Ollama, and similar OpenAI-compatible users.prompt_tokens→ fallback fortotalInputandcompletion_tokens→ fallback foroutputintoCliUsage(). BothparseCliJsonandparseCliJsonlroute through this function, so all CLI output parsing paths are covered.Closes #77992
Testing
Real behavior proof
?/131kwith llama.cpp after upgrading to 2026.5.4 — field name mismatch causes usage to be silently droppedprompt_tokens,completion_tokens,total_tokens).proof:override or advise on evidence format.