aKode fase 2c: eliminato il codice di invio dati (crate analytics, otel-trace-websocket, sentry, esportatori OTLP); /feedback salva solo in locale; chiavi legacy [analytics]/[otel] accettate e ignorate; test di analytics/OTLP/upload rimossi
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -21,6 +21,11 @@ use sha2::Sha256;
|
||||
use std::path::Path;
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
struct SavedFeedback {
|
||||
thread_id: String,
|
||||
prompt_hash: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct FeedbackRequestProcessor {
|
||||
auth_manager: Arc<AuthManager>,
|
||||
@@ -29,7 +34,7 @@ pub(crate) struct FeedbackRequestProcessor {
|
||||
feedback: CodexFeedback,
|
||||
log_db: Option<LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
uploads: Arc<Semaphore>,
|
||||
saves: Arc<Semaphore>,
|
||||
}
|
||||
|
||||
impl FeedbackRequestProcessor {
|
||||
@@ -48,24 +53,10 @@ impl FeedbackRequestProcessor {
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
uploads: Arc::new(Semaphore::new(/*permits*/ 3)),
|
||||
saves: Arc::new(Semaphore::new(/*permits*/ 3)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn feedback_upload(
|
||||
&self,
|
||||
params: FeedbackUploadParams,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
if !self.config.feedback_enabled {
|
||||
return Err(invalid_request(
|
||||
"sending feedback is disabled by configuration",
|
||||
));
|
||||
}
|
||||
self.feedback_response(params, /*save_path*/ None)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
|
||||
pub(crate) async fn feedback_save(
|
||||
&self,
|
||||
params: FeedbackSaveParams,
|
||||
@@ -78,9 +69,7 @@ impl FeedbackRequestProcessor {
|
||||
let save_path = AbsolutePathBuf::try_from(params.save_path)
|
||||
.map_err(|error| invalid_request(format!("invalid feedback savePath: {error}")))?;
|
||||
let saved_path = LegacyAppPathString::from_abs_path(&save_path);
|
||||
let response = self
|
||||
.feedback_response(params.feedback, Some(save_path))
|
||||
.await?;
|
||||
let response = self.feedback_response(params.feedback, save_path).await?;
|
||||
Ok(Some(
|
||||
FeedbackSaveResponse {
|
||||
saved_path,
|
||||
@@ -93,22 +82,22 @@ impl FeedbackRequestProcessor {
|
||||
|
||||
async fn feedback_response(
|
||||
&self,
|
||||
params: FeedbackUploadParams,
|
||||
save_path: Option<AbsolutePathBuf>,
|
||||
) -> Result<FeedbackUploadResponse, JSONRPCErrorError> {
|
||||
params: FeedbackReportParams,
|
||||
save_path: AbsolutePathBuf,
|
||||
) -> Result<SavedFeedback, JSONRPCErrorError> {
|
||||
let permit = self
|
||||
.uploads
|
||||
.saves
|
||||
.clone()
|
||||
.try_acquire_owned()
|
||||
.map_err(|_| JSONRPCErrorError {
|
||||
code: OVERLOADED_ERROR_CODE,
|
||||
message:
|
||||
"Three feedback uploads are already in progress; try again after one finishes"
|
||||
"Three feedback saves are already in progress; try again after one finishes"
|
||||
.to_string(),
|
||||
data: None,
|
||||
})?;
|
||||
|
||||
let FeedbackUploadParams {
|
||||
let FeedbackReportParams {
|
||||
classification,
|
||||
reason,
|
||||
thread_id,
|
||||
@@ -116,7 +105,7 @@ impl FeedbackRequestProcessor {
|
||||
extra_log_files,
|
||||
tags,
|
||||
} = params;
|
||||
let mut upload_tags = tags.unwrap_or_default();
|
||||
let mut report_tags = tags.unwrap_or_default();
|
||||
|
||||
let conversation_id = match thread_id.as_deref() {
|
||||
Some(thread_id) => match ThreadId::from_string(thread_id) {
|
||||
@@ -126,23 +115,22 @@ impl FeedbackRequestProcessor {
|
||||
None => None,
|
||||
};
|
||||
|
||||
let http_client_factory = self.config.http_client_factory();
|
||||
let auth = self.auth_manager.auth_cached();
|
||||
let turn_metadata = if let Some(conversation_id) = conversation_id
|
||||
&& let Some(rollout_path) = self
|
||||
.resolve_rollout_path(conversation_id, self.state_db.as_ref(), save_path.as_ref())
|
||||
.resolve_rollout_path(conversation_id, self.state_db.as_ref())
|
||||
.await?
|
||||
{
|
||||
feedback_turn_metadata_from_rollout(
|
||||
&rollout_path,
|
||||
upload_tags.get("turn_id").map(String::as_str),
|
||||
report_tags.get("turn_id").map(String::as_str),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
None
|
||||
};
|
||||
apply_feedback_turn_metadata(&mut upload_tags, turn_metadata);
|
||||
let prompt_hash = upload_tags.get("prompt_hash").cloned();
|
||||
apply_feedback_turn_metadata(&mut report_tags, turn_metadata);
|
||||
let prompt_hash = report_tags.get("prompt_hash").cloned();
|
||||
|
||||
if let Some(chatgpt_user_id) = auth
|
||||
.as_ref()
|
||||
@@ -230,11 +218,7 @@ impl FeedbackRequestProcessor {
|
||||
.flat_map(|index| &mut index.threads)
|
||||
{
|
||||
if let Some(rollout_path) = self
|
||||
.resolve_rollout_path(
|
||||
thread.thread_id,
|
||||
state_db_ctx.as_ref(),
|
||||
save_path.as_ref(),
|
||||
)
|
||||
.resolve_rollout_path(thread.thread_id, state_db_ctx.as_ref())
|
||||
.await?
|
||||
&& seen_attachment_paths.insert(rollout_path.clone())
|
||||
{
|
||||
@@ -259,10 +243,7 @@ impl FeedbackRequestProcessor {
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(mut index) = feedback_index {
|
||||
if save_path.is_some() {
|
||||
index.rollout_archive_filename = None;
|
||||
}
|
||||
if let Some(index) = feedback_index {
|
||||
match index.attachment() {
|
||||
Ok(attachment) => extra_attachments.insert(0, attachment),
|
||||
Err(err) => warn!("failed to serialize feedback thread index: {err}"),
|
||||
@@ -309,7 +290,7 @@ impl FeedbackRequestProcessor {
|
||||
{
|
||||
extra_attachments.push(doctor_report.attachment);
|
||||
for (key, value) in doctor_report.tags {
|
||||
upload_tags.entry(key).or_insert(value);
|
||||
report_tags.entry(key).or_insert(value);
|
||||
}
|
||||
}
|
||||
extra_attachments.extend(
|
||||
@@ -322,23 +303,17 @@ impl FeedbackRequestProcessor {
|
||||
}
|
||||
|
||||
let session_source = self.thread_manager.session_source();
|
||||
let runtime_handle = tokio::runtime::Handle::current();
|
||||
let codex_home = self.config.codex_home.clone();
|
||||
|
||||
let operation = if save_path.is_some() {
|
||||
"save"
|
||||
} else {
|
||||
"upload"
|
||||
};
|
||||
let upload_result = tokio::task::spawn_blocking(move || {
|
||||
// Cancelling the RPC waiter must not release a still-running upload's slot.
|
||||
let save_result = tokio::task::spawn_blocking(move || {
|
||||
// Cancelling the RPC waiter must not release a still-running save's slot.
|
||||
let _permit = permit;
|
||||
if include_logs {
|
||||
extra_attachments
|
||||
.extend(codex_feedback::daemon_log_attachments(codex_home.as_path()));
|
||||
}
|
||||
let tags = (!upload_tags.is_empty()).then_some(&upload_tags);
|
||||
let options = FeedbackUploadOptions {
|
||||
let tags = (!report_tags.is_empty()).then_some(&report_tags);
|
||||
let options = FeedbackSaveOptions {
|
||||
classification: &classification,
|
||||
reason: reason.as_deref(),
|
||||
tags,
|
||||
@@ -348,27 +323,21 @@ impl FeedbackRequestProcessor {
|
||||
session_source: Some(session_source),
|
||||
logs_override: sqlite_feedback_logs,
|
||||
};
|
||||
match save_path {
|
||||
Some(path) => snapshot.save_feedback(options, path.as_path()),
|
||||
None => {
|
||||
runtime_handle.block_on(snapshot.upload_feedback(options, &http_client_factory))
|
||||
}
|
||||
}
|
||||
snapshot.save_feedback(options, save_path.as_path())
|
||||
})
|
||||
.await;
|
||||
|
||||
let upload_result = match upload_result {
|
||||
let save_result = match save_result {
|
||||
Ok(result) => result,
|
||||
Err(join_err) => {
|
||||
return Err(internal_error(format!(
|
||||
"failed to {operation} feedback: {join_err}"
|
||||
"failed to save feedback: {join_err}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
upload_result
|
||||
.map_err(|err| internal_error(format!("failed to {operation} feedback: {err:#}")))?;
|
||||
Ok(FeedbackUploadResponse {
|
||||
save_result.map_err(|err| internal_error(format!("failed to save feedback: {err:#}")))?;
|
||||
Ok(SavedFeedback {
|
||||
thread_id,
|
||||
prompt_hash,
|
||||
})
|
||||
@@ -378,19 +347,13 @@ impl FeedbackRequestProcessor {
|
||||
&self,
|
||||
conversation_id: ThreadId,
|
||||
state_db_ctx: Option<&StateDbHandle>,
|
||||
save_path: Option<&AbsolutePathBuf>,
|
||||
) -> Result<Option<PathBuf>, JSONRPCErrorError> {
|
||||
if let Ok(conversation) = self.thread_manager.get_thread(conversation_id).await {
|
||||
if save_path.is_some() {
|
||||
// Explicit extraLogFiles are collected separately and remain strict, even
|
||||
// when they name this same not-yet-materialized automatic rollout.
|
||||
return conversation.feedback_rollout_path().await.map_err(|error| {
|
||||
internal_error(format!("failed to select feedback rollout: {error}"))
|
||||
});
|
||||
}
|
||||
if let Some(rollout_path) = conversation.rollout_path() {
|
||||
return Ok(Some(rollout_path));
|
||||
}
|
||||
// Explicit extraLogFiles are collected separately and remain strict, even
|
||||
// when they name this same not-yet-materialized automatic rollout.
|
||||
return conversation.feedback_rollout_path().await.map_err(|error| {
|
||||
internal_error(format!("failed to select feedback rollout: {error}"))
|
||||
});
|
||||
}
|
||||
|
||||
let Some(state_db_ctx) = state_db_ctx else {
|
||||
@@ -441,13 +404,13 @@ struct FeedbackTurnMetadata {
|
||||
}
|
||||
|
||||
fn apply_feedback_turn_metadata(
|
||||
upload_tags: &mut BTreeMap<String, String>,
|
||||
report_tags: &mut BTreeMap<String, String>,
|
||||
turn_metadata: Option<FeedbackTurnMetadata>,
|
||||
) {
|
||||
// These are reserved tags derived from the persisted rollout rather than
|
||||
// accepted from the feedback request.
|
||||
upload_tags.remove("prompt_hash");
|
||||
upload_tags.remove("prompt_version");
|
||||
report_tags.remove("prompt_hash");
|
||||
report_tags.remove("prompt_version");
|
||||
|
||||
if let Some(FeedbackTurnMetadata {
|
||||
model,
|
||||
@@ -455,10 +418,10 @@ fn apply_feedback_turn_metadata(
|
||||
prompt_hash,
|
||||
}) = turn_metadata
|
||||
{
|
||||
upload_tags.insert("model".to_string(), model);
|
||||
upload_tags.insert("effort".to_string(), format!("{effort:?}"));
|
||||
report_tags.insert("model".to_string(), model);
|
||||
report_tags.insert("effort".to_string(), format!("{effort:?}"));
|
||||
if let Some(prompt_hash) = prompt_hash {
|
||||
upload_tags.insert("prompt_hash".to_string(), prompt_hash);
|
||||
report_tags.insert("prompt_hash".to_string(), prompt_hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -649,7 +612,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn feedback_tags_drop_unverified_client_prompt_tags() {
|
||||
let mut upload_tags = BTreeMap::from([
|
||||
let mut report_tags = BTreeMap::from([
|
||||
("custom".to_string(), "preserved".to_string()),
|
||||
(
|
||||
"prompt_hash".to_string(),
|
||||
@@ -658,23 +621,23 @@ mod tests {
|
||||
("prompt_version".to_string(), "client-prompt-v1".to_string()),
|
||||
]);
|
||||
|
||||
apply_feedback_turn_metadata(&mut upload_tags, /*turn_metadata*/ None);
|
||||
apply_feedback_turn_metadata(&mut report_tags, /*turn_metadata*/ None);
|
||||
|
||||
assert_eq!(
|
||||
upload_tags,
|
||||
report_tags,
|
||||
BTreeMap::from([("custom".to_string(), "preserved".to_string())])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feedback_tags_drop_client_prompt_hash_when_rollout_has_no_hash() {
|
||||
let mut upload_tags = BTreeMap::from([(
|
||||
let mut report_tags = BTreeMap::from([(
|
||||
"prompt_hash".to_string(),
|
||||
"unverified-client-hash".to_string(),
|
||||
)]);
|
||||
|
||||
apply_feedback_turn_metadata(
|
||||
&mut upload_tags,
|
||||
&mut report_tags,
|
||||
Some(FeedbackTurnMetadata {
|
||||
model: "reported-model".to_string(),
|
||||
effort: Some(ReasoningEffort::High),
|
||||
@@ -683,7 +646,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
upload_tags,
|
||||
report_tags,
|
||||
BTreeMap::from([
|
||||
("effort".to_string(), "Some(High)".to_string()),
|
||||
("model".to_string(), "reported-model".to_string()),
|
||||
@@ -693,13 +656,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn feedback_tags_replace_client_prompt_hash_with_rollout_hash() {
|
||||
let mut upload_tags = BTreeMap::from([(
|
||||
let mut report_tags = BTreeMap::from([(
|
||||
"prompt_hash".to_string(),
|
||||
"unverified-client-hash".to_string(),
|
||||
)]);
|
||||
|
||||
apply_feedback_turn_metadata(
|
||||
&mut upload_tags,
|
||||
&mut report_tags,
|
||||
Some(FeedbackTurnMetadata {
|
||||
model: "reported-model".to_string(),
|
||||
effort: Some(ReasoningEffort::High),
|
||||
@@ -708,7 +671,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
upload_tags,
|
||||
report_tags,
|
||||
BTreeMap::from([
|
||||
("effort".to_string(), "Some(High)".to_string()),
|
||||
("model".to_string(), "reported-model".to_string()),
|
||||
@@ -721,17 +684,17 @@ mod tests {
|
||||
async fn feedback_tags_do_not_trust_the_prompt_version_from_the_reported_rollout() {
|
||||
let (_tempdir, rollout_path) =
|
||||
feedback_rollout(&[("turn-1", "synthetic-model", Some(ReasoningEffort::High))]);
|
||||
let mut upload_tags = BTreeMap::from([(
|
||||
let mut report_tags = BTreeMap::from([(
|
||||
"prompt_version".to_string(),
|
||||
"unverified-client-prompt".to_string(),
|
||||
)]);
|
||||
|
||||
let turn_metadata =
|
||||
feedback_turn_metadata_from_rollout(&rollout_path, Some("turn-1")).await;
|
||||
apply_feedback_turn_metadata(&mut upload_tags, turn_metadata);
|
||||
apply_feedback_turn_metadata(&mut report_tags, turn_metadata);
|
||||
|
||||
assert_eq!(
|
||||
upload_tags,
|
||||
report_tags,
|
||||
BTreeMap::from([
|
||||
("effort".to_string(), "Some(High)".to_string()),
|
||||
("model".to_string(), "synthetic-model".to_string()),
|
||||
|
||||
Reference in New Issue
Block a user