@@ -207,25 +207,44 @@ def _label_for_codex_window(seconds: int) -> str:
207207
208208
209209def _codex_reset_hint (win_map : Mapping [str , Any ]) -> str | None :
210- # Current shape: `resets_at` is a unix-seconds timestamp.
211- # Older shape: `reset_at` is an ISO-8601 string.
212- resets_at_unix = win_map .get ("resets_at" )
213- if isinstance (resets_at_unix , int | float ):
210+ # The reset time arrives under `resets_at` or `reset_at`, and as a
211+ # unix-seconds timestamp (number or numeric string) or an ISO-8601 string.
212+ # Always humanize it ("resets in 2h 14m") rather than printing a raw value.
213+ for key in ("resets_at" , "reset_at" ):
214+ raw = win_map .get (key )
215+ if raw is None :
216+ continue
217+ dt = _coerce_reset_datetime (raw )
218+ if dt is not None :
219+ return _format_reset_delta (dt , win_map )
220+ if isinstance (raw , str ) and raw .strip ():
221+ return f"resets at { raw .strip ()} "
222+ return None
223+
224+
225+ def _coerce_reset_datetime (raw : object ) -> datetime | None :
226+ """Parse a reset timestamp that may be unix seconds (number or numeric
227+ string) or an ISO-8601 string."""
228+ if isinstance (raw , bool ):
229+ return None
230+ if isinstance (raw , int | float ):
214231 try :
215- dt = datetime .fromtimestamp (float (resets_at_unix ), tz = UTC )
232+ return datetime .fromtimestamp (float (raw ), tz = UTC )
216233 except (OverflowError , OSError , ValueError ):
217234 return None
218- return _format_reset_delta (dt , win_map )
219-
220- reset_at = win_map .get ("reset_at" )
221- if reset_at is None :
222- return None
223- reset_at_str = str (reset_at )
224- try :
225- dt = datetime .fromisoformat (reset_at_str .replace ("Z" , "+00:00" ))
226- except (TypeError , ValueError ):
227- return f"resets at { reset_at_str } "
228- return _format_reset_delta (dt , win_map )
235+ if isinstance (raw , str ):
236+ candidate = raw .strip ()
237+ if not candidate :
238+ return None
239+ try : # numeric string -> unix seconds
240+ return datetime .fromtimestamp (float (candidate ), tz = UTC )
241+ except (OverflowError , OSError , ValueError ):
242+ pass
243+ try : # ISO-8601
244+ return datetime .fromisoformat (candidate .replace ("Z" , "+00:00" ))
245+ except (TypeError , ValueError ):
246+ return None
247+ return None
229248
230249
231250def _format_reset_delta (dt : datetime , win_map : Mapping [str , Any ]) -> str :
0 commit comments