Skip to content

[BUG] Network timeouts misclassified as context window errors #683

@dimensi

Description

@dimensi

Bug Description

HTTP timeouts from LLM providers (e.g. z.ai) are incorrectly classified as context window errors. This causes:

  1. Useless history compression triggered on network timeouts
  2. Misleading message to users: "Context window exceeded. Compressing history and retrying..."
  3. No actual retry of the failed request

Steps to Reproduce

  1. Configure picoclaw with z.ai (or any provider with slow/unstable network)
  2. Send a message that triggers an LLM call
  3. Wait for HTTP timeout (2 minutes)
  4. Observe the error in logs:
    error=failed to send request: context deadline exceeded 
    (Client.Timeout exceeded while awaiting headers)
    

Expected Behavior

  • Timeout errors should be recognized as network timeouts
  • The request should be retried with backoff
  • No false "Context window exceeded" message

Actual Behavior

  • context deadline exceeded matches the broad "context" substring check in the retry loop
  • Client.Timeout matches the broad "token" substring check
  • Error is classified as a context window error
  • History compression runs (pointless for a network issue)
  • User sees "Context window exceeded" (misleading)
  • After compression + retry fails, the error is not retried further

Root Cause

In pkg/agent/loop.go, the context window error detection uses overly broad substring matching:

isContextError := strings.Contains(errMsg, "token") ||
    strings.Contains(errMsg, "context") ||
    strings.Contains(errMsg, "invalidparameter") ||
    strings.Contains(errMsg, "length")
  • "context" matches both context_length_exceeded and context deadline exceeded
  • "token" matches both token limit errors and Client.Timeout

Fix

PR #681

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions