From 4cdc4334d8d69652fa870b4173718a727406297d Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Fri, 27 Nov 2026 18:13:18 +0100 Subject: [PATCH] config: configurable max_new generation budget (default 16384) so CoT+answer are not truncated --- README.md | 19 +++++++++++++------ src/api/formatter.rs | 4 +++- src/config.rs | 19 +++++++++++++++++++ src/inkling/formatter.rs | 10 +++++++++- src/main.rs | 18 +++++++++++------- tests/inkling_formatter.rs | 16 +++++++++++++++- 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6ef3eaf..2213a95 100644 --- a/README.md +++ b/README.md @@ -267,12 +267,19 @@ uses `tracing`; set `RUST_LOG` to control verbosity (default `info`). The config is the same JSON the other Strata tools use. Keys acted on here include `exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`, -`sampling`, `api_key`, `allowed_hosts`, `db_path` (GUI session database), -`workspace_root` (framework root), `system_prompt` (general default), `language` -(UI/prompt catalog, default `it`), and the optional `startup_timeout_secs` / -`silence_timeout_secs`. Everything else (`arch`, -`mcp_servers`, `cors_origins`, …) is preserved untouched and reported as ignored — -unknown keys never break startup. +`max_new` (default generation budget, see below), `sampling`, `api_key`, +`allowed_hosts`, `db_path` (GUI session database), `workspace_root` (framework +root), `system_prompt` (general default), `language` (UI/prompt catalog, default +`it`), and the optional `startup_timeout_secs` / `silence_timeout_secs`. Everything +else (`arch`, `mcp_servers`, `cors_origins`, …) is preserved untouched and reported +as ignored — unknown keys never break startup. + +**Generation budget (`max_new`).** When neither the request nor the session sets +`max_tokens`, generation is capped at `max_new` tokens (config, default **16384**). +Reasoning and answer share this ceiling: it was raised from 2048 because extended +chain-of-thought was being truncated mid-reasoning (`finish_reason: length`, empty +answer). The model still stops early at EOS, so the larger cap only matters when it +would otherwise run out; a per-session/per-request `max_tokens` still overrides it. ### Localization (i18n) diff --git a/src/api/formatter.rs b/src/api/formatter.rs index 5cb6e3e..d9fafcd 100644 --- a/src/api/formatter.rs +++ b/src/api/formatter.rs @@ -65,8 +65,10 @@ pub trait Formatter: Send + Sync { fn model_name(&self) -> &str; /// The formatter's default token budget when the request sets none. + /// Matches the project-wide generation budget (CoT + answer share it); a + /// dialect with a real tokenizer overrides this from its config. fn default_max_new(&self) -> u32 { - 2048 + 16384 } /// Token count of a text, used to route uploads (small-text inline threshold). diff --git a/src/config.rs b/src/config.rs index cbcb20f..5e65d27 100644 --- a/src/config.rs +++ b/src/config.rs @@ -77,6 +77,11 @@ pub struct Config { /// launcher's monkey-patch). #[serde(default)] pub reasoning_effort: Option, + /// Default generation budget (`max_new` tokens) when neither the request nor + /// the session sets one. Reasoning + answer share it; the default is raised + /// (16384) so chain-of-thought is not truncated mid-reasoning at the old 2048. + #[serde(default)] + pub max_new: Option, #[serde(default)] pub sampling: SamplingDefaults, @@ -263,6 +268,12 @@ impl Config { self.language.clone().unwrap_or_else(|| "it".to_string()) } + /// Effective default generation budget: config `max_new` > 16384. This is the + /// ceiling on reasoning + answer tokens when a request/session sets none. + pub fn max_new_default(&self) -> u32 { + self.max_new.unwrap_or(16384) + } + /// The top-level keys present in the file that we are not acting on — /// reported by `--check` so the shared-file contract stays visible. pub fn ignored_keys(&self) -> Vec<&str> { @@ -395,6 +406,14 @@ mod tests { assert_eq!(keys, " temperature=1.0"); } + #[test] + fn max_new_default_and_override() { + let cfg = Config::parse(REAL, "test").unwrap(); + assert_eq!(cfg.max_new_default(), 16384); // absent -> raised default + let cfg2 = Config::parse(r#"{"exe":"/x/e","max_new":8192}"#, "test").unwrap(); + assert_eq!(cfg2.max_new_default(), 8192); + } + #[test] fn timeouts_default_and_override() { let cfg = Config::parse(REAL, "test").unwrap(); diff --git a/src/inkling/formatter.rs b/src/inkling/formatter.rs index a8946e2..4bb2905 100644 --- a/src/inkling/formatter.rs +++ b/src/inkling/formatter.rs @@ -40,11 +40,19 @@ impl InklingFormatter { template, model, effort, - max_new_default: 2048, + max_new_default: 16384, default_sampling, } } + /// Override the default generation budget (config `max_new`). Reasoning and + /// answer share this ceiling; the model still stops early at EOS, so a larger + /// budget only matters when it would otherwise be truncated mid-reasoning. + pub fn with_max_new(mut self, n: u32) -> Self { + self.max_new_default = n; + self + } + /// OpenAI messages -> the JSON the template expects, normalizing the newer /// `developer` role to `system` (the template's role map has no developer). fn messages_json(req: &ChatRequest) -> Json { diff --git a/src/main.rs b/src/main.rs index 12306d5..81e0a9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -144,13 +144,16 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option) -> E return ExitCode::FAILURE; } }; - let fmt = Arc::new(InklingFormatter::new( - tok, - template, - cfg.model_name().to_string(), - cfg.reasoning_effort.clone(), - cfg.sampling.to_sampling(), - )); + let fmt = Arc::new( + InklingFormatter::new( + tok, + template, + cfg.model_name().to_string(), + cfg.reasoning_effort.clone(), + cfg.sampling.to_sampling(), + ) + .with_max_new(cfg.max_new_default()), + ); let engine = match Engine::start( &cfg.exe, @@ -252,6 +255,7 @@ fn print_plan(cfg: &Config, path: &std::path::Path, cli_host: Option<&str>, cli_ "reasoning_effort: {}", cfg.reasoning_effort.as_deref().unwrap_or("(default)") ); + println!("max_new (generation budget): {}", cfg.max_new_default()); println!( "sampling: temp={:?} top_p={:?} min_p={:?} rep_pen={:?}", cfg.sampling.temperature, diff --git a/tests/inkling_formatter.rs b/tests/inkling_formatter.rs index 4ae460c..3a12ef7 100644 --- a/tests/inkling_formatter.rs +++ b/tests/inkling_formatter.rs @@ -86,7 +86,7 @@ fn build_prompt_renders_and_encodes() { assert!(prompt.ids.contains(&text_id)); assert!(prompt.ids.contains(&2)); // "hello" assert!(prompt.ids.contains(&end_id)); - assert_eq!(prompt.max_new, 2048); // default + assert_eq!(prompt.max_new, 16384); // default (raised so CoT is not truncated) let _ = std::fs::remove_file(&path); } @@ -144,6 +144,20 @@ fn max_tokens_override_is_honored() { let _ = std::fs::remove_file(&path); } +#[test] +fn with_max_new_overrides_default_budget() { + let (fmt, _tok, path) = formatter(); + assert_eq!(fmt.default_max_new(), 16384); + let fmt = fmt.with_max_new(8192); + assert_eq!(fmt.default_max_new(), 8192); + let req: ChatRequest = serde_json::from_value( + json!({"model": "test-model", "messages": [{"role": "user", "content": "hello"}]}), + ) + .unwrap(); + assert_eq!(fmt.build_prompt(&req).unwrap().max_new, 8192); + let _ = std::fs::remove_file(&path); +} + #[test] fn decoder_emits_structured_tool_call() { let (fmt, tok, path) = formatter();