Tune Claude Code CLI retry/timeout resilience env#46
Open
mkonopelski-gd wants to merge 4 commits into
Open
Conversation
…ebug entrypoint Forward API_TIMEOUT_MS, CLAUDE_CODE_MAX_RETRIES, and CLAUDE_ASYNC_AGENT_STALL_TIMEOUT_MS to the Claude Code CLI subprocess so a transient network blip is retried by the CLI itself before it burns a phase-level resume attempt (or the whole phase) in agent_query_with_resume. Also fills in the previously-empty __main__ with a self-contained local debug entrypoint (throwaway git workspace, redirected cache/log/tmpdir settings, .env-backfilled provider key) plus a retry-forcing experiment used to verify the new env values are honored by the CLI end-to-end.
akozak-gd
approved these changes
Jul 13, 2026
Contributor
Author
|
@awrobel-gd This actually doesn't make sense. Because are way lower than default which I finally found (https://code.claude.com/docs/en/env-vars) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
API_TIMEOUT_MS(120s),CLAUDE_CODE_MAX_RETRIES(3), andCLAUDE_ASYNC_AGENT_STALL_TIMEOUT_MS(120s) to the Claude Code CLI subprocess via a newsetup_claude_code_resilience_env(), wired intoagent_query's env alongside the existingsetup_claude_code_*helpers. Goal: let the CLI itself retry past a transient network blip instead of burning a phase-level resume attempt (or the whole phase) inagent_query_with_resume.__main__with a self-contained local debug entrypoint (throwaway git workspace with a localorigin, redirectedAGENT_LOGS_BASE_PATH/WORKSPACE_BASE_PATH/CLAUDE_CODE_TMPDIR_PATH,.env-backfilled provider key) plus a retry-forcing experiment (_debug_retry_experiment, run viaDEBUG_RETRY_EXPERIMENT=1) used to verify the retry mechanism end-to-end.How this was tested
python -m app.services.claude_code): generated a working Express app end-to-end against a throwaway workspace — confirms the harness plumbing (workspace/cache/log paths, provider key resolution) works outside docker-compose._debug_retry_experimentruns a singleagent_querywith a deliberately lowAPI_TIMEOUT_MS(500ms, far below any real response time) andCLAUDE_CODE_MAX_RETRIES=5, forcing every attempt to time out. AtDEBUGlog level this produced exactly 5api_retrySystemMessages (attempt: 1..5,max_retries: 5) over ~21s before the CLI gave up — direct, first-party confirmation thatCLAUDE_CODE_MAX_RETRIESis honored by the SDK.make check(ruff clean; the 3 remaining mypy errors are pre-existing, in unrelated files not touched by this change) andmake unit-tests(658 passed) both green.Test plan
CLAUDE_CODE_MAX_RETRIES=3/API_TIMEOUT_MS=120000/CLAUDE_ASYNC_AGENT_STALL_TIMEOUT_MS=120000as the intended production defaults