Skip to content

The agent that grows with you

refactor(tui): restore compact WHY notes lost in earlier docstring compaction

Teknium28bc8d05b95a
diff --git a/tui_gateway/_stdin_recovery.py b/tui_gateway/_stdin_recovery.py
index 1f07c52bacd..4b7e685f2c1 100644
--- a/tui_gateway/_stdin_recovery.py
+++ b/tui_gateway/_stdin_recovery.py
@@ -103,6 +103,7 @@ def handle_spurious_eof(recovery_times: list[float], log_fn: object) -> bool:
# a non-zero timeout would make the next readline() return '' again, looping
# until the rate limiter fires.
os.set_blocking(0, True)
+ # "ll" = struct timeval {tv_sec, tv_usec}; zero timeval disables the timeout.
_stdin_sockopt(lambda s: s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, struct.pack("ll", 0, 0)))
# TextIOWrapper.readline returns '' on EAGAIN but does NOT stick EOF; the
diff --git a/tui_gateway/entry.py b/tui_gateway/entry.py
index f6f82785cb3..16726e91131 100644
--- a/tui_gateway/entry.py
+++ b/tui_gateway/entry.py
@@ -151,6 +151,8 @@ def _install_signal(signame, handler):
try:
signal.signal(sig, handler)
except (ValueError, OSError, RuntimeError):
+ # Off the main thread despite the check, or handler rejected by the
+ # platform — skip rather than crash the import.
pass
diff --git a/tui_gateway/hosted_room_driver.py b/tui_gateway/hosted_room_driver.py
index 94e4b8296fc..345b6c4ff1a 100644
--- a/tui_gateway/hosted_room_driver.py
+++ b/tui_gateway/hosted_room_driver.py
@@ -479,7 +479,11 @@ class HostedRoomRuntime:
def _resume_exact(
self, transport: InternalSessionRPC, room_id: str, profile: str
) -> str | None:
- """Resolve the canonical room session and return its resumed runtime id."""
+ """Resolve the canonical room session and return its resumed runtime id.
+
+ Callers must use the returned id (not the stored one) for every
+ subsequent history/info probe; resume may hand back a different id.
+ """
session = transport.resolve_exact(
profile=profile,
title=room_session_title(room_id),
diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.py
index 35286311fb9..bbfb455c3e0 100644
--- a/tui_gateway/methods_profiles.py
+++ b/tui_gateway/methods_profiles.py
@@ -106,6 +106,7 @@ def _latest_message_preview(db, session_id):
Messaging-app semantics for rosters (latest exchange), unlike the first-message
preview session lists use for recognition. Agent-delivery prefixes are kept.
+ Same query shape as ``SessionDB.latest_message_row_id`` — keep them in step.
"""
try:
with db._lock:
@@ -127,8 +128,9 @@ def _latest_message_preview(db, session_id):
def _open_profile_session_db_readonly(profile_path):
"""Read-only attach for roster previews, or None.
- A writable ``SessionDB()`` waits up to 20s for the write lock; the roster polls
- every 5s while the live backend holds it, which stalled the RPC past the desktop timeout.
+ A writable ``SessionDB()`` waits up to 20s for the write lock and runs schema init;
+ the roster polls every 5s while the live backend holds the writer, which stalled the
+ RPC past the desktop timeout. ``read_only=True`` takes neither the lock nor the DDL.
"""
db_path = Path(profile_path) / "state.db"
if not _try(db_path.exists, False):
diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.py
index 5f52c63905f..23d4a79bbdc 100644
--- a/tui_gateway/methods_session.py
+++ b/tui_gateway/methods_session.py
@@ -414,6 +414,8 @@ def _(rid, params: dict) -> dict:
def _session_list_by_title(rid, db, title_lookup: str) -> dict:
"""EXACT-title registry lookup (not a listing) for callers that treat a title as identity.
+ Window-free on purpose: a busy profile's recency-windowed listing can push the
+ row out, so scanning ``session.list`` output is not a reliable identity lookup.
Hidden rows resolve (canonical chats are born hidden); archived rows and
deny-listed sources do not; compression lineages resolve to the live tip
(``resolved_id``), mirroring profiles.list's canonical_session resolver.
@@ -858,7 +860,9 @@ def _resume_response(
def _resume_read_history(ctx: _Resume):
"""One lineage SELECT feeds both projections: model-fed copy alternation-repaired
- for live replay, display copy verbatim (inspection/export shows what is stored)."""
+ for live replay, display copy verbatim (inspection/export shows what is stored).
+ The repaired copy becomes the resumed session's working conversation, so healing
+ a durable violation once here avoids re-firing the pre-request repair every turn."""
ctx.db.reopen_session(ctx.target)
if ctx.omit_messages:
raw = ctx.db.get_messages_as_conversation(ctx.target, repair_alternation=True, include_row_ids=True)