Skip to content

The agent that grows with you

ci: don't cast int to int

Maciej Lisiewskib4e436c115b3
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 2e050390025..8c7e55c4d45 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -184,8 +184,8 @@ def _build_codex_gpt5_autoraise_notice(
else:
# Static fallback: codex-spark is natively 128K; gpt-5.4/5.5/5.6 are capped at 272K.
cap = "128K" if model.startswith("gpt-5.3-codex-spark") else "272K"
- from_pct = int(round(autoraise["from"] * 100))
- to_pct = int(round(autoraise["to"] * 100))
+ from_pct = round(autoraise["from"] * 100)
+ to_pct = round(autoraise["to"] * 100)
return (
f"ℹ Codex {model} caps context at {cap}, so auto-compaction was raised "
f"to {to_pct}% (from {from_pct}%) to use more of the window before "
@@ -225,8 +225,8 @@ def _codex_gpt55_autoraise_notice_state(autoraise: dict[str, Any]) -> str:
different autoraised Codex model re-notifies once.
"""
model = str(autoraise.get("model") or "").strip().lower().rsplit("/", 1)[-1]
- from_pct = int(round(float(autoraise["from"]) * 100))
- to_pct = int(round(float(autoraise["to"]) * 100))
+ from_pct = round(float(autoraise["from"]) * 100)
+ to_pct = round(float(autoraise["to"]) * 100)
return f"{model}:{from_pct}:{to_pct}"
diff --git a/agent/battery.py b/agent/battery.py
index 53eb56b06c7..7d81606bdfa 100644
--- a/agent/battery.py
+++ b/agent/battery.py
@@ -55,7 +55,7 @@ def _read_battery_uncached() -> BatteryStatus:
raw_percent = getattr(batt, "percent", None)
if raw_percent is not None:
try:
- percent = max(0, min(100, int(round(float(raw_percent)))))
+ percent = max(0, min(100, round(float(raw_percent))))
except (TypeError, ValueError):
percent = None
plugged = getattr(batt, "power_plugged", None)
diff --git a/agent/credits_tracker.py b/agent/credits_tracker.py
index e145eae5f2a..1ebd56c5174 100644
--- a/agent/credits_tracker.py
+++ b/agent/credits_tracker.py
@@ -362,7 +362,7 @@ def _credits_state_from_account(info) -> Optional[CreditsState]:
sub = getattr(info, "subscription", None)
def _money(dollars) -> tuple[int, str]: # (micros, display usd); (0, "") when absent
- return (int(round(dollars * 1_000_000)), f"{dollars:.2f}") if isinstance(dollars, (int, float)) else (0, "")
+ return (round(dollars * 1_000_000), f"{dollars:.2f}") if isinstance(dollars, (int, float)) else (0, "")
fields: dict[str, Any] = {}
for prefix, attr in (("remaining", "total_usable_credits"), ("subscription", "subscription_credits_remaining"),
("purchased", "purchased_credits_remaining")):
diff --git a/agent/pet/render.py b/agent/pet/render.py
index 55eaa3f75ed..cd36f719450 100644
--- a/agent/pet/render.py
+++ b/agent/pet/render.py
@@ -246,7 +246,7 @@ def _downscale_cells(frame, *, target_cols: int) -> list[list[Cell]]:
from PIL import Image
target_cols = max(4, target_cols)
- target_rows = max(2, int(round(target_cols * (frame.height / max(1, frame.width)) * 0.5)) * 2)
+ target_rows = max(2, round(target_cols * (frame.height / max(1, frame.width)) * 0.5) * 2)
px = frame.resize((target_cols, target_rows), Image.LANCZOS).convert("RGBA").load()
return [
[(px[x, y], px[x, y + 1] if y + 1 < target_rows else (0, 0, 0, 0)) for x in range(target_cols)]
diff --git a/agent/turn_summary.py b/agent/turn_summary.py
index 55d27fd6df4..3351c333c8b 100644
--- a/agent/turn_summary.py
+++ b/agent/turn_summary.py
@@ -149,7 +149,7 @@ def format_elapsed(seconds: float) -> str:
seconds = max(seconds, 0.0)
if seconds < 60:
return f"{seconds:.1f}s"
- minutes, rest = divmod(int(round(seconds)), 60)
+ minutes, rest = divmod(round(seconds), 60)
return f"{minutes}m{rest:02d}s"
diff --git a/gateway/platforms/signal_rate_limit.py b/gateway/platforms/signal_rate_limit.py
index 4ec09e55477..320c61edaf1 100644
--- a/gateway/platforms/signal_rate_limit.py
+++ b/gateway/platforms/signal_rate_limit.py
@@ -75,7 +75,7 @@ def _is_signal_rate_limit_error(err: Any) -> bool:
def _format_wait(seconds: float) -> str:
"""Human-friendly wait label for user-facing pacing notices."""
s = max(0.0, seconds)
- return t("platform.signal.wait_seconds", count=int(round(s))) if s < 90 else t("platform.signal.wait_minutes", count=max(1, int(round(s / 60))))
+ return t("platform.signal.wait_seconds", count=round(s)) if s < 90 else t("platform.signal.wait_minutes", count=max(1, round(s / 60)))
def _signal_send_timeout(num_attachments: int) -> float:
diff --git a/gateway/run.py b/gateway/run.py
index 9b40970ce41..a459ce250b6 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -2545,7 +2545,7 @@ def _build_document_context_note(
def _format_duration(seconds: float) -> str:
- total = max(0, int(round(seconds)))
+ total = max(0, round(seconds))
hours, rem = divmod(total, 3600)
minutes, secs = divmod(rem, 60)
if hours:
diff --git a/gateway/runtime_footer.py b/gateway/runtime_footer.py
index 54c923c8209..da5eda22a31 100644
--- a/gateway/runtime_footer.py
+++ b/gateway/runtime_footer.py
@@ -66,7 +66,7 @@ def _format_latency(seconds: float) -> str:
"""Humanize a turn duration: ``<1s``, ``22s``, ``1m05s``."""
if seconds < 1:
return "<1s"
- total = int(round(seconds))
+ total = round(seconds)
if total < 60:
return f"{total}s"
m, sec = divmod(total, 60)
diff --git a/gateway/slash_commands_status.py b/gateway/slash_commands_status.py
index 3f35f43f81b..bfeb5db729d 100644
--- a/gateway/slash_commands_status.py
+++ b/gateway/slash_commands_status.py
@@ -370,7 +370,7 @@ class GatewayStatusCommandsMixin:
# Gauge path: preserve the provenance of the selected occupancy figure.
if used > 0 and context_length > 0:
pct = _pct(used, context_length)
- filled = int(round(pct / 100 * 24))
+ filled = round(pct / 100 * 24)
lines = [
t("gateway.context.header"), "",
t("gateway.context.model", model=model_name or "?"),
diff --git a/gateway/status.py b/gateway/status.py
index 3275cf5cfab..7564c0438bf 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -496,7 +496,7 @@ def _get_process_start_time(pid: int) -> Optional[int]:
# of the same process compare equal without float-precision fragility.
try:
import psutil # type: ignore
- return int(round(psutil.Process(pid).create_time() * 100))
+ return round(psutil.Process(pid).create_time() * 100)
except Exception:
return None
@@ -2116,7 +2116,7 @@ def get_running_pid_identity_strict(pid_path: Path) -> Optional[tuple[int, float
exact_create_time = float(psutil.Process(pid).create_time())
except Exception as exc:
raise RuntimeError("exact gateway creation time is unavailable") from exc
- if int(round(exact_create_time * 100)) != int(current):
+ if round(exact_create_time * 100) != int(current):
raise RuntimeError("gateway process identity changed")
return pid, exact_create_time
diff --git a/hermes_cli/anon_auth.py b/hermes_cli/anon_auth.py
index 217937050a3..972471ca35c 100644
--- a/hermes_cli/anon_auth.py
+++ b/hermes_cli/anon_auth.py
@@ -142,8 +142,8 @@ def friendly_wait(seconds: Any) -> str:
if s < 90:
return "about a minute"
if s < 3600:
- return f"about {int(round(s / 60))} minutes"
- hours = int(round(s / 3600))
+ return f"about {round(s / 60)} minutes"
+ hours = round(s / 3600)
return "about an hour" if hours <= 1 else f"about {hours} hours"
@@ -485,7 +485,7 @@ class MintFailure:
"""The wire shape every status RPC carries: ``{error_code, error, retryable, retry_after}``
with ``retry_after`` the seconds still to wait (whole, rounded up)."""
return {"error_code": self.code, "error": self.message, "retryable": self.retryable,
- "retry_after": int(math.ceil(self.remaining())) if self.retryable else 0}
+ "retry_after": math.ceil(self.remaining()) if self.retryable else 0}
_mint_failures: dict[str, MintFailure] = {}
diff --git a/hermes_cli/auth_commands.py b/hermes_cli/auth_commands.py
index b6b62a11095..a478372262e 100644
--- a/hermes_cli/auth_commands.py
+++ b/hermes_cli/auth_commands.py
@@ -188,7 +188,7 @@ def _format_exhausted_status(entry) -> str:
exhausted_until = _exhausted_until(entry)
if exhausted_until is None:
return head
- remaining = max(0, int(math.ceil(exhausted_until - time.time())))
+ remaining = max(0, math.ceil(exhausted_until - time.time()))
if remaining <= 0:
return f"{head} (ready to retry)"
minutes, seconds = divmod(remaining, 60)
diff --git a/hermes_cli/journey.py b/hermes_cli/journey.py
index 8bbdff83954..beb19feca43 100644
--- a/hermes_cli/journey.py
+++ b/hermes_cli/journey.py
@@ -167,7 +167,7 @@ def _frame_renderable(payload, *, cols, rows, reveal, color):
axis_line.append(axis["end"], style=st("grey54"))
parts.append(axis_line)
- pct = int(round(reveal * 100))
+ pct = round(reveal * 100)
foot = Text(" ")
foot.append("◷ ", style=st("grey54"))
foot.append(frame["date"] or "—", style=st(_TITLE_COLOR))
diff --git a/hermes_cli/models_pricing.py b/hermes_cli/models_pricing.py
index 753c690fce4..b887276d1bc 100644
--- a/hermes_cli/models_pricing.py
+++ b/hermes_cli/models_pricing.py
@@ -147,7 +147,7 @@ def _sale_pct(current: Any, original: Any) -> int | None:
cur, orig = _price_float(current, positive=True), _price_float(original, positive=True)
if cur is None or orig is None or cur >= orig:
return None
- return int(round((1.0 - (cur / orig)) * 100))
+ return round((1.0 - (cur / orig)) * 100)
def compute_sale_discount(prompt: str, completion: str, original: Any) -> tuple[int, str, str] | None:
diff --git a/hermes_cli/update_cmd_windows.py b/hermes_cli/update_cmd_windows.py
index 71821b5a9c9..25596632628 100644
--- a/hermes_cli/update_cmd_windows.py
+++ b/hermes_cli/update_cmd_windows.py
@@ -521,7 +521,7 @@ def _orphaned_desktop_backend_pids(matches: list[tuple[int, str, str]]) -> list[
proc = psutil.Process(int(pid))
# Fingerprint from the SAME psutil handle, centisecond-quantized like
# gateway.status.get_process_start_time so pid_is_hermes round-trips at kill time.
- process_start_time = int(round(proc.create_time() * 100))
+ process_start_time = round(proc.create_time() * 100)
except psutil.NoSuchProcess:
continue # exited during classification — nothing to reap
except Exception:
@@ -1038,7 +1038,7 @@ def _stop_windows_gateways(running_pids, profile_processes, service_gateway_pids
from hermes_cli.update_cmd import _m
mapped = [int(p) for p in running_pids if int(p) not in service_gateway_pids and int(p) in profile_processes]
born = {**{int(k): v for k, v in (born or {}).items()},
- **{p: int(round(float(profile_processes[p].create_time) * 100)) for p in mapped
+ **{p: round(float(profile_processes[p].create_time) * 100) for p in mapped
if float(getattr(profile_processes[p], "create_time", 0) or 0) > 0}}
# Resolve venv-side launchers before any request: the launcher keeps ``.pyd`` mapped and would trip the
# venv-holder guard, so it is killed with the survivors, under the identity it has now.
diff --git a/hermes_state_portability.py b/hermes_state_portability.py
index a2348210a10..76d596973ba 100644
--- a/hermes_state_portability.py
+++ b/hermes_state_portability.py
@@ -106,7 +106,7 @@ def _export_timings(messages: list[dict[str, Any]], session_id: Optional[str] =
intervals = [{
"from_message_id": prev.get("id"), "to_message_id": nxt.get("id"),
"from_role": prev.get("role"), "to_role": nxt.get("role"),
- "gap_ms": max(0, int(round((nxt_ts - prev_ts) * 1000))),
+ "gap_ms": max(0, round((nxt_ts - prev_ts) * 1000)),
} for (prev, prev_ts), (nxt, nxt_ts) in zip(timestamped, timestamped[1:])]
iso = lambda ts: datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()
first_ts, last_ts = (timestamped[0][1], timestamped[-1][1]) if timestamped else (None, None)
@@ -118,7 +118,7 @@ def _export_timings(messages: list[dict[str, Any]], session_id: Optional[str] =
"message_timestamps": {"available": len(timestamped), "missing": len(messages) - len(timestamped)},
"first_message_at": iso(first_ts) if first_ts is not None else None,
"last_message_at": iso(last_ts) if last_ts is not None else None,
- "wall_clock_ms": max(0, int(round((last_ts - first_ts) * 1000))) if timestamped else None,
+ "wall_clock_ms": max(0, round((last_ts - first_ts) * 1000)) if timestamped else None,
"largest_gap_ms": max(i["gap_ms"] for i in intervals) if intervals else None,
"role_counts": dict(role_counts),
"tool_result_count": role_counts.get("tool", 0),
diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.py
index 6da84dd2111..5b1f016a4b0 100644
--- a/plugins/platforms/telegram/adapter.py
+++ b/plugins/platforms/telegram/adapter.py
@@ -215,7 +215,7 @@ _TELEGRAM_IMAGE_EXT_TO_MIME = {".png": "image/png", ".jpg": "image/jpeg", ".jpeg
def _coerce_duration_seconds(value: Any) -> Optional[int]:
"""Round a raw length to whole positive seconds, or None if unusable."""
try:
- secs = int(round(float(value)))
+ secs = round(float(value))
except (TypeError, ValueError):
return None
return secs if secs > 0 else None
diff --git a/ruff.strict.toml b/ruff.strict.toml
index 589a082f2fe..eb552554740 100644
--- a/ruff.strict.toml
+++ b/ruff.strict.toml
@@ -435,7 +435,7 @@ select = [
# "RUF034",
"RUF040",
"RUF041",
- # "RUF046",
+ "RUF046",
"RUF048",
"RUF049",
"RUF051",
diff --git a/tools/bot_relay.py b/tools/bot_relay.py
index 6d090eb2b61..0688a8a0748 100644
--- a/tools/bot_relay.py
+++ b/tools/bot_relay.py
@@ -637,7 +637,7 @@ class TurnBusyError(RuntimeError):
def __init__(self, profile: str, waited_seconds: float):
self.profile, self.waited_seconds = profile, waited_seconds
super().__init__(f"target_busy: another delivery turn is already running for profile '{profile}' — "
- f"queued behind it for ~{int(round(waited_seconds))}s without it finishing. "
+ f"queued behind it for ~{round(waited_seconds)}s without it finishing. "
"The message was NOT delivered; retry shortly.")
diff --git a/tools/tool_search.py b/tools/tool_search.py
index 06d524cec2d..d04ccebaac9 100644
--- a/tools/tool_search.py
+++ b/tools/tool_search.py
@@ -190,7 +190,7 @@ def estimate_tokens_from_schemas(tool_defs: Iterable[dict[str, Any]]) -> int:
return len(json.dumps(td, ensure_ascii=False, separators=(",", ":")))
except (TypeError, ValueError):
return len(str(td))
- return int(math.ceil(sum(map(_chars, tool_defs)) / CHARS_PER_TOKEN))
+ return math.ceil(sum(map(_chars, tool_defs)) / CHARS_PER_TOKEN)
def should_activate(config: ToolSearchConfig, deferrable_tokens: int,
diff --git a/tools/voice_mode.py b/tools/voice_mode.py
index 913b1629f4a..8940d031c16 100644
--- a/tools/voice_mode.py
+++ b/tools/voice_mode.py
@@ -131,7 +131,7 @@ def _default_input_samplerate(sd) -> int:
info = sd.query_devices(None, "input")
rate = info.get("default_samplerate") if isinstance(info, dict) else getattr(info, "default_samplerate", None)
if isinstance(rate, (int, float)) and rate > 0:
- return int(round(rate))
+ return round(rate)
return SAMPLE_RATE
@@ -1337,7 +1337,7 @@ class _BargeDetector:
def __init__(self, np, *, mult: float, calib_blocks: int, trip_blocks: int, grace_blocks: int) -> None:
self._np, self.mult, self.calib_blocks, self.grace_blocks = np, mult, calib_blocks, grace_blocks
- self.trip_needed = max(1, int(round(trip_blocks * 0.8)))
+ self.trip_needed = max(1, round(trip_blocks * 0.8))
self.ambient: deque = deque(maxlen=100) # ~3s of quiet-phase RMS
self.recent_above: deque = deque(maxlen=trip_blocks)
self.quiet_floor = float(SILENCE_RMS_THRESHOLD)
diff --git a/tools/wake_word.py b/tools/wake_word.py
index 8c826b185c2..dd2a0efd379 100644
--- a/tools/wake_word.py
+++ b/tools/wake_word.py
@@ -628,8 +628,8 @@ class WakeWordDetector:
cap, rate = _Capture(np=np), details.get("default_samplerate")
if isinstance(rate, (int, float)) and not isinstance(rate, bool) and rate > 0:
with suppress(OverflowError, ValueError):
- cap.rate = int(round(rate))
- cap.frame_length = max(1, int(round(frame_length * cap.rate / SAMPLE_RATE)))
+ cap.rate = round(rate)
+ cap.frame_length = max(1, round(frame_length * cap.rate / SAMPLE_RATE))
logger.info("wake word: opening microphone device=%s selector=%r hostapi=%s "
"default_rate=%s capture_rate=%d engine_rate=%d", details.get("name") or "system default",
self.input_device, details.get("hostapi") or "unknown",
diff --git a/tui_gateway/tool_progress.py b/tui_gateway/tool_progress.py
index 5e0f5be62c1..b2b03399011 100644
--- a/tui_gateway/tool_progress.py
+++ b/tui_gateway/tool_progress.py
@@ -70,7 +70,7 @@ def _fmt_tool_duration(seconds: float | None) -> str:
return f"{seconds:.1f}s"
if seconds < 60:
return f"{round(seconds)}s"
- mins, secs = divmod(int(round(seconds)), 60)
+ mins, secs = divmod(round(seconds), 60)
return f"{mins}m {secs}s" if secs else f"{mins}m"