refactor(gateway): session — fold short multi-line signatures/calls

This commit is contained in:
Teknium
2026-09-02 19:29:01 -07:00
parent ef4f0f4f61
commit e890c57a2b
4 changed files with 8 additions and 28 deletions

View File

@@ -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] = {}

View File

@@ -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

View File

@@ -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:

View File

@@ -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: