Repository navigation
fix: render null tool-call arguments in chat history - #780
Merged
davidkoski merged 1 commit intoNov 16, 2026
Merged
Conversation
swift-jinja throws on NSNull, so once a tool call with a null argument was in history every later prompt failed. Tool-call arguments now reach the template with null as Optional.none, which swift-jinja renders as null.
davidkoski
approved these changes
Nov 16, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thank you!
wballard
added a commit
to swissarmyhammer/mlx-swift-lm-old
that referenced
this pull request
Nov 21, 2026
Apply the upstream commits dbee7be..cb59e9a (the 18 after 6352907) as cherry-picks. CLAUDE.md is untouched. Where a conflict was only a fork refactor, upstream's code is taken; the fork's MTP speed and prompt-cache behavior is kept. - dbee7be Serialize integration tests and their model loading. (ml-explore#760) - 7dde329 GLM-OCR: count the temporal patch in the pixel budget (ml-explore#783) - f0d6150 fix: render null tool-call arguments in chat history (ml-explore#780) - c6c6556 Base Gemma diffusion implementation (ml-explore#352) - 5ecb13b Add LiquidAI LFM3 text support with extended validation and regression tests (ml-explore#756) - 7e2c90f Match the DeepSeek-V3 MoE gate to mlx-lm (ml-explore#795) - 700d8e2 Read r/u prefixes and adjacent string literals in PythonLiteralParser (ml-explore#799) - c75b537 Keep the DeepSeek-V3 MoE output in the activation dtype (ml-explore#793) - bc4746e Fix GLM-OCR small images; match smart_resize rounding in QwenVL.targetSize (ml-explore#764) - b55217c Keep Qwen2-VL vision attention inside each image (ml-explore#755) - dcfcf79 steering follow up and chat interrupt API (ml-explore#798) - e589f33 Load Hadamard-rotated ternary checkpoints (prism_hadamard_qwen35) (ml-explore#630) - cb2bd77 GPT-OSS: clip the SwiGLU with plain Float bounds (ml-explore#792) - bf5a5d4 Declare measured budget transitions for Muse Glimmer and Qwen3.5 (ml-explore#734) - 7517abc Let guided generation use the caller's sampler and logit processor (ml-explore#733) - 5a14024 Refuse LoRA/DoRA on layers the adapters cannot reproduce (ml-explore#800) (ml-explore#803) - ca661dc Size five float32 test comparisons for TF32 matmuls (ml-explore#802) - cb59e9a Batching: Apply a per-row mask to each row of Gemma 2's grouped-query scores (ml-explore#772) Conflict resolutions: - ml-explore#760: the fork's MTPGreedyVerificationIntegrationTests keeps its fixture and moves under ModelLoadingSuite; the fixture loads the target and the drafter as one TestModelManager entry. The fork-only MiniMax M3 suites drop their private `models` for the shared one. .gitignore keeps both. - ml-explore#352 diffusion: the edits to the monolithic Evaluate.swift and KVCache.swift go into the fork's split files (GenerateParameters, TokenIterators, GenerateTokens, GenerationLoop; KVCacheSimple/Chunked, RotatingKVCache, QuantizedKVCache). MTPSpeculation.makeTokenIterator builds the BlockDiffusionTokenIterator for a diffusion model, and throws unsupportedSpeculativeDecoding when a speculation is asked for, so every package path (FM executor, recording generate) takes it. ChatSession takes the diffusion branch before the fork's MTP eligibility check, with the pass's prompt token count; it takes no prompt-end checkpoint. The blockDiffusion guard is in the fork's shared private MTP init. TurboQuantKVCache saves the head width as a sixth meta-state value; the fork's strict prompt-cache validation accepts 5 (old files) or 6 values. The upstream KVCacheTests additions go into KVCacheTests and KVCacheQuantizationTests; MockMainModel (MLXLMTestSupport) gets `capabilities:`. New tests await the fork's async loadWeights. - ml-explore#756 LFM3: model.validate(tokenizer:) runs before the fork's closed- reasoning end guard. The upstream LFM3CheckpointTests await loadWeights. - ml-explore#755: the doc edit goes into the fork's PromptCacheFile.swift. - ml-explore#798 interrupt: `.interrupted` and the steering boundary go into the fork's GenerationLoop and GenerationResults; TokenLoopHandler keeps emitOrCancel with `hasOutput`. Both reasoning-history tests are kept. - ml-explore#734: the fork's QwenReasoningProtocol.qwen35 (history replay, closed thinking-off block) also declares the `.immediate` budget transition; upstream's second `qwen35` is folded into it. The family-delta test resets the fork's replay and prompt-strategy fields too. - ml-explore#733: ported into the fork's GuidedDecoder/GuidedGenerationLoop split. A caller processor or sampler decodes plainly: guided MTP speculation stays greedy-only, so its output stays that of plain greedy decoding. - ml-explore#802: the speculative log-probability test stays out (ml-explore#774 was dropped). After the merge (CLAUDE.md): - No manual `offset +=` after `advance(` in the merged models. - HybridRecurrentCacheOffsetTests adds prism_hadamard_qwen35 (LLM and VLM classes), whose Qwen 3.5 caches include MambaCache. - LFM3ReferenceTests.testLongContextChunking (gated by MLX_LFM3_LONG_CONTEXT) moves ungated to IntegrationTesting as LFM3LongContextProfileTests. The env-gated upstream IntegrationTesting suites LFM3CheckpointTests and LFM3TokenizerIntegrationTests stay gated. Tests: MLXLMTests 1227 XCTest and 2459 Swift Testing (3 known issues), MLXGuidedGenerationTests 85, MLXFoundationModelsTests 537, CXGrammarTests 7, MLXHuggingFaceMacrosTests 11 pass. Release, IntegrationTesting: Qwen35SessionPromptCacheTests, Qwen35AgenticPromptCacheAssessmentTests, PromptCacheSpoolCostAssessmentTests and LFM3LongContextProfileTests pass. Co-Authored-By: Claude Opus 5.5 <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.
Proposed changes
Once a tool call with a null argument is in chat history, every later prompt throws
JinjaError.runtime("Cannot convert value of type NSNull to Jinja Value")until the history is cleared. This also happens throughChatSession(history:).respond. Parsers produce such nulls, for example LFM3'sxmlFunctionparser when the schema allows["integer", "null"], or Python-styleNone.The cause is that tool-call arguments reached the template as
NSNull. swift-jinja'sValue(any:)has noNSNullcase, in 2.5.2 or 3.0.0, but it readsOptional.noneas null. This PR adds an internalJSONValue.templateValuethat maps.nulltoOptional.none, recursively through objects and arrays.ToolCall.Function.argumentsObject, which builds arguments only for template messages, now uses it.sendableValueandanyValuestill returnNSNull, because the parsers andJSONSerializationrely on it.A new unit test in
ToolCallIdTestschecks that null at the top level, inside a nested object, and inside an array reaches the generated message asnil, with noNSNullleft. The new integration testNullToolCallArgumentIntegrationTestsrenders the conversation with the LFM3 template (LiquidAI/LFM3-1.7B-MLX-4bitat91f3408). Both tests fail onmain. With this change, the prompt matches the transformers 5.23.0.dev0 output byte for byte, including<parameter=unit>\nnull\n</parameter>. The one exception is the order of keys in the<tools>JSON, which swift-jinja sorts; that difference is separate from this change.A null inside an app-built tool spec, for example a
JSONSerializationnull, still throws from the first turn. This PR does not change that.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.