Preserve running session replay state

This commit is contained in:
武阳
2026-05-07 16:49:42 +08:00
parent 2ba67ead00
commit 61a0a0a648
5 changed files with 213 additions and 31 deletions
+28 -2
View File
@@ -276,8 +276,7 @@ class RunManager:
def snapshot_latest(self, account_key: str, session_id: str) -> dict[str, Any] | None:
with self._lock:
run_id = self._latest_by_session.get((account_key, session_id))
record = self._runs.get(run_id or '')
record = self._select_session_record(account_key, session_id)
if record is None:
return None
return {
@@ -290,6 +289,33 @@ class RunManager:
'error': record.error,
}
def _select_session_record(
self,
account_key: str,
session_id: str,
) -> RunRecord | None:
records = [
record
for record in self._runs.values()
if record.account_key == account_key and record.session_id == session_id
]
running = [
record
for record in records
if record.status == 'running'
]
if running:
return max(running, key=lambda item: item.updated_at)
queued = [
record
for record in records
if record.status == 'queued'
]
if queued:
return max(queued, key=lambda item: item.started_at)
run_id = self._latest_by_session.get((account_key, session_id))
return self._runs.get(run_id or '')
class AgentState:
"""Holds account-scoped agent instances, config, and execution locks."""