chore(codex): identify failing request stage (#4929)

This commit is contained in:
chengyongru
2026-07-14 22:40:10 +08:00
committed by GitHub
parent 1a1e666625
commit 07f54c25e3
2 changed files with 8 additions and 3 deletions
+4 -1
View File
@@ -75,10 +75,12 @@ class OpenAICodexProvider(LLMProvider):
if tools:
body["tools"] = convert_tools(tools)
stage = "oauth_token"
try:
token = await asyncio.to_thread(get_codex_token, proxy=self.proxy)
headers = _build_headers(token.account_id, token.access)
stage = "codex_request"
try:
content, tool_calls, finish_reason, usage, reasoning_content = await _request_codex(
DEFAULT_CODEX_URL, headers, body, verify=True,
@@ -109,8 +111,9 @@ class OpenAICodexProvider(LLMProvider):
response = _codex_error_response(e)
exc_type = "CodexHTTPError" if isinstance(e, _CodexHTTPError) else type(e).__name__
logger.warning(
"Codex API request failed: type={} kind={} retryable={} status={} "
"Codex API request failed: stage={} type={} kind={} retryable={} status={} "
"error_type={} error_code={} retry_after={} summary={}",
stage,
exc_type,
response.error_kind,
response.error_should_retry,
@@ -294,9 +294,10 @@ async def test_codex_timeout_error_writes_diagnostic_log(monkeypatch) -> None:
)
assert log_capture.calls == [
(
"Codex API request failed: type={} kind={} retryable={} status={} "
"Codex API request failed: stage={} type={} kind={} retryable={} status={} "
"error_type={} error_code={} retry_after={} summary={}",
(
"codex_request",
"ReadTimeout",
"timeout",
True,
@@ -414,9 +415,10 @@ async def test_codex_http_diagnostic_log_omits_raw_body(monkeypatch) -> None:
assert response.content == "Error calling Codex (CodexHTTPError): HTTP 500: Codex API request failed"
assert log_capture.calls == [
(
"Codex API request failed: type={} kind={} retryable={} status={} "
"Codex API request failed: stage={} type={} kind={} retryable={} status={} "
"error_type={} error_code={} retry_after={} summary={}",
(
"codex_request",
"CodexHTTPError",
"http",
True,