Tune Claude Code CLI retry/timeout resilience env#46
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.
|
@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) |
Ok but maybe our version is too old? We have no retry, or the retries are not logged. Like if we have error about connection lost, the somewhere in this error or in the session JSON metadata printed, should be some time value ~600s, which we dont see. The default settings you posted seem to have no effect? What if we upgrade version or try to find which Claude SDK added these settins |
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