From e3ece6d35ebfb2fc62b261f7a0b06246eb6a63b9 Mon Sep 17 00:00:00 2001 From: Alexey Gusev Date: Tue, 17 Nov 2026 22:50:44 +0300 Subject: [PATCH 1/3] Add configurable Auto Mode classifier effort --- .../content/docs/reference/configuration.md | 4 + src/anthropic/schema.rs | 2 + src/config.rs | 58 ++++++++++++++ src/openai_compat/request.rs | 1 + src/providers/codex/translate/request.rs | 2 +- src/server.rs | 78 ++++++++++++++++++- tests/codex_agent_continuation.rs | 11 +++ 7 files changed, 154 insertions(+), 2 deletions(-) diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md index 08514b10..0181eaf0 100644 --- a/docs/src/content/docs/reference/configuration.md +++ b/docs/src/content/docs/reference/configuration.md @@ -15,6 +15,7 @@ These settings configure the proxy process. Claude Code client settings such as "port": 18765, "aliasProvider": "codex", "autoReviewModel": "gpt-5.6-terra", + "autoReviewEffort": "medium", "codex": { "originator": "claude-code-proxy", "userAgent": "claude-code-proxy/0.1.24", @@ -68,6 +69,7 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field | `CCP_CONFIG_DIR` | none | Platform config directory | Replaces the configuration and file-backed auth root. | | `CCP_ALIAS_PROVIDER` | `aliasProvider` | `codex` | Routes recognized Anthropic-style aliases through `codex` or `kimi`. | | `CCP_AUTO_REVIEW_MODEL` | `autoReviewModel` | `gpt-6-luna` for Codex | Routes Claude Code's non-streaming, tool-free Bash security-review classifier through a registered model. | +| `CCP_AUTO_REVIEW_EFFORT` | `autoReviewEffort` | — | Уровень рассуждения классификатора Auto Mode: `low`, `medium`, `high`, `xhigh` или `max`. | | `CCP_LOG_STDERR` | `log.stderr` | `false` | Mirrors logs to stderr when present in the environment, regardless of its value. | | `CCP_LOG_VERBOSE` | `log.verbose` | `false` | Preserves full string fields in structured logs when present, regardless of its value. | | `CCP_TRAFFIC_LOG` | none | `false` | Enables full request captures for `1`, `true`, or `yes`. | @@ -77,6 +79,8 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field Auto-review routing resolves the classifier's requested model first, not the main conversation's model. Recognized Claude aliases follow Codex/Kimi session affinity or `aliasProvider`; Grok and other providers do not establish alias affinity. Codex auto-review classifier requests use `gpt-6-luna` by default. Requests routed through other providers retain their requested model. `CCP_AUTO_REVIEW_MODEL` or `autoReviewModel` selects an explicit registered model for all detected classifier requests without changing the session's provider affinity. Normal messages, streaming requests, tool-using requests, and token counting retain their requested model. +Настройка `autoReviewEffort` действует независимо от `autoReviewModel`. Для запросов классификатора она имеет приоритет над `output_config.effort` и, в Codex, над `CCP_CODEX_EFFORT` / `codex.effort`. Допустимое значение переменной `CCP_AUTO_REVIEW_EFFORT` имеет приоритет над файлом. Пустые и недопустимые значения игнорируются; без настройки сохраняется обычный выбор уровня рассуждения. Доступные уровни зависят от модели и провайдера; например, у Cursor уровень задаётся вариантом модели. + ## Outbound proxies Outbound HTTP requests and Codex WebSocket setup inherit standard proxy environment variables when each provider client is created: diff --git a/src/anthropic/schema.rs b/src/anthropic/schema.rs index 6f35b105..7a31e5e0 100644 --- a/src/anthropic/schema.rs +++ b/src/anthropic/schema.rs @@ -11,6 +11,8 @@ pub struct MessagesRequest { pub stream: bool, #[serde(skip)] pub bypass_provider_model_override: bool, + #[serde(skip)] + pub bypass_provider_effort_override: bool, #[serde(flatten)] pub extra: serde_json::Map, } diff --git a/src/config.rs b/src/config.rs index ee1ff80a..a457a202 100644 --- a/src/config.rs +++ b/src/config.rs @@ -39,6 +39,8 @@ struct FileConfig { pub alias_provider: Option, #[serde(rename = "autoReviewModel")] pub auto_review_model: Option, + #[serde(rename = "autoReviewEffort")] + pub auto_review_effort: Option, pub log: Option, pub kimi: Option, pub codex: Option, @@ -325,6 +327,12 @@ pub fn config_override_summary_lines(cfg: &LoadedConfig) -> Vec { { out.push("CCP_AUTO_REVIEW_MODEL (env)".to_string()); } + if env + .get("CCP_AUTO_REVIEW_EFFORT") + .is_some_and(|raw| valid_auto_review_effort(raw)) + { + out.push("CCP_AUTO_REVIEW_EFFORT (env)".to_string()); + } if let Some(file_cfg) = file { if let Some(bind_address) = file_cfg.bind_address { out.push(format!("bindAddress: {bind_address}")); @@ -341,6 +349,14 @@ pub fn config_override_summary_lines(cfg: &LoadedConfig) -> Vec { { out.push("autoReviewModel (config)".to_string()); } + if file_cfg + .auto_review_effort + .as_ref() + .and_then(serde_json::Value::as_str) + .is_some_and(valid_auto_review_effort) + { + out.push("autoReviewEffort (config)".to_string()); + } if let Some(log) = file_cfg.log { if let Some(v) = log.verbose { out.push(format!("log.verbose: {v}")); @@ -900,6 +916,23 @@ pub fn auto_review_model() -> Option { .filter(|model| !model.is_empty()) } +pub fn auto_review_effort() -> Option { + std::env::var("CCP_AUTO_REVIEW_EFFORT") + .ok() + .filter(|raw| valid_auto_review_effort(raw)) + .or_else(|| { + let value = read_file_config(&paths::config_dir())?.auto_review_effort?; + value + .as_str() + .filter(|raw| valid_auto_review_effort(raw)) + .map(str::to_owned) + }) +} + +fn valid_auto_review_effort(effort: &str) -> bool { + matches!(effort, "low" | "medium" | "high" | "xhigh" | "max") +} + // --------------------------------------------------------------------------- // Codex transport config // --------------------------------------------------------------------------- @@ -1084,6 +1117,7 @@ mod tests { EnvGuard::unset("CCP_CODEX_TRANSCRIPTIONS_API"), EnvGuard::unset("CCP_CODEX_HEADER_TIMEOUT_MS"), EnvGuard::unset("CCP_AUTO_REVIEW_MODEL"), + EnvGuard::unset("CCP_AUTO_REVIEW_EFFORT"), EnvGuard::unset("CCP_GROK_CLIENT_VERSION"), ]; guards.push(EnvGuard::set("CCP_CONFIG_DIR", config.path())); @@ -1550,6 +1584,30 @@ mod tests { } } + #[test] + fn auto_review_effort_reads_top_level_config_and_env_takes_precedence() { + let _guard = ENV_LOCK.lock().unwrap(); + let config = tempfile::TempDir::new().unwrap(); + let _env = isolated_env(&config); + let path = config.path().join("config.json"); + assert_eq!(auto_review_effort(), None); + + std::fs::write(&path, r#"{"autoReviewEffort":"medium"}"#).unwrap(); + assert_eq!(auto_review_effort().as_deref(), Some("medium")); + for (raw, expected) in [("high", "high"), ("", "medium"), ("off", "medium")] { + let _effort_env = EnvGuard::set("CCP_AUTO_REVIEW_EFFORT", raw); + assert_eq!(auto_review_effort().as_deref(), Some(expected)); + } + + std::fs::write( + &path, + r#"{"autoReviewEffort":42,"autoReviewModel":"grok-4.5"}"#, + ) + .unwrap(); + assert_eq!(auto_review_effort(), None); + assert_eq!(auto_review_model().as_deref(), Some("grok-4.5")); + } + #[test] fn codex_server_compaction_defaults_and_overrides() { let _guard = ENV_LOCK.lock().unwrap(); diff --git a/src/openai_compat/request.rs b/src/openai_compat/request.rs index fac3aa6d..43b9d560 100644 --- a/src/openai_compat/request.rs +++ b/src/openai_compat/request.rs @@ -168,6 +168,7 @@ pub fn parse_request( messages, stream: true, bypass_provider_model_override: false, + bypass_provider_effort_override: false, extra, }, requested_model, diff --git a/src/providers/codex/translate/request.rs b/src/providers/codex/translate/request.rs index fea9a779..9224369a 100644 --- a/src/providers/codex/translate/request.rs +++ b/src/providers/codex/translate/request.rs @@ -589,7 +589,7 @@ fn translate_request_inner( let effort = read_effort(req)?; let codex_effort = to_codex_effort(effort); - let mut resolved_effort = if apply_codex_config { + let mut resolved_effort = if apply_codex_config && !req.bypass_provider_effort_override { resolve_effort(codex_effort)? } else { codex_effort diff --git a/src/server.rs b/src/server.rs index a12db0c8..ca731758 100644 --- a/src/server.rs +++ b/src/server.rs @@ -107,6 +107,27 @@ fn apply_auto_review_model( Some(route) } +fn apply_auto_review_effort( + body: &mut crate::anthropic::schema::MessagesRequest, + count_tokens: bool, + configured_effort: impl FnOnce() -> Option, +) { + if count_tokens || !is_claude_auto_review_request(body) { + return; + } + let Some(effort) = configured_effort() else { + return; + }; + let output_config = body.extra.entry("output_config").or_insert(Value::Null); + if output_config.is_null() { + *output_config = Value::Object(Map::new()); + } + if let Some(output_config) = output_config.as_object_mut() { + output_config.insert("effort".to_string(), Value::String(effort)); + body.bypass_provider_effort_override = true; + } +} + pub struct ServerConfig { pub bind_address: String, pub port: u16, @@ -1718,6 +1739,7 @@ async fn dispatch_request( }; body.bypass_provider_model_override = auto_review_route.is_some() && provider.name() == "codex"; + apply_auto_review_effort(&mut body, count_tokens, crate::config::auto_review_effort); if let Some(route) = auto_review_route.as_ref() { log.info( @@ -2318,7 +2340,10 @@ mod request_id_header_tests { #[cfg(test)] mod auto_review_tests { - use super::{apply_auto_review_model, headers_to_record, is_claude_auto_review_request}; + use super::{ + CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, apply_auto_review_effort, apply_auto_review_model, + headers_to_record, is_claude_auto_review_request, + }; use crate::anthropic::schema::MessagesRequest; use crate::request_identity::{CLAUDE_AGENT_HEADER, CLAUDE_PARENT_AGENT_HEADER}; use http::{HeaderMap, HeaderValue}; @@ -2365,6 +2390,57 @@ mod auto_review_tests { ))); } + #[test] + fn classifier_effort_preserves_output_format_without_a_model_override() { + let mut body = request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([])); + body.model = Some("grok-4.5".to_string()); + assert!(apply_auto_review_model(&mut body, false, None, "grok").is_none()); + let format = json!({"type": "json_schema", "schema": {"type": "object"}}); + body.extra.insert( + "output_config".to_string(), + json!({"effort": "low", "format": format}), + ); + apply_auto_review_effort(&mut body, false, || Some("high".to_string())); + assert_eq!(body.model.as_deref(), Some("grok-4.5")); + assert_eq!( + body.extra["output_config"], + json!({"effort": "high", "format": format}) + ); + assert!(body.bypass_provider_effort_override); + } + + #[test] + fn classifier_effort_does_not_change_other_requests_or_unconfigured_reviews() { + for (mut body, count_tokens) in [ + (request("An ordinary request", false, json!([])), false), + ( + request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, true, json!([])), + false, + ), + ( + request( + CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, + false, + json!([{"name": "Bash"}]), + ), + false, + ), + ( + request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([])), + true, + ), + ] { + apply_auto_review_effort(&mut body, count_tokens, || panic!("not a review message")); + assert!(!body.extra.contains_key("output_config")); + assert!(!body.bypass_provider_effort_override); + } + + let mut body = request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([])); + apply_auto_review_effort(&mut body, false, || None); + assert!(!body.extra.contains_key("output_config")); + assert!(!body.bypass_provider_effort_override); + } + #[test] fn codex_classifier_defaults_to_luna() { let mut classifier = request( diff --git a/tests/codex_agent_continuation.rs b/tests/codex_agent_continuation.rs index 68ab1168..0642b861 100644 --- a/tests/codex_agent_continuation.rs +++ b/tests/codex_agent_continuation.rs @@ -80,6 +80,7 @@ fn configure_environment(config_dir: &Path, upstream_url: &str) -> Vec "all_proxy", "REQUEST_METHOD", "CCP_AUTO_REVIEW_MODEL", + "CCP_AUTO_REVIEW_EFFORT", "CCP_CODEX_MODEL", "CCP_CODEX_SERVICE_TIER", "CCP_CODEX_EFFORT", @@ -1441,6 +1442,11 @@ async fn malformed_identity_sandwich_is_stateless_and_preserves_main() { async fn auto_review_with_agent_headers_is_stateless() { let _environment_lock = env_lock(); let mut harness = TestHarness::start().await; + std::fs::write( + harness._config_dir.path().join("config.json"), + r#"{"autoReviewEffort":"medium","codex":{"effort":"high"}}"#, + ) + .unwrap(); let case = unique("auto-review"); let session = tagged(&case, "session"); let headers = IdentityHeaders::agent(&session, &tagged(&case, "agent-a"), None); @@ -1471,6 +1477,7 @@ async fn auto_review_with_agent_headers_is_stateless() { "text": review_system }], "messages": [{"role": "user", "content": review}], + "output_config": {"effort": "low", "format": {"type": "json_object"}}, "tools": [] }), headers.clone(), @@ -1502,6 +1509,10 @@ async fn auto_review_with_agent_headers_is_stateless() { &[("developer", review_system), ("user", &review)], ); assert_eq!(classifier.body["model"], "gpt-6-luna"); + assert_eq!(classifier.body["reasoning"]["effort"], "medium"); + assert_eq!(classifier.body["text"]["format"]["type"], "json_object"); + assert_eq!(first.body["reasoning"]["effort"], "high"); + assert_eq!(second.body["reasoning"]["effort"], "high"); assert_eq!(first.socket_ordinal, 1); assert_eq!(classifier.socket_ordinal, 2); assert_delta_input(&second, &a_response, first.socket_ordinal, &a2); From c8554d2da7230e6c917a6216fb75bc0fdbd1e933 Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Sat, 21 Nov 2026 12:27:08 +0200 Subject: [PATCH 2/3] docs: clarify classifier effort precedence in english Keep the configuration reference readable in its working language and explain how invalid classifier settings fall back to normal resolution. --- docs/src/content/docs/reference/configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md index 0181eaf0..3a109081 100644 --- a/docs/src/content/docs/reference/configuration.md +++ b/docs/src/content/docs/reference/configuration.md @@ -69,7 +69,7 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field | `CCP_CONFIG_DIR` | none | Platform config directory | Replaces the configuration and file-backed auth root. | | `CCP_ALIAS_PROVIDER` | `aliasProvider` | `codex` | Routes recognized Anthropic-style aliases through `codex` or `kimi`. | | `CCP_AUTO_REVIEW_MODEL` | `autoReviewModel` | `gpt-6-luna` for Codex | Routes Claude Code's non-streaming, tool-free Bash security-review classifier through a registered model. | -| `CCP_AUTO_REVIEW_EFFORT` | `autoReviewEffort` | — | Уровень рассуждения классификатора Auto Mode: `low`, `medium`, `high`, `xhigh` или `max`. | +| `CCP_AUTO_REVIEW_EFFORT` | `autoReviewEffort` | — | Sets the Auto Mode classifier's reasoning effort to `low`, `medium`, `high`, `xhigh`, or `max`. | | `CCP_LOG_STDERR` | `log.stderr` | `false` | Mirrors logs to stderr when present in the environment, regardless of its value. | | `CCP_LOG_VERBOSE` | `log.verbose` | `false` | Preserves full string fields in structured logs when present, regardless of its value. | | `CCP_TRAFFIC_LOG` | none | `false` | Enables full request captures for `1`, `true`, or `yes`. | @@ -79,7 +79,7 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field Auto-review routing resolves the classifier's requested model first, not the main conversation's model. Recognized Claude aliases follow Codex/Kimi session affinity or `aliasProvider`; Grok and other providers do not establish alias affinity. Codex auto-review classifier requests use `gpt-6-luna` by default. Requests routed through other providers retain their requested model. `CCP_AUTO_REVIEW_MODEL` or `autoReviewModel` selects an explicit registered model for all detected classifier requests without changing the session's provider affinity. Normal messages, streaming requests, tool-using requests, and token counting retain their requested model. -Настройка `autoReviewEffort` действует независимо от `autoReviewModel`. Для запросов классификатора она имеет приоритет над `output_config.effort` и, в Codex, над `CCP_CODEX_EFFORT` / `codex.effort`. Допустимое значение переменной `CCP_AUTO_REVIEW_EFFORT` имеет приоритет над файлом. Пустые и недопустимые значения игнорируются; без настройки сохраняется обычный выбор уровня рассуждения. Доступные уровни зависят от модели и провайдера; например, у Cursor уровень задаётся вариантом модели. +Classifier effort is independent of model selection. A valid `CCP_AUTO_REVIEW_EFFORT` takes precedence over `autoReviewEffort` in the config file. Either overrides the classifier's `output_config.effort` and, on Codex, the global `CCP_CODEX_EFFORT` or `codex.effort`. Empty or invalid values are ignored. If neither setting is valid, normal effort selection applies. Supported levels depend on the provider and model; Cursor, for example, selects effort through its model variant. ## Outbound proxies From 05b20afa1b4522538c3d0e6887cfce3be9c70996 Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Sat, 21 Nov 2026 12:27:32 +0200 Subject: [PATCH 3/3] test classifier schema preservation on the codex wire A format type alone cannot detect a dropped schema. Check the full structured decision format alongside the classifier effort override and the ordinary requests on either side of it. --- tests/codex_agent_continuation.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/codex_agent_continuation.rs b/tests/codex_agent_continuation.rs index 0642b861..61de426c 100644 --- a/tests/codex_agent_continuation.rs +++ b/tests/codex_agent_continuation.rs @@ -1447,6 +1447,12 @@ async fn auto_review_with_agent_headers_is_stateless() { r#"{"autoReviewEffort":"medium","codex":{"effort":"high"}}"#, ) .unwrap(); + let schema = json!({ + "type": "object", + "properties": {"allow": {"type": "boolean"}}, + "required": ["allow"], + "additionalProperties": false + }); let case = unique("auto-review"); let session = tagged(&case, "session"); let headers = IdentityHeaders::agent(&session, &tagged(&case, "agent-a"), None); @@ -1477,7 +1483,10 @@ async fn auto_review_with_agent_headers_is_stateless() { "text": review_system }], "messages": [{"role": "user", "content": review}], - "output_config": {"effort": "low", "format": {"type": "json_object"}}, + "output_config": { + "effort": "low", + "format": {"type": "json_schema", "name": "decision", "schema": schema} + }, "tools": [] }), headers.clone(), @@ -1510,7 +1519,10 @@ async fn auto_review_with_agent_headers_is_stateless() { ); assert_eq!(classifier.body["model"], "gpt-6-luna"); assert_eq!(classifier.body["reasoning"]["effort"], "medium"); - assert_eq!(classifier.body["text"]["format"]["type"], "json_object"); + assert_eq!( + classifier.body["text"]["format"], + json!({"type": "json_schema", "name": "decision", "schema": schema, "strict": true}) + ); assert_eq!(first.body["reasoning"]["effort"], "high"); assert_eq!(second.body["reasoning"]["effort"], "high"); assert_eq!(first.socket_ordinal, 1);