Skip to content

ThinkBudget alone owns thinking: a response format no longer turns it off - #5808

Merged
joelteply merged 4 commits into
canaryfrom
fable/think-budget-owns-think
Nov 7, 2026
Merged

joelteply merged 4 commits into
canaryfrom
fable/think-budget-owns-think

Conversation

@joelteply

@joelteply joelteply commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

How this serves the minds: a resident whose request carries a structured format can reason before answering, within the budget her faculty measured. Her think term is the only thing that decides whether she thinks, and every generation the core makes has to state one. Order of work: line 2/3 (serving; the engine's request contract), "one owner per fact".

The defect

Found by Cormac on 2026-11-06, probing fork llama-server 0d7dda6ae. request_body::finish_body (canary 640a07b, request_body.rs:127-138) set enable_thinking = false for any response_format, Text included. A request with a format therefore never thought, whatever budget it carried. The fork handles a format and thinking together: the reasoning rule wraps the schema (common/chat.cpp:1235-1244) and the budget sampler runs before the grammar (common/sampling.cpp:631).

One owner

request_body::apply_think(Think, body) is the only place that decides thinking:

  • Think::Budget(n > 0): she thinks, with reasoning_budget_tokens: n.
  • Think::Budget(0): the caller's explicit no-think. The body gets enable_thinking = false and a zero budget.
  • Think::ModelDefault: no think term on the body.

Side rules deleted:

  • response_format turning thinking off (the defect).
  • purpose == VISION_DESCRIPTION_PURPOSE turning thinking off. vision_describe now sends "think": 0 itself.
  • The dead gateway ThinkingMode::Suppress and its /no_think text switch: no provider declared it. Removed ThinkingMode, suppress_thinking and apply_no_think_switch.
  • The smoke check's hand-written copy of the two thinking fields. It now calls apply_think.

Required, enforced by the compiler

  • DispatchTerms::think is a Think (ai/think.rs). It is not an Option and has no Default.
  • The terms-less adapter paths (generate_text, generate_stream, generate_stream_checked) take an adapter::Dispatched witness. Its field is private and only the engine's dispatch builds it; a test-only fixture() sits behind test-fixtures.
  • So a caller outside the engine can only generate through generate_admitted, or the new drain generate_under(request, terms), and must state its think.
  • Why this approach: think stays on DispatchTerms (Cormac). Restricting the terms-less paths with a witness is the one way to make them unreachable across crates while adapters in other crates (PlacementSwitch, test adapters) can still implement and forward them.
  • Two compile_fail doctests on DispatchTerms check both halves: terms without a think, and building the witness outside the engine.

Callers, each explicit with its current behaviour

Think Callers
Budget(ThinkBudget(0)) (today's no-think, now stated) should_respond (JSON), generate_response (Text), validate_response (Text), rag_inspect (JSON)
ModelDefault (as they always ran) rate_proposals, generate_recipe, request_replay, dream distiller, genome teach, models/try ×2, llm_module_service, handle_store, in-process warm-up
External passthrough keeps its own gateway (ModelDefault); ai/generate (Think::from_wire(params.think), one path)
Acts Budget(act_reasoning_budget(..)), unchanged on the wire

Follow-up card, owner Fable: measured per-purpose think budgets with a scheduled upward probe for these utility calls. Until then, the unmeasured prior is the mind's measured act think need.

Template check

Cormac verified this, and here is my own receipt. A read-only GET of /props on the M5 engine (port 58057, fork b11009-0d7dda6ae, Qwen3.6-35B-A3B-Q4_K_M, chat_template sha256 e84f32a2…) shows enable_thinking read only under add_generation_prompt: <think>\n\n</think>\n\n instead of <think>\n. Prior assistant turns render by preserve_thinking and last_query_index. Budget 0 => enable_thinking=false therefore keeps her prefix.

Touched files leave clean

  • generate_response: admission is now required. The self-sized DEFAULT_GENERATE_MAX_* constants, cost units, TTL pad and with_timeout are deleted, and ts-rs GenerateResponseRequest.ts is regenerated.
  • rag_inspect: the decision is parsed through a typed serde struct.
  • heuristic fixture: echoes the whole last message; its fingerprint is the digest's leading u32.
  • airc_remote_inference_end_to_end: the assertion now pins the missing-module hard error that task Implement Shared Pin Feature for Collaborative Team Memory #219 introduced. The test already failed on base.

Measured

Run in the worktree at 3f808a2 (2026-11-07) with CARGO_TARGET_DIR=cargo-target-thinkown and nice -n 19. Crate-scoped; serving was not touched.

  • Plain check: engine (metal), cognition, mind, academy, models, sentinel, gateway, genome, core and base build with no errors and no new warnings.
  • Tests:
    • engine lib 1498 passed, plus 2 compile-fail doctests
    • cognition 940, mind 1108, academy 192, genome 345, gateway 19, models 34, core lib 1189
    • core airc_remote_inference_end_to_end 3 and persona_command_inbound_pump 1 (with test-fixtures)
  • Gates: source-hygiene ratchets vs 640a07b: 87 passed, no count rose. oversized-edits: exit 0.

The live check comes after deploy: the format-bound callers' act time on the M5.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

… off

Defect (Cormac, 2026-11-06, probing fork llama-server 0d7dda6ae): request_body::finish_body set
chat_template_kwargs.enable_thinking=false for ANY response_format, Text included, so a
format-bound request never thought whatever ThinkBudget it carried. The fork composes a format
with thinking: the template's reasoning rule wraps the schema (common/chat.cpp:1235-1244) and the
budget sampler runs before the grammar (common/sampling.cpp:631): budget 40 -> forced </think>,
then schema-valid JSON, finish=stop.

One owner: request_body::apply_think(think, body) (replaces apply_reasoning_budget and
apply_enable_thinking_false). Some(n>0): thinks, reasoning_budget_tokens n, template left on.
Some(0): the caller's explicit no-think, enable_thinking=false + budget 0. None: model default.

Side rules removed, each now reading the one fact:
- response_format -> enable_thinking=false (the defect): deleted.
- purpose == VISION_DESCRIPTION_PURPOSE -> enable_thinking=false: deleted; vision_describe now
  states its intent as ai/generate's think term ("think": 0).
- gateway ThinkingMode::Suppress (enable_thinking=false + the /no_think text switch appended to
  her last user message): dead, no provider declared suppress_thinking. Deleted ThinkingMode,
  OpenAICompatibleConfig.thinking, ProviderCapabilities.suppress_thinking, apply_no_think_switch
  and their tests.
- the readiness smoke body's hand-written enable_thinking/reasoning_budget_tokens pair: now
  apply_think(Some(ThinkBudget(0))).

Behaviour change to note: callers carrying a response_format and no think term
(should_respond, rag_inspect: JsonObject; generate_response, validate_response: Text) now get the
model's default (think) instead of a forced no-think. Budget 0 still relies on the fork for
templates without an enable_thinking branch (Cormac's card 8b479782).

Tests (request_body's one test mod): the_think_budget_is_the_callers_measured_one_and_nothing_else
(extended: zero closes the template, None leaves it); new
a_response_format_never_turns_her_thinking_off_only_her_think_term_does (JsonObject and Text with
ThinkBudget(40) keep thinking at 40; ThinkBudget(0) turns it off; a purpose is not a think term).
vision_describe test asserts the description's zero think term parses as ai/generate's.

Validated (worktree, CARGO_TARGET_DIR=cargo-target-thinkown, nice 19, serving untouched):
cargo check -p continuum-engine --features continuum-engine/metal; cargo test -p continuum-engine
--lib (1498 passed, 16 ignored); cargo check + test -p continuum-cognition (vision_describe,
working_memory, act_output_room: 80 passed); source-hygiene ratchets vs 640a07b (87 passed, no
count rose); oversized-edits exit 0. No ts-rs wire type changed. 89 added, 241 removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…red and the terms-less paths take an engine-only witness

Review of #5808 (coordinator, Cormac). The think term is REQUIRED for every generation the core
makes, enforced by the compiler:

- ai/think.rs (new; ThinkBudget and DispatchTerms moved out of types.rs, re-exported there):
  `Think { Budget(ThinkBudget), ModelDefault }`. `DispatchTerms::think` is a `Think`: no Option,
  no Default (DispatchTerms' Default derive is gone), constructor `DispatchTerms::thinking`.
- adapter::Dispatched: a witness with a private field, built only by the engine's dispatch
  (`Dispatched::under(&terms)`; `fixture()` behind test-fixtures). `generate_text`,
  `generate_stream` and `generate_stream_checked` take it, so a caller outside the engine cannot
  reach a terms-less path: it generates through `DispatchTermsPolicy::generate_admitted`, or the
  new provided drain `generate_under(request, terms)`, and states its think. A wrapping adapter
  forwards the witness it was handed; the witness carries the terms (OpenAI's terms-less stream
  reads `dispatched.terms()`, the grid lane forwards its budget).
- Compile-fail doctests on DispatchTerms pin both: terms without a think, and building the
  witness outside the engine, do not compile.

Callers, each explicit with its current behaviour:
- ThinkBudget(0), today's no-think now stated by the one owner: cognition/should_respond (JSON),
  cognition/generate_response (Text), cognition/validate_response (Text), persona/rag_inspect
  (JSON).
- Think::ModelDefault (no think term, as they always ran; measured per-purpose budgets with an
  upward probe are a follow-up card, owner Fable): rate_proposals, generate_recipe (through the
  registry helper, which now takes terms), request_replay, academy dream distiller, genome teach,
  models/try (both probes), engine llm_module_service, handle_store, the in-process warm-up.
- External passthrough keeps its own: the gateway (ModelDefault, the client's body decides) and
  ai/generate (`Think::from_wire(params.think)`; one generate_admitted path replaces its four-way
  match).
- Acts: `Think::Budget(act_reasoning_budget(..))`, unchanged on the wire.

Template check (Cormac verified; receipt here too): the M5 engine's /props (fork b11009-0d7dda6ae,
Qwen3.6-35B-A3B-Q4_K_M, chat_template sha256 e84f32a2...) reads `enable_thinking` only under
`add_generation_prompt` (`<think>\n\n</think>\n\n` vs `<think>\n`); prior assistant turns render by
`preserve_thinking` / `last_query_index`. Budget 0 => enable_thinking=false keeps her prefix.

Touched files leave clean (ratchets judge a touched file whole):
- generate_response: `admission` is REQUIRED (GenerateResponseAdmissionPolicy, no Option); the
  self-sized DEFAULT_GENERATE_MAX_CONCURRENCY / MAX_COST_UNITS / COST_UNITS / LEASE_TTL_PAD
  constants and `with_timeout` are deleted (ts-rs GenerateResponseRequest.ts regenerated).
- rag_inspect: the decide-and-respond parse is a typed serde struct, not two "missing ..."
  complaints.
- heuristic_adapter (test fixture): echoes the whole last message (ECHO_CHARS deleted); the
  fingerprint is the digest's leading u32, not `.take(4)`.
- airc_remote_inference_end_to_end: the missing-module assertion pins the hard error task #219
  landed (it failed on base: the TS-bridge fallthrough it pinned is gone).

Validated (worktree, CARGO_TARGET_DIR=cargo-target-thinkown, nice 19, serving untouched):
- plain check: engine (metal), cognition, mind, academy, models, sentinel, gateway, genome, core,
  base: no errors, no new warnings.
- tests: engine lib 1498 passed (16 ignored) + 2 compile-fail doctests; cognition lib 940;
  mind 1108; academy 192; genome 345; gateway 19; models 34; core lib 1189; core
  airc_remote_inference_end_to_end 3 + persona_command_inbound_pump 1 (test-fixtures);
  core --tests check with and without test-fixtures.
- source-hygiene ratchets vs 640a07b: 87 passed, no count rose; oversized-edits exit 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: XL and removed size: L labels Nov 7, 2026
joelteply and others added 2 commits November 6, 2026 19:02
…doctests name their error codes

Cormac's review of #5808 at 3f808a2:

- Retracted claim removed: ThinkBudget's doc said the pinned fork's sampler forces the end tag at
  a zero budget. False on 0d7dda6ae; true only from the fork fix on (llama.cpp#95, card
  c5fb32b7). Restated in think.rs: zero is no-think through both levers, the template's
  enable_thinking=false on every pin (Cormac's receipt: deployed engine 0d7dda6ae, Qwen3.5-0.8B on
  the IntelMac ~01:10Z 2026-11-07: empty reasoning, 96 tokens of schema JSON, a 56-token answer,
  finish=stop), and the sampler's reasoning_budget_tokens 0 from the fork fix on. The same claim
  restated in request_body::apply_think's doc and act_room::act_reasoning_budget's doc (grep for
  "forces the end tag" / REASONING_BUDGET_FORCING: no other site).
- Doctests pinned: compile_fail,E0063 (terms without `think`) and compile_fail,E0423 (building
  Dispatched's private tuple field outside the engine). E0423, not E0603: rustc 1.96 reports
  "cannot initialize a tuple struct which contains private fields" (checked by compiling both
  snippets as a throwaway example: E0063 and E0423). Note: stable rustdoc does not enforce the
  code (a wrong code still passed); the codes are enforced where rustdoc runs on nightly.

Doctests: 2 passed (cargo test -p continuum-engine --doc think).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply enabled auto-merge (squash) November 7, 2026 01:23
@joelteply
joelteply disabled auto-merge November 7, 2026 01:24
@joelteply
joelteply merged commit e2c9e41 into canary Nov 7, 2026
44 checks passed
@joelteply
joelteply deleted the fable/think-budget-owns-think branch November 7, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant