Normalize Bedrock Mantle commentary before replay (#62095)

## Why

Bedrock Mantle's reasoning prefix omits empty `annotations` on assistant commentary. Replayed commentary needs to preserve that form to keep the prefix stable.

## What changed

Add a provider hook to normalize completed output items before they enter model history. For Mantle, omit empty `annotations` from assistant commentary text while preserving nonempty annotations, final answers, and Bedrock Runtime output.

## Testing

Add regression coverage for Mantle and Runtime that checks commentary replay across a tool continuation and a subsequent turn, including reasoning and tool item ordering and preservation of final-answer content.

GitOrigin-RevId: ecd5b9b5dca8c24956a6379c9d0fb643e4427af3
This commit is contained in:
Adnan Hajar
2026-11-17 18:55:30 +00:00
committed by copyberry
parent 04cfdee311
commit cb64621bf3
4 changed files with 122 additions and 0 deletions
@@ -28,6 +28,9 @@ use codex_models_manager::manager::StaticModelsManager;
use codex_protocol::account::ProviderAccount;
use codex_protocol::error::CodexErr;
use codex_protocol::error::Result;
use codex_protocol::models::ContentItem;
use codex_protocol::models::MessagePhase;
use codex_protocol::models::ResponseItem;
use codex_protocol::openai_models::ModelsResponse;
use crate::ProviderCapabilities;
@@ -277,6 +280,28 @@ impl ModelProvider for AmazonBedrockModelProvider {
&self.info
}
fn normalize_completed_output_item(&self, item: &mut ResponseItem) {
// Mantle's reasoning prefix omits empty annotations on commentary.
// Capture that form before the first replay so the prefix stays stable.
if self.endpoint == BedrockEndpoint::Mantle
&& let ResponseItem::Message {
role,
phase: Some(MessagePhase::Commentary),
content,
..
} = item
&& role == "assistant"
{
for part in content {
if let ContentItem::OutputText { annotations, .. } = part
&& annotations.as_ref().is_some_and(Vec::is_empty)
{
*annotations = None;
}
}
}
}
fn capabilities(&self) -> ProviderCapabilities {
ProviderCapabilities {
reasoning_summaries: true,
+4
View File
@@ -25,6 +25,7 @@ use codex_models_manager::manager::StaticModelsManager;
use codex_protocol::account::ProviderAccount;
use codex_protocol::auth::RefreshTokenFailedError;
use codex_protocol::error::CodexErr;
use codex_protocol::models::ResponseItem;
use codex_protocol::openai_models::ModelsResponse;
use codex_runtime_agent_instance::RuntimeAuthManager;
@@ -221,6 +222,9 @@ pub trait ModelProvider: fmt::Debug + Send + Sync {
codex_api::map_api_error(error)
}
/// Normalizes a completed output item before it enters model history.
fn normalize_completed_output_item(&self, _item: &mut ResponseItem) {}
/// Returns provider configuration adapted for the API client.
fn api_provider(&self) -> ModelProviderFuture<'_, codex_protocol::error::Result<Provider>> {
Box::pin(async move {