From 41dd24f49f919c7bbfd768712e519788fc6894ed Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Tue, 27 Oct 2026 23:24:44 -0700 Subject: [PATCH 1/5] GPT-OSS: match client stop sequences in the Harmony final message only The engine matched `stop` against every generated character, including the private Harmony analysis. A sequence that appeared while gpt-oss reasoned ended the request before any answer: finish_reason "stop", reasoning only, empty content. On provider 0.10.4 with production gpt-oss-20b weights, stop ["."] did this to 36/36 requests and ["\n\n"] to 14/36 (0/36 without a stop); each cut reasoning is an exact prefix of its same-seed no-stop twin, which went on to answer. ModelEOSPolicy.stopStringScope gives GPT-OSS the Harmony final-channel scope (<|channel|>final ... <|message|> up to <|end|>/<|return|>/<|call|>/<|start|>). It travels with the EOS policy: EngineV2SlotFactory -> makeBridge -> EngineV2Bridge -> CBv2Request.stopStringScope, and the matched-sequence replay uses the same scope. Other models keep whole-output matching. Bumps libs/mlx-swift-lm to 38b90ed1 (fix/harmony-final-stop-scope), which adds the scope to StopHoldback. Co-Authored-By: Claude Opus 5.5 --- changelog.d/gptoss-stop-in-final-channel.md | 9 +++++ docs/architecture/inference.md | 2 +- libs/mlx-swift-lm | 2 +- .../Bridge/EngineV2Bridge+StopSequence.swift | 17 ++++++++-- .../Bridge/EngineV2Bridge+Submission.swift | 3 +- .../Bridge/EngineV2Bridge+Translation.swift | 6 ++-- .../Engine/Bridge/EngineV2Bridge.swift | 5 +++ .../Engine/Factory/EngineV2Config.swift | 2 ++ .../Engine/Factory/EngineV2SlotFactory.swift | 1 + .../Prompting/ChatTemplateFixes.swift | 6 ++++ .../GPTOSSHarmonyTemplateFixes.swift | 9 +++++ .../Inference/Prompting/ModelEOSPolicy.swift | 10 ++++++ .../Engine/EngineV2BridgeTests.swift | 33 +++++++++++++++++++ .../MultiModelBatchSchedulerEngineTests.swift | 11 +++++++ 14 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 changelog.d/gptoss-stop-in-final-channel.md diff --git a/changelog.d/gptoss-stop-in-final-channel.md b/changelog.d/gptoss-stop-in-final-channel.md new file mode 100644 index 0000000000..da591a38d6 --- /dev/null +++ b/changelog.d/gptoss-stop-in-final-channel.md @@ -0,0 +1,9 @@ +### GPT-OSS stop sequences apply to the answer only + +- A client `stop` sequence on GPT-OSS models such as `gpt-oss-20b` now + matches only the Harmony `final` message, the text returned as `content`. + It used to match the private analysis too, so a sequence that appeared + while the model reasoned (for example `"\n\n"` or `"."`) ended the request + before any answer: `finish_reason` `stop`, reasoning only, empty content. + Tool-call arguments are never cut either. Other models keep whole-output + matching. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 5e51121117..4f24a26f5d 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -1843,7 +1843,7 @@ disabled for this hybrid model. | `logit_bias` | `logitBias` — string keys parsed to non-negative `Int`; invalid keys dropped and counted | `[:]` | | `logprobs` + `top_logprobs` | `topLogprobs = logprobs ? min(20, max(1, top_logprobs ?? 0)) : 0` | `0` | | `max_tokens` | `maxTokens = max_tokens ?? 4096` | 4096 | -| `stop` | `stopStrings`, matched on held-back detokenised text (`EngineV2Bridge+StopSequence.swift`) | `[]` | +| `stop` | `stopStrings`, matched on held-back detokenised text (`StopHoldback`). GPT-OSS sets `stopStringScope` to the Harmony `final` message (`ModelEOSPolicy.stopStringScope`), so analysis and tool-call frames never match; the reported sequence replays the same scope (`EngineV2Bridge+StopSequence.swift`) | `[]` | | `min_p`, `priority` | **Ignored**: always `0` | — | | `n`, `best_of` | **Not represented**: one alternative | — | diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index aee6ebb683..38b90ed185 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit aee6ebb6835c62feda80000c83f81f2788cc9822 +Subproject commit 38b90ed185d883bd5f54c355b8eab9df5fd0919a diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+StopSequence.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+StopSequence.swift index 5ddaf77813..6fb0f4c4c7 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+StopSequence.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+StopSequence.swift @@ -1,4 +1,5 @@ import Foundation +import MLXLMCommon extension EngineV2Bridge { func matchedStopSequence( @@ -10,13 +11,25 @@ extension EngineV2Bridge { tokenIds: generatedTokens, skipSpecialTokens: false ) - return Self.matchedStopSequence(candidates: candidates, generatedText: generatedText) + return Self.matchedStopSequence( + candidates: candidates, generatedText: generatedText, scope: stopStringScope) } + /// The candidate that ended generation. A scoped model matched stops only + /// inside its scope, so a candidate seen elsewhere (Harmony analysis) did + /// not stop it. static func matchedStopSequence( candidates: [String], - generatedText: String + generatedText: String, + scope: CBv2StopStringScope? = nil ) -> String? { + if let scope { + let holdback = StopHoldback(stopStrings: candidates, scope: scope) + let scan = holdback.ingest(generatedText) + guard scan.stopped else { return nil } + let tail = generatedText.unicodeScalars.dropFirst(scan.text.unicodeScalars.count) + return candidates.first { !$0.isEmpty && tail.starts(with: $0.unicodeScalars) } + } let generatedScalars = Array(generatedText.unicodeScalars) var best: (position: Int, candidateIndex: Int, value: String)? for (candidateIndex, candidate) in candidates.enumerated() where !candidate.isEmpty { diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Submission.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Submission.swift index 39116e8c83..1abc162e03 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Submission.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Submission.swift @@ -246,7 +246,8 @@ extension EngineV2Bridge { samplingDefaults: samplingDefaults, // The same coordinator hint that gates the write also tells the // engine which fork boundary is worth staging. - prefixCheckpointTargetTokens: donationDemand?.repeatedPrefixTokens + prefixCheckpointTargetTokens: donationDemand?.repeatedPrefixTokens, + stopStringScope: stopStringScope ) cbv2Request.positionState = positionState ?? multimodal?.positionState cbv2Request.hybridPrefixIdentity = hybridPrefixIdentity diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Translation.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Translation.swift index 3a33336bb5..da8a5bd87c 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Translation.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Translation.swift @@ -65,7 +65,8 @@ enum EngineV2Translation { multimodal: CBv2MultimodalInput? = nil, tokenConstraint: (any CBv2TokenConstraint)? = nil, samplingDefaults: EngineV2SamplingDefaults = .legacy, - prefixCheckpointTargetTokens: Int? = nil + prefixCheckpointTargetTokens: Int? = nil, + stopStringScope: CBv2StopStringScope? = nil ) -> CBv2Request { CBv2Request( id: id, @@ -79,7 +80,8 @@ enum EngineV2Translation { prefixCacheEnabled: cacheEnabled, multimodal: multimodal, tokenConstraint: tokenConstraint, - prefixCheckpointTargetTokens: cacheEnabled ? prefixCheckpointTargetTokens : nil + prefixCheckpointTargetTokens: cacheEnabled ? prefixCheckpointTargetTokens : nil, + stopStringScope: stopStringScope ) } diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge.swift index eda037ee03..1d2eae904b 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge.swift @@ -106,6 +106,9 @@ public actor EngineV2Bridge { /// tokens) — `buildStopTokenIds` semantics, computed ONCE at bridge /// construction so B=1 and batched behavior stay identical. let stopTokenIds: Set + /// Where client stop strings apply (`ModelEOSPolicy.stopStringScope`); + /// nil matches the whole generated text. + let stopStringScope: CBv2StopStringScope? /// Artifact sampling defaults resolved once at construction /// (`EngineV2SamplingDefaults.resolve`); `.legacy` for every family /// that has not been admitted. @@ -368,6 +371,7 @@ public actor EngineV2Bridge { tokenizer: TokenizerHandle, eosTokenIds: Set, extraEOSTokens: [String] = [], + stopStringScope: CBv2StopStringScope? = nil, samplingDefaults: EngineV2SamplingDefaults = .legacy, defaultMaxTokens: Int = 4096, maxConcurrentRequests: Int = 4, @@ -428,6 +432,7 @@ public actor EngineV2Bridge { extraEOSTokens: extraEOSTokens, convertTokenToId: { [inner = tokenizer.inner] in inner.convertTokenToId($0) } ) + self.stopStringScope = stopStringScope self.samplingDefaults = samplingDefaults self.defaultMaxTokens = defaultMaxTokens self.maxConcurrentRequests = maxConcurrentRequests diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Config.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Config.swift index e587d969fc..4641bbfd99 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Config.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2Config.swift @@ -154,6 +154,7 @@ public enum EngineV2Factory { tokenizer: TokenizerHandle, eosTokenIds: Set, extraEOSTokens: [String] = [], + stopStringScope: CBv2StopStringScope? = nil, samplingDefaults: EngineV2SamplingDefaults = .legacy, defaultMaxTokens: Int = 4096, maxConcurrentRequests: Int = 4, @@ -204,6 +205,7 @@ public enum EngineV2Factory { tokenizer: tokenizer, eosTokenIds: eosTokenIds, extraEOSTokens: extraEOSTokens, + stopStringScope: stopStringScope, samplingDefaults: samplingDefaults, defaultMaxTokens: defaultMaxTokens, maxConcurrentRequests: maxConcurrentRequests, diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2SlotFactory.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2SlotFactory.swift index ab3f5e7e95..faec07ae75 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2SlotFactory.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2SlotFactory.swift @@ -571,6 +571,7 @@ enum EngineV2SlotFactory { tokenizer: tokenizer, eosTokenIds: eosTokenIds, extraEOSTokens: snapshot.extraEOSTokens, + stopStringScope: ModelEOSPolicy.stopStringScope(modelId: modelId, modelType: modelType), samplingDefaults: samplingDefaults, defaultMaxTokens: sizing.defaultMaxTokens, maxConcurrentRequests: effectiveMaxConcurrentRequests, diff --git a/provider-swift/Sources/ProviderCore/Inference/Prompting/ChatTemplateFixes.swift b/provider-swift/Sources/ProviderCore/Inference/Prompting/ChatTemplateFixes.swift index a7fbe46dd6..66ef982671 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Prompting/ChatTemplateFixes.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Prompting/ChatTemplateFixes.swift @@ -5,6 +5,7 @@ // after the model family so future fixes do not bleed across templates. import Foundation +import MLXLMCommon import MLXLMServer struct ChatTemplateFixContext: Sendable { @@ -132,6 +133,11 @@ enum ChatTemplateFixes { return ids } + static func stopStringScope(context: ChatTemplateFixContext) -> CBv2StopStringScope? { + GPTOSSHarmonyTemplateFix.applies(to: context) + ? GPTOSSHarmonyTemplateFix.finalChannelStopScope : nil + } + static func validateGenericToolHistory( _ messages: [[String: any Sendable]] ) throws { diff --git a/provider-swift/Sources/ProviderCore/Inference/Prompting/GPTOSSHarmonyTemplateFixes.swift b/provider-swift/Sources/ProviderCore/Inference/Prompting/GPTOSSHarmonyTemplateFixes.swift index ed312169f1..de294d465c 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Prompting/GPTOSSHarmonyTemplateFixes.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Prompting/GPTOSSHarmonyTemplateFixes.swift @@ -5,6 +5,7 @@ // templates without changing other model families. import Foundation +import MLXLMCommon enum GPTOSSHarmonyTemplateFix { static func applies(to context: ChatTemplateFixContext) -> Bool { @@ -37,6 +38,14 @@ enum GPTOSSHarmonyTemplateFix { Set(["<|return|>", "<|endoftext|>", "<|call|>"].compactMap(tokenToId)) } + /// Client stop strings apply to the final channel, the text clients + /// receive as `content`. Matching them in analysis ended requests before + /// any answer existed (finish_reason "stop", reasoning only); tool-call + /// arguments are not answer text either. + static let finalChannelStopScope = CBv2StopStringScope( + opener: "<|channel|>final", openerEnd: "<|message|>", + closers: ["<|end|>", "<|return|>", "<|call|>", "<|start|>"]) + private static func isHarmonyModelHint(_ value: String?) -> Bool { guard let value else { return false } let normalized = value.lowercased() diff --git a/provider-swift/Sources/ProviderCore/Inference/Prompting/ModelEOSPolicy.swift b/provider-swift/Sources/ProviderCore/Inference/Prompting/ModelEOSPolicy.swift index 707593cce7..f7c5d80cf0 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Prompting/ModelEOSPolicy.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Prompting/ModelEOSPolicy.swift @@ -6,6 +6,7 @@ // slot construction has one scheduler-independent stop-token policy. import Foundation +import MLXLMCommon public enum ModelEOSPolicy { /// Return model-specific EOS tokens at the engine boundary. Most models @@ -24,4 +25,13 @@ public enum ModelEOSPolicy { tokenToId: tokenToId ) } + + /// Where client stop strings apply; nil keeps whole-output matching. + public static func stopStringScope( + modelId: String, + modelType: String? = nil + ) -> CBv2StopStringScope? { + ChatTemplateFixes.stopStringScope( + context: ChatTemplateFixContext(modelId: modelId, modelType: modelType)) + } } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2BridgeTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2BridgeTests.swift index 5cb3ce2e73..b320bb793b 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2BridgeTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2BridgeTests.swift @@ -804,6 +804,39 @@ struct EngineV2MatchedStopSequenceTests { ) == nil) } + @Test("a scoped model reports only the stop that ended its answer") + func scopedMatchedSequence() { + let scope = ModelEOSPolicy.stopStringScope(modelId: "gpt-oss-20b") + let analysis = "<|channel|>analysis<|message|>The answer: Canberra. Done.<|end|>" + #expect(EngineV2Bridge.matchedStopSequence( + candidates: ["."], + generatedText: analysis + "<|start|>assistant<|channel|>final<|message|>It is Canberra", + scope: scope + ) == nil, "a period in the analysis did not stop the request") + #expect(EngineV2Bridge.matchedStopSequence( + candidates: ["!", "."], + generatedText: analysis + "<|start|>assistant<|channel|>final<|message|>It is Canberra. More", + scope: scope + ) == ".") + } + + @Test("GPT-OSS requests carry the bridge's stop-string scope") + func translationCarriesStopScope() { + let scope = ModelEOSPolicy.stopStringScope(modelId: "gpt-oss-20b") + let request = ChatCompletionRequest( + model: "gpt-oss-20b", messages: [ChatMessage(role: "user", content: "hi")], + stop: .multiple(["\n\n"])) + let scoped = EngineV2Translation.cbv2Request( + id: CBv2RequestID(1), promptTokens: [1], request: request, defaultMaxTokens: 16, + stopTokenIds: [], stopStringScope: scope) + #expect(scoped.stopStrings == ["\n\n"]) + #expect(scoped.stopStringScope == scope) + let unscoped = EngineV2Translation.cbv2Request( + id: CBv2RequestID(2), promptTokens: [1], request: request, defaultMaxTokens: 16, + stopTokenIds: []) + #expect(unscoped.stopStringScope == nil) + } + @Test("compares Unicode scalars exactly rather than canonically") func unicodeScalarExactness() { #expect(EngineV2Bridge.matchedStopSequence( diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/MultiModelBatchSchedulerEngineTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/MultiModelBatchSchedulerEngineTests.swift index 50875deaf8..f30f4074cd 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/MultiModelBatchSchedulerEngineTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/MultiModelBatchSchedulerEngineTests.swift @@ -622,6 +622,17 @@ func harmonyEOSUsesModelTypeForAliasedModels() { #expect(ids == [199999, 200002, 200012]) } +@Test("GPT-OSS client stop strings apply to the Harmony final channel only") +func gptOssStopStringsAreScopedToTheFinalChannel() { + let scope = ModelEOSPolicy.stopStringScope(modelId: "gpt-oss-20b") + #expect(scope == CBv2StopStringScope( + opener: "<|channel|>final", openerEnd: "<|message|>", + closers: ["<|end|>", "<|return|>", "<|call|>", "<|start|>"])) + #expect(ModelEOSPolicy.stopStringScope(modelId: "local-alias", modelType: "gpt_oss") == scope) + #expect(ModelEOSPolicy.stopStringScope(modelId: "gemma-4-26b-qat-4bit") == nil) + #expect(ModelEOSPolicy.stopStringScope(modelId: "qwen3.6-35b-a3b-vl-mtp-mxfp8") == nil) +} + @Test("non-Harmony EOS set is unchanged") func nonHarmonyEOSIsUnchanged() { let ids = ModelEOSPolicy.effectiveEOSTokenIds( From 46f7ae9c5d35ca5be5296596c8faec4f02b06cd1 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Wed, 28 Oct 2026 12:04:15 -0700 Subject: [PATCH 2/5] Pin the merged mlx-swift-lm (#369) and the MLX stack it builds on libs/mlx-swift-lm moves to main 25bcd63f, the squash merge of Layr-Labs/mlx-swift-lm#369 (the Harmony final-channel stop scope this PR depends on). SDK main calls mlx-swift APIs newer than the pinned M5 hotfix (MLXFast fencedInputs), so the stack moves with it to the revision SDK main declares, as #1596 did: libs/mlx-swift c633d221 (nested mlx 72dffa2d, mlx-c 2ac897e3) and libs/mlx 72dffa2d. All three are on their repos' main. 72dffa2d carries the NAX head-dim split attention JIT fix (mlx main 6bc9de5b), the same get_steel_attention_nax_kernel change as the 0.10.3 hotfix 31f550af. Provider adaptations for the new SDK enum cases, behavior-preserving: - MLXServerGenerationEvent.logprobs is token metadata, handled like .info by the GLM and JSON answer-format observers (the provider streams logprobs through its own channel and emits no such events today). - MLXOpenAIServiceError.responseFormatCutOffByMaxTokens is the case the SDK split out of invalidResponseFormatOutput for a structured answer cut off by max_tokens; it keeps that case's 422 and retryable classification. Verified on M5 Max: Gemma 4 26B QAT serves an 8,204-token prompt (the 0.10.2 crash path) with an 8,192-token prefix hit on repeat; gpt-oss-20b stop ["."] still returns "The capital of Australia is Canberra". Co-Authored-By: Claude Opus 5.5 --- libs/mlx | 2 +- libs/mlx-swift | 2 +- libs/mlx-swift-lm | 2 +- .../Inference/Engine/InferenceErrorClassifier.swift | 2 +- .../Inference/Prompting/GLM5NextResponseFormat.swift | 2 +- .../ProviderCore/Inference/Prompting/JSONAnswerFormat.swift | 2 +- .../Sources/ProviderCore/ProviderLoop+ErrorMapping.swift | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/mlx b/libs/mlx index 31f550af4d..72dffa2dbb 160000 --- a/libs/mlx +++ b/libs/mlx @@ -1 +1 @@ -Subproject commit 31f550af4df734c1296143b556dad624db3985fc +Subproject commit 72dffa2dbbdce95601fd84f5e8b6d7b4ec97a11b diff --git a/libs/mlx-swift b/libs/mlx-swift index 4926d3d977..c633d221d6 160000 --- a/libs/mlx-swift +++ b/libs/mlx-swift @@ -1 +1 @@ -Subproject commit 4926d3d977d691d2828231d8808058c57c63c874 +Subproject commit c633d221d627898502046714dcca677d9374a1ab diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 38b90ed185..25bcd63f18 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 38b90ed185d883bd5f54c355b8eab9df5fd0919a +Subproject commit 25bcd63f187b96ecf55796c93e104d20c9852d6a diff --git a/provider-swift/Sources/ProviderCore/Inference/Engine/InferenceErrorClassifier.swift b/provider-swift/Sources/ProviderCore/Inference/Engine/InferenceErrorClassifier.swift index 9f5ed4be4c..76230786cd 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Engine/InferenceErrorClassifier.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Engine/InferenceErrorClassifier.swift @@ -39,7 +39,7 @@ func classifyTypedInferenceErrorReason(_ error: Error) -> InferenceErrorReason? } if let serviceError = error as? MLXOpenAIServiceError { switch serviceError { - case .invalidResponseFormatOutput, .multipleToolCallsNotAllowed: + case .invalidResponseFormatOutput, .responseFormatCutOffByMaxTokens, .multipleToolCallsNotAllowed: // Response-format validation and parallel-tool enforcement inspect // sampled model output. Another sample/provider can comply, so // these share the retryable non-provider-fault reason above. diff --git a/provider-swift/Sources/ProviderCore/Inference/Prompting/GLM5NextResponseFormat.swift b/provider-swift/Sources/ProviderCore/Inference/Prompting/GLM5NextResponseFormat.swift index 2ae6daa37f..9f282a1b49 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Prompting/GLM5NextResponseFormat.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Prompting/GLM5NextResponseFormat.swift @@ -98,7 +98,7 @@ struct GLM5NextResponseFormatOutput { content += parsed.content guard let reasoning = parsed.reasoningContent, !reasoning.isEmpty else { return nil } return .parsed(.init(content: "", reasoningContent: reasoning)) - case .toolCall, .toolCallDelta, .info: + case .toolCall, .toolCallDelta, .info, .logprobs: return event } } diff --git a/provider-swift/Sources/ProviderCore/Inference/Prompting/JSONAnswerFormat.swift b/provider-swift/Sources/ProviderCore/Inference/Prompting/JSONAnswerFormat.swift index a93497091e..2e8bb5ba9f 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Prompting/JSONAnswerFormat.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Prompting/JSONAnswerFormat.swift @@ -78,7 +78,7 @@ struct JSONAnswerOutput { switch event { case .content(let text): content += text case .parsed(let parsed): content += parsed.content - case .toolCall, .toolCallDelta, .info: break + case .toolCall, .toolCallDelta, .info, .logprobs: break } } diff --git a/provider-swift/Sources/ProviderCore/ProviderLoop+ErrorMapping.swift b/provider-swift/Sources/ProviderCore/ProviderLoop+ErrorMapping.swift index ba44ca7431..024bcedf20 100644 --- a/provider-swift/Sources/ProviderCore/ProviderLoop+ErrorMapping.swift +++ b/provider-swift/Sources/ProviderCore/ProviderLoop+ErrorMapping.swift @@ -246,7 +246,7 @@ extension ProviderLoop { } if let svcErr = error as? MLXOpenAIServiceError { switch svcErr { - case .invalidResponseFormatOutput, .multipleToolCallsNotAllowed: + case .invalidResponseFormatOutput, .responseFormatCutOffByMaxTokens, .multipleToolCallsNotAllowed: return 422 case .embeddingsNotConfigured: return 501 From 2185dfe93cb60aa95ece16449f30d936b26dcb2a Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Wed, 28 Oct 2026 12:37:56 -0700 Subject: [PATCH 3/5] Handle the SDK's .logprobs event in provider test switches The re-pinned mlx-swift-lm adds MLXServerGenerationEvent.logprobs. Seven test helpers switch exhaustively over events; each treats it like its existing non-content cases (.info / skipped). No assertion changes. Co-Authored-By: Claude Opus 5.5 --- .../Inference/Engine/EngineV2ProductionWiringTests.swift | 2 +- .../Inference/Live/Gemma/GemmaToolCallLiveTests.swift | 2 +- .../Inference/Live/Qwen/Qwen36ProductionCanaryTests.swift | 2 ++ .../Inference/Tools/FlintAnswerStopTests.swift | 1 + .../Inference/Tools/FlintResponseFormatTests.swift | 2 +- .../Inference/Tools/QwenJSONAnswerServingTests.swift | 2 +- .../Tests/ProviderCoreTests/NemotronSuperLocalOutputTests.swift | 1 + 7 files changed, 8 insertions(+), 4 deletions(-) diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2ProductionWiringTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2ProductionWiringTests.swift index 5ba94ab9b2..157337c61e 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2ProductionWiringTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Engine/EngineV2ProductionWiringTests.swift @@ -310,7 +310,7 @@ private func recordServerStream( events.append(.parsed(parsed)) case .info(let info): events.append(.info(prompt: info.promptTokens, completion: info.completionTokens)) - case .toolCall, .toolCallDelta: + case .toolCall, .toolCallDelta, .logprobs: continue } } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Live/Gemma/GemmaToolCallLiveTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Live/Gemma/GemmaToolCallLiveTests.swift index c2510f1f03..1bd15374ec 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Live/Gemma/GemmaToolCallLiveTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Live/Gemma/GemmaToolCallLiveTests.swift @@ -261,7 +261,7 @@ struct GemmaToolCallLiveTests { case .toolCall(let call): calls.append(call) case .content(let text): visible += text case .parsed(let parsed): visible += parsed.content - case .info: break + case .info, .logprobs: break case .toolCallDelta: Issue.record("a named tool_choice call is never streamed") } } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Live/Qwen/Qwen36ProductionCanaryTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Live/Qwen/Qwen36ProductionCanaryTests.swift index 97864fb0de..126037d353 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Live/Qwen/Qwen36ProductionCanaryTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Live/Qwen/Qwen36ProductionCanaryTests.swift @@ -391,6 +391,8 @@ private enum Qwen36ProductionCanary { if let call = delta.completed { result.toolCalls.append(call) } case .info(let info): result.info = info + case .logprobs: + break } } return result diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintAnswerStopTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintAnswerStopTests.swift index 0eb4a9b83f..353513fcdf 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintAnswerStopTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintAnswerStopTests.swift @@ -127,6 +127,7 @@ private struct FlintStreamOutcome { case .toolCall(let call): calls.append(call) case .toolCallDelta(let delta): if let call = delta.completed { calls.append(call) } case .info(let info): self.info = info + case .logprobs: break } } } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintResponseFormatTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintResponseFormatTests.swift index 513ce9b551..7f097a8a3c 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintResponseFormatTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/FlintResponseFormatTests.swift @@ -359,7 +359,7 @@ struct FlintResponseFormatOutputTests { case .content(let text): outcome.content += text case .toolCall: outcome.calls += 1 case .toolCallDelta(let delta): if delta.completed != nil { outcome.calls += 1 } - case .info: break + case .info, .logprobs: break } } } catch { outcome.error = error } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/QwenJSONAnswerServingTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/QwenJSONAnswerServingTests.swift index 2bc354f374..1e9786d650 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Tools/QwenJSONAnswerServingTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Tools/QwenJSONAnswerServingTests.swift @@ -104,7 +104,7 @@ private struct QwenAnswerOutcome { case .content(let text): parser.parse(text).forEach { apply($0) } case .parsed(let parsed): apply(parsed) case .info(let info): self.info = info - case .toolCall, .toolCallDelta: break + case .toolCall, .toolCallDelta, .logprobs: break } } diff --git a/provider-swift/Tests/ProviderCoreTests/NemotronSuperLocalOutputTests.swift b/provider-swift/Tests/ProviderCoreTests/NemotronSuperLocalOutputTests.swift index ff2fe52951..d883ce4a82 100644 --- a/provider-swift/Tests/ProviderCoreTests/NemotronSuperLocalOutputTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/NemotronSuperLocalOutputTests.swift @@ -34,6 +34,7 @@ final class NemotronSuperLocalOutputTests: XCTestCase { return "F:" + call.function.name + String(decoding: try encoder.encode(call.function.arguments), as: UTF8.self) case .info: return "I" + case .logprobs: return "L" case .toolCallDelta: XCTFail("the Super output holds calls until validation; it never streams fragments") return "D" From 2841c6fe59741189d352a6bde934291a53f2aaa4 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:10:42 -0700 Subject: [PATCH 4/5] ci: fresh run for Release Integrity Attempt 2 of run 40756992782 failed test_cli_result_write_failure_preserves_original_error_and_findings: the test inherits the runner's GITHUB_RUN_ATTEMPT=2, so the budget runner reports MANUAL_SCAN_RERUN_DISABLED. Attempt 1 on the same tree passed. No code change. Co-Authored-By: Claude Opus 5.5 From f22f89962ecf0fed9ece36afe98a8bcde2b2c388 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 28 Oct 2026 18:28:40 -0700 Subject: [PATCH 5/5] chore(provider): pin SDK main 2beb401f, the same pin as #1643 SDK main moved from the #369 squash (25bcd63f) to 2beb401f (#368). #368 only adds demandedLatestCheckpointMinimumTokens, which is nil by default and unset by this PR, so behaviour here is unchanged. With the same SDK pin as #1643, the two PRs merge cleanly in either order. Co-Authored-By: Claude Opus 5.5 --- libs/mlx-swift-lm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 25bcd63f18..2beb401f99 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 25bcd63f187b96ecf55796c93e104d20c9852d6a +Subproject commit 2beb401f99db736e2c7128234a2e9d969d750c77