Route TUI /feedback submission through the app server (#16184)

The TUI’s `/feedback` flow was still uploading directly through the
local feedback crate, which bypassed app-server behavior such as
auth-derived feedback tags like chatgpt_user_id and made TUI feedback
handling diverge from other clients. It also meant that remove TUI
sessions failed to upload the correct feedback logs and session details.

Testing: Manually tested `/feedback` flow and confirmed that it didn't
regress.
This commit is contained in:
Eric Traut authored and GitHub committed 2026-03-31 10:36:47 -06:00
1 parent 03b2465591
commit f396454097
6 files changed
+531 -159

No files matched your search

+197 -131
View File
@@ -1,6 +1,3 @@
use std::cell::RefCell;
use std::path::PathBuf;
use codex_feedback::feedback_diagnostics::FEEDBACK_DIAGNOSTICS_ATTACHMENT_FILENAME;
use codex_feedback::feedback_diagnostics::FeedbackDiagnostics;
use crossterm::event::KeyCode;
@@ -15,13 +12,13 @@ use ratatui::widgets::Clear;
use ratatui::widgets::Paragraph;
use ratatui::widgets::StatefulWidgetRef;
use ratatui::widgets::Widget;
use std::cell::RefCell;
use crate::app_event::AppEvent;
use crate::app_event::FeedbackCategory;
use crate::app_event_sender::AppEventSender;
use crate::history_cell;
use crate::render::renderable::Renderable;
use codex_protocol::protocol::SessionSource;
use super::CancellationEvent;
use super::bottom_pane_view::BottomPaneView;
@@ -44,15 +41,12 @@ pub(crate) enum FeedbackAudience {
External,
}
/// Minimal input overlay to collect an optional feedback note, then upload
/// both logs and rollout with classification + metadata.
/// Minimal input overlay to collect an optional feedback note, then submit it
/// through the app-server-managed feedback flow.
pub(crate) struct FeedbackNoteView {
category: FeedbackCategory,
snapshot: codex_feedback::FeedbackSnapshot,
rollout_path: Option<PathBuf>,
app_event_tx: AppEventSender,
include_logs: bool,
feedback_audience: FeedbackAudience,
// UI state
textarea: TextArea,
@@ -63,19 +57,13 @@ pub(crate) struct FeedbackNoteView {
impl FeedbackNoteView {
pub(crate) fn new(
category: FeedbackCategory,
snapshot: codex_feedback::FeedbackSnapshot,
rollout_path: Option<PathBuf>,
app_event_tx: AppEventSender,
include_logs: bool,
feedback_audience: FeedbackAudience,
) -> Self {
Self {
category,
snapshot,
rollout_path,
app_event_tx,
include_logs,
feedback_audience,
textarea: TextArea::new(),
textarea_state: RefCell::new(TextAreaState::default()),
complete: false,
@@ -84,90 +72,12 @@ impl FeedbackNoteView {
fn submit(&mut self) {
let note = self.textarea.text().trim().to_string();
let reason_opt = if note.is_empty() {
None
} else {
Some(note.as_str())
};
let attachment_paths = if self.include_logs {
self.rollout_path.iter().cloned().collect::<Vec<_>>()
} else {
Vec::new()
};
let classification = feedback_classification(self.category);
let mut thread_id = self.snapshot.thread_id.clone();
let result = self.snapshot.upload_feedback(
classification,
reason_opt,
self.include_logs,
&attachment_paths,
Some(SessionSource::Cli),
/*logs_override*/ None,
);
match result {
Ok(()) => {
let prefix = if self.include_logs {
"• Feedback uploaded."
} else {
"• Feedback recorded (no logs)."
};
let issue_url =
issue_url_for_category(self.category, &thread_id, self.feedback_audience);
let mut lines = vec![Line::from(match issue_url.as_ref() {
Some(_) if self.feedback_audience == FeedbackAudience::OpenAiEmployee => {
format!("{prefix} Please report this in #codex-feedback:")
}
Some(_) => format!("{prefix} Please open an issue using the following URL:"),
None => format!("{prefix} Thanks for the feedback!"),
})];
match issue_url {
Some(url) if self.feedback_audience == FeedbackAudience::OpenAiEmployee => {
lines.extend([
"".into(),
Line::from(vec![" ".into(), url.cyan().underlined()]),
"".into(),
Line::from(" Share this and add some info about your problem:"),
Line::from(vec![
" ".into(),
format!("https://go/codex-feedback/{thread_id}").bold(),
]),
]);
}
Some(url) => {
lines.extend([
"".into(),
Line::from(vec![" ".into(), url.cyan().underlined()]),
"".into(),
Line::from(vec![
" Or mention your thread ID ".into(),
std::mem::take(&mut thread_id).bold(),
" in an existing issue.".into(),
]),
]);
}
None => {
lines.extend([
"".into(),
Line::from(vec![
" Thread ID: ".into(),
std::mem::take(&mut thread_id).bold(),
]),
]);
}
}
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::PlainHistoryCell::new(lines),
)));
}
Err(e) => {
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::new_error_event(format!("Failed to upload feedback: {e}")),
)));
}
}
let reason = if note.is_empty() { None } else { Some(note) };
self.app_event_tx.send(AppEvent::SubmitFeedback {
category: self.category,
reason,
include_logs: self.include_logs,
});
self.complete = true;
}
}
@@ -382,7 +292,7 @@ fn feedback_title_and_placeholder(category: FeedbackCategory) -> (String, String
}
}
fn feedback_classification(category: FeedbackCategory) -> &'static str {
pub(crate) fn feedback_classification(category: FeedbackCategory) -> &'static str {
match category {
FeedbackCategory::BadResult => "bad_result",
FeedbackCategory::GoodResult => "good_result",
@@ -392,6 +302,60 @@ fn feedback_classification(category: FeedbackCategory) -> &'static str {
}
}
pub(crate) fn feedback_success_cell(
category: FeedbackCategory,
include_logs: bool,
thread_id: &str,
feedback_audience: FeedbackAudience,
) -> history_cell::PlainHistoryCell {
let prefix = if include_logs {
"• Feedback uploaded."
} else {
"• Feedback recorded (no logs)."
};
let issue_url = issue_url_for_category(category, thread_id, feedback_audience);
let mut lines = vec![Line::from(match issue_url.as_ref() {
Some(_) if feedback_audience == FeedbackAudience::OpenAiEmployee => {
format!("{prefix} Please report this in #codex-feedback:")
}
Some(_) => format!("{prefix} Please open an issue using the following URL:"),
None => format!("{prefix} Thanks for the feedback!"),
})];
match issue_url {
Some(url) if feedback_audience == FeedbackAudience::OpenAiEmployee => {
lines.extend([
"".into(),
Line::from(vec![" ".into(), url.cyan().underlined()]),
"".into(),
Line::from(" Share this and add some info about your problem:"),
Line::from(vec![
" ".into(),
format!("https://go/codex-feedback/{thread_id}").bold(),
]),
]);
}
Some(url) => {
lines.extend([
"".into(),
Line::from(vec![" ".into(), url.cyan().underlined()]),
"".into(),
Line::from(vec![
" Or mention your thread ID ".into(),
thread_id.to_string().bold(),
" in an existing issue.".into(),
]),
]);
}
None => {
lines.extend([
"".into(),
Line::from(vec![" Thread ID: ".into(), thread_id.to_string().bold()]),
]);
}
}
history_cell::PlainHistoryCell::new(lines)
}
fn issue_url_for_category(
category: FeedbackCategory,
thread_id: &str,
@@ -625,18 +589,25 @@ mod tests {
lines.join("\n")
}
fn render_cell(cell: &impl history_cell::HistoryCell, width: u16) -> String {
cell.display_lines(width)
.into_iter()
.map(|line| {
line.spans
.into_iter()
.map(|span| span.content.into_owned())
.collect::<String>()
.trim_end()
.to_string()
})
.collect::<Vec<_>>()
.join("\n")
}
fn make_view(category: FeedbackCategory) -> FeedbackNoteView {
let (tx_raw, _rx) = tokio::sync::mpsc::unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let snapshot = codex_feedback::CodexFeedback::new().snapshot(/*session_id*/ None);
FeedbackNoteView::new(
category,
snapshot,
/*rollout_path*/ None,
tx,
/*include_logs*/ true,
FeedbackAudience::External,
)
FeedbackNoteView::new(category, tx, /*include_logs*/ true)
}
#[test]
@@ -678,33 +649,56 @@ mod tests {
fn feedback_view_with_connectivity_diagnostics() {
let (tx_raw, _rx) = tokio::sync::mpsc::unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let diagnostics = FeedbackDiagnostics::new(vec![
FeedbackDiagnostic {
headline: "Proxy environment variables are set and may affect connectivity."
.to_string(),
details: vec!["HTTP_PROXY = http://proxy.example.com:8080".to_string()],
},
FeedbackDiagnostic {
headline: "OPENAI_BASE_URL is set and may affect connectivity.".to_string(),
details: vec!["OPENAI_BASE_URL = https://example.com/v1".to_string()],
},
]);
let snapshot = codex_feedback::CodexFeedback::new()
.snapshot(/*session_id*/ None)
.with_feedback_diagnostics(diagnostics);
let view = FeedbackNoteView::new(
FeedbackCategory::Bug,
snapshot,
/*rollout_path*/ None,
tx,
/*include_logs*/ false,
FeedbackAudience::External,
);
let view = FeedbackNoteView::new(FeedbackCategory::Bug, tx, /*include_logs*/ false);
let rendered = render(&view, /*width*/ 60);
insta::assert_snapshot!("feedback_view_with_connectivity_diagnostics", rendered);
}
#[test]
fn submit_feedback_emits_submit_event_with_trimmed_note() {
let (tx_raw, mut rx) = tokio::sync::mpsc::unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut view = FeedbackNoteView::new(FeedbackCategory::Bug, tx, /*include_logs*/ true);
view.textarea.insert_str(" something broke ");
view.submit();
let event = rx.try_recv().expect("submit feedback event");
assert!(matches!(
event,
AppEvent::SubmitFeedback {
category: FeedbackCategory::Bug,
reason: Some(reason),
include_logs: true,
} if reason == "something broke"
));
assert_eq!(view.is_complete(), true);
}
#[test]
fn submit_feedback_omits_empty_note() {
let (tx_raw, mut rx) = tokio::sync::mpsc::unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut view = FeedbackNoteView::new(
FeedbackCategory::GoodResult,
tx,
/*include_logs*/ false,
);
view.submit();
let event = rx.try_recv().expect("submit feedback event");
assert!(matches!(
event,
AppEvent::SubmitFeedback {
category: FeedbackCategory::GoodResult,
reason: None,
include_logs: false,
}
));
}
#[test]
fn should_show_feedback_connectivity_details_only_for_non_good_result_with_diagnostics() {
let diagnostics = FeedbackDiagnostics::new(vec![FeedbackDiagnostic {
@@ -774,4 +768,76 @@ mod tests {
let expected_external_url = "https://github.com/openai/codex/issues/new?template=3-cli.yml&steps=Uploaded%20thread:%20t";
assert_eq!(bug_url_non_employee.as_deref(), Some(expected_external_url));
}
#[test]
fn feedback_success_cell_matches_external_bug_copy() {
let rendered = render_cell(
&feedback_success_cell(
FeedbackCategory::Bug,
/*include_logs*/ true,
"thread-1",
FeedbackAudience::External,
),
/*width*/ 120,
);
assert_eq!(
rendered,
"• Feedback uploaded. Please open an issue using the following URL:\n\n https://github.com/openai/codex/issues/new?template=3-cli.yml&steps=Uploaded%20thread:%20thread-1\n\n Or mention your thread ID thread-1 in an existing issue."
);
}
#[test]
fn feedback_success_cell_matches_employee_bug_copy() {
let rendered = render_cell(
&feedback_success_cell(
FeedbackCategory::Bug,
/*include_logs*/ true,
"thread-2",
FeedbackAudience::OpenAiEmployee,
),
/*width*/ 120,
);
assert_eq!(
rendered,
"• Feedback uploaded. Please report this in #codex-feedback:\n\n http://go/codex-feedback-internal\n\n Share this and add some info about your problem:\n https://go/codex-feedback/thread-2"
);
}
#[test]
fn feedback_success_cell_matches_good_result_copy() {
let rendered = render_cell(
&feedback_success_cell(
FeedbackCategory::GoodResult,
/*include_logs*/ false,
"thread-3",
FeedbackAudience::External,
),
/*width*/ 120,
);
assert_eq!(
rendered,
"• Feedback recorded (no logs). Thanks for the feedback!\n\n Thread ID: thread-3"
);
}
#[test]
fn feedback_success_cell_uses_issue_links_for_remaining_categories() {
for category in [
FeedbackCategory::BadResult,
FeedbackCategory::SafetyCheck,
FeedbackCategory::Other,
] {
let rendered = render_cell(
&feedback_success_cell(
category,
/*include_logs*/ false,
"thread-4",
FeedbackAudience::External,
),
/*width*/ 120,
);
assert!(rendered.contains("Please open an issue using the following URL:"));
assert!(rendered.contains("thread-4"));
}
}
}