fix(account): keep the first of a repeated response header

AR
12h ago
+982-136

The response header block was collected into a BTreeMap with insert(), which replaces:

for (name, value) in response.headers() {
    if let Ok(text) = value.to_str() {
        headers.insert(name.as_str().to_string(), text.to_string());
    }
}

So when a field arrived twice, the last value won and the console's own answer was silently discarded.

These are single-valued fields — a duplicate is invalid per RFC — but this map is acted on, not just displayed:

  • retry_after_seconds() (console.rs:57) feeds next_poll_delay_seconds for the sign-in poll's backoff;
  • it also produces the message a person reads: "Wally Cloud is busy - try again in {wait}s" (console.rs:1138);
  • and it gates the coincident retry sleep (console.rs:1430).

A second Retry-After could therefore shorten a backoff the console explicitly asked for, and tell the person a smaller number than the console sent.

The transport already reads this the other way: header_lookup (http1.rs:324) walks a Vec and takes the first match. The console agreed with it only by accident, because nothing upstream happened to send a duplicate.

Change

entry().or_insert_with() — keep the first value, matching header_lookup.

Test

a_repeated_header_keeps_the_first_value drives real_transport against a socket that sends the header twice, then asserts on the HttpResponse it actually produced:

assertion `left == right` failed: the console's own Retry-After was replaced by the duplicate
  left: 1
 right: 30

Fails on main with left: 1; passes with 30.

Verification

  • cargo test --lib: 636 passed, 0 failed (three consecutive runs)
  • cargo clippy --all-targets -- -D warnings: clean
  • cargo fmt --all: clean

Summary by cubic

Fixes the console client keeping the last of a repeated response header, so a duplicate Retry-After can no longer silently shorten the backoff the console actually requested. These fields are single-valued; the first value now wins, matching the transport's own header_lookup.

Also in this PR

  • Console requests share one pooled connection per proxy and timeout pair instead of paying a handshake per request.
  • The image gate keeps one upstream agent, forwards Content-Encoding so encoded bodies reach the editor, and drops the response reader before the client write.
  • The codex shim declares X-RA-Harness: codex on every request instead of relying on the User-Agent fallback.
  • Chunked framing reads through a buffer rather than one read syscall per byte.
  • Link-filtering logic moves out of build.rs into build_link_args.rs and drops compile-only flags together with their operands, fixing a --sysroot/-isystem link failure.

Summary by CodeRabbit

  • Performance

    • Reused upstream connections for console and image requests, reducing repeated connection setup.
    • Improved handling of chunked responses to reduce unnecessary read operations.
  • Bug Fixes

    • Preserved valid content-encoding information when forwarding image responses.
    • Kept the first value when responses contain duplicate headers.