fix: derive streaming status from retry firsts

This commit is contained in:
2026-07-10 07:26:15 +08:00
parent ccecee2a44
commit f67cbbda65
4 changed files with 50 additions and 9 deletions
+34 -7
View File
@@ -23,7 +23,7 @@ from typing import Any
APP_NAME = "codex-retry-gateway-tui"
FALLBACK_VERSION = "0.1.7"
FALLBACK_VERSION = "0.1.8"
DEFAULT_GATEWAY_ADMIN_PATH = "/__codex_retry_gateway"
DEFAULT_GATEWAY_URL = "http://127.0.0.1:4610/__codex_retry_gateway"
DEFAULT_API_URL = DEFAULT_GATEWAY_URL
@@ -870,6 +870,7 @@ def normalize_request_retry_firsts(value: Any) -> list[dict[str, Any]]:
{
"round": parse_int_value(item.get("round")),
"slot": parse_int_value(item.get("slot")),
"first_response_at": item.get("first_response_at"),
"first_delay_ms": item.get("first_response_delay_ms", item.get("first_delay_ms", item.get("first_ms"))),
"outcome": str(item.get("outcome") or "").strip(),
"status_code": item.get("status_code", item.get("upstream_status_code", item.get("status"))),
@@ -1339,13 +1340,38 @@ def request_match_score(row: dict[str, Any], needle: str) -> bool:
return needle in haystack
def request_retry_first_received_at(row: dict[str, Any]) -> Any:
latest_value = None
latest_at = None
for first in row.get("reasoning_retry_current_firsts") or []:
if not isinstance(first, dict):
continue
value = first.get("first_response_at")
parsed = parse_datetime(value)
if parsed and (latest_at is None or parsed > latest_at):
latest_value = value
latest_at = parsed
return latest_value
def request_has_received_first(row: dict[str, Any]) -> bool:
if parse_datetime(row.get("first_response_at")):
return True
for first in row.get("reasoning_retry_current_firsts") or []:
if not isinstance(first, dict):
continue
if parse_datetime(first.get("first_response_at")) or parse_int_value(first.get("first_delay_ms")) is not None:
return True
return False
def request_lifecycle_label(row: dict[str, Any]) -> str:
state = str(row.get("lifecycle_state") or "").strip().lower()
if request_is_discarded(row):
return "discarded"
if state in {"finish", "finished", "complete", "completed"} or parse_datetime(row.get("finished_at")):
return "finished"
if state in {"receive_first", "streaming"} or parse_datetime(row.get("first_response_at")):
if state in {"receive_first", "streaming"} or request_has_received_first(row):
return "streaming"
return "waiting"
@@ -1368,11 +1394,12 @@ def request_is_discarded(row: dict[str, Any]) -> bool:
def request_activity_at(row: dict[str, Any]) -> Any:
for key in ("last_activity_at", "first_response_at", "started_at"):
value = row.get(key)
if parse_datetime(value):
return value
return None
candidates = [row.get("last_activity_at"), row.get("first_response_at"), request_retry_first_received_at(row), row.get("started_at")]
parsed_candidates = [(parse_datetime(value), value) for value in candidates]
valid_candidates = [(parsed, value) for parsed, value in parsed_candidates if parsed]
if not valid_candidates:
return None
return max(valid_candidates, key=lambda item: item[0])[1]
def request_activity_age_seconds(row: dict[str, Any], now: dt.datetime | None = None) -> float | None: