Increase TCP user timeout for default client to avoid compaction hangs
What version of Codex CLI is running?
codex-cli 0.134.0
What subscription do you have?
GPT Pro 20x
Which model were you using?
gpt-5.5
What platform is your computer?
Ubuntu
What terminal emulator and version are you using (if applicable)?
_No response_
Codex doctor report
What issue are you seeing?
Long-running unary requests such as remote compaction can keep the connection open long enough that the default TCP user timeout is too short
on Linux-family targets.
When that happens, compaction may hang or fail before the server finishes responding.
## Fix
Set a bounded but longer timeout for the default client:
```rust
const DEFAULT_TCP_USER_TIMEOUT: Duration = Duration::from_secs(120);
and apply it when building the reqwest::Client:
builder = builder.tcp_user_timeout(DEFAULT_TCP_USER_TIMEOUT);
````rust
## Patch
diff --git a/codex-rs/core/src/default_client.rs b/codex-rs/core/src/default_client.rs
--- a/codex-rs/core/src/default_client.rs
+++ b/codex-rs/core/src/default_client.rs
@@
use std::sync::LazyLock;
use std::sync::Mutex;
use std::sync::RwLock;
+use std::time::Duration;
@@
pub const CODEX_INTERNAL_ORIGINATOR_OVERRIDE_ENV_VAR: &str = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
pub const RESIDENCY_HEADER_NAME: &str = "x-openai-internal-codex-residency";
+const DEFAULT_TCP_USER_TIMEOUT: Duration = Duration::from_secs(120);
@@
let mut builder = reqwest::Client::builder()
.user_agent(ua)
.default_headers(default_headers());
- // reqwest defaults tcp_user_timeout to 30s on Linux-family targets, which is too short
- // for long-running unary requests such as remote compaction.
- builder = builder.tcp_user_timeout(DEFAULT_TCP_USER_TIMEOUT);
if is_sandboxed() {
builder = builder.no_proxy();
}
```
## Build
From the repository:
```
cd codex-rs
cargo build -p codex-cli --release
Optional musl build:
cargo build --target x86_64-unknown-linux-musl -p codex-cli --release
## Result
After applying this change and rebuilding, compact / remote compaction completed successfully instead of hanging.
## Comments
Increase TCP user timeout for default client
Set an explicit 120s tcp_user_timeout on the shared reqwest client.
The default timeout can be too short for long-running unary requests such
as remote compaction on Linux-family targets.
### What steps can reproduce the bug?
Use /goal and this bug will happen.
### What is the expected behavior?
_No response_
### Additional information
_No response_
3 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I saw duplicates before but never saw anyone talking about actually fixing the problem, I hope this helps others.
Thanks for reporting this problem. Until recently, Codex used a separate endpoint and server-side logic for compaction. We recently switched to a more robust approach where the compaction logic is moved locally using the same endpoint as normal turns. This eliminates "remote compaction" errors and increases the stability and reliability of compaction operations. If you see further problems with compaction, please use
/feedbackand open a new bug report.