mirror of
https://github.com/openai/codex.git
synced 2026-11-08 20:40:33 +00:00
## What changed - Send the core report event before its attachments, then upload each attachment in a separate gzip-compressed envelope linked to that event. - Bound encoded and decoded payload sizes, truncate oversized attachment copies with format-aware handling for JSONL, and preserve attachment priority when applying size limits. - Retry transient attachment failures within a shared upload-time budget while honoring Sentry rate-limit and retry headers without replaying the core event. - Add APIs to prepare and send persisted report events and attachments using a stable report ID, explicit delivery outcomes, and caller-controlled retries. ## Testing - Cover attachment retries, truncation, rate limits, rejected responses, transport failures, redirect handling, content types, diagnostic consent, and report tags. GitOrigin-RevId: 5eacd384843795d05d1c024b76e1c6d0c1c4b8d7
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::Context;
|
|
use anyhow::Result;
|
|
|
|
/// Shorten and label an attachment copy, leaving files within the target untouched.
|
|
/// JSONL keeps at least one complete record when a smaller record prefix is possible,
|
|
/// even if it exceeds the target. Callers must check the resulting upload size.
|
|
/// Other formats use a byte prefix.
|
|
pub(super) fn truncate_attachment(
|
|
filename: &mut String,
|
|
buffer: &mut Vec<u8>,
|
|
target_bytes: usize,
|
|
) -> Result<()> {
|
|
if buffer.len() <= target_bytes {
|
|
return Ok(());
|
|
}
|
|
|
|
let end = match Path::new(filename)
|
|
.extension()
|
|
.and_then(|extension| extension.to_str())
|
|
{
|
|
Some(extension) if extension.eq_ignore_ascii_case("jsonl") => buffer[..target_bytes]
|
|
.iter()
|
|
.rposition(|byte| *byte == b'\n')
|
|
.or_else(|| {
|
|
buffer
|
|
.iter()
|
|
.position(|byte| *byte == b'\n')
|
|
.filter(|end| *end + 1 < buffer.len())
|
|
})
|
|
.map(|end| end + 1)
|
|
.context("feedback attachment cannot be shortened to a complete JSONL record")?,
|
|
_ => target_bytes,
|
|
};
|
|
buffer.truncate(end);
|
|
if !filename.starts_with("truncated-") {
|
|
filename.insert_str(0, "truncated-");
|
|
}
|
|
Ok(())
|
|
}
|