Repository navigation
Description
Context
While implementing Agent Guardrails Phase 1 (GUARD-001 / #140), I discovered that execute_claude_code() (chat mode) in docker/base-image/agent_server/services/claude_code.py has no subprocess wall-clock timeout, unlike execute_headless_task() (task mode) which correctly uses asyncio.wait_for(...) and calls process.kill() on timeout.
This is GUARD-003's "execution timeout" requirement for chat mode, which was explicitly deferred from the Phase 1 PR to keep scope tight.
The gap
In execute_claude_code() the subprocess runs through:
stderr_output, return_code = await loop.run_in_executor(_executor, read_subprocess_output)No asyncio.wait_for wrapper. If the Claude CLI hangs (billing error, stuck in a loop that max-turns doesn't catch, infinite stream), the chat session will hang until something external kills the container. GUARD-003 added --max-turns which covers the common "agent got confused" case, but not the case where the subprocess never emits another line.
Task mode handles this correctly at execute_headless_task() via:
return_code = await asyncio.wait_for(
loop.run_in_executor(None, read_subprocess_output_with_timeout),
timeout=timeout_seconds
)with explicit process.kill() on asyncio.TimeoutError.
Proposed fix
Wire chat mode through the same pattern. Read execution_timeout_sec from the guardrails config (same field chat and task share), default to 30 min, wrap the executor call in asyncio.wait_for, and SIGKILL the subprocess + return 504 on timeout.
Files
docker/base-image/agent_server/services/claude_code.py—execute_claude_code()around line 580
Labels
- priority-p2 (real gap but not actively causing incidents known to me)
- type-bug
Related
- Agent Guardrails: Deterministic safety enforcement for autonomous execution (GUARD-001) #140 GUARD-001 Phase 1 (where this was deferred)
- GUARD-003 requirement in
docs/memory/requirements.mdsection 28.3
Activity
feat(guardrails): Phase 1 deterministic safety enforcement (GUARD-001) (
feat(guardrails): Phase 1 deterministic safety enforcement (GUARD-001) (
feat(guardrails): Phase 1 deterministic safety enforcement (GUARD-001) (
fix(agent-server): wall-clock timeout on chat-mode subprocess (#313) (#…