Skip to content

openai_endpoint: ✨ Send a typed reasoning_effort - #10

Merged
yasyf merged 1 commit into
mainfrom
openai-reasoning-effort
Sep 25, 2026
Merged

yasyf merged 1 commit into
mainfrom
openai-reasoning-effort

Conversation

@yasyf

@yasyf yasyf commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Summary

The OpenAI-compatible endpoint backend now takes a typed reasoning_effort (none, minimal, low, medium, high, xhigh) and sends it in every /chat/completions body. Leaving it unset sends nothing, so existing callers see the same request as before.

capt-hook's plain-English rewrite drove this. It calls Cerebras qwen-3.8-27b, which reasons by default. Over 12 calls on one 850-token prompt, the model spent a median 6,292 reasoning tokens (p95 10,801) to produce about 520 output tokens, taking 4.44s at p50 and 7.41s at p95. With reasoning_effort: "none" the same calls took 0.73s at p50 and 1.15s at p95, and the rewrites read as well or better. There was no way to send the field through spawnllm, because the core plans the body.

Change

The core's wire OpenAiEndpoint gains reasoning_effort: Option<ReasoningEffort>, a snake_case serde enum next to AppleSampling. plan/openai.rs inserts reasoning_effort into the body only when it is set. Like the other config fields it has no serde default, so every host sends it, as null when unset.

  • Python: OpenAiEndpointBackend(..., reasoning_effort="none"), typed by the new exported TReasoningEffort literal and carried in openai_section().
  • Go: OpenAIOpts.ReasoningEffort, a ReasoningEffort string type with ReasoningEffortNone … ReasoningEffortXhigh constants. The empty string maps to null in coreOpenAI.
  • Rust: OpenAiEndpoint.reasoning_effort in the crate, with ReasoningEffort re-exported behind the openai feature. The crate's OpenAiEndpoint gains a public field, so a struct literal naming every field has to add it. That makes this release 0.14.0.

The run-spec schema fixture lists the enum. conformance-gen --write regenerated the two existing endpoint vectors, which gained "reasoning_effort": null, and added openai-endpoint-reasoning-effort.

Tests

  • New core unit test reasoning_effort_plan_matches_vector and a new conformance vector, both replayed through the Python and Go hosts against a rebuilt wasm blob.
  • Go TestOpenAIEndpointSendsReasoningEffortOnlyWhenSet checks that the body omits the field when unset and carries "none" when set.
  • Python test_execute_sends_reasoning_effort. test_openai_endpoint_section_set_only_by_owning_backend now expects reasoning_effort: None in the wire section.
  • cargo test --workspace passes except empty_securestorage_env_reads_the_bare_item_over_config_dir_env, which reads this machine's Keychain and fails the same way without this change. cargo clippy --workspace --all-targets reports no warnings, and cargo fmt --check passes. go vet ./... and go test ./... pass. uv run pytest passes with one Apple-sidecar skip, and ruff check is clean.

## Summary

The OpenAI-compatible endpoint backend now takes a typed `reasoning_effort` (`none`, `minimal`, `low`, `medium`, `high`, `xhigh`) and sends it in every `/chat/completions` body. Leaving it unset sends nothing, so existing callers see the same request as before.

capt-hook's plain-English rewrite drove this. It calls Cerebras `qwen-3.8-27b`, which reasons by default. Over 12 calls on one 850-token prompt, the model spent a median 6,292 reasoning tokens (p95 10,801) to produce about 520 output tokens, taking 4.44s at p50 and 7.41s at p95. With `reasoning_effort: "none"` the same calls took 0.73s at p50 and 1.15s at p95, and the rewrites read as well or better. There was no way to send the field through spawnllm, because the core plans the body.

## Change

The core's wire `OpenAiEndpoint` gains `reasoning_effort: Option<ReasoningEffort>`, a snake_case serde enum next to `AppleSampling`. `plan/openai.rs` inserts `reasoning_effort` into the body only when it is set. Like the other config fields it has no serde default, so every host sends it, as `null` when unset.

- Python: `OpenAiEndpointBackend(..., reasoning_effort="none")`, typed by the new exported `TReasoningEffort` literal and carried in `openai_section()`.
- Go: `OpenAIOpts.ReasoningEffort`, a `ReasoningEffort` string type with `ReasoningEffortNone` … `ReasoningEffortXhigh` constants. The empty string maps to `null` in `coreOpenAI`.
- Rust: `OpenAiEndpoint.reasoning_effort` in the crate, with `ReasoningEffort` re-exported behind the `openai` feature. The crate's `OpenAiEndpoint` gains a public field, so a struct literal naming every field has to add it. That makes this release 0.14.0.

The run-spec schema fixture lists the enum. `conformance-gen --write` regenerated the two existing endpoint vectors, which gained `"reasoning_effort": null`, and added `openai-endpoint-reasoning-effort`.

## Tests

- New core unit test `reasoning_effort_plan_matches_vector` and a new conformance vector, both replayed through the Python and Go hosts against a rebuilt wasm blob.
- Go `TestOpenAIEndpointSendsReasoningEffortOnlyWhenSet` checks that the body omits the field when unset and carries `"none"` when set.
- Python `test_execute_sends_reasoning_effort`. `test_openai_endpoint_section_set_only_by_owning_backend` now expects `reasoning_effort: None` in the wire section.
- `cargo test --workspace` passes except `empty_securestorage_env_reads_the_bare_item_over_config_dir_env`, which reads this machine's Keychain and fails the same way without this change. `cargo clippy --workspace --all-targets` reports no warnings, and `cargo fmt --check` passes. `go vet ./...` and `go test ./...` pass. `uv run pytest` passes with one Apple-sidecar skip, and `ruff check` is clean.

Claude-Session-Id: ced006fd-6116-478a-b0f3-56be8ce8183d
@yasyf
yasyf merged commit 57bfe12 into main Sep 25, 2026
17 checks passed
yasyf added a commit to yasyf/captain-hook that referenced this pull request Sep 25, 2026
Context: Follows #165. The plain-English rewrite calls Cerebras `qwen-3.8-27b`, which reasons by default. On a 2,300-character reply it spent a median 6,300 reasoning tokens for about 520 output tokens, so even with #165's 6-second cap many rewrites timed out and showed the original.

Summary: `plain_english` passes `reasoning_effort="none"` to `OpenAiEndpointBackend`, and the spawnllm pin moves to `>=0.14.0,<0.15`, the first release with that field (yasyf/spawnllm#10).

Motivation: The owner chose to make `reasoning_effort` a typed field in spawnllm rather than override the backend's request planning here.

Details: 20 calls through the real `plain_english.plain_english()` path, same prompt and harness, a fresh nonce per call:

| | p50 | p95 | max | fell back to original |
|---|---|---|---|---|
| #165 (spawnllm 0.13.4, reasoning on) | 4.42s | 6.02s | 6.47s | 3 of 20 (6s cap) |
| this PR (spawnllm with reasoning_effort, `"none"`) | 0.52s | 0.98s | 1.13s | 0 of 20 |

The "after" row ran against yasyf/spawnllm#10 installed from its branch. After v0.14.0 was published, 12 more calls against the locked release gave 0.52s p50 and 0.74s p95, with no fallbacks. `uv lock --upgrade-package spawnllm` moves the lock from 0.13.4 to 0.14.0. `test_streamed_message_is_rewritten_once` asserts that the backend carries `reasoning_effort == "none"`. Both changelog entries move to Unreleased: #165's landed under 12.56.0, which was tagged before #165 merged. `pytest tests/test_plain_english.py tests/test_plugin_hooks.py` passes.
yasyf added a commit to yasyf/captain-hook that referenced this pull request Sep 25, 2026
)

Context: Follows #165. The plain-English rewrite calls Cerebras `qwen-3.8-27b`, which reasons by default. On a 2,300-character reply it spent a median 6,300 reasoning tokens for about 520 output tokens, so even with #165's 6-second cap many rewrites timed out and showed the original.

Summary: `plain_english` passes `reasoning_effort="none"` to `OpenAiEndpointBackend`, and the spawnllm pin moves to `>=0.14.0,<0.15`, the first release with that field (yasyf/spawnllm#10).

Motivation: The owner chose to make `reasoning_effort` a typed field in spawnllm rather than override the backend's request planning here.

Details: 20 calls through the real `plain_english.plain_english()` path, same prompt and harness, a fresh nonce per call:

| | p50 | p95 | max | fell back to original |
|---|---|---|---|---|
| #165 (spawnllm 0.13.4, reasoning on) | 4.42s | 6.02s | 6.47s | 3 of 20 (6s cap) |
| this PR (spawnllm with reasoning_effort, `"none"`) | 0.52s | 0.98s | 1.13s | 0 of 20 |

The "after" row ran against yasyf/spawnllm#10 installed from its branch. After v0.14.0 was published, 12 more calls against the locked release gave 0.52s p50 and 0.74s p95, with no fallbacks. `uv lock --upgrade-package spawnllm` moves the lock from 0.13.4 to 0.14.0. `test_streamed_message_is_rewritten_once` asserts that the backend carries `reasoning_effort == "none"`. Both changelog entries move to Unreleased: #165's landed under 12.56.0, which was tagged before #165 merged. `pytest tests/test_plain_english.py tests/test_plugin_hooks.py` passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant