MCPcopy
hub / github.com/aiming-lab/MetaClaw / resolve_session

Method resolve_session

metaclaw/cli_session_store.py:91–131  ·  view source on GitHub ↗

Resolve the CLI session ID for a given MetaClaw session. Returns (cli_session_id, is_new). If the session is invalidated (auth or system prompt changed), a new session is started.

(
        self,
        metaclaw_session_id: str,
        auth_profile_id: str | None = None,
        system_prompt: str | None = None,
    )

Source from the content-addressed store, hash-verified

89 # ── session resolution (mirrors OpenClaw's resolveCliSessionReuse) ───
90
91 def resolve_session(
92 self,
93 metaclaw_session_id: str,
94 auth_profile_id: str | None = None,
95 system_prompt: str | None = None,
96 ) -> tuple[str, bool]:
97 """Resolve the CLI session ID for a given MetaClaw session.
98
99 Returns (cli_session_id, is_new).
100 If the session is invalidated (auth or system prompt changed),
101 a new session is started.
102 """
103 current_sp_hash = _hash_text(system_prompt)
104 existing = self._bindings.get(metaclaw_session_id)
105
106 if existing:
107 # Check if session is still valid
108 invalidated = self._check_invalidation(
109 existing, auth_profile_id, current_sp_hash
110 )
111 if not invalidated:
112 return existing.cli_session_id, False
113 else:
114 logger.info(
115 "[CliSessionStore] session %s invalidated: %s",
116 metaclaw_session_id,
117 invalidated,
118 )
119
120 # Create new CLI session
121 import time
122
123 cli_sid = str(uuid.uuid4())
124 self._bindings[metaclaw_session_id] = CliSessionBinding(
125 cli_session_id=cli_sid,
126 auth_profile_id=auth_profile_id,
127 system_prompt_hash=current_sp_hash,
128 created_at=time.time(),
129 )
130 self.save()
131 return cli_sid, True
132
133 def _check_invalidation(
134 self,

Callers 1

_forward_to_cliMethod · 0.95

Calls 6

_check_invalidationMethod · 0.95
saveMethod · 0.95
_hash_textFunction · 0.85
CliSessionBindingClass · 0.85
getMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected