From 82a4a3681e6dd48a1bfaf10d3f98eddd292ed2e3 Mon Sep 17 00:00:00 2001 From: Francis Chalissery Date: Tue, 23 Jun 2026 10:13:43 -0700 Subject: [PATCH] Propagate safety buffering learn-more link --- .../schema/json/ServerNotification.json | 6 ++++++ .../codex_app_server_protocol.schemas.json | 6 ++++++ .../codex_app_server_protocol.v2.schemas.json | 6 ++++++ ...delSafetyBufferingUpdatedNotification.json | 6 ++++++ ...ModelSafetyBufferingUpdatedNotification.ts | 2 +- .../src/protocol/common.rs | 4 +++- .../src/protocol/v2/model.rs | 1 + .../app-server/src/bespoke_event_handling.rs | 1 + codex-rs/codex-api/src/common.rs | 4 ++++ codex-rs/codex-api/src/safety_buffering.rs | 19 +++++++++++++------ codex-rs/core/src/session/turn.rs | 1 + codex-rs/core/tests/suite/safety_buffering.rs | 5 ++++- codex-rs/protocol/src/protocol.rs | 1 + 13 files changed, 53 insertions(+), 9 deletions(-) diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json index b79e3cb13f..91543a79c3 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -2591,6 +2591,12 @@ "null" ] }, + "learnMoreLink": { + "type": [ + "string", + "null" + ] + }, "model": { "type": "string" }, 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.json index 597fd5a1b8..8c299fcbf0 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 @@ -12648,6 +12648,12 @@ "null" ] }, + "learnMoreLink": { + "type": [ + "string", + "null" + ] + }, "model": { "type": "string" }, 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.json index 3af48cc6c0..757b1e38ac 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 @@ -9052,6 +9052,12 @@ "null" ] }, + "learnMoreLink": { + "type": [ + "string", + "null" + ] + }, "model": { "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/json/v2/ModelSafetyBufferingUpdatedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ModelSafetyBufferingUpdatedNotification.json index ab542b6399..3597c0bcba 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ModelSafetyBufferingUpdatedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ModelSafetyBufferingUpdatedNotification.json @@ -7,6 +7,12 @@ "null" ] }, + "learnMoreLink": { + "type": [ + "string", + "null" + ] + }, "model": { "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ModelSafetyBufferingUpdatedNotification.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ModelSafetyBufferingUpdatedNotification.ts index 5abc9f3bf6..7bd405b31d 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/ModelSafetyBufferingUpdatedNotification.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ModelSafetyBufferingUpdatedNotification.ts @@ -2,4 +2,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type ModelSafetyBufferingUpdatedNotification = { threadId: string, turnId: string, model: string, useCases: Array, reasons: Array, showBufferingUi: boolean, fasterModel: string | null, }; +export type ModelSafetyBufferingUpdatedNotification = { threadId: string, turnId: string, model: string, useCases: Array, reasons: Array, showBufferingUi: boolean, fasterModel: string | null, learnMoreLink: string | null, }; diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index ba63f59e9a..2ce39c18aa 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -3397,6 +3397,7 @@ mod tests { reasons: vec!["user_risk".to_string()], show_buffering_ui: true, faster_model: Some("faster-model".to_string()), + learn_more_link: Some("https://example.com/safety".to_string()), }, ); assert_eq!( @@ -3409,7 +3410,8 @@ mod tests { "useCases": ["cyber"], "reasons": ["user_risk"], "showBufferingUi": true, - "fasterModel": "faster-model" + "fasterModel": "faster-model", + "learnMoreLink": "https://example.com/safety" } }), serde_json::to_value(¬ification)?, diff --git a/codex-rs/app-server-protocol/src/protocol/v2/model.rs b/codex-rs/app-server-protocol/src/protocol/v2/model.rs index bb6c411124..d334a863e4 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/model.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/model.rs @@ -174,4 +174,5 @@ pub struct ModelSafetyBufferingUpdatedNotification { pub reasons: Vec, pub show_buffering_ui: bool, pub faster_model: Option, + pub learn_more_link: Option, } diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rs index 36dbdd9d3b..f3ad07af34 100644 --- a/codex-rs/app-server/src/bespoke_event_handling.rs +++ b/codex-rs/app-server/src/bespoke_event_handling.rs @@ -361,6 +361,7 @@ pub(crate) async fn apply_bespoke_event_handling( reasons: event.reasons, show_buffering_ui: event.show_buffering_ui, faster_model: event.faster_model, + learn_more_link: event.learn_more_link, }; outgoing .send_server_notification(ServerNotification::ModelSafetyBufferingUpdated( diff --git a/codex-rs/codex-api/src/common.rs b/codex-rs/codex-api/src/common.rs index bd037deb58..a74764afb5 100644 --- a/codex-rs/codex-api/src/common.rs +++ b/codex-rs/codex-api/src/common.rs @@ -123,12 +123,15 @@ pub struct SafetyBuffering { pub show_buffering_ui: bool, #[serde(skip)] pub faster_model: Option, + #[serde(skip)] + pub learn_more_link: Option, } impl SafetyBuffering { pub(crate) fn with_treatment(mut self, treatment: &SafetyBufferingTreatment) -> Self { self.show_buffering_ui = treatment.show_buffering_ui; self.faster_model.clone_from(&treatment.faster_model); + self.learn_more_link.clone_from(&treatment.learn_more_link); self } } @@ -137,6 +140,7 @@ impl SafetyBuffering { pub(crate) struct SafetyBufferingTreatment { pub show_buffering_ui: bool, pub faster_model: Option, + pub learn_more_link: Option, } #[derive(Debug, Serialize, Clone, PartialEq)] diff --git a/codex-rs/codex-api/src/safety_buffering.rs b/codex-rs/codex-api/src/safety_buffering.rs index e5f3dcd79e..735b0e4cb6 100644 --- a/codex-rs/codex-api/src/safety_buffering.rs +++ b/codex-rs/codex-api/src/safety_buffering.rs @@ -4,24 +4,26 @@ use http::HeaderMap; pub(crate) const X_CODEX_SAFETY_BUFFERING_ENABLED_HEADER: &str = "x-codex-safety-buffering-enabled"; pub(crate) const X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER: &str = "x-codex-safety-buffering-faster-model"; +pub(crate) const X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER: &str = + "x-codex-safety-buffering-learn-more-link"; pub(crate) fn treatment_from_headers(headers: &HeaderMap) -> Option { let show_buffering_ui = headers .get(X_CODEX_SAFETY_BUFFERING_ENABLED_HEADER) .and_then(|value| value.to_str().ok())? .eq_ignore_ascii_case("true"); - let faster_model = if show_buffering_ui { - headers - .get(X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER) + let treatment_value = |header| { + show_buffering_ui + .then(|| headers.get(header)) + .flatten() .and_then(|value| value.to_str().ok()) .map(str::to_string) - } else { - None }; Some(SafetyBufferingTreatment { show_buffering_ui, - faster_model, + faster_model: treatment_value(X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER), + learn_more_link: treatment_value(X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER), }) } @@ -42,12 +44,17 @@ mod tests { X_CODEX_SAFETY_BUFFERING_FASTER_MODEL_HEADER, HeaderValue::from_static("faster-model"), ); + headers.insert( + X_CODEX_SAFETY_BUFFERING_LEARN_MORE_LINK_HEADER, + HeaderValue::from_static("https://example.com/safety"), + ); assert_eq!( treatment_from_headers(&headers), Some(SafetyBufferingTreatment { show_buffering_ui: true, faster_model: Some("faster-model".to_string()), + learn_more_link: Some("https://example.com/safety".to_string()), }) ); } diff --git a/codex-rs/core/src/session/turn.rs b/codex-rs/core/src/session/turn.rs index 84442a6caf..64b10b0e08 100644 --- a/codex-rs/core/src/session/turn.rs +++ b/codex-rs/core/src/session/turn.rs @@ -2237,6 +2237,7 @@ async fn try_run_sampling_request( reasons: buffering.reasons, show_buffering_ui: buffering.show_buffering_ui, faster_model: buffering.faster_model, + learn_more_link: buffering.learn_more_link, }), ) .await; diff --git a/codex-rs/core/tests/suite/safety_buffering.rs b/codex-rs/core/tests/suite/safety_buffering.rs index 6e41b23766..eb31cfbb56 100644 --- a/codex-rs/core/tests/suite/safety_buffering.rs +++ b/codex-rs/core/tests/suite/safety_buffering.rs @@ -17,6 +17,7 @@ use pretty_assertions::assert_eq; use serde_json::json; const FASTER_MODEL: &str = "faster-model"; +const LEARN_MORE_LINK: &str = "https://example.com/safety"; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()> { @@ -32,7 +33,8 @@ async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()> &server, sse_response(sse(vec![created, ev_completed("resp-1")])) .insert_header("x-codex-safety-buffering-enabled", "true") - .insert_header("x-codex-safety-buffering-faster-model", FASTER_MODEL), + .insert_header("x-codex-safety-buffering-faster-model", FASTER_MODEL) + .insert_header("x-codex-safety-buffering-learn-more-link", LEARN_MORE_LINK), ) .await; @@ -63,6 +65,7 @@ async fn emits_safety_buffering_with_the_requested_model() -> anyhow::Result<()> reasons: vec!["policy-check".to_string()], show_buffering_ui: true, faster_model: Some(FASTER_MODEL.to_string()), + learn_more_link: Some(LEARN_MORE_LINK.to_string()), } ); wait_for_event(&test.codex, |event| { diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index 8a678281d2..9933dbd2b6 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -1955,6 +1955,7 @@ pub struct SafetyBufferingEvent { pub reasons: Vec, pub show_buffering_ui: bool, pub faster_model: Option, + pub learn_more_link: Option, } #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]