From e890c57a2b6e6ae2bdff429775c1303ec754e722 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 19:29:01 -0700 Subject: [PATCH] =?UTF-8?q?refactor(gateway):=20session=20=E2=80=94=20fold?= =?UTF-8?q?=20short=20multi-line=20signatures/calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway/session.py | 14 +++----------- gateway/session_lifecycle.py | 5 +---- gateway/session_persistence.py | 9 ++------- gateway/session_transcript.py | 8 ++------ 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/gateway/session.py b/gateway/session.py index 24e688de70..d2d87f066d 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 and transcripts, 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_dir self.config = config self._entries: Dict[str, SessionEntry] = {} diff --git a/gateway/session_lifecycle.py b/gateway/session_lifecycle.py index 287b5126a5..0a77992e10 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 sessions diff --git a/gateway/session_persistence.py b/gateway/session_persistence.py index 96adecd8eb..220debd355 100644 --- a/gateway/session_persistence.py +++ b/gateway/session_persistence.py @@ -302,9 +302,7 @@ class SessionPersistenceMixin: self._loaded = True self._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] = verdict recovered_keys += 1 except 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) return for key in stale_keys: diff --git a/gateway/session_transcript.py b/gateway/session_transcript.py index 14af7b9ac7..fe97425c2e 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 the per-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: