From 09e8ec7fe3166588fe53f387d7caa9f9f54b641b Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:56:47 -0800 Subject: [PATCH 1/4] fix(gemma): adopt opt-in quoted numeric argument parsing --- .github/workflows/provider-tests.yml | 8 ++ changelog.d/gemma-quoted-numeric-arguments.md | 3 + docs/architecture/hardware-support.md | 4 + docs/architecture/inference.md | 4 + docs/developer/build.md | 6 +- docs/developer/test.md | 4 + docs/provider/cli-reference.md | 4 + docs/reference/configuration.md | 8 ++ libs/mlx-swift-lm | 2 +- .../GemmaQuotedArgumentConformanceTests.swift | 117 ++++++++++++++++++ 10 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 changelog.d/gemma-quoted-numeric-arguments.md create mode 100644 provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift diff --git a/.github/workflows/provider-tests.yml b/.github/workflows/provider-tests.yml index a7602b7527..3792427525 100644 --- a/.github/workflows/provider-tests.yml +++ b/.github/workflows/provider-tests.yml @@ -456,6 +456,14 @@ jobs: --output-dir "$RUNNER_TEMP/provider-test-diagnostics" \ --diagnostic-after-seconds 900 --timeout-seconds 1800 \ -- ../scripts/run-provider-tests.sh + - name: Test Gemma o4 conformance switches + if: ${{ !cancelled() && matrix.shard == 1 && steps.test-products.outcome == 'success' }} + working-directory: provider-swift + timeout-minutes: 5 + run: | + for enabled in 0 1; do + env DARKBLOOM_GEMMA_SCHEMA_COERCION="$enabled" ../scripts/run-nested-suite.sh GemmaQuotedArgumentConformanceTests --no-parallel + done - name: Upload provider test diagnostics if: ${{ !cancelled() && steps.provider-unit-tests.outcome != 'skipped' }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/changelog.d/gemma-quoted-numeric-arguments.md b/changelog.d/gemma-quoted-numeric-arguments.md new file mode 100644 index 0000000000..e50394a3b9 --- /dev/null +++ b/changelog.d/gemma-quoted-numeric-arguments.md @@ -0,0 +1,3 @@ +### Gemma quoted numeric tool arguments + +Adopt the opt-in SDK parser fix. `DARKBLOOM_GEMMA_SCHEMA_COERCION=1` enables it for a foreground provider; unset or `0` retains current behavior. Numeric marker strings become numbers at frame close only when the parameter schema unambiguously requests a numeric type. Potentially converted values stay withheld from argument deltas until the completed parse; unsupported or ambiguous schemas preserve their quoted text. The provider still validates strict calls. diff --git a/docs/architecture/hardware-support.md b/docs/architecture/hardware-support.md index 7a7432c946..e7607d58ba 100644 --- a/docs/architecture/hardware-support.md +++ b/docs/architecture/hardware-support.md @@ -1617,3 +1617,7 @@ memory is free. Admission limits and native memory guards are unchanged. See [planned cluster stop ordering](inference.md#planned-cluster-stop-ordering) and `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift` (`ClusterService.stopLocalPart`). + +### Gemma o4 parser qualification + +The [Gemma quoted numeric tool arguments change](inference.md#gemma-quoted-numeric-tool-arguments) operates on CPU text and schema values. Parser tests do not establish full-model numerical, memory, throughput or concurrency qualification. This opt-in does not change hardware admission or model memory allowances. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 927b42b396..b355d2aae4 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -9981,3 +9981,7 @@ Each tensor-parallel rank reserves only the request state it holds (`QwenTensorP Concurrent speculative requests verify their draft windows in one target forward, and each request must emit exactly the tokens it emits alone. MLX picks a quantized matmul kernel from the product's total row count. Up to the device's vector limit (`get_qmv_batch_limit`: 12 rows at Qwen27's widths on the M3 Ultra, 13 on the M5 Max) a product runs `qmv_wide`; at or beyond it, split-K QMM, with a different reduction order. One request's three-column window is 3 rows; four requests' windows in one product are 12, so on the M3 they took the other kernel. In an installed run before this change, 5 of 30 concurrent requests, all in waves with four-request cohorts, chose a different near-tie token. `QwenTensorParallelTargetWindow.beginBatch` therefore runs the batched verify forward under `Qwen35BatchDecodeScope.verifyRows`. Every projection computes each request's `[1, S, H]` rows as that request's own window would, the row-parallel projections concatenate those partials into one collective per projection (two per dense layer), and the LM head follows the same rule. Below the vector limit, `qmv_wide` (and `qmv` before Apple GPU family 15) computes each vector the same way at any vector count: its tile size only decides which vectors share a weight read. So requests share a quantized call while their windows' total rows stay below the limit (`Qwen35QuantizedVectorLimit`, which mirrors `get_qmv_batch_limit` for the device MLX reads, including `MLX_METAL_GPU_ARCH`). At Qwen27's widths with depth 3 that is two four-column windows per call on the M3 Ultra and three on the M5 Max. `qmv_wide` still reads the weights once per tile of up to five vectors, so sharing saves launches and some weight reads rather than whole passes; the installed round profile (`darkbloom-tp-mtp-profile-v1`, c35) still shows about 44 ms of verify time per additional row. Only exact base `QuantizedLinear` modules in affine mode on the GPU share calls; the CPU, other quantizers, overridden forwards and MLX's 64/128-wide quad kernel keep one call per row. `QwenTensorParallelBatchMTPWindowTests.sharedWindowCallsKeepEveryRowsQuantizedArithmetic` checks the shared calls byte for byte against each row's own call at Qwen27's projection shapes. Attention and the recurrent layers were already per-request, so only the projection row count changed between alone and together. `QwenTensorParallelBatchMTPWindowTests.everyRectangleRowEqualsItsOwnSingleRequestWindowBitwise` compares every row of eight-request rectangles with its own window, byte for byte, on both ranks. The agreement carries `verify-rows=single-window-v1`. Where it measured faster and byte-equal, a cohort's verify rows go through one kernel instead of MLX's own calls (`Qwen35WideQuantizedKernel`, a port of `qmv_wide_impl`): each vector keeps `qmv_wide`'s lanes, sub-chunk sums and shuffle ladder, but up to eight vectors (two four-column windows) share a weight read instead of five, and a thread may carry two output rows so each input value is converted once for both. The layout follows the GPU family (`Qwen35WideQuantizedKernel.layout`). On the M5 Max (family 17), one row a thread for bfloat16 and float32 inputs, up to 20% faster than MLX's calls. On the M3 Ultra (family 15), two rows a thread for the row-parallel float32 partials, 1.5-2.1x faster, while its bfloat16 projections keep MLX's calls, which measured as fast or faster; one row a thread was up to 1.6x slower there. Other families keep MLX's calls. The figures come from `QwenTensorParallelVerifyBenchTests` (opt-in) on each Mac with Qwen27's shard shapes, and `QwenTensorParallelBatchMTPWindowTests.wideKernelRowsEqualEachRowsOwnWindowCall` checks both layouts byte for byte against each row's own call on whichever GPU runs it. + +## Gemma quoted numeric tool arguments + +The SDK parser behind `DARKBLOOM_GEMMA_SCHEMA_COERCION` is adopted through the `libs/mlx-swift-lm` gitlink. Numeric marker strings become numbers at frame close only when the parameter schema unambiguously requests a numeric type. Potentially converted values stay withheld from argument deltas until the completed parse; unsupported or ambiguous schemas preserve their quoted text. The provider still validates strict calls. See the [process switch](../reference/configuration.md#gemma-o4-conformance). Source: `libs/mlx-swift-lm/Libraries/MLXLMCommon/Tool/Parsers/GemmaFunctionParser.swift` (`GemmaFunctionParser`). diff --git a/docs/developer/build.md b/docs/developer/build.md index c7c4b6f6fa..94b708f801 100644 --- a/docs/developer/build.md +++ b/docs/developer/build.md @@ -1,6 +1,6 @@ # Build The Provider And Landing -> Last updated: 2026-11-12 +> Last updated: 2026-11-13 Build the provider, its source-matched native resources, and the independent landing site from this repository. Backend, sidecar, console and admin builds @@ -1134,3 +1134,7 @@ Qwen27 TP batch prefix capture/restore changes the Runtime target only; it reuses the pinned SDK owned-state APIs. Rebuild the worker and planner together because the same complete LOAD budget prices the additional snapshot banks. See [warm-prefix validation](test.md#qwen27-tp-warm-prefix-checks). + +### Gemma o4 dependency adoption + +The Gemma quoted numeric tool arguments conformance suite consumes the exact `libs/mlx-swift-lm` gitlink, including its parser tests. Use the normal recursive dependency checkout and test-product build; the [isolated conformance runs](test.md#gemma-o4-conformance) reuse those products without a second build. Native MLX and nested core pins are unchanged. diff --git a/docs/developer/test.md b/docs/developer/test.md index 49673945be..6a1ce91e22 100644 --- a/docs/developer/test.md +++ b/docs/developer/test.md @@ -3671,3 +3671,7 @@ one-line explanation and that request lengths still come from every build; read and the router's build-keyed setup. `swift test --filter DistributedAutomaticBatchPlannerTests` and `--filter ClusterObservabilityTests` from `provider-swift` cover replacement calibration and the recorded builds. + +### Gemma o4 conformance + +`GemmaQuotedArgumentConformanceTests` exercises the adopted SDK through provider-facing types without loading a model. CI reuses the compiled test products and runs this suite in separate processes with `DARKBLOOM_GEMMA_SCHEMA_COERCION=0` and `=1`; the ordinary suite retains the default-off check. In an authorized CPU test lane, from `provider-swift`, use `DARKBLOOM_GEMMA_SCHEMA_COERCION=1 ../scripts/run-nested-suite.sh GemmaQuotedArgumentConformanceTests --no-parallel` after building the exact pinned composition. GPU qualification remains separate. diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index 656d56b148..8790bf7cbb 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -4420,3 +4420,7 @@ Source: `provider-swift/Sources/darkbloom/ClusterServiceCommand.swift` for the bounds and process custody rules. Qwen3.8 27B automatic cluster capacity changes keep the current tensor split and native request execution path. Widening occurs only when the complete reservation fits that split; otherwise the current capacity remains available. No additional command or user setting is required. Implementation: `DistributedAutomaticBatchPlanner` and `ClusterPlacementFlow` in `provider-swift/Sources/ProviderCore/Inference/Distributed/`. + +### Gemma o4 parser switch + +For foreground qualification, set `DARKBLOOM_GEMMA_SCHEMA_COERCION` before starting the process. The [configuration reference](../reference/configuration.md#gemma-o4-conformance) defines activation and rollback; the daemon LaunchAgent does not inherit this switch. diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 129435dba3..3fdbc547d7 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -1847,3 +1847,11 @@ Sources: `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/C The wizard’s optional local stopDrain token is saved with stopped intent and retained after a local timeout. Leases preserve the peer’s prior intent until the local supervisor retires its owned part and outstanding lease. The token is not a wire or user-facing configuration field; older records decode without it. A new serve is refused while it remains, and a model change retries the shared stop first. Every write of the wizard's record (`~/.darkbloom/cluster-setup/wizard.json`) takes the `wizard.json.lock` flock. When another writer holds that lock, the write waits up to 2 seconds for it (`ClusterSetupStore.recordLockWaitSeconds`). After 2 seconds the write fails with "Configuration or native device lease is currently held". The cluster service writes the record while it holds its own service lock, so it tries once and writes again on its next supervision cycle. Source: `provider-swift/Sources/ProviderCore/Inference/Distributed/Console/ClusterSetupWizardStore.swift` (`ClusterSetupStore.updateRecord`). + +### Gemma o4 conformance + +| Variable | Values / type | Default | Read in | Effect | +|---|---|---|---|---| +| `DARKBLOOM_GEMMA_SCHEMA_COERCION` | exact `1` enables | unset (off); `0` keeps legacy behavior | `libs/mlx-swift-lm/Libraries/MLXLMCommon/Tool/Parsers/GemmaFunctionParser.swift` (`GemmaFunctionParser`) | Opts in to Gemma quoted numeric tool arguments. Read once per process. | + +Set this variable before starting an isolated foreground provider. It is not forwarded by the LaunchAgent allow-list. Unset it or use `0` and restart the process to roll back. See the [parser behavior](../architecture/inference.md#gemma-quoted-numeric-tool-arguments). diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 859f641529..61a532d5d1 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 859f641529adc2f8fd011b8df295ee214d673060 +Subproject commit 61a532d5d1bd4cd6f571e9da687c0101bece45b3 diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift new file mode 100644 index 0000000000..870f013171 --- /dev/null +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift @@ -0,0 +1,117 @@ +// Copyright © 2026 Eigen Labs. + +import Foundation +import MLXLMCommon +import MLXLMServer +import Testing + +@testable import ProviderCore + +@Suite("Gemma quoted numeric argument conformance") +struct GemmaQuotedArgumentConformanceTests { + private let enabled = ProcessInfo.processInfo.environment["DARKBLOOM_GEMMA_SCHEMA_COERCION"] == "1" + + @Test("strict validation sees the completed numeric conversion", arguments: [false, true]) + func validatesCompletedCall(stream: Bool) throws { + let (prepared, handler) = try setup(schema: #"{"type":"integer"}"#, stream: stream) + let frame = #"<|tool_call>call:count_items{count:<|"|>3<|"|>}"# + func streamedCalls() throws -> [ToolCall] { + var router = NativeToolStreamRouter(handler: handler, requiresToolCall: false, nativePrefix: nil, + streamedCalls: prepared) + var events: [MLXServerGenerationEvent] = [] + for character in frame { events += try router.process(String(character)) } + events += try router.finishText() + events += try router.finishToolCalls(truncated: false) + let deltas = events.compactMap { if case .toolCallDelta(let delta) = $0 { delta } else { nil } } + let completed = try #require(deltas.last?.completed) + let json = Data(deltas.map(\.arguments).joined().utf8) + #expect(try JSONDecoder().decode([String: MLXLMCommon.JSONValue].self, from: json) + == completed.function.arguments) + return router.completedToolCalls + } + if stream && !enabled { + #expect(throws: MultiModelBatchSchedulerEngineError.toolChoiceViolation(ToolNoncomplianceCheck.schemaViolation)) { + _ = try streamedCalls() + } + return + } + let calls: [ToolCall] + if stream { + calls = try streamedCalls() + } else { + _ = handler.processChunk(frame) + calls = handler.finish() + } + #expect(calls.count == 1) + #expect(calls.first?.function.arguments["count"] == (enabled ? .int(3) : .string("3"))) + if enabled { + try ToolConstraintValidation.validate(calls, prepared: prepared) + } else { + #expect(throws: MultiModelBatchSchedulerEngineError.toolChoiceViolation(ToolNoncomplianceCheck.schemaViolation)) { + try ToolConstraintValidation.validate(calls, prepared: prepared) + } + } + } + + @Test("render types do not erase caller-admitted strings", arguments: [false, true]) + func unionStrings(stream: Bool) throws { + for schema in [ + #"{"anyOf":[{"type":"integer"},{"type":"string"}]}"#, + #"{"anyOf":[{"type":"string"},{"type":"integer"}]}"#, + #"{"type":["integer","string"]}"#, + #"{"type":["string","integer"]}"#, + ] { + let (prepared, handler) = try setup(schema: schema, stream: stream) + let frame = #"<|tool_call>call:count_items{count:<|"|>003<|"|>}"# + let calls: [ToolCall] + if stream { + var router = NativeToolStreamRouter(handler: handler, requiresToolCall: false, nativePrefix: nil, + streamedCalls: prepared) + for character in frame { _ = try router.process(String(character)) } + _ = try router.finishText() + _ = try router.finishToolCalls(truncated: false) + calls = router.completedToolCalls + } else { + _ = handler.processChunk(frame) + calls = handler.finish() + } + #expect(calls.count == 1) + #expect(calls.first?.function.arguments["count"] == .string("003")) + try ToolConstraintValidation.validate(calls, prepared: prepared) + } + } + + @Test("invalid numeric text fails before completed-call exposure") + func rejectsFractionBeforeResponseStarts() throws { + let (prepared, handler) = try setup(schema: #"{"type":"integer"}"#, stream: true) + var router = NativeToolStreamRouter(handler: handler, requiresToolCall: false, nativePrefix: nil, + streamedCalls: prepared) + // Deliberately leave responseStarted false: post-start leniency is a separate policy. + let before = try router.process(#"<|tool_call>call:count_items{count:<|"|>3.5<|"|>}"#) + for event in before { + if case .toolCallDelta(let delta) = event { + #expect(delta.completed == nil) + if enabled { #expect(delta.arguments.isEmpty) } + } + } + #expect(throws: MultiModelBatchSchedulerEngineError.toolChoiceViolation(ToolNoncomplianceCheck.schemaViolation)) { + _ = try router.process("") + } + #expect(router.completedToolCalls.isEmpty) + } + + private func setup(schema: String, stream: Bool) throws + -> (ToolChoicePromptPolicy.Prepared, BatchedToolStreamHandler) { + let body = Data(""" + {"model":"gemma-4-26b-qat-4bit","messages":[{"role":"user","content":"Count it."}],"stream":true, + "tools":[{"type":"function","function":{"name":"count_items","strict":true,"parameters":{ + "type":"object","properties":{"count":\(schema)},"required":["count"],"additionalProperties":false}}}]} + """.utf8) + var request = try ProviderLoop.decodeOpenAIRequest(body) + request.streamToolCallDeltas = stream + let prepared = try ToolChoicePromptPolicy.prepare(request, modelType: "gemma4") + let handler = try #require(try ToolStreamPreparation.makeHandler( + request: request, prepared: prepared, modelType: "gemma4", streamToolCalls: stream)) + return (prepared, handler) + } +} From aaee9e53ce0c6d3d9d44fe6b7f2589ecd4dbfc86 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:58:38 -0800 Subject: [PATCH 2/4] test(ci): inventory isolated Gemma numeric argument runs --- .github/workflows/provider-tests.yml | 4 ++-- scripts/test-provider-ci-workflow.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/provider-tests.yml b/.github/workflows/provider-tests.yml index 3792427525..bbabc590d3 100644 --- a/.github/workflows/provider-tests.yml +++ b/.github/workflows/provider-tests.yml @@ -456,8 +456,8 @@ jobs: --output-dir "$RUNNER_TEMP/provider-test-diagnostics" \ --diagnostic-after-seconds 900 --timeout-seconds 1800 \ -- ../scripts/run-provider-tests.sh - - name: Test Gemma o4 conformance switches - if: ${{ !cancelled() && matrix.shard == 1 && steps.test-products.outcome == 'success' }} + - name: Test Gemma quoted numeric argument conformance switches + if: ${{ !cancelled() && matrix.shard == strategy.job-total && steps.test-products.outcome == 'success' }} working-directory: provider-swift timeout-minutes: 5 run: | diff --git a/scripts/test-provider-ci-workflow.py b/scripts/test-provider-ci-workflow.py index f3aa1b4d0f..60dc1a357d 100644 --- a/scripts/test-provider-ci-workflow.py +++ b/scripts/test-provider-ci-workflow.py @@ -480,6 +480,9 @@ def test_provider_entrypoint_and_resource_installer_checks_are_retained(self): MIMO_HTTP_PREPARE, MIMO_PROVIDER_PREPARE, PROVIDER_TEST_COMMAND, + "for enabled in 0 1; do\n" + ' env DARKBLOOM_GEMMA_SCHEMA_COERCION="$enabled" ../scripts/run-nested-suite.sh GemmaQuotedArgumentConformanceTests --no-parallel\n' + "done", "python3 scripts/test-desktop-api.py provider-swift/.build/debug/darkbloom", *MIMO_NATIVE_COMMANDS.values(), 'python3 scripts/prepare-mimo-audio-fixtures.py --cache /private/tmp/dinf-ci/mimo-audio-source --output "$RUNNER_TEMP/mimo-audio-fixtures" --github-env "$GITHUB_ENV"', From 6bf57226f968ed361be2d9d5a279f0bac4866dee Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:10:51 -0800 Subject: [PATCH 3/4] fix(gemma): adopt conservative nested union coercion guard --- libs/mlx-swift-lm | 2 +- .../Streaming/GemmaQuotedArgumentConformanceTests.swift | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 61a532d5d1..6015044b9f 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 61a532d5d1bd4cd6f571e9da687c0101bece45b3 +Subproject commit 6015044b9f6925ec38b99ee9b710c4ced0090d5b diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift index 870f013171..6bc2c48be6 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift @@ -60,6 +60,8 @@ struct GemmaQuotedArgumentConformanceTests { #"{"anyOf":[{"type":"string"},{"type":"integer"}]}"#, #"{"type":["integer","string"]}"#, #"{"type":["string","integer"]}"#, + #"{"anyOf":[{"type":["integer","string"]},{"type":"null"}]}"#, + #"{"allOf":[{"anyOf":[{"type":"integer"},{"type":"string"}]}]}"#, ] { let (prepared, handler) = try setup(schema: schema, stream: stream) let frame = #"<|tool_call>call:count_items{count:<|"|>003<|"|>}"# From d422ea479266ae54b61531ab24cbf7d1104c9339 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:36:37 -0800 Subject: [PATCH 4/4] test(gemma): carry caller schemas into conformance validation --- .../Streaming/GemmaQuotedArgumentConformanceTests.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift index 6bc2c48be6..77c8e83567 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Streaming/GemmaQuotedArgumentConformanceTests.swift @@ -109,9 +109,13 @@ struct GemmaQuotedArgumentConformanceTests { "tools":[{"type":"function","function":{"name":"count_items","strict":true,"parameters":{ "type":"object","properties":{"count":\(schema)},"required":["count"],"additionalProperties":false}}}]} """.utf8) - var request = try ProviderLoop.decodeOpenAIRequest(body) + let inbound = try ProviderLoop.decodeInboundChatRequest(body) + var request = inbound.request request.streamToolCallDeltas = stream - let prepared = try ToolChoicePromptPolicy.prepare(request, modelType: "gemma4") + var prepared = try ToolChoicePromptPolicy.prepare(request, modelType: "gemma4") + // Mirror the scheduler: validate against caller declarations, not the + // normalized render types passed to the Gemma parser/template. + prepared.declaredTools = try #require(inbound.extensions.templateControls.declaredTools) let handler = try #require(try ToolStreamPreparation.makeHandler( request: request, prepared: prepared, modelType: "gemma4", streamToolCalls: stream)) return (prepared, handler)