mirror of
https://github.com/openai/codex.git
synced 2026-11-22 07:13:50 +00:00
Attach connector caches to diagnostic uploads (#32891)
## What changed - Include the active Codex Apps tools cache and connector directory cache, when available, in diagnostic uploads that include logs. - Resolve cache paths from the current authentication context and use stable attachment filenames. - List both optional cache files in the upload consent dialog. ## Testing - Add coverage for selecting existing active cache files, including a directory cache without an account ID. - Update consent dialog snapshots to include the optional attachments. GitOrigin-RevId: 1d4ffbf2bcb96653f03dc25f91d80dd65038d585
This commit is contained in:
1 parent
bb947e8e36
commit
fb350d1e7d
10 files changed
+197
-13
No files matched your search
@@ -1,4 +1,9 @@
|
||||
use super::*;
|
||||
use codex_connectors::ConnectorDirectoryCacheContext;
|
||||
use codex_connectors::ConnectorDirectoryCacheKey;
|
||||
use codex_connectors::connector_runtime_cache_path;
|
||||
use codex_feedback::CODEX_APP_DIRECTORY_CACHE_ATTACHMENT_FILENAME;
|
||||
use codex_feedback::CODEX_APPS_TOOLS_CACHE_ATTACHMENT_FILENAME;
|
||||
#[cfg(target_os = "windows")]
|
||||
use codex_feedback::WINDOWS_SANDBOX_LOG_ATTACHMENT_FILENAME;
|
||||
|
||||
@@ -70,17 +75,16 @@ impl FeedbackRequestProcessor {
|
||||
None => None,
|
||||
};
|
||||
|
||||
if let Some(chatgpt_user_id) = self
|
||||
.auth_manager
|
||||
.auth_cached()
|
||||
.and_then(|auth| auth.get_chatgpt_user_id())
|
||||
let auth = self.auth_manager.auth_cached();
|
||||
if let Some(chatgpt_user_id) = auth
|
||||
.as_ref()
|
||||
.and_then(codex_login::CodexAuth::get_chatgpt_user_id)
|
||||
{
|
||||
tracing::info!(target: "feedback_tags", chatgpt_user_id);
|
||||
}
|
||||
if let Some(account_id) = self
|
||||
.auth_manager
|
||||
.auth_cached()
|
||||
.and_then(|auth| auth.get_account_id())
|
||||
if let Some(account_id) = auth
|
||||
.as_ref()
|
||||
.and_then(codex_login::CodexAuth::get_account_id)
|
||||
{
|
||||
tracing::info!(target: "feedback_tags", account_id);
|
||||
}
|
||||
@@ -197,6 +201,15 @@ impl FeedbackRequestProcessor {
|
||||
{
|
||||
attachment_paths.push(sandbox_log_attachment);
|
||||
}
|
||||
for cache_attachment in tool_cache_feedback_attachments(
|
||||
self.config.codex_home.as_path(),
|
||||
&self.config.chatgpt_base_url,
|
||||
auth.as_ref(),
|
||||
) {
|
||||
if seen_attachment_paths.insert(cache_attachment.path.clone()) {
|
||||
attachment_paths.push(cache_attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(extra_log_files) = extra_log_files {
|
||||
for extra_log_file in extra_log_files {
|
||||
@@ -272,6 +285,47 @@ impl FeedbackRequestProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
fn tool_cache_feedback_attachments(
|
||||
codex_home: &Path,
|
||||
chatgpt_base_url: &str,
|
||||
auth: Option<&CodexAuth>,
|
||||
) -> Vec<FeedbackAttachmentPath> {
|
||||
let mut attachments = Vec::with_capacity(2);
|
||||
let tools_cache_path = connector_runtime_cache_path(codex_home, auth);
|
||||
if tools_cache_path.is_file() {
|
||||
attachments.push(FeedbackAttachmentPath {
|
||||
path: tools_cache_path,
|
||||
attachment_filename_override: Some(
|
||||
CODEX_APPS_TOOLS_CACHE_ATTACHMENT_FILENAME.to_string(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
let Some(auth) = auth.filter(|auth| auth.uses_codex_backend()) else {
|
||||
return attachments;
|
||||
};
|
||||
let directory_cache_context = ConnectorDirectoryCacheContext::new(
|
||||
codex_home.to_path_buf(),
|
||||
ConnectorDirectoryCacheKey::new(
|
||||
chatgpt_base_url.to_string(),
|
||||
auth.get_account_id(),
|
||||
auth.get_chatgpt_user_id(),
|
||||
auth.is_workspace_account(),
|
||||
),
|
||||
);
|
||||
let directory_cache_path = directory_cache_context.cache_path();
|
||||
if directory_cache_path.is_file() {
|
||||
attachments.push(FeedbackAttachmentPath {
|
||||
path: directory_cache_path,
|
||||
attachment_filename_override: Some(
|
||||
CODEX_APP_DIRECTORY_CACHE_ATTACHMENT_FILENAME.to_string(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
attachments
|
||||
}
|
||||
|
||||
fn auto_review_rollout_filename(thread_id: ThreadId) -> String {
|
||||
format!("auto-review-rollout-{thread_id}.jsonl")
|
||||
}
|
||||
@@ -292,11 +346,106 @@ fn windows_sandbox_log_attachment(_codex_home: &Path) -> Option<FeedbackAttachme
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(all(test, target_os = "windows"))]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn tool_cache_feedback_attachments_include_existing_active_cache_files() {
|
||||
let codex_home = tempfile::tempdir().expect("create tempdir");
|
||||
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
|
||||
let tools_cache_path = connector_runtime_cache_path(codex_home.path(), Some(&auth));
|
||||
std::fs::create_dir_all(tools_cache_path.parent().expect("tools cache parent"))
|
||||
.expect("create tools cache directory");
|
||||
std::fs::write(&tools_cache_path, b"tools").expect("write tools cache");
|
||||
|
||||
let account_id = auth.get_account_id().expect("dummy auth account id");
|
||||
let directory_cache_context = ConnectorDirectoryCacheContext::new(
|
||||
codex_home.path().to_path_buf(),
|
||||
ConnectorDirectoryCacheKey::new(
|
||||
"https://chatgpt.com/backend-api".to_string(),
|
||||
Some(account_id),
|
||||
auth.get_chatgpt_user_id(),
|
||||
auth.is_workspace_account(),
|
||||
),
|
||||
);
|
||||
let directory_cache_path = directory_cache_context.cache_path();
|
||||
std::fs::create_dir_all(
|
||||
directory_cache_path
|
||||
.parent()
|
||||
.expect("directory cache parent"),
|
||||
)
|
||||
.expect("create directory cache directory");
|
||||
std::fs::write(&directory_cache_path, b"directory").expect("write directory cache");
|
||||
|
||||
let attachments = tool_cache_feedback_attachments(
|
||||
codex_home.path(),
|
||||
"https://chatgpt.com/backend-api",
|
||||
Some(&auth),
|
||||
)
|
||||
.into_iter()
|
||||
.map(|attachment| (attachment.path, attachment.attachment_filename_override))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(
|
||||
attachments,
|
||||
vec![
|
||||
(
|
||||
tools_cache_path,
|
||||
Some(CODEX_APPS_TOOLS_CACHE_ATTACHMENT_FILENAME.to_string()),
|
||||
),
|
||||
(
|
||||
directory_cache_path,
|
||||
Some(CODEX_APP_DIRECTORY_CACHE_ATTACHMENT_FILENAME.to_string()),
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_cache_feedback_attachments_include_directory_cache_without_account_id() {
|
||||
let codex_home = tempfile::tempdir().expect("create tempdir");
|
||||
let auth = CodexAuth::Headers(codex_login::AuthHeaders::new(
|
||||
reqwest::header::HeaderMap::new(),
|
||||
));
|
||||
let directory_cache_context = ConnectorDirectoryCacheContext::new(
|
||||
codex_home.path().to_path_buf(),
|
||||
ConnectorDirectoryCacheKey::new(
|
||||
"https://chatgpt.com/backend-api".to_string(),
|
||||
/*account_id*/ None,
|
||||
auth.get_chatgpt_user_id(),
|
||||
auth.is_workspace_account(),
|
||||
),
|
||||
);
|
||||
let directory_cache_path = directory_cache_context.cache_path();
|
||||
std::fs::create_dir_all(
|
||||
directory_cache_path
|
||||
.parent()
|
||||
.expect("directory cache parent"),
|
||||
)
|
||||
.expect("create directory cache directory");
|
||||
std::fs::write(&directory_cache_path, b"directory").expect("write directory cache");
|
||||
|
||||
let attachments = tool_cache_feedback_attachments(
|
||||
codex_home.path(),
|
||||
"https://chatgpt.com/backend-api",
|
||||
Some(&auth),
|
||||
)
|
||||
.into_iter()
|
||||
.map(|attachment| (attachment.path, attachment.attachment_filename_override))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(
|
||||
attachments,
|
||||
vec![(
|
||||
directory_cache_path,
|
||||
Some(CODEX_APP_DIRECTORY_CACHE_ATTACHMENT_FILENAME.to_string()),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn windows_sandbox_log_attachment_uses_current_log() {
|
||||
let codex_home = tempfile::tempdir().expect("create tempdir");
|
||||
|
||||
Reference in new issue
Block a user