anthropics / anthropics/claude-agent-sdk-python

Feature request: configurable API response timeout for subagent calls

Đang mở
#666 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
8.1k
Fork
1.3k
Merge trung bình
2 ngày 31 phút
Pull request đã merge (30 ngày)
1

Mô tả

## Summary

When a subagent makes an API call with large context (~83K tokens) and needs to generate large output (~30KB), the API call can hang indefinitely with zero events written to the JSONL transcript. There is no configurable timeout to detect or recover from this state.

## Reproduction

1. Launch a background agent (`run_in_background=True`) with a task requiring large context
2. Agent accumulates ~80K+ tokens of context via multiple Read calls
3. Agent makes a tool call that succeeds (e.g., `mkdir`)
4. Next API call (to generate a large Write) hangs — zero JSONL events for 4+ minutes
5. Parent agent polls via TaskOutput — always sees `status: running`
6. No mechanism to detect the hang or kill the subagent

## Observed behavior

- JSONL transcript stops at the successful `tool_result` — no new entries
- `TaskOutput` always returns `running` (can't distinguish "actively generating" from "API hung")
- `KillShell` fails ("not a local bash task")
- `TaskStop` kills the agent but destroys any in-progress work

## Expected behavior

A configurable timeout (e.g., `api_timeout_seconds` in `ClaudeAgentOptions`) that:
1. Detects when an API response hasn't produced any events for N seconds
2. Marks the agent as `error` with a clear timeout message
3. Writes the error to the agent's JSONL for downstream tracking

## Workaround

We implemented a 20-minute wall-clock timeout in our stop hook that unblocks the parent task, but the hung agent process itself stays alive consuming resources.

## Environment

- claude-agent-sdk: 0.1.48
- Claude Code CLI: 2.1.72 (bundled)
- Observed on: Python 3.12, Linux (GKE)
- Original incident: CLI 2.0.72, but the underlying issue (no API timeout) persists

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.