Skip to content

bug: chat mode has no wall-clock timeout (GUARD-003 follow-up) #313

Closed

Description

@dolho

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p2theme-reliabilitytype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions