Skip to content

Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.

fix(gateway): preserve thinking display and Claude continuation (#61)

澄潭bdb1c1d6121d
diff --git a/crates/gateway/README.md b/crates/gateway/README.md
index 62719562..9fe00a41 100644
--- a/crates/gateway/README.md
+++ b/crates/gateway/README.md
@@ -9,6 +9,15 @@ branch decision, plan and freeze candidates, then admit execution into
`hiroute-gateway-core`. The core owns attempts, response commit, cancellation and
resource cleanup; the Gateway does not run a second execution loop.
+Messages thinking computation is projected in
+[request/native.rs](src/adapters/request/native.rs); request-local `thinking.display`
+is resolved by [ingress.rs](src/adapters/ingress.rs) before Replay externalization.
+[Native response projection](src/adapters/response/native_passthrough.rs) preserves
+signatures and usage while enforcing omitted text. Cross-protocol Messages
+renderers omit foreign reasoning without inventing signatures. The
+[production protocol matrix](../../tools/e2e-harness/tests/p0_gateway_protocol/production_matrix.rs)
+covers the listener boundary, including tool continuation.
+
## Decision operation
[core_runtime/classification.rs](src/core_runtime/classification.rs) owns the
diff --git a/crates/gateway/src/adapters/ingress.rs b/crates/gateway/src/adapters/ingress.rs
index 38b1d140..be17d8b7 100644
--- a/crates/gateway/src/adapters/ingress.rs
+++ b/crates/gateway/src/adapters/ingress.rs
@@ -509,13 +509,19 @@ fn decode_messages(
validate_messages_metadata(context, object.get("metadata"))?;
validate_messages_context_management(context, object.get("context_management"))?;
for (key, fields) in [
- ("thinking", &["type", "budget_tokens"][..]),
+ ("thinking", &["type", "budget_tokens", "display"][..]),
("output_config", &["effort", "format"][..]),
] {
if let Some(value) = object.get(key) {
checked_object(context, value, fields, "messages reasoning control")?;
}
}
+ let omit_thinking =
+ body.pointer("/thinking/display").and_then(Value::as_str) == Some("omitted");
+ if body.pointer("/thinking/display").is_some() && !omit_thinking {
+ // Only omitted has a defined cross-protocol return-content mapping.
+ context.native_only.set(true);
+ }
if body.pointer("/output_config/format").is_some()
&& super::structured_output::messages_schema_format(body).is_none()
{
@@ -549,13 +555,14 @@ fn decode_messages(
MessageRole::User | MessageRole::Assistant => messages.push(message),
}
}
- let requested_reasoning = match (object.get("thinking"), object.get("output_config")) {
+ let mut requested_reasoning = match (object.get("thinking"), object.get("output_config")) {
(None, None) => RequestedReasoningControl::absent(),
(thinking, output_config) => RequestedReasoningControl::overridden(serde_json::json!({
"thinking": thinking.cloned(),
"output_config": output_config.cloned(),
})),
};
+ requested_reasoning.messages_omit_thinking = omit_thinking;
Ok(ModelRequestIRV1 {
native_body: None,
native_only: false,
@@ -663,9 +670,20 @@ fn decode_messages_content(
ensure_keys(
context,
object,
- &["type", "id", "name", "input", "cache_control"],
+ &["type", "id", "name", "input", "cache_control", "caller"],
"messages tool_use",
)?;
+ if let Some(caller) = object.get("caller") {
+ let caller =
+ checked_object(context, caller, &["type"], "messages tool_use caller")?;
+ // Direct calls retain ordinary tool semantics. Programmatic callers carry
+ // execution authority that cannot be silently dropped during projection.
+ if required_string(caller, "type")? != "direct" {
+ return Err(ModelIrError::UnsupportedValue(
+ "messages tool_use caller type".into(),
+ ));
+ }
+ }
validate_messages_cache_control(context, object.get("cache_control"))?;
Ok(ContentPart::ToolCall {
logical_id: required_string(object, "id")?,
diff --git a/crates/gateway/src/adapters/native_reasoning_tests.rs b/crates/gateway/src/adapters/native_reasoning_tests.rs
index 928250cb..983d32de 100644
--- a/crates/gateway/src/adapters/native_reasoning_tests.rs
+++ b/crates/gateway/src/adapters/native_reasoning_tests.rs
@@ -6,6 +6,47 @@ use crate::server::core_runtime::profiles::{
};
use crate::server::request_plan::IngressProtocol;
use serde_json::json;
+
+fn display_request() -> serde_json::Value {
+ json!({"model":"alias", "max_tokens":2048,
+ "messages":[{"role":"user","content":"hello"}],
+ "thinking":{"type":"enabled","budget_tokens":1024,"display":"omitted"},
+ "output_config":{"format":{"type":"json_schema","schema":{"type":"object","properties":{"ok":{"type":"boolean"}}}}}})
+}
+
+#[test]
+fn thinking_display_plan_default_never_emits_display_only_object() {
+ let body = display_request();
+ let request = decode_ingress_request(IngressProtocol::Messages, &body).unwrap();
+ let profile = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Messages,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ let native = project_candidate_request(&request, &profile).unwrap();
+ assert!(native.body.get("thinking").is_none(), "{}", native.body);
+ assert_eq!(
+ native.body["output_config"]["format"],
+ body["output_config"]["format"]
+ );
+}
+
+#[test]
+fn thinking_display_omitted_can_cross_protocol_without_disabling_reasoning() {
+ let request = decode_ingress_request(IngressProtocol::Messages, &display_request()).unwrap();
+ for upstream in [IngressProtocol::ChatCompletions, IngressProtocol::Responses] {
+ let profile = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ upstream,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ let native = project_candidate_request(&request, &profile).unwrap();
+ assert!(native.body.get("thinking").is_none());
+ assert!(native.body.get("reasoning_effort").is_none());
+ }
+}
#[test]
fn messages_adaptive_effort_overwrites_caller_disabled_thinking_and_effort() {
let request = decode_ingress_request(
@@ -41,3 +82,160 @@ fn messages_adaptive_effort_overwrites_caller_disabled_thinking_and_effort() {
assert_eq!(native.body["thinking"], json!({"type":"adaptive"}));
assert_eq!(native.body["output_config"], json!({"effort":"high"}));
}
+
+fn display_profile(mode: &str) -> CandidateProtocolProfile {
+ let mut reasoning = fixed_reasoning(mode);
+ reasoning.control_kind = ReasoningControlKind::Discrete;
+ let mut fields = vec![NativeReasoningFieldAssignment {
+ path: vec!["thinking".into(), "type".into()],
+ value: NativeReasoningValue::String(mode.into()),
+ }];
+ if mode == "enabled" {
+ fields.push(NativeReasoningFieldAssignment {
+ path: vec!["thinking".into(), "budget_tokens".into()],
+ value: NativeReasoningValue::U64(128),
+ });
+ }
+ reasoning.render = NativeReasoningRender::ExactFields {
+ protocol: IngressProtocol::Messages,
+ fields,
+ };
+ CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Messages,
+ "physical",
+ reasoning,
+ )
+}
+
+#[test]
+fn thinking_display_plan_modes_use_only_plan_budget_and_preserve_format() {
+ let body = display_request();
+ let request = decode_ingress_request(IngressProtocol::Messages, &body).unwrap();
+ for (mode, expected) in [
+ ("disabled", json!({"type":"disabled"})),
+ ("adaptive", json!({"type":"adaptive","display":"omitted"})),
+ (
+ "enabled",
+ json!({"type":"enabled","budget_tokens":128,"display":"omitted"}),
+ ),
+ ] {
+ let native = project_candidate_request(&request, &display_profile(mode)).unwrap();
+ assert_eq!(native.body["thinking"], expected);
+ assert_eq!(
+ native.body["output_config"]["format"],
+ body["output_config"]["format"]
+ );
+ }
+ assert_eq!(request.native_body.as_ref().unwrap(), &body);
+}
+
+#[test]
+fn thinking_display_fixed_preserves_native_controls_and_unknown_values_stay_bounded() {
+ use crate::server::core_runtime::model_ir::RequestedReasoningDisposition;
+ for display in [
+ json!("omitted"),
+ json!("summarized"),
+ json!("future-mode"),
+ json!(42),
+ json!(null),
+ ] {
+ let mut body = display_request();
+ body["thinking"]["display"] = display.clone();
+ let mut request = decode_ingress_request(IngressProtocol::Messages, &body).unwrap();
+ assert_eq!(request.native_only, display != "omitted");
+ request.requested_reasoning.disposition =
+ RequestedReasoningDisposition::AppliedToFixedBinding;
+ let native = project_candidate_request(&request, &display_profile("disabled")).unwrap();
+ assert_eq!(native.body["thinking"], body["thinking"]);
+ request.requested_reasoning.disposition =
+ RequestedReasoningDisposition::OverriddenByAgentPlan;
+ if display != "omitted" {
+ let native = project_candidate_request(&request, &display_profile("adaptive")).unwrap();
+ assert_eq!(native.body["thinking"]["display"], display);
+ assert!(project_candidate_request(&request, &display_profile("disabled")).is_err());
+ for upstream in [IngressProtocol::ChatCompletions, IngressProtocol::Responses] {
+ let profile = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ upstream,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ assert!(project_candidate_request(&request, &profile).is_err());
+ }
+ }
+ }
+}
+
+#[test]
+fn thinking_display_does_not_allow_unrelated_extensions_to_cross_protocol() {
+ let mut body = display_request();
+ body["thinking"]["future_control"] = json!(true);
+ let request = decode_ingress_request(IngressProtocol::Messages, &body).unwrap();
+ assert!(request.native_only);
+ let native_default = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Messages,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ assert!(project_candidate_request(&request, &native_default).is_err());
+ let adaptive = project_candidate_request(&request, &display_profile("adaptive")).unwrap();
+ assert_eq!(adaptive.body["thinking"]["future_control"], true);
+ assert_eq!(adaptive.body["thinking"]["display"], "omitted");
+ let profile = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::ChatCompletions,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ assert!(project_candidate_request(&request, &profile).is_err());
+}
+
+#[test]
+fn thinking_display_policy_survives_replay_externalization() {
+ use crate::{
+ content_ref::externalize_model_request,
+ replay::{ReplayConfig, ReplayManager},
+ };
+ use hiroute_gateway_core::runtime::body::BudgetTree;
+ let root = std::env::temp_dir().join(format!(
+ "hiroute-thinking-display-{}-{}",
+ std::process::id(),
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap()
+ .as_nanos()
+ ));
+ let manager = ReplayManager::open(ReplayConfig {
+ root: root.clone(),
+ memory_threshold_bytes: 128,
+ record_bytes: 31,
+ orphan_ttl: std::time::Duration::from_secs(60),
+ })
+ .unwrap();
+ let budget = BudgetTree::new(1024 * 1024, 1024 * 1024)
+ .unwrap()
+ .stream(1024 * 1024)
+ .unwrap();
+ let store = manager.begin_request(budget).unwrap();
+ let mut request =
+ decode_ingress_request(IngressProtocol::Messages, &display_request()).unwrap();
+ externalize_model_request(&mut request, &store, 0).unwrap();
+ assert!(request.requested_reasoning.messages_omit_thinking);
+ assert_ne!(
+ request.native_body.as_ref().unwrap()["thinking"]["display"],
+ "omitted"
+ );
+ assert!(project_candidate_request_template(&request, &display_profile("disabled")).is_ok());
+ let serialized = serde_json::to_value(&request).unwrap();
+ assert!(
+ serialized["requested_reasoning"]
+ .get("messages_omit_thinking")
+ .is_none()
+ );
+ drop(request);
+ drop(store);
+ drop(manager);
+ std::fs::remove_dir_all(root).unwrap();
+}
diff --git a/crates/gateway/src/adapters/request/native.rs b/crates/gateway/src/adapters/request/native.rs
index f2462097..f2a5edd9 100644
--- a/crates/gateway/src/adapters/request/native.rs
+++ b/crates/gateway/src/adapters/request/native.rs
@@ -111,6 +111,12 @@ pub(super) fn project(
remove_assignment(object, &field.path);
}
render_reasoning(object, reasoning, request.ingress_protocol)?;
+ if request.ingress_protocol == IngressProtocol::Messages {
+ normalize_messages_thinking(
+ object,
+ request.requested_reasoning.messages_omit_thinking,
+ )?;
+ }
}
// Preserve the existing Claude instruction-reminder normalization.
@@ -152,6 +158,46 @@ pub(super) fn project(
Ok(body)
}
+fn normalize_messages_thinking(
+ object: &mut Map<String, Value>,
+ omit_thinking: bool,
+) -> Result<(), ProtocolAdapterError> {
+ let Some(thinking) = object.get_mut("thinking").and_then(Value::as_object_mut) else {
+ return Ok(());
+ };
+ match thinking.get("type").and_then(Value::as_str) {
+ Some("enabled") => (),
+ Some("adaptive") => {
+ thinking.remove("budget_tokens");
+ }
+ None | Some("disabled") => {
+ thinking.remove("budget_tokens");
+ if thinking.contains_key("display") {
+ if !omit_thinking {
+ return Err(ProtocolAdapterError::ClientUnrepresentable(
+ "thinking.display cannot be preserved with the selected Plan mode".into(),
+ ));
+ }
+ thinking.remove("display");
+ }
+ }
+ Some(_) if thinking.contains_key("display") => {
+ return Err(ProtocolAdapterError::ClientUnrepresentable(
+ "thinking.display has no mapping for the selected Plan mode".into(),
+ ));
+ }
+ Some(_) => (),
+ }
+ if thinking.is_empty() {
+ object.remove("thinking");
+ } else if omit_thinking && !thinking.contains_key("type") {
+ return Err(ProtocolAdapterError::ClientUnrepresentable(
+ "thinking extensions require a selected Plan thinking mode".into(),
+ ));
+ }
+ Ok(())
+}
+
fn append_instruction_blocks(
blocks: &mut Vec<Value>,
value: Option<&Value>,
diff --git a/crates/gateway/src/adapters/response/mod.rs b/crates/gateway/src/adapters/response/mod.rs
index 061a4b8a..c05dd34b 100644
--- a/crates/gateway/src/adapters/response/mod.rs
+++ b/crates/gateway/src/adapters/response/mod.rs
@@ -18,6 +18,8 @@ mod wire;
mod native_passthrough_tests;
#[cfg(test)]
mod native_reasoning_tests;
+#[cfg(test)]
+mod service_tier_tests;
#[cfg(test)]
mod size_tests;
diff --git a/crates/gateway/src/adapters/response/native_passthrough.rs b/crates/gateway/src/adapters/response/native_passthrough.rs
index 6310a73f..fd3b8bdf 100644
--- a/crates/gateway/src/adapters/response/native_passthrough.rs
+++ b/crates/gateway/src/adapters/response/native_passthrough.rs
@@ -58,6 +58,11 @@ pub(crate) struct NativeResponseProjector {
}
impl NativeResponseProjector {
+ pub(crate) fn with_omitted_thinking(mut self, omitted: bool) -> Self {
+ self.state.omit_thinking = omitted && self.state.protocol == IngressProtocol::Messages;
+ self
+ }
+
pub(crate) fn new_for_attempt(
profile: &CandidateProtocolProfile,
streaming: bool,
@@ -161,6 +166,7 @@ impl NativeResponseProjector {
budget: budget.clone(),
framer,
state: ProjectionState {
+ omit_thinking: false,
protocol: profile.capability.upstream_protocol,
alias: served_model_alias,
owner: profile.exact_provider_path()?,
@@ -293,6 +299,7 @@ struct ResponseItemEvidence {
}
pub(super) struct ProjectionState {
+ omit_thinking: bool,
pub(super) protocol: IngressProtocol,
alias: String,
owner: ExactProviderPathV1,
@@ -333,11 +340,15 @@ impl ProjectionState {
value: &mut Value,
) -> Result<ProjectionMetadata, ProtocolAdapterError> {
let object = value.as_object_mut().ok_or(ModelIrError::ExpectedObject)?;
- match self.protocol {
+ let metadata = match self.protocol {
IngressProtocol::Responses => self.project_responses_nonstream(object),
IngressProtocol::ChatCompletions => self.project_chat_nonstream(object),
IngressProtocol::Messages => self.project_messages_nonstream(object),
+ }?;
+ if self.omit_thinking {
+ omit_messages_thinking_text(value);
}
+ Ok(metadata)
}
pub(super) fn project_sse(
@@ -405,6 +416,9 @@ impl ProjectionState {
metadata.terminal = None;
metadata.failure = None;
}
+ if self.omit_thinking {
+ omit_messages_thinking_text(&mut value);
+ }
let changed = value
!= serde_json::from_slice::<Value>(data)
.map_err(|error| ModelIrError::InvalidJson(error.to_string()))?;
diff --git a/crates/gateway/src/adapters/response/native_passthrough_helpers.rs b/crates/gateway/src/adapters/response/native_passthrough_helpers.rs
index 57f1b566..512f3ee2 100644
--- a/crates/gateway/src/adapters/response/native_passthrough_helpers.rs
+++ b/crates/gateway/src/adapters/response/native_passthrough_helpers.rs
@@ -302,3 +302,38 @@ pub(super) fn loose_error(value: &Value) -> ModelError {
.and_then(Value::as_bool),
}
}
+
+/// Display is independent of computation: preserve block identity, signature,
+/// redacted state, usage and all non-thinking content, changing only text.
+pub(super) fn omit_messages_thinking_text(value: &mut Value) {
+ fn clear_text(value: &mut Value, kind: &str) {
+ if value.get("type").and_then(Value::as_str) == Some(kind)
+ && let Some(text) = value.get_mut("thinking")
+ {
+ *text = Value::String(String::new());
+ }
+ }
+ if let Some(content) = value.get_mut("content").and_then(Value::as_array_mut) {
+ for part in content {
+ clear_text(part, "thinking");
+ }
+ }
+ match value.get("type").and_then(Value::as_str) {
+ Some("message_start") => {
+ if let Some(message) = value.get_mut("message") {
+ omit_messages_thinking_text(message);
+ }
+ }
+ Some("content_block_start") => {
+ if let Some(part) = value.get_mut("content_block") {
+ clear_text(part, "thinking");
+ }
+ }
+ Some("content_block_delta") => {
+ if let Some(delta) = value.get_mut("delta") {
+ clear_text(delta, "thinking_delta");
+ }
+ }
+ _ => (),
+ }
+}
diff --git a/crates/gateway/src/adapters/response/native_reasoning_tests.rs b/crates/gateway/src/adapters/response/native_reasoning_tests.rs
index 1c691ee8..d70da348 100644
--- a/crates/gateway/src/adapters/response/native_reasoning_tests.rs
+++ b/crates/gateway/src/adapters/response/native_reasoning_tests.rs
@@ -101,3 +101,166 @@ fn failed_response_preserves_reported_usage() {
assert_eq!(projector.usage().input_tokens, Some(100));
assert_eq!(projector.usage().output_tokens, Some(2));
}
+
+fn messages_projector(streaming: bool, omitted: bool) -> NativeResponseProjector {
+ let profile = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Messages,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ NativeResponseProjector::new_for_observation(
+ &profile,
+ streaming,
+ "alias".into(),
+ None,
+ crate::server::core_runtime::adapters::ToolIdProjection::new(IngressProtocol::Messages),
+ )
+ .unwrap()
+ .with_omitted_thinking(omitted)
+}
+
+#[test]
+fn thinking_display_native_json_preserves_state_tools_and_usage() {
+ let original = json!({"id":"msg","type":"message","role":"assistant","model":"physical",
+ "content":[{"type":"thinking","thinking":"private thought","signature":"opaque-signature"},
+ {"type":"redacted_thinking","data":"opaque-state"},
+ {"type":"text","text":"answer"},
+ {"type":"tool_use","id":"tool_1","name":"probe","input":{"value":1}}],
+ "stop_reason":"tool_use","usage":{"input_tokens":7,"output_tokens":19}});
+ for omitted in [false, true] {
+ let mut projector = messages_projector(false, omitted);
+ let units = projector
+ .feed(&serde_json::to_vec(&original).unwrap(), true)
+ .unwrap();
+ let body: Value = serde_json::from_slice(&units[0].bytes).unwrap();
+ assert_eq!(
+ body["content"][0]["thinking"],
+ if omitted { "" } else { "private thought" }
+ );
+ assert_eq!(body["content"][0]["signature"], "opaque-signature");
+ assert_eq!(body["content"][1], original["content"][1]);
+ assert_eq!(body["content"][2], original["content"][2]);
+ assert_eq!(body["content"][3]["name"], "probe");
+ assert_eq!(body["content"][3]["input"], json!({"value":1}));
+ assert!(!body["content"][3]["id"].as_str().unwrap().is_empty());
+ assert_eq!(body["usage"], original["usage"]);
+ assert_eq!(projector.usage().output_tokens, Some(19));
+ assert_eq!(units[0].terminal, Some(NativeTerminalOutcome::Complete));
+ }
+}
+
+#[test]
+fn thinking_display_fragmented_sse_retains_signature_tool_lifecycle_and_usage() {
+ let events = vec![
+ json!({"type":"message_start","message":{"id":"msg","type":"message","role":"assistant","model":"physical","content":[],"usage":{"input_tokens":7,"output_tokens":0}}}),
+ json!({"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"private start"}}),
+ json!({"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"private delta"}}),
+ json!({"type":"content_block_delta","index":0,"delta":{"type":"signature_delta","signature":"opaque-signature"}}),
+ json!({"type":"content_block_stop","index":0}),
+ json!({"type":"content_block_start","index":1,"content_block":{"type":"redacted_thinking","data":"opaque-state"}}),
+ json!({"type":"content_block_stop","index":1}),
+ json!({"type":"content_block_start","index":2,"content_block":{"type":"text","text":""}}),
+ json!({"type":"content_block_delta","index":2,"delta":{"type":"text_delta","text":"answer"}}),
+ json!({"type":"content_block_stop","index":2}),
+ json!({"type":"content_block_start","index":3,"content_block":{"type":"tool_use","id":"tool_1","name":"probe","input":{}}}),
+ json!({"type":"content_block_delta","index":3,"delta":{"type":"input_json_delta","partial_json":"{\"value\":1}"}}),
+ json!({"type":"content_block_stop","index":3}),
+ json!({"type":"message_delta","delta":{"stop_reason":"tool_use"},"usage":{"output_tokens":19}}),
+ json!({"type":"message_stop"}),
+ ];
+ let input: Vec<u8> = events.iter().flat_map(|v| wire(v.clone())).collect();
+ for omitted in [false, true] {
+ let mut projector = messages_projector(true, omitted);
+ let mut units = Vec::new();
+ for chunk in input.chunks(7) {
+ units.extend(projector.feed(chunk, false).unwrap());
+ }
+ units.extend(projector.feed(&[], true).unwrap());
+ let output: Vec<u8> = units.iter().flat_map(|u| u.bytes.clone()).collect();
+ let text = String::from_utf8(output).unwrap();
+ assert_eq!(text.contains("private start"), !omitted);
+ assert_eq!(text.contains("private delta"), !omitted);
+ assert!(text.contains("opaque-signature") && text.contains("opaque-state"));
+ assert!(text.contains("answer") && text.contains("probe"));
+ let projected: Vec<Value> = text
+ .lines()
+ .filter_map(|l| l.strip_prefix("data: "))
+ .map(|s| serde_json::from_str(s).unwrap())
+ .collect();
+ assert_eq!(projected.len(), events.len());
+ assert_eq!(projected[3], events[3]);
+ assert_eq!(projected[11], events[11]);
+ assert_eq!(projected[13], events[13]);
+ assert_eq!(projector.usage().input_tokens, Some(7));
+ assert_eq!(projector.usage().output_tokens, Some(19));
+ assert_eq!(
+ units.last().unwrap().terminal,
+ Some(NativeTerminalOutcome::Complete)
+ );
+ }
+}
+
+#[test]
+fn thinking_display_cross_protocol_messages_omit_text_but_keep_tools_and_usage() {
+ use super::{
+ ClientResponseRenderer, IncrementalClientSseRenderer, NativeResponseDecoder,
+ RenderedClientResponse,
+ };
+ use crate::server::core_runtime::profiles::ClientProtocolProfile;
+ for (upstream, document) in [
+ (
+ IngressProtocol::ChatCompletions,
+ json!({"id":"r","model":"physical",
+ "choices":[{"index":0,"message":{"role":"assistant","content":"answer","reasoning_content":"private thought",
+ "tool_calls":[{"id":"tool_1","type":"function","function":{"name":"probe","arguments":"{\"value\":1}"}}]},"finish_reason":"tool_calls"}],
+ "usage":{"prompt_tokens":7,"completion_tokens":19,"total_tokens":26,"completion_tokens_details":{"reasoning_tokens":10}}}),
+ ),
+ (
+ IngressProtocol::Responses,
+ json!({"id":"r","model":"physical","status":"completed",
+ "output":[{"type":"reasoning","id":"reason","summary":[{"type":"summary_text","text":"private thought"}],"encrypted_content":"opaque-state"},
+ {"type":"message","id":"msg","role":"assistant","status":"completed","content":[{"type":"output_text","text":"answer","annotations":[]}]},
+ {"type":"function_call","id":"fc","call_id":"tool_1","name":"probe","arguments":"{\"value\":1}","status":"completed"}],
+ "usage":{"input_tokens":7,"output_tokens":19,"total_tokens":26,"output_tokens_details":{"reasoning_tokens":10}}}),
+ ),
+ ] {
+ let candidate = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ upstream,
+ "physical",
+ fixed_reasoning("default"),
+ );
+ let profile = ClientProtocolProfile::for_candidate(&candidate).unwrap();
+ let mut decoder = NativeResponseDecoder::new(&candidate, 200, false).unwrap();
+ decoder
+ .feed(&serde_json::to_vec(&document).unwrap(), true)
+ .unwrap();
+ let decoded = decoder.finish().unwrap();
+ let RenderedClientResponse::Json { body, .. } =
+ ClientResponseRenderer::render_nonstream_with_profile(
+ &profile,
+ "alias",
+ &decoded.response,
+ )
+ .unwrap()
+ else {
+ panic!("JSON expected")
+ };
+ assert!(!body.to_string().contains("private thought"));
+ assert!(body.to_string().contains("answer") && body.to_string().contains("probe"));
+ assert!(!body.to_string().contains("signature"));
+ assert_eq!(body["usage"]["output_tokens"], 19);
+ assert_eq!(body["usage"]["input_tokens"], 7);
+ let mut renderer = IncrementalClientSseRenderer::new(profile, "alias").unwrap();
+ let mut output = Vec::new();
+ for event in &decoded.events {
+ output.extend(renderer.push(event).unwrap());
+ }
+ let text: String = output.iter().map(|event| event.data.to_string()).collect();
+ assert!(!text.contains("private thought") && !text.contains("signature"));
+ assert!(text.contains("answer") && text.contains("probe") && text.contains("message_stop"));
+ assert_eq!(renderer.usage().output_tokens, Some(19));
+ assert_eq!(renderer.usage().reasoning_tokens, Some(10));
+ }
+}
diff --git a/crates/gateway/src/adapters/response/protocols.rs b/crates/gateway/src/adapters/response/protocols.rs
index f45288ba..4915c829 100644
--- a/crates/gateway/src/adapters/response/protocols.rs
+++ b/crates/gateway/src/adapters/response/protocols.rs
@@ -779,7 +779,7 @@ fn decode_chat_sse(
output,
)?;
reject_non_null(object, "system_fingerprint")?;
- reject_non_null(object, "service_tier")?;
+ let _ = optional_str(object, "service_tier")?;
if let Some(usage) = object.get("usage")
&& !usage.is_null()
{
@@ -1038,7 +1038,7 @@ fn decode_chat_nonstream(
],
)?;
reject_non_null(object, "system_fingerprint")?;
- reject_non_null(object, "service_tier")?;
+ let _ = optional_str(object, "service_tier")?;
core.start_response(
required_str(object, "id")?.into(),
required_str(object, "model")?.into(),
diff --git a/crates/gateway/src/adapters/response/render.rs b/crates/gateway/src/adapters/response/render.rs
index 8e7e3ea8..916300f7 100644
--- a/crates/gateway/src/adapters/response/render.rs
+++ b/crates/gateway/src/adapters/response/render.rs
@@ -942,11 +942,9 @@ fn validate_projection(
"client protocol cannot represent cache-write usage".into(),
));
}
- IngressProtocol::Messages if response.usage.reasoning_tokens.is_some() => {
- return Err(ProtocolAdapterError::ClientUnrepresentable(
- "Messages cannot represent reasoning-token usage".into(),
- ));
- }
+ // Messages has no separate reasoning-token counter. As in the
+ // incremental renderer, retain the billable output total; the canonical
+ // usage still records its reasoning breakdown for observation.
_ => {}
}
if protocol == IngressProtocol::ChatCompletions {
diff --git a/crates/gateway/src/adapters/response/service_tier_tests.rs b/crates/gateway/src/adapters/response/service_tier_tests.rs
new file mode 100644
index 00000000..ea6fb181
--- /dev/null
+++ b/crates/gateway/src/adapters/response/service_tier_tests.rs
@@ -0,0 +1,158 @@
+use super::*;
+use crate::server::core_runtime::profiles::{
+ CandidateProtocolProfile, ClientProtocolProfile, fixed_reasoning,
+};
+use serde_json::{Value, json};
+
+fn candidate() -> CandidateProtocolProfile {
+ CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::ChatCompletions,
+ "physical",
+ fixed_reasoning("default"),
+ )
+}
+
+fn response() -> Value {
+ json!({"id":"r","model":"physical","service_tier":"default",
+ "choices":[{"index":0,"message":{"role":"assistant","content":"answer",
+ "tool_calls":[{"id":"call_1","type":"function","function":{"name":"probe","arguments":"{\"value\":1}"}}]},"finish_reason":"tool_calls"}],
+ "usage":{"prompt_tokens":7,"completion_tokens":19,"total_tokens":26}})
+}
+
+#[test]
+fn chat_service_tier_json_keeps_answer_tools_and_usage() {
+ for tier in [
+ Value::Null,
+ json!("default"),
+ json!("priority"),
+ json!("provider-future-tier"),
+ ] {
+ let mut document = response();
+ document["service_tier"] = tier;
+ let profile = candidate();
+ let mut decoder = NativeResponseDecoder::new(&profile, 200, false).unwrap();
+ decoder
+ .feed(&serde_json::to_vec(&document).unwrap(), true)
+ .unwrap();
+ let decoded = decoder.finish().unwrap();
+ let RenderedClientResponse::Json { body, .. } =
+ ClientResponseRenderer::render_nonstream_with_profile(
+ &ClientProtocolProfile::for_candidate(&profile).unwrap(),
+ "alias",
+ &decoded.response,
+ )
+ .unwrap()
+ else {
+ panic!("expected JSON")
+ };
+ assert_eq!(body["content"][0]["text"], "answer");
+ let tool = body["content"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|v| v["type"] == "tool_use")
+ .unwrap();
+ assert_eq!(tool["name"], "probe");
+ assert_eq!(tool["input"], json!({"value":1}));
+ assert_eq!(body["stop_reason"], "tool_use");
+ assert_eq!(body["usage"], json!({"input_tokens":7,"output_tokens":19}));
+ assert!(body.get("service_tier").is_none());
+ }
+}
+
+fn stream(tier: Value) -> Vec<u8> {
+ let chunks = [
+ json!({"id":"r","model":"physical","choices":[{"index":0,"delta":{"role":"assistant","content":"answer"},"finish_reason":null}]}),
+ json!({"id":"r","model":"physical","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"call_1","type":"function","function":{"name":"probe","arguments":"{\"value\":"}}]},"finish_reason":null}]}),
+ json!({"id":"r","model":"physical","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"1}"}}]},"finish_reason":"tool_calls"}]}),
+ // The observed failure is metadata arriving after semantic output is committed.
+ json!({"id":"r","model":"physical","choices":[],"service_tier":tier,"usage":{"prompt_tokens":7,"completion_tokens":19,"total_tokens":26}}),
+ ];
+ let mut wire: String = chunks.iter().map(|v| format!("data: {v}\n\n")).collect();
+ wire.push_str("data: [DONE]\n\n");
+ wire.into_bytes()
+}
+
+#[test]
+fn chat_service_tier_stream_tail_completes_tools_and_usage() {
+ for size in [1, 17, usize::MAX] {
+ let profile = candidate();
+ let mut decoder = NativeResponseDecoder::new(&profile, 200, true).unwrap();
+ let mut renderer = IncrementalClientSseRenderer::new(
+ ClientProtocolProfile::for_candidate(&profile).unwrap(),
+ "alias",
+ )
+ .unwrap();
+ let mut output = Vec::new();
+ for chunk in stream(json!("default")).chunks(size) {
+ let mut status = decoder.feed(chunk, false).unwrap();
+ loop {
+ for event in decoder.take_events() {
+ output.extend(renderer.push(&event).unwrap());
+ }
+ if status != ResponseDecodeStatus::NeedDrain {
+ break;
+ }
+ status = decoder.resume().unwrap();
+ }
+ }
+ assert_eq!(
+ decoder.feed(&[], true).unwrap(),
+ ResponseDecodeStatus::Terminal
+ );
+ for event in decoder.take_events() {
+ output.extend(renderer.push(&event).unwrap());
+ }
+ decoder.finish().unwrap();
+ assert_eq!(
+ output
+ .iter()
+ .filter(|v| v.data["type"] == "message_stop")
+ .count(),
+ 1
+ );
+ let text: String = output
+ .iter()
+ .filter_map(|v| v.data["delta"]["text"].as_str())
+ .collect();
+ assert_eq!(text, "answer");
+ assert!(
+ output
+ .iter()
+ .any(|v| v.data["content_block"]["name"] == "probe")
+ );
+ let arguments: String = output
+ .iter()
+ .filter_map(|v| v.data["delta"]["partial_json"].as_str())
+ .collect();
+ assert_eq!(
+ serde_json::from_str::<Value>(&arguments).unwrap(),
+ json!({"value":1})
+ );
+ assert_eq!(renderer.usage().input_tokens, Some(7));
+ assert_eq!(renderer.usage().output_tokens, Some(19));
+ }
+}
+
+#[test]
+fn chat_service_tier_invalid_types_still_fail() {
+ for tier in [json!(true), json!(7), json!({}), json!([])] {
+ let mut document = response();
+ document["service_tier"] = tier.clone();
+ let profile = candidate();
+ let mut decoder = NativeResponseDecoder::new(&profile, 200, false).unwrap();
+ assert!(
+ decoder
+ .feed(&serde_json::to_vec(&document).unwrap(), true)
+ .is_err()
+ );
+ let mut decoder = NativeResponseDecoder::new(&profile, 200, true).unwrap();
+ let mut result = decoder.feed(&stream(tier), true);
+ while matches!(result, Ok(ResponseDecodeStatus::NeedDrain)) {
+ decoder.take_events();
+ result = decoder.resume();
+ }
+ assert!(result.is_err());
+ }
+}
diff --git a/crates/gateway/src/adapters/tests.rs b/crates/gateway/src/adapters/tests.rs
index 0bf587a8..e43bb632 100644
--- a/crates/gateway/src/adapters/tests.rs
+++ b/crates/gateway/src/adapters/tests.rs
@@ -162,6 +162,63 @@ fn malformed_tool_arguments_above_inline_limit_replay_exactly() {
fs_err_remove_dir(&root);
}
+#[test]
+fn messages_direct_tool_caller_preserves_native_history_and_portable_tool_pairing() {
+ let mut body = json!({
+ "model": "alias", "max_tokens": 16, "stream": true,
+ "messages": [
+ {"role":"user","content":"Use return_ok with value OK."},
+ {"role":"assistant","content":[{
+ "type":"tool_use","id":"toolu_fixture","name":"return_ok",
+ "input":{"value":"OK"},"caller":{"type":"direct"}
+ }]},
+ {"role":"user","content":[{
+ "type":"tool_result","tool_use_id":"toolu_fixture","content":"OK"
+ }]}
+ ],
+ "tools":[{"name":"return_ok","input_schema":{"type":"object"}}]
+ });
+ let request = decode_ingress_request(IngressProtocol::Messages, &body).unwrap();
+ assert!(!request.native_only);
+ let native = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Messages,
+ "physical",
+ fixed_reasoning("fixed"),
+ );
+ let projected = project_candidate_request(&request, &native).unwrap();
+ assert_eq!(projected.body["messages"], body["messages"]);
+ assert_eq!(projected.body["stream"], true);
+ let portable = CandidateProtocolProfile::exact_portable_path(
+ IngressProtocol::Messages,
+ IngressProtocol::Responses,
+ "physical",
+ fixed_reasoning("fixed"),
+ );
+ let projected = project_candidate_request(&request, &portable).unwrap();
+ assert_eq!(projected.body["input"][1]["type"], "function_call");
+ assert_eq!(projected.body["input"][2]["type"], "function_call_output");
+ assert_eq!(
+ projected.body["input"][1]["call_id"],
+ projected.body["input"][2]["call_id"]
+ );
+ assert_eq!(projected.body["input"][2]["output"], "OK");
+
+ // A direct caller adds no execution authority. Programmatic execution and unknown
+ // fields must not be admitted by widening the surrounding tool-field allowlist.
+ for caller in [
+ json!(null),
+ json!("direct"),
+ json!({}),
+ json!({"type":"future"}),
+ json!({"type":"direct","tool_id":"unexpected"}),
+ json!({"type":"code_execution_20260120","tool_id":"srvtoolu_fixture"}),
+ ] {
+ body["messages"][1]["content"][0]["caller"] = caller;
+ assert!(decode_ingress_request(IngressProtocol::Messages, &body).is_err());
+ }
+}
+
#[test]
fn messages_ingress_accepts_claude_compaction_after_tool_roundtrip() {
let body = json!({
diff --git a/crates/gateway/src/model_ir/request.rs b/crates/gateway/src/model_ir/request.rs
index 7bb5b4ed..1c7b6100 100644
--- a/crates/gateway/src/model_ir/request.rs
+++ b/crates/gateway/src/model_ir/request.rs
@@ -404,6 +404,10 @@ pub enum RequestedReasoningDisposition {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RequestedReasoningControl {
+ /// Messages return-text policy, fixed before Replay externalizes controls.
+ /// It never changes computation, accounting, or persisted IR contracts.
+ #[serde(skip)]
+ pub(crate) messages_omit_thinking: bool,
pub native_value: Option<Value>,
pub disposition: RequestedReasoningDisposition,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -416,6 +420,7 @@ pub struct RequestedReasoningControl {
impl RequestedReasoningControl {
pub fn absent() -> Self {
Self {
+ messages_omit_thinking: false,
native_value: None,
disposition: RequestedReasoningDisposition::Absent,
fixed_profile_digest: None,
@@ -425,6 +430,7 @@ impl RequestedReasoningControl {
pub fn overridden(native_value: Value) -> Self {
Self {
+ messages_omit_thinking: false,
native_value: Some(native_value),
disposition: RequestedReasoningDisposition::OverriddenByAgentPlan,
fixed_profile_digest: None,
diff --git a/crates/gateway/src/runtime/driver.rs b/crates/gateway/src/runtime/driver.rs
index a8b16624..240c30cc 100644
--- a/crates/gateway/src/runtime/driver.rs
+++ b/crates/gateway/src/runtime/driver.rs
@@ -174,6 +174,7 @@ pub struct ProductionAttemptState {
served_model_alias: String,
streaming: bool,
native_output: bool,
+ omit_thinking: bool,
chat_tool_projection: Option<adapters::ChatToolProjection>,
chat_tool_projection_budget: Option<Reservation>,
decoder: Option<adapters::NativeResponseDecoder>,
diff --git a/crates/gateway/src/runtime/driver/materialization.rs b/crates/gateway/src/runtime/driver/materialization.rs
index 6b3ce83e..baa91b2d 100644
--- a/crates/gateway/src/runtime/driver/materialization.rs
+++ b/crates/gateway/src/runtime/driver/materialization.rs
@@ -557,6 +557,7 @@ pub(super) async fn materialize_attempt(
served_model_alias,
streaming,
native_output,
+ omit_thinking: ir.requested_reasoning.messages_omit_thinking,
chat_tool_projection,
chat_tool_projection_budget,
decoder: None,
diff --git a/crates/gateway/src/runtime/driver/response.rs b/crates/gateway/src/runtime/driver/response.rs
index daffb754..696dfb20 100644
--- a/crates/gateway/src/runtime/driver/response.rs
+++ b/crates/gateway/src/runtime/driver/response.rs
@@ -92,7 +92,8 @@ pub(super) fn classify_precommit(
state.chat_tool_projection.take(),
state.budget.clone(),
)
- .map_err(|_| Arc::from(MATERIALIZATION_PROTOCOL_FAILED))?,
+ .map_err(|_| Arc::from(MATERIALIZATION_PROTOCOL_FAILED))?
+ .with_omitted_thinking(state.omit_thinking),
));
} else {
state.decoder = Some(
diff --git a/tools/e2e-harness/tests/p0_gateway_protocol/production_matrix.rs b/tools/e2e-harness/tests/p0_gateway_protocol/production_matrix.rs
index 35139002..3c3851b1 100644
--- a/tools/e2e-harness/tests/p0_gateway_protocol/production_matrix.rs
+++ b/tools/e2e-harness/tests/p0_gateway_protocol/production_matrix.rs
@@ -191,7 +191,7 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
request["output_config"] = json!({"format": messages_schema_format()});
}
if !fixed && ingress == IngressProtocol::Messages {
- request["thinking"] = json!({"type":"adaptive"});
+ request["thinking"] = json!({"type":"adaptive","display":"omitted"});
request["output_config"]["effort"] = json!("high");
}
if ingress == IngressProtocol::Messages && upstream == IngressProtocol::Responses {
@@ -199,7 +199,7 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
request["messages"].as_array_mut().unwrap().extend([
json!({"role":"assistant","content":[
{"type":"text","text":"before"},
- {"type":"tool_use","id":"call_1","name":"probe","input":{"value":1}},
+ {"type":"tool_use","id":"call_1","name":"probe","input":{"value":1},"caller":{"type":"direct"}},
{"type":"text","text":"after"}]}),
json!({"role":"user","content":[
{"type":"tool_result","tool_use_id":"call_1","content":"1"},
@@ -211,7 +211,7 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
let calls = (0..4)
.map(|index| {
json!({"type":"tool_use","id":format!("call_{index}"),
- "name":"probe","input":{"value":index}})
+ "name":"probe","input":{"value":index},"caller":{"type":"direct"}})
})
.collect::<Vec<_>>();
let mut results = (0..4)
@@ -245,9 +245,13 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
String::from_utf8_lossy(&response.body),
process.stderr()
);
+ let mut expected = expected_client_body(ingress, upstream, &alias);
+ if !fixed && ingress == IngressProtocol::Messages && upstream == ingress {
+ expected["content"][0]["thinking"] = json!("");
+ }
assert_eq!(
serde_json::from_slice::<Value>(&response.body).unwrap(),
- expected_client_body(ingress, upstream, &alias),
+ expected,
"{path}: {}",
String::from_utf8_lossy(&response.body)
);
@@ -264,7 +268,7 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
request["output_config"] = json!({"format": messages_schema_format()});
}
if !fixed && protocol == IngressProtocol::Messages {
- request["thinking"] = json!({"type":"adaptive"});
+ request["thinking"] = json!({"type":"adaptive","display":"omitted"});
request["output_config"]["effort"] = json!("high");
}
request["stream"] = Value::Bool(true);
@@ -302,6 +306,11 @@ fn run_protocol_matrix(fixed: bool, pairs: Vec<(IngressProtocol, IngressProtocol
Some("text/event-stream")
);
assert_same_protocol_stream(protocol, &alias, &response.body);
+ if protocol == IngressProtocol::Messages {
+ let text = std::str::from_utf8(&response.body).unwrap();
+ assert_eq!(text.contains("private thought"), fixed);
+ assert!(text.contains("opaque-signature"));
+ }
}
let invalid = single_write_request(
address,
@@ -645,7 +654,7 @@ fn messages_schema_format() -> Value {
fn native_response(upstream: IngressProtocol) -> &'static [u8] {
match upstream {
IngressProtocol::Responses => br#"{"id":"native-provider","model":"runtime-native","status":"completed","output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"ok"}]}],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}}"#,
- IngressProtocol::ChatCompletions => br#"{"id":"native-provider","object":"chat.completion","created":0,"model":"runtime-native","choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2}}"#,
+ IngressProtocol::ChatCompletions => br#"{"id":"native-provider","object":"chat.completion","service_tier":"default","created":0,"model":"runtime-native","choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2}}"#,
IngressProtocol::Messages => br#"{"id":"native-provider","type":"message","role":"assistant","model":"runtime-native","content":[{"type":"text","text":"ok"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":1,"output_tokens":1}}"#,
}
}
@@ -653,8 +662,8 @@ fn native_response(upstream: IngressProtocol) -> &'static [u8] {
fn native_same_protocol_response(upstream: IngressProtocol) -> &'static [u8] {
match upstream {
IngressProtocol::Responses => br#"{"id":"native-provider","model":"runtime-native","status":"completed","output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"ok"}]}],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2},"provider_extension":{"model":"nested-untouched","future":true}}"#,
- IngressProtocol::ChatCompletions => br#"{"id":"native-provider","object":"chat.completion","created":0,"model":"runtime-native","choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2},"provider_extension":{"model":"nested-untouched","future":true}}"#,
- IngressProtocol::Messages => br#"{"id":"native-provider","type":"message","role":"assistant","model":"runtime-native","content":[{"type":"text","text":"ok","provider_extension":{"future":true}}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":1,"output_tokens":1},"provider_extension":{"model":"nested-untouched"}}"#,
+ IngressProtocol::ChatCompletions => br#"{"id":"native-provider","object":"chat.completion","service_tier":"default","created":0,"model":"runtime-native","choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2},"provider_extension":{"model":"nested-untouched","future":true}}"#,
+ IngressProtocol::Messages => br#"{"id":"native-provider","type":"message","role":"assistant","model":"runtime-native","content":[{"type":"thinking","thinking":"private thought","signature":"opaque-signature"},{"type":"text","text":"ok","provider_extension":{"future":true}}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":1,"output_tokens":1},"provider_extension":{"model":"nested-untouched"}}"#,
}
}
@@ -678,7 +687,7 @@ data: {"type":"response.completed","response":{"id":"native-stream","model":"run
data: {"id":"native-stream","object":"chat.completion.chunk","created":1,"model":"runtime-native","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"provider_extension":{"future":true}}
-data: {"id":"native-stream","object":"chat.completion.chunk","created":1,"model":"runtime-native","choices":[],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2},"provider_extension":{"future":true}}
+data: {"id":"native-stream","object":"chat.completion.chunk","created":1,"model":"runtime-native","choices":[],"service_tier":"default","usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2},"provider_extension":{"future":true}}
data: [DONE]
@@ -690,6 +699,18 @@ data: {"type":"message.vendor_extension","provider_extension":{"model":"nested-u
event: message_start
data: {"type":"message_start","message":{"id":"native-stream","type":"message","role":"assistant","model":"runtime-native","content":[],"stop_reason":null,"usage":{"input_tokens":1},"provider_extension":{"future":true}}}
+event: content_block_start
+data: {"type":"content_block_start","index":7,"content_block":{"type":"thinking","thinking":"private thought"}}
+
+event: content_block_delta
+data: {"type":"content_block_delta","index":7,"delta":{"type":"thinking_delta","thinking":"private thought delta"}}
+
+event: content_block_delta
+data: {"type":"content_block_delta","index":7,"delta":{"type":"signature_delta","signature":"opaque-signature"}}
+
+event: content_block_stop
+data: {"type":"content_block_stop","index":7}
+
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":"","provider_extension":{"future":true}}}
@@ -725,6 +746,7 @@ fn assert_same_protocol_stream(protocol: IngressProtocol, alias: &str, body: &[u
}
IngressProtocol::ChatCompletions => {
assert!(wire.contains("data: [DONE]\n\n"));
+ assert!(wire.contains(r#""service_tier":"default""#));
}
IngressProtocol::Messages => {
assert!(wire.contains("event: message.vendor_extension\nid: opaque\n"));
@@ -764,7 +786,7 @@ fn stream_terminal_partition(protocol: IngressProtocol) -> &'static [u8] {
IngressProtocol::ChatCompletions => {
b"data: {\"id\":\"native-stream\",\"object\":\"chat.completion.chunk\",\"created\":1,\"model\":\"runtime-native\",\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\"stop\"}"
}
- IngressProtocol::Messages => b"event: content_block_stop\n",
+ IngressProtocol::Messages => b"event: message_delta\n",
}
}
@@ -772,7 +794,7 @@ fn stream_visible_marker(protocol: IngressProtocol) -> &'static [u8] {
match protocol {
IngressProtocol::Responses => b"response.output_text.delta",
IngressProtocol::ChatCompletions => b"\"content\":\"ok\"",
- IngressProtocol::Messages => b"content_block_delta",
+ IngressProtocol::Messages => b"\"text\":\"ok\"",
}
}
diff --git a/tools/e2e-harness/tests/p0_gateway_protocol/support.rs b/tools/e2e-harness/tests/p0_gateway_protocol/support.rs
index f232ab45..90495f85 100644
--- a/tools/e2e-harness/tests/p0_gateway_protocol/support.rs
+++ b/tools/e2e-harness/tests/p0_gateway_protocol/support.rs
@@ -156,7 +156,7 @@ pub fn native_nonstream(protocol: IngressProtocol) -> Vec<u8> {
"usage":{"input_tokens":10,"output_tokens":20,"total_tokens":30}
}),
IngressProtocol::ChatCompletions => json!({
- "id":"chat_native","object":"chat.completion","created":1,"model":"physical-chat",
+ "id":"chat_native","object":"chat.completion","service_tier":"default","created":1,"model":"physical-chat",
"choices":[{"index":0,"message":{"role":"assistant","reasoning_content":"careful","content":"done","tool_calls":[
{"id":"chat_native_a","type":"function","function":{"name":"weather","arguments":"{\"city\":\"Paris\"}"}},
{"id":"chat_native_b","type":"function","function":{"name":"units","arguments":"{\"unit\":\"C\"}"}}
@@ -281,7 +281,7 @@ fn chat_events() -> Vec<RenderedSseEvent> {
]},"finish_reason":null}],"usage":null}),
),
unnamed(
- json!({"id":"chat_native","object":"chat.completion.chunk","created":1,"model":"physical-chat","choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}],"usage":null}),
+ json!({"id":"chat_native","object":"chat.completion.chunk","created":1,"model":"physical-chat","choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}],"service_tier":"default","usage":null}),
),
unnamed(
json!({"id":"chat_native","object":"chat.completion.chunk","created":1,"model":"physical-chat","choices":[],"usage":{"prompt_tokens":10,"completion_tokens":20,"total_tokens":30}}),