Skip to content

fix(aider): stream Anthropic requests to avoid the 10-min non-streaming cancel - #8

Merged
anthonyadame merged 2 commits into
mainfrom
fix/aider-stream-anthropic
Jun 9, 2026
Merged

fix(aider): stream Anthropic requests to avoid the 10-min non-streaming cancel#8
anthonyadame merged 2 commits into
mainfrom
fix/aider-stream-anthropic

Conversation

@anthonyadame

@anthonyadame anthonyadame commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Problem

The aider runner failed 100% deterministically on Anthropic for large-generation libraries, with:

httpcore.RemoteProtocolError: Server disconnected without sending a response

aider spun ~601 s (elapsed_s ≈ 600), committed an empty patch (sha e3b0c442…), and the valid-rep gate correctly discarded it. This blocked the Sonnet re-validation of the floor-lib Aider cells (chardet, voluptuous, marshmallow, jinja).

Root cause (found via a $0 request-capture diagnostic)

An httpx-layer shim captured aider's outgoing request and diffed it against a working direct litellm.completion. The only meaningful difference: aider sends max_tokens=64000 with stream=False.

Anthropic cancels non-streaming requests whose generation can exceed its ~10-minute server cap — and the large floor-lib generations hit it (the elapsed_s ≈ 600 is exactly that 10-min timeout). Everything else was ruled out as a red herring: key, model (claude-sonnet-4-6), litellm 1.83.14, prompt caching, WSL MTU, and direct litellm calls up to 200k tokens / 683 KB (stream and non-stream) all succeeded. This also explains the pattern — the 7 small/fast Aider×Sonnet cells that ran on 2026-06-04 succeeded; only the 4 long-generation cells failed.

Fix

stream=(provider == "anthropic") in commit0/baselines/aider/_aider_runner.py — streaming is enabled for Anthropic only, since it cancels non-streaming requests at its ~10-min server cap. OpenAI keeps its validated stream=False path (no such cap observed). Also adds a KAIZEN_AIDER_CACHE env toggle (default on; disabling caching was tested and is not the cause).

Validation (2026-06-08)

Re-ran the affected Sonnet cells full-suite via score_branch, with streaming:

Cell Result Δ vs single-shot Sonnet cost
voluptuous 89.3% (133/149) +89.3 pp $1.81
marshmallow 87.3% (1073/1229) +87.3 pp $3.84
chardet 66.5% (250/376) +66.2 pp $5.31
jinja n/a

jinja remains n/a — its ~170k-token repo context + the 64k max_tokens exceeds Sonnet's 200k window (a separate, fundamental limit; it ran on OpenAI only because of the larger window). Voluptuous Sonnet 89.3% ≈ the OpenAI sampled 88.7% — nice cross-provider agreement.

Docs

  • commit0/RERUN_CHECKLIST.md — full diagnosis + the fix-then-rerun recipe (references the tracked baselines/sampling/repeat_runner.py command for reproducibility).
  • CORRECTIONS.md — Aider×Sonnet updated to 10/16 full-suite-scored (7 + the 3 re-validated; jinja n/a).

🤖 Generated with Claude Code

…ng cancel

aider configured the Anthropic coder with stream=False + max_tokens=64000. Anthropic cancels non-streaming requests whose generation can exceed its ~10-min server cap; the large floor-lib generations (chardet, voluptuous, marshmallow, jinja) hit it and failed with httpcore.RemoteProtocolError 'Server disconnected without sending a response' (elapsed_s~600 = the cap), producing empty patches. Small/fast libs were unaffected -- which is why the 7 cells that ran on 2026-06-04 succeeded and these 4 did not.

Root-caused via a $0 httpx request-capture diagnostic: direct litellm calls of every size (up to 200k tok) + caching + streaming all succeeded; only aider's max_tokens=64000 + stream=False combo failed. Fix: stream=True.

Validated 2026-06-08 -- re-ran the affected Sonnet cells full-suite via score_branch: voluptuous 133/149 (89.3%), marshmallow 1073/1229 (87.3%), chardet 250/376 (66.5%); jinja remains n/a (its ~170k-tok context + 64k max_tokens exceeds Sonnet's 200k window -- a separate, fundamental limit).

Also adds a KAIZEN_AIDER_CACHE env toggle (default on; tested off, not the cause), and documents the diagnosis + corrected 10/16 Aider-Sonnet count in RERUN_CHECKLIST.md / CORRECTIONS.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses deterministic failures when running the Aider baseline against Anthropic Sonnet for long generations by enabling request streaming, and updates the re-validation documentation to reflect the corrected rerun status and root-cause diagnosis.

Changes:

  • Enable streaming in the Aider runner to avoid Anthropic’s ~10-minute non-streaming server cap for long generations.
  • Add an env toggle (KAIZEN_AIDER_CACHE) to disable Aider prompt caching while keeping it enabled by default.
  • Update CORRECTIONS.md and commit0/RERUN_CHECKLIST.md to document the diagnosis, fix, and updated full-suite re-validation status.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
commit0/baselines/aider/_aider_runner.py Switches Aider to streaming requests and adds an env-controlled prompt-cache toggle.
commit0/RERUN_CHECKLIST.md Documents the Anthropic streaming root cause/fix and rerun outcomes.
CORRECTIONS.md Updates the corrected status/numbers for Aider × Sonnet and references the streaming fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +325 to +326
cache_prompts=(os.environ.get("KAIZEN_AIDER_CACHE", "1") != "0"), # native Anthropic prompt cache; KAIZEN_AIDER_CACHE=0 disables
stream=True, # MUST stream on Anthropic: non-streaming requests are cancelled at the ~10-min server cap, and large-generation cells (chardet/voluptuous/marshmallow/jinja) exceed it -> httpcore.RemoteProtocolError "Server disconnected" (elapsed_s~600 = the 10-min cap). Root cause confirmed via $0 request-capture diagnostic 2026-06-08; see RERUN_CHECKLIST.md.
Comment thread commit0/RERUN_CHECKLIST.md Outdated
Comment on lines +27 to +28
> Tier-A re-run of the 4 aider-Sonnet cells (`chardet, voluptuous, marshmallow, jinja`;
> `.git/run_tier_a_sonnet.sh`) failed 100% with **`httpcore.RemoteProtocolError: Server
…pic; drop untracked-script ref

- stream: enable only for Anthropic (provider == 'anthropic') rather than unconditionally, so OpenAI keeps its validated stream=False path. The 10-min non-streaming cancel is Anthropic-specific; no need to change OpenAI behavior.

- RERUN_CHECKLIST: reference the tracked, reproducible repeat_runner command instead of the untracked .git/ scratch script.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@anthonyadame

Copy link
Copy Markdown
Contributor Author

Thanks @copilot — both addressed in 9c6af15:

  • stream scope: good catch. Gated to Anthropic only (stream=(provider == "anthropic")) so OpenAI keeps its validated stream=False path — the ~10-min non-streaming cancel is Anthropic-specific, no reason to change OpenAI behavior. Comment updated to match.
  • untracked script ref: replaced the .git/run_tier_a_sonnet.sh mention with the tracked, reproducible command (baselines/sampling/repeat_runner.py --arch aider --provider anthropic --libs <lib> --reps 1).

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown

Thanks @copilot — both addressed in 9c6af15:

  • stream scope: good catch. Gated to Anthropic only (stream=(provider == "anthropic")) so OpenAI keeps its validated stream=False path — the ~...

Confirmed — both changes in 9c6af15 look correct. stream=(provider == "anthropic") properly scopes the behavior to Anthropic only (OpenAI keeps stream=False), and the checklist now references the tracked repeat_runner.py command instead of the .git/ scratch script.

@anthonyadame
anthonyadame merged commit 7ebb849 into main Jun 9, 2026
3 checks passed
@anthonyadame
anthonyadame deleted the fix/aider-stream-anthropic branch June 9, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants