mirror of
https://github.com/openai/codex.git
synced 2026-12-01 15:42:13 +00:00
Improve Guardian report diagnostics (#42033)
## Why Reports from a large thread tree can exceed the rollout attachment limit, making the threads involved in a failed Guardian review harder to diagnose. ## What changed - Prioritize descendants with retained failed reviews when selecting bounded report rollouts, while always preserving the reported thread. - Include each selected thread's available Guardian trunk rollout alongside its conversation rollout. - Add a thread index attachment with selected filenames, bounded omission details, retained failure threads, and the process-wide discarded-record count. - Link failed-review records to their reviewed turn and target item when available. ## Testing - Cover failed-review prioritization, bounded omission metadata, discarded-record accounting, and turn/item linkage in Guardian report records. GitOrigin-RevId: ae7916c27a3c279e899cd5a6ead8a4b7e0cc26a1
This commit is contained in:
1 parent
8209978616
commit
2e5ee418ad
13 files changed
+293
-66
No files matched your search
@@ -13,17 +13,29 @@ const MAX_BYTES: usize = 8 * 1024 * 1024;
|
||||
static RECORDS: Mutex<ReviewRecords> = Mutex::new(ReviewRecords {
|
||||
records: VecDeque::new(),
|
||||
bytes: 0,
|
||||
discarded_records: 0,
|
||||
});
|
||||
|
||||
/// A consistent snapshot of retained failures and their owning threads.
|
||||
pub struct GuardianReviewFailures {
|
||||
pub attachment: Option<FeedbackAttachment>,
|
||||
/// Unique threads, ordered by most recently retained failure first.
|
||||
pub thread_ids: Vec<ThreadId>,
|
||||
/// Process-wide evictions or oversized records, not a count for this task tree.
|
||||
pub process_discarded_records: usize,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ReviewRecords {
|
||||
records: VecDeque<(ThreadId, Vec<u8>)>,
|
||||
bytes: usize,
|
||||
discarded_records: usize,
|
||||
}
|
||||
|
||||
impl ReviewRecords {
|
||||
fn push(&mut self, thread_id: ThreadId, record: Vec<u8>) {
|
||||
if record.len() + 1 > MAX_BYTES {
|
||||
self.discarded_records = self.discarded_records.saturating_add(1);
|
||||
return;
|
||||
}
|
||||
if self
|
||||
@@ -36,17 +48,19 @@ impl ReviewRecords {
|
||||
&& let Some((_, removed)) = self.records.remove(index)
|
||||
{
|
||||
self.bytes -= removed.len() + 1;
|
||||
self.discarded_records = self.discarded_records.saturating_add(1);
|
||||
}
|
||||
while self.records.len() >= MAX_RECORDS || self.bytes + record.len() + 1 > MAX_BYTES {
|
||||
if let Some((_, removed)) = self.records.pop_front() {
|
||||
self.bytes -= removed.len() + 1;
|
||||
self.discarded_records = self.discarded_records.saturating_add(1);
|
||||
}
|
||||
}
|
||||
self.bytes += record.len() + 1;
|
||||
self.records.push_back((thread_id, record));
|
||||
}
|
||||
|
||||
fn attachment(&self, thread_ids: &[ThreadId]) -> Option<FeedbackAttachment> {
|
||||
fn snapshot(&self, thread_ids: &[ThreadId]) -> GuardianReviewFailures {
|
||||
let thread_ids = thread_ids.iter().copied().collect::<HashSet<_>>();
|
||||
let mut buffer = Vec::new();
|
||||
for (thread_id, record) in &self.records {
|
||||
@@ -55,11 +69,24 @@ impl ReviewRecords {
|
||||
buffer.push(b'\n');
|
||||
}
|
||||
}
|
||||
(!buffer.is_empty()).then_some(FeedbackAttachment {
|
||||
let attachment = (!buffer.is_empty()).then_some(FeedbackAttachment {
|
||||
filename: "auto-review-failures.jsonl".to_string(),
|
||||
buffer,
|
||||
content_type: Some("application/x-ndjson".to_string()),
|
||||
})
|
||||
});
|
||||
let mut seen = HashSet::new();
|
||||
let thread_ids = self
|
||||
.records
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|(id, _)| thread_ids.contains(id) && seen.insert(*id))
|
||||
.map(|(id, _)| *id)
|
||||
.collect();
|
||||
GuardianReviewFailures {
|
||||
attachment,
|
||||
thread_ids,
|
||||
process_discarded_records: self.discarded_records,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +99,11 @@ pub fn record_guardian_review_failure(thread_id: ThreadId, record: Vec<u8>) {
|
||||
}
|
||||
|
||||
/// Snapshot failures for the reported task tree without including other tasks' records.
|
||||
pub fn guardian_review_failures_attachment(thread_ids: &[ThreadId]) -> Option<FeedbackAttachment> {
|
||||
pub fn guardian_review_failures(thread_ids: &[ThreadId]) -> GuardianReviewFailures {
|
||||
RECORDS
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.attachment(thread_ids)
|
||||
.snapshot(thread_ids)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user