HKUDS/Vibe-Trading · error · RuntimeError

OpenAI Codex response failed: {str(detail)[:500]}

Error message

OpenAI Codex response failed: {str(detail)[:500]}

What it means

While streaming Codex SSE events, the event loop received an event of type 'error' or 'response.failed'. The library surfaces the upstream error payload (truncated to 500 chars) as RuntimeError so callers see the backend's failure detail.

Source

Thrown at agent/src/providers/openai_codex.py:602

                tool_buffers[call_id]["arguments"] = event.get("arguments") or ""
        elif event_type == "response.output_item.done":
            item = event.get("item") or {}
            if item.get("type") == "function_call" and item.get("call_id"):
                call_id = item["call_id"]
                buf = tool_buffers.get(call_id) or {}
                args_raw = buf.get("arguments") or item.get("arguments") or "{}"
                tool = CodexToolCall(
                    id=f"{call_id}|{buf.get('id') or item.get('id') or 'fc_0'}",
                    name=buf.get("name") or item.get("name") or "",
                    arguments=_decode_tool_args(args_raw),
                )
                yield CodexAIMessage(tool_calls=[tool.as_langchain_tool_call()])
        elif event_type == "response.completed":
            status = (event.get("response") or {}).get("status")
            yield CodexAIMessage(response_metadata={"finish_reason": _map_finish_reason(status)})
        elif event_type in {"error", "response.failed"}:
            detail = event.get("error") or event.get("message") or event
            raise RuntimeError(f"OpenAI Codex response failed: {str(detail)[:500]}")


class OpenAICodexLLM:
    """Minimal LangChain-compatible adapter for Vibe-Trading's ChatLLM."""

    def __init__(
        self,
        *,
        model: str,
        temperature: float = 0.0,
        timeout: int = 120,
        tools: list[dict[str, Any]] | None = None,
        reasoning_effort: str | None = None,
        codex_url: str | None = None,
    ) -> None:
        if httpx is None:
            raise RuntimeError("OpenAI Codex OAuth requires httpx. Install dependencies first.")
        self.model = model

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Read the truncated detail in the message — it usually names the exact upstream cause and fixes differ accordingly
  2. For transient overload/rate errors, retry the request with backoff
  3. Validate tool definitions (JSON schema fields) before streaming; for auth issues, re-login via the Codex provider flow

Example fix

# before
for chunk in llm.stream(messages):
    ...  # RuntimeError mid-iteration

# after
try:
    for chunk in llm.stream(messages):
        ...
except RuntimeError as e:
    if "rate" in str(e).lower():
        time.sleep(5); retry()
    else:
        raise
Defensive patterns

Strategy: retry

Validate before calling

_CODEX_TOOLS_SCHEMA_OK = all(isinstance(t, dict) and 'name' in t for t in tools or [])

Try / catch

try:
    for chunk in llm.stream(messages):
        handle(chunk)
except RuntimeError as e:
    if 'Codex response failed' not in str(e):
        raise
    if is_transient(str(e)):
        retry_with_backoff()
    else:
        surface_to_user(str(e))

Prevention

When it happens

Trigger: Calling OpenAICodexLLM.stream and the backend mid-response emits {"type":"error"} or "response.failed" — e.g. model overload, content policy, malformed tool definitions, or upstream 5xx surfaced in the SSE stream.

Common situations: Passing invalid tool schemas the backend rejects mid-stream; capacity/rate limit errors during long streaming sessions; expired auth occasionally surfacing as stream errors.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/d766a1e45a38b48c. Report an issue: GitHub.