[codex] Preserve remote plugin download status errors (#28863)

## Summary

- preserve the original HTTP status when a remote plugin bundle download
returns a non-success response
- retain at most 8 KiB of the error response body and annotate
truncation or body-read failures
- add regression coverage for an oversized error response

## Root cause

The non-success response path reused the normal size-limited body
reader. When an error response exceeded 8 KiB, that reader returned
`DownloadTooLarge` before the code constructed `DownloadStatus`, masking
the upstream HTTP status and response context.

## Impact

Remote plugin installation failures now retain the actionable upstream
HTTP status without allowing unbounded error bodies into logs.

## Validation

- `just test -p codex-app-server
plugin_install_preserves_status_when_remote_bundle_error_body_is_too_large`
- `just fmt`
- `git diff --check`
This commit is contained in:
xl-openai
2026-06-18 14:29:01 -07:00
committed by GitHub
parent 4af7762f01
commit 406062c3af
2 changed files with 49 additions and 14 deletions
+31 -7
View File
@@ -293,13 +293,37 @@ async fn download_remote_plugin_bundle_with_limit(
let url = final_url.to_string();
let status = response.status();
if !status.is_success() {
let body = read_response_body_with_limit(
response,
&url,
/*max_bytes*/ REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES,
)
.await?;
let body = String::from_utf8_lossy(&body).to_string();
let mut response = response;
let mut body = Vec::new();
let mut body_truncated = false;
let mut body_read_error = None;
loop {
let chunk = match response.chunk().await {
Ok(Some(chunk)) => chunk,
Ok(None) => break,
Err(source) => {
body_read_error = Some(source);
break;
}
};
let remaining = REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES as usize - body.len();
if chunk.len() > remaining {
body.extend_from_slice(&chunk[..remaining]);
body_truncated = true;
break;
}
body.extend_from_slice(&chunk);
}
let mut body = String::from_utf8_lossy(&body).into_owned();
if body_truncated {
body.push_str(&format!(
"\n[response body truncated after {REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES} bytes]"
));
}
if let Some(source) = body_read_error {
body.push_str(&format!("\n[failed to read response body: {source}]"));
}
return Err(RemotePluginBundleInstallError::DownloadStatus { url, status, body });
}