Lightweight coding agent that runs in your terminal
Rust
[codex] Forward turn moderation metadata through app-server (#25710)
carlc-oai55aa071b17c8
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.jsonindex 16656e3a55..010ec33e08 100644--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json@@ -4909,6 +4909,23 @@}]},+ "TurnModerationMetadataNotification": {+ "properties": {+ "metadata": true,+ "threadId": {+ "type": "string"+ },+ "turnId": {+ "type": "string"+ }+ },+ "required": [+ "metadata",+ "threadId",+ "turnId"+ ],+ "type": "object"+ },"TurnPlanStep": {"properties": {"status": {@@ -6248,6 +6265,26 @@"title": "Model/verificationNotification","type": "object"},+ {+ "properties": {+ "method": {+ "enum": [+ "turn/moderationMetadata"+ ],+ "title": "Turn/moderationMetadataNotificationMethod",+ "type": "string"+ },+ "params": {+ "$ref": "#/definitions/TurnModerationMetadataNotification"+ }+ },+ "required": [+ "method",+ "params"+ ],+ "title": "Turn/moderationMetadataNotification",+ "type": "object"+ },{"properties": {"method": {diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.jsonindex bbcbb20be4..10bde05597 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json@@ -4904,6 +4904,26 @@"title": "Model/verificationNotification","type": "object"},+ {+ "properties": {+ "method": {+ "enum": [+ "turn/moderationMetadata"+ ],+ "title": "Turn/moderationMetadataNotificationMethod",+ "type": "string"+ },+ "params": {+ "$ref": "#/definitions/v2/TurnModerationMetadataNotification"+ }+ },+ "required": [+ "method",+ "params"+ ],+ "title": "Turn/moderationMetadataNotification",+ "type": "object"+ },{"properties": {"method": {@@ -18601,6 +18621,25 @@}]},+ "TurnModerationMetadataNotification": {+ "$schema": "http://json-schema.org/draft-07/schema#",+ "properties": {+ "metadata": true,+ "threadId": {+ "type": "string"+ },+ "turnId": {+ "type": "string"+ }+ },+ "required": [+ "metadata",+ "threadId",+ "turnId"+ ],+ "title": "TurnModerationMetadataNotification",+ "type": "object"+ },"TurnPlanStep": {"properties": {"status": {diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.jsonindex 65d999b334..e4c91e7586 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json@@ -12420,6 +12420,26 @@"title": "Model/verificationNotification","type": "object"},+ {+ "properties": {+ "method": {+ "enum": [+ "turn/moderationMetadata"+ ],+ "title": "Turn/moderationMetadataNotificationMethod",+ "type": "string"+ },+ "params": {+ "$ref": "#/definitions/TurnModerationMetadataNotification"+ }+ },+ "required": [+ "method",+ "params"+ ],+ "title": "Turn/moderationMetadataNotification",+ "type": "object"+ },{"properties": {"method": {@@ -16418,6 +16438,25 @@}]},+ "TurnModerationMetadataNotification": {+ "$schema": "http://json-schema.org/draft-07/schema#",+ "properties": {+ "metadata": true,+ "threadId": {+ "type": "string"+ },+ "turnId": {+ "type": "string"+ }+ },+ "required": [+ "metadata",+ "threadId",+ "turnId"+ ],+ "title": "TurnModerationMetadataNotification",+ "type": "object"+ },"TurnPlanStep": {"properties": {"status": {diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnModerationMetadataNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnModerationMetadataNotification.jsonnew file mode 100644index 0000000000..273bd41061--- /dev/null+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnModerationMetadataNotification.json@@ -0,0 +1,19 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "properties": {+ "metadata": true,+ "threadId": {+ "type": "string"+ },+ "turnId": {+ "type": "string"+ }+ },+ "required": [+ "metadata",+ "threadId",+ "turnId"+ ],+ "title": "TurnModerationMetadataNotification",+ "type": "object"+}\ No newline at end of filediff --git a/codex-rs/app-server-protocol/schema/typescript/ServerNotification.ts b/codex-rs/app-server-protocol/schema/typescript/ServerNotification.tsindex 3ed710efc0..2520c71c3c 100644--- a/codex-rs/app-server-protocol/schema/typescript/ServerNotification.ts+++ b/codex-rs/app-server-protocol/schema/typescript/ServerNotification.ts@@ -61,6 +61,7 @@ import type { ThreadTokenUsageUpdatedNotification } from "./v2/ThreadTokenUsageUimport type { ThreadUnarchivedNotification } from "./v2/ThreadUnarchivedNotification";import type { TurnCompletedNotification } from "./v2/TurnCompletedNotification";import type { TurnDiffUpdatedNotification } from "./v2/TurnDiffUpdatedNotification";+import type { TurnModerationMetadataNotification } from "./v2/TurnModerationMetadataNotification";import type { TurnPlanUpdatedNotification } from "./v2/TurnPlanUpdatedNotification";import type { TurnStartedNotification } from "./v2/TurnStartedNotification";import type { WarningNotification } from "./v2/WarningNotification";@@ -70,4 +71,4 @@ import type { WindowsWorldWritableWarningNotification } from "./v2/WindowsWorldW/*** Notification sent from the server to the client.*/-export type ServerNotification = { "method": "error", "params": ErrorNotification } | { "method": "thread/started", "params": ThreadStartedNotification } | { "method": "thread/status/changed", "params": ThreadStatusChangedNotification } | { "method": "thread/archived", "params": ThreadArchivedNotification } | { "method": "thread/unarchived", "params": ThreadUnarchivedNotification } | { "method": "thread/closed", "params": ThreadClosedNotification } | { "method": "skills/changed", "params": SkillsChangedNotification } | { "method": "thread/name/updated", "params": ThreadNameUpdatedNotification } | { "method": "thread/goal/updated", "params": ThreadGoalUpdatedNotification } | { "method": "thread/goal/cleared", "params": ThreadGoalClearedNotification } | { "method": "thread/settings/updated", "params": ThreadSettingsUpdatedNotification } | { "method": "thread/tokenUsage/updated", "params": ThreadTokenUsageUpdatedNotification } | { "method": "turn/started", "params": TurnStartedNotification } | { "method": "hook/started", "params": HookStartedNotification } | { "method": "turn/completed", "params": TurnCompletedNotification } | { "method": "hook/completed", "params": HookCompletedNotification } | { "method": "turn/diff/updated", "params": TurnDiffUpdatedNotification } | { "method": "turn/plan/updated", "params": TurnPlanUpdatedNotification } | { "method": "item/started", "params": ItemStartedNotification } | { "method": "item/autoApprovalReview/started", "params": ItemGuardianApprovalReviewStartedNotification } | { "method": "item/autoApprovalReview/completed", "params": ItemGuardianApprovalReviewCompletedNotification } | { "method": "item/completed", "params": ItemCompletedNotification } | { "method": "rawResponseItem/completed", "params": RawResponseItemCompletedNotification } | { "method": "item/agentMessage/delta", "params": AgentMessageDeltaNotification } | { "method": "item/plan/delta", "params": PlanDeltaNotification } | { "method": "command/exec/outputDelta", "params": CommandExecOutputDeltaNotification } | { "method": "process/outputDelta", "params": ProcessOutputDeltaNotification } | { "method": "process/exited", "params": ProcessExitedNotification } | { "method": "item/commandExecution/outputDelta", "params": CommandExecutionOutputDeltaNotification } | { "method": "item/commandExecution/terminalInteraction", "params": TerminalInteractionNotification } | { "method": "item/fileChange/outputDelta", "params": FileChangeOutputDeltaNotification } | { "method": "item/fileChange/patchUpdated", "params": FileChangePatchUpdatedNotification } | { "method": "serverRequest/resolved", "params": ServerRequestResolvedNotification } | { "method": "item/mcpToolCall/progress", "params": McpToolCallProgressNotification } | { "method": "mcpServer/oauthLogin/completed", "params": McpServerOauthLoginCompletedNotification } | { "method": "mcpServer/startupStatus/updated", "params": McpServerStatusUpdatedNotification } | { "method": "account/updated", "params": AccountUpdatedNotification } | { "method": "account/rateLimits/updated", "params": AccountRateLimitsUpdatedNotification } | { "method": "app/list/updated", "params": AppListUpdatedNotification } | { "method": "remoteControl/status/changed", "params": RemoteControlStatusChangedNotification } | { "method": "externalAgentConfig/import/completed", "params": ExternalAgentConfigImportCompletedNotification } | { "method": "fs/changed", "params": FsChangedNotification } | { "method": "item/reasoning/summaryTextDelta", "params": ReasoningSummaryTextDeltaNotification } | { "method": "item/reasoning/summaryPartAdded", "params": ReasoningSummaryPartAddedNotification } | { "method": "item/reasoning/textDelta", "params": ReasoningTextDeltaNotification } | { "method": "thread/compacted", "params": ContextCompactedNotification } | { "method": "model/rerouted", "params": ModelReroutedNotification } | { "method": "model/verification", "params": ModelVerificationNotification } | { "method": "warning", "params": WarningNotification } | { "method": "guardianWarning", "params": GuardianWarningNotification } | { "method": "deprecationNotice", "params": DeprecationNoticeNotification } | { "method": "configWarning", "params": ConfigWarningNotification } | { "method": "fuzzyFileSearch/sessionUpdated", "params": FuzzyFileSearchSessionUpdatedNotification } | { "method": "fuzzyFileSearch/sessionCompleted", "params": FuzzyFileSearchSessionCompletedNotification } | { "method": "thread/realtime/started", "params": ThreadRealtimeStartedNotification } | { "method": "thread/realtime/itemAdded", "params": ThreadRealtimeItemAddedNotification } | { "method": "thread/realtime/transcript/delta", "params": ThreadRealtimeTranscriptDeltaNotification } | { "method": "thread/realtime/transcript/done", "params": ThreadRealtimeTranscriptDoneNotification } | { "method": "thread/realtime/outputAudio/delta", "params": ThreadRealtimeOutputAudioDeltaNotification } | { "method": "thread/realtime/sdp", "params": ThreadRealtimeSdpNotification } | { "method": "thread/realtime/error", "params": ThreadRealtimeErrorNotification } | { "method": "thread/realtime/closed", "params": ThreadRealtimeClosedNotification } | { "method": "windows/worldWritableWarning", "params": WindowsWorldWritableWarningNotification } | { "method": "windowsSandbox/setupCompleted", "params": WindowsSandboxSetupCompletedNotification } | { "method": "account/login/completed", "params": AccountLoginCompletedNotification };+export type ServerNotification = { "method": "error", "params": ErrorNotification } | { "method": "thread/started", "params": ThreadStartedNotification } | { "method": "thread/status/changed", "params": ThreadStatusChangedNotification } | { "method": "thread/archived", "params": ThreadArchivedNotification } | { "method": "thread/unarchived", "params": ThreadUnarchivedNotification } | { "method": "thread/closed", "params": ThreadClosedNotification } | { "method": "skills/changed", "params": SkillsChangedNotification } | { "method": "thread/name/updated", "params": ThreadNameUpdatedNotification } | { "method": "thread/goal/updated", "params": ThreadGoalUpdatedNotification } | { "method": "thread/goal/cleared", "params": ThreadGoalClearedNotification } | { "method": "thread/settings/updated", "params": ThreadSettingsUpdatedNotification } | { "method": "thread/tokenUsage/updated", "params": ThreadTokenUsageUpdatedNotification } | { "method": "turn/started", "params": TurnStartedNotification } | { "method": "hook/started", "params": HookStartedNotification } | { "method": "turn/completed", "params": TurnCompletedNotification } | { "method": "hook/completed", "params": HookCompletedNotification } | { "method": "turn/diff/updated", "params": TurnDiffUpdatedNotification } | { "method": "turn/plan/updated", "params": TurnPlanUpdatedNotification } | { "method": "item/started", "params": ItemStartedNotification } | { "method": "item/autoApprovalReview/started", "params": ItemGuardianApprovalReviewStartedNotification } | { "method": "item/autoApprovalReview/completed", "params": ItemGuardianApprovalReviewCompletedNotification } | { "method": "item/completed", "params": ItemCompletedNotification } | { "method": "rawResponseItem/completed", "params": RawResponseItemCompletedNotification } | { "method": "item/agentMessage/delta", "params": AgentMessageDeltaNotification } | { "method": "item/plan/delta", "params": PlanDeltaNotification } | { "method": "command/exec/outputDelta", "params": CommandExecOutputDeltaNotification } | { "method": "process/outputDelta", "params": ProcessOutputDeltaNotification } | { "method": "process/exited", "params": ProcessExitedNotification } | { "method": "item/commandExecution/outputDelta", "params": CommandExecutionOutputDeltaNotification } | { "method": "item/commandExecution/terminalInteraction", "params": TerminalInteractionNotification } | { "method": "item/fileChange/outputDelta", "params": FileChangeOutputDeltaNotification } | { "method": "item/fileChange/patchUpdated", "params": FileChangePatchUpdatedNotification } | { "method": "serverRequest/resolved", "params": ServerRequestResolvedNotification } | { "method": "item/mcpToolCall/progress", "params": McpToolCallProgressNotification } | { "method": "mcpServer/oauthLogin/completed", "params": McpServerOauthLoginCompletedNotification } | { "method": "mcpServer/startupStatus/updated", "params": McpServerStatusUpdatedNotification } | { "method": "account/updated", "params": AccountUpdatedNotification } | { "method": "account/rateLimits/updated", "params": AccountRateLimitsUpdatedNotification } | { "method": "app/list/updated", "params": AppListUpdatedNotification } | { "method": "remoteControl/status/changed", "params": RemoteControlStatusChangedNotification } | { "method": "externalAgentConfig/import/completed", "params": ExternalAgentConfigImportCompletedNotification } | { "method": "fs/changed", "params": FsChangedNotification } | { "method": "item/reasoning/summaryTextDelta", "params": ReasoningSummaryTextDeltaNotification } | { "method": "item/reasoning/summaryPartAdded", "params": ReasoningSummaryPartAddedNotification } | { "method": "item/reasoning/textDelta", "params": ReasoningTextDeltaNotification } | { "method": "thread/compacted", "params": ContextCompactedNotification } | { "method": "model/rerouted", "params": ModelReroutedNotification } | { "method": "model/verification", "params": ModelVerificationNotification } | { "method": "turn/moderationMetadata", "params": TurnModerationMetadataNotification } | { "method": "warning", "params": WarningNotification } | { "method": "guardianWarning", "params": GuardianWarningNotification } | { "method": "deprecationNotice", "params": DeprecationNoticeNotification } | { "method": "configWarning", "params": ConfigWarningNotification } | { "method": "fuzzyFileSearch/sessionUpdated", "params": FuzzyFileSearchSessionUpdatedNotification } | { "method": "fuzzyFileSearch/sessionCompleted", "params": FuzzyFileSearchSessionCompletedNotification } | { "method": "thread/realtime/started", "params": ThreadRealtimeStartedNotification } | { "method": "thread/realtime/itemAdded", "params": ThreadRealtimeItemAddedNotification } | { "method": "thread/realtime/transcript/delta", "params": ThreadRealtimeTranscriptDeltaNotification } | { "method": "thread/realtime/transcript/done", "params": ThreadRealtimeTranscriptDoneNotification } | { "method": "thread/realtime/outputAudio/delta", "params": ThreadRealtimeOutputAudioDeltaNotification } | { "method": "thread/realtime/sdp", "params": ThreadRealtimeSdpNotification } | { "method": "thread/realtime/error", "params": ThreadRealtimeErrorNotification } | { "method": "thread/realtime/closed", "params": ThreadRealtimeClosedNotification } | { "method": "windows/worldWritableWarning", "params": WindowsWorldWritableWarningNotification } | { "method": "windowsSandbox/setupCompleted", "params": WindowsSandboxSetupCompletedNotification } | { "method": "account/login/completed", "params": AccountLoginCompletedNotification };diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/TurnModerationMetadataNotification.ts b/codex-rs/app-server-protocol/schema/typescript/v2/TurnModerationMetadataNotification.tsnew file mode 100644index 0000000000..1d46d1b4b8--- /dev/null+++ b/codex-rs/app-server-protocol/schema/typescript/v2/TurnModerationMetadataNotification.ts@@ -0,0 +1,6 @@+// GENERATED CODE! DO NOT MODIFY BY HAND!++// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.+import type { JsonValue } from "../serde_json/JsonValue";++export type TurnModerationMetadataNotification = { threadId: string, turnId: string, metadata: JsonValue, };diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts b/codex-rs/app-server-protocol/schema/typescript/v2/index.tsindex b4c65946d5..bb19c92bdf 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts@@ -447,6 +447,7 @@ export type { TurnError } from "./TurnError";export type { TurnInterruptParams } from "./TurnInterruptParams";export type { TurnInterruptResponse } from "./TurnInterruptResponse";export type { TurnItemsView } from "./TurnItemsView";+export type { TurnModerationMetadataNotification } from "./TurnModerationMetadataNotification";export type { TurnPlanStep } from "./TurnPlanStep";export type { TurnPlanStepStatus } from "./TurnPlanStepStatus";export type { TurnPlanUpdatedNotification } from "./TurnPlanUpdatedNotification";diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rsindex 5a60d8d002..47410551cf 100644--- a/codex-rs/app-server-protocol/src/protocol/common.rs+++ b/codex-rs/app-server-protocol/src/protocol/common.rs@@ -1549,6 +1549,8 @@ server_notification_definitions! {ContextCompacted => "thread/compacted" (v2::ContextCompactedNotification),ModelRerouted => "model/rerouted" (v2::ModelReroutedNotification),ModelVerification => "model/verification" (v2::ModelVerificationNotification),+ #[experimental("turn/moderationMetadata")]+ TurnModerationMetadata => "turn/moderationMetadata" (v2::TurnModerationMetadataNotification),Warning => "warning" (v2::WarningNotification),GuardianWarning => "guardianWarning" (v2::GuardianWarningNotification),DeprecationNotice => "deprecationNotice" (v2::DeprecationNoticeNotification),@@ -3222,6 +3224,21 @@ mod tests {);}+ #[test]+ fn turn_moderation_metadata_notification_is_marked_experimental() {+ let notification =+ ServerNotification::TurnModerationMetadata(v2::TurnModerationMetadataNotification {+ thread_id: "thr_123".to_string(),+ turn_id: "turn_123".to_string(),+ metadata: json!({"presentation": "inline"}),+ });++ assert_eq!(+ crate::experimental_api::ExperimentalApi::experimental_reason(¬ification),+ Some("turn/moderationMetadata")+ );+ }+#[test]fn thread_realtime_started_notification_is_marked_experimental() {let notification =diff --git a/codex-rs/app-server-protocol/src/protocol/v2/model.rs b/codex-rs/app-server-protocol/src/protocol/v2/model.rsindex 7f97d791a6..d8fa249582 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/model.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/model.rs@@ -8,6 +8,7 @@ use codex_protocol::protocol::ModelVerification as CoreModelVerification;use schemars::JsonSchema;use serde::Deserialize;use serde::Serialize;+use serde_json::Value as JsonValue;use ts_rs::TS;v2_enum_from_core!(@@ -152,3 +153,12 @@ pub struct ModelVerificationNotification {pub turn_id: String,pub verifications: Vec<ModelVerification>,}++#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]+#[serde(rename_all = "camelCase")]+#[ts(export_to = "v2/")]+pub struct TurnModerationMetadataNotification {+ pub thread_id: String,+ pub turn_id: String,+ pub metadata: JsonValue,+}diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.mdindex 6d705afa98..d112eeff9d 100644--- a/codex-rs/app-server/README.md+++ b/codex-rs/app-server/README.md@@ -1244,6 +1244,7 @@ The app-server streams JSON-RPC notifications while a turn is running. Each turn- `turn/plan/updated` — `{ turnId, explanation?, plan }` whenever the agent shares or changes its plan; each `plan` entry is `{ step, status }` with `status` in `pending`, `inProgress`, or `completed`.- `model/rerouted` — `{ threadId, turnId, fromModel, toModel, reason }` when the backend reroutes a request to a different model (for example, due to high-risk cyber safety checks).- `model/verification` — `{ threadId, turnId, verifications }` when the backend flags additional account verification, such as `trustedAccessForCyber`.+- `turn/moderationMetadata` — experimental; `{ threadId, turnId, metadata }` when a first-party backend supplies turn-scoped moderation metadata for client-side presentation.Today both notifications carry an empty `items` array even when item events were streamed; rely on `item/*` notifications for the canonical item list until this is fixed.diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rsindex f4a5f3b45f..0cec31b6f2 100644--- a/codex-rs/app-server/src/bespoke_event_handling.rs+++ b/codex-rs/app-server/src/bespoke_event_handling.rs@@ -75,6 +75,7 @@ use codex_app_server_protocol::TurnDiffUpdatedNotification;use codex_app_server_protocol::TurnError;use codex_app_server_protocol::TurnInterruptResponse;use codex_app_server_protocol::TurnItemsView;+use codex_app_server_protocol::TurnModerationMetadataNotification;use codex_app_server_protocol::TurnPlanStep;use codex_app_server_protocol::TurnPlanUpdatedNotification;use codex_app_server_protocol::TurnStartedNotification;@@ -337,6 +338,16 @@ pub(crate) async fn apply_bespoke_event_handling(.send_server_notification(ServerNotification::ModelVerification(notification)).await;}+ EventMsg::TurnModerationMetadata(event) => {+ let notification = TurnModerationMetadataNotification {+ thread_id: conversation_id.to_string(),+ turn_id: event_turn_id.clone(),+ metadata: event.metadata,+ };+ outgoing+ .send_server_notification(ServerNotification::TurnModerationMetadata(notification))+ .await;+ }EventMsg::RealtimeConversationStarted(event) => {let notification = ThreadRealtimeStartedNotification {thread_id: conversation_id.to_string(),diff --git a/codex-rs/app-server/src/outgoing_message.rs b/codex-rs/app-server/src/outgoing_message.rsindex ac7e87741a..2e67e23398 100644--- a/codex-rs/app-server/src/outgoing_message.rs+++ b/codex-rs/app-server/src/outgoing_message.rs@@ -725,6 +725,7 @@ mod tests {use codex_app_server_protocol::RateLimitWindow;use codex_app_server_protocol::ServerResponse;use codex_app_server_protocol::ToolRequestUserInputParams;+ use codex_app_server_protocol::TurnModerationMetadataNotification;use codex_protocol::ThreadId;use pretty_assertions::assert_eq;use serde_json::json;@@ -951,6 +952,31 @@ mod tests {);}+ #[test]+ fn verify_turn_moderation_metadata_notification_serialization() {+ let notification =+ ServerNotification::TurnModerationMetadata(TurnModerationMetadataNotification {+ thread_id: "thread-1".to_string(),+ turn_id: "turn-1".to_string(),+ metadata: json!({"presentation": "inline"}),+ });++ let jsonrpc_notification = OutgoingMessage::AppServerNotification(notification);+ assert_eq!(+ json!({+ "method": "turn/moderationMetadata",+ "params": {+ "threadId": "thread-1",+ "turnId": "turn-1",+ "metadata": {"presentation": "inline"},+ },+ }),+ serde_json::to_value(jsonrpc_notification)+ .expect("ensure the notification serializes correctly"),+ "ensure the notification serializes correctly"+ );+ }+#[test]fn server_request_response_from_result_decodes_typed_response() {let request = ServerRequest::CommandExecutionRequestApproval {diff --git a/codex-rs/app-server/tests/suite/v2/safety_check_downgrade.rs b/codex-rs/app-server/tests/suite/v2/safety_check_downgrade.rsindex c5b70b2334..ea3cd8dada 100644--- a/codex-rs/app-server/tests/suite/v2/safety_check_downgrade.rs+++ b/codex-rs/app-server/tests/suite/v2/safety_check_downgrade.rs@@ -15,6 +15,7 @@ use codex_app_server_protocol::RequestId;use codex_app_server_protocol::ThreadItem;use codex_app_server_protocol::ThreadStartParams;use codex_app_server_protocol::ThreadStartResponse;+use codex_app_server_protocol::TurnModerationMetadataNotification;use codex_app_server_protocol::TurnStartParams;use codex_app_server_protocol::TurnStartResponse;use codex_app_server_protocol::UserInput;@@ -309,6 +310,87 @@ async fn model_verification_emits_typed_notification_and_warning_v2() -> Result<Ok(())}+#[tokio::test]+async fn turn_moderation_metadata_emits_typed_notification_v2() -> Result<()> {+ skip_if_no_network!(Ok(()));++ let server = responses::start_mock_server().await;+ let body = responses::sse(vec![+ responses::ev_response_created("resp-1"),+ serde_json::json!({+ "type": "response.metadata",+ "sequence_number": 1,+ "response_id": "resp-1",+ "metadata": {+ "openai_chatgpt_moderation_metadata": {+ "presentation": "inline"+ }+ }+ }),+ responses::ev_assistant_message("msg-1", "Done"),+ responses::ev_completed("resp-1"),+ ]);+ let response = responses::sse_response(body);+ let _response_mock = responses::mount_response_once(&server, response).await;++ let codex_home = TempDir::new()?;+ create_config_toml(codex_home.path(), &server.uri())?;++ let mut mcp = TestAppServer::new(codex_home.path()).await?;+ timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;++ let thread_req = mcp+ .send_thread_start_request(ThreadStartParams {+ model: Some(REQUESTED_MODEL.to_string()),+ ..Default::default()+ })+ .await?;+ let thread_resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(thread_req)),+ )+ .await??;+ let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(thread_resp)?;++ let turn_req = mcp+ .send_turn_start_request(TurnStartParams {+ thread_id: thread.id.clone(),+ client_user_message_id: None,+ input: vec![UserInput::Text {+ text: "trigger moderation metadata".to_string(),+ text_elements: Vec::new(),+ }],+ ..Default::default()+ })+ .await?;+ let turn_resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(turn_req)),+ )+ .await??;+ let turn_start: TurnStartResponse = to_response(turn_resp)?;++ let notification = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_notification_message("turn/moderationMetadata"),+ )+ .await??;+ let metadata: TurnModerationMetadataNotification =+ serde_json::from_value(notification.params.ok_or_else(|| {+ anyhow::anyhow!("turn/moderationMetadata notifications must include params")+ })?)?;+ assert_eq!(+ metadata,+ TurnModerationMetadataNotification {+ thread_id: thread.id,+ turn_id: turn_start.turn.id,+ metadata: serde_json::json!({"presentation": "inline"}),+ }+ );++ Ok(())+}+async fn collect_turn_notifications_and_validate_no_warning_item(mcp: &mut TestAppServer,) -> Result<ModelReroutedNotification> {diff --git a/codex-rs/codex-api/src/common.rs b/codex-rs/codex-api/src/common.rsindex 12f8cc55da..17753e799a 100644--- a/codex-rs/codex-api/src/common.rs+++ b/codex-rs/codex-api/src/common.rs@@ -6,6 +6,7 @@ use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;use codex_protocol::protocol::ModelVerification;use codex_protocol::protocol::RateLimitSnapshot;use codex_protocol::protocol::TokenUsage;+use codex_protocol::protocol::TurnModerationMetadataEvent;use codex_protocol::protocol::W3cTraceContext;use futures::Stream;use serde::Deserialize;@@ -78,6 +79,8 @@ pub enum ResponseEvent {ServerModel(String),/// Emitted when the server recommends additional account verification.ModelVerifications(Vec<ModelVerification>),+ /// Emitted when the server includes moderation metadata for first-party turn presentation.+ TurnModerationMetadata(TurnModerationMetadataEvent),/// Emitted when `X-Reasoning-Included: true` is present on the response,/// meaning the server already accounted for past reasoning tokens and the/// client should not re-estimate them.diff --git a/codex-rs/codex-api/src/endpoint/responses_websocket.rs b/codex-rs/codex-api/src/endpoint/responses_websocket.rsindex a7366a9871..44cb6a544b 100644--- a/codex-rs/codex-api/src/endpoint/responses_websocket.rs+++ b/codex-rs/codex-api/src/endpoint/responses_websocket.rs@@ -683,6 +683,7 @@ async fn run_websocket_response_stream(}};let model_verifications = event.model_verifications();+ let turn_moderation_metadata = event.turn_moderation_metadata();if event.kind() == "codex.rate_limits" {if let Some(snapshot) = parse_rate_limit_event(&text) {let _ = tx_event.send(Ok(ResponseEvent::RateLimits(snapshot))).await;@@ -707,6 +708,16 @@ async fn run_websocket_response_stream("response event consumer dropped".to_string(),));}+ if let Some(metadata) = turn_moderation_metadata+ && tx_event+ .send(Ok(ResponseEvent::TurnModerationMetadata(metadata)))+ .await+ .is_err()+ {+ return Err(ApiError::Stream(+ "response event consumer dropped".to_string(),+ ));+ }match process_responses_event(event) {Ok(Some(event)) => {let is_completed = matches!(event, ResponseEvent::Completed { .. });diff --git a/codex-rs/codex-api/src/sse/responses.rs b/codex-rs/codex-api/src/sse/responses.rsindex c9f35e5a4e..ab1be640df 100644--- a/codex-rs/codex-api/src/sse/responses.rs+++ b/codex-rs/codex-api/src/sse/responses.rs@@ -8,6 +8,7 @@ use codex_client::StreamResponse;use codex_protocol::models::ResponseItem;use codex_protocol::protocol::ModelVerification;use codex_protocol::protocol::TokenUsage;+use codex_protocol::protocol::TurnModerationMetadataEvent;use eventsource_stream::Eventsource;use futures::StreamExt;use serde::Deserialize;@@ -193,6 +194,18 @@ impl ResponsesStreamEvent {.and_then(|metadata| metadata.get("openai_verification_recommendation")).and_then(model_verifications_from_json_value)}++ pub(crate) fn turn_moderation_metadata(&self) -> Option<TurnModerationMetadataEvent> {+ if self.kind() != "response.metadata" {+ return None;+ }++ self.metadata+ .as_ref()+ .and_then(|metadata| metadata.get("openai_chatgpt_moderation_metadata"))+ .cloned()+ .map(|metadata| TurnModerationMetadataEvent { metadata })+ }}fn header_openai_model_value_from_json(value: &Value) -> Option<String> {@@ -444,6 +457,7 @@ pub async fn process_sse(}};let model_verifications = event.model_verifications();+ let turn_moderation_metadata = event.turn_moderation_metadata();if let Some(model) = event.response_model()&& last_server_model.as_deref() != Some(model.as_str())@@ -465,6 +479,14 @@ pub async fn process_sse({return;}+ if let Some(metadata) = turn_moderation_metadata+ && tx_event+ .send(Ok(ResponseEvent::TurnModerationMetadata(metadata)))+ .await+ .is_err()+ {+ return;+ }match process_responses_event(event) {Ok(Some(event)) => {@@ -1215,6 +1237,41 @@ mod tests {);}+ #[tokio::test]+ async fn process_sse_emits_turn_moderation_metadata_field() {+ let events = run_sse(vec![+ json!({+ "type": "response.metadata",+ "metadata": {+ "openai_chatgpt_moderation_metadata": {+ "presentation": "inline"+ }+ }+ }),+ json!({+ "type": "response.completed",+ "response": {+ "id": "resp-1"+ }+ }),+ ])+ .await;++ assert_matches!(+ &events[0],+ ResponseEvent::TurnModerationMetadata(result)+ if result.metadata == json!({"presentation": "inline"})+ );+ assert_matches!(+ &events[1],+ ResponseEvent::Completed {+ response_id,+ token_usage: None,+ end_turn: None,+ } if response_id == "resp-1"+ );+ }+#[test]fn responses_stream_event_response_model_reads_top_level_headers() {let ev: ResponsesStreamEvent = serde_json::from_value(json!({diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rsindex 9aeca1991b..1b40bd7656 100644--- a/codex-rs/core/src/session/mod.rs+++ b/codex-rs/core/src/session/mod.rs@@ -359,6 +359,7 @@ use codex_protocol::protocol::ThreadMemoryMode;use codex_protocol::protocol::TokenCountEvent;use codex_protocol::protocol::TokenUsage;use codex_protocol::protocol::TokenUsageInfo;+use codex_protocol::protocol::TurnModerationMetadataEvent;use codex_protocol::protocol::WarningEvent;use codex_protocol::user_input::UserInput;use codex_tools::ToolEnvironmentMode;@@ -2637,6 +2638,15 @@ impl Session {.await;}+ pub(crate) async fn emit_turn_moderation_metadata(+ self: &Arc<Self>,+ turn_context: &Arc<TurnContext>,+ metadata: TurnModerationMetadataEvent,+ ) {+ self.send_event(turn_context, EventMsg::TurnModerationMetadata(metadata))+ .await;+ }+pub(crate) async fn replace_history(&self,items: Vec<ResponseItem>,diff --git a/codex-rs/core/src/session/turn.rs b/codex-rs/core/src/session/turn.rsindex 996e59187e..63195d9fa7 100644--- a/codex-rs/core/src/session/turn.rs+++ b/codex-rs/core/src/session/turn.rs@@ -1392,6 +1392,7 @@ pub(super) fn realtime_text_for_event(msg: &EventMsg) -> Option<String> {| EventMsg::RealtimeConversationClosed(_)| EventMsg::ModelReroute(_)| EventMsg::ModelVerification(_)+ | EventMsg::TurnModerationMetadata(_)| EventMsg::ContextCompacted(_)| EventMsg::ThreadRolledBack(_)| EventMsg::TurnStarted(_)@@ -2057,6 +2058,10 @@ async fn try_run_sampling_request(.await;}}+ ResponseEvent::TurnModerationMetadata(metadata) => {+ sess.emit_turn_moderation_metadata(&turn_context, metadata)+ .await;+ }ResponseEvent::ServerReasoningIncluded(included) => {sess.set_server_reasoning_included(included).await;}diff --git a/codex-rs/core/src/turn_timing.rs b/codex-rs/core/src/turn_timing.rsindex bcb3cb8b9e..445fe16214 100644--- a/codex-rs/core/src/turn_timing.rs+++ b/codex-rs/core/src/turn_timing.rs@@ -147,6 +147,7 @@ fn response_event_records_turn_ttft(event: &ResponseEvent) -> bool {ResponseEvent::Created| ResponseEvent::ServerModel(_)| ResponseEvent::ModelVerifications(_)+ | ResponseEvent::TurnModerationMetadata(_)| ResponseEvent::ServerReasoningIncluded(_)| ResponseEvent::ToolCallInputDelta { .. }| ResponseEvent::Completed { .. }diff --git a/codex-rs/mcp-server/src/codex_tool_runner.rs b/codex-rs/mcp-server/src/codex_tool_runner.rsindex 05b995e721..fd56805d4e 100644--- a/codex-rs/mcp-server/src/codex_tool_runner.rs+++ b/codex-rs/mcp-server/src/codex_tool_runner.rs@@ -266,7 +266,8 @@ async fn run_codex_tool_session_inner(}EventMsg::Warning(_)| EventMsg::GuardianWarning(_)- | EventMsg::ModelVerification(_) => {+ | EventMsg::ModelVerification(_)+ | EventMsg::TurnModerationMetadata(_) => {continue;}EventMsg::GuardianAssessment(_) => {diff --git a/codex-rs/otel/src/events/session_telemetry.rs b/codex-rs/otel/src/events/session_telemetry.rsindex 65ca0c4530..00c13046dd 100644--- a/codex-rs/otel/src/events/session_telemetry.rs+++ b/codex-rs/otel/src/events/session_telemetry.rs@@ -1208,6 +1208,7 @@ impl SessionTelemetry {}ResponseEvent::ServerModel(_) => "server_model".into(),ResponseEvent::ModelVerifications(_) => "model_verifications".into(),+ ResponseEvent::TurnModerationMetadata(_) => "turn_moderation_metadata".into(),ResponseEvent::ServerReasoningIncluded(_) => "server_reasoning_included".into(),ResponseEvent::RateLimits(_) => "rate_limits".into(),ResponseEvent::ModelsEtag(_) => "models_etag".into(),diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rsindex b3538a27a1..ed278d1843 100644--- a/codex-rs/protocol/src/protocol.rs+++ b/codex-rs/protocol/src/protocol.rs@@ -1221,6 +1221,9 @@ pub enum EventMsg {/// Backend recommends additional account verification for this turn.ModelVerification(ModelVerificationEvent),+ /// Backend moderation metadata intended for first-party turn presentation.+ TurnModerationMetadata(TurnModerationMetadataEvent),+/// Conversation history was compacted (either automatically or manually).ContextCompacted(ContextCompactedEvent),@@ -1885,6 +1888,11 @@ pub struct ModelVerificationEvent {pub verifications: Vec<ModelVerification>,}+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]+pub struct TurnModerationMetadataEvent {+ pub metadata: Value,+}+#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]pub struct ContextCompactedEvent;diff --git a/codex-rs/rollout-trace/src/protocol_event.rs b/codex-rs/rollout-trace/src/protocol_event.rsindex a862af116c..a3e1f184ec 100644--- a/codex-rs/rollout-trace/src/protocol_event.rs+++ b/codex-rs/rollout-trace/src/protocol_event.rs@@ -224,6 +224,7 @@ pub(crate) fn tool_runtime_trace_event(event: &EventMsg) -> Option<ToolRuntimeTr| EventMsg::RealtimeConversationSdp(_)| EventMsg::ModelReroute(_)| EventMsg::ModelVerification(_)+ | EventMsg::TurnModerationMetadata(_)| EventMsg::ContextCompacted(_)| EventMsg::ThreadRolledBack(_)| EventMsg::ThreadGoalUpdated(_)@@ -297,6 +298,7 @@ pub(crate) fn wrapped_protocol_event_type(event: &EventMsg) -> Option<&'static s| EventMsg::RealtimeConversationSdp(_)| EventMsg::ModelReroute(_)| EventMsg::ModelVerification(_)+ | EventMsg::TurnModerationMetadata(_)| EventMsg::ContextCompacted(_)| EventMsg::ThreadSettingsApplied(_)| EventMsg::TokenCount(_)diff --git a/codex-rs/rollout/src/policy.rs b/codex-rs/rollout/src/policy.rsindex d1a0045cd9..17da9e6203 100644--- a/codex-rs/rollout/src/policy.rs+++ b/codex-rs/rollout/src/policy.rs@@ -117,6 +117,7 @@ pub fn should_persist_event_msg(ev: &EventMsg) -> bool {| EventMsg::RealtimeConversationClosed(_)| EventMsg::ModelReroute(_)| EventMsg::ModelVerification(_)+ | EventMsg::TurnModerationMetadata(_)| EventMsg::AgentReasoningSectionBreak(_)| EventMsg::RawResponseItem(_)| EventMsg::SessionConfigured(_)diff --git a/codex-rs/tui/src/app/app_server_event_targets.rs b/codex-rs/tui/src/app/app_server_event_targets.rsindex 0b2143b429..ea9fce90fb 100644--- a/codex-rs/tui/src/app/app_server_event_targets.rs+++ b/codex-rs/tui/src/app/app_server_event_targets.rs@@ -118,6 +118,9 @@ pub(super) fn server_notification_thread_target(ServerNotification::ModelVerification(notification) => {Some(notification.thread_id.as_str())}+ ServerNotification::TurnModerationMetadata(notification) => {+ Some(notification.thread_id.as_str())+ }ServerNotification::ThreadRealtimeStarted(notification) => {Some(notification.thread_id.as_str())}diff --git a/codex-rs/tui/src/chatwidget/protocol.rs b/codex-rs/tui/src/chatwidget/protocol.rsindex 6d56330367..1ddbe40d54 100644--- a/codex-rs/tui/src/chatwidget/protocol.rs+++ b/codex-rs/tui/src/chatwidget/protocol.rs@@ -233,6 +233,7 @@ impl ChatWidget {| ServerNotification::RemoteControlStatusChanged(_)| ServerNotification::ExternalAgentConfigImportCompleted(_)| ServerNotification::FsChanged(_)+ | ServerNotification::TurnModerationMetadata(_)| ServerNotification::FuzzyFileSearchSessionUpdated(_)| ServerNotification::FuzzyFileSearchSessionCompleted(_)| ServerNotification::ThreadRealtimeTranscriptDelta(_)