The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): session — fold short multi-line signatures/calls
Tekniume890c57a2b6e
diff --git a/gateway/session.py b/gateway/session.pyindex 24e688de70c..d2d87f066d7 100644--- a/gateway/session.py+++ b/gateway/session.py@@ -404,11 +404,7 @@ _PLATFORM_NOTES = {}-def build_session_context_prompt(- context: SessionContext,- *,- redact_pii: bool = False,-) -> str:+def build_session_context_prompt(context: SessionContext, *, redact_pii: bool = False) -> str:"""Build the "Current Session Context" system prompt section.With *redact_pii* and a PII-safe platform (builtin set or plugin registry@@ -675,10 +671,7 @@ class SessionEntry:)-def build_channel_continuity_note(- entry: "SessionEntry",- source: SessionSource,-) -> Optional[str]:+def build_channel_continuity_note(entry: "SessionEntry", source: SessionSource) -> Optional[str]:"""One-line continuity hint for long-lived Slack/Discord channels/threads.After an auto-reset the agent could bind a new request to an unrelated@@ -867,8 +860,7 @@ class SessionStore("""Session storage/retrieval: SQLite (SessionDB) for metadata andtranscripts, legacy JSONL fallback when SQLite is unavailable."""- def __init__(self, sessions_dir: Path, config: GatewayConfig,- has_active_processes_fn=None):+ def __init__(self, sessions_dir: Path, config: GatewayConfig, has_active_processes_fn=None):self.sessions_dir = sessions_dirself.config = configself._entries: Dict[str, SessionEntry] = {}diff --git a/gateway/session_lifecycle.py b/gateway/session_lifecycle.pyindex 287b5126a57..0a77992e104 100644--- a/gateway/session_lifecycle.py+++ b/gateway/session_lifecycle.py@@ -263,10 +263,7 @@ class SessionLifecycleMixin:self._set_turn_marker_locked(session_key, entry, None, None)return True- def recover_interrupted_turns(- self,- max_age_seconds: int = 60 * 60,- ) -> int:+ def recover_interrupted_turns(self, max_age_seconds: int = 60 * 60) -> int:"""Promote crash-left turn markers into ``resume_pending`` (unclean startup only).Old/invalid markers are cleared without resuming; suspended sessionsdiff --git a/gateway/session_persistence.py b/gateway/session_persistence.pyindex 96adecd8ebf..220debd3554 100644--- a/gateway/session_persistence.py+++ b/gateway/session_persistence.py@@ -302,9 +302,7 @@ class SessionPersistenceMixin:self._loaded = Trueself._routing_db_loaded = db_load_succeeded- self._routing_fallback_baseline = (- None if db_load_succeeded else self._entries_as_dicts()- )+ self._routing_fallback_baseline = None if db_load_succeeded else self._entries_as_dicts()# A hard crash skips graceful shutdown and leaves sessions.json# pointing at ended sessions; self-heal before the first message.@@ -374,10 +372,7 @@ class SessionPersistenceMixin:self._entries[key] = verdictrecovered_keys += 1except Exception as exc:- logger.warning(- "gateway.session: stale-entry pruning skipped due to DB error: %s",- exc,- )+ logger.warning("gateway.session: stale-entry pruning skipped due to DB error: %s", exc)returnfor key in stale_keys:diff --git a/gateway/session_transcript.py b/gateway/session_transcript.pyindex 14af7b9ac73..fe97425c2e1 100644--- a/gateway/session_transcript.py+++ b/gateway/session_transcript.py@@ -255,9 +255,7 @@ class SessionTranscriptMixin:if _hints:_hints.pop(child_id, None)- def _append_to_transcript_serialized(- self, session_id: str, message: Dict[str, Any]- ) -> None:+ def _append_to_transcript_serialized(self, session_id: str, message: Dict[str, Any]) -> None:"""Append a message to a session's transcript (SQLite), draining theper-session retry queue."""with self._transcript_retry_lock:@@ -461,9 +459,7 @@ class SessionTranscriptMixin:self._dirty_transcripts.pop(session_id, None)self._transcript_append_failures.pop(session_id, None)- def has_platform_message_id(- self, session_id: str, platform_message_id: str- ) -> bool:+ def has_platform_message_id(self, session_id: str, platform_message_id: str) -> bool:"""Whether a message with this platform_message_id is persisted (False without a DB)."""db = self._db_for_session_id(session_id)if not db: