mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
d692b74007
CXC-392 [With 401](https://openai.sentry.io/issues/7333870443/?project=4510195390611458&query=019ce8f8-560c-7f10-a00a-c59553740674&referrer=issue-stream) <img width="1909" height="555" alt="401 auth tags in Sentry" src="https://github.com/user-attachments/assets/412ea950-61c4-4780-9697-15c270971ee3" /> - auth_401_*: preserved facts from the latest unauthorized response snapshot - auth_*: latest auth-related facts from the latest request attempt - auth_recovery_*: unauthorized recovery state and follow-up result Without 401 <img width="1917" height="522" alt="happy-path auth tags in Sentry" src="https://github.com/user-attachments/assets/3381ed28-8022-43b0-b6c0-623a630e679f" /> ###### Summary - Add client-visible 401 diagnostics for auth attachment, upstream auth classification, and 401 request id / cf-ray correlation. - Record unauthorized recovery mode, phase, outcome, and retry/follow-up status without changing auth behavior. - Surface the highest-signal auth and recovery fields on uploaded client bug reports so they are usable in Sentry. - Preserve original unauthorized evidence under `auth_401_*` while keeping follow-up result tags separate. ###### Rationale (from spec findings) - The dominant bucket needed proof of whether the client attached auth before send or upstream still classified the request as missing auth. - Client uploads needed to show whether unauthorized recovery ran and what the client tried next. - Request id and cf-ray needed to be preserved on the unauthorized response so server-side correlation is immediate. - The bug-report path needed the same auth evidence as the request telemetry path, otherwise the observability would not be operationally useful. ###### Scope - Add auth 401 and unauthorized-recovery observability in `codex-rs/core`, `codex-rs/codex-api`, and `codex-rs/otel`, including feedback-tag surfacing. - Keep auth semantics, refresh behavior, retry behavior, endpoint classification, and geo-denial follow-up work out of this PR. ###### Trade-offs - This exports only safe auth evidence: header presence/name, upstream auth classification, request ids, and recovery state. It does not export token values or raw upstream bodies. - This keeps websocket connection reuse as a transport clue because it can help distinguish stale reused sessions from fresh reconnects. - Misroute/base-url classification and geo-denial are intentionally deferred to a separate follow-up PR so this review stays focused on the dominant auth 401 bucket. ###### Client follow-up - PR 2 will add misroute/provider and geo-denial observability plus the matching feedback-tag surfacing. - A separate host/app-server PR should log auth-decision inputs so pre-send host auth state can be correlated with client request evidence. - `device_id` remains intentionally separate until there is a safe existing source on the feedback upload path. ###### Testing - `cargo test -p codex-core refresh_available_models_sorts_by_priority` - `cargo test -p codex-core emit_feedback_request_tags_` - `cargo test -p codex-core emit_feedback_auth_recovery_tags_` - `cargo test -p codex-core auth_request_telemetry_context_tracks_attached_auth_and_retry_phase` - `cargo test -p codex-core extract_response_debug_context_decodes_identity_headers` - `cargo test -p codex-core identity_auth_details` - `cargo test -p codex-core telemetry_error_messages_preserve_non_http_details` - `cargo test -p codex-core --all-features --no-run` - `cargo test -p codex-otel otel_export_routing_policy_routes_api_request_auth_observability` - `cargo test -p codex-otel otel_export_routing_policy_routes_websocket_connect_auth_observability` - `cargo test -p codex-otel otel_export_routing_policy_routes_websocket_request_transport_observability`
180 lines
5.4 KiB
Rust
180 lines
5.4 KiB
Rust
//! Root of the `codex-core` library.
|
|
|
|
// Prevent accidental direct writes to stdout/stderr in library code. All
|
|
// user-visible output must go through the appropriate abstraction (e.g.,
|
|
// the TUI or the tracing stack).
|
|
#![deny(clippy::print_stdout, clippy::print_stderr)]
|
|
|
|
mod analytics_client;
|
|
pub mod api_bridge;
|
|
mod apply_patch;
|
|
mod apps;
|
|
mod arc_monitor;
|
|
pub mod auth;
|
|
mod client;
|
|
mod client_common;
|
|
pub mod codex;
|
|
mod realtime_context;
|
|
mod realtime_conversation;
|
|
pub use codex::SteerInputError;
|
|
mod codex_thread;
|
|
mod compact_remote;
|
|
pub use codex_thread::CodexThread;
|
|
pub use codex_thread::ThreadConfigSnapshot;
|
|
mod agent;
|
|
mod codex_delegate;
|
|
mod command_canonicalization;
|
|
mod commit_attribution;
|
|
pub mod config;
|
|
pub mod config_loader;
|
|
pub mod connectors;
|
|
mod context_manager;
|
|
mod contextual_user_message;
|
|
pub mod custom_prompts;
|
|
pub mod env;
|
|
mod environment_context;
|
|
pub mod error;
|
|
pub mod exec;
|
|
pub mod exec_env;
|
|
mod exec_policy;
|
|
pub mod external_agent_config;
|
|
pub mod features;
|
|
mod file_watcher;
|
|
mod flags;
|
|
pub mod git_info;
|
|
mod guardian;
|
|
pub mod instructions;
|
|
pub mod landlock;
|
|
pub mod mcp;
|
|
mod mcp_connection_manager;
|
|
mod mcp_tool_approval_templates;
|
|
pub mod models_manager;
|
|
mod network_policy_decision;
|
|
pub mod network_proxy_loader;
|
|
mod original_image_detail;
|
|
pub use mcp_connection_manager::MCP_SANDBOX_STATE_CAPABILITY;
|
|
pub use mcp_connection_manager::MCP_SANDBOX_STATE_METHOD;
|
|
pub use mcp_connection_manager::SandboxState;
|
|
pub use text_encoding::bytes_to_string_smart;
|
|
mod mcp_tool_call;
|
|
mod memories;
|
|
pub mod mention_syntax;
|
|
mod mentions;
|
|
mod message_history;
|
|
mod model_provider_info;
|
|
pub mod path_utils;
|
|
pub mod personality_migration;
|
|
pub mod plugins;
|
|
mod sandbox_tags;
|
|
pub mod sandboxing;
|
|
mod session_prefix;
|
|
mod shell_detect;
|
|
mod stream_events_utils;
|
|
pub mod test_support;
|
|
mod text_encoding;
|
|
pub mod token_data;
|
|
mod truncate;
|
|
mod unified_exec;
|
|
pub mod windows_sandbox;
|
|
pub use client::X_RESPONSESAPI_INCLUDE_TIMING_METRICS_HEADER;
|
|
pub use model_provider_info::DEFAULT_LMSTUDIO_PORT;
|
|
pub use model_provider_info::DEFAULT_OLLAMA_PORT;
|
|
pub use model_provider_info::LMSTUDIO_OSS_PROVIDER_ID;
|
|
pub use model_provider_info::ModelProviderInfo;
|
|
pub use model_provider_info::OLLAMA_OSS_PROVIDER_ID;
|
|
pub use model_provider_info::OPENAI_PROVIDER_ID;
|
|
pub use model_provider_info::WireApi;
|
|
pub use model_provider_info::built_in_model_providers;
|
|
pub use model_provider_info::create_oss_provider_with_base_url;
|
|
mod event_mapping;
|
|
mod response_debug_context;
|
|
pub mod review_format;
|
|
pub mod review_prompts;
|
|
mod seatbelt_permissions;
|
|
mod thread_manager;
|
|
pub mod web_search;
|
|
pub mod windows_sandbox_read_grants;
|
|
pub use thread_manager::NewThread;
|
|
pub use thread_manager::ThreadManager;
|
|
#[deprecated(note = "use ThreadManager")]
|
|
pub type ConversationManager = ThreadManager;
|
|
#[deprecated(note = "use NewThread")]
|
|
pub type NewConversation = NewThread;
|
|
#[deprecated(note = "use CodexThread")]
|
|
pub type CodexConversation = CodexThread;
|
|
// Re-export common auth types for workspace consumers
|
|
pub use analytics_client::AnalyticsEventsClient;
|
|
pub use auth::AuthManager;
|
|
pub use auth::CodexAuth;
|
|
pub mod default_client;
|
|
pub mod project_doc;
|
|
mod rollout;
|
|
pub(crate) mod safety;
|
|
pub mod seatbelt;
|
|
pub mod shell;
|
|
pub mod shell_snapshot;
|
|
pub mod skills;
|
|
pub mod spawn;
|
|
pub mod state_db;
|
|
pub mod terminal;
|
|
mod tools;
|
|
pub mod turn_diff_tracker;
|
|
mod turn_metadata;
|
|
mod turn_timing;
|
|
pub use rollout::ARCHIVED_SESSIONS_SUBDIR;
|
|
pub use rollout::INTERACTIVE_SESSION_SOURCES;
|
|
pub use rollout::RolloutRecorder;
|
|
pub use rollout::RolloutRecorderParams;
|
|
pub use rollout::SESSIONS_SUBDIR;
|
|
pub use rollout::SessionMeta;
|
|
pub use rollout::append_thread_name;
|
|
pub use rollout::find_archived_thread_path_by_id_str;
|
|
#[deprecated(note = "use find_thread_path_by_id_str")]
|
|
pub use rollout::find_conversation_path_by_id_str;
|
|
pub use rollout::find_thread_name_by_id;
|
|
pub use rollout::find_thread_path_by_id_str;
|
|
pub use rollout::find_thread_path_by_name_str;
|
|
pub use rollout::list::Cursor;
|
|
pub use rollout::list::ThreadItem;
|
|
pub use rollout::list::ThreadSortKey;
|
|
pub use rollout::list::ThreadsPage;
|
|
pub use rollout::list::parse_cursor;
|
|
pub use rollout::list::read_head_for_summary;
|
|
pub use rollout::list::read_session_meta_line;
|
|
pub use rollout::policy::EventPersistenceMode;
|
|
pub use rollout::rollout_date_parts;
|
|
pub use rollout::session_index::find_thread_names_by_ids;
|
|
mod function_tool;
|
|
mod state;
|
|
mod tasks;
|
|
mod user_shell_command;
|
|
pub mod util;
|
|
pub(crate) use codex_protocol::protocol;
|
|
pub(crate) use codex_shell_command::bash;
|
|
pub(crate) use codex_shell_command::is_dangerous_command;
|
|
pub(crate) use codex_shell_command::is_safe_command;
|
|
pub(crate) use codex_shell_command::parse_command;
|
|
pub(crate) use codex_shell_command::powershell;
|
|
|
|
pub use client::ModelClient;
|
|
pub use client::ModelClientSession;
|
|
pub use client::X_CODEX_TURN_METADATA_HEADER;
|
|
pub use client::ws_version_from_features;
|
|
pub use client_common::Prompt;
|
|
pub use client_common::REVIEW_PROMPT;
|
|
pub use client_common::ResponseEvent;
|
|
pub use client_common::ResponseStream;
|
|
pub use compact::content_items_to_text;
|
|
pub use event_mapping::parse_turn_item;
|
|
pub use exec_policy::ExecPolicyError;
|
|
pub use exec_policy::check_execpolicy_for_warnings;
|
|
pub use exec_policy::format_exec_policy_error_with_source;
|
|
pub use exec_policy::load_exec_policy;
|
|
pub use file_watcher::FileWatcherEvent;
|
|
pub use safety::get_platform_sandbox;
|
|
pub use tools::spec::parse_tool_input_schema;
|
|
pub use turn_metadata::build_turn_metadata_header;
|
|
pub mod compact;
|
|
pub mod memory_trace;
|
|
pub mod otel_init;
|