bots-garden/razorbillpublic Fork
⑂ 1f0e95f
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

Reasoning can be hidden; streaming of reasoning verified (#37)

show_reasoning in the configuration's defaults or locked blocks (server
wide or per model) and include_reasoning per request decide whether the
model's reasoning is sent. When hidden the model still thinks, nothing of
it reaches the client (plain or streamed), and reasoning_tokens still
counts it. A lock cannot be overridden by clients.

Reasoning deltas are checked on the Mac with a real Qwen3 model: token by
token, before the answer, absent when hidden.

Tests: Linux 123, Mac 135.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
k33g committed 2026-11-25T13:58:23+01:00 Browse files
1f0e95f parent: 7cdd37d
modified .memory/handoffs/2026-11-25-v0-2-server-foundation.md +3 -1
@@ -6,7 +6,9 @@ Update after #34: `ModelManager`, `/v1/models` done (Linux 89, Mac 94).
66 Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests).
77 Update after #36: streaming done (Linux 113, Mac 122).
88 Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were
9-made by Claude on a plain "go": mention them to the user if reasoning comes up.
9+made by Claude on a plain "go": mention them to the user if reasoning comes up. The user then asked
10+for a way to hide it (`show_reasoning` / `include_reasoning`, done) and for it to stream (it did;
11+now verified on the Mac).
1012 Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP
1113 server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket
1214 closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task
@@ -6,7 +6,9 @@ Update after #34: `ModelManager`, `/v1/models` done (Linux 89, Mac 94).
6 Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests).6 Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests).
7 Update after #36: streaming done (Linux 113, Mac 122).7 Update after #36: streaming done (Linux 113, Mac 122).
8 Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were8 Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were
9-made by Claude on a plain "go": mention them to the user if reasoning comes up.9+made by Claude on a plain "go": mention them to the user if reasoning comes up. The user then asked
10+for a way to hide it (`show_reasoning` / `include_reasoning`, done) and for it to stream (it did;
11+now verified on the Mac).
10 Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP12 Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP
11 server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket13 server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket
12 closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task14 closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task
modified .memory/history.md +6 -0
@@ -183,3 +183,9 @@
183183 protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking
184184 (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate
185185 PASS (run #12). #37 closed (`needs-decision` label removed).
186+- #37 follow-up asked by the user: option to hide the reasoning + reasoning must stream. Added
187+ `show_reasoning` (GenerationSettings/Overrides, config defaults/locked, imposed when locked) and
188+ the request field `include_reasoning`; hiding happens in `CompletionStream` (counted, not passed
189+ on), shared by plain and streamed answers through `ChatCompletionRoute.generate`. Streaming of
190+ reasoning already existed; now verified with real Qwen3 on the Mac. Linux 123, Mac 135, gate PASS
191+ (run #13). Comment #2 on #37.
@@ -183,3 +183,9 @@
183 protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking183 protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking
184 (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate184 (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate
185 PASS (run #12). #37 closed (`needs-decision` label removed).185 PASS (run #12). #37 closed (`needs-decision` label removed).
186+- #37 follow-up asked by the user: option to hide the reasoning + reasoning must stream. Added
187+ `show_reasoning` (GenerationSettings/Overrides, config defaults/locked, imposed when locked) and
188+ the request field `include_reasoning`; hiding happens in `CompletionStream` (counted, not passed
189+ on), shared by plain and streamed answers through `ChatCompletionRoute.generate`. Streaming of
190+ reasoning already existed; now verified with real Qwen3 on the Mac. Linux 123, Mac 135, gate PASS
191+ (run #13). Comment #2 on #37.
modified .memory/summary.md +4 -2
@@ -59,7 +59,9 @@ server side (`StopSequenceFilter` in Core); the chat route closes the connection
5959 stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive`
6060 comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request
6161 `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default;
62-budget only via the `thinking_budget` extension field; engine errors caused by a request setting
62+budget only via the `thinking_budget` extension field; hidden with `show_reasoning: false`
63+(config `defaults`/`locked`) or `include_reasoning: false` (request) — the model still thinks and
64+`reasoning_tokens` still counts; engine errors caused by a request setting
6365 adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike.
6466
6567 ## Architecture of v0.1 (agent, removed on the v0.2 branch)
@@ -151,7 +153,7 @@ razorbill`, `host.sh run . rzb <args>` (no TTY: `rzb run` only); host-runner tes
151153 (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`).
152154 Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped
153155 signatures as `) throws -> T {` or on one line (the two tools fight over brace placement).
154-Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 120, Mac 131 (incl. `ChatSmokeTests`: real
156+Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 123, Mac 135 (incl. `ChatSmokeTests`: real
155157 Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache).
156158 Server tests start the real server on a random port (`HummingbirdTesting` `.live`).
157159
@@ -59,7 +59,9 @@ server side (`StopSequenceFilter` in Core); the chat route closes the connection
59 stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive`59 stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive`
60 comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request60 comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request
61 `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default;61 `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default;
62-budget only via the `thinking_budget` extension field; engine errors caused by a request setting62+budget only via the `thinking_budget` extension field; hidden with `show_reasoning: false`
63+(config `defaults`/`locked`) or `include_reasoning: false` (request) — the model still thinks and
64+`reasoning_tokens` still counts; engine errors caused by a request setting
63 adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike.65 adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike.
64 66
65 ## Architecture of v0.1 (agent, removed on the v0.2 branch)67 ## Architecture of v0.1 (agent, removed on the v0.2 branch)
@@ -151,7 +153,7 @@ razorbill`, `host.sh run . rzb <args>` (no TTY: `rzb run` only); host-runner tes
151 (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`).153 (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`).
152 Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped154 Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped
153 signatures as `) throws -> T {` or on one line (the two tools fight over brace placement).155 signatures as `) throws -> T {` or on one line (the two tools fight over brace placement).
154-Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 120, Mac 131 (incl. `ChatSmokeTests`: real156+Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 123, Mac 135 (incl. `ChatSmokeTests`: real
155 Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache).157 Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache).
156 Server tests start the real server on a random port (`HummingbirdTesting` `.live`).158 Server tests start the real server on a random port (`HummingbirdTesting` `.live`).
157 159
modified .quality/history.jsonl +1 -0
@@ -10,3 +10,4 @@
1010 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"}
1111 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"}
1212 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"}
13+{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "7cdd37d", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 338, "cyclo": 401, "fields": 770, "funcs": 390, "lcom": 77, "lines": 7106, "loc": 5580}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 13, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:55:33Z"}
@@ -10,3 +10,4 @@
10 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"}10 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"}
11 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"}11 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"}
12 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"}12 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"}
13+{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "7cdd37d", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 338, "cyclo": 401, "fields": 770, "funcs": 390, "lcom": 77, "lines": 7106, "loc": 5580}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 13, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:55:33Z"}
added .quality/report-20261125T125533Z.md +73 -0
new file mode 100644
@@ -0,0 +1,73 @@
1+# Quality report — 2026-11-25T12:55:33Z
2+
3+- **Gate**: ✅ **PASS**
4+- **Commit**: `7cdd37d` on `feature/v0.2-openai-server`
5+- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)
6+- **swiftlint**: 0.65.1 (run directly, merged into lint issues)
7+- **Run**: #13 (previous: 2026-11-25T12:48:22Z)
8+
9+## Lint issues (`qlty check`)
10+
11+_none_
12+
13+### Top rules
14+
15+_none_
16+
17+### Most affected files
18+
19+_none_
20+
21+## Code smells (`qlty smells`)
22+
23+Total: **0** (vs previous: ±0)
24+
25+_none_
26+
27+## Metrics (`qlty metrics`)
28+
29+| metric | total | vs previous |
30+|---|---|---|
31+| funcs | 390 | +6 |
32+| classes | 171 | ±0 |
33+| fields | 770 | +12 |
34+| cyclo | 401 | +6 |
35+| complex | 338 | +9 |
36+| lcom | 77 | +1 |
37+| lines | 7106 | +107 |
38+| loc | 5580 | +92 |
39+
40+### Most complex files
41+
42+| file | complex | cyclo | loc |
43+|---|---|---|---|
44+| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 |
45+| tools/host-runner/host_runner.py | 22 | 22 | 141 |
46+| Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 |
47+| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 |
48+| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 |
49+| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 |
50+| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 |
51+| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 |
52+| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 |
53+| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 |
54+| Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 |
55+| Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 |
56+| Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 |
57+| Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 |
58+| Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 |
59+
60+## Trend
61+
62+| run | timestamp | error | warning | smells | complex | gate |
63+|---|---|---|---|---|---|---|
64+| 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS |
65+| 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS |
66+| 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS |
67+| 7 | 2026-11-25T12:28:23Z | 0 | 0 | 1 | 311 | FAIL |
68+| 8 | 2026-11-25T12:28:48Z | 0 | 1 | 0 | 296 | FAIL |
69+| 9 | 2026-11-25T12:29:03Z | 0 | 0 | 0 | 296 | PASS |
70+| 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS |
71+| 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS |
72+| 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS |
73+| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS |
new file mode 100644
@@ -0,0 +1,73 @@
1+# Quality report — 2026-11-25T12:55:33Z
2+
3+- **Gate**: ✅ **PASS**
4+- **Commit**: `7cdd37d` on `feature/v0.2-openai-server`
5+- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)
6+- **swiftlint**: 0.65.1 (run directly, merged into lint issues)
7+- **Run**: #13 (previous: 2026-11-25T12:48:22Z)
8+
9+## Lint issues (`qlty check`)
10+
11+_none_
12+
13+### Top rules
14+
15+_none_
16+
17+### Most affected files
18+
19+_none_
20+
21+## Code smells (`qlty smells`)
22+
23+Total: **0** (vs previous: ±0)
24+
25+_none_
26+
27+## Metrics (`qlty metrics`)
28+
29+| metric | total | vs previous |
30+|---|---|---|
31+| funcs | 390 | +6 |
32+| classes | 171 | ±0 |
33+| fields | 770 | +12 |
34+| cyclo | 401 | +6 |
35+| complex | 338 | +9 |
36+| lcom | 77 | +1 |
37+| lines | 7106 | +107 |
38+| loc | 5580 | +92 |
39+
40+### Most complex files
41+
42+| file | complex | cyclo | loc |
43+|---|---|---|---|
44+| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 |
45+| tools/host-runner/host_runner.py | 22 | 22 | 141 |
46+| Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 |
47+| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 |
48+| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 |
49+| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 |
50+| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 |
51+| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 |
52+| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 |
53+| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 |
54+| Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 |
55+| Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 |
56+| Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 |
57+| Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 |
58+| Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 |
59+
60+## Trend
61+
62+| run | timestamp | error | warning | smells | complex | gate |
63+|---|---|---|---|---|---|---|
64+| 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS |
65+| 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS |
66+| 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS |
67+| 7 | 2026-11-25T12:28:23Z | 0 | 0 | 1 | 311 | FAIL |
68+| 8 | 2026-11-25T12:28:48Z | 0 | 1 | 0 | 296 | FAIL |
69+| 9 | 2026-11-25T12:29:03Z | 0 | 0 | 0 | 296 | PASS |
70+| 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS |
71+| 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS |
72+| 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS |
73+| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS |
modified .quality/report-latest.md +17 -17
@@ -1,10 +1,10 @@
1-# Quality report — 2026-11-25T12:48:22Z
1+# Quality report — 2026-11-25T12:55:33Z
22
33 - **Gate**: ✅ **PASS**
4-- **Commit**: `d8981f3` on `feature/v0.2-openai-server`
4+- **Commit**: `7cdd37d` on `feature/v0.2-openai-server`
55 - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)
66 - **swiftlint**: 0.65.1 (run directly, merged into lint issues)
7-- **Run**: #12 (previous: 2026-11-25T12:38:59Z)
7+- **Run**: #13 (previous: 2026-11-25T12:48:22Z)
88
99 ## Lint issues (`qlty check`)
1010
@@ -28,31 +28,31 @@ _none_
2828
2929 | metric | total | vs previous |
3030 |---|---|---|
31-| funcs | 384 | +12 |
32-| classes | 171 | +2 |
33-| fields | 758 | +33 |
34-| cyclo | 395 | +5 |
35-| complex | 329 | +4 |
36-| lcom | 76 | +1 |
37-| lines | 6999 | +228 |
38-| loc | 5488 | +189 |
31+| funcs | 390 | +6 |
32+| classes | 171 | ±0 |
33+| fields | 770 | +12 |
34+| cyclo | 401 | +6 |
35+| complex | 338 | +9 |
36+| lcom | 77 | +1 |
37+| lines | 7106 | +107 |
38+| loc | 5580 | +92 |
3939
4040 ### Most complex files
4141
4242 | file | complex | cyclo | loc |
4343 |---|---|---|---|
44-| Sources/RazorbillServer/Chat/CompletionStream.swift | 25 | 16 | 106 |
44+| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 |
4545 | tools/host-runner/host_runner.py | 22 | 22 | 141 |
4646 | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 |
47-| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 214 |
47+| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 |
4848 | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 |
4949 | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 |
50-| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 264 |
50+| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 |
5151 | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 |
52-| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 132 |
52+| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 |
53+| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 |
5354 | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 |
5455 | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 |
55-| Sources/RazorbillCore/Config/GenerationOverrides.swift | 10 | 11 | 47 |
5656 | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 |
5757 | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 |
5858 | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 |
@@ -61,7 +61,6 @@ _none_
6161
6262 | run | timestamp | error | warning | smells | complex | gate |
6363 |---|---|---|---|---|---|---|
64-| 3 | 2026-11-24T05:57:47Z | 0 | 0 | 0 | 358 | PASS |
6564 | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS |
6665 | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS |
6766 | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS |
@@ -71,3 +70,4 @@ _none_
7170 | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS |
7271 | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS |
7372 | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS |
73+| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS |
@@ -1,10 +1,10 @@
1-# Quality report — 2026-11-25T12:48:22Z1+# Quality report — 2026-11-25T12:55:33Z
2 2
3 - **Gate**: ✅ **PASS**3 - **Gate**: ✅ **PASS**
4-- **Commit**: `d8981f3` on `feature/v0.2-openai-server`4+- **Commit**: `7cdd37d` on `feature/v0.2-openai-server`
5 - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)5 - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)
6 - **swiftlint**: 0.65.1 (run directly, merged into lint issues)6 - **swiftlint**: 0.65.1 (run directly, merged into lint issues)
7-- **Run**: #12 (previous: 2026-11-25T12:38:59Z)7+- **Run**: #13 (previous: 2026-11-25T12:48:22Z)
8 8
9 ## Lint issues (`qlty check`)9 ## Lint issues (`qlty check`)
10 10
@@ -28,31 +28,31 @@ _none_
28 28
29 | metric | total | vs previous |29 | metric | total | vs previous |
30 |---|---|---|30 |---|---|---|
31-| funcs | 384 | +12 |31+| funcs | 390 | +6 |
32-| classes | 171 | +2 |32+| classes | 171 | ±0 |
33-| fields | 758 | +33 |33+| fields | 770 | +12 |
34-| cyclo | 395 | +5 |34+| cyclo | 401 | +6 |
35-| complex | 329 | +4 |35+| complex | 338 | +9 |
36-| lcom | 76 | +1 |36+| lcom | 77 | +1 |
37-| lines | 6999 | +228 |37+| lines | 7106 | +107 |
38-| loc | 5488 | +189 |38+| loc | 5580 | +92 |
39 39
40 ### Most complex files40 ### Most complex files
41 41
42 | file | complex | cyclo | loc |42 | file | complex | cyclo | loc |
43 |---|---|---|---|43 |---|---|---|---|
44-| Sources/RazorbillServer/Chat/CompletionStream.swift | 25 | 16 | 106 |44+| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 |
45 | tools/host-runner/host_runner.py | 22 | 22 | 141 |45 | tools/host-runner/host_runner.py | 22 | 22 | 141 |
46 | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 |46 | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 |
47-| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 214 |47+| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 |
48 | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 |48 | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 |
49 | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 |49 | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 |
50-| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 264 |50+| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 |
51 | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 |51 | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 |
52-| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 132 |52+| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 |
53+| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 |
53 | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 |54 | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 |
54 | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 |55 | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 |
55-| Sources/RazorbillCore/Config/GenerationOverrides.swift | 10 | 11 | 47 |
56 | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 |56 | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 |
57 | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 |57 | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 |
58 | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 |58 | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 |
@@ -61,7 +61,6 @@ _none_
61 61
62 | run | timestamp | error | warning | smells | complex | gate |62 | run | timestamp | error | warning | smells | complex | gate |
63 |---|---|---|---|---|---|---|63 |---|---|---|---|---|---|---|
64-| 3 | 2026-11-24T05:57:47Z | 0 | 0 | 0 | 358 | PASS |
65 | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS |64 | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS |
66 | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS |65 | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS |
67 | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS |66 | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS |
@@ -71,3 +70,4 @@ _none_
71 | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS |70 | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS |
72 | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS |71 | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS |
73 | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS |72 | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS |
73+| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS |
modified .tickets/issues/0037-reasoning-models-over-the-api-reasoning-content.yaml +11 -2
@@ -6,7 +6,7 @@ author:
66 name: k33g
77 email: ph.charriere@gmail.com
88 createdAt: 2026-11-24T21:17:08.000Z
9-updatedAt: 2026-11-25T12:55:00.000Z
9+updatedAt: 2026-11-25T13:10:00.000Z
1010 labels:
1111 - "kind::feature"
1212 - "area::engine"
@@ -94,4 +94,13 @@ comments:
9494 - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0.
9595 Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed).
9696 Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS.
97-
97+ - id: 2
98+ author:
99+ name: k33g
100+ email: ph.charriere@gmail.com
101+ createdAt: 2026-11-25T13:10:00.000Z
102+ body: |
103+ User's follow-up (2026-11-25): an option to hide the reasoning, and reasoning must be streamed.
104+ - Hide: `show_reasoning` (bool, default true) in the configuration's `defaults` / `locked` (server-wide or per model), and `include_reasoning` per request (OpenRouter's convention). `locked: { show_reasoning: false }` cannot be overridden by clients. When hidden, the model still thinks; nothing of it is sent (message or stream), and `reasoning_tokens` still counts it.
105+ - Streaming: reasoning was already sent as `delta.reasoning_content`; now also checked on the Mac with real Qwen3 (reasoning deltas token by token, all before the answer; none when hidden).
106+ Tests: +3 server, +1 loader, +1 Mac smoke. Linux 123, Mac 135, gate PASS.
@@ -6,7 +6,7 @@ author:
6 name: k33g6 name: k33g
7 email: ph.charriere@gmail.com7 email: ph.charriere@gmail.com
8 createdAt: 2026-11-24T21:17:08.000Z8 createdAt: 2026-11-24T21:17:08.000Z
9-updatedAt: 2026-11-25T12:55:00.000Z9+updatedAt: 2026-11-25T13:10:00.000Z
10 labels:10 labels:
11 - "kind::feature"11 - "kind::feature"
12 - "area::engine"12 - "area::engine"
@@ -94,4 +94,13 @@ comments:
94 - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0.94 - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0.
95 Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed).95 Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed).
96 Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS.96 Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS.
97-97+ - id: 2
98+ author:
99+ name: k33g
100+ email: ph.charriere@gmail.com
101+ createdAt: 2026-11-25T13:10:00.000Z
102+ body: |
103+ User's follow-up (2026-11-25): an option to hide the reasoning, and reasoning must be streamed.
104+ - Hide: `show_reasoning` (bool, default true) in the configuration's `defaults` / `locked` (server-wide or per model), and `include_reasoning` per request (OpenRouter's convention). `locked: { show_reasoning: false }` cannot be overridden by clients. When hidden, the model still thinks; nothing of it is sent (message or stream), and `reasoning_tokens` still counts it.
105+ - Streaming: reasoning was already sent as `delta.reasoning_content`; now also checked on the Mac with real Qwen3 (reasoning deltas token by token, all before the answer; none when hidden).
106+ Tests: +3 server, +1 loader, +1 Mac smoke. Linux 123, Mac 135, gate PASS.
modified Sources/RazorbillCore/Config/GenerationOverrides.swift +9 -3
@@ -14,16 +14,19 @@ public struct GenerationOverrides: Sendable, Equatable {
1414 public var maxTokens: Int?
1515 public var thinking: Bool?
1616 public var thinkingBudget: Int?
17+ /// `show_reasoning`: send the model's reasoning to clients.
18+ public var showReasoning: Bool?
1719
1820 public init(
1921 temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil,
20- thinking: Bool? = nil, thinkingBudget: Int? = nil
22+ thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil
2123 ) {
2224 self.temperature = temperature
2325 self.topP = topP
2426 self.maxTokens = maxTokens
2527 self.thinking = thinking
2628 self.thinkingBudget = thinkingBudget
29+ self.showReasoning = showReasoning
2730 }
2831
2932 /// No setting given.
@@ -37,16 +40,19 @@ public struct GenerationOverrides: Sendable, Equatable {
3740 if let maxTokens { result.maxTokens = maxTokens }
3841 if let thinking { result.thinking = thinking }
3942 if let thinkingBudget { result.thinkingBudget = thinkingBudget }
43+ if let showReasoning { result.showReasoning = showReasoning }
4044 return result
4145 }
4246
43- /// `settings` with this block enforced as locked values: `temperature`, `topP` and `thinking`
44- /// are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller request is kept).
47+ /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking`
48+ /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller
49+ /// request is kept).
4550 public func enforcing(on settings: GenerationSettings) -> GenerationSettings {
4651 var result = settings
4752 if let temperature { result.temperature = temperature }
4853 if let topP { result.topP = topP }
4954 if let thinking { result.thinking = thinking }
55+ if let showReasoning { result.showReasoning = showReasoning }
5056 if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) }
5157 if let thinkingBudget {
5258 result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget)
@@ -14,16 +14,19 @@ public struct GenerationOverrides: Sendable, Equatable {
14 public var maxTokens: Int?14 public var maxTokens: Int?
15 public var thinking: Bool?15 public var thinking: Bool?
16 public var thinkingBudget: Int?16 public var thinkingBudget: Int?
17+ /// `show_reasoning`: send the model's reasoning to clients.
18+ public var showReasoning: Bool?
17 19
18 public init(20 public init(
19 temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil,21 temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil,
20- thinking: Bool? = nil, thinkingBudget: Int? = nil22+ thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil
21 ) {23 ) {
22 self.temperature = temperature24 self.temperature = temperature
23 self.topP = topP25 self.topP = topP
24 self.maxTokens = maxTokens26 self.maxTokens = maxTokens
25 self.thinking = thinking27 self.thinking = thinking
26 self.thinkingBudget = thinkingBudget28 self.thinkingBudget = thinkingBudget
29+ self.showReasoning = showReasoning
27 }30 }
28 31
29 /// No setting given.32 /// No setting given.
@@ -37,16 +40,19 @@ public struct GenerationOverrides: Sendable, Equatable {
37 if let maxTokens { result.maxTokens = maxTokens }40 if let maxTokens { result.maxTokens = maxTokens }
38 if let thinking { result.thinking = thinking }41 if let thinking { result.thinking = thinking }
39 if let thinkingBudget { result.thinkingBudget = thinkingBudget }42 if let thinkingBudget { result.thinkingBudget = thinkingBudget }
43+ if let showReasoning { result.showReasoning = showReasoning }
40 return result44 return result
41 }45 }
42 46
43- /// `settings` with this block enforced as locked values: `temperature`, `topP` and `thinking`47+ /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking`
44- /// are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller request is kept).48+ /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller
49+ /// request is kept).
45 public func enforcing(on settings: GenerationSettings) -> GenerationSettings {50 public func enforcing(on settings: GenerationSettings) -> GenerationSettings {
46 var result = settings51 var result = settings
47 if let temperature { result.temperature = temperature }52 if let temperature { result.temperature = temperature }
48 if let topP { result.topP = topP }53 if let topP { result.topP = topP }
49 if let thinking { result.thinking = thinking }54 if let thinking { result.thinking = thinking }
55+ if let showReasoning { result.showReasoning = showReasoning }
50 if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) }56 if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) }
51 if let thinkingBudget {57 if let thinkingBudget {
52 result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget)58 result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget)
modified Sources/RazorbillCore/Config/ServerConfigLoader.swift +3 -2
@@ -55,7 +55,7 @@ public struct ServerConfigLoader: Sendable {
5555 static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"]
5656 static let serverKeys = ["host", "port", "api_key_env", "cors_origin"]
5757 static let generationKeys = [
58- "temperature", "top_p", "max_tokens", "thinking", "thinking_budget",
58+ "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning",
5959 ]
6060 static let modelKeys = [
6161 "id", "source", "revision", "path", "kind", "preload", "defaults", "locked",
@@ -113,7 +113,8 @@ private struct Context {
113113 ) { $0 > 0 && $0 <= 1 },
114114 maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1),
115115 thinking: reader.bool(mapping, "thinking", path: path),
116- thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0))
116+ thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0),
117+ showReasoning: reader.bool(mapping, "show_reasoning", path: path))
117118 if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens {
118119 reader.report(
119120 "\(path).thinking_budget", mapping["thinking_budget"],
@@ -55,7 +55,7 @@ public struct ServerConfigLoader: Sendable {
55 static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"]55 static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"]
56 static let serverKeys = ["host", "port", "api_key_env", "cors_origin"]56 static let serverKeys = ["host", "port", "api_key_env", "cors_origin"]
57 static let generationKeys = [57 static let generationKeys = [
58- "temperature", "top_p", "max_tokens", "thinking", "thinking_budget",58+ "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning",
59 ]59 ]
60 static let modelKeys = [60 static let modelKeys = [
61 "id", "source", "revision", "path", "kind", "preload", "defaults", "locked",61 "id", "source", "revision", "path", "kind", "preload", "defaults", "locked",
@@ -113,7 +113,8 @@ private struct Context {
113 ) { $0 > 0 && $0 <= 1 },113 ) { $0 > 0 && $0 <= 1 },
114 maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1),114 maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1),
115 thinking: reader.bool(mapping, "thinking", path: path),115 thinking: reader.bool(mapping, "thinking", path: path),
116- thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0))116+ thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0),
117+ showReasoning: reader.bool(mapping, "show_reasoning", path: path))
117 if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens {118 if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens {
118 reader.report(119 reader.report(
119 "\(path).thinking_budget", mapping["thinking_budget"],120 "\(path).thinking_budget", mapping["thinking_budget"],
modified Sources/RazorbillCore/Engine/GenerationSettings.swift +5 -1
@@ -15,6 +15,8 @@ public struct GenerationSettings: Sendable, Equatable {
1515 /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit.
1616 /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`.
1717 public var thinkingBudget: Int?
18+ /// Send the model's reasoning to the client (it still thinks when this is false). Default true.
19+ public var showReasoning: Bool
1820 /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random.
1921 public var seed: UInt64?
2022 /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`).
@@ -24,7 +26,8 @@ public struct GenerationSettings: Sendable, Equatable {
2426
2527 public init(
2628 temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024,
27- thinking: Bool = false, thinkingBudget: Int? = nil, seed: UInt64? = nil,
29+ thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true,
30+ seed: UInt64? = nil,
2831 presencePenalty: Double? = nil, frequencyPenalty: Double? = nil
2932 ) {
3033 self.temperature = temperature
@@ -32,6 +35,7 @@ public struct GenerationSettings: Sendable, Equatable {
3235 self.maxTokens = maxTokens
3336 self.thinking = thinking
3437 self.thinkingBudget = thinkingBudget
38+ self.showReasoning = showReasoning
3539 self.seed = seed
3640 self.presencePenalty = presencePenalty
3741 self.frequencyPenalty = frequencyPenalty
@@ -15,6 +15,8 @@ public struct GenerationSettings: Sendable, Equatable {
15 /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit.15 /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit.
16 /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`.16 /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`.
17 public var thinkingBudget: Int?17 public var thinkingBudget: Int?
18+ /// Send the model's reasoning to the client (it still thinks when this is false). Default true.
19+ public var showReasoning: Bool
18 /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random.20 /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random.
19 public var seed: UInt64?21 public var seed: UInt64?
20 /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`).22 /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`).
@@ -24,7 +26,8 @@ public struct GenerationSettings: Sendable, Equatable {
24 26
25 public init(27 public init(
26 temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024,28 temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024,
27- thinking: Bool = false, thinkingBudget: Int? = nil, seed: UInt64? = nil,29+ thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true,
30+ seed: UInt64? = nil,
28 presencePenalty: Double? = nil, frequencyPenalty: Double? = nil31 presencePenalty: Double? = nil, frequencyPenalty: Double? = nil
29 ) {32 ) {
30 self.temperature = temperature33 self.temperature = temperature
@@ -32,6 +35,7 @@ public struct GenerationSettings: Sendable, Equatable {
32 self.maxTokens = maxTokens35 self.maxTokens = maxTokens
33 self.thinking = thinking36 self.thinking = thinking
34 self.thinkingBudget = thinkingBudget37 self.thinkingBudget = thinkingBudget
38+ self.showReasoning = showReasoning
35 self.seed = seed39 self.seed = seed
36 self.presencePenalty = presencePenalty40 self.presencePenalty = presencePenalty
37 self.frequencyPenalty = frequencyPenalty41 self.frequencyPenalty = frequencyPenalty
modified Sources/RazorbillServer/Chat/ChatCompletionRequest.swift +4 -1
@@ -27,6 +27,8 @@ struct ChatCompletionRequest: Decodable, Sendable {
2727 var chatTemplateKwargs: ConfigValue?
2828 /// razorbill extension: most tokens the model may think before it must answer.
2929 var thinkingBudget: Int?
30+ /// OpenRouter's convention: `false` hides the reasoning (the model still thinks).
31+ var includeReasoning: Bool?
3032
3133 enum CodingKeys: String, CodingKey {
3234 case model, messages, temperature, stop, seed, stream, logprobs, tools
@@ -41,6 +43,7 @@ struct ChatCompletionRequest: Decodable, Sendable {
4143 case reasoningEffort = "reasoning_effort"
4244 case chatTemplateKwargs = "chat_template_kwargs"
4345 case thinkingBudget = "thinking_budget"
46+ case includeReasoning = "include_reasoning"
4447 }
4548
4649 /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field.
@@ -172,7 +175,7 @@ extension ChatCompletionRequest {
172175 messages: try messages.enumerated().map { try Self.message($1, at: $0) },
173176 client: GenerationOverrides(
174177 temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking,
175- thinkingBudget: thinkingBudget),
178+ thinkingBudget: thinkingBudget, showReasoning: includeReasoning),
176179 seed: seed.map { UInt64(bitPattern: $0) },
177180 presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty,
178181 stops: stops, stream: stream ?? false,
@@ -27,6 +27,8 @@ struct ChatCompletionRequest: Decodable, Sendable {
27 var chatTemplateKwargs: ConfigValue?27 var chatTemplateKwargs: ConfigValue?
28 /// razorbill extension: most tokens the model may think before it must answer.28 /// razorbill extension: most tokens the model may think before it must answer.
29 var thinkingBudget: Int?29 var thinkingBudget: Int?
30+ /// OpenRouter's convention: `false` hides the reasoning (the model still thinks).
31+ var includeReasoning: Bool?
30 32
31 enum CodingKeys: String, CodingKey {33 enum CodingKeys: String, CodingKey {
32 case model, messages, temperature, stop, seed, stream, logprobs, tools34 case model, messages, temperature, stop, seed, stream, logprobs, tools
@@ -41,6 +43,7 @@ struct ChatCompletionRequest: Decodable, Sendable {
41 case reasoningEffort = "reasoning_effort"43 case reasoningEffort = "reasoning_effort"
42 case chatTemplateKwargs = "chat_template_kwargs"44 case chatTemplateKwargs = "chat_template_kwargs"
43 case thinkingBudget = "thinking_budget"45 case thinkingBudget = "thinking_budget"
46+ case includeReasoning = "include_reasoning"
44 }47 }
45 48
46 /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field.49 /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field.
@@ -172,7 +175,7 @@ extension ChatCompletionRequest {
172 messages: try messages.enumerated().map { try Self.message($1, at: $0) },175 messages: try messages.enumerated().map { try Self.message($1, at: $0) },
173 client: GenerationOverrides(176 client: GenerationOverrides(
174 temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking,177 temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking,
175- thinkingBudget: thinkingBudget),178+ thinkingBudget: thinkingBudget, showReasoning: includeReasoning),
176 seed: seed.map { UInt64(bitPattern: $0) },179 seed: seed.map { UInt64(bitPattern: $0) },
177 presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty,180 presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty,
178 stops: stops, stream: stream ?? false,181 stops: stops, stream: stream ?? false,
modified Sources/RazorbillServer/Chat/ChatCompletionRoute.swift +15 -9
@@ -103,10 +103,7 @@ struct ChatCompletionRoute {
103103 let lease = try await models.acquire(plan.model)
104104 let pieces: AsyncThrowingStream<CompletionPiece, Error>
105105 do {
106- let setup = SessionSetup(
107- system: "", tools: [], generation: plan.settings(for: lease.model))
108- let session = try await lease.engine.makeSession(setup)
109- pieces = CompletionStream.pieces(from: session.send(plan.messages), stops: plan.stops)
106+ pieces = try await Self.generate(plan, with: lease)
110107 } catch {
111108 await lease.release()
112109 throw error
@@ -118,11 +115,7 @@ struct ChatCompletionRoute {
118115
119116 func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse {
120117 try await models.withModel(plan.model) { lease in
121- let setup = SessionSetup(
122- system: "", tools: [], generation: plan.settings(for: lease.model))
123- let session = try await lease.engine.makeSession(setup)
124- let pieces = CompletionStream.pieces(
125- from: session.send(plan.messages), stops: plan.stops)
118+ let pieces = try await Self.generate(plan, with: lease)
126119 var content = ""
127120 var reasoning = ""
128121 var calls: [WireToolCall] = []
@@ -145,6 +138,19 @@ struct ChatCompletionRoute {
145138 }
146139 }
147140
141+ /// Starts the answer: a fresh session with the request's settings for this model, the whole
142+ /// conversation, the stop sequences, and the reasoning hidden unless it may be shown.
143+ static func generate(
144+ _ plan: ChatPlan, with lease: ModelLease
145+ ) async throws -> AsyncThrowingStream<CompletionPiece, Error> {
146+ let settings = plan.settings(for: lease.model)
147+ let session = try await lease.engine.makeSession(
148+ SessionSetup(system: "", tools: [], generation: settings))
149+ return CompletionStream.pieces(
150+ from: session.send(plan.messages), stops: plan.stops,
151+ showReasoning: settings.showReasoning)
152+ }
153+
148154 /// `chatcmpl-` followed by 24 random hexadecimal digits.
149155 static func newID() -> String {
150156 "chatcmpl-"
@@ -103,10 +103,7 @@ struct ChatCompletionRoute {
103 let lease = try await models.acquire(plan.model)103 let lease = try await models.acquire(plan.model)
104 let pieces: AsyncThrowingStream<CompletionPiece, Error>104 let pieces: AsyncThrowingStream<CompletionPiece, Error>
105 do {105 do {
106- let setup = SessionSetup(106+ pieces = try await Self.generate(plan, with: lease)
107- system: "", tools: [], generation: plan.settings(for: lease.model))
108- let session = try await lease.engine.makeSession(setup)
109- pieces = CompletionStream.pieces(from: session.send(plan.messages), stops: plan.stops)
110 } catch {107 } catch {
111 await lease.release()108 await lease.release()
112 throw error109 throw error
@@ -118,11 +115,7 @@ struct ChatCompletionRoute {
118 115
119 func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse {116 func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse {
120 try await models.withModel(plan.model) { lease in117 try await models.withModel(plan.model) { lease in
121- let setup = SessionSetup(118+ let pieces = try await Self.generate(plan, with: lease)
122- system: "", tools: [], generation: plan.settings(for: lease.model))
123- let session = try await lease.engine.makeSession(setup)
124- let pieces = CompletionStream.pieces(
125- from: session.send(plan.messages), stops: plan.stops)
126 var content = ""119 var content = ""
127 var reasoning = ""120 var reasoning = ""
128 var calls: [WireToolCall] = []121 var calls: [WireToolCall] = []
@@ -145,6 +138,19 @@ struct ChatCompletionRoute {
145 }138 }
146 }139 }
147 140
141+ /// Starts the answer: a fresh session with the request's settings for this model, the whole
142+ /// conversation, the stop sequences, and the reasoning hidden unless it may be shown.
143+ static func generate(
144+ _ plan: ChatPlan, with lease: ModelLease
145+ ) async throws -> AsyncThrowingStream<CompletionPiece, Error> {
146+ let settings = plan.settings(for: lease.model)
147+ let session = try await lease.engine.makeSession(
148+ SessionSetup(system: "", tools: [], generation: settings))
149+ return CompletionStream.pieces(
150+ from: session.send(plan.messages), stops: plan.stops,
151+ showReasoning: settings.showReasoning)
152+ }
153+
148 /// `chatcmpl-` followed by 24 random hexadecimal digits.154 /// `chatcmpl-` followed by 24 random hexadecimal digits.
149 static func newID() -> String {155 static func newID() -> String {
150 "chatcmpl-"156 "chatcmpl-"
modified Sources/RazorbillServer/Chat/CompletionStream.swift +7 -3
@@ -50,13 +50,16 @@ enum CompletionPiece: Sendable, Equatable {
5050 /// When a stop sequence ends the answer, the engine is interrupted before it reports its token
5151 /// counts: `usage` then counts one token per piece of text received, and no prompt tokens.
5252 enum CompletionStream {
53+ /// With `showReasoning` false, reasoning is counted in `usage` but not passed on.
5354 static func pieces(
54- from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String]
55+ from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String],
56+ showReasoning: Bool = true
5557 ) -> AsyncThrowingStream<CompletionPiece, Error> {
5658 AsyncThrowingStream { continuation in
5759 let task = Task {
5860 do {
59- var state = State(filter: StopSequenceFilter(stops))
61+ var state = State(
62+ filter: StopSequenceFilter(stops), showReasoning: showReasoning)
6063 events: for try await event in events {
6164 for piece in state.consume(event) { continuation.yield(piece) }
6265 if state.filter.isStopped { break events }
@@ -74,6 +77,7 @@ enum CompletionStream {
7477 /// What has been seen so far.
7578 struct State {
7679 var filter: StopSequenceFilter
80+ var showReasoning = true
7781 var stats: GenerationStats?
7882 var calledTools = false
7983 var textPieces = 0
@@ -95,7 +99,7 @@ enum CompletionStream {
9599 || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
96100 guard reasoningStarted else { return [] }
97101 reasoningPieces += 1
98- return [.reasoning(text)]
102+ return showReasoning ? [.reasoning(text)] : []
99103 case .toolCall(let call):
100104 calledTools = true
101105 return [.toolCall(call)]
@@ -50,13 +50,16 @@ enum CompletionPiece: Sendable, Equatable {
50 /// When a stop sequence ends the answer, the engine is interrupted before it reports its token50 /// When a stop sequence ends the answer, the engine is interrupted before it reports its token
51 /// counts: `usage` then counts one token per piece of text received, and no prompt tokens.51 /// counts: `usage` then counts one token per piece of text received, and no prompt tokens.
52 enum CompletionStream {52 enum CompletionStream {
53+ /// With `showReasoning` false, reasoning is counted in `usage` but not passed on.
53 static func pieces(54 static func pieces(
54- from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String]55+ from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String],
56+ showReasoning: Bool = true
55 ) -> AsyncThrowingStream<CompletionPiece, Error> {57 ) -> AsyncThrowingStream<CompletionPiece, Error> {
56 AsyncThrowingStream { continuation in58 AsyncThrowingStream { continuation in
57 let task = Task {59 let task = Task {
58 do {60 do {
59- var state = State(filter: StopSequenceFilter(stops))61+ var state = State(
62+ filter: StopSequenceFilter(stops), showReasoning: showReasoning)
60 events: for try await event in events {63 events: for try await event in events {
61 for piece in state.consume(event) { continuation.yield(piece) }64 for piece in state.consume(event) { continuation.yield(piece) }
62 if state.filter.isStopped { break events }65 if state.filter.isStopped { break events }
@@ -74,6 +77,7 @@ enum CompletionStream {
74 /// What has been seen so far.77 /// What has been seen so far.
75 struct State {78 struct State {
76 var filter: StopSequenceFilter79 var filter: StopSequenceFilter
80+ var showReasoning = true
77 var stats: GenerationStats?81 var stats: GenerationStats?
78 var calledTools = false82 var calledTools = false
79 var textPieces = 083 var textPieces = 0
@@ -95,7 +99,7 @@ enum CompletionStream {
95 || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty99 || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
96 guard reasoningStarted else { return [] }100 guard reasoningStarted else { return [] }
97 reasoningPieces += 1101 reasoningPieces += 1
98- return [.reasoning(text)]102+ return showReasoning ? [.reasoning(text)] : []
99 case .toolCall(let call):103 case .toolCall(let call):
100 calledTools = true104 calledTools = true
101 return [.toolCall(call)]105 return [.toolCall(call)]
modified Tests/RazorbillCoreTests/ServerConfigLoaderTests.swift +9 -0
@@ -17,6 +17,15 @@ import Testing
1717 }
1818 }
1919
20+ @Test func showReasoningIsAGenerationSetting() throws {
21+ let config = try loader.parse("locked: { show_reasoning: false }\n")
22+ #expect(config.locked == GenerationOverrides(showReasoning: false))
23+ let locked = GenerationOverrides.resolve(
24+ defaults: [], client: GenerationOverrides(showReasoning: true), locked: [config.locked])
25+ #expect(!locked.showReasoning)
26+ #expect(GenerationSettings().showReasoning)
27+ }
28+
2029 @Test func emptyFileIsTheDefaultConfiguration() throws {
2130 #expect(try loader.parse("") == ServerConfig())
2231 #expect(try loader.parse("# only a comment\n") == ServerConfig())
@@ -17,6 +17,15 @@ import Testing
17 }17 }
18 }18 }
19 19
20+ @Test func showReasoningIsAGenerationSetting() throws {
21+ let config = try loader.parse("locked: { show_reasoning: false }\n")
22+ #expect(config.locked == GenerationOverrides(showReasoning: false))
23+ let locked = GenerationOverrides.resolve(
24+ defaults: [], client: GenerationOverrides(showReasoning: true), locked: [config.locked])
25+ #expect(!locked.showReasoning)
26+ #expect(GenerationSettings().showReasoning)
27+ }
28+
20 @Test func emptyFileIsTheDefaultConfiguration() throws {29 @Test func emptyFileIsTheDefaultConfiguration() throws {
21 #expect(try loader.parse("") == ServerConfig())30 #expect(try loader.parse("") == ServerConfig())
22 #expect(try loader.parse("# only a comment\n") == ServerConfig())31 #expect(try loader.parse("# only a comment\n") == ServerConfig())
modified Tests/RazorbillMLXTests/ChatSmokeTests.swift +32 -0
@@ -55,6 +55,38 @@ struct ChatSmokeTests {
5555 #expect(response.usage.reasoningTokens > 0)
5656 }
5757
58+ /// Streams `plan` and returns the reasoning and content deltas, in order.
59+ func streamedDeltas(_ plan: ChatPlan) async throws -> [(reasoning: Bool, text: String)] {
60+ let lease = try await models.acquire(smokeModel)
61+ let pieces = try await ChatCompletionRoute.generate(plan, with: lease)
62+ let chunks = ChatCompletionRoute.chunks(
63+ pieces, lease: lease, plan: plan, logger: .init(label: "test"))
64+ var deltas: [(reasoning: Bool, text: String)] = []
65+ for try await chunk in chunks {
66+ guard let delta = chunk.choices.first?.delta else { continue }
67+ if let text = delta.reasoningContent { deltas.append((true, text)) }
68+ if let text = delta.content, !text.isEmpty { deltas.append((false, text)) }
69+ }
70+ return deltas
71+ }
72+
73+ @Test func reasoningStreamsBeforeTheAnswer() async throws {
74+ var thinking = plan("What is the capital of France?", maxTokens: 600)
75+ thinking.client.thinking = true
76+ let deltas = try await streamedDeltas(thinking)
77+ let reasoning = deltas.filter(\.reasoning)
78+ #expect(reasoning.count > 5) // token by token
79+ #expect(deltas.first?.reasoning == true)
80+ let firstAnswer = try #require(deltas.firstIndex { !$0.reasoning })
81+ #expect(deltas[firstAnswer...].allSatisfy { !$0.reasoning })
82+ #expect(deltas.filter { !$0.reasoning }.map(\.text).joined().contains("Paris"))
83+
84+ thinking.client.showReasoning = false
85+ let hidden = try await streamedDeltas(thinking)
86+ #expect(hidden.allSatisfy { !$0.reasoning })
87+ #expect(hidden.map(\.text).joined().contains("Paris"))
88+ }
89+
5890 @Test func thinkingBudgetShortensTheReasoning() async throws {
5991 var thinking = plan("Is 391 a prime number?", maxTokens: 600)
6092 thinking.client.thinking = true
@@ -55,6 +55,38 @@ struct ChatSmokeTests {
55 #expect(response.usage.reasoningTokens > 0)55 #expect(response.usage.reasoningTokens > 0)
56 }56 }
57 57
58+ /// Streams `plan` and returns the reasoning and content deltas, in order.
59+ func streamedDeltas(_ plan: ChatPlan) async throws -> [(reasoning: Bool, text: String)] {
60+ let lease = try await models.acquire(smokeModel)
61+ let pieces = try await ChatCompletionRoute.generate(plan, with: lease)
62+ let chunks = ChatCompletionRoute.chunks(
63+ pieces, lease: lease, plan: plan, logger: .init(label: "test"))
64+ var deltas: [(reasoning: Bool, text: String)] = []
65+ for try await chunk in chunks {
66+ guard let delta = chunk.choices.first?.delta else { continue }
67+ if let text = delta.reasoningContent { deltas.append((true, text)) }
68+ if let text = delta.content, !text.isEmpty { deltas.append((false, text)) }
69+ }
70+ return deltas
71+ }
72+
73+ @Test func reasoningStreamsBeforeTheAnswer() async throws {
74+ var thinking = plan("What is the capital of France?", maxTokens: 600)
75+ thinking.client.thinking = true
76+ let deltas = try await streamedDeltas(thinking)
77+ let reasoning = deltas.filter(\.reasoning)
78+ #expect(reasoning.count > 5) // token by token
79+ #expect(deltas.first?.reasoning == true)
80+ let firstAnswer = try #require(deltas.firstIndex { !$0.reasoning })
81+ #expect(deltas[firstAnswer...].allSatisfy { !$0.reasoning })
82+ #expect(deltas.filter { !$0.reasoning }.map(\.text).joined().contains("Paris"))
83+
84+ thinking.client.showReasoning = false
85+ let hidden = try await streamedDeltas(thinking)
86+ #expect(hidden.allSatisfy { !$0.reasoning })
87+ #expect(hidden.map(\.text).joined().contains("Paris"))
88+ }
89+
58 @Test func thinkingBudgetShortensTheReasoning() async throws {90 @Test func thinkingBudgetShortensTheReasoning() async throws {
59 var thinking = plan("Is 391 a prime number?", maxTokens: 600)91 var thinking = plan("Is 391 a prime number?", maxTokens: 600)
60 thinking.client.thinking = true92 thinking.client.thinking = true
modified Tests/RazorbillServerTests/ReasoningTests.swift +42 -0
@@ -63,6 +63,48 @@ struct BadBudget: RequestSettingError {
6363 }
6464 }
6565
66+ @Test func includeReasoningFalseHidesItButUsageCountsIt() async throws {
67+ let script: [EngineEvent] = [.thinking("Secret plan."), .text("42"), .stats(stats)]
68+ let engines = TestEngines(script: [script, script])
69+ let hidden = #","include_reasoning":false"#
70+ try await withLiveServer(engines: engines) { client in
71+ let body = try json(try await post(client, simpleRequest(extra: hidden)))
72+ #expect(message(body)?["reasoning_content"] == nil)
73+ #expect(message(body)?["content"] as? String == "42")
74+ let usage = try #require(body["usage"] as? [String: Any])
75+ #expect(
76+ (usage["completion_tokens_details"] as? [String: Int]) == ["reasoning_tokens": 1])
77+ }
78+ try await withLiveServer(engines: engines) { client in
79+ let response = try await post(client, simpleRequest(extra: hidden + #","stream":true"#))
80+ #expect(!String(buffer: response.body).contains("Secret"))
81+ #expect(
82+ try chunks(response).compactMap { delta($0)?["content"] as? String } == ["", "42"])
83+ }
84+ }
85+
86+ @Test func configurationDecidesAndLocksWhetherReasoningIsShown() async throws {
87+ let script: [EngineEvent] = [.thinking("Plan."), .text("Ok")]
88+ let engines = TestEngines(script: [script, script, script])
89+ var settings = testSettings
90+ settings.config.defaults = GenerationOverrides(showReasoning: false)
91+ try await withLiveServer(settings, engines: engines) { client in
92+ let quiet = try json(try await post(client, simpleRequest()))
93+ #expect(message(quiet)?["reasoning_content"] == nil)
94+ }
95+ try await withLiveServer(settings, engines: engines) { client in
96+ let asked = try json(
97+ try await post(client, simpleRequest(extra: #","include_reasoning":true"#)))
98+ #expect(message(asked)?["reasoning_content"] as? String == "Plan.")
99+ }
100+ settings.config.locked = GenerationOverrides(showReasoning: false)
101+ try await withLiveServer(settings, engines: engines) { client in
102+ let refused = try json(
103+ try await post(client, simpleRequest(extra: #","include_reasoning":true"#)))
104+ #expect(message(refused)?["reasoning_content"] == nil)
105+ }
106+ }
107+
66108 static let switches: [(extra: String, thinking: Bool)] = [
67109 (#","reasoning_effort":"high""#, true),
68110 (#","reasoning_effort":"low""#, true),
@@ -63,6 +63,48 @@ struct BadBudget: RequestSettingError {
63 }63 }
64 }64 }
65 65
66+ @Test func includeReasoningFalseHidesItButUsageCountsIt() async throws {
67+ let script: [EngineEvent] = [.thinking("Secret plan."), .text("42"), .stats(stats)]
68+ let engines = TestEngines(script: [script, script])
69+ let hidden = #","include_reasoning":false"#
70+ try await withLiveServer(engines: engines) { client in
71+ let body = try json(try await post(client, simpleRequest(extra: hidden)))
72+ #expect(message(body)?["reasoning_content"] == nil)
73+ #expect(message(body)?["content"] as? String == "42")
74+ let usage = try #require(body["usage"] as? [String: Any])
75+ #expect(
76+ (usage["completion_tokens_details"] as? [String: Int]) == ["reasoning_tokens": 1])
77+ }
78+ try await withLiveServer(engines: engines) { client in
79+ let response = try await post(client, simpleRequest(extra: hidden + #","stream":true"#))
80+ #expect(!String(buffer: response.body).contains("Secret"))
81+ #expect(
82+ try chunks(response).compactMap { delta($0)?["content"] as? String } == ["", "42"])
83+ }
84+ }
85+
86+ @Test func configurationDecidesAndLocksWhetherReasoningIsShown() async throws {
87+ let script: [EngineEvent] = [.thinking("Plan."), .text("Ok")]
88+ let engines = TestEngines(script: [script, script, script])
89+ var settings = testSettings
90+ settings.config.defaults = GenerationOverrides(showReasoning: false)
91+ try await withLiveServer(settings, engines: engines) { client in
92+ let quiet = try json(try await post(client, simpleRequest()))
93+ #expect(message(quiet)?["reasoning_content"] == nil)
94+ }
95+ try await withLiveServer(settings, engines: engines) { client in
96+ let asked = try json(
97+ try await post(client, simpleRequest(extra: #","include_reasoning":true"#)))
98+ #expect(message(asked)?["reasoning_content"] as? String == "Plan.")
99+ }
100+ settings.config.locked = GenerationOverrides(showReasoning: false)
101+ try await withLiveServer(settings, engines: engines) { client in
102+ let refused = try json(
103+ try await post(client, simpleRequest(extra: #","include_reasoning":true"#)))
104+ #expect(message(refused)?["reasoning_content"] == nil)
105+ }
106+ }
107+
66 static let switches: [(extra: String, thinking: Bool)] = [108 static let switches: [(extra: String, thinking: Bool)] = [
67 (#","reasoning_effort":"high""#, true),109 (#","reasoning_effort":"high""#, true),
68 (#","reasoning_effort":"low""#, true),110 (#","reasoning_effort":"low""#, true),
modified examples/server.yaml +3 -1
@@ -14,9 +14,11 @@ defaults:
1414 max_tokens: 2048
1515
1616 # Settings clients cannot change. Nothing is locked unless listed here (or under a model).
17-# temperature, top_p and thinking are imposed; max_tokens and thinking_budget are ceilings.
17+# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are
18+# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning.
1819 locked:
1920 max_tokens: 8192
21+ # show_reasoning: false # never send the models' reasoning (they still think)
2022
2123 # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too.
2224 models:
@@ -14,9 +14,11 @@ defaults:
14 max_tokens: 204814 max_tokens: 2048
15 15
16 # Settings clients cannot change. Nothing is locked unless listed here (or under a model).16 # Settings clients cannot change. Nothing is locked unless listed here (or under a model).
17-# temperature, top_p and thinking are imposed; max_tokens and thinking_budget are ceilings.17+# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are
18+# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning.
18 locked:19 locked:
19 max_tokens: 819220 max_tokens: 8192
21+ # show_reasoning: false # never send the models' reasoning (they still think)
20 22
21 # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too.23 # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too.
22 models:24 models: