aKode fase 1 (parziale): niente Statsig, analytics, upload Sentry, update check e announcement remoti
This commit is contained in:
@@ -59,8 +59,9 @@ pub const CODEX_APP_DIRECTORY_CACHE_ATTACHMENT_FILENAME: &str = "codex-app-direc
|
||||
/// Filename used for the Windows sandbox log feedback attachment.
|
||||
pub const WINDOWS_SANDBOX_LOG_ATTACHMENT_FILENAME: &str = "windows-sandbox.log";
|
||||
const DEFAULT_MAX_BYTES: usize = 4 * 1024 * 1024; // 4 MiB
|
||||
const SENTRY_DSN: &str =
|
||||
"https://ae32ed50620d7a7792c1ce5df38b3e3e@o33249.ingest.us.sentry.io/4510195390611458";
|
||||
// aKode: the upstream Sentry DSN has been removed. This placeholder only keeps
|
||||
// DSN parsing valid; `upload::send_envelope` refuses to send anything.
|
||||
const SENTRY_DSN: &str = "https://disabled@127.0.0.1/0";
|
||||
const UPLOAD_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 300);
|
||||
// Raw collection budgets used by the report API, not the interactive upload.
|
||||
pub const MAX_ATTACHMENT_BYTES: usize = 64 * 1024 * 1024;
|
||||
|
||||
@@ -4,7 +4,6 @@ use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use bytes::Bytes;
|
||||
use codex_http_client::RequestBuilder;
|
||||
@@ -51,79 +50,18 @@ pub(super) fn envelope_request(
|
||||
}
|
||||
|
||||
/// Send an already-serialized envelope within the report's shared deadline.
|
||||
///
|
||||
/// aKode: feedback is never uploaded to a remote service (upstream sent it to
|
||||
/// Sentry). The signature is kept so callers compile; it always fails.
|
||||
pub(super) async fn send_envelope(
|
||||
client_pool: &RouteAwareClientPool,
|
||||
dsn: &Dsn,
|
||||
body: Vec<u8>,
|
||||
kind: EnvelopeKind,
|
||||
deadline: Instant,
|
||||
rate_limited: &mut bool,
|
||||
_client_pool: &RouteAwareClientPool,
|
||||
_dsn: &Dsn,
|
||||
_body: Vec<u8>,
|
||||
_kind: EnvelopeKind,
|
||||
_deadline: Instant,
|
||||
_rate_limited: &mut bool,
|
||||
) -> Result<StatusCode> {
|
||||
let body = Bytes::from(body);
|
||||
// Retain the exact request bytes for at most two diagnostic retries. Never replay the core.
|
||||
let mut retry_delays = [250, 500].map(Duration::from_millis).into_iter();
|
||||
let response = loop {
|
||||
let timeout = deadline.saturating_duration_since(Instant::now());
|
||||
anyhow::ensure!(!timeout.is_zero(), "feedback upload deadline exceeded");
|
||||
let response = envelope_request(client_pool, dsn, body.clone(), timeout)
|
||||
.send()
|
||||
.await;
|
||||
if response.as_ref().is_ok_and(|response| {
|
||||
sentry_rate_limit_delay(response.headers()).is_some_and(|delay| !delay.is_zero())
|
||||
|| (response.status().is_success()
|
||||
&& response.headers().get("Retry-After").is_some_and(|value| {
|
||||
parse_retry_after(value.to_str().unwrap_or_default())
|
||||
.is_none_or(|delay| !delay.is_zero())
|
||||
}))
|
||||
}) {
|
||||
// Even accepted requests can impose a quota on events or attachments.
|
||||
// https://develop.sentry.dev/sdk/foundations/transport/rate-limiting/
|
||||
*rate_limited = true;
|
||||
break response;
|
||||
}
|
||||
let retryable = match &response {
|
||||
Ok(response) => matches!(response.status().as_u16(), 408 | 429 | 500..=599),
|
||||
Err(error) => {
|
||||
error.is_timeout()
|
||||
|| (error.failure_class().is_none()
|
||||
&& (error.is_connect() || error.is_request() || error.is_body()))
|
||||
}
|
||||
};
|
||||
if matches!(kind, EnvelopeKind::Event) || !retryable {
|
||||
break response;
|
||||
}
|
||||
let retry_delay = retry_delays.next();
|
||||
if response.as_ref().is_ok_and(|response| {
|
||||
response.status() == StatusCode::TOO_MANY_REQUESTS
|
||||
&& (retry_delay.is_none() || !response.headers().contains_key("Retry-After"))
|
||||
}) {
|
||||
// Never let later files bypass an exhausted rate limit.
|
||||
*rate_limited = true;
|
||||
break response;
|
||||
}
|
||||
let Some(retry_delay) = retry_delay else {
|
||||
break response;
|
||||
};
|
||||
let retry_after = response
|
||||
.as_ref()
|
||||
.ok()
|
||||
.and_then(|response| response.headers().get("Retry-After"))
|
||||
.map(|value| {
|
||||
// An invalid cooldown is not permission to send immediately.
|
||||
parse_retry_after(value.to_str().unwrap_or_default())
|
||||
.unwrap_or_else(|| deadline.saturating_duration_since(Instant::now()))
|
||||
});
|
||||
let delay = retry_delay.max(retry_after.unwrap_or_default());
|
||||
if delay >= deadline.saturating_duration_since(Instant::now()) {
|
||||
// Leave long cooldowns for a later submission, including its remaining files.
|
||||
*rate_limited = true;
|
||||
break response;
|
||||
}
|
||||
tokio::time::sleep(delay).await;
|
||||
};
|
||||
response
|
||||
.map(|response| response.status())
|
||||
.context("failed to upload feedback to Sentry")
|
||||
anyhow::bail!("feedback upload is disabled in aKode; use the local save option instead")
|
||||
}
|
||||
|
||||
pub(super) fn sentry_rate_limit_delay(headers: &HeaderMap) -> Option<Duration> {
|
||||
|
||||
Reference in New Issue
Block a user