Present encrypted subagent replies as evidence in Guardian reviews (#63926)

## Why

Encrypted replies from subagents can provide evidence for a Guardian
decision. Reviewer compaction can drop those replies when it filters
descendant progress and completion messages.

## What changed

When native multi-agent history is enabled and the reviewer uses the
OpenAI provider, send encrypted replies from descendants to ancestors
as standalone `guardian.subagent_reply` tool outputs in Guardian review
and async scoring requests. Include the sender and recipient, preserve
the encrypted payload, and keep native message IDs in stored history
for deduplication.

Retain qualifying replies across reviewer compaction within the existing
per-message and shared token budgets.

## Testing

Extend regression coverage for incremental reviews, compaction recovery
with and without native agent review, and reply ID stability across
retained WebSocket scoring requests.

GitOrigin-RevId: bb46149426b1a60a6ed5cac6765283ec77682d23
This commit is contained in:
jif
2026-11-25 14:22:54 +00:00
committed by copyberry
parent e8fb104cd6
commit d3ca5182df
15 changed files with 339 additions and 45 deletions
@@ -17,12 +17,26 @@ async fn retained_websocket_requests_preserve_model_output_and_ids() -> Result<(
];
let ws =
responses::start_websocket_server(vec![Vec::new(), vec![events.clone(), events]]).await;
let sampler = connect_sampler(sampler_config(format!(
let mut config = sampler_config(format!(
"http://{}/v1",
ws.uri().trim_start_matches("ws://")
)))
.await?;
));
config.quote_guardian_replies = true;
let sampler = connect_sampler(config).await?;
let mut committed = sample_request("parent").input;
let root = codex_protocol::AgentPath::root();
let mut child = codex_protocol::protocol::InterAgentCommunication::new_encrypted(
root.join("scoring").expect("scoring path"),
root,
Vec::new(),
"opaque-score".into(),
/*trigger_turn*/ false,
)
.to_model_input_item();
child.set_id(Some(codex_protocol::ResponseItemId::with_suffix(
"amsg", "child",
)));
committed.push(child);
let mut output = Vec::new();
for _ in 0..2 {
let (ready, score) = tokio::sync::oneshot::channel();
@@ -74,9 +88,20 @@ async fn retained_websocket_requests_preserve_model_output_and_ids() -> Result<(
let first = requests[0].body_json();
assert_eq!(first["include"], json!(["reasoning.encrypted_content"]));
let second = requests[1].body_json();
assert_eq!(second["input"][0], first["input"][0]);
let reply = &first["input"][1];
assert_eq!(reply["type"], "function_call_output");
assert_eq!(reply["id"], "fco_child");
assert_eq!(reply["namespace"], "guardian");
assert_eq!(reply["name"], "subagent_reply");
assert!(reply.get("call_id").is_none());
assert_eq!(
json!(&second["input"].as_array().unwrap()[1..1 + output.len()]),
reply["output"][1],
json!({"type": "encrypted_content", "encrypted_content": "opaque-score"})
);
assert_eq!(second["input"][0], first["input"][0]);
assert_eq!(&second["input"][1], reply);
assert_eq!(
json!(&second["input"].as_array().unwrap()[2..2 + output.len()]),
serde_json::to_value(&output)?
);
Ok(())
@@ -47,6 +47,7 @@ const MAX_CONCURRENT_REQUESTS: usize = 16;
/// Host-owned provider, authentication, and attribution for one Luna connection.
pub struct LunaSamplerConfig {
pub quote_guardian_replies: bool,
/// Provider and credentials selected for the owning thread.
pub provider: SharedModelProvider,
/// Provider and feature policy shared with ordinary model requests.
@@ -332,12 +333,24 @@ impl LunaSampler {
.map(|envelope| (envelope.item, envelope.metadata))
.unzip();
let mut execution = self.execution(&sampling, input, auth_owner);
// Only the request sees tool outputs. Restore native replies for transcript deduplication.
let mut native_replies = Vec::new();
if self.config.quote_guardian_replies {
for (index, item) in execution.request.input.iter_mut().enumerate() {
if let Some(output) = codex_guardian_context::subagent_reply_output(item) {
native_replies.push((index, std::mem::replace(item, output)));
}
}
}
execution.request.include = vec!["reasoning.encrypted_content".to_owned()];
let mut telemetry = telemetry::SamplingTelemetry::new(
self.config.metrics.clone(),
sampling.pending_score.clone(),
);
let result = execution.run(&mut completion, &mut telemetry).await;
for (index, item) in native_replies {
execution.request.input[index] = item;
}
execution
.request
.input
@@ -243,6 +243,7 @@ pub(in crate::async_scorer) async fn proxy_websocket_servers_with_http(
pub(in crate::async_scorer) fn sampler_config(base_url: String) -> LunaSamplerConfig {
LunaSamplerConfig {
quote_guardian_replies: false,
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
inherit_parent_cyber_access_program: true,
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
@@ -662,6 +663,7 @@ async fn preconnected_sampler_reuses_authenticated_websocket_for_classifications
);
let sampler = connect_sampler(LunaSamplerConfig {
quote_guardian_replies: false,
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
inherit_parent_cyber_access_program: true,
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
@@ -848,6 +850,7 @@ async fn sampler_returns_classification_token_before_terminal_response_events()
))),
);
let sampler = connect_sampler(LunaSamplerConfig {
quote_guardian_replies: false,
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
inherit_parent_cyber_access_program: true,
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
@@ -156,6 +156,7 @@ pub(super) async fn sampler_config(
});
let luna_compaction_hash = luna_model.and_then(|model| model.comp_hash.clone());
Ok(LunaSamplerConfig {
quote_guardian_replies: input.config.guardian_quotes_subagent_replies(&provider_id),
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::for_provider(
provider.info(),
&provider_id,