Add attachment upload and resolution APIs and pass stores into sessions (#45556)

## What changed

Replace `AttachmentStore::persist` with `upload` and `resolve`. Uploads return inline bytes or a file ID; resolution returns optional file metadata and a download URL only when a minimum URL lifetime is requested. Add image dimensions, digest, size, MIME type, and categorized errors to the API.

Make `InlineAttachmentStore` return the original bytes and report `NotFound` when resolving file IDs. Redact attachment bytes and file URLs in debug output.

Pass the configured image store from the thread manager into sessions and inherit it in delegated sessions. Allow `TestCodexBuilder` to accept a custom image store.

## Testing

Update unit coverage for preserving PNG and JPEG bytes, redacting bytes and URLs in debug output, and rejecting file resolution in the inline store.

GitOrigin-RevId: f313e0048925998d84394c7e5a278e0d39d86a45
This commit is contained in:
Krish Chainani authored and copyberry committed 2026-09-15 00:29:13 +00:00
1 parent 364b511dcd
commit 446b771049
13 files changed
+247 -89

No files matched your search

+1
View File
@@ -127,6 +127,7 @@ pub(crate) async fn run_codex_thread_interactive(
client_mcp_extensions: parent_session.services.client_mcp_extensions.clone(),
reserved_thread_id: None,
analytics_events_client: Some(parent_session.services.analytics_events_client.clone()),
image_store: Arc::clone(&parent_session.services.image_store),
thread_store: Arc::clone(&parent_session.services.thread_store),
attestation_provider: parent_session.services.attestation_provider.clone(),
external_time_provider: Some(Arc::clone(&parent_session.services.time_provider)),
+4
View File
@@ -64,6 +64,7 @@ use codex_analytics::ImagePreparationMetadata;
use codex_analytics::SubAgentThreadStartedInput;
use codex_analytics::TurnCodexErrorFact;
use codex_async_utils::OrCancelExt;
use codex_attachment_store::AttachmentStore;
use codex_connectors::connector_runtime_context_key;
use codex_context_fragments::RenderedFragment;
use codex_exec_server::Environment;
@@ -468,6 +469,7 @@ pub(crate) struct SessionSpawnArgs {
pub(crate) client_mcp_extensions: ClientMcpExtensions,
pub(crate) reserved_thread_id: Option<ThreadId>,
pub(crate) analytics_events_client: Option<AnalyticsEventsClient>,
pub(crate) image_store: Arc<dyn AttachmentStore>,
pub(crate) thread_store: Arc<dyn ThreadStore>,
pub(crate) attestation_provider: Option<Arc<dyn AttestationProvider>>,
pub(crate) external_time_provider: Option<Arc<dyn TimeProvider>>,
@@ -570,6 +572,7 @@ impl Session {
client_mcp_extensions,
reserved_thread_id,
analytics_events_client,
image_store,
thread_store,
attestation_provider,
external_time_provider,
@@ -890,6 +893,7 @@ impl Session {
environment_manager,
inherited_environments,
analytics_events_client,
image_store,
thread_store,
parent_rollout_thread_trace,
attestation_provider,
+3
View File
@@ -21,6 +21,7 @@ use crate::shell_snapshot::ShellSnapshot;
use crate::shell_snapshot::SnapshotCredentialBrokerState;
use crate::state::ActiveTurn;
use crate::turn_metadata::ExecutionMetadata;
use codex_attachment_store::AttachmentStore;
use codex_extension_api::ExtensionDataInit;
use codex_http_client::ClientRouteClass;
use codex_http_client::RouteAwareClientPool;
@@ -753,6 +754,7 @@ impl Session {
environment_manager: Arc<EnvironmentManager>,
inherited_environments: Option<TurnEnvironmentSnapshot>,
analytics_events_client: Option<AnalyticsEventsClient>,
image_store: Arc<dyn AttachmentStore>,
thread_store: Arc<dyn ThreadStore>,
parent_rollout_thread_trace: ThreadTraceContext,
attestation_provider: Option<Arc<dyn AttestationProvider>>,
@@ -1636,6 +1638,7 @@ impl Session {
network_approval: Arc::clone(&network_approval),
state_db: state_db_ctx.clone(),
live_thread: live_thread.clone(),
image_store,
thread_store: Arc::clone(&thread_store),
attestation_provider: attestation_provider.clone(),
time_provider,
+5
View File
@@ -5824,6 +5824,7 @@ async fn session_new_fails_when_zsh_fork_enabled_without_packaged_zsh() {
environment_manager,
/*inherited_environments*/ None,
/*analytics_events_client*/ None,
crate::passthrough_image_store(),
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
/*state_db*/ None,
@@ -6061,6 +6062,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
network_approval: Arc::clone(&network_approval),
state_db: None,
live_thread: None,
image_store: crate::passthrough_image_store(),
thread_store: Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
/*state_db*/ None,
@@ -6309,6 +6311,7 @@ async fn make_session_with_config_and_rx(
environment_manager,
/*inherited_environments*/ None,
/*analytics_events_client*/ None,
crate::passthrough_image_store(),
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
/*state_db*/ None,
@@ -6439,6 +6442,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(
environment_manager,
/*inherited_environments*/ None,
/*analytics_events_client*/ None,
crate::passthrough_image_store(),
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
Some(
@@ -8239,6 +8243,7 @@ where
network_approval: Arc::clone(&network_approval),
state_db: state_db.clone(),
live_thread: None,
image_store: crate::passthrough_image_store(),
thread_store: Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
state_db,
@@ -1302,6 +1302,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() {
client_mcp_extensions: ClientMcpExtensions::default(),
reserved_thread_id: None,
analytics_events_client: None,
image_store: crate::thread_manager::passthrough_image_store(),
thread_store,
attestation_provider: None,
external_time_provider: None,
+2
View File
@@ -22,6 +22,7 @@ use crate::unified_exec::UnifiedExecProcessManager;
use arc_swap::ArcSwap;
use arc_swap::ArcSwapOption;
use codex_analytics::AnalyticsEventsClient;
use codex_attachment_store::AttachmentStore;
use codex_core_plugins::PluginsManager;
use codex_extension_api::ExtensionData;
use codex_extension_api::ExtensionDataInit;
@@ -88,6 +89,7 @@ pub(crate) struct SessionServices {
pub(crate) network_approval: Arc<NetworkApprovalService>,
pub(crate) state_db: Option<StateDbHandle>,
pub(crate) live_thread: Option<LiveThread>,
pub(crate) image_store: Arc<dyn AttachmentStore>,
pub(crate) thread_store: Arc<dyn ThreadStore>,
pub(crate) attestation_provider: Option<Arc<dyn AttestationProvider>>,
pub(crate) time_provider: Arc<dyn TimeProvider>,
+1
View File
@@ -2191,6 +2191,7 @@ impl ThreadManagerState {
client_mcp_extensions,
reserved_thread_id,
analytics_events_client: self.analytics_events_client.clone(),
image_store: Arc::clone(&self.image_store),
thread_store: Arc::clone(&self.thread_store),
attestation_provider: self.attestation_provider.clone(),
external_time_provider: self.external_time_provider.clone(),