Skip to content

The agent that grows with you

refactor(tui): compact native-threshold coercion and terminal-error surface classification

Tekniumb139f4f41810
diff --git a/tui_gateway/session_auto_continue.py b/tui_gateway/session_auto_continue.py
index c480e9de229..5a90068eabd 100644
--- a/tui_gateway/session_auto_continue.py
+++ b/tui_gateway/session_auto_continue.py
@@ -5,6 +5,8 @@ busy-submit handling. Bodies are rebound onto server.py's globals at install tim
from __future__ import annotations
+import contextlib
+
from .method_ctx import bind_module
# A concluded turn (success, handled error, interrupt) clears its durable marker (turn_marker.py) in
@@ -371,19 +373,16 @@ def _emit_terminal_turn_error(
code, retryable}) is classified here from an exception when the caller doesn't know the layer."""
agent = session.get("agent")
if error_surface is None and isinstance(error, BaseException):
- try:
+ with contextlib.suppress(Exception):
from agent.error_surface import build_error_surface_from_exception
error_surface = build_error_surface_from_exception(
error, provider=str(getattr(agent, "provider", "") or ""), model=str(getattr(agent, "model", "") or "")
)
- except Exception:
- error_surface = None
with session["history_lock"]:
_fail_inflight_turn(session, error, error_surface=error_surface)
turn = session.get("inflight_turn") or {}
- message = str(turn.get("error") or "turn failed")
- partial = str(turn.get("assistant") or "")
+ message, partial = str(turn.get("error") or "turn failed"), str(turn.get("assistant") or "")
cols = int(session.get("cols", 80))
text = partial or f"Error: {message}"
try:
diff --git a/tui_gateway/session_compression.py b/tui_gateway/session_compression.py
index 1497d7729f6..a2e7a8836c4 100644
--- a/tui_gateway/session_compression.py
+++ b/tui_gateway/session_compression.py
@@ -82,8 +82,7 @@ def _apply_live_compression_config(agent: Any, cfg: dict | None) -> None:
agent.codex_responses_native_compaction = is_truthy_value(compression.get("codex_responses_native", False))
native_threshold_raw = compression.get("codex_responses_compact_threshold", 200_000)
try:
- native_threshold = int(native_threshold_raw)
- if isinstance(native_threshold_raw, bool) or native_threshold <= 0:
+ if isinstance(native_threshold_raw, bool) or (native_threshold := int(native_threshold_raw)) <= 0:
raise ValueError
except (TypeError, ValueError):
logger.warning("Invalid compression.codex_responses_compact_threshold=%r; using 200000.", native_threshold_raw)