mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:22:05 +00:00
Enforce subagent ownership across app-server inputs (#40464)
## Why Parent-owned Multi-Agent V2 subagents must remain controlled by their parent, but several app-server endpoints could still mutate them directly. ## What changed - Centralize the direct-input ownership check and apply it to turn injection, MCP calls, reviews, compaction, rollback and revert, shell and Guardian actions, realtime requests, and goal mutations. - Enforce the same policy for goal mutations on unloaded threads while keeping goal reads and turn interruption available. - Document the affected endpoint behavior and continue exposing `canAcceptDirectInput: false` for parent-owned subagents. ## Testing - Cover direct-input rejection for both legacy and paginated thread history. - Cover goal mutation ownership checks for unloaded V2 subagents, V1 subagents, and non-subagent V2 threads. GitOrigin-RevId: 791b7af98490aed5eab4e672b90661acad11ec23
This commit is contained in:
1 parent
bf3eb2ec91
commit
b6333bb1bb
12 files changed
+419
-62
No files matched your search
@@ -1,3 +1,4 @@
|
||||
use super::thread_input::ensure_direct_input_allowed;
|
||||
use super::*;
|
||||
use codex_agent_extension::AgentInvocation;
|
||||
use codex_agent_extension::AgentRun;
|
||||
@@ -7,29 +8,11 @@ use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::FunctionCallOutputContentItem;
|
||||
use codex_protocol::protocol::AdditionalContextEntry as CoreAdditionalContextEntry;
|
||||
use codex_protocol::protocol::AdditionalContextKind as CoreAdditionalContextKind;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_skills::system_cache_root_dir;
|
||||
|
||||
use crate::image_url::REMOTE_IMAGE_URL_ERROR;
|
||||
use crate::image_url::is_remote_image_url;
|
||||
|
||||
pub(super) const DIRECT_INPUT_TO_MULTI_AGENT_V2_SUBAGENT_ERROR: &str =
|
||||
"direct app-server input is not allowed for multi-agent v2 sub-agents";
|
||||
|
||||
/// Mirrors the direct-input policy in both request validation and thread capability responses.
|
||||
pub(super) fn can_accept_direct_input(
|
||||
multi_agent_version: Option<MultiAgentVersion>,
|
||||
session_source: &SessionSource,
|
||||
) -> bool {
|
||||
multi_agent_version != Some(MultiAgentVersion::V2)
|
||||
|| !matches!(
|
||||
session_source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn validate_user_input_image_urls(
|
||||
input: &[V2UserInput],
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
@@ -196,9 +179,10 @@ impl TurnRequestProcessor {
|
||||
|
||||
pub(crate) async fn thread_inject_items(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ThreadInjectItemsParams,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.thread_inject_items_response_inner(params)
|
||||
self.thread_inject_items_response_inner(request_id, params)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
@@ -343,17 +327,11 @@ impl TurnRequestProcessor {
|
||||
request_id: &ConnectionRequestId,
|
||||
thread: &CodexThread,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
if !can_accept_direct_input(
|
||||
thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
) {
|
||||
let error = invalid_request(DIRECT_INPUT_TO_MULTI_AGENT_V2_SUBAGENT_ERROR);
|
||||
self.track_error_response(request_id, &error, /*error_type*/ None);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
ensure_direct_input_allowed(thread)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
self.track_error_response(request_id, error, /*error_type*/ None);
|
||||
})
|
||||
}
|
||||
|
||||
fn normalize_collaboration_mode(
|
||||
@@ -870,9 +848,12 @@ impl TurnRequestProcessor {
|
||||
|
||||
async fn thread_inject_items_response_inner(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ThreadInjectItemsParams,
|
||||
) -> Result<ThreadInjectItemsResponse, JSONRPCErrorError> {
|
||||
let (_, thread) = self.load_thread(¶ms.thread_id).await?;
|
||||
self.ensure_direct_input_allowed(request_id, thread.as_ref())
|
||||
.await?;
|
||||
|
||||
let items = params
|
||||
.items
|
||||
@@ -1052,6 +1033,8 @@ impl TurnRequestProcessor {
|
||||
thread_id: &str,
|
||||
) -> Result<Option<(ThreadId, Arc<CodexThread>)>, JSONRPCErrorError> {
|
||||
let (thread_id, thread) = self.load_thread(thread_id).await?;
|
||||
self.ensure_direct_input_allowed(request_id, thread.as_ref())
|
||||
.await?;
|
||||
|
||||
match self
|
||||
.ensure_conversation_listener(
|
||||
@@ -1439,6 +1422,8 @@ impl TurnRequestProcessor {
|
||||
} = params;
|
||||
|
||||
let (_, parent_thread) = self.load_thread(&thread_id).await?;
|
||||
self.ensure_direct_input_allowed(request_id, parent_thread.as_ref())
|
||||
.await?;
|
||||
let (review_request, display_text, target_prompt) =
|
||||
Self::review_request_from_target(target)?;
|
||||
match delivery.unwrap_or(ApiReviewDelivery::Inline).to_core() {
|
||||
|
||||
Reference in new issue
Block a user